3 import sys,os,subprocess
7 print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
14 os.system(netcmd + " cache flush")
16 def fill_cache(inids, idtype='gid'):
20 subprocess.Popen([wbinfo, '--%s-to-sid=%s' % (idtype, inid)],
21 stdout=subprocess.PIPE).communicate()
23 domain = subprocess.Popen([wbinfo, "--own-domain"],
24 stdout=subprocess.PIPE).communicate()[0].strip()
25 domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
26 stdout=subprocess.PIPE).communicate()[0]
27 domsid = domsid.split(' ')[0]
32 sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513' ]
36 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
37 stdout=subprocess.PIPE).communicate()[0].strip()
43 for line in sids2xids.split('\n'):
44 result = line.split(' ')[2:]
45 idtypes.append(result[0])
49 if result[0] == 'gid':
51 elif result[0] == 'uid':
53 elif result[0] == 'uid/gid':
65 # Check the list produced by the sids-to-xids call with the
66 # singular variant (sid-to-xid) for each sid in turn.
67 def check_singular(sids, ids, idtype='gid'):
73 outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
74 stdout=subprocess.PIPE).communicate()[0].strip()
76 print "Expected %s, got %s\n" % (outid, ids[i])
81 # Check the list produced by the sids-to-xids call with the
82 # multiple variant (sid-to-xid) for each sid in turn.
83 def check_multiple(sids, idtypes):
84 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
85 stdout=subprocess.PIPE).communicate()[0].strip()
88 for line in sids2xids.split('\n'):
89 result = line.split(' ')[2:]
91 if result[0] != idtypes[i]:
92 print "Expected %s, got %s\n" % (idtypes[i], result[0])
97 # first round: with filled cache via sid-to-id
98 check_singular(sids, gids, 'gid')
99 check_singular(sids, uids, 'uid')
101 # second round: with empty cache
103 check_singular(sids, gids, 'gid')
105 check_singular(sids, uids, 'uid')
107 # third round: with filled cache via uid-to-sid
109 fill_cache(uids, 'uid')
110 check_multiple(sids, idtypes)
112 # fourth round: with filled cache via gid-to-sid
114 fill_cache(gids, 'gid')
115 check_multiple(sids, idtypes)
117 # flush the cache so any incorrect mappings don't break other tests