dsdb: Honour @SAMBA_FEATURES_SUPPORTED flag in @IDXATTR
[sfrench/samba-autobuild/.git] / source4 / scripting / devel / crackname
1 #!/usr/bin/env python
2
3 # Copyright Matthieu Patou <mat@matws.net> 2011
4 # script to call a DRSUAPI crackname
5 # this is useful for plugfest testing and replication debug
6
7 import sys
8 from optparse import OptionParser
9
10 sys.path.insert(0, "bin/python")
11
12 import samba.getopt as options
13 from samba.dcerpc import drsuapi, misc
14
15 def do_DsBind(drs):
16     '''make a DsBind call, returning the binding handle'''
17     bind_info = drsuapi.DsBindInfoCtr()
18     bind_info.length = 28
19     bind_info.info = drsuapi.DsBindInfo28()
20     bind_info.info.supported_extensions = 0
21     (info, handle) = drs.DsBind(misc.GUID(drsuapi.DRSUAPI_DS_BIND_GUID), bind_info)
22     return handle
23
24
25 ########### main code ###########
26 if __name__ == "__main__":
27     parser = OptionParser("crackname server [options]")
28     sambaopts = options.SambaOptions(parser)
29     parser.add_option_group(sambaopts)
30     credopts = options.CredentialsOptionsDouble(parser)
31     parser.add_option_group(credopts)
32
33     parser.add_option("", "--name", type='str',
34                       default='{ED9F5546-9729-4B04-9385-3FCFE2B17BA1}', help="name to crack")
35     parser.add_option("", "--outformat", type='int',
36                       default=drsuapi.DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
37                       help='format desired')
38     parser.add_option("", "--informat", type='int',
39                       default=drsuapi.DRSUAPI_DS_NAME_FORMAT_GUID,
40                       help='format offered')
41
42     (opts, args) = parser.parse_args()
43
44     lp = sambaopts.get_loadparm()
45     creds = credopts.get_credentials(lp)
46
47     if len(args) != 1:
48         parser.error("You must supply a server")
49
50     if creds.is_anonymous():
51         parser.error("You must supply credentials")
52
53     server = args[0]
54
55     binding_str = "ncacn_ip_tcp:%s[seal,print]" % server
56
57     drs = drsuapi.drsuapi(binding_str, lp, creds)
58     drs_handle = do_DsBind(drs)
59     print "DRS Handle: %s" % drs_handle
60
61     req = drsuapi.DsNameRequest1()
62     names = drsuapi.DsNameString()
63     names.str = opts.name
64
65     req.codepage = 1252
66     req.language = 1033
67     req.format_flags = 0
68     req.format_offered = opts.informat
69     req.format_desired = opts.outformat
70     req.count = 1
71     req.names = [names]
72
73     (result, ctr) = drs.DsCrackNames(drs_handle, 1, req)
74     print "# of result = %d" %ctr.count
75     if ctr.count:
76         print "status = %d" % ctr.array[0].status
77         print "result name = %s" % ctr.array[0].result_name
78         print "domain = %s" % ctr.array[0].dns_domain_name