Message ID | 20210923104123.29878-2-lhenriques@suse.de (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | generic/079 test fails if 'nobody' and 'daemon' don't exist | expand |
On Thu, Sep 23, 2021 at 11:41:22AM +0100, Luis Henriques wrote: > Function _require_user() does check if a user exists *and* if it is able > to execute commands. Add a new function to simply check if a user exists. > > Signed-off-by: Luis Henriques <lhenriques@suse.de> Looks like a simple enough hoist. You /could/ streamline the bash constructs too, but ... fmeh. This is easy to review, at least. Reviewed-by: Darrick J. Wong <djwong@kernel.org> --D > --- > common/rc | 27 ++++++++++++++++++--------- > 1 file changed, 18 insertions(+), 9 deletions(-) > > diff --git a/common/rc b/common/rc > index 154bc2dd7e94..c7e77c0e26dc 100644 > --- a/common/rc > +++ b/common/rc > @@ -2289,18 +2289,27 @@ _cat_group() > cat /etc/group > } > > -# check for a user on the machine, fsgqa as default > +# check if a user exists in the system > +# > +_require_user_exists() > +{ > + user=$1 > + _cat_passwd | grep -q $user > + [ "$?" == "0" ] || _notrun "$user user not defined." > +} > + > +# check if a user exists and is able to execute commands. > +# Uses 'fsgqa' user as default. > # > _require_user() > { > - qa_user=fsgqa > - if [ -n "$1" ];then > - qa_user=$1 > - fi > - _cat_passwd | grep -q $qa_user > - [ "$?" == "0" ] || _notrun "$qa_user user not defined." > - echo /bin/true | su $qa_user > - [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands." > + qa_user=fsgqa > + if [ -n "$1" ];then > + qa_user=$1 > + fi > + _require_user_exists $qa_user > + echo /bin/true | su $qa_user > + [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands." > } > > # check for a chown support
On Thu, Sep 23, 2021 at 11:41:22AM +0100, Luis Henriques wrote: > Function _require_user() does check if a user exists *and* if it is able > to execute commands. Add a new function to simply check if a user exists. > > Signed-off-by: Luis Henriques <lhenriques@suse.de> > --- > common/rc | 27 ++++++++++++++++++--------- > 1 file changed, 18 insertions(+), 9 deletions(-) > > diff --git a/common/rc b/common/rc > index 154bc2dd7e94..c7e77c0e26dc 100644 > --- a/common/rc > +++ b/common/rc > @@ -2289,18 +2289,27 @@ _cat_group() > cat /etc/group > } > > -# check for a user on the machine, fsgqa as default > +# check if a user exists in the system > +# > +_require_user_exists() > +{ > + user=$1 > + _cat_passwd | grep -q $user > + [ "$?" == "0" ] || _notrun "$user user not defined." > +} Please make "user" a local variable so that it doesn't overwrite another variable with the same name. - Eric
diff --git a/common/rc b/common/rc index 154bc2dd7e94..c7e77c0e26dc 100644 --- a/common/rc +++ b/common/rc @@ -2289,18 +2289,27 @@ _cat_group() cat /etc/group } -# check for a user on the machine, fsgqa as default +# check if a user exists in the system +# +_require_user_exists() +{ + user=$1 + _cat_passwd | grep -q $user + [ "$?" == "0" ] || _notrun "$user user not defined." +} + +# check if a user exists and is able to execute commands. +# Uses 'fsgqa' user as default. # _require_user() { - qa_user=fsgqa - if [ -n "$1" ];then - qa_user=$1 - fi - _cat_passwd | grep -q $qa_user - [ "$?" == "0" ] || _notrun "$qa_user user not defined." - echo /bin/true | su $qa_user - [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands." + qa_user=fsgqa + if [ -n "$1" ];then + qa_user=$1 + fi + _require_user_exists $qa_user + echo /bin/true | su $qa_user + [ "$?" == "0" ] || _notrun "$qa_user cannot execute commands." } # check for a chown support
Function _require_user() does check if a user exists *and* if it is able to execute commands. Add a new function to simply check if a user exists. Signed-off-by: Luis Henriques <lhenriques@suse.de> --- common/rc | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)