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
2 changes: 2 additions & 0 deletions chkcrontab
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def main(argv):
dest='whitelisted_users',
help='user to ignore when warning of unrecognized users; may be passed multiple times',
default=['postgres', 'buildbot'])
parser.add_argument('-u', '--user', action='store_true',
dest='user', help='crontab user')
parser.add_argument('-n', '--no-check-passwd', action='store_false',
dest='check_passwd', help='disable user lookup')
parser.add_argument('-q', '--quiet', action='store_true',
Expand Down
12 changes: 9 additions & 3 deletions chkcrontab_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ def ValidateAndLog(self, log):
# User checks.
if self.user in self.whitelisted_users:
pass
elif self.user is False:
pass
elif len(self.user) > 31:
log.LineError(log.MSG_INVALID_USER,
'Username too long "%s"' % self.user)
Expand Down Expand Up @@ -806,7 +808,8 @@ def ValidateAndLog(self, log):
class CronLineFactory(object):
"""Classify a line in a cron field by what type of line it is."""

def __init__(self):
def __init__(self, is_user_crontab=False):
self.is_user_crontab = is_user_crontab
pass

def ParseLine(self, line, options ):
Expand Down Expand Up @@ -857,7 +860,10 @@ def ParseLine(self, line, options ):
'month': match.groups()[3],
'day of week': match.groups()[4],
}
return CronLineTime(field, match.groups()[5], match.groups()[6], options)
if self.is_user_crontab:
return CronLineTime(field, False, match.groups()[5] + " " + match.groups()[6], options)
else:
return CronLineTime(field, match.groups()[5], match.groups()[6], options)

return CronLineUnknown()

Expand Down Expand Up @@ -1100,7 +1106,7 @@ def check_crontab(arguments, log):
' [A-Za-z0-9_-]+ .')

line_no = 0
cron_line_factory = CronLineFactory()
cron_line_factory = CronLineFactory(arguments.user)
with open(arguments.crontab, 'r') as crontab_f:
for line in crontab_f:
missing_newline = line[-1] != "\n"
Expand Down