3 from __future__ import print_function
4 import sys, os, subprocess
8 print("Usage: test_wbinfo_sids2xids_int.py wbinfo net")
14 def flush_cache(sids=[], uids=[], gids=[]):
16 os.system(netcmd + (" cache del IDMAP/SID2XID/%s" % (sid)))
18 os.system(netcmd + (" cache del IDMAP/UID2SID/%s" % (uid)))
20 os.system(netcmd + (" cache del IDMAP/GID2SID/%s" % (gid)))
22 def fill_cache(inids, idtype='gid'):
26 subprocess.Popen([wbinfo, '--%s-to-sid=%s' % (idtype, inid)],
27 stdout=subprocess.PIPE).communicate()
29 domain = subprocess.Popen([wbinfo, "--own-domain"],
30 stdout=subprocess.PIPE).communicate()[0].strip()
31 domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
32 stdout=subprocess.PIPE).communicate()[0]
33 domsid = domsid.split(' ')[0]
38 sids = [domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1']
40 flush_cache(sids=sids)
42 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
43 stdout=subprocess.PIPE).communicate()[0].strip()
49 for line in sids2xids.split('\n'):
50 result = line.split(' ')[2:]
51 idtypes.append(result[0])
55 if result[0] == 'gid':
57 elif result[0] == 'uid':
59 elif result[0] == 'uid/gid':
71 # Check the list produced by the sids-to-xids call with the
72 # singular variant (sid-to-xid) for each sid in turn.
73 def check_singular(sids, ids, idtype='gid'):
79 outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
80 stdout=subprocess.PIPE).communicate()[0].strip()
82 print("Expected %s, got %s\n" % (outid, ids[i]))
83 flush_cache(sids=sids, uids=uids, gids=gids)
87 # Check the list produced by the sids-to-xids call with the
88 # multiple variant (sid-to-xid) for each sid in turn.
89 def check_multiple(sids, idtypes):
90 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
91 stdout=subprocess.PIPE).communicate()[0].strip()
94 for line in sids2xids.split('\n'):
95 result = line.split(' ')[2:]
97 if result[0] != idtypes[i]:
98 print("Expected %s, got %s\n" % (idtypes[i], result[0]))
99 flush_cache(sids=sids, uids=uids, gids=gids)
103 # first round: with filled cache via sid-to-id
104 check_singular(sids, gids, 'gid')
105 check_singular(sids, uids, 'uid')
107 # second round: with empty cache
108 flush_cache(sids=sids, gids=gids)
109 check_singular(sids, gids, 'gid')
110 flush_cache(sids=sids, uids=uids)
111 check_singular(sids, uids, 'uid')
113 # third round: with filled cache via uid-to-sid
114 flush_cache(sids=uids, uids=uids)
115 fill_cache(uids, 'uid')
116 check_multiple(sids, idtypes)
118 # fourth round: with filled cache via gid-to-sid
119 flush_cache(sids=sids, gids=gids)
120 fill_cache(gids, 'gid')
121 check_multiple(sids, idtypes)
123 # flush the cache so any incorrect mappings don't break other tests
124 flush_cache(sids=sids, uids=uids, gids=gids)