How can I obtain an array with uid and names?
I could iterate from 0 to 99999 and do a getpwnam()
.
However most machines have less than 5 accounts, so it's not optimal. I don't know what framework is responsible for this and thus I have no clue what to search for.
Is there a more optimal solution that can traverse the accounts?
Edit: Right after I posted I discovered getpwent()
for traversing accounts.
setpwent();
struct passwd *pw;
while ((pw = getpwent())) printf("%d\n", pw->pw_uid);
endpwent();
However that doesn't indicate wether an account is a System Preferences account or not.
So still how does one obtain the System Preferences accounts?
Edit: I have found the commandline equivalent of this, the dscl
command.
prompt> dscl . -list /Users UniqueID
_mysql 74
_postfix 27
_spotlight 89
_sshd 75
_windowserver 88
_www 70
daemon 1
johndoe 501
nobody -2
root 0