Index: /pykota/trunk/conf/pykota.conf.sample
===================================================================
--- /pykota/trunk/conf/pykota.conf.sample (revision 1095)
+++ /pykota/trunk/conf/pykota.conf.sample (revision 1105)
@@ -73,4 +73,19 @@
 #groupquotabase: ou=GQuotas,ou=PyKota,dc=librelogiciel,dc=com
 #lastjobbase: ou=LastJobs,ou=PyKota,dc=librelogiciel,dc=com
+#
+# How to create new accounts and groups
+# authorized values are "below" and "attach(objectclass name)"
+#
+# "below" creates the new accounts/groups as standalone entries
+# below the above defined 'userbase' ou
+# 
+# attach(objectclass name) tries to find some existing user/group
+# using the above defined 'userrdn' or 'grouprdn' and 'userbase'
+# 'groupbase', and attach the PyKota specific entries to it.
+#
+# a possible value:  newuser: attach(posixAccount)
+newuser : below
+newgroup : below
+
 # 
 # Choose what attribute contains the list of group members
Index: /pykota/trunk/setup.py
===================================================================
--- /pykota/trunk/setup.py (revision 1095)
+++ /pykota/trunk/setup.py (revision 1105)
@@ -23,4 +23,8 @@
 #
 # $Log$
+# Revision 1.21  2003/07/28 09:11:12  jalet
+# PyKota now tries to add its attributes intelligently in existing LDAP
+# directories.
+#
 # Revision 1.20  2003/07/23 16:51:32  jalet
 # waitprinter.sh is now included to prevent PyKota from asking the
@@ -241,4 +245,16 @@
             sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n")
             sys.exit(-1)
+            
+        # warns for new LDAP fields    
+        if sb.get("storagebackend") == "ldapstorage" :    
+            newuser = conf.getGlobalOption("newuser", ignore=1)
+            newgroup = conf.getGlobalOption("newgroup", ignore=1)
+            if not (newuser and newgroup) :
+                sys.stderr.write("From version 1.14 on, PyKota LDAP Support needs two additional configuration fields.\n")
+                sys.stderr.write("Please put the 'newuser' and 'newgroup' configuration fields in a [global] section in /etc/pykota/pykota.conf\n")
+                sys.stderr.write("You can look at the conf/pykota.conf.sample file for examples.\n")
+                sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n")
+                sys.stderr.write("INSTALLATION ABORTED BECAUSE CONFIGURATION INCOMPLETE.\n")
+                sys.exit(-1)
         
     # change files permissions    
Index: /pykota/trunk/pykota/storages/ldapstorage.py
===================================================================
--- /pykota/trunk/pykota/storages/ldapstorage.py (revision 1099)
+++ /pykota/trunk/pykota/storages/ldapstorage.py (revision 1105)
@@ -21,4 +21,8 @@
 #
 # $Log$
+# Revision 1.21  2003/07/28 09:11:12  jalet
+# PyKota now tries to add its attributes intelligently in existing LDAP
+# directories.
+#
 # Revision 1.20  2003/07/25 10:41:30  jalet
 # Better documentation.
@@ -468,26 +472,54 @@
     def addUser(self, user) :        
         """Adds a user to the quota storage, returns it."""
-        fields = { self.info["userrdn"] : user.Name,
-                   "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"],
-                   "cn" : user.Name,
-                   "pykotaUserName" : user.Name,
-                   "pykotaLimitBY" : (user.LimitBy or "quota"),
-                   "pykotaBalance" : str(user.AccountBalance or 0.0),
-                   "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0),
-                 } 
-        dn = "%s=%s,%s" % (self.info["userrdn"], user.Name, self.info["userbase"])
-        self.doAdd(dn, fields)
+        newfields = {
+                       "pykotaUserName" : user.Name,
+                       "pykotaLimitBY" : (user.LimitBy or "quota"),
+                       "pykotaBalance" : str(user.AccountBalance or 0.0),
+                       "pykotaLifeTimePaid" : str(user.LifeTimePaid or 0.0),
+                    }   
+        mustadd = 1
+        if self.info["newuser"].lower() != 'below' :
+            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (self.info["newuser"], self.info["userrdn"], user.Name), None, base=self.info["userbase"])
+            if result :
+                (dn, fields) = result[0]
+                fields["objectClass"].extend(["pykotaAccount", "pykotaAccountBalance"])
+                fields.update(newfields)
+                self.doModify(dn, fields)
+                mustadd = 0
+                
+        if mustadd :
+            fields = { self.info["userrdn"] : user.Name,
+                       "objectClass" : ["pykotaObject", "pykotaAccount", "pykotaAccountBalance"],
+                       "cn" : user.Name,
+                     } 
+            fields.update(newfields)         
+            dn = "%s=%s,%s" % (self.info["userrdn"], user.Name, self.info["userbase"])
+            self.doAdd(dn, fields)
         return self.getUser(user.Name)
         
     def addGroup(self, group) :        
         """Adds a group to the quota storage, returns it."""
