1996-12-24 07:39:42 +08:00
|
|
|
from test_support import verbose
|
1996-12-12 00:53:51 +08:00
|
|
|
import pwd
|
|
|
|
import string
|
|
|
|
|
1996-12-24 07:39:42 +08:00
|
|
|
print 'pwd.getpwall()'
|
1996-12-12 00:53:51 +08:00
|
|
|
entries = pwd.getpwall()
|
|
|
|
|
|
|
|
for e in entries:
|
|
|
|
name = e[0]
|
|
|
|
uid = e[2]
|
|
|
|
if verbose:
|
1998-03-27 03:42:58 +08:00
|
|
|
print name, uid
|
1996-12-24 07:39:42 +08:00
|
|
|
print 'pwd.getpwuid()'
|
1996-12-12 00:53:51 +08:00
|
|
|
dbuid = pwd.getpwuid(uid)
|
2000-12-13 07:11:42 +08:00
|
|
|
if dbuid[0] != name:
|
1998-03-27 03:42:58 +08:00
|
|
|
print 'Mismatch in pwd.getpwuid()'
|
1996-12-24 07:39:42 +08:00
|
|
|
print 'pwd.getpwnam()'
|
1996-12-12 00:53:51 +08:00
|
|
|
dbname = pwd.getpwnam(name)
|
2000-12-13 07:11:42 +08:00
|
|
|
if dbname[2] != uid:
|
1998-03-27 03:42:58 +08:00
|
|
|
print 'Mismatch in pwd.getpwnam()'
|
1996-12-24 07:39:42 +08:00
|
|
|
else:
|
1998-03-27 03:42:58 +08:00
|
|
|
print 'name matches uid'
|
1996-12-12 00:53:51 +08: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)):
|
1998-03-27 03:42:58 +08:00
|
|
|
if chars[i] == 'z':
|
|
|
|
chars[i] = 'A'
|
|
|
|
break
|
|
|
|
elif chars[i] == 'Z':
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
chars[i] = chr(ord(chars[i]) + 1)
|
|
|
|
break
|
1996-12-12 00:53:51 +08:00
|
|
|
else:
|
1998-03-27 03:42:58 +08:00
|
|
|
namei = namei + 1
|
|
|
|
try:
|
|
|
|
fakename = allnames[namei]
|
|
|
|
except IndexError:
|
|
|
|
# should never happen... if so, just forget it
|
|
|
|
break
|
1996-12-12 00:53:51 +08:00
|
|
|
fakename = string.join(map(None, chars), '')
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1996-12-12 00:53:51 +08:00
|
|
|
try:
|
|
|
|
pwd.getpwnam(fakename)
|
|
|
|
except KeyError:
|
1996-12-24 07:39:42 +08:00
|
|
|
print 'caught expected exception'
|
1996-12-12 00:53:51 +08:00
|
|
|
else:
|
|
|
|
print 'fakename', fakename, 'did not except pwd.getpwnam()'
|
|
|
|
|
2000-06-28 22:48:01 +08:00
|
|
|
# Choose a non-existent uid.
|
1997-05-21 03:31:25 +08:00
|
|
|
fakeuid = 4127
|
|
|
|
while byuids.has_key(fakeuid):
|
1997-05-21 03:32:22 +08:00
|
|
|
fakeuid = (fakeuid * 3) % 0x10000
|
1996-12-12 00:53:51 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
pwd.getpwuid(fakeuid)
|
|
|
|
except KeyError:
|
1996-12-24 07:39:42 +08:00
|
|
|
print 'caught expected exception'
|
1996-12-12 00:53:51 +08:00
|
|
|
else:
|
|
|
|
print 'fakeuid', fakeuid, 'did not except pwd.getpwuid()'
|