Etc.passwd on OS X

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

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”

On Oct 12, 2009, at 8:28 PM, Steven H. wrote:

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 W.

Thanks Gary and Peter!

Best,
Steven

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs