當前位置: 首頁>>代碼示例>>Python>>正文


Python ldap.VERSION3屬性代碼示例

本文整理匯總了Python中ldap.VERSION3屬性的典型用法代碼示例。如果您正苦於以下問題:Python ldap.VERSION3屬性的具體用法?Python ldap.VERSION3怎麽用?Python ldap.VERSION3使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在ldap的用法示例。


在下文中一共展示了ldap.VERSION3屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __ldap_getgid

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def __ldap_getgid(self, cn="員工"):
        """
        查詢 組cn對應的gid
        :param cn: 組cn
        :return: 對應cn的gidNumber
        """
        obj = self.ldapconn
        obj.protocal_version = ldap.VERSION3
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttributes = None
        searchFilter = "cn=" + cn
        try:
            ldap_result_id = obj.search(
                base="%s" % self.base_dn,
                scope=searchScope,
                filterstr=searchFilter,
                attrlist=retrieveAttributes
            )
            result_type, result_data = obj.result(ldap_result_id, 0)
            if result_type == ldap.RES_SEARCH_ENTRY:
                return result_data[0][1].get('gidNumber')[0]
            else:
                return None
        except ldap.LDAPError as e:
            logger.error('獲取gid失敗,原因為: %s' % str(e)) 
開發者ID:getway,項目名稱:diting,代碼行數:27,代碼來源:ldapadmin.py

示例2: ldap_update_password

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_update_password(self, uid, new_password=None, old_password=None):
        """
        更新密碼
        :param uid: 用戶uid,新password
        :return: True|None
        """
        result = None
        try:
            obj = self.ldapconn
            obj.protocal_version = ldap.VERSION3
            modifyDN = "uid=%s,%s" % (uid, BASE_DN)
            new_password_encrypt = pass_encrypt(new_password)
            #有old_password情況下
            if old_password:
                obj.passwd_s(modifyDN, [str(old_password).encode('utf-8')], [new_password_encrypt.encode('utf-8')])
                result = True
            else:
                obj.modify_s(modifyDN, [(ldap.MOD_REPLACE, 'userPassword', [new_password_encrypt.encode('utf-8')])])
                result = True
            obj.unbind_s()
        except ldap.LDAPError as e:
            logger.error("%s 密碼更新失敗,原因為: %s" % (uid, str(e)))
            return False
        return result 
開發者ID:getway,項目名稱:diting,代碼行數:26,代碼來源:ldapadmin.py

示例3: ldap_search_dn

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_search_dn(self,uid=None):
        obj = self.ldapconn
        obj.protocal_version = ldap.VERSION3
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttributes = None
        searchFilter = "cn=" + uid

        try:
            ldap_result_id = obj.search(self.base_dn, searchScope, searchFilter, retrieveAttributes)
            result_type, result_data = obj.result(ldap_result_id, 0)
#返回數據格式
#('cn=django,ou=users,dc=gccmx,dc=cn',
#    {  'objectClass': ['inetOrgPerson', 'top'],
#        'userPassword': ['{MD5}lueSGJZetyySpUndWjMBEg=='],
#        'cn': ['django'], 'sn': ['django']  }  )
#
            if result_type == ldap.RES_SEARCH_ENTRY:
                #dn = result[0][0]
                return result_data[0][0]
            else:
                return None
        except ldap.LDAPError, e:
            print e

#查詢用戶記錄,返回需要的信息 
開發者ID:zhixingchou,項目名稱:Adminset_Zabbix,代碼行數:27,代碼來源:ldap.py

示例4: ldap_get_user

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_get_user(self,uid=None):
        obj = self.ldapconn
        obj.protocal_version = ldap.VERSION3
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttributes = None
        searchFilter = "cn=" + uid
        try:
            ldap_result_id = obj.search(self.base_dn, searchScope, searchFilter, retrieveAttributes)
            result_type, result_data = obj.result(ldap_result_id, 0)
            if result_type == ldap.RES_SEARCH_ENTRY:
                username = result_data[0][1]['cn'][0]
                email = result_data[0][1]['mail'][0]
                nick = result_data[0][1]['sn'][0]
                result = {'username':username,'email':email,'nick':nick}
                return result
            else:
                return None
        except ldap.LDAPError, e:
            print e

