From: Luis Henriques <lhenriques@suse.de>
To: Zorro Lang <zlang@redhat.com>
Cc: fstests@vger.kernel.org, Eric Biggers <ebiggers@kernel.org>,
"Darrick J . Wong" <djwong@kernel.org>, Eryu Guan <guan@eryu.me>,
Luis Chamberlain <mcgrof@kernel.org>
Subject: Re: [PATCH v2 1/2] common/rc: add _require_user_exists() to check if a user exists
Date: Mon, 27 Sep 2021 09:44:17 +0100 [thread overview]
Message-ID: <YVGEYQLYroePoys6@suse.de> (raw)
In-Reply-To: <20210926102217.332hdmrhwlvgkrxj@fedora>
On Sun, Sep 26, 2021 at 06:22:17PM +0800, Zorro Lang wrote:
> On Sun, Sep 26, 2021 at 06:13:54PM +0800, Zorro Lang wrote:
> > On Fri, Sep 24, 2021 at 10:19:10AM +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..de9ba56eefcf 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()
> > > +{
> > > + local user=$1
> > > + _cat_passwd | grep -q $user
> > > + [ "$?" == "0" ] || _notrun "$user user not defined."
> >
> > As _require_user() does "su $qa_user" after the "grep", so it really make sure
> > there's an "user". But if the _require_user_exists() only trys to grep /etc/passed
> > to make sure there's an "$user", I'd like to make the "grep" condition be more exact.
> > For example, if there's an user "myuser100" in the /etc/passwd, then _require_user_exists
> > "myuser" or "user100" or "user1" or "user10" all return 0.
> >
> > So how about:
> > _cat_passwd | grep -qw $user
> >
> > Or more exact:
> > _cat_passwd | cut -d: -f1 | grep -qw $user
> >
> > Or other better command line:)
>
> Oh, the "-w" doesn't work with an user with "_", likes myuser_123. So
> how about:
>
> _cat_passwd | grep -q ^$user:
Yep, that seems to make sense. I'll prepare v3 and send it out soon.
Cheers,
--
Luís
next prev parent reply other threads:[~2021-09-27 8:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-24 9:19 [PATCH v2 0/2] generic/079 test fails if 'nobody' and 'daemon' don't exist Luis Henriques
2021-09-24 9:19 ` [PATCH v2 1/2] common/rc: add _require_user_exists() to check if a user exists Luis Henriques
2021-09-26 10:13 ` Zorro Lang
2021-09-26 10:22 ` Zorro Lang
2021-09-27 8:44 ` Luis Henriques [this message]
2021-09-24 9:19 ` [PATCH v2 2/2] generic/079: make sure users 'nobody' and 'daemon' exist Luis Henriques
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YVGEYQLYroePoys6@suse.de \
--to=lhenriques@suse.de \
--cc=djwong@kernel.org \
--cc=ebiggers@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=guan@eryu.me \
--cc=mcgrof@kernel.org \
--cc=zlang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.