summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-25 08:29:13 +0100
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-05-25 08:35:28 +0100
commitff846861b629c3ec697d04207ca681505970e3a6 (patch)
tree31a4defe4eeaddcb2645d5ce644459aee53d94e3 /pykolab
parenteda6b87c1a8e1db5ee92fc2dfc73f04d7998f635 (diff)
downloadpykolab-ff846861b629c3ec697d04207ca681505970e3a6.tar.gz
Make sure our log file has the correct owner, group and read/write permissions
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/logger.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pykolab/logger.py b/pykolab/logger.py
index 2101866..94a84fb 100644
--- a/pykolab/logger.py
+++ b/pykolab/logger.py
@@ -17,9 +17,11 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
+import grp
import logging
import logging.handlers
import os
+import pwd
import sys
import time
@@ -82,6 +84,30 @@ class Logger(logging.Logger):
else:
self.logfile = '/var/log/kolab/pykolab.log'
+ # Make sure the log file exists
+ fhandle = file(self.logfile, 'a')
+ try:
+ os.utime(self.logfile, None)
+ finally:
+ fhandle.close()
+
+ # Make sure (read: attempt to change) the permissions
+ (ruid, euid, suid) = os.getresuid()
+ (rgid, egid, sgid) = os.getresgid()
+ if ruid == 0 or rgid == 0:
+ try:
+ os.chown(
+ self.logfile,
+ pwd.getpwnam('kolab')[2],
+ grp.getgrnam('kolab-n')[2]
+ )
+ os.chmod(self.logfile, 0660)
+ except:
+ print >> sys.stderr, \
+ _("Could not change the ownership of log file %s") % (
+ self.logfile
+ )
+
try:
filelog_handler = logging.FileHandler(filename=self.logfile)
filelog_handler.setFormatter(plaintextformatter)