-        fields = { self.info["grouprdn"] : group.Name,
-                   "objectClass" : ["pykotaObject", "pykotaGroup"],
-                   "cn" : group.Name,
-                   "pykotaGroupName" : group.Name,
-                   "pykotaLimitBY" : (group.LimitBy or "quota"),
-                 } 
-        dn = "%s=%s,%s" % (self.info["grouprdn"], group.Name, self.info["groupbase"])
-        self.doAdd(dn, fields)
+        newfields = { 
+                      "pykotaGroupName" : group.Name,
+                      "pykotaLimitBY" : (group.LimitBy or "quota"),
+                    } 
+        mustadd = 1
+        if self.info["newgroup"].lower() != 'below' :
+            result = self.doSearch("(&(objectClass=%s)(%s=%s))" % (self.info["newgroup"], self.info["grouprdn"], group.Name), None, base=self.info["groupbase"])
+            if result :
+                (dn, fields) = result[0]
+                fields["objectClass"].extend(["pykotaGroup"])
+                fields.update(newfields)
+                self.doModify(dn, fields)
+                mustadd = 0
+                
+        if mustadd :
+            fields = { self.info["grouprdn"] : group.Name,
+                       "objectClass" : ["pykotaObject", "pykotaGroup"],
+                       "cn" : group.Name,
+                     } 
+            fields.update(newfields)         
+            dn = "%s=%s,%s" % (self.info["grouprdn"], group.Name, self.info["groupbase"])
+            self.doAdd(dn, fields)
         return self.getGroup(group.Name)
         
Index: /pykota/trunk/pykota/config.py
===================================================================
--- /pykota/trunk/pykota/config.py (revision 1087)
+++ /pykota/trunk/pykota/config.py (revision 1105)
@@ -21,4 +21,8 @@
 #
 # $Log$
+# Revision 1.34  2003/07/28 09:11:12  jalet
+# PyKota now tries to add its attributes intelligently in existing LDAP
+# directories.
+#
 # Revision 1.33  2003/07/16 21:53:07  jalet
 # Really big modifications wrt new configuration file's location and content.
@@ -231,6 +235,10 @@
                         "userquotabase", "groupquotabase", \
                         "jobbase", "lastjobbase", \
+                        "newuser", "newgroup", \
                       ] :
-            ldapinfo[option] = self.getGlobalOption(option)
+            ldapinfo[option] = self.getGlobalOption(option).strip()
+        for field in ["newuser", "newgroup"] :
+            if ldapinfo[field].lower().startswith('attach(') :
+                ldapinfo[field] = ldapinfo[field][7:-1]
         return ldapinfo
         
Index: /pykota/trunk/pykota/version.py
===================================================================
--- /pykota/trunk/pykota/version.py (revision 1099)
+++ /pykota/trunk/pykota/version.py (revision 1105)
@@ -21,5 +21,5 @@
 #
 
-__version__ = "1.14alpha9_unofficial"
+__version__ = "1.14beta_unofficial"
 
 __doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng."""
Index: /pykota/trunk/bin/edpykota
===================================================================
--- /pykota/trunk/bin/edpykota (revision 1089)
+++ /pykota/trunk/bin/edpykota (revision 1105)
@@ -23,4 +23,8 @@
 #
 # $Log$
+# Revision 1.55  2003/07/28 09:11:12  jalet
+# PyKota now tries to add its attributes intelligently in existing LDAP
+# directories.
+#
 # Revision 1.54  2003/07/21 06:32:42  jalet
 # Prevents email messages to be sent at modification/creation time for
@@ -445,4 +449,5 @@
                 else :        
                     self.logger.log_message(_("Prototype object %s not found in Quota Storage.") % protoentry.Name)
+                    
             if not options["noquota"] :    
                 if hardlimit is None :    
@@ -469,5 +474,6 @@
                     if not options["groups"] :
                         changed[entry.Name]["ingroups"] = []
-                if not entrypquota.Exists :
+                        
+                if not entry.Exists :        
                     # not found
                     if options["add"] :
@@ -477,7 +483,5 @@
                         # only remotely
                         if self.isValidName(entry.Name) :
-                            if not entry.Exists :
-                                entry = getattr(self.storage, "add%s" % suffix)(entry)
-                            entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer)
+                            entry = getattr(self.storage, "add%s" % suffix)(entry)
                         else :    
                             if options["groups"] :
@@ -485,4 +489,10 @@
                             else :    
                                 self.logger.log_message(_("Invalid user name %s") % entry.Name)
+                                
+                if not entrypquota.Exists :
+                    # not found
+                    if options["add"] :
+                        entrypquota = getattr(self.storage, "add%sPQuota" % suffix)(entry, printer)
+                        
                 if not entrypquota.Exists :     
                     self.logger.log_message(_("Quota not found for object %s on printer %s.") % (entry.Name, printer.Name))
Index: /pykota/trunk/NEWS
===================================================================
--- /pykota/trunk/NEWS (revision 1099)
+++ /pykota/trunk/NEWS (revision 1105)
@@ -22,4 +22,11 @@
 PyKota NEWS :
 
+    - 1.14beta :
+    
+        - Two new LDAP-specific configuration fields were introduced,
+          newuser and newgroup. Use them to specify if you want to add
+          quota information to existing entries or elsewhere.
+          See sample configuration file for details.
+          
     - 1.14alpha9 :
     
