Remove remaining bits of Bernard's postgres dispense
[uccvend-vendserver.git] / sql-edition / servers / LDAPConnector.py
index 6a8d67a..8699fd2 100644 (file)
@@ -10,10 +10,14 @@ def get_ldap_connection():
         ldap.set_option(ldap.OPT_X_TLS,1)
         ldap.set_option(ldap.OPT_X_TLS_ALLOW,1)
         #ldap.set_option(ldap.OPT_DEBUG_LEVEL,255)
-        conn = ldap.initialize('ldaps://mussel.ucc.gu.uwa.edu.au:636/')
+        conn = ldap.initialize('ldaps://mussel.ucc.gu.uwa.edu.au/')
         
-        # Anonymous bind - server ACLs should allow searching on uccDispenseMIFARE
-        conn.simple_bind_s()
+        binddn = 'cn=mifareagent,ou=profile,dc=ucc,dc=gu,dc=uwa,dc=edu,dc=au'
+        passfile = open('/etc/dispense2/ldap.passwd')
+        password = passfile.readline().strip()
+        passfile.close()
+        
+        conn.simple_bind_s(binddn, password)
         return conn
 
 def get_uid(card_id):
@@ -32,6 +36,22 @@ def get_uid(card_id):
         
         return results[0][1]['uidNumber'][0]
 
+def get_uname(uid):
+        ldapconn = get_ldap_connection()
+        
+        basedn = 'ou=People,dc=ucc,dc=gu,dc=uwa,dc=edu,dc=au'
+        filter = ldap.filter.filter_format('(uidNumber=%s)', (uid, ))
+        attrs = ('uid',)
+        
+        results = ldapconn.search_st(basedn, ldap.SCOPE_SUBTREE, filter, attrs, timeout=LDAP_TIMEOUT)
+        
+        ldapconn.unbind()
+        
+        if len(results) != 1:
+                raise ValueError, "no username found for user id"
+        
+        return results[0][1]['uid'][0]
+
 def set_card_id(uidNumber, card_id):
         ldapconn = get_ldap_connection()
         
@@ -68,5 +88,5 @@ def set_card_id(uidNumber, card_id):
             ldapconn.unbind()
 
 if __name__ == '__main__':
-        #print get_uid('\x01\x02\x03\x04\x05\x06')
-        set_card_id('11251', '\x01\x02\x03\x04\x05\x06')
+        set_card_id('11126', '\x01\x02\x03\x04\x05\x06')
+        print get_uid('\x01\x02\x03\x04\x05\x06')

UCC git Repository :: git.ucc.asn.au