summaryrefslogtreecommitdiff
path: root/source4/scripting/python/examples
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-09-26 09:50:41 +1000
committerAndrew Tridgell <tridge@samba.org>2011-10-04 15:08:56 +1100
commit7d18241faaadb5a9682f5e28b3b18e656cfae056 (patch)
treeaef2493b9b02beb0a74ea62f56f585cf6fb22d23 /source4/scripting/python/examples
parent57e30bc0cba85e5361ae62f679f7de544d0676e6 (diff)
downloadsamba-7d18241faaadb5a9682f5e28b3b18e656cfae056.tar.gz
samba-7d18241faaadb5a9682f5e28b3b18e656cfae056.tar.bz2
samba-7d18241faaadb5a9682f5e28b3b18e656cfae056.zip
dns: added example python script for dnsserver protocol
Diffstat (limited to 'source4/scripting/python/examples')
-rwxr-xr-xsource4/scripting/python/examples/dnsserver.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/source4/scripting/python/examples/dnsserver.py b/source4/scripting/python/examples/dnsserver.py
new file mode 100755
index 0000000000..c65b1c4099
--- /dev/null
+++ b/source4/scripting/python/examples/dnsserver.py
@@ -0,0 +1,89 @@
+#!/usr/bin/env python
+
+# script to test the dnsserver RPC protocol
+
+import sys
+from optparse import OptionParser
+
+sys.path.insert(0, "bin/python")
+
+import samba
+import samba.getopt as options
+from samba.dcerpc import dnsserver, security, dnsp
+
+
+########### main code ###########
+if __name__ == "__main__":
+ parser = OptionParser("dnsserver [options] server")
+ sambaopts = options.SambaOptions(parser)
+ credopts = options.CredentialsOptionsDouble(parser)
+ parser.add_option_group(credopts)
+
+ (opts, args) = parser.parse_args()
+
+ if len(args) < 3:
+ print("Usage: dnsserver.py [options] DNSSERVER DNSZONE NEWNAME")
+ sys.exit(1)
+
+ server = args[0]
+ dnszone = args[1]
+ newname = args[2]
+
+ lp = sambaopts.get_loadparm()
+ creds = credopts.get_credentials(lp)
+
+ if not creds.authentication_requested():
+ parser.error("You must supply credentials")
+
+ binding_str = "ncacn_ip_tcp:%s[print,sign]" % server
+
+ dns_conn = dnsserver.dnsserver(binding_str, lp, creds)
+
+ print("querying a NS record")
+ res = dns_conn.DnssrvEnumRecords2(0x00070000,
+ 0,
+ server,
+ dnszone,
+ newname,
+ None,
+ dnsp.DNS_TYPE_NS,
+ 0x0f,
+ None,
+ None)
+
+ print("adding a NS glue record")
+ name = dnsserver.DNS_RPC_NAME()
+ name.str = newname
+
+ addrec = dnsserver.DNS_RPC_RECORD()
+ addrec.wType = dnsp.DNS_TYPE_NS
+ addrec.dwFlags = 0
+ addrec.dwSerial = 0
+ addrec.dwTtlSeconds = 3600
+ addrec.dwTimeStamp = 0
+ addrec.dwReserved = 0
+ addrec.data = name
+
+ addrecbuf = dnsserver.DNS_RPC_RECORD_BUF()
+ addrecbuf.rec = addrec
+
+ res = dns_conn.DnssrvUpdateRecord2(0x00070000,
+ 0,
+ server,
+ dnszone,
+ newname,
+ addrecbuf,
+ None)
+
+
+ print("querying the NS record")
+ res = dns_conn.DnssrvEnumRecords2(0x00070000,
+ 0,
+ server,
+ dnszone,
+ newname,
+ None,
+ dnsp.DNS_TYPE_NS,
+ 0x0f,
+ None,
+ None)