Show
Ignore:
Timestamp:
05/28/04 22:56:45 (20 years ago)
Author:
jalet
Message:

Extended syntax for LDAP specific newuser and newgroup directives. Untested.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/storages/ldapstorage.py

    r1506 r1510  
    2222# 
    2323# $Log$ 
     24# Revision 1.66  2004/05/28 20:56:45  jalet 
     25# Extended syntax for LDAP specific newuser and newgroup directives. Untested. 
     26# 
    2427# Revision 1.65  2004/05/27 12:52:12  jalet 
    2528# More useful error message in case of misconfiguration of an LDAP  search base 
     
    762765        mustadd = 1 
    763766        if self.info["newuser"].lower() != 'below' : 
    764             result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (self.info["newuser"], self.info["userrdn"], user.Name), None, base=self.info["userbase"]) 
     767            try : 
     768                (where, action) = [s.strip() for s in self.info["newuser"].split(",")] 
     769            except ValueError : 
     770                (where, action) = (self.info["newuser"].strip(), "fail") 
     771            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["userrdn"], user.Name), None, base=self.info["userbase"]) 
    765772            if result : 
    766773                (dn, fields) = result[0] 
     
    769776                self.doModify(dn, fields) 
    770777                mustadd = 0 
     778            else : 
     779                message = _("Unable to find an existing entry to attach pykotaAccount objectclass %s") % user.Name 
     780                if action.lower() == "warn" :     
     781                    self.tool.logger.log_message("%s. A new entry will be created instead." % message, "warn") 
     782                else : # 'fail' or incorrect setting 
     783                    raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message 
    771784                 
    772785        if mustadd : 
     
    788801        mustadd = 1 
    789802        if self.info["newgroup"].lower() != 'below' : 
    790             result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (self.info["newgroup"], self.info["grouprdn"], group.Name), None, base=self.info["groupbase"]) 
     803            try : 
     804                (where, action) = [s.strip() for s in self.info["newgroup"].split(",")] 
     805            except ValueError : 
     806                (where, action) = (self.info["newgroup"].strip(), "fail") 
     807            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (where, self.info["grouprdn"], group.Name), None, base=self.info["groupbase"]) 
    791808            if result : 
    792809                (dn, fields) = result[0] 
     
    795812                self.doModify(dn, fields) 
    796813                mustadd = 0 
     814            else : 
     815                message = _("Unable to find an existing entry to attach pykotaGroup objectclass %s") % group.Name 
     816                if action.lower() == "warn" :     
     817                    self.tool.logger.log_message("%s. A new entry will be created instead." % message, "warn") 
     818                else : # 'fail' or incorrect setting 
     819                    raise PyKotaStorageError, "%s. Action aborted. Please check your configuration." % message 
    797820                 
    798821        if mustadd :