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()
31 domain = subprocess.Popen([wbinfo, "--own-domain"],
32 stdout=subprocess.PIPE).communicate()[0].strip()
33 domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
34 stdout=subprocess.PIPE).communicate()[0]
35 domsid = domsid.split(' ')[0]
40 sids = [domsid + '-512', 'S-1-5-32-545', domsid + '-513', 'S-1-1-0', 'S-1-3-1', 'S-1-5-1']
42 flush_cache(sids=sids)
44 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
45 stdout=subprocess.PIPE).communicate()[0].strip()
51 for line in sids2xids.split('\n'):
52 result = line.split(' ')[2:]
53 idtypes.append(result[0])
57 if result[0] == 'gid':
59 elif result[0] == 'uid':
61 elif result[0] == 'uid/gid':
73 # Check the list produced by the sids-to-xids call with the
74 # singular variant (sid-to-xid) for each sid in turn.
77 def check_singular(sids, ids, idtype='gid'):
83 outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
84 stdout=subprocess.PIPE).communicate()[0].strip()
86 print("Expected %s, got %s\n" % (outid, ids[i]))
87 flush_cache(sids=sids, uids=uids, gids=gids)
91 # Check the list produced by the sids-to-xids call with the
92 # multiple variant (sid-to-xid) for each sid in turn.
95 def check_multiple(sids, idtypes):
96 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
97 stdout=subprocess.PIPE).communicate()[0].strip()
100 for line in sids2xids.split('\n'):
101 result = line.split(' ')[2:]
103 if result[0] != idtypes[i]:
104 print("Expected %s, got %s\n" % (idtypes[i], result[0]))
105 flush_cache(sids=sids, uids=uids, gids=gids)
109 # first round: with filled cache via sid-to-id
110 check_singular(sids, gids, 'gid')
111 check_singular(sids, uids, 'uid')
113 # second round: with empty cache
114 flush_cache(sids=sids, gids=gids)
115 check_singular(sids, gids, 'gid')
116 flush_cache(sids=sids, uids=uids)
117 check_singular(sids, uids, 'uid')
119 # third round: with filled cache via uid-to-sid
120 flush_cache(sids=uids, uids=uids)
121 fill_cache(uids, 'uid')
122 check_multiple(sids, idtypes)
124 # fourth round: with filled cache via gid-to-sid
125 flush_cache(sids=sids, gids=gids)
126 fill_cache(gids, 'gid')
127 check_multiple(sids, idtypes)
129 # flush the cache so any incorrect mappings don't break other tests
130 flush_cache(sids=sids, uids=uids, gids=gids)