Changeset 1087

Show
Ignore:
Timestamp:
07/16/03 23:53:08 (21 years ago)
Author:
jalet
Message:

Really big modifications wrt new configuration file's location and content.

Location:
pykota/trunk
Files:
1 added
11 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/conf/pykota.conf.sample

    r1077 r1087  
    11# PyKota sample configuration file 
    22# 
    3 # Copy this file in cups' configuration directory 
    4 # usually /etc/cups under the name pykota.conf 
     3# Copy this file into the /etc/pykota/ directory 
     4# under the name /etc/pykota/pykota.conf 
    55# 
    66# PyKota - Print Quotas for CUPS and LPRng 
     
    4040storagename: pykota 
    4141 
    42 # Quota Storage administrator's and normal user's names and passwords 
    43 storageadmin: pykotaadmin 
    44 # storageadminpw: Comment out if unused, or set to Quota Storage admin password 
     42#  
     43# Quota Storage normal user's name and password 
     44# These two fields contain a username and optional password  
     45# which may give readonly access to your print quota database. 
     46#  
     47# PLEASE ENSURE THAT THIS USER CAN'T WRITE TO YOUR PRINT QUOTA 
     48# DATABASE, OTHERWISE ANY USER WHO COULD READ THIS CONFIGURATION 
     49# FILE COULD CHANGE HIS PRINT QUOTA. 
     50# 
     51storageuser: pykotauser 
     52# storageuserpw: Comment out if unused, or set to Quota Storage user password 
    4553 
    4654# NB : storageuser and storageuserpw are not used anymore 
     
    5058#storageserver: ldap://ldap.librelogiciel.com:389 
    5159#storagename: dc=librelogiciel,dc=com 
    52 #storageadmin: cn=admin,dc=librelogiciel,dc=com 
    53 #storageadminpw: abc.123 
     60#storageuser: cn=notadmin,dc=librelogiciel,dc=com 
     61#storageuserpw: abc.123 
    5462# 
    5563# Here we define some helpers to know where  
  • pykota/trunk/initscripts/postgresql/pykota-postgresql.sql

    r1079 r1087  
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.4  2003/07/16 21:53:07  jalet 
     23-- Really big modifications wrt new configuration file's location and content. 
     24-- 
    2225-- Revision 1.3  2003/07/09 20:17:07  jalet 
    2326-- Email field added to PostgreSQL schema 
     
    5154--  
    5255CREATE USER pykotaadmin; 
     56CREATE USER pykotauser; 
    5357 
    5458--  
     
    127131-- 
    128132REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM public;                         
     133REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq FROM public; 
     134 
    129135GRANT SELECT, INSERT, UPDATE, DELETE, REFERENCES ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotaadmin; 
    130136GRANT SELECT, UPDATE ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq TO pykotaadmin; 
     137GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotauser; 
    131138 
  • pykota/trunk/initscripts/postgresql/upgrade-to-1.14.sql

    r1079 r1087  
    2020-- 
    2121-- $Log$ 
     22-- Revision 1.2  2003/07/16 21:53:07  jalet 
     23-- Really big modifications wrt new configuration file's location and content. 
     24-- 
    2225-- Revision 1.1  2003/07/09 20:17:07  jalet 
    2326-- Email field added to PostgreSQL schema 
     
    4043-- 
    4144ALTER TABLE users ADD COLUMN email TEXT; 
     45CREATE USER pykotauser; 
     46REVOKE ALL ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory FROM pykotauser; 
     47REVOKE ALL ON users_id_seq, groups_id_seq, printers_id_seq, userpquota_id_seq, grouppquota_id_seq, jobhistory_id_seq FROM pykotauser; 
     48GRANT SELECT ON users, groups, printers, userpquota, grouppquota, groupsmembers, jobhistory TO pykotauser; 
  • pykota/trunk/NEWS

    r1085 r1087  
    2222PyKota NEWS : 
    2323 
     24    - 1.14alpha6 : 
     25     
     26        - Configuration file split and moved to /etc/pykota/pykota.conf 
     27          and /etc/pykota/pykotadmin.conf to prevent simple users to 
     28          have Read/Write access to the Quota Database. 
     29          Don't forget to : 
     30           
     31                $ chmod 640 /etc/pykota/pykotadmin.conf 
     32                 
     33        - storageuser and storageuserpw configuration fields reintroduced 
     34          for the same reason. 
     35           
     36        - Code cleaning for future implementation of email addresses  
     37          support in the PostgreSQL and LDAP backends. 
     38           
    2439    - 1.14alpha5 : 
    2540         
  • pykota/trunk/pykota/config.py

    r1077 r1087  
    2121# 
    2222# $Log$ 
     23# Revision 1.33  2003/07/16 21:53:07  jalet 
     24# Really big modifications wrt new configuration file's location and content. 
     25# 
    2326# Revision 1.32  2003/07/08 19:43:51  jalet 
    2427# Configurable warning messages. 
     
    200203        backendinfo = {} 
    201204        for option in [ "storagebackend", "storageserver", \ 
    202                         "storagename", "storageadmin", \ 
     205                        "storagename", "storageuser", \ 
    203206                      ] : 
    204207            backendinfo[option] = self.getGlobalOption(option) 
    205         backendinfo["storageadminpw"] = self.getGlobalOption("storageadminpw", ignore=1) 
     208        backendinfo["storageuserpw"] = self.getGlobalOption("storageuserpw", ignore=1)  # password is optional 
     209        backendinfo["storageadmin"] = None 
     210        backendinfo["storageadminpw"] = None 
     211        adminconf = ConfigParser.ConfigParser() 
     212        adminconf.read(["/etc/pykota/pykotadmin.conf"]) 
     213        if adminconf.sections() : # were we able to read the file ? 
     214            try : 
     215                backendinfo["storageadmin"] = adminconf.get("global", "storageadmin", raw=1) 
     216            except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     217                raise PyKotaConfigError, _("Option %s not found in section global of %s") % ("storageadmin", "/etc/pykota/pykotadmin.conf") 
     218            try : 
     219                backendinfo["storageadminpw"] = adminconf.get("global", "storageadminpw", raw=1) 
     220            except (ConfigParser.NoSectionError, ConfigParser.NoOptionError) :     
     221                pass # Password is optional 
    206222        return backendinfo 
    207223         
  • pykota/trunk/pykota/storage.py

    r1067 r1087  
    2121# 
    2222# $Log$ 
     23# Revision 1.19  2003/07/16 21:53:07  jalet 
     24# Really big modifications wrt new configuration file's location and content. 
     25# 
    2326# Revision 1.18  2003/07/07 08:33:18  jalet 
    2427# Bug fix due to a typo in LDAP code 
     
    314317        host = backendinfo["storageserver"] 
    315318        database = backendinfo["storagename"] 
    316         admin = backendinfo["storageadmin"] 
    317         adminpw = backendinfo["storageadminpw"] 
     319        admin = backendinfo["storageadmin"] or backendinfo["storageuser"] 
     320        adminpw = backendinfo["storageadminpw"] or backendinfo["storageuserpw"] 
    318321        return getattr(storagebackend, "Storage")(pykotatool, host, database, admin, adminpw) 
    319322 
  • pykota/trunk/pykota/storages/pgstorage.py

    r1085 r1087  
    2121# 
    2222# $Log$ 
     23# Revision 1.10  2003/07/16 21:53:08  jalet 
     24# Really big modifications wrt new configuration file's location and content. 
     25# 
    2326# Revision 1.9  2003/07/14 17:20:15  jalet 
    2427# Bug in postgresql storage when modifying the prices for a printer 
     
    333336    def addUser(self, user) :         
    334337        """Adds a user to the quota storage, returns its id.""" 
    335         self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid) VALUES (%s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy), self.doQuote(user.AccountBalance), self.doQuote(user.LifeTimePaid))) 
     338        self.doModify("INSERT INTO users (username, limitby, balance, lifetimepaid, email) VALUES (%s, %s, %s, %s, %s)" % (self.doQuote(user.Name), self.doQuote(user.LimitBy), self.doQuote(user.AccountBalance), self.doQuote(user.LifeTimePaid), self.doQuote(user.Email))) 
    336339        return self.getUser(user.Name) 
    337340         
  • pykota/trunk/pykota/tool.py

    r1079 r1087  
    2121# 
    2222# $Log$ 
     23# Revision 1.47  2003/07/16 21:53:08  jalet 
     24# Really big modifications wrt new configuration file's location and content. 
     25# 
    2326# Revision 1.46  2003/07/09 20:17:07  jalet 
    2427# Email field added to PostgreSQL schema 
     
    223226        # pykota specific stuff 
    224227        self.documentation = doc 
    225         self.config = config.PyKotaConfig("/etc") 
     228        self.config = config.PyKotaConfig("/etc/pykota") 
    226229        self.logger = logger.openLogger(self) 
    227230        self.storage = storage.openConnection(self) 
  • pykota/trunk/pykota/version.py

    r1085 r1087  
    2121# 
    2222 
    23 __version__ = "1.14alpha5_unofficial" 
     23__version__ = "1.14alpha6_unofficial" 
    2424 
    2525__doc__ = """PyKota : a complete Printing Quota Solution for CUPS and LPRng.""" 
  • pykota/trunk/SECURITY

    r1074 r1087  
    6363    PyKota and/or your printing system completely inoperative. 
    6464     
    65   - Ensure that no regular user can read PyKota's configuration file, 
    66     but that both the print quota administrator and the user the 
    67     printing system is run as can read it. Depending on your system's 
    68     configuration, this may give something like : 
     65  - Ensure that no regular user can read PyKota administrator's  
     66    configuration file, but that both the print quota administrator and  
     67    the user the printing system is run as can read it. Depending on  
     68    your system's configuration, this may give something like :  
    6969     
    70       $ chown lp.lpadmin /etc/pykota.conf 
    71       $ chmod 640 /etc/pykota.conf 
     70      $ chown lp.lpadmin /etc/pykota/pykotadmin.conf 
     71      $ chmod 640 /etc/pykota/pykotadmin.conf 
    7272     
    7373    If the print quota administrator is root then he will always be 
    7474    able to read PyKota's configuration file. 
    7575     
    76     Letting any user read PyKota's configuration file may expose 
    77     passwords or database information which would allow direct 
    78     connections to it if the user can write and execute his own 
    79     scripts or download and execute his own version of PyKota. 
     76    Letting any user read PyKota administrator's configuration file may  
     77    expose passwords or database information which would allow direct  
     78    connections to it if the user can write and execute his own scripts  
     79    or download and execute his own version of PyKota.  
    8080   
     81    If you want to let users generate their own print quota reports,  
     82    then ensure that /etc/pykota/pykota.conf is readable by 
     83    everyone, but writeable only by the root user : 
     84     
     85      $ chown root.root /etc/pykota/pykota.conf 
     86      $ chmod 644 /etc/pykota/pykota.conf 
     87       
    8188    NB : If you use the printquota.cgi CGI script, ensure that 
    8289         the user this script is run as (e.g. nobody or www-data) 
    83          can read PyKota's configuration file too, for example 
    84          by putting www-data in the lpadmin group. 
    85          WARNING : putting www-data in the lpadmin group so that 
    86          the CGI script can read the /etc/pykota.conf file is 
    87          dangerous. If any user can create CGI scripts launchable 
    88          as www-data then he could steal a copy of the /etc/pykota.conf  
    89          file and learn database and database users' name and passwords. 
    90          The best solution is probably to create a pykota system 
    91          account and run the CGI script as this user using Apache's SuEXEC 
    92          facility. Refer to Apache's documentation for details. 
     90         can read PyKota's configuration file /etc/pykota/pykota.conf 
     91         BUT can't read PyKota administrator's configuration file 
     92         /etc/pykota/pykotadmin.conf 
     93         Refer to Apache's documentation for details. 
    9394   
    9495  - Secure your database connection : 
  • pykota/trunk/setup.py

    r1057 r1087  
    2323# 
    2424# $Log$ 
     25# Revision 1.19  2003/07/16 21:53:07  jalet 
     26# Really big modifications wrt new configuration file's location and content. 
     27# 
    2528# Revision 1.18  2003/07/03 09:44:00  jalet 
    2629# Now includes the pykotme utility 
     
    9093import os 
    9194import shutil 
    92 import ConfigParser 
    9395try : 
    9496    from distutils.core import setup 
     
    149151        sys.exit(-1) 
    150152         
    151     # checks if a configuration file is present in the old location 
    152     if os.path.isfile("/etc/cups/pykota.conf") : 
    153         if not os.path.isfile("/etc/pykota.conf") : 
    154             sys.stdout.write("From version 1.02 on, PyKota expects to find its configuration\nfile in /etc instead of /etc/cups.\n") 
     153    # checks if a configuration file is present in the new location 
     154    if not os.path.isfile("/etc/pykota/pykota.conf") : 
     155        if not os.path.isdir("/etc/pykota") : 
     156            try : 
     157                os.mkdir("/etc/pykota") 
     158            except OSError, msg :     
     159                sys.stderr.write("An error occured while creating the /etc/pykota directory.\n%s\n" % msg) 
     160                sys.exit(-1) 
     161                 
     162        if os.path.isfile("/etc/pykota.conf") : 
     163            # upgrade from pre-1.14 to 1.14 and above 
     164            sys.stdout.write("From version 1.14 on, PyKota expects to find its configuration\nfile in /etc/pykota/ instead of /etc/\n") 
    155165            sys.stdout.write("It seems that you've got a configuration file in the old location,\nso it will not be used anymore,\nand there's no configuration file in the new location.\n") 
    156             answer = raw_input("Do you want to move /etc/cups/pykota.conf to /etc/pykota.conf (y/N) ? ") 
     166            answer = raw_input("Do you want to move /etc/pykota.conf to /etc/pykota/pykota.conf (y/N) ? ") 
    157167            if answer[0:1].upper() == 'Y' : 
    158168                try : 
    159                     os.rename("/etc/cups/pykota.conf", "/etc/pykota.conf") 
     169                    os.rename("/etc/pykota.conf", "/etc/pykota/pykota.conf") 
    160170                except OSError :     
    161                     sys.stderr.write("ERROR : An error occured while moving /etc/cups/pykota.conf to /etc/pykota.conf\nAborted !\n") 
     171                    sys.stderr.write("ERROR : An error occured while moving /etc/pykota.conf to /etc/pykota/pykota.conf\nAborted !\n") 
    162172                    sys.exit(-1) 
     173                else :     
     174                    sys.stdout.write("Configuration file /etc/pykota.conf moved to /etc/pykota/pykota.conf.\n") 
    163175            else : 
    164                 sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf won't be used ! Move it to /etc instead.\n") 
    165                 sys.stderr.write("PyKota installation will continue anyway, but the software won't run until you put a proper configuration file in /etc\n") 
    166         else :         
    167             sys.stderr.write("WARNING : Configuration file /etc/cups/pykota.conf will not be used !\nThe file /etc/pykota.conf will be used instead.\n") 
    168     elif not os.path.isfile("/etc/pykota.conf") :         
    169         # no configuration file, first installation it seems. 
    170         if os.path.isfile("conf/pykota.conf.sample") : 
    171             answer = raw_input("Do you want to install conf/pykota.conf.sample as /etc/pykota.conf (y/N) ? ") 
    172             if answer[0:1].upper() == 'Y' : 
    173                 try : 
    174                     shutil.copy("conf/pykota.conf.sample", "/etc/pykota.conf")         
    175                 except IOError :     
    176                     sys.stderr.write("WARNING : Problem while installing /etc/pykota.conf, please do it manually.\n") 
    177                 else :     
    178                     sys.stdout.write("Configuration file /etc/pykota.conf installed.\nDon't forget to adapt /etc/pykota.conf to your needs.\n") 
     176                sys.stderr.write("WARNING : Configuration file /etc/pykota.conf won't be used ! Move it to /etc/pykota/ instead.\n") 
     177                sys.stderr.write("PyKota installation will continue anyway,\nbut the software won't run until you put a proper configuration file in /etc/pykota/\n") 
     178            dummy = raw_input("Please press ENTER when you have read the message above. ") 
     179        else : 
     180            # first installation 
     181            if os.path.isfile("conf/pykota.conf.sample") : 
     182                answer = raw_input("Do you want to install\n\tconf/pykota.conf.sample as /etc/pykota/pykota.conf (y/N) ? ") 
     183                if answer[0:1].upper() == 'Y' : 
     184                    try : 
     185                        shutil.copy("conf/pykota.conf.sample", "/etc/pykota/pykota.conf")         
     186                        shutil.copy("conf/pykotadmin.conf.sample", "/etc/pykota/pykotadmin.conf")         
     187                    except IOError, msg :     
     188                        sys.stderr.write("WARNING : Problem while installing sample configuration files in /etc/pykota/, please do it manually.\n%s\n" % msg) 
     189                    else :     
     190                        sys.stdout.write("Configuration file /etc/pykota/pykota.conf and /etc/pykota/pykotadmin.conf installed.\nDon't forget to adapt these files to your needs.\n") 
     191                else :         
     192                    sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n") 
    179193            else :         
    180                 sys.stderr.write("WARNING : PyKota won't run without a configuration file !\n") 
    181     else :             
    182         # Configuration file already exists. Check if this is an old version or not 
    183         # if the 'method: lazy' line is present, then the configuration file 
    184         # has to be updated. 
    185         oldconf = ConfigParser.ConfigParser() 
    186         oldconf.read(["/etc/pykota.conf"]) 
    187         try : 
    188             if oldconf.get("global", "method", raw=1).lower().strip() == "lazy" : 
    189                 sys.stdout.write("You have got an OLD PyKota configuration file !\n") 
    190                 sys.stdout.write("The 'method' statement IS NOT SUPPORTED ANYMORE\nand was replaced with the 'accounter' statement.\n")  
    191                 sys.stdout.write("You have to manually set an 'accounter' statement,\neither globally or for each printer.\n") 
    192                 sys.stdout.write("Please read the sample configuration file conf/pykota.conf.sample\n") 
    193                 sys.stdout.write("to learn how to MANUALLY apply the modifications needed,\nafter the installation is done.\n") 
    194                 sys.stdout.write("If you don't do this, then PyKota will stop working !\n") 
    195                 answer = raw_input("Please, press ENTER when you'll have read the above paragraph.") 
    196         except ConfigParser.NoOptionError : 
    197             # New configuration file, OK 
    198             pass 
     194                # Problem ? 
     195                sys.stderr.write("WARNING : PyKota's sample configuration file cannot be found.\nWhat you have downloaded seems to be incomplete,\nor you are not in the pykota directory.\nPlease double check, and restart the installation procedure.\n") 
     196            dummy = raw_input("Please press ENTER when you have read the message above. ") 
     197    else :     
     198        # already at 1.14 or above, nothing to be done. 
     199        pass 
     200         
     201    # Second stage, we will fail if onfiguration is incorrect for security reasons 
     202    from pykota.config import PyKotaConfig,PyKotaConfigError 
     203    try : 
     204        conf = PyKotaConfig("/etc/pykota/") 
     205    except PyKotaConfigError, msg :     
     206        sys.stedrr.write("%s\nINSTALLATION ABORTED !\nPlease restart installation.\n" % msg) 
     207        sys.exit(-1) 
     208    else : 
     209        hasadmin = conf.getGlobalOption("storageadmin", ignore=1) 
     210        hasadminpw = conf.getGlobalOption("storageadminpw", ignore=1) 
     211        hasuser = conf.getGlobalOption("storageuser", ignore=1) 
     212        if hasadmin or hasadminpw :  
     213            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf doesn't contain the Quota Storage Administrator's name and optional password.\n") 
     214            sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykotadmin.conf\n") 
     215            sys.stderr.write("Then replace these values with 'storageuser' and 'storageuserpw' in /etc/pykota/pykota.conf\n") 
     216            sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n") 
     217            sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n") 
     218            sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n") 
     219            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") 
     220            sys.exit(-1) 
     221        if not hasuser : 
     222            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password.\n") 
     223            sys.stderr.write("Please put these in a [global] section in /etc/pykota/pykota.conf\n") 
     224            sys.stderr.write("These fields are respectively named 'storageuser' and 'storageuserpw'.\n") 
     225            sys.stderr.write("These two fields were re-introduced to allow any user to read to his own quota, without allowing them to modify it.\n") 
     226            sys.stderr.write("You can look at the conf/pykota.conf.sample and conf/pykotadmin.conf.sample files for examples.\n") 
     227            sys.stderr.write("YOU HAVE TO DO THESE MODIFICATIONS MANUALLY, AND RESTART THE INSTALLATION.\n") 
     228            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") 
     229            sys.exit(-1) 
     230             
     231        sb = conf.getStorageBackend() 
     232        if (sb.get("storageadmin") is None) or (sb.get("storageuser") is None) : 
     233            sys.stderr.write("From version 1.14 on, PyKota expects that /etc/pykota/pykota.conf contains the Quota Storage Normal User's name and optional password which gives READONLY access to the Print Quota DataBase,") 
     234            sys.stderr.write("and that /etc/pykota/pykotadmin.conf contains the Quota Storage Administrator's name and optional password which gives READ/WRITE access to the Print Quota DataBase.\n") 
     235            sys.stderr.write("Your configuration doesn't seem to be OK, please modify your configuration files in /etc/pykota/\n") 
     236            sys.stderr.write("AND RESTART THE INSTALLATION.\n") 
     237            sys.stderr.write("INSTALLATION ABORTED FOR SECURITY REASONS.\n") 
     238            sys.exit(-1) 
     239         
     240    # change files permissions     
     241    os.chmod("/etc/pykota/pykota.conf", 0644) 
     242    os.chmod("/etc/pykota/pykotadmin.conf", 0640) 
     243     
     244    # WARNING MESSAGE     
     245    sys.stdout.write("WARNING : IF YOU ARE UPGRADING FROM A PRE-1.14 TO 1.14 OR ABOVE\n") 
     246    sys.stdout.write("AND USE THE POSTGRESQL BACKEND, THEN YOU HAVE TO MODIFY YOUR\n") 
     247    sys.stdout.write("DATABASE SCHEMA USING initscripts/postgresql/upgrade-to-1.14.sql\n") 
     248    sys.stdout.write("PLEASE READ DOCUMENTATION IN initscripts/postgresql/ TO LEARN HOW TO DO.\n") 
     249    sys.stdout.write("\n\nYOU DON'T HAVE ANYTHING SPECIAL TO DO IF THIS IS YOUR FIRST INSTALLATION.\n\n") 
     250    dummy = raw_input("Please press ENTER when you have read the message above. ") 
    199251     
    200252    # checks if some needed Python modules are there or not.