1

I'm looking for a cross-platform way of determining whether or not a username and groupname is valid. The platforms are Linux, Solaris, Aix, and HPUX. It would need to work whether the user/group is defined locally (e.g. /etc/passwd) or through a service like LDAP or NIS/YP. It's probably wishful thinking that such a method exists, but it can't hurt (too much) to ask. Thanks!

Additional Info: Unfortunately I don't control the systems where this will run; the script is going out to clients and they can do whatever they want. And I don't have a way to test any of this myself...

Joe Casadonte
  • 338
  • 3
  • 16

3 Answers3

4

does "getent passwd | grep " not get you anywhere ?

Sirex
  • 5,499
  • 2
  • 33
  • 54
  • 7
    BTW, you do not need to grep, `getent passwd username` works. – ptman Oct 21 '10 at 14:39
  • Does getent hook into LDAP and NIS? – Joe Casadonte Oct 21 '10 at 17:13
  • 1
    @Joe At least on Solaris, getent goes through the nsswitch backend to get the data from whatever you've configured in nsswitch.conf (NIS, LDAP, /etc/* files and so on). – alanc Oct 21 '10 at 17:22
  • 1
    Generally, getent will hook into NIS and LDAP. getent should be calling the appropriate C library calls to pull user ID information. As long as LDAP or NIS is setup correctly on a system, the getent command will return information about those entries. – SteveM Oct 21 '10 at 17:26
  • @ptman, yea i know :( but, but, i love grep ! – Sirex Oct 22 '10 at 08:09
2

From commandlinefu:

id <username>
Belmin Fernandez
  • 10,799
  • 27
  • 84
  • 148
1

If not groking the flatfiles, I typically use the commands id or finger. If you have the system configured to use LDAP or NIS/YP system-wide, any command-line utility should share this functionality.

Ultimately, for your solution to be infallible, you will likely have to write more complicated logic into your script. This is a good example of why IT departments often try to prevent too many technology variances.

Warner
  • 23,756
  • 2
  • 59
  • 69