Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chkcrontab_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import pwd
import re
import string
import stat


# The following extensions imply further postprocessing or that the slack
Expand Down Expand Up @@ -1099,6 +1100,12 @@ def check_crontab(arguments, log):
log.Warn('Cron will not process this file - its name must match'
' [A-Za-z0-9_-]+ .')

# check file permissions should not have g+w
st=os.stat(arguments.crontab)
if bool(st.st_mode & stat.S_IWGRP):
log.Error('Cron will not process this file - it has group write '
'permission. Use "chmod g-w %s"' % arguments.crontab)

line_no = 0
cron_line_factory = CronLineFactory()
with open(arguments.crontab, 'r') as crontab_f:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ def testCheckBadWithUserLookup(self):
args.check_passwd = False
self.CheckACrontab(args)

def testCheckWrongPermissions(self):
args = type("", (), {})()
args.crontab = os.path.join(BASE_PATH, 'test_crontab.permissions')
self.CheckACrontab(args)

if __name__ == '__main__':
result = unittest.main()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_crontab.permissions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# WARN 1 for filename issue.
# FAIL 1 for writable permissions by group