views:

92

answers:

1

Hello I'd like to list all real users on Linux/*nix and it's data. I probably need to parse /etc/passwd and /etc/shadow and check if user have password.

The problem is that is not cross-platform (on *BSD there is no /etc/shadow). Is there any cross-platform library/command I can use?

+2  A: 

See man pages for getpwent.

   The getpwent() function returns a pointer to a structure containing the
   broken-out  fields  of  a  record from the password database (e.g., the
   local password file /etc/passwd, NIS, and LDAP).

I will add that if you want to check the passwords, look at getspent, getspnam for listing the shadow password file. The man page says that the getspent etc. functions might not be cross-platform though.

ondra
You could call `getpwent()` and check if the shell ends in `sh` - system users often have something like `/bin/false` as their "shell".
caf
Unless someone have chosen `tmux` or `screen` as logging shell ;) However there is `/etc/shells` file.
Maciej Piechotka