[SCM] Samba Shared Repository - branch master updated

Andrew Tridgell tridge at samba.org
Sun Sep 19 12:30:26 MDT 2010


The branch, master has been updated
       via  f6fa73b s4-rodc: added RODC DNS update support to samba_dnsupdate
       via  50f56c6 s4-finddcs: added some debug messages on failure
       via  e72a1e2 s4-pydsdb: added am_rodc() method on samdb
       via  2666cc9 s4-pydsdb: don't force am_rodc unless it is set by caller
      from  7a59c90 pytdb: Make filename argument optional.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f6fa73bbd38100529ae5b1a3133e78148e0f7268
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Sep 18 20:57:26 2010 -0700

    s4-rodc: added RODC DNS update support to samba_dnsupdate
    
    for DNS updates that have a netlogon equivalent, send via netlogon

commit 50f56c6a82e7bd3742730a50b7d7c614482b9fec
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Sep 18 20:22:44 2010 -0700

    s4-finddcs: added some debug messages on failure

commit e72a1e20557f212af03d32152f0cc11acee57814
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Sep 18 20:22:23 2010 -0700

    s4-pydsdb: added am_rodc() method on samdb

commit 2666cc9c161d4a0f5083f546dbcf470d34b24499
Author: Andrew Tridgell <tridge at samba.org>
Date:   Sat Sep 18 19:28:05 2010 -0700

    s4-pydsdb: don't force am_rodc unless it is set by caller
    
    we should normally get the rodc flag by looking at the database, not
    by forcing it in the database connect

-----------------------------------------------------------------------

Summary of changes:
 source4/dsdb/pydsdb.c                   |   27 +++++++++++
 source4/libcli/finddcs_cldap.c          |   11 +++--
 source4/scripting/bin/samba_dnsupdate   |   73 +++++++++++++++++++++++++++++-
 source4/scripting/python/samba/samdb.py |    8 +++-
 4 files changed, 110 insertions(+), 9 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/dsdb/pydsdb.c b/source4/dsdb/pydsdb.c
index 5ba69d7..7f2e715 100644
--- a/source4/dsdb/pydsdb.c
+++ b/source4/dsdb/pydsdb.c
@@ -534,6 +534,30 @@ static PyObject *py_dsdb_get_partitions_dn(PyObject *self, PyObject *args)
 }
 
 
