1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-02 00:22:11 +03:00

s4:libnet/py_net.c: "py_net_finddc" - add an "address" parameter

This is useful for a new "samba-tool domain info" command.

Patch inspired by Matthieu Patou.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
This commit is contained in:
Matthias Dieter Wallnöfer
2011-11-22 22:26:06 +01:00
committed by Stefan Metzmacher
parent dec1435a42
commit 179bf9b51c
4 changed files with 25 additions and 14 deletions

View File

@ -580,23 +580,31 @@ static PyObject *py_net_replicate_chunk(py_net_Object *self, PyObject *args, PyO
/* /*
find a DC given a domain name and server type find a DC given a domain name and server type
*/ */
static PyObject *py_net_finddc(py_net_Object *self, PyObject *args) static PyObject *py_net_finddc(py_net_Object *self, PyObject *args, PyObject *kwargs)
{ {
const char *domain_name; const char *domain = NULL, *address = NULL;
unsigned server_type; unsigned server_type;
NTSTATUS status; NTSTATUS status;
struct finddcs *io; struct finddcs *io;
TALLOC_CTX *mem_ctx; TALLOC_CTX *mem_ctx;
PyObject *ret; PyObject *ret;
const char * const kwnames[] = { "flags", "domain", "address", NULL };
if (!PyArg_ParseTuple(args, "sI", &domain_name, &server_type)) { if (!PyArg_ParseTupleAndKeywords(args, kwargs, "I|ss",
discard_const_p(char *, kwnames),
&server_type, &domain, &address)) {
return NULL; return NULL;
} }
mem_ctx = talloc_new(self->mem_ctx); mem_ctx = talloc_new(self->mem_ctx);
io = talloc_zero(mem_ctx, struct finddcs); io = talloc_zero(mem_ctx, struct finddcs);
io->in.domain_name = domain_name; if (domain != NULL) {
io->in.domain_name = domain;
}
if (address != NULL) {
io->in.server_address = address;
}
io->in.minimum_dc_flags = server_type; io->in.minimum_dc_flags = server_type;
status = finddcs_cldap(io, io, status = finddcs_cldap(io, io,
@ -624,8 +632,8 @@ static const char py_net_replicate_init_doc[] = "replicate_init(samdb, lp, drspi
static const char py_net_replicate_chunk_doc[] = "replicate_chunk(state, level, ctr, schema)\n" static const char py_net_replicate_chunk_doc[] = "replicate_chunk(state, level, ctr, schema)\n"
"Process replication for one chunk"; "Process replication for one chunk";
static const char py_net_finddc_doc[] = "finddc(domain, server_type)\n" static const char py_net_finddc_doc[] = "finddc(flags=server_type, domain=None, address=None)\n"
"find a DC with the specified server_type bits. Return the DNS name"; "Find a DC with the specified 'server_type' bits. The 'domain' and/or 'address' have to be used as additional search criteria. Returns the whole netlogon struct";
static PyMethodDef net_obj_methods[] = { static PyMethodDef net_obj_methods[] = {
{"join_member", (PyCFunction)py_net_join_member, METH_VARARGS|METH_KEYWORDS, py_net_join_member_doc}, {"join_member", (PyCFunction)py_net_join_member, METH_VARARGS|METH_KEYWORDS, py_net_join_member_doc},
@ -638,7 +646,7 @@ static PyMethodDef net_obj_methods[] = {
{"vampire", (PyCFunction)py_net_vampire, METH_VARARGS|METH_KEYWORDS, py_net_vampire_doc}, {"vampire", (PyCFunction)py_net_vampire, METH_VARARGS|METH_KEYWORDS, py_net_vampire_doc},
{"replicate_init", (PyCFunction)py_net_replicate_init, METH_VARARGS|METH_KEYWORDS, py_net_replicate_init_doc}, {"replicate_init", (PyCFunction)py_net_replicate_init, METH_VARARGS|METH_KEYWORDS, py_net_replicate_init_doc},
{"replicate_chunk", (PyCFunction)py_net_replicate_chunk, METH_VARARGS|METH_KEYWORDS, py_net_replicate_chunk_doc}, {"replicate_chunk", (PyCFunction)py_net_replicate_chunk, METH_VARARGS|METH_KEYWORDS, py_net_replicate_chunk_doc},
{"finddc", (PyCFunction)py_net_finddc, METH_VARARGS, py_net_finddc_doc}, {"finddc", (PyCFunction)py_net_finddc, METH_KEYWORDS, py_net_finddc_doc},
{ NULL } { NULL }
}; };

View File

@ -190,7 +190,7 @@ def call_rodc_update(d):
net = Net(creds=creds, lp=lp) net = Net(creds=creds, lp=lp)
try: try:
cldap_ret = net.finddc(domain, nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) cldap_ret = net.finddc(domain=domain, flags=nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
except Exception, reason: except Exception, reason:
print("Unable to find writeable DC for domain '%s' to send DRS writeSPN to : %s" % (domain, reason)) print("Unable to find writeable DC for domain '%s' to send DRS writeSPN to : %s" % (domain, reason))
sys.exit(1) sys.exit(1)

View File

@ -195,7 +195,7 @@ class dc_join(object):
def find_dc(ctx, domain): def find_dc(ctx, domain):
'''find a writeable DC for the given domain''' '''find a writeable DC for the given domain'''
try: try:
ctx.cldap_ret = ctx.net.finddc(domain, nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) ctx.cldap_ret = ctx.net.finddc(domain=domain, flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
except Exception: except Exception:
raise Exception("Failed to find a writeable DC for domain '%s'" % domain) raise Exception("Failed to find a writeable DC for domain '%s'" % domain)
if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "": if ctx.cldap_ret.client_site is not None and ctx.cldap_ret.client_site != "":

View File

@ -52,10 +52,13 @@ def netcmd_dnsname(lp):
return lp.get('netbios name').lower() + "." + lp.get('realm').lower() return lp.get('netbios name').lower() + "." + lp.get('realm').lower()
def netcmd_finddc(lp, creds): def netcmd_finddc(lp, creds, realm=None):
'''return domain-name of a writable/ldap-capable DC for the domain.''' '''Return domain-name of a writable/ldap-capable DC for the default
domain (parameter "realm" in smb.conf) unless another realm has been
specified as argument'''
net = Net(creds=creds, lp=lp) net = Net(creds=creds, lp=lp)
realm = lp.get('realm') if realm is None:
cldap_ret = net.finddc(realm, realm = lp.get('realm')
nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE) cldap_ret = net.finddc(domain=realm,
flags=nbt.NBT_SERVER_LDAP | nbt.NBT_SERVER_DS | nbt.NBT_SERVER_WRITABLE)
return cldap_ret.pdc_dns_name return cldap_ret.pdc_dns_name