1758016 Members
1925 Online
108866 Solutions
New Discussion юеВ

Verify user

 
SOLVED
Go to solution
Mary Rice
Frequent Advisor

Verify user

Hi everyone,

I'm hoping someone has a handy script that will allow me to verify a login. I would like to know if 'mrice' is valid. I can't just grep /etc/passwd because we run NIS.

Thanks for any ideas,
Mary Rice
6 REPLIES 6
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Verify user

Hi Mary:

I just happen to have something very clsoe in my /utils directory, Getpwnam.pl.

Use it like this:

USER="mrice"

Getpwnam.pl -q ${USER}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "${USER} is valid"
else
echo "${USER} ain't no good"
fi

The -q says only return a status; without it you get a list of passwd fields.

If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Verify user

Ooops, I suppose you might want the script.

If it ain't broke, I can fix that.
Mary Rice
Frequent Advisor

Re: Verify user

Hi Clay,

Thanks for the quick reply. Does this script work with NIS/NIS+ or will I need to modify it? It looks like it reads the passwd file.

Mary
A. Clay Stephenson
Acclaimed Contributor

Re: Verify user

Mary, Mary, Mary ...

You should have asked your box rather than me but yes, Getpwnam.pl does read /etc/passwd BUT it also reads the NIS/NIS+ passwd map. Perl's getpwnam() function simply calls the underlying getpwnam() C libC function. It takes care of all of this for you. If no matching user is found in /etc/passwd and a '+' entry is founds then the NIS map is examined for a match.

This routine works equally well in the NIS and non-NIS worlds. Ain't Perl nice?

Regards, Clay

If it ain't broke, I can fix that.
Mary Rice
Frequent Advisor

Re: Verify user

Clay,

I'm sorry that I doubted you. I should have known better.

Thanks again,
Mary
A. Clay Stephenson
Acclaimed Contributor

Re: Verify user

Hi Mary:

I trust you know that that was tongue in cheek.

Regards, Clay
If it ain't broke, I can fix that.