1: #define ANY -1
   2: #define LIST    -2
   3: #define RANGE   -3
   4: #define EOF -4
   5: char    *crontab    "/usr/lib/crontab";
   6: char    *crontmp    "/tmp/crontmp";
   7: char    *aend;
   8: char    *itime[2];
   9: int *loct;
  10: int *localtime();
  11: int reset();
  12: int flag;
  13: 
  14: main()
  15: {
  16:     register i, t;
  17:     register char *cp;
  18:     extern char end[];
  19: 
  20:     setuid(1);
  21:     itime[0] = fork();
  22:     if(itime[0])
  23:         exit();
  24:     setexit();
  25:     signal(1, reset);
  26:     time(itime);
  27:     while(*localtime(itime))
  28:         if(itime[1]-- == 0)
  29:             itime[0]--;
  30: 
  31: loop:
  32:     init();
  33:     for(i=60; i; i--) {
  34:         loct = localtime(itime);
  35:         for(cp = end; *cp != EOF;) {
  36:             flag = 0;
  37:             cp = cmp(cp, loct[1]); /* minute */
  38:             cp = cmp(cp, loct[2]); /* hour */
  39:             cp = cmp(cp, loct[3]); /* day */
  40:             cp = cmp(cp, loct[4]); /* month */
  41:             cp = cmp(cp, loct[6]); /* day of week */
  42:             if(flag == 0) {
  43:                 slp();
  44:                 ex(cp);
  45:             }
  46:             while(*cp++ != 0)
  47:                 ;
  48:         }
  49:         t = itime[1] + 60;
  50:         if(t < itime[1])
  51:             itime[0]++;
  52:         itime[1] = t;
  53:     }
  54:     slp();
  55:     goto loop;
  56: }
  57: 
  58: cmp(p, v)
  59: char *p;
  60: {
  61:     register char *cp;
  62: 
  63:     cp = p;
  64:     switch(*cp++) {
  65: 
  66:     case ANY:
  67:         return(cp);
  68: 
  69:     case LIST:
  70:         while(*cp != LIST)
  71:             if(*cp++ == v) {
  72:                 while(*cp++ != LIST)
  73:                     ;
  74:                 return(cp);
  75:             }
  76:         flag++;
  77:         return(cp+1);
  78: 
  79:     case RANGE:
  80:         if(*cp > v || cp[1] < v)
  81:             flag++;
  82:         return(cp+2);
  83:     }
  84:     if(cp[-1] != v)
  85:         flag++;
  86:     return(cp);
  87: }
  88: 
  89: slp()
  90: {
  91:     register i;
  92:     int t[2];
  93: 
  94:     time(t);
  95:     i = itime[1] - t[1];
  96:     if(i > 0)
  97:         sleep(i);
  98: }
  99: 
 100: ex(s)
 101: char *s;
 102: {
 103:     register i;
 104: 
 105:     if(fork()) {
 106:         wait();
 107:         return;
 108:     }
 109:     for(i=0; s[i]; i++);
 110:     close(0);
 111:     creat(crontmp, 0600);
 112:     write(0, s, i);
 113:     close(0);
 114:     open(crontmp, 0);
 115:     unlink(crontmp);
 116:     if(fork())
 117:         exit();
 118:     execl("/bin/sh", "sh", "-t", 0);
 119:     exit();
 120: }
 121: 
 122: init()
 123: {
 124:     int ib[259], t[10];
 125:     register i, c;
 126:     register char *cp;
 127:     char *ocp;
 128:     int n;
 129:     extern char end[];
 130: 
 131:     if(fopen(crontab, ib) < 0) {
 132:         write(1, "cannot open table\n", 18);
 133:         exit();
 134:     }
 135:     cp = end;
 136:     if(aend == 0)
 137:         aend = cp;
 138: 
 139: loop:
 140:     ocp = cp;
 141:     if(cp+100 > aend) {
 142:         aend =+ 512;
 143:         brk(aend);
 144:     }
 145:     for(i=0;; i++) {
 146:         do
 147:             c = getc(ib);
 148:         while(c == ' ' || c == '\t');
 149:         if(c <= 0 || c == '\n')
 150:             goto ignore;
 151:         if(i == 5)
 152:             break;
 153:         if(c == '*') {
 154:             *cp++ = ANY;
 155:             continue;
 156:         }
 157:         n = 0;
 158:         while(c >= '0' && c <= '9') {
 159:             n = n*10 + c-'0';
 160:             c = getc(ib);
 161:         }
 162:         if(n < 0 || n > 100)
 163:             goto ignore;
 164:         if(c == ',')
 165:             goto list;
 166:         if(c == '-')
 167:             goto range;
 168:         if(c != '\t' && c != ' ')
 169:             goto ignore;
 170:         *cp++ = n;
 171:         continue;
 172: 
 173:     list:
 174:         *cp++ = LIST;
 175:         *cp++ = n;
 176:     list1:
 177:         n = 0;
 178:         c = getc(ib);
 179:         while(c >= '0' && c <= '9') {
 180:             n = n*10 + c-'0';
 181:             c = getc(ib);
 182:         }
 183:         if(n < 0 || n > 100)
 184:             goto ignore;
 185:         *cp++ = n;
 186:         if(c == ',')
 187:             goto list1;
 188:         if(c != '\t' && c != ' ')
 189:             goto ignore;
 190:         *cp++ = LIST;
 191:         continue;
 192: 
 193:     range:
 194:         *cp++ = RANGE;
 195:         *cp++ = n;
 196:         n = 0;
 197:         c = getc(ib);
 198:         while(c >= '0' && c <= '9') {
 199:             n = n*10 + c-'0';
 200:             c = getc(ib);
 201:         }
 202:         if(n < 0 || n > 100)
 203:             goto ignore;
 204:         if(c != '\t' && c != ' ')
 205:             goto ignore;
 206:         *cp++ = n;
 207:     }
 208:     while(c != '\n') {
 209:         if(c <= 0)
 210:             goto ignore;
 211:         if(c == '%')
 212:             c = '\n';
 213:         *cp++ = c;
 214:         c = getc(ib);
 215:     }
 216:     *cp++ = '\n';
 217:     *cp++ = 0;
 218:     goto loop;
 219: 
 220: ignore:
 221:     cp = ocp;
 222:     while(c != '\n') {
 223:         if(c <= 0) {
 224:             close(ib[0]);
 225:             *cp++ = EOF;
 226:             *cp++ = EOF;
 227:             aend = cp;
 228:             brk(aend);
 229:             return;
 230:         }
 231:         c = getc(ib);
 232:     }
 233:     goto loop;
 234: }

Defined functions

cmp defined in line 58; used 5 times
ex defined in line 100; used 1 times
  • in line 44
init defined in line 122; used 1 times
  • in line 32
main defined in line 14; never used
slp defined in line 89; used 2 times

Defined variables

aend defined in line 7; used 7 times
crontab defined in line 5; used 1 times
crontmp defined in line 6; used 3 times
flag defined in line 12; used 5 times
itime defined in line 8; used 12 times
loct defined in line 9; used 6 times

Defined macros

ANY defined in line 1; used 1 times
EOF defined in line 4; used 3 times
LIST defined in line 2; used 4 times
RANGE defined in line 3; used 1 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1515
Valid CSS Valid XHTML 1.0 Strict