s3-libnet: avoid using lp_dns_hostname() in join code
[samba4-gss.git] / source4 / scripting / devel / crackname
blob021adfa05151ea3bf86864171711d385e5943782
1 #!/usr/bin/env python3
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 import sys
7 from optparse import OptionParser
9 sys.path.insert(0, "bin/python")
11 import samba.getopt as options
12 from samba.dcerpc import drsuapi, misc
14 def do_DsBind(drs):
15     '''make a DsBind call, returning the binding handle'''
16     bind_info = drsuapi.DsBindInfoCtr()
17     bind_info.length = 28
18     bind_info.info = drsuapi.DsBindInfo28()
19     bind_info.info.supported_extensions = 0
20     (info, handle) = drs.DsBind(misc.GUID(drsuapi.DRSUAPI_DS_BIND_GUID), bind_info)
21     return handle
24 ########### main code ###########
25 if __name__ == "__main__":
26     parser = OptionParser("crackname server [options]")
27     sambaopts = options.SambaOptions(parser)
28     parser.add_option_group(sambaopts)
29     credopts = options.CredentialsOptionsDouble(parser)
30     parser.add_option_group(credopts)
32     parser.add_option("", "--name", type='str',
33                       default='{ED9F5546-9729-4B04-9385-3FCFE2B17BA1}', help="name to crack")
34     parser.add_option("", "--outformat", type='int',
35                       default=drsuapi.DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
36                       help='format desired')
37     parser.add_option("", "--informat", type='int',
38                       default=drsuapi.DRSUAPI_DS_NAME_FORMAT_GUID,
39                       help='format offered')
41     (opts, args) = parser.parse_args()
43     lp = sambaopts.get_loadparm()
44     creds = credopts.get_credentials(lp)
46     if len(args) != 1:
47         parser.error("You must supply a server")
49     if creds.is_anonymous():
50         parser.error("You must supply credentials")
52     server = args[0]
54     binding_str = "ncacn_ip_tcp:%s[seal,print]" % server
56     drs = drsuapi.drsuapi(binding_str, lp, creds)
57     drs_handle = do_DsBind(drs)
58     print("DRS Handle: %s" % drs_handle)
60     req = drsuapi.DsNameRequest1()
61     names = drsuapi.DsNameString()
62     names.str = opts.name
64     req.codepage = 1252
65     req.language = 1033
66     req.format_flags = 0
67     req.format_offered = opts.informat
68     req.format_desired = opts.outformat
69     req.count = 1
70     req.names = [names]
72     (result, ctr) = drs.DsCrackNames(drs_handle, 1, req)
73     print("# of result = %d" %ctr.count)
74     if ctr.count:
75         print("status = %d" % ctr.array[0].status)
76         print("result name = %s" % ctr.array[0].result_name)
77         print("domain = %s" % ctr.array[0].dns_domain_name)