#用戶驗證,根據傳遞來的用戶名和密碼,搜索LDAP,返回boolean值 
開發者ID:zhixingchou,項目名稱:Adminset_Zabbix,代碼行數:23,代碼來源:ldap.py

示例5: __init__

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def __init__(self, *args, **kwargs):
        """
        Implementation of :func:`~kqueen.auth.base.__init__`
        """

        super(LDAPAuth, self).__init__(*args, **kwargs)
        if not all(hasattr(self, attr) for attr in ['uri', 'admin_dn', '_password']):
            msg = 'Failed to configure LDAP, please provide valid LDAP credentials'
            logger.error(msg)
            raise ImproperlyConfigured(msg)

        # Define Kqueen rdn for all dc's
        d_names = ldap.dn.explode_dn(self.admin_dn)
        dc_list = [dc for dc in d_names if dc.startswith('dc=')]
        self.kqueen_dc = ','.join(dc_list)

        # Bind connection for Kqueen Read-only user
        if self._bind(self.admin_dn, self._password):
            self.connection = ldap.initialize(self.uri)
            self.connection.simple_bind_s(self.admin_dn, self._password)
            self.connection.protocol_version = ldap.VERSION3
        else:
            msg = 'Failed to bind connection for Kqueen Read-only user'
            logger.error(msg)
            raise ImproperlyConfigured(msg) 
開發者ID:Mirantis,項目名稱:kqueen,代碼行數:27,代碼來源:ldap.py

示例6: initialize

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def initialize(self):
        """Initialize a connection to the LDAP server.

        :return: LDAP connection object.
        """

        try:
            conn = ldap.initialize('{0}://{1}:{2}'.format(
                current_app.config['LDAP_SCHEMA'],
                current_app.config['LDAP_HOST'],
                current_app.config['LDAP_PORT']))
            conn.set_option(ldap.OPT_NETWORK_TIMEOUT,
                            current_app.config['LDAP_TIMEOUT'])
            conn = self._set_custom_options(conn)
            conn.protocol_version = ldap.VERSION3
            if current_app.config['LDAP_USE_TLS']:
                conn.start_tls_s()
            return conn
        except ldap.LDAPError as e:
            raise LDAPException(self.error(e.args)) 
開發者ID:alexferl,項目名稱:flask-simpleldap,代碼行數:22,代碼來源:__init__.py

示例7: _ldap_get_con

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def _ldap_get_con():
    if not _check_ldap_settings_present():
        return None

    con = ldap.initialize(fame_config.ldap_uri)
    con.protocol_version = ldap.VERSION3
    con.set_option(ldap.OPT_REFERRALS, 0)
    return con 
開發者ID:certsocietegenerale,項目名稱:fame,代碼行數:10,代碼來源:user_management.py

示例8: __init__

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def __init__(self, path):
        """Initialize new LdapConfig with options parsed from config file on the ``path``.

        Arguments:
            path (Optional[path]): Path to the config file to read and parse.
                If not provided, then empty config is initialized.
        """
        conf = parse_config_file(path) if path else {}

        if 'uri' in conf:
            self.uris = conf['uri'].split()
        else:
            host = conf.get('host', DEFAULT_HOST)
            port = conf.get('port', DEFAULT_PORT)
            self.uris = ["ldap://%s:%s" % (host, port)]

        self.base = conf.get('nss_base_passwd', '').split('?')[0] or conf.get('base', None)
        self.bind_dn = conf.get('binddn', None)
        self.bind_pass = conf.get('bindpw', None)
        self.bind_timeout = int(conf.get('bind_timelimit', DEFAULT_TIMEOUT))
        self.cacert_dir = conf.get('tls_cacertdir', None)
        self.filter = conf.get('pam_filter', DEFAULT_FILTER)
        self.ldap_version = int(conf.get('ldap_version', ldap.VERSION3))
        self.login_attr = conf.get('pam_login_attribute', DEFAULT_LOGIN_ATTR)
        self.pubkey_attr = conf.get('pubkey_attr', DEFAULT_PUBKEY_ATTR)
        self.pubkey_class = conf.get('pubkey_class', DEFAULT_PUBKEY_CLASS)
        self.referrals = parse_bool(conf.get('referrals', DEFAULT_REFERRALS))
        self.sasl = conf.get('sasl', None)
        self.scope = parse_scope_opt(conf.get('scope', DEFAULT_SCOPE))
        self.search_timeout = int(conf.get('timelimit', DEFAULT_TIMEOUT))
        self.ssl = conf.get('ssl', None)
        self.tls_require_cert = parse_tls_reqcert_opt(conf.get('tls_reqcert')) 
