s3:selftest: extend sids2xids test script to cope with "ID_TYPE_BOTH mappings
[vlendec/samba-autobuild/.git] / source3 / script / tests / test_wbinfo_sids2xids_int.py
1 #!/usr/bin/env python
2
3 import sys,os,subprocess
4
5
6 if len(sys.argv) != 3:
7     print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
8     sys.exit(1)
9
10 wbinfo = sys.argv[1]
11 netcmd = sys.argv[2]
12
13 def flush_cache():
14     os.system(netcmd + "cache flush")
15
16 domain = subprocess.Popen([wbinfo, "--own-domain"],
17                           stdout=subprocess.PIPE).communicate()[0].strip()
18 domsid = subprocess.Popen([wbinfo, "-n", domain + "\\"],
19                           stdout=subprocess.PIPE).communicate()[0]
20 domsid = domsid.split(' ')[0]
21
22 #print domain
23 #print domsid
24
25 sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513' ]
26
27 flush_cache
28
29 sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' +  ','.join(sids)],
30                              stdout=subprocess.PIPE).communicate()[0].strip()
31
32 gids=[]
33
34 for line in sids2xids.split('\n'):
35     result = line.split(' ')[2:]
36
37     if result[0] == 'gid' or result[0] == 'uid/gid':
38         gid = result[1]
39     else:
40         gid = ''
41     if gid == '-1':
42         gid = ''
43     gids.append(gid)
44
45 # Check the list produced by the sids-to-xids call with the
46 # singular variant (sid-to-gid) for each sid in turn.
47 def check_singular(sids, gids):
48     i=0
49     for sid in sids:
50         gid = subprocess.Popen([wbinfo, '--sid-to-gid', sid],
51                                stdout=subprocess.PIPE).communicate()[0].strip()
52         if gid != gids[i]:
53             print "Expected %s, got %s\n", gid, gids[i]
54             sys.exit(1)
55         i+=1
56
57 # first round: with filled cache
58 check_singular(sids, gids)
59
60 # second round: with empty cache
61 flush_cache
62 check_singular(sids, gids)
63
64 sys.exit(0)