1996-12-23 19:39:42 -04:00
|
|
|
from test_support import verbose
|
1996-12-11 12:53:51 -04:00
|
|
|
import pwd
|
|
|
|
import string
|
|
|
|
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'pwd.getpwall()'
|
1996-12-11 12:53:51 -04:00
|
|
|
entries = pwd.getpwall()
|
|
|
|
|
|
|
|
for e in entries:
|
|
|
|
name = e[0]
|
|
|
|
uid = e[2]
|
|
|
|
if verbose:
|
|
|
|
print name, uid
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'pwd.getpwuid()'
|
1996-12-11 12:53:51 -04:00
|
|
|
dbuid = pwd.getpwuid(uid)
|
|
|
|
if dbuid[0] <> name:
|
|
|
|
print 'Mismatch in pwd.getpwuid()'
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'pwd.getpwnam()'
|
1996-12-11 12:53:51 -04:00
|
|
|
dbname = pwd.getpwnam(name)
|
|
|
|
if dbname[2] <> uid:
|
|
|
|
print 'Mismatch in pwd.getpwnam()'
|
1996-12-23 19:39:42 -04:00
|
|
|
else:
|
|
|
|
print 'name matches uid'
|
1996-12-11 12:53:51 -04:00
|
|
|
break
|
|
|
|
|
|
|
|
# try to get some errors
|
|
|
|
bynames = {}
|
|
|
|
byuids = {}
|
|
|
|
for n, p, u, g, gecos, d, s in entries:
|
|
|
|
bynames[n] = u
|
|
|
|
byuids[u] = n
|
|
|
|
|
|
|
|
allnames = bynames.keys()
|
|
|
|
namei = 0
|
|
|
|
fakename = allnames[namei]
|
|
|
|
while bynames.has_key(fakename):
|
|
|
|
chars = map(None, fakename)
|
|
|
|
for i in range(len(chars)):
|
|
|
|
if chars[i] == 'z':
|
|
|
|
chars[i] = 'A'
|
|
|
|
break
|
|
|
|
elif chars[i] == 'Z':
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
chars[i] = chr(ord(chars[i]) + 1)
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
namei = namei + 1
|
|
|
|
try:
|
|
|
|
fakename = allnames[namei]
|
|
|
|
except IndexError:
|
|
|
|
# should never happen... if so, just forget it
|
|
|
|
break
|
|
|
|
fakename = string.join(map(None, chars), '')
|
|
|
|
|
|
|
|
try:
|
|
|
|
pwd.getpwnam(fakename)
|
|
|
|
except KeyError:
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'caught expected exception'
|
1996-12-11 12:53:51 -04:00
|
|
|
else:
|
|
|
|
print 'fakename', fakename, 'did not except pwd.getpwnam()'
|
|
|
|
|
1997-05-20 16:31:25 -03:00
|
|
|
# Choose a non-existant uid.
|
|
|
|
fakeuid = 4127
|
|
|
|
while byuids.has_key(fakeuid):
|
1997-05-20 16:32:22 -03:00
|
|
|
fakeuid = (fakeuid * 3) % 0x10000
|
1996-12-11 12:53:51 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
pwd.getpwuid(fakeuid)
|
|
|
|
except KeyError:
|
1996-12-23 19:39:42 -04:00
|
|
|
print 'caught expected exception'
|
1996-12-11 12:53:51 -04:00
|
|
|
else:
|
|
|
|
print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()'
|