1*0Sstevel@tonic-gate#!./perl 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate} 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gateBEGIN { 9*0Sstevel@tonic-gate our $haspw; 10*0Sstevel@tonic-gate eval { my @n = getpwuid 0 }; 11*0Sstevel@tonic-gate $haspw = 1 unless $@ && $@ =~ /unimplemented/; 12*0Sstevel@tonic-gate unless ($haspw) { print "1..0 # Skip: no getpwuid\n"; exit 0 } 13*0Sstevel@tonic-gate use Config; 14*0Sstevel@tonic-gate # VMS's pwd.h struct passwd conflicts with the one in vmsish.h 15*0Sstevel@tonic-gate $haspw = 0 unless ( $Config{'i_pwd'} eq 'define' || $^O eq 'VMS' ); 16*0Sstevel@tonic-gate unless ($haspw) { print "1..0 # Skip: no pwd.h\n"; exit 0 } 17*0Sstevel@tonic-gate} 18*0Sstevel@tonic-gate 19*0Sstevel@tonic-gateBEGIN { 20*0Sstevel@tonic-gate our $uid = 0; 21*0Sstevel@tonic-gate # On VMS getpwuid(0) may return [$gid,0] UIC info (which may not exist). 22*0Sstevel@tonic-gate # It is better to use the $< uid for testing on VMS instead. 23*0Sstevel@tonic-gate if ( $^O eq 'VMS' ) { $uid = $< ; } 24*0Sstevel@tonic-gate our @pwent = getpwuid $uid; # This is the function getpwuid. 25*0Sstevel@tonic-gate unless (@pwent) { print "1..0 # Skip: no uid $uid\n"; exit 0 } 26*0Sstevel@tonic-gate} 27*0Sstevel@tonic-gate 28*0Sstevel@tonic-gateprint "1..9\n"; 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gateuse User::pwent; 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gateprint "ok 1\n"; 33*0Sstevel@tonic-gate 34*0Sstevel@tonic-gatemy $pwent = getpwuid $uid; # This is the OO getpwuid. 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gatemy $uid_expect = $uid; 37*0Sstevel@tonic-gateif ( $^O eq 'cygwin' ) { 38*0Sstevel@tonic-gate print "not " unless ( $pwent->uid == $uid_expect 39*0Sstevel@tonic-gate || $pwent->uid == 500 ); # go figure 40*0Sstevel@tonic-gate} 41*0Sstevel@tonic-gateelse { 42*0Sstevel@tonic-gate print "not " unless $pwent->uid == $uid_expect ; 43*0Sstevel@tonic-gate} 44*0Sstevel@tonic-gateprint "ok 2\n"; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gateprint "not " unless $pwent->name eq $pwent[0]; 47*0Sstevel@tonic-gateprint "ok 3\n"; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gateif ($^O eq 'os390') { 50*0Sstevel@tonic-gate print "not " 51*0Sstevel@tonic-gate unless not defined $pwent->passwd && 52*0Sstevel@tonic-gate $pwent[1] eq '0'; # go figure 53*0Sstevel@tonic-gate} else { 54*0Sstevel@tonic-gate print "not " unless $pwent->passwd eq $pwent[1]; 55*0Sstevel@tonic-gate} 56*0Sstevel@tonic-gateprint "ok 4\n"; 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gateprint "not " unless $pwent->uid == $pwent[2]; 59*0Sstevel@tonic-gateprint "ok 5\n"; 60*0Sstevel@tonic-gate 61*0Sstevel@tonic-gateprint "not " unless $pwent->gid == $pwent[3]; 62*0Sstevel@tonic-gateprint "ok 6\n"; 63*0Sstevel@tonic-gate 64*0Sstevel@tonic-gate# The quota and comment fields are unportable. 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gateprint "not " unless $pwent->gecos eq $pwent[6]; 67*0Sstevel@tonic-gateprint "ok 7\n"; 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gateprint "not " unless $pwent->dir eq $pwent[7]; 70*0Sstevel@tonic-gateprint "ok 8\n"; 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gateprint "not " unless $pwent->shell eq $pwent[8]; 73*0Sstevel@tonic-gateprint "ok 9\n"; 74*0Sstevel@tonic-gate 75*0Sstevel@tonic-gate# The expire field is unportable. 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate# Testing pretty much anything else is unportable: 78*0Sstevel@tonic-gate# there maybe more than one username with uid 0; 79*0Sstevel@tonic-gate# uid 0's home directory may be "/" or "/root' or something else, 80*0Sstevel@tonic-gate# and so on. 81*0Sstevel@tonic-gate 82