開發者ID:jirutka,項目名稱:ssh-ldap-pubkey,代碼行數:34,代碼來源:config.py

示例9: __init__

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def __init__(self, conf, sasl):
        self.connection = ldap.initialize(conf.ldap_server_uri)
        self.base_dn = conf.ldap_base_dn
        self.sasl = sasl
        self.connection.protocol_version = ldap.VERSION3
        if self.sasl:
            self.sasl_auth = ldap.sasl.sasl({}, 'GSSAPI') 
開發者ID:DistributedSystemsGroup,項目名稱:zoe,代碼行數:9,代碼來源:ldap.py

示例10: get_ldap_connection

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def get_ldap_connection(host):
    conn = ldap.initialize("ldap://{}".format(host))
    conn.set_option(ldap.OPT_PROTOCOL_VERSION, ldap.VERSION3)
    conn.start_tls_s()
    return conn 
開發者ID:zentralopensource,項目名稱:zentral,代碼行數:7,代碼來源:__init__.py

示例11: ldap_init_conn

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_init_conn(self):
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
        conn = ldap.initialize(Setting().get('ldap_uri'))
        conn.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
        conn.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
        conn.set_option(ldap.OPT_X_TLS, ldap.OPT_X_TLS_DEMAND)
        conn.set_option(ldap.OPT_X_TLS_DEMAND, True)
        conn.set_option(ldap.OPT_DEBUG_LEVEL, 255)
        conn.protocol_version = ldap.VERSION3
        return conn 
開發者ID:ngoduykhanh,項目名稱:PowerDNS-Admin,代碼行數:12,代碼來源:user.py

示例12: ldap_auth_login

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_auth_login(self):
        _ldap = self.application.settings.get('ldap')
        try:
            conn = ldap.initialize(_ldap.get('server_uri'))
            conn.protocal_version = ldap.VERSION3
            conn.simple_bind_s(_ldap.get('bind_dn'), _ldap.get('bind_password'))
        except Exception as e:
            logging.error('Initialize Bind ldap failed: %s' % str(e))
            response_data = dict(code=500, msg='Login failed')
        else:
            scope_subtree = ldap.SCOPE_SUBTREE
            filterstr = '(uid=%s)' % self.username
            result_id = conn.search(_ldap.get('base_dn'), scope_subtree, filterstr, None)
            result_type, result_data = conn.result(result_id, 0)
            if not result_data:
                response_data = dict(code=401, msg='Username or password incorrect')
            else:
                try:
                    conn.simple_bind_s(result_data[0][0], self.password)
                except Exception as e:
                    logging.error('Bind ldap user failed: %s' % str(e))
                    response_data = dict(code=401, msg='Username or password incorrect')
                else:
                    self.ldap_user = result_data[0][1]
                    user = self.base_user()  # loggrove base user
                    if not user:
                        response_data = dict(code=500, msg='Login failed')
                    elif user.get('status') != 1:
                        response_data = dict(code=403, msg='User disabled')
                    else:
                        response_data = self.login(user)
            conn.unbind_s()
        return response_data 
開發者ID:olajowon,項目名稱:loggrove,代碼行數:35,代碼來源:login.py

