diff options
| author | basabi <none@none> | 2005-09-13 07:37:29 -0700 |
|---|---|---|
| committer | basabi <none@none> | 2005-09-13 07:37:29 -0700 |
| commit | 032624d56c174c5c55126582b32e314a6af15522 (patch) | |
| tree | ac44d0f39005a6a32204d598de37b5a2e2b7704f /usr/src/cmd/cron/atrm.c | |
| parent | f8047eab588b3c002f465da96280cf9f29b21d19 (diff) | |
| download | illumos-joyent-032624d56c174c5c55126582b32e314a6af15522.tar.gz | |
6271014 gcc and cmd/cron don't get along
6271953 gcc and cmd/login don't get along
6274736 gcc and ucbcmd/expr don't get along
6274737 gcc and ucbcmd/from don't get along
6274776 gcc and ucbcmd/rusage don't get along
6274779 gcc and ucbcmd/shutdown don't get along
Diffstat (limited to 'usr/src/cmd/cron/atrm.c')
| -rw-r--r-- | usr/src/cmd/cron/atrm.c | 176 |
1 files changed, 95 insertions, 81 deletions
diff --git a/usr/src/cmd/cron/atrm.c b/usr/src/cmd/cron/atrm.c index 161b56ece4..54e2ffc124 100644 --- a/usr/src/cmd/cron/atrm.c +++ b/usr/src/cmd/cron/atrm.c @@ -1,3 +1,8 @@ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ @@ -6,12 +11,9 @@ * Copyright (c) 1983 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. - - * Copyright 1984-2002 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ +#pragma ident "%Z%%M% %I% %E% SMI" /* * synopsis: atrm [-f] [-i] [-a] [[job #] [user] ...] @@ -30,17 +32,17 @@ #include <errno.h> #include <unistd.h> #include <locale.h> +#include <strings.h> #include "cron.h" extern time_t num(); extern char *errmsg(); -extern int errno; extern void audit_at_delete(char *, char *, int); -#define SUPERUSER 0 /* is user super-user? */ -#define CANTCD "can't change directory to the at directory" -#define NOREADDIR "can't read the at directory" +#define SUPERUSER 0 /* is user super-user? */ +#define CANTCD "can't change directory to the at directory" +#define NOREADDIR "can't read the at directory" uid_t user; /* person requesting removal */ int fflag = 0; /* suppress announcements? */ @@ -49,21 +51,25 @@ int iflag = 0; /* run interactively? */ char login[UNAMESIZE]; char login_authchk[UNAMESIZE]; /* used for authorization checks */ -#define INVALIDUSER "you are not a valid user (no entry in /etc/passwd)" -#define NOTALLOWED "you are not authorized to use at. Sorry." +#define INVALIDUSER "you are not a valid user (no entry in /etc/passwd)" +#define NOTALLOWED "you are not authorized to use at. Sorry." #define NAMETOOLONG "login name too long" -main(argc,argv) -int argc; -char **argv; +static void usage(void); +static void atabortperror(char *msg); +static void atabort(char *msg); +static void atperror(char *msg); +static void atperror2(char *msg, char *name); +static void aterror(char *msg); +static void powner(char *file); +int +main(int argc, char **argv) { int i; /* for loop index */ int numjobs; /* # of jobs in spooling area */ - int usage(); /* print usage info and exit */ int allflag = 0; /* remove all jobs belonging to user? */ int jobexists; /* does a requested job exist? */ - extern int strcmp(); /* sort jobs by date of execution */ char *pp; char *getuser(); struct dirent **namelist; /* names of jobs in spooling area */ @@ -74,13 +80,13 @@ char **argv; * If job number, user name, or "-" is not specified, just print * usage info and exit. */ - (void)setlocale(LC_ALL, ""); + (void) setlocale(LC_ALL, ""); if (argc < 2) usage(); --argc; ++argv; - pp = getuser((user=getuid())); + pp = getuser((user = getuid())); if (pp == NULL) atabort(INVALIDUSER); if (strlcpy(login, pp, sizeof (login)) >= sizeof (login)) @@ -97,7 +103,8 @@ char **argv; */ while (argc > 0 && **argv == '-') { *(*argv)++; - while (**argv) switch (*(*argv)++) { + while (**argv) { + switch (*(*argv)++) { case 'a': ++allflag; break; @@ -109,22 +116,23 @@ char **argv; break; default: usage(); + } } ++argv; --argc; } /* - * If all jobs are to be removed and extra command line arguments + * If all jobs are to be removed and extra command line arguments * are given, print usage info and exit. */ - if (allflag && argc) + if (allflag && argc) usage(); /* * If only certain jobs are to be removed and no job #'s or user * names are specified, print usage info and exit. */ - if (!allflag && !argc) + if (!allflag && !argc) usage(); /* @@ -139,7 +147,7 @@ char **argv; * Move to spooling directory and get a list of the files in the * spooling area. */ - numjobs = getjoblist(&namelist,&statlist,strcmp); + numjobs = getjoblist(&namelist, &statlist, strcmp); /* * If all jobs belonging to the user are to be removed, compare * the user's id to the owner of the file. If they match, remove @@ -147,7 +155,7 @@ char **argv; * the id's. After all files are removed, exit (status 0). */ if (allflag) { - for (i = 0; i < numjobs; ++i) { + for (i = 0; i < numjobs; ++i) { if (chkauthattr(CRONADMIN_AUTH, login_authchk) || user == statlist[i]->st_uid) (void) removentry(namelist[i]->d_name, @@ -161,7 +169,7 @@ char **argv; * line argument. A check is done to see if it is a user's name or * a job number (inode #). If it's a user's name, compare the argument * to the files owner. If it's a job number, compare the argument to - * the file name. In either case, if a match occurs, try to + * the file name. In either case, if a match occurs, try to * remove the file. */ @@ -173,7 +181,7 @@ char **argv; if (statlist[i]->st_ino == 0) continue; - /* + /* * if argv is a username, compare his/her uid to * the uid of the owner of the file...... */ @@ -185,7 +193,7 @@ char **argv; * thus compare argv to the file name. */ } else { - if (strcmp(namelist[i]->d_name,*argv)) + if (strcmp(namelist[i]->d_name, *argv)) continue; } ++jobexists; @@ -193,7 +201,8 @@ char **argv; * if the entry is ultimately removed, don't * try to remove it again later. */ - if (removentry(namelist[i]->d_name, statlist[i], user)) { + if (removentry(namelist[i]->d_name, statlist[i], + user)) { statlist[i]->st_ino = 0; } } @@ -202,19 +211,21 @@ char **argv; * If a requested argument doesn't exist, print a message. */ if (!jobexists && !fflag) { - fprintf(stderr, "atrm: %s: no such job number\n", *argv); + fprintf(stderr, "atrm: %s: no such job number\n", + *argv); } ++argv; } - exit(0); + return (0); } /* * Print usage info and exit. */ -usage() +static void +usage(void) { - fprintf(stderr,"usage: atrm [-f] [-i] [-a] [[job #] [user] ...]\n"); + fprintf(stderr, "usage: atrm [-f] [-i] [-a] [[job #] [user] ...]\n"); exit(1); } @@ -224,16 +235,13 @@ usage() * write permission (since all jobs are mode 644). If access is granted, * unlink the file. If the fflag (suppress announcements) is not set, * print the job number that we are removing and the result of the access - * check (either "permission denied" or "removed"). If we are running - * interactively (iflag), prompt the user before we unlink the file. If - * the super-user is removing jobs, inform him/her who owns each file before + * check (either "permission denied" or "removed"). If we are running + * interactively (iflag), prompt the user before we unlink the file. If + * the super-user is removing jobs, inform him/her who owns each file before * it is removed. Return TRUE if file removed, else FALSE. */ int -removentry(filename,statptr,user) -char *filename; -register struct stat *statptr; -uid_t user; +removentry(char *filename, struct stat *statptr, uid_t user) { struct passwd *pwd; char *pp; @@ -241,7 +249,7 @@ uid_t user; int r; if (!fflag) - printf("%s: ",filename); + printf("%s: ", filename); if (user != statptr->st_uid && !chkauthattr(CRONADMIN_AUTH, login_authchk)) { @@ -264,14 +272,14 @@ uid_t user; } if (chkauthattr(CRONADMIN_AUTH, login_authchk)) { - pp = getuser((uid_t) statptr->st_uid); + pp = getuser((uid_t)statptr->st_uid); if (pp == NULL) atabort(INVALIDUSER); if (strlcpy(login, pp, sizeof (login)) >= sizeof (login)) atabort(NAMETOOLONG); } - cron_sendmsg(DELETE,login,filename,AT); + cron_sendmsg(DELETE, login, filename, AT); if ((r = unlink(filename)) < 0) { if (!fflag) { fputs("could not remove\n", stdout); @@ -292,34 +300,32 @@ uid_t user; * Print the owner of the job. This is the owner of the spoolfile. * If we run into trouble getting the name, we'll just print "???". */ -powner(file) -char *file; +static void +powner(char *file) { struct stat statb; char *getname(); - if (stat(file,&statb) < 0) { - printf("%s","???"); - (void) fprintf(stderr,"atrm: Couldn't stat spoolfile %s: %s\n", + if (stat(file, &statb) < 0) { + printf("%s", "???"); + (void) fprintf(stderr, "atrm: Couldn't stat spoolfile %s: %s\n", file, errmsg(errno)); - return(0); + return; } - printf("%s",getname(statb.st_uid)); + printf("%s", getname(statb.st_uid)); } int -getjoblist(namelistp, statlistp,sortfunc) - struct dirent ***namelistp; - struct stat ***statlistp; - int (*sortfunc)(); +getjoblist(struct dirent ***namelistp, struct stat ***statlistp, + int (*sortfunc)()) { - register int numjobs; - register struct dirent **namelist; - register int i; - register struct stat *statptr; /* pointer to file stat structure */ - register struct stat **statlist; + int numjobs; + struct dirent **namelist; + int i; + struct stat *statptr; /* pointer to file stat structure */ + struct stat **statlist; extern int alphasort(); /* sort jobs by date of execution */ extern int filewanted(); /* should a file be listed in queue? */ @@ -329,10 +335,12 @@ getjoblist(namelistp, statlistp,sortfunc) /* * Get a list of the files in the spooling area. */ - if ((numjobs = ascandir(".",namelistp,filewanted,sortfunc)) < 0) + if ((numjobs = ascandir(".", namelistp, filewanted, sortfunc)) < 0) atabortperror(NOREADDIR); - if ((statlist = (struct stat **) malloc(numjobs * sizeof (struct stat ***))) == NULL) + if ((statlist = + (struct stat **)malloc(numjobs * sizeof (struct stat ***))) + == NULL) atabort("Out of memory"); namelist = *namelistp; @@ -341,12 +349,12 @@ getjoblist(namelistp, statlistp,sortfunc) * Build an array of pointers to the file stats for all jobs in * the spooling area. */ - for (i = 0; i < numjobs; ++i) { - statptr = (struct stat *) malloc(sizeof(struct stat)); + for (i = 0; i < numjobs; ++i) { + statptr = (struct stat *)malloc(sizeof (struct stat)); if (statptr == NULL) atabort("Out of memory"); if (stat(namelist[i]->d_name, statptr) < 0) { - atperror("Can't stat", namelist[i]->d_name); + atperror2("Can't stat", namelist[i]->d_name); continue; } statlist[i] = statptr; @@ -361,17 +369,18 @@ getjoblist(namelistp, statlistp,sortfunc) * Get answer to interactive prompts, eating all characters beyond the first * one. If a 'y' is typed, return 1. */ -yes() +int +yes(void) { - register int ch; /* dummy variable */ - register int ch1; /* dummy variable */ + int ch; /* dummy variable */ + int ch1; /* dummy variable */ ch = ch1 = getchar(); while (ch1 != '\n' && ch1 != EOF) ch1 = getchar(); if (isupper(ch)) ch = tolower(ch); - return(ch == 'y'); + return (ch == 'y'); } @@ -379,38 +388,43 @@ yes() * Get the full login name of a person using his/her user id. */ char * -getname(uid) -uid_t uid; +getname(uid_t uid) { - register struct passwd *pwdinfo; /* password info structure */ + struct passwd *pwdinfo; /* password info structure */ if ((pwdinfo = getpwuid(uid)) == 0) - return("???"); - return(pwdinfo->pw_name); + return ("???"); + return (pwdinfo->pw_name); +} + +static void +aterror(char *msg) +{ + fprintf(stderr, "atrm: %s\n", msg); } -aterror(msg) - char *msg; +static void +atperror(char *msg) { - fprintf(stderr,"atrm: %s\n",msg); + fprintf(stderr, "atrm: %s: %s\n", msg, errmsg(errno)); } -atperror(msg) - char *msg; +static void +atperror2(char *msg, char *name) { - fprintf(stderr,"atrm: %s: %s\n", msg, errmsg(errno)); + fprintf(stderr, "atrm: %s %s: %s\n", msg, name, errmsg(errno)); } -atabort(msg) - char *msg; +static void +atabort(char *msg) { aterror(msg); exit(1); } -atabortperror(msg) - char *msg; +static void +atabortperror(char *msg) { atperror(msg); exit(1); |
