Adding federated user in LDAP.sed on email
[sfa.git] / sfa / senslab / LDAPapi.py
1 import random
2 from passlib.hash import ldap_salted_sha1 as lssha
3 from sfa.util.xrn import get_authority 
4 import ldap
5 from sfa.util.config import Config
6 from sfa.trust.hierarchy import Hierarchy
7
8 import ldap.modlist as modlist
9 from sfa.util.sfalogging import logger
10 import os.path
11
12 #API for OpenLDAP
13
14
15 class LdapConfig():
16     def __init__(self, config_file =  '/etc/sfa/ldap_config.py'):
17         
18         try:
19             execfile(config_file, self.__dict__)
20        
21             self.config_file = config_file
22             # path to configuration data
23             self.config_path = os.path.dirname(config_file)
24         except IOError:
25             raise IOError, "Could not find or load the configuration file: %s" \
26                             % config_file
27   
28         
29 class ldap_co:
30     """ Set admin login and server configuration variables."""
31     
32     def __init__(self):
33         #Senslab PROD LDAP parameters
34         self.ldapserv = None
35         ldap_config = LdapConfig()
36         self.config = ldap_config
37         self.ldapHost = ldap_config.LDAP_IP_ADDRESS 
38         self.ldapPeopleDN = ldap_config.LDAP_PEOPLE_DN
39         self.ldapGroupDN = ldap_config.LDAP_GROUP_DN
40         self.ldapAdminDN = ldap_config.LDAP_WEB_DN
41         self.ldapAdminPassword = ldap_config.LDAP_WEB_PASSWORD
42
43
44         self.ldapPort = ldap.PORT
45         self.ldapVersion  = ldap.VERSION3
46         self.ldapSearchScope = ldap.SCOPE_SUBTREE
47
48
49     def connect(self, bind = True):
50         """Enables connection to the LDAP server.
51         Set the bind parameter to True if a bind is needed
52         (for add/modify/delete operations).
53         Set to False otherwise.
54         
55         """
56         try:
57             self.ldapserv = ldap.open(self.ldapHost)
58         except ldap.LDAPError, error:
59             return {'bool' : False, 'message' : error }
60         
61         # Bind with authentification
62         if(bind): 
63             return self.bind()
64         
65         else:     
66             return {'bool': True} 
67     
68     def bind(self):
69         """ Binding method. """
70         try:
71             # Opens a connection after a call to ldap.open in connect:
72             self.ldapserv = ldap.initialize("ldap://" + self.ldapHost)
73                 
74             # Bind/authenticate with a user with apropriate 
75             #rights to add objects
76             self.ldapserv.simple_bind_s(self.ldapAdminDN, \
77                                     self.ldapAdminPassword)
78
79         except ldap.LDAPError, error:
80             return {'bool' : False, 'message' : error }
81
82         return {'bool': True}
83     
84     def close(self):
85         """ Close the LDAP connection """
86         try:
87             self.ldapserv.unbind_s()
88         except ldap.LDAPError, error:
89             return {'bool' : False, 'message' : error }
90             
91         
92 class LDAPapi :
93     def __init__(self):
94         logger.setLevelDebug() 
95         #SFA related config
96         self.senslabauth = Hierarchy()
97         config = Config()
98         
99         self.authname = config.SFA_REGISTRY_ROOT_AUTH
100
101         self.conn =  ldap_co() 
102         self.ldapUserQuotaNFS = self.conn.config.LDAP_USER_QUOTA_NFS 
103         self.ldapUserUidNumberMin = self.conn.config.LDAP_USER_UID_NUMBER_MIN 
104         self.ldapUserGidNumber = self.conn.config.LDAP_USER_GID_NUMBER 
105         self.ldapUserHomePath = self.conn.config.LDAP_USER_HOME_PATH 
106         
107         self.lengthPassword = 8
108         self.baseDN = self.conn.ldapPeopleDN
109         #authinfo=self.senslabauth.get_auth_info(self.authname)
110         
111         
112         self.charsPassword = [ '!','$','(',')','*','+',',','-','.', \
113                                 '0','1','2','3','4','5','6','7','8','9', \
114                                 'A','B','C','D','E','F','G','H','I','J', \
115                                 'K','L','M','N','O','P','Q','R','S','T', \
116                                 'U','V','W','X','Y','Z','_','a','b','c', \
117                                 'd','e','f','g','h','i','j','k','l','m', \
118                                 'n','o','p','q','r','s','t','u','v','w', \
119                                 'x','y','z','\'']
120         
121         self.ldapShell = '/bin/bash'
122
123     
124     def generate_login(self, record):
125         """Generate login for adding a new user in LDAP Directory 
126         (four characters minimum length)
127         Record contains first name and last name.
128         
129         """ 
130         if 'first_name' in record and 'last_name' in record:
131             #Remove all special characters from first_name/last name
132             lower_first_name = record['first_name'].replace('-','')\
133                                             .replace('_','').replace('[','')\
134                                             .replace(']','').replace(' ','')\
135                                             .lower()
136             lower_last_name = record['last_name'].replace('-','')\
137                                             .replace('_','').replace('[','')\
138                                             .replace(']','').replace(' ','')\
139                                             .lower()  
140
141             
142         #No first name and last name 
143         #check  email    
144         else:
145             email = record['mail']
146             email = email.split('@')[0].lower()
147             lower_first_name = None
148             lower_last_name = None
149             #Assume there is first name and last name in email
150             #if there is a  separator
151             separator_list = ['.','_','-']
152             for sep in separator_list:
153                 if sep in email:
154                     mail = email.split(sep)
155                     lower_first_name = mail[0]
156                     lower_last_name = mail[1]
157                     break
158             #Otherwise just take the part before the @ as the 
159             #lower_first_name  and lower_last_name
160             if lower_first_name is None:
161                lower_first_name = email
162                lower_last_name = email
163                
164         length_last_name = len(lower_last_name)  
165         login_max_length = 8
166         
167         #Try generating a unique login based on first name and last name
168         getAttrs = ['uid']
169         if length_last_name >= login_max_length :
170             login = lower_last_name[0:login_max_length]
171             index = 0
172             logger.debug("login : %s index : %s" %(login, index))
173         elif length_last_name >= 4 :
174             login = lower_last_name
175             index = 0
176             logger.debug("login : %s index : %s" %(login, index))
177         elif length_last_name == 3 :
178             login = lower_first_name[0:1] + lower_last_name
179             index = 1
180             logger.debug("login : %s index : %s" %(login, index))
181         elif length_last_name == 2:
182             if len ( lower_first_name) >=2:
183                 login = lower_first_name[0:2] + lower_last_name
184                 index = 2
185                 logger.debug("login : %s index : %s" %(login, index))
186             else:
187                 logger.error("LoginException : \
188                             Generation login error with \
189                             minimum four characters")
190             
191                 
192         else :
193             logger.error("LDAP generate_login failed : \
194                             impossible to generate unique login for %s %s" \
195                             %(lower_first_name,lower_last_name))
196             
197         login_filter = '(uid=' + login + ')'
198         
199         try :
200             #Check if login already in use
201             while (len(self.LdapSearch(login_filter, getAttrs)) is not 0 ):
202             
203                 index += 1
204                 if index >= 9:
205                     logger.error("LoginException : Generation login error \
206                                     with minimum four characters")
207                 else:
208                     try:
209                         login = lower_first_name[0:index] + \
210                                     lower_last_name[0:login_max_length-index]
211                         login_filter = '(uid='+ login+ ')'
212                     except KeyError:
213                         print "lower_first_name - lower_last_name too short"
214                         
215             logger.debug("LDAP.API \t generate_login login %s" %(login))
216             return login
217                     
218         except  ldap.LDAPError, error :
219             logger.log_exc("LDAP generate_login Error %s" %error)
220             return None
221
222         
223
224     def generate_password(self):
225     
226         """Generate password for adding a new user in LDAP Directory 
227         (8 characters length) return password
228         
229         """
230         password = str()
231         length = len(self.charsPassword)
232         for index in range(self.lengthPassword):
233             char_index = random.randint(0, length-1)
234             password += self.charsPassword[char_index]
235
236         return password
237
238     def encrypt_password(self, password):
239         """ Use passlib library to make a RFC2307 LDAP encrypted password
240         salt size = 8, use sha-1 algorithm. Returns encrypted password.
241         
242         """
243         #Keep consistency with Java Senslab's LDAP API 
244         #RFC2307SSHAPasswordEncryptor so set the salt size to 8 bytres
245         return lssha.encrypt(password, salt_size = 8)
246     
247
248
249     def find_max_uidNumber(self):
250             
251         """Find the LDAP max uidNumber (POSIX uid attribute) .
252         Used when adding a new user in LDAP Directory 
253         returns string  max uidNumber + 1
254         
255         """
256         #First, get all the users in the LDAP
257         getAttrs = "(uidNumber=*)"
258         login_filter = ['uidNumber']
259
260         result_data = self.LdapSearch(getAttrs, login_filter) 
261         #It there is no user in LDAP yet, First LDAP user
262         if result_data == []:
263             max_uidnumber = self.ldapUserUidNumberMin
264         #Otherwise, get the highest uidNumber
265         else:
266             
267             uidNumberList = [int(r[1]['uidNumber'][0])for r in result_data ]
268             logger.debug("LDAPapi.py \tfind_max_uidNumber  \
269                                     uidNumberList %s " %(uidNumberList))
270             max_uidnumber = max(uidNumberList) + 1
271             
272         return str(max_uidnumber)
273          
274          
275     def get_ssh_pkey(self, record):
276         """TODO ; Get ssh public key from sfa record  
277         To be filled by N. Turro ? or using GID pl way?
278         
279         """
280         return 'A REMPLIR '
281
282     def make_ldap_filters_from_record(self, record=None):
283         """TODO Handle OR filtering in the ldap query when 
284         dealing with a list of records instead of doing a for loop in GetPersons   
285         Helper function to make LDAP filter requests out of SFA records.
286         """
287         req_ldap = ''
288         req_ldapdict = {}
289         if record :
290             if 'first_name' in record  and 'last_name' in record:
291                 req_ldapdict['cn'] = str(record['first_name'])+" "\
292                                         + str(record['last_name'])
293             if 'email' in record :
294                 req_ldapdict['mail'] = record['email']
295             if 'mail' in record:
296                 req_ldapdict['mail'] = record['mail']
297             if 'enabled' in record:
298                 if record['enabled'] == True :
299                     req_ldapdict['shadowExpire'] = '-1'
300                 else:
301                     req_ldapdict['shadowExpire'] = '0'
302                 
303             #Hrn should not be part of the filter because the hrn 
304             #presented by a certificate of a SFA user not imported in 
305             #Senslab  does not include the senslab login in it 
306             #Plus, the SFA user may already have an account with senslab
307             #using another login.
308                 
309            
310
311             logger.debug("\r\n \t LDAP.PY make_ldap_filters_from_record \
312                                 record %s req_ldapdict %s" \
313                                 %(record, req_ldapdict))
314             
315             for k in req_ldapdict:
316                 req_ldap += '('+ str(k)+ '=' + str(req_ldapdict[k]) + ')'
317             if  len(req_ldapdict.keys()) >1 :
318                 req_ldap = req_ldap[:0]+"(&"+req_ldap[0:]
319                 size = len(req_ldap)
320                 req_ldap = req_ldap[:(size-1)] +')'+ req_ldap[(size-1):]
321         else:
322             req_ldap = "(cn=*)"
323         
324         return req_ldap
325         
326     def make_ldap_attributes_from_record(self, record):
327         """When addind a new user to Senslab's LDAP, creates an attributes 
328         dictionnary from the SFA record.
329         
330         """
331
332         attrs = {}
333         attrs['objectClass'] = ["top", "person", "inetOrgPerson", \
334                                     "organizationalPerson", "posixAccount", \
335                                     "shadowAccount", "systemQuotas", \
336                                     "ldapPublicKey"]
337         
338         attrs['givenName'] = str(record['first_name']).lower().capitalize()
339         attrs['sn'] = str(record['last_name']).lower().capitalize()
340         attrs['cn'] = attrs['givenName'] + ' ' + attrs['sn']
341         attrs['gecos'] = attrs['givenName'] + ' ' + attrs['sn']
342         attrs['uid'] = self.generate_login(record)   
343                     
344         attrs['quota'] = self.ldapUserQuotaNFS 
345         attrs['homeDirectory'] = self.ldapUserHomePath + attrs['uid']
346         attrs['loginShell'] = self.ldapShell
347         attrs['gidNumber'] = self.ldapUserGidNumber
348         attrs['uidNumber'] = self.find_max_uidNumber()
349         attrs['mail'] = record['mail'].lower()
350         try:
351             attrs['sshPublicKey'] = record['pkey']
352         except KeyError:
353             attrs['sshPublicKey'] = self.get_ssh_pkey(record) 
354         
355
356         #Password is automatically generated because SFA user don't go 
357         #through the Senslab website  used to register new users, 
358         #There is no place in SFA where users can enter such information
359         #yet.
360         #If the user wants to set his own password , he must go to the Senslab 
361         #website.
362         password = self.generate_password()
363         attrs['userPassword'] = self.encrypt_password(password)
364         
365         #Account automatically validated (no mail request to admins)
366         #Set to 0 to disable the account, -1 to enable it,
367         attrs['shadowExpire'] = '-1'
368
369         #Motivation field in Senslab
370         attrs['description'] = 'SFA USER FROM OUTSIDE SENSLAB'
371
372         attrs['ou'] = 'SFA'         #Optional: organizational unit
373         #No info about those here:
374         attrs['l'] = 'To be defined'#Optional: Locality. 
375         attrs['st'] = 'To be defined' #Optional: state or province (country).
376
377         return attrs
378
379
380
381     def LdapAddUser(self, record) :
382         """Add SFA user to LDAP if it is not in LDAP  yet. """
383         
384         user_ldap_attrs = self.make_ldap_attributes_from_record(record)
385
386         
387         #Check if user already in LDAP wih email, first name and last name
388         filter_by = self.make_ldap_filters_from_record(user_ldap_attrs)
389         user_exist = self.LdapSearch(filter_by)
390         if user_exist:
391             logger.warning(" \r\n \t LDAP LdapAddUser user %s %s \
392                         already exists" %(user_ldap_attrs['sn'], \
393                         user_ldap_attrs['mail'])) 
394             return {'bool': False}
395         
396         #Bind to the server
397         result = self.conn.connect()
398         
399         if(result['bool']):
400             
401             # A dict to help build the "body" of the object
402             
403             logger.debug(" \r\n \t LDAP LdapAddUser attrs %s " %user_ldap_attrs)
404
405             # The dn of our new entry/object
406             dn = 'uid=' + user_ldap_attrs['uid'] + "," + self.baseDN 
407
408             try:
409                 ldif = modlist.addModlist(user_ldap_attrs)
410                 logger.debug("LDAPapi.py add attrs %s \r\n  ldif %s"\
411                                 %(user_ldap_attrs,ldif) )
412                 self.conn.ldapserv.add_s(dn,ldif)
413                 
414                 logger.info("Adding user %s login %s in LDAP" \
415                         %(user_ldap_attrs['cn'] ,user_ldap_attrs['uid']))
416                         
417                         
418             except ldap.LDAPError, error:
419                 logger.log_exc("LDAP Add Error %s" %error)
420                 return {'bool' : False, 'message' : error }
421         
422             self.conn.close()
423             return {'bool': True}  
424         else: 
425             return result
426
427         
428     def LdapDelete(self, person_dn):
429         """
430         Deletes a person in LDAP. Uses the dn of the user.
431         """
432         #Connect and bind   
433         result =  self.conn.connect()
434         if(result['bool']):
435             try:
436                 self.conn.ldapserv.delete_s(person_dn)
437                 self.conn.close()
438                 return {'bool': True}
439             
440             except ldap.LDAPError, error:
441                 logger.log_exc("LDAP Delete Error %s" %error)
442                 return {'bool': False}
443         
444     
445     def LdapDeleteUser(self, record_filter): 
446         """
447         Deletes a SFA person in LDAP, based on the user's hrn.
448         """
449         #Find uid of the  person 
450         person = self.LdapFindUser(record_filter,[])
451         logger.debug("LDAPapi.py \t LdapDeleteUser record %s person %s" \
452         %(record_filter, person))
453
454         if person:
455             dn = 'uid=' + person['uid'] + "," +self.baseDN 
456         else:
457             return {'bool': False}
458         
459         result = self.LdapDelete(dn)
460         return result
461         
462
463     def LdapModify(self, dn, old_attributes_dict, new_attributes_dict): 
464         """ Modifies a LDAP entry """
465          
466         ldif = modlist.modifyModlist(old_attributes_dict,new_attributes_dict)
467         # Connect and bind/authenticate    
468         result = self.conn.connect() 
469         if (result['bool']): 
470             try:
471                 self.conn.ldapserv.modify_s(dn,ldif)
472                 self.conn.close()
473                 return {'bool' : True }
474             except ldap.LDAPError, error:
475                 logger.log_exc("LDAP LdapModify Error %s" %error)
476                 return {'bool' : False }
477     
478         
479     def LdapModifyUser(self, user_record, new_attributes_dict):
480         """
481         Gets the record from one user_uid_login based on record_filter 
482         and changes the attributes according to the specified new_attributes.
483         Does not use this if we need to modify the uid. Use a ModRDN 
484         #operation instead ( modify relative DN )
485         """
486         if user_record is None:
487             logger.error("LDAP \t LdapModifyUser Need user record  ")
488             return {'bool': False} 
489         
490         #Get all the attributes of the user_uid_login 
491         #person = self.LdapFindUser(record_filter,[])
492         req_ldap = self.make_ldap_filters_from_record(user_record)
493         person_list = self.LdapSearch(req_ldap,[])
494         logger.debug("LDAPapi.py \t LdapModifyUser person_list : %s" \
495                                                         %(person_list))
496         if person_list and len(person_list) > 1 :
497             logger.error("LDAP \t LdapModifyUser Too many users returned")
498             return {'bool': False}
499         if person_list is None :
500             logger.error("LDAP \t LdapModifyUser  User %s doesn't exist "\
501                         %(user_record))
502             return {'bool': False} 
503         
504         # The dn of our existing entry/object
505         #One result only from ldapSearch
506         person = person_list[0][1]
507         dn  = 'uid=' + person['uid'][0] + "," +self.baseDN  
508        
509         if new_attributes_dict:
510             old = {}
511             for k in new_attributes_dict:
512                 if k not in person:
513                     old[k] =  ''
514                 else :
515                     old[k] = person[k]
516             logger.debug(" LDAPapi.py \t LdapModifyUser  new_attributes %s"\
517                                 %( new_attributes_dict))  
518             result = self.LdapModify(dn, old,new_attributes_dict)
519             return result
520         else:
521             logger.error("LDAP \t LdapModifyUser  No new attributes given. ")
522             return {'bool': False} 
523             
524             
525             
526             
527     def LdapMarkUserAsDeleted(self, record): 
528
529         
530         new_attrs = {}
531         #Disable account
532         new_attrs['shadowExpire'] = '0'
533         logger.debug(" LDAPapi.py \t LdapMarkUserAsDeleted ")
534         ret = self.LdapModifyUser(record, new_attrs)
535         return ret
536
537             
538     def LdapResetPassword(self,record):
539         """
540         Resets password for the user whose record is the parameter and changes
541         the corresponding entry in the LDAP.
542         
543         """
544         password = self.generate_password()
545         attrs = {}
546         attrs['userPassword'] = self.encrypt_password(password)
547         logger.debug("LDAP LdapResetPassword encrypt_password %s"\
548                     %(attrs['userPassword']))
549         result = self.LdapModifyUser(record, attrs)
550         return result
551         
552         
553     def LdapSearch (self, req_ldap = None, expected_fields = None ):
554         """
555         Used to search directly in LDAP, by using ldap filters and
556         return fields. 
557         When req_ldap is None, returns all the entries in the LDAP.
558       
559         """
560         result = self.conn.connect(bind = False)
561         if (result['bool']) :
562             
563             return_fields_list = []
564             if expected_fields == None : 
565                 return_fields_list = ['mail','givenName', 'sn', 'uid', \
566                                         'sshPublicKey', 'shadowExpire']
567             else : 
568                 return_fields_list = expected_fields
569             #No specifc request specified, get the whole LDAP    
570             if req_ldap == None:
571                 req_ldap = '(cn=*)'
572                
573             logger.debug("LDAP.PY \t LdapSearch  req_ldap %s \
574                                     return_fields_list %s" \
575                                     %(req_ldap, return_fields_list))
576
577             try:
578                 msg_id = self.conn.ldapserv.search(
579                                             self.baseDN,ldap.SCOPE_SUBTREE,\
580                                             req_ldap, return_fields_list)     
581                 #Get all the results matching the search from ldap in one 
582                 #shot (1 value)
583                 result_type, result_data = \
584                                         self.conn.ldapserv.result(msg_id,1)
585
586                 self.conn.close()
587
588                 logger.debug("LDAP.PY \t LdapSearch  result_data %s"\
589                             %(result_data))
590
591                 return result_data
592             
593             except  ldap.LDAPError,error :
594                 logger.log_exc("LDAP LdapSearch Error %s" %error)
595                 return []
596             
597             else:
598                 logger.error("LDAP.PY \t Connection Failed" )
599                 return 
600         
601     def LdapFindUser(self, record = None, is_user_enabled=None, \
602             expected_fields = None):
603         """
604         Search a SFA user with a hrn. User should be already registered 
605         in Senslab LDAP. 
606         Returns one matching entry 
607         """   
608         custom_record = {}
609         if is_user_enabled: 
610           
611             custom_record['enabled'] = is_user_enabled
612         if record:  
613             custom_record.update(record)
614
615
616         req_ldap = self.make_ldap_filters_from_record(custom_record)     
617         return_fields_list = []
618         if expected_fields == None : 
619             return_fields_list = ['mail','givenName', 'sn', 'uid', \
620                                     'sshPublicKey']
621         else : 
622             return_fields_list = expected_fields
623             
624         result_data = self.LdapSearch(req_ldap, return_fields_list )
625         logger.debug("LDAP.PY \t LdapFindUser  result_data %s" %(result_data))
626            
627         if len(result_data) is 0:
628             return None
629         #Asked for a specific user
630         if record :
631             #try:
632             ldapentry = result_data[0][1]
633             logger.debug("LDAP.PY \t LdapFindUser ldapentry %s" %(ldapentry))
634             tmpname = ldapentry['uid'][0]
635
636             tmpemail = ldapentry['mail'][0]
637             if ldapentry['mail'][0] == "unknown":
638                 tmpemail = None
639                     
640             #except IndexError: 
641                 #logger.error("LDAP ldapFindHRn : no entry for record %s found"\
642                             #%(record))
643                 #return None
644                 
645             try:
646                 hrn = record['hrn']
647                 parent_hrn = get_authority(hrn)
648                 peer_authority = None
649                 if parent_hrn is not self.authname:
650                     peer_authority = parent_hrn
651
652                 results =  {    
653                             'type': 'user',
654                             'pkey': ldapentry['sshPublicKey'][0],
655                             #'uid': ldapentry[1]['uid'][0],
656                             'uid': tmpname ,
657                             'email':tmpemail,
658                             #'email': ldapentry[1]['mail'][0],
659                             'first_name': ldapentry['givenName'][0],
660                             'last_name': ldapentry['sn'][0],
661                             #'phone': 'none',
662                             'serial': 'none',
663                             'authority': parent_hrn,
664                             'peer_authority': peer_authority,
665                             'pointer' : -1,
666                             'hrn': hrn,
667                             }
668             except KeyError,error:
669                 logger.log_exc("LDAPapi \t LdaFindUser KEyError %s" \
670                                 %error )
671                 return
672         else:
673         #Asked for all users in ldap
674             results = []
675             for ldapentry in result_data:
676                 logger.debug(" LDAP.py LdapFindUser ldapentry name : %s " \
677                                 %(ldapentry[1]['uid'][0]))
678                 tmpname = ldapentry[1]['uid'][0]
679                 hrn=self.authname+"."+ tmpname
680                 
681                 tmpemail = ldapentry[1]['mail'][0]
682                 if ldapentry[1]['mail'][0] == "unknown":
683                     tmpemail = None
684
685         
686                 parent_hrn = get_authority(hrn)
687                 parent_auth_info = self.senslabauth.get_auth_info(parent_hrn)
688                 try:
689                     results.append(  {  
690                             'type': 'user',
691                             'pkey': ldapentry[1]['sshPublicKey'][0],
692                             #'uid': ldapentry[1]['uid'][0],
693                             'uid': tmpname ,
694                             'email':tmpemail,
695                             #'email': ldapentry[1]['mail'][0],
696                             'first_name': ldapentry[1]['givenName'][0],
697                             'last_name': ldapentry[1]['sn'][0],
698                             #'phone': 'none',
699                             'serial': 'none',
700                             'authority': self.authname,
701                             'peer_authority': '',
702                             'pointer' : -1,
703                             'hrn': hrn,
704                             } ) 
705                 except KeyError,error:
706                     logger.log_exc("LDAPapi.PY \t LdapFindUser EXCEPTION %s" \
707                                                 %(error))
708                     return
709         return results   
710