132 const char *sendargs[4];
137 while ((
opt = getoptb(argc,argv,
"cCdDi:lLt:w:vV")) != opteof)
143 case 'i': scan_ulong(optarg,&
deltah);
break;
146 case 't': pos = scan_ulong(optarg,&
hh);
147 if (!optarg[pos++] ==
':') die_usage();
148 pos = scan_ulong(optarg + pos,&
mm);
150 case 'w':
dow = optarg;
153 if (*
cp >=
'0' && *
cp <=
'7') {
156 }
else if (*
cp ==
',') {
165 default: die_usage();
170 if (
uid && !(
euid = geteuid()))
183 if (chdir(
dir.s) == -1)
186 local = argv[optind++];
194 pos = str_chr(
local,
'@');
214 if (getln(&
bi,&line,&
match,
'\n') == -1)
220 line.s[line.len - 1] =
'\0';
228 if (getln(&
bi,&line,&
match,
'\n') == -1)
232 line.s[line.len-1] =
'\0';
233 if (!case_startb(line.s,line.len,
user.s))
236 if (pos >= line.len || line.s[pos] !=
':')
246 line.s[line.len-1] =
'\n';
248 if (buffer_put(&
bo,line.s,line.len) == -1)
250 if (buffer_flush(&
bo) == -1)
255 len = str_chr(line.s+pos,
':');
256 if (!line.s[pos +
len])
264 if (!str_diffn(line.s+pos,
local,
len))
268 len = str_chr(line.s + pos,
':');
269 if (!line.s[pos +
len])
276 if (!case_diffb(line.s+pos,
len,
host))
280 pos += scan_ulong(line.s+pos,&
maxlists);
282 if (line.s[pos] !=
':')
284 if (line.s[pos+1+str_chr(line.s+pos+1,
':')])
288 while (++pos < line.len) {
289 len = str_chr(line.s + pos,
'@');
292 if (!line.s[pos])
break;
294 len = str_chr(line.s+pos,
',');
320 if (
dow[0] ==
'*')
dow =
"1,3,5";
321 }
else if (
deltah <= 72L) {
322 if (
dow[0] ==
'*')
dow =
"1,4";
324 if (
dow[0] ==
'*')
dow =
"1";
332 if (!stralloc_catb(&
addr,strnum,fmt_ulong(strnum,
t % 24L)))
die_nomem();
360 if ((
fdin = open_read(
"crontab")) == -1) {
368 if ((
fdout = open_trunc(
"crontabn")) == -1)
377 line.s[line.len-1] =
'\n';
378 if (buffer_put(&
bo,line.s,line.len) == -1)
381 if (getln(&
bi,&line,&
match,
'\n') == -1)
387 line.s[line.len - 1] =
'\0';
389 while (line.s[pos] ==
' ' && line.s[pos] ==
'\t') ++pos;
390 if (line.s[pos] ==
'#')
392 pos = str_chr(line.s,
'/');
393 if (!str_start(line.s+pos,
auto_qmail))
continue;
398 pos = byte_rchr(line.s,line.len,
'<');
402 len = str_chr(line.s+pos,
'@');
411 if (pos +
lenhost +1 >= line.len)
continue;
412 if (case_diffb(line.s+pos+1,
lenhost,
host))
continue;
413 if (line.s[pos+
lenhost+1] !=
'%')
continue;
418 if (!str_start(line.s+
pos2,
"-dig-"))
continue;
424 if (buffer_put(&
bo,line.s,line.len) == -1)
426 if (buffer_put(&
bo,
"\n",1) == -1)
437 if (buffer_flush(&
bo) == -1)
453 if (buffer_flush(&
bo) == -1)
455 if (fsync(
fdout) == -1)
457 if (close(
fdout) == -1)
459 if (rename(
"crontabn",
"crontab") == -1)
465 if (!stralloc_cats(&line,
"/crontab '"))
die_nomem();
467 if (!stralloc_cats(&line,
"/crontab'"))
die_nomem();
469 sendargs[2] = line.s;
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)