3 import sys,os,subprocess
7 print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
13 def flush_cache(sids=[], uids=[], gids=[]):
15 os.system(netcmd + (" cache del IDMAP/SID2XID/%s" % (sid)))
17 os.system(netcmd + (" cache del IDMAP/UID2SID/%s" % (uid)))
19 os.system(netcmd + (" cache del IDMAP/GID2SID/%s" % (gid)))
21 def fill_cache(inids, idtype='gid'):
25 subprocess.Popen([wbinfo, '--%s-to-sid=%s' % (idtype, inid)],
26 stdout=subprocess.PIPE).communicate()
28 domain = subprocess.Popen([wbinfo, "--own-domain"],
29 stdout=subprocess.PIPE).communicate()[0].strip()
30 domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
31 stdout=subprocess.PIPE).communicate()[0]
32 domsid = domsid.split(' ')[0]
37 sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1' ]
39 flush_cache(sids=sids)
41 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
42 stdout=subprocess.PIPE).communicate()[0].strip()
48 for line in sids2xids.split('\n'):
49 result = line.split(' ')[2:]
50 idtypes.append(result[0])
54 if result[0] == 'gid':
56 elif result[0] == 'uid':
58 elif result[0] == 'uid/gid':
70 # Check the list produced by the sids-to-xids call with the
71 # singular variant (sid-to-xid) for each sid in turn.
72 def check_singular(sids, ids, idtype='gid'):
78 outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
79 stdout=subprocess.PIPE).communicate()[0].strip()
81 print "Expected %s, got %s\n" % (outid, ids[i])
82 flush_cache(sids=sids, uids=uids, gids=gids)
86 # Check the list produced by the sids-to-xids call with the
87 # multiple variant (sid-to-xid) for each sid in turn.
88 def check_multiple(sids, idtypes):
89 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
90 stdout=subprocess.PIPE).communicate()[0].strip()
93 for line in sids2xids.split('\n'):
94 result = line.split(' ')[2:]
96 if result[0] != idtypes[i]:
97 print "Expected %s, got %s\n" % (idtypes[i], result[0])
98 flush_cache(sids=sids, uids=uids, gids=gids)
102 # first round: with filled cache via sid-to-id
103 check_singular(sids, gids, 'gid')
104 check_singular(sids, uids, 'uid')
106 # second round: with empty cache
107 flush_cache(sids=sids, gids=gids)
108 check_singular(sids, gids, 'gid')
109 flush_cache(sids=sids, uids=uids)
110 check_singular(sids, uids, 'uid')
112 # third round: with filled cache via uid-to-sid
113 flush_cache(sids=uids, uids=uids)
114 fill_cache(uids, 'uid')
115 check_multiple(sids, idtypes)
117 # fourth round: with filled cache via gid-to-sid
118 flush_cache(sids=sids, gids=gids)
119 fill_cache(gids, 'gid')
120 check_multiple(sids, idtypes)
122 # flush the cache so any incorrect mappings don't break other tests
123 flush_cache(sids=sids, uids=uids, gids=gids)