aboutsummaryrefslogtreecommitdiffstats
path: root/bin/check_perms
diff options
context:
space:
mode:
authorbwarsaw <>2003-03-31 20:07:57 +0000
committerbwarsaw <>2003-03-31 20:07:57 +0000
commitd258eeb3b86fc7a084e68428f3354789ef8e3b4c (patch)
treec5e669fcefd0fa98790159734d09c0d37d63c204 /bin/check_perms
parent5a6aeea41cd141bc4e962381284cbeeefa7bf4d9 (diff)
downloadmailman2-d258eeb3b86fc7a084e68428f3354789ef8e3b4c.tar.gz
mailman2-d258eeb3b86fc7a084e68428f3354789ef8e3b4c.tar.xz
mailman2-d258eeb3b86fc7a084e68428f3354789ef8e3b4c.zip
Backporting various fixes and improvements from the trunk.
Diffstat (limited to '')
-rwxr-xr-xbin/check_perms45
1 files changed, 29 insertions, 16 deletions
diff --git a/bin/check_perms b/bin/check_perms
index 44fbe547..4f976b06 100755
--- a/bin/check_perms
+++ b/bin/check_perms
@@ -26,12 +26,12 @@ permission problems found. With -v be verbose.
"""
-import sys
import os
-import errno
-import getopt
+import sys
import pwd
import grp
+import errno
+import getopt
from stat import *
try:
@@ -55,11 +55,17 @@ PROGRAM = sys.argv[0]
# Gotta check the archives/private/*/database/* files
+try:
+ True, False
+except NameError:
+ True = 1
+ False = 0
+
class State:
- FIX = 0
- VERBOSE = 0
+ FIX = False
+ VERBOSE = False
ERRORS = 0
STATE = State()
@@ -78,7 +84,13 @@ def statgidmode(path):
stat = os.stat(path)
return stat[ST_MODE], stat[ST_GID]
+seen = {}
+
def checkwalk(arg, dirname, names):
+ # Short-circuit duplicates
+ if seen.has_key(dirname):
+ return
+ seen[dirname] = True
for name in names:
path = os.path.join(dirname, name)
if arg.VERBOSE:
@@ -151,10 +163,16 @@ def checkall():
prefix = mm_cfg.PREFIX
print _('checking mode for %(prefix)s')
dirs = {}
- for d in (mm_cfg.PREFIX, mm_cfg.EXEC_PREFIX, mm_cfg.VAR_PREFIX):
- dirs[d] = 1
+ for d in (mm_cfg.PREFIX, mm_cfg.EXEC_PREFIX, mm_cfg.VAR_PREFIX,
+ mm_cfg.LOG_DIR):
+ dirs[d] = True
for d in dirs.keys():
- mode = statmode(d)
+ try:
+ mode = statmode(d)
+ except OSError, e:
+ if e.errno <> errno.ENOENT: raise
+ print _('WARNING: directory does not exist: %(d)s')
+ continue
if (mode & DIRPERMS) <> DIRPERMS:
STATE.ERRORS += 1
print _('directory must be at least 02775: %(d)s'),
@@ -166,7 +184,6 @@ def checkall():
# check all subdirs
os.path.walk(d, checkwalk, STATE)
-
def checkarchives():
private = mm_cfg.PRIVATE_ARCHIVE_FILE_DIR
if STATE.VERBOSE:
@@ -185,7 +202,6 @@ def checkarchives():
MBOXPERMS = S_IRGRP | S_IWGRP | S_IRUSR | S_IWUSR
-
def checkmboxfile(mboxdir):
absdir = os.path.join(mm_cfg.PRIVATE_ARCHIVE_FILE_DIR, mboxdir)
for f in os.listdir(absdir):
@@ -202,7 +218,6 @@ def checkmboxfile(mboxdir):
else:
print
-
def checkarchivedbs():
# The archives/private/listname/database file must not be other readable
# or executable otherwise those files will be accessible when the archives
@@ -226,7 +241,6 @@ def checkarchivedbs():
else:
print
-
def checkcgi():
cgidir = os.path.join(mm_cfg.EXEC_PREFIX, 'cgi-bin')
if STATE.VERBOSE:
@@ -332,8 +346,7 @@ def usage(code, msg=''):
if __name__ == '__main__':
try:
- opts, args = getopt.getopt(sys.argv[1:],
- 'fvh',
+ opts, args = getopt.getopt(sys.argv[1:], 'fvh',
['fix', 'verbose', 'help'])
except getopt.error, msg:
usage(1, msg)
@@ -342,9 +355,9 @@ if __name__ == '__main__':
if opt in ('-h', '--help'):
usage(0)
elif opt in ('-f', '--fix'):
- STATE.FIX = 1
+ STATE.FIX = True
elif opt in ('-v', '--verbose'):
- STATE.VERBOSE = 1
+ STATE.VERBOSE = True
checkall()
checkarchives()