示例#1
0
文件: ldapobject.py 项目: netsoc/nd
 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)
示例#2
0
文件: ldapobject.py 项目: netsoc/nd
 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)
示例#3
0
文件: ldapobject.py 项目: netsoc/nd
 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)
示例#4
0
文件: ldapobject.py 项目: netsoc/nd
 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)
示例#5
0
文件: ldapconnect.py 项目: netsoc/nd
def modify(l, dn, modlist):
    ldebug("Modifying %s: %s" % (dn, modlist))
    l.modify_s(dn, modlist)
示例#6
0
文件: ldapconnect.py 项目: netsoc/nd
def add(l, dn, modlist):
    ldebug("Adding %s" % modlist)
    l.add_s(dn, modlist)
示例#7
0
文件: ldapconnect.py 项目: netsoc/nd
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)
示例#8
0
文件: ldapconnect.py 项目: netsoc/nd
def passwd(l, dn, oldpw, newpw):
    ldebug("Changing password for %s" % dn)
    l.passwd_s(dn, oldpw, newpw)
示例#9
0
文件: ldapconnect.py 项目: netsoc/nd
def modrdn(l, dn, newrdn):
    ldebug("Renaming %s" % dn)
    l.rename_s(dn, newrdn)
示例#10
0
def modify(l, dn, modlist):
    ldebug("Modifying %s: %s" % (dn, modlist))
    l.modify_s(dn, modlist)
示例#11
0
def add(l, dn, modlist):
    ldebug("Adding %s" % modlist)
    l.add_s(dn, modlist)
示例#12
0
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)
示例#13
0
def passwd(l, dn, oldpw, newpw):
    ldebug("Changing password for %s" % dn)
    l.passwd_s(dn, oldpw, newpw)
示例#14
0
def modrdn(l, dn, newrdn):
    ldebug("Renaming %s" % dn)
    l.rename_s(dn, newrdn)