Line
Link Here
|
0 |
-- a/queue_repair.py 2003-10-22 23:54:13.000000000 +0800 |
0 |
++ b/queue_repair.py 2020-01-17 18:21:18.834455813 +0800 |
Lines 1-4
Link Here
|
1 |
#!/usr/bin/python |
1 |
#!/usr/bin/python3 |
2 |
'''queue_repair.py - qmail tools in Python. |
2 |
'''queue_repair.py - qmail tools in Python. |
3 |
Copyright (C) 2001 Charles Cazabon |
3 |
Copyright (C) 2001 Charles Cazabon |
4 |
|
4 |
|
Lines 66-89
Link Here
|
66 |
# key: pathname - all paths are relative to conf-qmail |
66 |
# key: pathname - all paths are relative to conf-qmail |
67 |
# data: (user, group, mode, split) |
67 |
# data: (user, group, mode, split) |
68 |
# split is: 0 : no, 1 : yes, -1 : only with big-todo |
68 |
# split is: 0 : no, 1 : yes, -1 : only with big-todo |
69 |
'queue' : ('qmailq', 'qmail', 0750, 0), |
69 |
'queue' : ('qmailq', 'qmail', 0o750, 0), |
70 |
'queue/bounce' : ('qmails', 'qmail', 0700, 0), |
70 |
'queue/bounce' : ('qmails', 'qmail', 0o700, 0), |
71 |
'queue/info' : ('qmails', 'qmail', 0700, 1), |
71 |
'queue/info' : ('qmails', 'qmail', 0o700, 1), |
72 |
'queue/intd' : ('qmailq', 'qmail', 0700, -1), |
72 |
'queue/intd' : ('qmailq', 'qmail', 0o700, -1), |
73 |
'queue/local' : ('qmails', 'qmail', 0700, 1), |
73 |
'queue/local' : ('qmails', 'qmail', 0o700, 1), |
74 |
'queue/lock' : ('qmailq', 'qmail', 0750, 0), |
74 |
'queue/lock' : ('qmailq', 'qmail', 0o750, 0), |
75 |
'queue/mess' : ('qmailq', 'qmail', 0750, 1), |
75 |
'queue/mess' : ('qmailq', 'qmail', 0o750, 1), |
76 |
'queue/pid' : ('qmailq', 'qmail', 0700, 0), |
76 |
'queue/pid' : ('qmailq', 'qmail', 0o700, 0), |
77 |
'queue/remote' : ('qmails', 'qmail', 0700, 1), |
77 |
'queue/remote' : ('qmails', 'qmail', 0o700, 1), |
78 |
'queue/todo' : ('qmailq', 'qmail', 0750, -1), |
78 |
'queue/todo' : ('qmailq', 'qmail', 0o750, -1), |
79 |
} |
79 |
} |
80 |
|
80 |
|
81 |
nondirs = { |
81 |
nondirs = { |
82 |
# Files to check; format is: |
82 |
# Files to check; format is: |
83 |
# key: pathname - all paths are relative to conf-qmail |
83 |
# key: pathname - all paths are relative to conf-qmail |
84 |
# data: (user, group, mode) |
84 |
# data: (user, group, mode) |
85 |
'queue/lock/sendmutex' : ('qmails', 'qmail', 0600), |
85 |
'queue/lock/sendmutex' : ('qmails', 'qmail', 0o600), |
86 |
'queue/lock/tcpto' : ('qmailr', 'qmail', 0644), |
86 |
'queue/lock/tcpto' : ('qmailr', 'qmail', 0o644), |
87 |
} |
87 |
} |
88 |
|
88 |
|
89 |
|
89 |
|
Lines 105-111
Link Here
|
105 |
while i <= max: |
105 |
while i <= max: |
106 |
for p in primelist: |
106 |
for p in primelist: |
107 |
if (i % p == 0) or (p * p > i): break |
107 |
if (i % p == 0) or (p * p > i): break |
108 |
if (i % p <> 0): |
108 |
if (i % p != 0): |
109 |
primelist.append(i) |
109 |
primelist.append(i) |
110 |
if i >= min: |
110 |
if i >= min: |
111 |
result.append(i) |
111 |
result.append(i) |
Lines 151-158
Link Here
|
151 |
''' |
151 |
''' |
152 |
global users, groups |
152 |
global users, groups |
153 |
msg('finding qmail UIDs/GIDs...') |
153 |
msg('finding qmail UIDs/GIDs...') |
154 |
us = users.keys() |
154 |
us = list(users.keys()) |
155 |
gs = groups.keys() |
155 |
gs = list(groups.keys()) |
156 |
for u in us: |
156 |
for u in us: |
157 |
if users[u]: |
157 |
if users[u]: |
158 |
# Handle case of someone else determining UIDs for us |
158 |
# Handle case of someone else determining UIDs for us |
Lines 182-188
Link Here
|
182 |
that it has octal mode mode. If testmode is set, create path if it |
182 |
that it has octal mode mode. If testmode is set, create path if it |
183 |
doesn't exist. |
183 |
doesn't exist. |
184 |
''' |
184 |
''' |
185 |
if checked_dir.has_key(path): |
185 |
if path in checked_dir: |
186 |
return |
186 |
return |
187 |
msg(' checking directory %s...' % path) |
187 |
msg(' checking directory %s...' % path) |
188 |
if not os.path.exists(path): |
188 |
if not os.path.exists(path): |
Lines 208-214
Link Here
|
208 |
|
208 |
|
209 |
Verify path is owned by user:group, and make it so if testmode is not set. |
209 |
Verify path is owned by user:group, and make it so if testmode is not set. |
210 |
''' |
210 |
''' |
211 |
if checked_owner.has_key(path): |
211 |
if path in checked_owner: |
212 |
return |
212 |
return |
213 |
uid = users[user] |
213 |
uid = users[user] |
214 |
gid = groups[group] |
214 |
gid = groups[group] |
Lines 223-229
Link Here
|
223 |
msg(' fixed, %s ownership %i:%i' % (path, s[ST_UID], s[ST_GID])) |
223 |
msg(' fixed, %s ownership %i:%i' % (path, s[ST_UID], s[ST_GID])) |
224 |
else: |
224 |
else: |
225 |
msg(' testmode, not fixing') |
225 |
msg(' testmode, not fixing') |
226 |
except OSError, o: |
226 |
except OSError as o: |
227 |
err(o or '[no error message]') |
227 |
err(o or '[no error message]') |
228 |
checked_owner[path] = None |
228 |
checked_owner[path] = None |
229 |
|
229 |
|
Lines 233-239
Link Here
|
233 |
|
233 |
|
234 |
Verify path has mode mode, and make it so if testmode is not set. |
234 |
Verify path has mode mode, and make it so if testmode is not set. |
235 |
''' |
235 |
''' |
236 |
if checked_mode.has_key(path): |
236 |
if path in checked_mode: |
237 |
return |
237 |
return |
238 |
try: |
238 |
try: |
239 |
s = os.stat(path) |
239 |
s = os.stat(path) |
Lines 247-253
Link Here
|
247 |
msg(' changed %s mode to %o' % (path, newmode)) |
247 |
msg(' changed %s mode to %o' % (path, newmode)) |
248 |
else: |
248 |
else: |
249 |
msg(' testmode, not fixing') |
249 |
msg(' testmode, not fixing') |
250 |
except OSError, o: |
250 |
except OSError as o: |
251 |
err(o or '[no error message]') |
251 |
err(o or '[no error message]') |
252 |
checked_mode[path] = None |
252 |
checked_mode[path] = None |
253 |
|
253 |
|
Lines 259-265
Link Here
|
259 |
''' |
259 |
''' |
260 |
splits = [] |
260 |
splits = [] |
261 |
msg('determining conf-split...') |
261 |
msg('determining conf-split...') |
262 |
for (path, (user, group, mode, is_split)) in dirs.items(): |
262 |
for (path, (user, group, mode, is_split)) in list(dirs.items()): |
263 |
if is_split != 1: |
263 |
if is_split != 1: |
264 |
continue |
264 |
continue |
265 |
highest = 0 |
265 |
highest = 0 |
Lines 311-317
Link Here
|
311 |
else: |
311 |
else: |
312 |
msg(' found unexpected direntry %s' % p) |
312 |
msg(' found unexpected direntry %s' % p) |
313 |
|
313 |
|
314 |
if splits == range(split): |
314 |
if splits == list(range(split)): |
315 |
# big-todo apparently in use |
315 |
# big-todo apparently in use |
316 |
bigtodo = 1 |
316 |
bigtodo = 1 |
317 |
msg(' big-todo found') |
317 |
msg(' big-todo found') |
Lines 330-343
Link Here
|
330 |
Verify ownership, mode, and contents of each queue directory in paths. |
330 |
Verify ownership, mode, and contents of each queue directory in paths. |
331 |
''' |
331 |
''' |
332 |
msg('checking main queue directories...') |
332 |
msg('checking main queue directories...') |
333 |
_dirs = paths.keys() |
333 |
_dirs = list(paths.keys()) |
334 |
_dirs.sort() |
334 |
_dirs.sort() |
335 |
for path in _dirs: |
335 |
for path in _dirs: |
336 |
(user, group, mode, is_split) = paths[path] |
336 |
(user, group, mode, is_split) = paths[path] |
337 |
check_dir(path, user, group, mode) |
337 |
check_dir(path, user, group, mode) |
338 |
|
338 |
|
339 |
msg('checking split sub-directories...') |
339 |
msg('checking split sub-directories...') |
340 |
for (path, (user, group, mode, is_split)) in paths.items(): |
340 |
for (path, (user, group, mode, is_split)) in list(paths.items()): |
341 |
if path in ('queue', 'queue/lock'): |
341 |
if path in ('queue', 'queue/lock'): |
342 |
# Nothing in these directories to check at this point |
342 |
# Nothing in these directories to check at this point |
343 |
continue |
343 |
continue |
Lines 345-351
Link Here
|
345 |
if not this_split: |
345 |
if not this_split: |
346 |
splits = [] |
346 |
splits = [] |
347 |
else: |
347 |
else: |
348 |
splits = range(split) |
348 |
splits = list(range(split)) |
349 |
for i in splits: |
349 |
for i in splits: |
350 |
splitpath = os.path.join(path, str(i)) |
350 |
splitpath = os.path.join(path, str(i)) |
351 |
check_dir(splitpath, user, group, mode) |
351 |
check_dir(splitpath, user, group, mode) |
Lines 428-434
Link Here
|
428 |
Verify ownership and mode of each queue file in paths. |
428 |
Verify ownership and mode of each queue file in paths. |
429 |
''' |
429 |
''' |
430 |
msg('checking files...') |
430 |
msg('checking files...') |
431 |
for (path, (user, group, mode)) in paths.items(): |
431 |
for (path, (user, group, mode)) in list(paths.items()): |
432 |
if os.path.exists(path): |
432 |
if os.path.exists(path): |
433 |
if not os.path.isfile(path): |
433 |
if not os.path.isfile(path): |
434 |
msg(' %s is not a file' % path) |
434 |
msg(' %s is not a file' % path) |
Lines 467-473
Link Here
|
467 |
if not os.path.exists(path) and not testmode: |
467 |
if not os.path.exists(path) and not testmode: |
468 |
os.mkfifo(path) |
468 |
os.mkfifo(path) |
469 |
chown(path, user, group) |
469 |
chown(path, user, group) |
470 |
chmod(path, 0622) |
470 |
chmod(path, 0o622) |
471 |
|
471 |
|
472 |
####################################### |
472 |
####################################### |
473 |
def check_messages(path, split): |
473 |
def check_messages(path, split): |
Lines 516-522
Link Here
|
516 |
check_messages(). Correct split sub-directory location as well. |
516 |
check_messages(). Correct split sub-directory location as well. |
517 |
''' |
517 |
''' |
518 |
msg('fixing misnamed messages...') |
518 |
msg('fixing misnamed messages...') |
519 |
for (path, (user, junk, junk, is_split)) in paths.items(): |
519 |
for (path, (user, junk, junk, is_split)) in list(paths.items()): |
520 |
for (oldhash, oldno, newno) in misnamed: |
520 |
for (oldhash, oldno, newno) in misnamed: |
521 |
if not is_splitdir(is_split, bigtodo): |
521 |
if not is_splitdir(is_split, bigtodo): |
522 |
old_p = os.path.join(path, str(oldno)) |
522 |
old_p = os.path.join(path, str(oldno)) |
Lines 544-560
Link Here
|
544 |
of all files found. |
544 |
of all files found. |
545 |
''' |
545 |
''' |
546 |
msg('checking split locations...') |
546 |
msg('checking split locations...') |
547 |
for (path, (user, group, junk, is_split)) in paths.items(): |
547 |
for (path, (user, group, junk, is_split)) in list(paths.items()): |
548 |
if path in ('queue', 'queue/lock'): |
548 |
if path in ('queue', 'queue/lock'): |
549 |
# Nothing in these directories to check at this point |
549 |
# Nothing in these directories to check at this point |
550 |
continue |
550 |
continue |
551 |
elif path in ('queue/mess', 'queue/todo'): |
551 |
elif path in ('queue/mess', 'queue/todo'): |
552 |
mode = 0644 |
552 |
mode = 0o644 |
553 |
else: |
553 |
else: |
554 |
mode = 0600 |
554 |
mode = 0o600 |
555 |
this_split = is_splitdir(is_split, bigtodo) |
555 |
this_split = is_splitdir(is_split, bigtodo) |
556 |
if this_split: |
556 |
if this_split: |
557 |
splits = range(split) |
557 |
splits = list(range(split)) |
558 |
else: |
558 |
else: |
559 |
splits = [''] |
559 |
splits = [''] |
560 |
for splitval in splits: |
560 |
for splitval in splits: |
Lines 635-641
Link Here
|
635 |
wd = os.getcwd() |
635 |
wd = os.getcwd() |
636 |
try: |
636 |
try: |
637 |
os.chdir(qmaildir) |
637 |
os.chdir(qmaildir) |
638 |
except StandardError: |
638 |
except Exception: |
639 |
err('failed to chdir to %s' % qmaildir) |
639 |
err('failed to chdir to %s' % qmaildir) |
640 |
|
640 |
|
641 |
if testmode: |
641 |
if testmode: |
Lines 747-753
Link Here
|
747 |
if force_split < 1: |
747 |
if force_split < 1: |
748 |
raise ValueError |
748 |
raise ValueError |
749 |
except ValueError: |
749 |
except ValueError: |
750 |
raise getopt.error, 'split value must be a positive integer (%s)' % value |
750 |
raise getopt.error('split value must be a positive integer (%s)' % value) |
751 |
elif option in ('-n', '--no-bigtodo'): |
751 |
elif option in ('-n', '--no-bigtodo'): |
752 |
force_bigtodo = -1 |
752 |
force_bigtodo = -1 |
753 |
elif option in ('-b', '--bigtodo'): |
753 |
elif option in ('-b', '--bigtodo'): |
Lines 765-774
Link Here
|
765 |
create = 1 |
765 |
create = 1 |
766 |
if args: |
766 |
if args: |
767 |
if len(args) > 1: |
767 |
if len(args) > 1: |
768 |
raise getopt.error, 'conf-qmail must be a single argument (%s)' % string.join(args) |
768 |
raise getopt.error('conf-qmail must be a single argument (%s)' % string.join(args)) |
769 |
qmaildir = args[0] |
769 |
qmaildir = args[0] |
770 |
|
770 |
|
771 |
except getopt.error, o: |
771 |
except getopt.error as o: |
772 |
err('Error: %s' % o, showhelp=1) |
772 |
err('Error: %s' % o, showhelp=1) |
773 |
|
773 |
|
774 |
check_queue(qmaildir, test, force_split, force_bigtodo, create, mathishard) |
774 |
check_queue(qmaildir, test, force_split, force_bigtodo, create, mathishard) |
Lines 776-778
Link Here
|
776 |
####################################### |
776 |
####################################### |
777 |
if __name__ == '__main__': |
777 |
if __name__ == '__main__': |
778 |
main() |
778 |
main() |
|
|
779 |
|