Etc.passwd on OS X

S

Steven Hansen

Hi,

I'm wondering if anyone knows how the Etc class locates users for OS X.

The documentation suggests that it simply parses the /etc/passwd file
and returns a list of the users in there. However, I don't think this
is true for OSX. When I look through my /etc/passwd file I notice that
there are several users missing, including the username that Iogin with.

However, the Etc class still manages to find all of the users on my
system... For OSX, does the Etc class inspect an alternate file? If
so, what file is it getting its information from?


Thanks,
Steven
 
P

Peter Booth

[Note: parts of this message were removed to make it a legal post.]

Steven,

OS/X doesn't use the Unix/Linux /etc/passwd and /etc/group files.
Instead it uses
netinfo (or another directory service). There's a command line tool
dscl that is quite powerful.
See below (ignore the names) or look at the manpages for dscl

Peter


# Create user mr-potato-head
sudo "/usr/bin/dscl . -create /Users/mr-potato-head UniqueID 2400"
sudo "ditto --rsrc '/System/Library/User\ Template/
English.lproj/' /Users/mr-potato-head"
sudo "chown -R mr-potato-head /Users/mr-potato-head"
sudo "/usr/bin/dscl . -create /Users/mr-potato-head
NFSHomeDirectory /Users/mr-potato-head"
# mr-potato-head user needs admin access
sudo "/usr/bin/dscl . -append /groups/wheel GroupMembership mr-
potato-head"
# Create user mr-radish
sudo "/usr/bin/dscl . -create /Users/mr-radish UniqueID 2410"
sudo "ditto --rsrc '/System/Library/User\ Template/
English.lproj/' /Users/mr-radish"
sudo "chown -R mr-potato-head /Users/mr-radish"
sudo "/usr/bin/dscl . -create /Users/mr-radish NFSHomeDirectory /
Users/mr-radish"
sudo "/usr/bin/dscl . create /Groups/vegetable PrimaryGroupID 2420"
sudo "/usr/bin/dscl . append /groups/vegetable GroupMembership mr-
potato-head"
sudo "/usr/bin/dscl . append /groups/vegetable GroupMembership mr-
radish"
 
G

Gary Wright

However, the Etc class still manages to find all of the users on my
system... For OSX, does the Etc class inspect an alternate file? If
so, what file is it getting its information from?

Without looking at the Ruby source I would guess that ruby uses the
POSIX getpwnam function. The man page ("man getpwnam") for that
function
says:
These functions obtain information from DirectoryService(8),
including records in /etc/passwd which is described in passwd(5).
Each entry in the database is defined by the structure passwd found
in the include file <pwd.h>

So the magic is happening in the Apple supplied getpwnam function
which accesses Mac OS's DirectoryService daemon (as well as the
static /etc/passwd file apparently) for the actual data.

Gary Wright
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top