+/*
+  call into samdb_rodc()
+ */
+static PyObject *py_dsdb_am_rodc(PyObject *self, PyObject *args)
+{
+	PyObject *py_ldb;
+	struct ldb_context *ldb;
+	int ret;
+	bool am_rodc;
+
+	if (!PyArg_ParseTuple(args, "O", &py_ldb))
+		return NULL;
+
+	PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+	ret = samdb_rodc(ldb, &am_rodc);
+	if (samdb_rodc(ldb, &am_rodc) != LDB_SUCCESS) {
+		PyErr_SetString(PyExc_RuntimeError, ldb_errstring(ldb));
+		return NULL;
+	}
+
+	return PyBool_FromLong(am_rodc);
+}
+
 
 static PyMethodDef py_dsdb_methods[] = {
 	{ "_samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
@@ -573,6 +597,9 @@ static PyMethodDef py_dsdb_methods[] = {
 	{ "_dsdb_set_am_rodc",
 		(PyCFunction)py_dsdb_set_am_rodc, METH_VARARGS,
 		NULL },
+	{ "_am_rodc",
+		(PyCFunction)py_dsdb_am_rodc, METH_VARARGS,
+		NULL },
 	{ "_dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
 		NULL },
 	{ "_dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
diff --git a/source4/libcli/finddcs_cldap.c b/source4/libcli/finddcs_cldap.c
index 33e31a9..b8cc5cb 100644
--- a/source4/libcli/finddcs_cldap.c
+++ b/source4/libcli/finddcs_cldap.c
@@ -36,6 +36,7 @@ struct finddcs_cldap_state {
 	struct tevent_req *req;
 	const char *domain_name;
 	struct dom_sid *domain_sid;
+	const char *srv_name;
 	const char **srv_addresses;
 	uint32_t minimum_dc_flags;
 	uint32_t srv_address_index;
@@ -112,18 +113,17 @@ static bool finddcs_cldap_srv_lookup(struct finddcs_cldap_state *state,
 				     struct resolve_context *resolve_ctx,
 				     struct tevent_context *event_ctx)
 {
-	const char *srv_name;
 	struct composite_context *creq;
 	struct nbt_name name;
 
 	if (io->in.site_name) {
-		srv_name = talloc_asprintf(state, "_ldap._tcp.%s._sites.%s",
+		state->srv_name = talloc_asprintf(state, "_ldap._tcp.%s._sites.%s",
 					   io->in.site_name, io->in.domain_name);
 	} else {
-		srv_name = talloc_asprintf(state, "_ldap._tcp.%s", io->in.domain_name);
+		state->srv_name = talloc_asprintf(state, "_ldap._tcp.%s", io->in.domain_name);
 	}
 
-	make_nbt_name(&name, srv_name, 0);
+	make_nbt_name(&name, state->srv_name, 0);
 
 	creq = resolve_name_ex_send(resolve_ctx, state,
 				    RESOLVE_NAME_FLAG_FORCE_DNS | RESOLVE_NAME_FLAG_DNS_SRV,
@@ -167,6 +167,7 @@ static void finddcs_cldap_next_server(struct finddcs_cldap_state *state)
 
 	if (state->srv_addresses[state->srv_address_index] == NULL) {
 		tevent_req_nterror(state->req, NT_STATUS_OBJECT_NAME_NOT_FOUND);
+		DEBUG(2,("No matching CLDAP server found\n"));
 		return;
 	}
 
@@ -247,6 +248,7 @@ static void finddcs_cldap_name_resolved(struct composite_context *ctx)
 
 	status = resolve_name_recv(ctx, state, &address);
 	if (tevent_req_nterror(state->req, status)) {
+		DEBUG(2,("No matching NBT <1c> server found\n"));
 		return;
 	}
 
@@ -279,6 +281,7 @@ static void finddcs_cldap_srv_resolved(struct composite_context *ctx)
 
 	status = resolve_name_multiple_recv(ctx, state, &state->srv_addresses);
 	if (tevent_req_nterror(state->req, status)) {
+		DEBUG(2,("Failed to find SRV record for %s\n", state->srv_name));
 		return;
 	}
 
diff --git a/source4/scripting/bin/samba_dnsupdate b/source4/scripting/bin/samba_dnsupdate
index b295224..4dafe79 100755
--- a/source4/scripting/bin/samba_dnsupdate
+++ b/source4/scripting/bin/samba_dnsupdate
@@ -36,11 +36,13 @@ from samba import getopt as options
 from ldb import SCOPE_BASE
 from samba.auth import system_session
 from samba.samdb import SamDB
+from samba.dcerpc import netlogon, winbind
 
 samba.ensure_external_module("dns", "dnspython")
 import dns.resolver as resolver
 
 default_ttl = 900
+am_rodc = False
 
 parser = optparse.OptionParser("samba_dnsupdate")
 sambaopts = options.SambaOptions(parser)
@@ -75,7 +77,8 @@ if len(IPs) == 0:
     print "No IP interfaces - skipping DNS updates"
     sys.exit(0)
 
-
+if opts.verbose:
+    print "IPs: %s" % IPs
 
 ########################################################
 # get credentials if we haven't got them already
@@ -189,19 +192,22 @@ def check_dns_name(d):
 ###########################################
 # get the list of substitution vars
 def get_subst_vars():
-    global lp
+    global lp, am_rodc
     vars = {}
 
     samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
                   lp=lp)
 
     vars['DNSDOMAIN'] = lp.get('realm').lower()
+    vars['DNSFOREST'] = lp.get('realm').lower()
     vars['HOSTNAME']  = lp.get('netbios name').lower() + "." + vars['DNSDOMAIN']
     vars['NTDSGUID']  = samdb.get_ntds_GUID()
     vars['SITE']      = samdb.server_site_name()
     res = samdb.search(base=None, scope=SCOPE_BASE, attrs=["objectGUID"])
     guid = samdb.schema_format_value("objectGUID", res[0]['objectGUID'][0])
     vars['DOMAINGUID'] = guid
+    am_rodc = samdb.am_rodc()
+
     return vars
 
 
@@ -241,6 +247,64 @@ def call_nsupdate(d):
     os.unlink(tmpfile)
 
 
+
+def rodc_dns_update(d, t):
+    '''a single DNS update via the RODC netlogon call'''
+    global sub_vars
+
+    if opts.verbose:
+        print "Calling netlogon RODC update for %s" % d
+
+    w = winbind.winbind("irpc:winbind_server", lp)
+    dns_names = netlogon.NL_DNS_NAME_INFO_ARRAY()
+    dns_names.count = 1
+    name = netlogon.NL_DNS_NAME_INFO()
+    name.type = t
+    name.priority = 0
+    name.weight   = 0
+    if d.port is not None:
+        name.port = int(d.port)
+    name.dns_register = True
+    dns_names.names = [ name ]
+    site_name = sub_vars['SITE'].decode('utf-8')
+
+    try:
+        ret_names = w.DsrUpdateReadOnlyServerDnsRecords(site_name, default_ttl, dns_names)
+        if ret_names.names[0].status != 0:
+            print("Failed to set DNS entry: %s (status %u)" % (d, ret_names.names[0].status))
+    except:
+        print("Error setting DNS entry: %s" % d)
+
+
+def call_rodc_update(d):
+    '''RODCs need to use the netlogon API for nsupdate'''
+    global lp, sub_vars
+
+    # we expect failure for 3268 if we aren't a GC
+    if d.port is not None and int(d.port) == 3268:
+        return
+
+    # map the DNS request to a netlogon update type
+    map = {
+        netlogon.NlDnsLdapAtSite :     '_ldap._tcp.${SITE}._sites.${DNSDOMAIN}',
+        netlogon.NlDnsGcAtSite         : '_ldap._tcp.${SITE}._sites.gc._msdcs.${DNSDOMAIN}',
+        netlogon.NlDnsDsaCname         : '${NTDSGUID}._msdcs.${DNSFOREST}',
+        netlogon.NlDnsKdcAtSite        : '_kerberos._tcp.${SITE}._sites.dc._msdcs.${DNSDOMAIN}',
+        netlogon.NlDnsDcAtSite         : '_ldap._tcp.${SITE}._sites.dc._msdcs.${DNSDOMAIN}',
+        netlogon.NlDnsRfc1510KdcAtSite : '_kerberos._tcp.${SITE}._sites.${DNSDOMAIN}',
+        netlogon.NlDnsGenericGcAtSite  : '_gc._tcp.${SITE}._sites.${DNSFOREST}'
+        }
+
+    for t in map:
+        subname = samba.substitute_var(map[t], sub_vars)
+        if subname.lower() == d.name.lower():
+            # found a match - do the update
+            rodc_dns_update(d, t)
+            return
+    if opts.verbose:
+        print("Unable to map to netlogon DNS update: %s" % d)
+
+
 # get the list of DNS entries we should have
 dns_update_list = lp.private_path('dns_update_list')
 
@@ -286,7 +350,10 @@ get_credentials(lp)
 
 # ask nsupdate to add entries as needed
 for d in update_list:
-    call_nsupdate(d)
+    if am_rodc:
+        call_rodc_update(d)
+    else:
+        call_nsupdate(d)
 
 # delete the ccache if we created it
 if ccachename is not None:
diff --git a/source4/scripting/python/samba/samdb.py b/source4/scripting/python/samba/samdb.py
index e2ac37a..bbc52a9 100644
--- a/source4/scripting/python/samba/samdb.py
+++ b/source4/scripting/python/samba/samdb.py
@@ -40,7 +40,7 @@ class SamDB(samba.Ldb):
 
     def __init__(self, url=None, lp=None, modules_dir=None, session_info=None,
                  credentials=None, flags=0, options=None, global_schema=True,
-                 auto_connect=True, am_rodc=False):
+                 auto_connect=True, am_rodc=None):
         self.lp = lp
         if not auto_connect:
             url = None
@@ -54,7 +54,8 @@ class SamDB(samba.Ldb):
         if global_schema:
             dsdb._dsdb_set_global_schema(self)
 
-        dsdb._dsdb_set_am_rodc(self, am_rodc)
+        if am_rodc is not None:
+            dsdb._dsdb_set_am_rodc(self, am_rodc)
 
     def connect(self, url=None, flags=0, options=None):
         if self.lp is not None:
@@ -63,6 +64,9 @@ class SamDB(samba.Ldb):
         super(SamDB, self).connect(url=url, flags=flags,
                 options=options)
 
+    def am_rodc(self):
+        return dsdb._am_rodc(self)
+
     def domain_dn(self):
         # find the DNs for the domain
         res = self.search(base="",


-- 
Samba Shared Repository


More information about the samba-cvs mailing list