def __setattr__(self, name, val): if isinstance(val, ValueSet): # This is to work around some weirdness of Python # If I do user.memberOf += group, this calls the __iadd__ method # on ValueSet (see below) to add the element, but then does a # __setattr__ on user, which we want to avoid. return elif name.startswith("_"): # names that start with an underscore are not routed through LDAP self.__dict__[name] = val elif name in self.__dict__ or hasattr(type(self), name): # this isn't an LDAP attribute either ldebug("Not updating attribute %s of %s", name, self) return else: self.set_attribute(name, val)
def _update_class_tree(cls, dnsuffix): if cls is LDAPObject: assert(len(dnsuffix) == 0) dn = () elif 'base_dn' in cls.__dict__ and cls.base_dn is not None: dn = dn_to_tuple(cls.base_dn) # dn must end with dnsuffix if len(dnsuffix) > 0 and not dn[-len(dnsuffix):] == dnsuffix: raise TypeError("Invalid DN %s for class %s\ (must be under %s)" % (dn, cls.__name__, dnsuffix)) else: # classes are mapped to organizationalUnits dn = (("ou", cls.__name__),) + dnsuffix cmap = LDAPClass._classmap if dn in cmap: raise TypeError("Duplicate classes (%s and %s)\ for DN %s" % (cls.__name__, cmap[dn], dn)) ldebug("rebuilding classmap: %s has base dn %s" % (cls.__name__, dn)) cmap[dn] = cls for subclass in cls.__subclasses__(): subclass._update_class_tree(dn) cls.cls_dn_tuple = dn cls.cls_dn_str = tuple_to_dn(dn)
def _update_class_tree(cls, dnsuffix): if cls is LDAPObject: assert (len(dnsuffix) == 0) dn = () elif 'base_dn' in cls.__dict__ and cls.base_dn is not None: dn = dn_to_tuple(cls.base_dn) # dn must end with dnsuffix if len(dnsuffix) > 0 and not dn[-len(dnsuffix):] == dnsuffix: raise TypeError("Invalid DN %s for class %s\ (must be under %s)" % (dn, cls.__name__, dnsuffix)) else: # classes are mapped to organizationalUnits dn = (("ou", cls.__name__), ) + dnsuffix cmap = LDAPClass._classmap if dn in cmap: raise TypeError("Duplicate classes (%s and %s)\ for DN %s" % (cls.__name__, cmap[dn], dn)) ldebug("rebuilding classmap: %s has base dn %s" % (cls.__name__, dn)) cmap[dn] = cls for subclass in cls.__subclasses__(): subclass._update_class_tree(dn) cls.cls_dn_tuple = dn cls.cls_dn_str = tuple_to_dn(dn)
def modify(l, dn, modlist): ldebug("Modifying %s: %s" % (dn, modlist)) l.modify_s(dn, modlist)
def add(l, dn, modlist): ldebug("Adding %s" % modlist) l.add_s(dn, modlist)
def search(l, base, scope, filter, attrlist=None): if filter is None: filter = "(objectClass=*)" ldebug("Searching in %s for %s" % (base, filter)) return l.search_s(base, scope, filter, attrlist)
def passwd(l, dn, oldpw, newpw): ldebug("Changing password for %s" % dn) l.passwd_s(dn, oldpw, newpw)
def modrdn(l, dn, newrdn): ldebug("Renaming %s" % dn) l.rename_s(dn, newrdn)