dns_server: Add python method to extract a DNS entry from a ldb.MessageElement
authorAndrew Bartlett <abartlet@samba.org>
Tue, 22 Sep 2015 03:32:57 +0000 (15:32 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Mon, 26 Oct 2015 04:11:21 +0000 (05:11 +0100)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
python/samba/samdb.py
source4/dns_server/pydns.c

index 7081e3da6e1d68961e84ddc66e19607a31799522..94f81f8162875cfdb4ed27209c0bea9af98e6633 100644 (file)
@@ -926,6 +926,10 @@ accountExpires: %u
         '''Do a DNS lookup in the database, returns the NDR database structures'''
         return dsdb_dns.lookup(self, dns_name)
 
+    def dns_extract(self, el):
+        '''Return the NDR database structures from a dnsRecord element'''
+        return dsdb_dns.extract(el)
+
     def dns_replace(self, dns_name, new_records):
         '''Do a DNS modification on the database, sets the NDR database structures'''
         return dsdb_dns.replace(self, dns_name, new_records)
index 1fad6922ed01e1d3aaa20e1c6c6ef1923ca2cf80..2f631bdcd1c5201844c02e42b43245af01c2b2e2 100644 (file)
@@ -141,6 +141,40 @@ static PyObject *py_dsdb_dns_lookup(PyObject *self, PyObject *args)
        return py_dnsp_DnssrvRpcRecord_get_list(records, num_records);
 }
 
+static PyObject *py_dsdb_dns_extract(PyObject *self, PyObject *args)
+{
+       PyObject *py_dns_el;
+       TALLOC_CTX *frame;
+       WERROR werr;
+       struct ldb_message_element *dns_el;
+       struct dnsp_DnssrvRpcRecord *records;
+       uint16_t num_records;
+
+       if (!PyArg_ParseTuple(args, "O", &py_dns_el)) {
+               return NULL;
+       }
+
+       if (!py_check_dcerpc_type(py_dns_el, "ldb", "MessageElement")) {
+               PyErr_SetString(py_ldb_get_exception(),
+                               "ldb MessageElement object required");
+               return NULL;
+       }
+       dns_el = pyldb_MessageElement_AsMessageElement(py_dns_el);
+
+       frame = talloc_stackframe();
+
+       werr = dns_common_extract(dns_el,
+                                 frame,
+                                 &records,
+                                 &num_records);
+       if (!W_ERROR_IS_OK(werr)) {
+               PyErr_SetWERROR(werr);
+               return NULL;
+       }
+
+       return py_dnsp_DnssrvRpcRecord_get_list(records, num_records);
+}
+
 static PyObject *py_dsdb_dns_replace(PyObject *self, PyObject *args)
 {
        struct ldb_context *samdb;
@@ -209,6 +243,8 @@ static PyMethodDef py_dsdb_dns_methods[] = {
                METH_VARARGS, "Get the DNS database entries for a DNS name"},
        { "replace", (PyCFunction)py_dsdb_dns_replace,
                METH_VARARGS, "Replace the DNS database entries for a DNS name"},
+       { "extract", (PyCFunction)py_dsdb_dns_extract,
+               METH_VARARGS, "Return the DNS database entry as a python structure from an Ldb.MessageElement of type dnsRecord"},
        { NULL }
 };