This allows lookups to be confined to one partition, which in turn avoids issues
when running this against MS Windows, which does not match Samba behaviour
for dns_common_zones()
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
res = self.search(base="", scope=ldb.SCOPE_BASE, attrs=["serverName"])
return res[0]["serverName"][0]
- def dns_lookup(self, dns_name):
+ def dns_lookup(self, dns_name, dns_partition=None):
'''Do a DNS lookup in the database, returns the NDR database structures'''
- return dsdb_dns.lookup(self, dns_name)
+ if dns_partition is None:
+ return dsdb_dns.lookup(self, dns_name)
+ else:
+ return dsdb_dns.lookup(self, dns_name,
+ dns_partition=dns_partition)
def dns_extract(self, el):
'''Return the NDR database structures from a dnsRecord element'''
struct dns_server_zone *new_list = NULL;
struct dns_server_zone *old_list = NULL;
struct dns_server_zone *old_zone;
- status = dns_common_zones(dns->samdb, dns, &new_list);
+ status = dns_common_zones(dns->samdb, dns, NULL, &new_list);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
NTSTATUS dns_common_zones(struct ldb_context *samdb,
TALLOC_CTX *mem_ctx,
+ struct ldb_dn *base_dn,
struct dns_server_zone **zones_ret)
{
int ret;
struct dns_server_zone *new_list = NULL;
TALLOC_CTX *frame = talloc_stackframe();
- /* TODO: this search does not work against windows */
- ret = dsdb_search(samdb, frame, &res, NULL, LDB_SCOPE_SUBTREE,
- attrs, DSDB_SEARCH_SEARCH_ALL_PARTITIONS, "(objectClass=dnsZone)");
+ if (base_dn) {
+ /* This search will work against windows */
+ ret = dsdb_search(samdb, frame, &res,
+ base_dn, LDB_SCOPE_SUBTREE,
+ attrs, 0, "(objectClass=dnsZone)");
+ } else {
+ /* TODO: this search does not work against windows */
+ ret = dsdb_search(samdb, frame, &res, NULL,
+ LDB_SCOPE_SUBTREE,
+ attrs,
+ DSDB_SEARCH_SEARCH_ALL_PARTITIONS,
+ "(objectClass=dnsZone)");
+ }
if (ret != LDB_SUCCESS) {
TALLOC_FREE(frame);
return NT_STATUS_INTERNAL_DB_CORRUPTION;
TALLOC_CTX *mem_ctx,
const char *name,
struct ldb_dn **_dn);
+
+/*
+ * For this routine, base_dn is generally NULL. The exception comes
+ * from the python bindings to support setting ACLs on DNS objects
+ * when joining Windows
+ */
NTSTATUS dns_common_zones(struct ldb_context *samdb,
TALLOC_CTX *mem_ctx,
+ struct ldb_dn *base_dn,
struct dns_server_zone **zones_ret);
#endif /* __DNSSERVER_COMMON_H__ */
return 0;
}
-static PyObject *py_dsdb_dns_lookup(PyObject *self, PyObject *args)
+static PyObject *py_dsdb_dns_lookup(PyObject *self,
+ PyObject *args, PyObject *kwargs)
{
struct ldb_context *samdb;
PyObject *py_ldb, *ret, *pydn;
+ PyObject *py_dns_partition = NULL;
char *dns_name;
TALLOC_CTX *frame;
NTSTATUS status;
WERROR werr;
struct dns_server_zone *zones_list;
- struct ldb_dn *dn;
+ struct ldb_dn *dn, *dns_partition = NULL;
struct dnsp_DnssrvRpcRecord *records;
uint16_t num_records;
+ const char * const kwnames[] = { "ldb", "dns_name",
+ "dns_partition", NULL };
- if (!PyArg_ParseTuple(args, "Os", &py_ldb, &dns_name)) {
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|O",
+ discard_const_p(char *, kwnames),
+ &py_ldb, &dns_name,
+ &py_dns_partition)) {
return NULL;
}
PyErr_LDB_OR_RAISE(py_ldb, samdb);
+ if (py_dns_partition) {
+ PyErr_LDB_DN_OR_RAISE(py_dns_partition,
+ dns_partition);
+ }
+
frame = talloc_stackframe();
- status = dns_common_zones(samdb, frame, &zones_list);
+ status = dns_common_zones(samdb, frame, dns_partition,
+ &zones_list);
if (!NT_STATUS_IS_OK(status)) {
talloc_free(frame);
PyErr_SetNTSTATUS(status);
frame = talloc_stackframe();
- status = dns_common_zones(samdb, frame, &zones_list);
+ status = dns_common_zones(samdb, frame, NULL, &zones_list);
if (!NT_STATUS_IS_OK(status)) {
PyErr_SetNTSTATUS(status);
talloc_free(frame);
static PyMethodDef py_dsdb_dns_methods[] = {
{ "lookup", (PyCFunction)py_dsdb_dns_lookup,
- METH_VARARGS, "Get the DNS database entries for a DNS name"},
+ METH_VARARGS|METH_KEYWORDS,
+ "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"},
{ "replace_by_dn", (PyCFunction)py_dsdb_dns_replace_by_dn,