gpo: Fix crashes in gpo unapply
[metze/samba/wip.git] / python / examples / dnsserver.py
1 #!/usr/bin/env python
2
3 # script to test the dnsserver RPC protocol
4
5 import sys
6 from optparse import OptionParser
7
8 sys.path.insert(0, "bin/python")
9
10 import samba
11 import samba.getopt as options
12 from samba.dcerpc import dnsserver, security, dnsp
13
14
15 ########### main code ###########
16 if __name__ == "__main__":
17     parser = OptionParser("dnsserver [options] server")
18     sambaopts = options.SambaOptions(parser)
19     credopts = options.CredentialsOptionsDouble(parser)
20     parser.add_option_group(credopts)
21
22     (opts, args) = parser.parse_args()
23
24     if len(args) < 3:
25         print("Usage: dnsserver.py [options] DNSSERVER DNSZONE NEWNAME")
26         sys.exit(1)
27
28     server = args[0]
29     dnszone   = args[1]
30     newname   = args[2]
31
32     lp = sambaopts.get_loadparm()
33     creds = credopts.get_credentials(lp)
34
35     if not creds.authentication_requested():
36         parser.error("You must supply credentials")
37
38     binding_str = "ncacn_ip_tcp:%s[print,sign]" % server
39
40     dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
41
42     print("querying a NS record")
43     res = dns_conn.DnssrvEnumRecords2(0x00070000,
44                                       0,
45                                       server,
46                                       dnszone,
47                                       newname,
48                                       None,
49                                       dnsp.DNS_TYPE_NS,
50                                       0x0f,
51                                       None,
52                                       None)
53
54     print("adding a NS glue record")
55     name = dnsserver.DNS_RPC_NAME()
56     name.str = newname
57
58     addrec = dnsserver.DNS_RPC_RECORD()
59     addrec.wType = dnsp.DNS_TYPE_NS
60     addrec.dwFlags = 0
61     addrec.dwSerial = 0
62     addrec.dwTtlSeconds = 3600
63     addrec.dwTimeStamp = 0
64     addrec.dwReserved = 0
65     addrec.data = name
66
67     addrecbuf     = dnsserver.DNS_RPC_RECORD_BUF()
68     addrecbuf.rec = addrec
69
70     res = dns_conn.DnssrvUpdateRecord2(0x00070000,
71                                        0,
72                                        server,
73                                        dnszone,
74                                        newname,
75                                        addrecbuf,
76                                        None)
77
78
79     print("querying the NS record")
80     res = dns_conn.DnssrvEnumRecords2(0x00070000,
81                                       0,
82                                       server,
83                                       dnszone,
84                                       newname,
85                                       None,
86                                       dnsp.DNS_TYPE_NS,
87                                       0x0f,
88                                       None,
89                                       None)