The branch, master has been updated via 03e5f58 pyldb: Add more docstrings. via e76c981 samba.drs_utils: Use new style classes and exceptions, fix formatting of docstrings to make pydoctor happy. via 452d1ef samba.kcc_utils: Fix formatting to match PEP8, make pydoctor happy. from 664eb70 s3-dbwrap: & is not required when taking a function pointer
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 03e5f581aed89b3eea5769a244864a0f9938ac59 Author: Jelmer Vernooij <jel...@samba.org> Date: Thu Dec 8 20:28:18 2011 +0100 pyldb: Add more docstrings. Autobuild-User: Jelmer Vernooij <jel...@samba.org> Autobuild-Date: Thu Dec 8 22:08:49 CET 2011 on sn-devel-104 commit e76c981c8008668609061755528f59c7ffc483a6 Author: Jelmer Vernooij <jel...@samba.org> Date: Thu Dec 8 20:23:57 2011 +0100 samba.drs_utils: Use new style classes and exceptions, fix formatting of docstrings to make pydoctor happy. commit 452d1ef8ef9e5eeaec02dfa464ce2f1998761892 Author: Jelmer Vernooij <jel...@samba.org> Date: Thu Dec 8 20:20:03 2011 +0100 samba.kcc_utils: Fix formatting to match PEP8, make pydoctor happy. ----------------------------------------------------------------------- Summary of changes: lib/ldb/pyldb.c | 19 +- source4/scripting/python/samba/drs_utils.py | 32 ++- source4/scripting/python/samba/kcc_utils.py | 460 +++++++++++++-------------- 3 files changed, 245 insertions(+), 266 deletions(-) Changeset truncated at 500 lines: diff --git a/lib/ldb/pyldb.c b/lib/ldb/pyldb.c index 2f1a6a3..b2315e6 100644 --- a/lib/ldb/pyldb.c +++ b/lib/ldb/pyldb.c @@ -2117,6 +2117,7 @@ static PyTypeObject PyLdbModule = { .tp_basicsize = sizeof(PyLdbModuleObject), .tp_dealloc = (destructor)py_ldb_module_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = "LDB module (extension)", }; @@ -2436,6 +2437,7 @@ static PyTypeObject PyLdbMessageElement = { .tp_as_sequence = &py_ldb_msg_element_seq, .tp_new = py_ldb_msg_element_new, .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = "An element of a Message", }; @@ -2836,6 +2838,7 @@ static PyTypeObject PyLdbMessage = { .tp_flags = Py_TPFLAGS_DEFAULT, .tp_iter = (getiterfunc)py_ldb_msg_iter, .tp_compare = (cmpfunc)py_ldb_msg_compare, + .tp_doc = "A LDB Message", }; static PyObject *PyLdbTree_FromTree(struct ldb_parse_tree *tree) @@ -2864,6 +2867,7 @@ static PyTypeObject PyLdbTree = { .tp_basicsize = sizeof(PyLdbTreeObject), .tp_dealloc = (destructor)py_ldb_tree_dealloc, .tp_flags = Py_TPFLAGS_DEFAULT, + .tp_doc = "A search tree", }; /* Ldb_module */ @@ -3247,24 +3251,25 @@ static PyObject *py_binary_decode(PyObject *self, PyObject *args) static PyMethodDef py_ldb_global_methods[] = { { "register_module", py_register_module, METH_VARARGS, - "S.register_module(module) -> None\n" + "S.register_module(module) -> None\n\n" "Register a LDB module."}, { "timestring", py_timestring, METH_VARARGS, - "S.timestring(int) -> string\n" + "S.timestring(int) -> string\n\n" "Generate a LDAP time string from a UNIX timestamp" }, { "string_to_time", py_string_to_time, METH_VARARGS, - "S.string_to_time(string) -> int\n" + "S.string_to_time(string) -> int\n\n" "Parse a LDAP time string into a UNIX timestamp." }, { "valid_attr_name", py_valid_attr_name, METH_VARARGS, - "S.valid_attr_name(name) -> bool\n" + "S.valid_attr_name(name) -> bool\n\nn" "Check whether the supplied name is a valid attribute name." }, { "open", (PyCFunction)py_ldb_new, METH_VARARGS|METH_KEYWORDS, - NULL }, + "S.open() -> Ldb\n\n" + "Open a new LDB context." }, { "binary_encode", py_binary_encode, METH_VARARGS, - "S.binary_encode(string) -> string\n" + "S.binary_encode(string) -> string\n\n" "Perform a RFC2254 binary encoding on a string" }, { "binary_decode", py_binary_decode, METH_VARARGS, - "S.binary_decode(string) -> string\n" + "S.binary_decode(string) -> string\n\n" "Perform a RFC2254 binary decode on a string" }, { NULL } }; diff --git a/source4/scripting/python/samba/drs_utils.py b/source4/scripting/python/samba/drs_utils.py index 9aacfbc..fe14a8f 100644 --- a/source4/scripting/python/samba/drs_utils.py +++ b/source4/scripting/python/samba/drs_utils.py @@ -24,7 +24,7 @@ from samba.net import Net import samba, ldb -class drsException: +class drsException(Exception): """Base element for drs errors""" def __init__(self, value): @@ -35,8 +35,8 @@ class drsException: def drsuapi_connect(server, lp, creds): - """ - make a DRSUAPI connection to the server + """Make a DRSUAPI connection to the server. + :param server: the name of the server to connect to :param lp: a samba line parameter object :param creds: credential used for the connection @@ -57,15 +57,18 @@ def drsuapi_connect(server, lp, creds): return (drsuapiBind, drsuapiHandle, bindSupportedExtensions) -def sendDsReplicaSync(drsuapiBind, drsuapi_handle, source_dsa_guid, naming_context, req_option): - """ + +def sendDsReplicaSync(drsuapiBind, drsuapi_handle, source_dsa_guid, + naming_context, req_option): + """Send DS replica sync request. + :param drsuapiBind: a drsuapi Bind object :param drsuapi_handle: a drsuapi hanle on the drsuapi connection :param source_dsa_guid: the guid of the source dsa for the replication :param naming_context: the DN of the naming context to replicate :param req_options: replication options for the DsReplicaSync call - :raise drsException: if any error occur while sending and receiving the reply - for the dsReplicaSync + :raise drsException: if any error occur while sending and receiving the + reply for the dsReplicaSync """ nc = drsuapi.DsReplicaObjectIdentifier() @@ -81,14 +84,17 @@ def sendDsReplicaSync(drsuapiBind, drsuapi_handle, source_dsa_guid, naming_conte except Exception, estr: raise drsException("DsReplicaSync failed %s" % estr) + def sendRemoveDsServer(drsuapiBind, drsuapi_handle, server_dsa_dn, domain): - """ + """Send RemoveDSServer request. + :param drsuapiBind: a drsuapi Bind object :param drsuapi_handle: a drsuapi hanle on the drsuapi connection - :param server_dsa_dn: a DN object of the server's dsa that we want to demote + :param server_dsa_dn: a DN object of the server's dsa that we want to + demote :param domain: a DN object of the server's domain - :raise drsException: if any error occur while sending and receiving the reply - for the DsRemoveDSServer + :raise drsException: if any error occur while sending and receiving the + reply for the DsRemoveDSServer """ try: @@ -101,6 +107,7 @@ def sendRemoveDsServer(drsuapiBind, drsuapi_handle, server_dsa_dn, domain): except Exception, estr: raise drsException("DsRemoveDSServer failed %s" % estr) + def drs_DsBind(drs): '''make a DsBind call, returning the binding handle''' bind_info = drsuapi.DsBindInfoCtr() @@ -139,7 +146,7 @@ def drs_DsBind(drs): return (handle, info.info.supported_extensions) -class drs_Replicate: +class drs_Replicate(object): '''DRS replication calls''' def __init__(self, binding_string, lp, creds, samdb): @@ -239,7 +246,6 @@ class drs_Replicate: setattr(req5, a, getattr(req8, a)) req = req5 - while True: (level, ctr) = self.drs.DsGetNCChanges(self.drs_handle, req_level, req) if ctr.first_object == None and ctr.object_count != 0: diff --git a/source4/scripting/python/samba/kcc_utils.py b/source4/scripting/python/samba/kcc_utils.py index 13bc241..f762f4a 100644 --- a/source4/scripting/python/samba/kcc_utils.py +++ b/source4/scripting/python/samba/kcc_utils.py @@ -3,6 +3,7 @@ # KCC topology utilities # # Copyright (C) Dave Craft 2011 +# Copyright (C) Jelmer Vernooij 2011 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,37 +18,41 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -import samba, ldb +import ldb import uuid -from samba import dsdb -from samba.dcerpc import misc -from samba.dcerpc import drsblobs -from samba.dcerpc import drsuapi -from samba.common import dsdb_Dn -from samba.ndr import ndr_unpack -from samba.ndr import ndr_pack +from samba import dsdb +from samba.dcerpc import ( + drsblobs, + drsuapi, + misc, + ) +from samba.common import dsdb_Dn +from samba.ndr import (ndr_unpack, ndr_pack) -class NCType: + +class NCType(object): (unknown, schema, domain, config, application) = range(0, 5) -class NamingContext: - """Base class for a naming context. Holds the DN, - GUID, SID (if available) and type of the DN. - Subclasses may inherit from this and specialize + +class NamingContext(object): + """Base class for a naming context. + + Holds the DN, GUID, SID (if available) and type of the DN. + Subclasses may inherit from this and specialize """ def __init__(self, nc_dnstr, nc_guid=None, nc_sid=None): """Instantiate a NamingContext - :param nc_dnstr: NC dn string - :param nc_guid: NC guid - :param nc_sid: NC sid + + :param nc_dnstr: NC dn string + :param nc_guid: NC guid + :param nc_sid: NC sid """ - self.nc_dnstr = nc_dnstr - self.nc_guid = nc_guid - self.nc_sid = nc_sid - self.nc_type = NCType.unknown - return + self.nc_dnstr = nc_dnstr + self.nc_guid = nc_guid + self.nc_sid = nc_sid + self.nc_type = NCType.unknown def __str__(self): '''Debug dump string output of class''' @@ -56,7 +61,6 @@ class NamingContext: text = text + "\n\tnc_guid=%s" % str(self.nc_guid) text = text + "\n\tnc_sid=%s" % self.nc_sid text = text + "\n\tnc_type=%s" % self.nc_type - return text def is_schema(self): @@ -91,15 +95,15 @@ class NamingContext: self.nc_type = NCType.domain else: self.nc_type = NCType.application - return def identify_by_dsa_attr(self, samdb, attr): """Given an NC which has been discovered thru the - nTDSDSA database object, determine what type of NC - it is (i.e. schema, config, domain, application) via - the use of the schema attribute under which the NC - was found. - :param attr: attr of nTDSDSA object where NC DN appears + nTDSDSA database object, determine what type of NC + it is (i.e. schema, config, domain, application) via + the use of the schema attribute under which the NC + was found. + + :param attr: attr of nTDSDSA object where NC DN appears """ # If the NC is listed under msDS-HasDomainNCs then # this can only be a domain NC and it is our default @@ -124,29 +128,29 @@ class NamingContext: if self.nc_type == NCType.unknown: self.identify_by_basedn(samdb) - return class NCReplica(NamingContext): - """Class defines a naming context replica that is relative - to a specific DSA. This is a more specific form of - NamingContext class (inheriting from that class) and it - identifies unique attributes of the DSA's replica for a NC. + """Naming context replica that is relative to a specific DSA. + + This is a more specific form of NamingContext class (inheriting from that + class) and it identifies unique attributes of the DSA's replica for a NC. """ - def __init__(self, dsa_dnstr, dsa_guid, nc_dnstr, \ + def __init__(self, dsa_dnstr, dsa_guid, nc_dnstr, nc_guid=None, nc_sid=None): """Instantiate a Naming Context Replica - :param dsa_guid: GUID of DSA where replica appears - :param nc_dnstr: NC dn string - :param nc_guid: NC guid - :param nc_sid: NC sid + + :param dsa_guid: GUID of DSA where replica appears + :param nc_dnstr: NC dn string + :param nc_guid: NC guid + :param nc_sid: NC sid """ - self.rep_dsa_dnstr = dsa_dnstr - self.rep_dsa_guid = dsa_guid - self.rep_default = False # replica for DSA's default domain - self.rep_partial = False - self.rep_ro = False - self.rep_instantiated_flags = 0 + self.rep_dsa_dnstr = dsa_dnstr + self.rep_dsa_guid = dsa_guid + self.rep_default = False # replica for DSA's default domain + self.rep_partial = False + self.rep_ro = False + self.rep_instantiated_flags = 0 # RepsFromTo tuples self.rep_repsFrom = [] @@ -160,7 +164,6 @@ class NCReplica(NamingContext): # Call my super class we inherited from NamingContext.__init__(self, nc_dnstr, nc_guid, nc_sid) - return def __str__(self): '''Debug dump string output of class''' @@ -183,13 +186,13 @@ class NCReplica(NamingContext): self.rep_instantiated_flags = 0 else: self.rep_instantiated_flags = flags - return def identify_by_dsa_attr(self, samdb, attr): """Given an NC which has been discovered thru the - nTDSDSA database object, determine what type of NC - replica it is (i.e. partial, read only, default) - :param attr: attr of nTDSDSA object where NC DN appears + nTDSDSA database object, determine what type of NC + replica it is (i.e. partial, read only, default) + + :param attr: attr of nTDSDSA object where NC DN appears """ # If the NC was found under hasPartialReplicaNCs # then a partial replica at this dsa @@ -231,11 +234,9 @@ class NCReplica(NamingContext): # context type by calling the super class method # of the same name NamingContext.identify_by_dsa_attr(self, samdb, attr) - return def is_default(self): - """Returns True if this is a default domain NC for the dsa - that this NC appears on + """Whether this is a default domain for the dsa that this NC appears on """ return self.rep_default @@ -249,10 +250,10 @@ class NCReplica(NamingContext): def is_present(self): """Given an NC replica which has been discovered thru the - nTDSDSA database object and populated with replica flags - from the msDS-HasInstantiatedNCs; return whether the NC - replica is present (true) or if the IT_NC_GOING flag is - set then the NC replica is not present (false) + nTDSDSA database object and populated with replica flags + from the msDS-HasInstantiatedNCs; return whether the NC + replica is present (true) or if the IT_NC_GOING flag is + set then the NC replica is not present (false) """ if self.rep_present_criteria_one and \ self.rep_instantiated_flags & dsdb.INSTANCE_TYPE_NC_GOING == 0: @@ -261,28 +262,26 @@ class NCReplica(NamingContext): def load_repsFrom(self, samdb): """Given an NC replica which has been discovered thru the nTDSDSA - database object, load the repsFrom attribute for the local replica. - held by my dsa. The repsFrom attribute is not replicated so this - attribute is relative only to the local DSA that the samdb exists on + database object, load the repsFrom attribute for the local replica. + held by my dsa. The repsFrom attribute is not replicated so this + attribute is relative only to the local DSA that the samdb exists on """ try: res = samdb.search(base=self.nc_dnstr, scope=ldb.SCOPE_BASE, attrs=[ "repsFrom" ]) except ldb.LdbError, (enum, estr): - raise Exception("Unable to find NC for (%s) - (%s)" % \ + raise Exception("Unable to find NC for (%s) - (%s)" % (self.nc_dnstr, estr)) - return msg = res[0] # Possibly no repsFrom if this is a singleton DC if "repsFrom" in msg: for value in msg["repsFrom"]: - rep = RepsFromTo(self.nc_dnstr, \ + rep = RepsFromTo(self.nc_dnstr, ndr_unpack(drsblobs.repsFromToBlob, value)) self.rep_repsFrom.append(rep) - return def commit_repsFrom(self, samdb): """Commit repsFrom to the database""" @@ -297,7 +296,7 @@ class NCReplica(NamingContext): # reflect the reference docs. As of right now this # commit to the database will work as its what the # older KCC also did - modify = False + modify = False newreps = [] for repsFrom in self.rep_repsFrom: @@ -318,7 +317,7 @@ class NCReplica(NamingContext): if modify == False: return - m = ldb.Message() + m = ldb.Message() m.dn = ldb.Dn(samdb, self.nc_dnstr) m["repsFrom"] = \ @@ -328,9 +327,8 @@ class NCReplica(NamingContext): samdb.modify(m) except ldb.LdbError, estr: - raise Exception("Could not set repsFrom for (%s) - (%s)" % \ + raise Exception("Could not set repsFrom for (%s) - (%s)" % (self.dsa_dnstr, estr)) - return def load_fsmo_roles(self, samdb): # XXX - to be implemented @@ -340,19 +338,22 @@ class NCReplica(NamingContext): # XXX - to be implemented return False -class DirectoryServiceAgent: + +class DirectoryServiceAgent(object): def __init__(self, dsa_dnstr): - """Initialize DSA class. Class is subsequently - fully populated by calling the load_dsa() method - :param dsa_dnstr: DN of the nTDSDSA + """Initialize DSA class. + + Class is subsequently fully populated by calling the load_dsa() method + + :param dsa_dnstr: DN of the nTDSDSA """ - self.dsa_dnstr = dsa_dnstr - self.dsa_guid = None - self.dsa_ivid = None - self.dsa_is_ro = False - self.dsa_options = 0 - self.dsa_behavior = 0 + self.dsa_dnstr = dsa_dnstr + self.dsa_guid = None + self.dsa_ivid = None + self.dsa_is_ro = False + self.dsa_options = 0 + self.dsa_behavior = 0 self.default_dnstr = None # default domain dn string for dsa # NCReplicas for this dsa that are "present" @@ -368,8 +369,6 @@ class DirectoryServiceAgent: # in the database. Indexed by DN string of connection self.connect_table = {} - return - def __str__(self): '''Debug dump string output of class''' @@ -407,19 +406,17 @@ class DirectoryServiceAgent: return False def is_minimum_behavior(self, version): - """Is dsa at minimum windows level greater than or - equal to (version) - :param version: Windows version to test against - (e.g. DS_BEHAVIOR_WIN2008) + """Is dsa at minimum windows level greater than or equal to (version) + + :param version: Windows version to test against + (e.g. DS_BEHAVIOR_WIN2008) """ if self.dsa_behavior >= version: return True return False def should_translate_ntdsconn(self): - """Returns True if DSA object allows NTDSConnection - translation in its options. False otherwise. - """ + """Whether this allows NTDSConnection translation in its options.""" if (self.options & dsdb.DS_NTDSDSA_OPT_DISABLE_NTDSCONN_XLATE) != 0: return False return True @@ -430,37 +427,33 @@ class DirectoryServiceAgent: return self.current_rep_table, self.needed_rep_table -- Samba Shared Repository