rmjob.c (6a30de0e1ca6ab5f79c70117a66c24791ea958bb) | rmjob.c (ba7a1ad76a812b38f8bddc730e03a14591d997b8) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 59 unchanged lines hidden (view full) --- 68 */ 69static char root[] = "root"; 70static int all = 0; /* eliminate all files (root only) */ 71static int cur_daemon; /* daemon's pid */ 72static char current[7+MAXHOSTNAMELEN]; /* active control file name */ 73 74extern uid_t uid, euid; /* real and effective user id's */ 75 | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 59 unchanged lines hidden (view full) --- 68 */ 69static char root[] = "root"; 70static int all = 0; /* eliminate all files (root only) */ 71static int cur_daemon; /* daemon's pid */ 72static char current[7+MAXHOSTNAMELEN]; /* active control file name */ 73 74extern uid_t uid, euid; /* real and effective user id's */ 75 |
76static void alarmhandler __P((int)); 77static void do_unlink __P((char *)); | 76static void alarmhandler(int _signo); 77static void do_unlink(char *_file); |
78 79void | 78 79void |
80rmjob(printer) 81 const char *printer; | 80rmjob(const char *printer) |
82{ 83 register int i, nitems; 84 int assasinated = 0; 85 struct dirent **files; 86 char *cp; 87 struct printer myprinter, *pp = &myprinter; 88 89 init_printer(pp); --- 59 unchanged lines hidden (view full) --- 149} 150 151/* 152 * Process a lock file: collect the pid of the active 153 * daemon and the file name of the active spool entry. 154 * Return boolean indicating existence of a lock file. 155 */ 156int | 81{ 82 register int i, nitems; 83 int assasinated = 0; 84 struct dirent **files; 85 char *cp; 86 struct printer myprinter, *pp = &myprinter; 87 88 init_printer(pp); --- 59 unchanged lines hidden (view full) --- 148} 149 150/* 151 * Process a lock file: collect the pid of the active 152 * daemon and the file name of the active spool entry. 153 * Return boolean indicating existence of a lock file. 154 */ 155int |
157lockchk(pp, s) 158 struct printer *pp; 159 char *s; | 156lockchk(struct printer *pp, char *slockf) |
160{ 161 register FILE *fp; 162 register int i, n; 163 164 seteuid(euid); | 157{ 158 register FILE *fp; 159 register int i, n; 160 161 seteuid(euid); |
165 if ((fp = fopen(s, "r")) == NULL) { | 162 if ((fp = fopen(slockf, "r")) == NULL) { |
166 if (errno == EACCES) | 163 if (errno == EACCES) |
167 fatal(pp, "%s: %s", s, strerror(errno)); | 164 fatal(pp, "%s: %s", slockf, strerror(errno)); |
168 else 169 return(0); 170 } 171 seteuid(uid); 172 if (!getline(fp)) { 173 (void) fclose(fp); 174 return(0); /* no daemon present */ 175 } --- 13 unchanged lines hidden (view full) --- 189 (void) fclose(fp); 190 return(1); 191} 192 193/* 194 * Process a control file. 195 */ 196void | 165 else 166 return(0); 167 } 168 seteuid(uid); 169 if (!getline(fp)) { 170 (void) fclose(fp); 171 return(0); /* no daemon present */ 172 } --- 13 unchanged lines hidden (view full) --- 186 (void) fclose(fp); 187 return(1); 188} 189 190/* 191 * Process a control file. 192 */ 193void |
197process(pp, file) 198 const struct printer *pp; 199 char *file; | 194process(const struct printer *pp, char *file) |
200{ 201 FILE *cfp; 202 203 if (!chk(file)) 204 return; 205 seteuid(euid); 206 if ((cfp = fopen(file, "r")) == NULL) 207 fatal(pp, "cannot open %s", file); --- 6 unchanged lines hidden (view full) --- 214 do_unlink(line+1); 215 } 216 } 217 (void) fclose(cfp); 218 do_unlink(file); 219} 220 221static void | 195{ 196 FILE *cfp; 197 198 if (!chk(file)) 199 return; 200 seteuid(euid); 201 if ((cfp = fopen(file, "r")) == NULL) 202 fatal(pp, "cannot open %s", file); --- 6 unchanged lines hidden (view full) --- 209 do_unlink(line+1); 210 } 211 } 212 (void) fclose(cfp); 213 do_unlink(file); 214} 215 216static void |
222do_unlink(file) 223 char *file; | 217do_unlink(char *file) |
224{ 225 int ret; 226 227 if (from != host) 228 printf("%s: ", host); 229 seteuid(euid); 230 ret = unlink(file); 231 seteuid(uid); 232 printf(ret ? "cannot dequeue %s\n" : "%s dequeued\n", file); 233} 234 235/* 236 * Do the dirty work in checking 237 */ 238int | 218{ 219 int ret; 220 221 if (from != host) 222 printf("%s: ", host); 223 seteuid(euid); 224 ret = unlink(file); 225 seteuid(uid); 226 printf(ret ? "cannot dequeue %s\n" : "%s dequeued\n", file); 227} 228 229/* 230 * Do the dirty work in checking 231 */ 232int |
239chk(file) 240 char *file; | 233chk(char *file) |
241{ 242 register int *r, n; 243 register char **u, *cp; 244 FILE *cfp; 245 246 /* 247 * Check for valid cf file name (mostly checking current). 248 */ --- 39 unchanged lines hidden (view full) --- 288 289/* 290 * If root is removing a file on the local machine, allow it. 291 * If root is removing a file from a remote machine, only allow 292 * files sent from the remote machine to be removed. 293 * Normal users can only remove the file from where it was sent. 294 */ 295int | 234{ 235 register int *r, n; 236 register char **u, *cp; 237 FILE *cfp; 238 239 /* 240 * Check for valid cf file name (mostly checking current). 241 */ --- 39 unchanged lines hidden (view full) --- 281 282/* 283 * If root is removing a file on the local machine, allow it. 284 * If root is removing a file from a remote machine, only allow 285 * files sent from the remote machine to be removed. 286 * Normal users can only remove the file from where it was sent. 287 */ 288int |
296isowner(owner, file) 297 char *owner, *file; | 289isowner(char *owner, char *file) |
298{ 299 if (!strcmp(person, root) && (from == host || !strcmp(from, file+6))) | 290{ 291 if (!strcmp(person, root) && (from == host || !strcmp(from, file+6))) |
300 return(1); | 292 return (1); |
301 if (!strcmp(person, owner) && !strcmp(from, file+6)) | 293 if (!strcmp(person, owner) && !strcmp(from, file+6)) |
302 return(1); | 294 return (1); |
303 if (from != host) 304 printf("%s: ", host); 305 printf("%s: Permission denied\n", file); 306 return(0); 307} 308 309/* 310 * Check to see if we are sending files to a remote machine. If we are, 311 * then try removing files on the remote machine. 312 */ 313void | 295 if (from != host) 296 printf("%s: ", host); 297 printf("%s: Permission denied\n", file); 298 return(0); 299} 300 301/* 302 * Check to see if we are sending files to a remote machine. If we are, 303 * then try removing files on the remote machine. 304 */ 305void |
314rmremote(pp) 315 const struct printer *pp; | 306rmremote(const struct printer *pp) |
316{ 317 int i, elem, firstreq, niov, rem, totlen; 318 char buf[BUFSIZ]; 319 void (*savealrm)(int); 320 struct iovec *iov; 321 322 if (!pp->remote) 323 return; /* not sending to a remote machine */ --- 61 unchanged lines hidden (view full) --- 385 free(iov[firstreq + i].iov_base); 386 free(iov); 387} 388 389/* 390 * Return 1 if the filename begins with 'cf' 391 */ 392int | 307{ 308 int i, elem, firstreq, niov, rem, totlen; 309 char buf[BUFSIZ]; 310 void (*savealrm)(int); 311 struct iovec *iov; 312 313 if (!pp->remote) 314 return; /* not sending to a remote machine */ --- 61 unchanged lines hidden (view full) --- 376 free(iov[firstreq + i].iov_base); 377 free(iov); 378} 379 380/* 381 * Return 1 if the filename begins with 'cf' 382 */ 383int |
393iscf(d) 394 struct dirent *d; | 384iscf(struct dirent *d) |
395{ 396 return(d->d_name[0] == 'c' && d->d_name[1] == 'f'); 397} 398 399void | 385{ 386 return(d->d_name[0] == 'c' && d->d_name[1] == 'f'); 387} 388 389void |
400alarmhandler(signo) 401 int signo; | 390alarmhandler(int signo __unused) |
402{ | 391{ |
403 /* ignored */ | 392 /* the signal is ignored */ 393 /* (the '__unused' is just to avoid a compile-time warning) */ |
404} | 394} |