示例13: ldap_search_dn

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_search_dn(self, value=None, value_type='uid'):
        """
        # 根據表單提交的用戶名,檢索該用戶的dn,一條dn就相當於數據庫裏的一條記錄。
        # 在ldap裏類似cn=username,ou=users,dc=gccmx,dc=cn,驗證用戶密碼,必須先檢索出該DN
        :param value: 用戶 uid或 組cn
        :param value_type: 用戶 uid|cn
        :return: search result
        """
        obj = self.ldapconn
        obj.protocal_version = ldap.VERSION3
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttributes = None
        if value_type == 'cn':
            searchFilter = "cn=" + value
        else:
            searchFilter = "uid=" + value
        try:
            ldap_result_id = obj.search(
                base=self.base_dn,
                scope=searchScope,
                filterstr=searchFilter,
                attrlist=retrieveAttributes
            )
            result_type, result_data = obj.result(ldap_result_id, 0)
            if result_type == ldap.RES_SEARCH_ENTRY:
                return result_data
            else:
                return None
        except ldap.LDAPError as e:
            logger.error('ldap search %s 失敗,原因為: %s' % (value, str(e))) 
開發者ID:getway,項目名稱:diting,代碼行數:32,代碼來源:ldapadmin.py

示例14: __get_max_uidNumber

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def __get_max_uidNumber(self):
        """
        查詢 當前最大的uid,這個是在添加用戶時,用於自增uid
        :param: None
        :return: max uidNumber
        """
        obj = self.ldapconn
        obj.protocal_version = ldap.VERSION3
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttributes = ['uidNumber']
        searchFilter = "uid=*"

        try:
            ldap_result = obj.search(
                base="%s" % self.base_dn,
                scope=searchScope,
                filterstr=searchFilter,
                attrlist=retrieveAttributes
            )
            print(ldap_result)
            result_set = []
            while True:
                result_type, result_data = obj.result(ldap_result, 0)
                if not result_data:
                    break
                else:
                    if result_type == ldap.RES_SEARCH_ENTRY:
                        result_set.append(int(result_data[0][1].get('uidNumber')[0]))
            return max(result_set) + 1
        except ldap.LDAPError as e:
            logger.error('獲取最大uid失敗,原因為: %s' % str(e)) 
開發者ID:getway,項目名稱:diting,代碼行數:33,代碼來源:ldapadmin.py

示例15: ldap_add_user

# 需要導入模塊: import ldap [as 別名]
# 或者: from ldap import VERSION3 [as 別名]
def ldap_add_user(self, cn, mail, username, password):
        """
        添加ldap用戶
        :param cn: 中文名, mail: 郵箱, username: 用戶名, password: 密碼
        :return: True/None
        """
        result = None
        try:
            obj = self.ldapconn
            obj.protocal_version = ldap.VERSION3
            password_encrypt = pass_encrypt(password)
            addDN = "uid=%s,%s" % (username, BASE_DN)
            attrs = {}
            attrs['objectclass'] = ['inetOrgPerson'.encode('utf-8')]
            attrs['cn'] = [str(cn).encode('utf-8')]
            # attrs['homeDirectory'] = str('/home/%s' % username)
            # attrs['loginShell'] = '/bin/bash'
            attrs['mail'] = [str(mail).encode('utf-8')]
            attrs['sn'] = [str(username).encode('utf-8')]
            attrs['uid'] = [str(username).encode('utf-8')]
            attrs['userPassword'] = [str(password_encrypt).encode('utf-8')]
            # attrs['uidNumber'] = str(self.__get_max_uidNumber())
            # attrs['gidNumber'] = self.__ldap_getgid(cn='員工')
            ldif = ldap.modlist.addModlist(attrs)
            obj.add_s(addDN, ldif)
            obj.unbind_s()
            result = True
        except ldap.LDAPError as e:
            logger.error("生成用戶%s 失敗,原因為: %s" % (username, str(e)))
        return result 
開發者ID:getway,項目名稱:diting,代碼行數:32,代碼來源:ldapadmin.py


注:本文中的ldap.VERSION3屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。