crontab.c (637cce3a3292c1b3729aed80c0119333fc87962a) crontab.c (d21656dcabd2cd5740927495479e0819bc3e9ca0)
1/* Copyright 1988,1990,1993,1994 by Paul Vixie
2 * All rights reserved
3 *
4 * Distribute freely, except: don't remove my name from the source or
5 * documentation (don't take credit for my work), mark your changes (don't
6 * get me blamed for your possible bugs), don't alter or remove this
7 * notice. May be sold if buildable source is provided to buyer. No
8 * warrantee of any kind, express or implied, is included with this

--- 49 unchanged lines hidden (view full) ---

58
59
60static PID_T Pid;
61static char User[MAXLOGNAME], RealUser[MAXLOGNAME];
62static char Filename[MAX_FNAME];
63static FILE *NewCrontab;
64static int CheckErrorCount;
65static enum opt_t Option;
1/* Copyright 1988,1990,1993,1994 by Paul Vixie
2 * All rights reserved
3 *
4 * Distribute freely, except: don't remove my name from the source or
5 * documentation (don't take credit for my work), mark your changes (don't
6 * get me blamed for your possible bugs), don't alter or remove this
7 * notice. May be sold if buildable source is provided to buyer. No
8 * warrantee of any kind, express or implied, is included with this

--- 49 unchanged lines hidden (view full) ---

58
59
60static PID_T Pid;
61static char User[MAXLOGNAME], RealUser[MAXLOGNAME];
62static char Filename[MAX_FNAME];
63static FILE *NewCrontab;
64static int CheckErrorCount;
65static enum opt_t Option;
66static int fflag;
66static struct passwd *pw;
67static void list_cmd(void),
68 delete_cmd(void),
69 edit_cmd(void),
70 poke_daemon(void),
71 check_error(char *),
72 parse_args(int c, char *v[]);
73static int replace_cmd(void);
74
75
76static void
77usage(char *msg)
78{
79 fprintf(stderr, "crontab: usage error: %s\n", msg);
80 fprintf(stderr, "%s\n%s\n",
81 "usage: crontab [-u user] file",
67static struct passwd *pw;
68static void list_cmd(void),
69 delete_cmd(void),
70 edit_cmd(void),
71 poke_daemon(void),
72 check_error(char *),
73 parse_args(int c, char *v[]);
74static int replace_cmd(void);
75
76
77static void
78usage(char *msg)
79{
80 fprintf(stderr, "crontab: usage error: %s\n", msg);
81 fprintf(stderr, "%s\n%s\n",
82 "usage: crontab [-u user] file",
82 " crontab [-u user] { -e | -l | -r }");
83 " crontab [-u user] { -l | -r [-f] | -e }");
83 exit(ERROR_EXIT);
84}
85
86
87int
88main(int argc, char *argv[])
89{
90 int exitstatus;

--- 46 unchanged lines hidden (view full) ---

137 if (!(pw = getpwuid(getuid())))
138 errx(ERROR_EXIT, "your UID isn't in the passwd file, bailing out");
139 bzero(pw->pw_passwd, strlen(pw->pw_passwd));
140 (void) strncpy(User, pw->pw_name, (sizeof User)-1);
141 User[(sizeof User)-1] = '\0';
142 strcpy(RealUser, User);
143 Filename[0] = '\0';
144 Option = opt_unknown;
84 exit(ERROR_EXIT);
85}
86
87
88int
89main(int argc, char *argv[])
90{
91 int exitstatus;

--- 46 unchanged lines hidden (view full) ---

138 if (!(pw = getpwuid(getuid())))
139 errx(ERROR_EXIT, "your UID isn't in the passwd file, bailing out");
140 bzero(pw->pw_passwd, strlen(pw->pw_passwd));
141 (void) strncpy(User, pw->pw_name, (sizeof User)-1);
142 User[(sizeof User)-1] = '\0';
143 strcpy(RealUser, User);
144 Filename[0] = '\0';
145 Option = opt_unknown;
145 while ((argch = getopt(argc, argv, "u:lerx:")) != -1) {
146 while ((argch = getopt(argc, argv, "u:lerx:f")) != -1) {
146 switch (argch) {
147 case 'x':
148 if (!set_debug_flags(optarg))
149 usage("bad debug option");
150 break;
151 case 'u':
152 if (getuid() != ROOT_UID)
153 errx(ERROR_EXIT, "must be privileged to use -u");

--- 13 unchanged lines hidden (view full) ---

167 usage("only one operation permitted");
168 Option = opt_delete;
169 break;
170 case 'e':
171 if (Option != opt_unknown)
172 usage("only one operation permitted");
173 Option = opt_edit;
174 break;
147 switch (argch) {
148 case 'x':
149 if (!set_debug_flags(optarg))
150 usage("bad debug option");
151 break;
152 case 'u':
153 if (getuid() != ROOT_UID)
154 errx(ERROR_EXIT, "must be privileged to use -u");

--- 13 unchanged lines hidden (view full) ---

168 usage("only one operation permitted");
169 Option = opt_delete;
170 break;
171 case 'e':
172 if (Option != opt_unknown)
173 usage("only one operation permitted");
174 Option = opt_edit;
175 break;
176 case 'f':
177 fflag = 1;
178 break;
175 default:
176 usage("unrecognized option");
177 }
178 }
179
180 endpwent();
181
182 if (Option != opt_unknown) {

--- 94 unchanged lines hidden (view full) ---

277}
278
279
280static void
281delete_cmd() {
282 char n[MAX_FNAME];
283 int ch, first;
284
179 default:
180 usage("unrecognized option");
181 }
182 }
183
184 endpwent();
185
186 if (Option != opt_unknown) {

--- 94 unchanged lines hidden (view full) ---

281}
282
283
284static void
285delete_cmd() {
286 char n[MAX_FNAME];
287 int ch, first;
288
285 if (isatty(STDIN_FILENO)) {
289 if (!fflag && isatty(STDIN_FILENO)) {
286 (void)fprintf(stderr, "remove crontab for %s? ", User);
287 first = ch = getchar();
288 while (ch != '\n' && ch != EOF)
289 ch = getchar();
290 if (first != 'y' && first != 'Y')
291 return;
292 }
293

--- 351 unchanged lines hidden ---
290 (void)fprintf(stderr, "remove crontab for %s? ", User);
291 first = ch = getchar();
292 while (ch != '\n' && ch != EOF)
293 ch = getchar();
294 if (first != 'y' && first != 'Y')
295 return;
296 }
297

--- 351 unchanged lines hidden ---