3 from __future__ import print_function
4 import sys, os, subprocess
8 print("Usage: test_wbinfo_sids2xids_int.py wbinfo net")
15 def flush_cache(sids=[], uids=[], gids=[]):
17 os.system(netcmd + (" cache del IDMAP/SID2XID/%s" % (sid)))
19 os.system(netcmd + (" cache del IDMAP/UID2SID/%s" % (uid)))
21 os.system(netcmd + (" cache del IDMAP/GID2SID/%s" % (gid)))
24 def fill_cache(inids, idtype='gid'):
28 subprocess.Popen([wbinfo, '--%s-to-sid=%s' % (idtype, inid)],
29 stdout=subprocess.PIPE).communicate()
32 domain = subprocess.Popen([wbinfo, "--own-domain"],
33 stdout=subprocess.PIPE).communicate()[0].strip()
34 domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
35 stdout=subprocess.PIPE).communicate()[0]
36 domsid = domsid.split(' ')[0]
41 sids = [domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1']
43 flush_cache(sids=sids)
45 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
46 stdout=subprocess.PIPE).communicate()[0].strip()
52 for line in sids2xids.split('\n'):
53 result = line.split(' ')[2:]
54 idtypes.append(result[0])
58 if result[0] == 'gid':
60 elif result[0] == 'uid':
62 elif result[0] == 'uid/gid':
74 # Check the list produced by the sids-to-xids call with the
75 # singular variant (sid-to-xid) for each sid in turn.
78 def check_singular(sids, ids, idtype='gid'):
84 outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
85 stdout=subprocess.PIPE).communicate()[0].strip()
87 print("Expected %s, got %s\n" % (outid, ids[i]))
88 flush_cache(sids=sids, uids=uids, gids=gids)
92 # Check the list produced by the sids-to-xids call with the
93 # multiple variant (sid-to-xid) for each sid in turn.
96 def check_multiple(sids, idtypes):
97 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
98 stdout=subprocess.PIPE).communicate()[0].strip()
101 for line in sids2xids.split('\n'):
102 result = line.split(' ')[2:]
104 if result[0] != idtypes[i]:
105 print("Expected %s, got %s\n" % (idtypes[i], result[0]))
106 flush_cache(sids=sids, uids=uids, gids=gids)
111 # first round: with filled cache via sid-to-id
112 check_singular(sids, gids, 'gid')
113 check_singular(sids, uids, 'uid')
115 # second round: with empty cache
116 flush_cache(sids=sids, gids=gids)
117 check_singular(sids, gids, 'gid')
118 flush_cache(sids=sids, uids=uids)
119 check_singular(sids, uids, 'uid')
121 # third round: with filled cache via uid-to-sid
122 flush_cache(sids=uids, uids=uids)
123 fill_cache(uids, 'uid')
124 check_multiple(sids, idtypes)
126 # fourth round: with filled cache via gid-to-sid
127 flush_cache(sids=sids, gids=gids)
128 fill_cache(gids, 'gid')
129 check_multiple(sids, idtypes)
131 # flush the cache so any incorrect mappings don't break other tests
132 flush_cache(sids=sids, uids=uids, gids=gids)