| 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | import ldap |
|---|
| 3 | from config import ldapSERVER, ldapBASE |
|---|
| 4 | from common import log |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | def checkORGQuota(): |
|---|
| 8 | return None |
|---|
| 9 | |
|---|
| 10 | def checkORG(ORG): |
|---|
| 11 | l=anonymousLDAPbind() |
|---|
| 12 | |
|---|
| 13 | if '.' in ORG: |
|---|
| 14 | return ORG in [entry[1]['o'][0] for entry in l.search_s(ldapBASE,1,'o='+'*')] |
|---|
| 15 | else: |
|---|
| 16 | return ORG in [entry[1]['ou'][0] for entry in l.search_s(ldapBASE,1,'ou='+'*')] |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | def anonymousLDAPbind(): |
|---|
| 20 | # Compatibility mode, JIC ® |
|---|
| 21 | # l.protocol_version = ldap.VERSION2 |
|---|
| 22 | |
|---|
| 23 | # This might through an exception |
|---|
| 24 | try: |
|---|
| 25 | return ldap.open(ldapSERVER).simple_bind("", "") |
|---|
| 26 | |
|---|
| 27 | except ldap.SERVER_DOWN: |
|---|
| 28 | log("CRITICAL", "SERVER FAILED: DOWN") |
|---|
| 29 | return None |
|---|
| 30 | except: |
|---|
| 31 | log("CRITICAL", "SERVER FAILED: Unknown (Server wasn't detected down)") |
|---|
| 32 | return None |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | def listORGs(FQDN=False): |
|---|
| 36 | l=anonymousLDAPbind() |
|---|
| 37 | |
|---|
| 38 | if FQDN: |
|---|
| 39 | return [entry[1]['ou'][0] for entry in l.search_s(ldapBASE,1,'ou='+'*')] |
|---|
| 40 | else: |
|---|
| 41 | return [entry[1]['o'][0] for entry in l.search_s(ldapBASE,1,'o='+'*')] |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | def testUpLDAP(): |
|---|
| 45 | return anonymousLDAPbind() != None |
|---|
| 46 | |
|---|
| 47 | def getLDAPuidNumber(): |
|---|
| 48 | l=anonymousLDAPbind() |
|---|
| 49 | uidNumberList=[entry[1]['uidNumber'] for entry in l.search_s(ldapBASE,2,'uidNumber='+'*')] |
|---|
| 50 | uidNumberList.sort(reverse=True) |
|---|
| 51 | return uidNumberList[0]+1 |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | def checkORGApprovalMode(): |
|---|
| 55 | return None |
|---|
| 56 | |
|---|
| 57 | def checkORGCordinatorActivity(): |
|---|
| 58 | return None |
|---|
| 59 | |
|---|
| 60 | def grantORGCordinatorPasswordReset(): |
|---|
| 61 | return None |
|---|