Exemplo n.º 1
0
def search(l, dn, filter=None):
    try:    
        result_set = l.search_s(dn, searchScope, filter) if filter is not None else l.search_s(dn, searchScope)
        result_set = ldaphelper.get_search_results(result_set)
    except ldap.NO_SUCH_OBJECT:
        result_set = []
    return result_set
Exemplo n.º 2
0
def update_all_user_last_bind():
    accountz = ldaphelper.get_search_results(get_account())
    # Parsing all accountz retrieved
    for account in accountz:
        account_attrz = account.get_attributes()

        #  If user has a last bind we update it
        if 'authTimestamp' in account_attrz:
            bind_datetime = generalized_time_to_datetime(
                account_attrz['authTimestamp'][0])
            uid_number = account_attrz['uidNumber'][0]
            uid = account_attrz['uid'][0]
            update_user_last_bind(uid_number, uid, bind_datetime)
Exemplo n.º 3
0
def update_all_user_last_bind():
    accountz = ldaphelper.get_search_results(
        get_account()
    )
    # Parsing all accountz retrieved
    for account in accountz:
        account_attrz = account.get_attributes()

        #  If user has a last bind we update it
        if 'authTimestamp' in account_attrz:
            bind_datetime = generalized_time_to_datetime(
                account_attrz['authTimestamp'][0])
            uid_number = account_attrz['uidNumber'][0]
            uid = account_attrz['uid'][0]
            update_user_last_bind(uid_number, uid, bind_datetime)
Exemplo n.º 4
0
def get_account_info(accountType,baseDN,user,password):
    """Return a list of accounts with attributes."""
    accounts = []
    searchScope = ldap.SCOPE_SUBTREE
    try:
        l = ldap.initialize('ldap://ldap1.kps')
        l.protocol_version = ldap.VERSION3
        l.simple_bind_s(user, password)
        r = l.search_s(baseDN, searchScope, searchFilter, retrieveAttributes)
        res = ldaphelper.get_search_results(r)
        for record in res:
            cn = record.get_attr_values('cn')[0]
            cn = cn.lower()
            mail = record.get_attr_values('mail')[0]
            mail = mail.lower()
            id = record.get_attr_values('studentID')[0]
            accounts.append(id,cn,email)
    except ldap.LDAPError, e:
        print e
Exemplo n.º 5
0
def anonymous_search(base_dn=None,
                     ldap_filter=None,
                     attributes=None,
                     scope=ldap.SCOPE_SUBTREE):
    if not base_dn:
        base_dn = LDAP_SEARCH_BASE
    try:
        conn = connect()
        conn.simple_bind_s("","")
        records = conn.search_s(
            base_dn, scope, ldap_filter, attributes
        )
        conn.unbind_s()
        return ldaphelper.get_search_results(records)

    except ldap.LDAPError as e:
        print(e)
    except Exception as e:
        print(e)
Exemplo n.º 6
0
    def anonymous_search(self,
                         base_dn=None,
                         ldap_filter=None,
                         attributes=None,
                         scope=ldap.SCOPE_SUBTREE):
        if not base_dn:
            base_dn = self.ldap_search_base
        try:
            self.connect()
            self.conn.simple_bind_s("", "")
            records = self.conn.search_s(base_dn, scope, ldap_filter,
                                         attributes)
            self.conn.unbind_s()
            return ldaphelper.get_search_results(records)

        except ldap.LDAPError as e:
            print(e)
            return self.ldap_err(e)
        except Exception as e:
            return self.other_err(e)
Exemplo n.º 7
0
    def anonymous_search(self,
                         base_dn=None,
                         ldap_filter=None,
                         attributes=None,
                         scope=ldap.SCOPE_SUBTREE):
        if not base_dn:
            base_dn = self.ldap_search_base
        try:
            self.connect()
            self.conn.simple_bind_s("","")
            records = self.conn.search_s(
                base_dn, scope, ldap_filter, attributes
            )
            self.conn.unbind_s()
            return ldaphelper.get_search_results(records)

        except ldap.LDAPError as e:
            print(e)
            return self.ldap_err(e)
        except Exception as e:
            return self.other_err(e)
Exemplo n.º 8
0
 def search(self,
            base_dn=None,
            ldap_filter='',
            attributes=None,
            scope=ldap.SCOPE_SUBTREE):
     if not base_dn:
         base_dn = self.ldap_search_base
     try:
         self.connect()
         self.conn.simple_bind_s(session['user_dn'], session['password'])
         records = self.conn.search_s(base_dn, scope, ldap_filter, attributes)
         self.conn.unbind_s()
         if records:
             return ldaphelper.get_search_results(records)
         else:
             return None
     except ldap.LDAPError as e:
         print(e)
         return self.ldap_err(e)
     except Exception as e:
         return self.other_err(e)
         print(e)
Exemplo n.º 9
0
 def search(self,
            base_dn=None,
            ldap_filter='',
            attributes=None,
            scope=ldap.SCOPE_SUBTREE):
     if not base_dn:
         base_dn = self.ldap_search_base
     try:
         self.connect()
         self.conn.simple_bind_s(session['user_dn'], session['password'])
         records = self.conn.search_s(base_dn, scope, ldap_filter,
                                      attributes)
         self.conn.unbind_s()
         if records:
             return ldaphelper.get_search_results(records)
         else:
             return None
     except ldap.LDAPError as e:
         print(e)
         return self.ldap_err(e)
     except Exception as e:
         return self.other_err(e)
         print(e)
Exemplo n.º 10
0
import ldap, ldif, ldaphelper

l = ldap.initialize('ldap://localhost')
l.bind_s('cn=admin,dc=fluidsignal,dc=com', 'Aiphootah3')

raw = l.search_s('dc=fluidsignal,dc=com', ldap.SCOPE_SUBTREE)
res = ldaphelper.get_search_results(raw)

for i in res:
    print i.to_ldif()