def add_user(self, user_name, uid_number=None, gid_number=None, home_directory=None): dn = "uid=%s,%s" % (user_name, self.people_base_cn) attributes = dict() for key in ("uid", "cn", "sn"): attributes[key] = encode(user_name) attributes["objectClass"] = [ "top", "person", "inetOrgPerson", "posixAccount", "organizationalPerson", "shadowAccount" ] if uid_number is None: attributes["uidNumber"] = encode(self.__get_next_uid_number()) else: attributes["uidNumber"] = encode(uid_number) if gid_number is None: attributes["gidNumber"] = encode(self.GROUP_ID_NUMBER) else: attributes["gidNumber"] = encode(gid_number) if attributes["gidNumber"] is None: raise LDAPError("please set gidNumber") if home_directory is None: home_directory = os.path.join(self.HOME_BASE_DIRECTORY, user_name) attributes["homeDirectory"] = encode(home_directory) attributes["loginShell"] = encode(self.LOGIN_SHELL) if self.CREATOR is not None: attributes["givenName"] = encode(self.CREATOR) mod_list = ldap.modlist.addModlist(attributes) self.ldap_com.add_s(dn, mod_list)
def simple_bind_s(self, user, passw, *args, **kwargs): """emulate a simple_bind""" if "fail" in self.uri: raise LDAPError("failed to connect") if passw != "geheim1": raise INVALID_CREDENTIALS("not geheim1!") return True
def simple_bind_s(self, user, passw, *args, **kwargs): """ emulate a simple_bind """ if 'fail' in self.uri: raise LDAPError('failed to connect') if passw != 'geheim1': raise INVALID_CREDENTIALS('not geheim1!') return True