I beleve there is a bug in Etc.getpwnam. On our OS X server running
10.4 with ruby 1.8.2 (2004-12-25) [powerpc-darwin8.0] we use AD for user
management.
The two id’s the one that is my real id i got from ls -ln and the one
from getpwnam differ only in the sign bit, so it looks like ruby is
treating it as a 1’s compliment number when it is an unsigned int. i
could change if you take -566183520 & 0x7FFFFFFF in ruby it will return
the proper number 1581300128. The same happens for all users with
larger id’s in our AD system.
irb(main):016:0> Etc.getpwuid(1581300128)
=> #<struct Struct::Passwd name=“mcgoverp”, passwd="********",
uid=-566183520, gid=513, gecos=“Ryan McGovern”,
dir="/Network/Servers/ucfilespace.uc.edu/Home/m/mcgoverp",
shell="/usr/local/profile", change=0, uclass="", expire=0>
irb(main):017:0> uinf=Etc.getpwnam(“mcgoverp”)
=> #<struct Struct::Passwd name=“mcgoverp”, passwd="********",
uid=-566183520, gid=513, gecos=“Ryan McGovern”,
dir="/Network/Servers/ucfilespace.uc.edu/Home/m/mcgoverp",
shell="/usr/local/profile", change=0, uclass="", expire=0>
irb(main):019:0> Etc.getpwuid(-566183520)
ArgumentError: can’t find user for -566183520
from (irb):19:in `getpwuid’
from (irb):19
from :0
irb(main):005:0> Etc.getpwnam(“monkir”)
=> #<struct Struct::Passwd name=“monkir”, passwd=“",
uid=-476125468, gid=513, gecos=“Ian Monk”,
dir="/Network/Servers/ucfilespace.uc.edu/Home/m/monkir",
shell="/bin/bash", change=0, uclass="", expire=0>
irb(main):006:0> Etc.getpwnam(“monkir”).uid & 0x7FFFFFFF
=> 1671358180
irb(main):007:0> Etc.getpwuid(1671358180)
=> #<struct Struct::Passwd name=“monkir”, passwd="”,
uid=-476125468, gid=513, gecos=“Ian Monk”,
dir="/Network/Servers/ucfilespace.uc.edu/Home/m/monkir",
shell="/bin/bash", change=0, uclass="", expire=0>