1032624d5Sbasabi /* 2*3d63ea05Sas145665 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3032624d5Sbasabi * Use is subject to license terms. 4032624d5Sbasabi */ 5032624d5Sbasabi 67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 77c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate 107c478bd9Sstevel@tonic-gate /* 117c478bd9Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California. 127c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 137c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 147c478bd9Sstevel@tonic-gate */ 157c478bd9Sstevel@tonic-gate 16032624d5Sbasabi #pragma ident "%Z%%M% %I% %E% SMI" 177c478bd9Sstevel@tonic-gate 187c478bd9Sstevel@tonic-gate /* 197c478bd9Sstevel@tonic-gate * synopsis: atrm [-f] [-i] [-a] [[job #] [user] ...] 207c478bd9Sstevel@tonic-gate * 217c478bd9Sstevel@tonic-gate * 227c478bd9Sstevel@tonic-gate * Remove "at" jobs. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate 257c478bd9Sstevel@tonic-gate #include <stdio.h> 267c478bd9Sstevel@tonic-gate #include <pwd.h> 277c478bd9Sstevel@tonic-gate #include <ctype.h> 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <dirent.h> 307c478bd9Sstevel@tonic-gate #include <sys/file.h> 317c478bd9Sstevel@tonic-gate #include <sys/stat.h> 327c478bd9Sstevel@tonic-gate #include <errno.h> 337c478bd9Sstevel@tonic-gate #include <unistd.h> 347c478bd9Sstevel@tonic-gate #include <locale.h> 35032624d5Sbasabi #include <strings.h> 36*3d63ea05Sas145665 #include <stdlib.h> 37*3d63ea05Sas145665 #include <libintl.h> 387c478bd9Sstevel@tonic-gate #include "cron.h" 39*3d63ea05Sas145665 #include "getresponse.h" 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate extern time_t num(); 427c478bd9Sstevel@tonic-gate extern char *errmsg(); 437c478bd9Sstevel@tonic-gate extern void audit_at_delete(char *, char *, int); 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate #define SUPERUSER 0 /* is user super-user? */ 467c478bd9Sstevel@tonic-gate #define CANTCD "can't change directory to the at directory" 477c478bd9Sstevel@tonic-gate #define NOREADDIR "can't read the at directory" 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate uid_t user; /* person requesting removal */ 507c478bd9Sstevel@tonic-gate int fflag = 0; /* suppress announcements? */ 517c478bd9Sstevel@tonic-gate int iflag = 0; /* run interactively? */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate char login[UNAMESIZE]; 547c478bd9Sstevel@tonic-gate char login_authchk[UNAMESIZE]; /* used for authorization checks */ 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #define INVALIDUSER "you are not a valid user (no entry in /etc/passwd)" 577c478bd9Sstevel@tonic-gate #define NOTALLOWED "you are not authorized to use at. Sorry." 587c478bd9Sstevel@tonic-gate #define NAMETOOLONG "login name too long" 597c478bd9Sstevel@tonic-gate 60032624d5Sbasabi static void usage(void); 61032624d5Sbasabi static void atabortperror(char *msg); 62032624d5Sbasabi static void atabort(char *msg); 63032624d5Sbasabi static void atperror(char *msg); 64032624d5Sbasabi static void atperror2(char *msg, char *name); 65032624d5Sbasabi static void aterror(char *msg); 66032624d5Sbasabi static void powner(char *file); 677c478bd9Sstevel@tonic-gate 68*3d63ea05Sas145665 int getjoblist(struct dirent ***, struct stat ***, int (*)()); 69*3d63ea05Sas145665 int removentry(char *, struct stat *, uid_t); 70*3d63ea05Sas145665 71032624d5Sbasabi int 72032624d5Sbasabi main(int argc, char **argv) 737c478bd9Sstevel@tonic-gate { 747c478bd9Sstevel@tonic-gate int i; /* for loop index */ 757c478bd9Sstevel@tonic-gate int numjobs; /* # of jobs in spooling area */ 767c478bd9Sstevel@tonic-gate int allflag = 0; /* remove all jobs belonging to user? */ 777c478bd9Sstevel@tonic-gate int jobexists; /* does a requested job exist? */ 787c478bd9Sstevel@tonic-gate char *pp; 797c478bd9Sstevel@tonic-gate struct dirent **namelist; /* names of jobs in spooling area */ 807c478bd9Sstevel@tonic-gate struct stat **statlist; 817c478bd9Sstevel@tonic-gate struct passwd *pwd; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * If job number, user name, or "-" is not specified, just print 857c478bd9Sstevel@tonic-gate * usage info and exit. 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 88*3d63ea05Sas145665 (void) textdomain(TEXT_DOMAIN); 897c478bd9Sstevel@tonic-gate if (argc < 2) 907c478bd9Sstevel@tonic-gate usage(); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate --argc; ++argv; 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate pp = getuser((user = getuid())); 957c478bd9Sstevel@tonic-gate if (pp == NULL) 967c478bd9Sstevel@tonic-gate atabort(INVALIDUSER); 977c478bd9Sstevel@tonic-gate if (strlcpy(login, pp, sizeof (login)) >= sizeof (login)) 987c478bd9Sstevel@tonic-gate atabort(NAMETOOLONG); 997c478bd9Sstevel@tonic-gate if (strlcpy(login_authchk, pp, sizeof (login_authchk)) 1007c478bd9Sstevel@tonic-gate >= sizeof (NAMETOOLONG)) 1017c478bd9Sstevel@tonic-gate atabort(INVALIDUSER); 1027c478bd9Sstevel@tonic-gate if (!allowed(login, ATALLOW, ATDENY)) 1037c478bd9Sstevel@tonic-gate atabort(NOTALLOWED); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate /* 1067c478bd9Sstevel@tonic-gate * Process command line flags. 1077c478bd9Sstevel@tonic-gate * Special case the "-" option so that others may be grouped. 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate while (argc > 0 && **argv == '-') { 1107c478bd9Sstevel@tonic-gate *(*argv)++; 111032624d5Sbasabi while (**argv) { 112032624d5Sbasabi switch (*(*argv)++) { 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate case 'a': ++allflag; 1157c478bd9Sstevel@tonic-gate break; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate case 'f': ++fflag; 1187c478bd9Sstevel@tonic-gate break; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate case 'i': ++iflag; 1217c478bd9Sstevel@tonic-gate break; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate default: usage(); 1247c478bd9Sstevel@tonic-gate } 125032624d5Sbasabi } 1267c478bd9Sstevel@tonic-gate ++argv; --argc; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * If all jobs are to be removed and extra command line arguments 1317c478bd9Sstevel@tonic-gate * are given, print usage info and exit. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate if (allflag && argc) 1347c478bd9Sstevel@tonic-gate usage(); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * If only certain jobs are to be removed and no job #'s or user 1387c478bd9Sstevel@tonic-gate * names are specified, print usage info and exit. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate if (!allflag && !argc) 1417c478bd9Sstevel@tonic-gate usage(); 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * If interactive removal and quiet removal are requested, override 1457c478bd9Sstevel@tonic-gate * quiet removal and run interactively. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate if (iflag && fflag) 1487c478bd9Sstevel@tonic-gate fflag = 0; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1527c478bd9Sstevel@tonic-gate * Move to spooling directory and get a list of the files in the 1537c478bd9Sstevel@tonic-gate * spooling area. 1547c478bd9Sstevel@tonic-gate */ 1557c478bd9Sstevel@tonic-gate numjobs = getjoblist(&namelist, &statlist, strcmp); 1567c478bd9Sstevel@tonic-gate /* 1577c478bd9Sstevel@tonic-gate * If all jobs belonging to the user are to be removed, compare 1587c478bd9Sstevel@tonic-gate * the user's id to the owner of the file. If they match, remove 1597c478bd9Sstevel@tonic-gate * the file. If the user is the super-user, don't bother comparing 1607c478bd9Sstevel@tonic-gate * the id's. After all files are removed, exit (status 0). 1617c478bd9Sstevel@tonic-gate */ 1627c478bd9Sstevel@tonic-gate if (allflag) { 1637c478bd9Sstevel@tonic-gate for (i = 0; i < numjobs; ++i) { 1647c478bd9Sstevel@tonic-gate if (chkauthattr(CRONADMIN_AUTH, login_authchk) || 1657c478bd9Sstevel@tonic-gate user == statlist[i]->st_uid) 1667c478bd9Sstevel@tonic-gate (void) removentry(namelist[i]->d_name, 1677c478bd9Sstevel@tonic-gate statlist[i], user); 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate exit(0); 1707c478bd9Sstevel@tonic-gate } 1717c478bd9Sstevel@tonic-gate 1727c478bd9Sstevel@tonic-gate /* 1737c478bd9Sstevel@tonic-gate * If only certain jobs are to be removed, interpret each command 1747c478bd9Sstevel@tonic-gate * line argument. A check is done to see if it is a user's name or 1757c478bd9Sstevel@tonic-gate * a job number (inode #). If it's a user's name, compare the argument 1767c478bd9Sstevel@tonic-gate * to the files owner. If it's a job number, compare the argument to 1777c478bd9Sstevel@tonic-gate * the file name. In either case, if a match occurs, try to 1787c478bd9Sstevel@tonic-gate * remove the file. 1797c478bd9Sstevel@tonic-gate */ 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate while (argc--) { 1827c478bd9Sstevel@tonic-gate jobexists = 0; 1837c478bd9Sstevel@tonic-gate for (i = 0; i < numjobs; ++i) { 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* if the inode number is 0, this entry was removed */ 1867c478bd9Sstevel@tonic-gate if (statlist[i]->st_ino == 0) 1877c478bd9Sstevel@tonic-gate continue; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* 1907c478bd9Sstevel@tonic-gate * if argv is a username, compare his/her uid to 1917c478bd9Sstevel@tonic-gate * the uid of the owner of the file...... 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate if (pwd = getpwnam(*argv)) { 1947c478bd9Sstevel@tonic-gate if (statlist[i]->st_uid != pwd->pw_uid) 1957c478bd9Sstevel@tonic-gate continue; 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * otherwise, we assume that the argv is a job # and 1987c478bd9Sstevel@tonic-gate * thus compare argv to the file name. 1997c478bd9Sstevel@tonic-gate */ 2007c478bd9Sstevel@tonic-gate } else { 2017c478bd9Sstevel@tonic-gate if (strcmp(namelist[i]->d_name, *argv)) 2027c478bd9Sstevel@tonic-gate continue; 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate ++jobexists; 2057c478bd9Sstevel@tonic-gate /* 2067c478bd9Sstevel@tonic-gate * if the entry is ultimately removed, don't 2077c478bd9Sstevel@tonic-gate * try to remove it again later. 2087c478bd9Sstevel@tonic-gate */ 209032624d5Sbasabi if (removentry(namelist[i]->d_name, statlist[i], 210032624d5Sbasabi user)) { 2117c478bd9Sstevel@tonic-gate statlist[i]->st_ino = 0; 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate /* 2167c478bd9Sstevel@tonic-gate * If a requested argument doesn't exist, print a message. 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate if (!jobexists && !fflag) { 219032624d5Sbasabi fprintf(stderr, "atrm: %s: no such job number\n", 220032624d5Sbasabi *argv); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate ++argv; 2237c478bd9Sstevel@tonic-gate } 224032624d5Sbasabi return (0); 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * Print usage info and exit. 2297c478bd9Sstevel@tonic-gate */ 230032624d5Sbasabi static void 231032624d5Sbasabi usage(void) 2327c478bd9Sstevel@tonic-gate { 2337c478bd9Sstevel@tonic-gate fprintf(stderr, "usage: atrm [-f] [-i] [-a] [[job #] [user] ...]\n"); 2347c478bd9Sstevel@tonic-gate exit(1); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * Remove an entry from the queue. The access of the file is checked for 2407c478bd9Sstevel@tonic-gate * write permission (since all jobs are mode 644). If access is granted, 2417c478bd9Sstevel@tonic-gate * unlink the file. If the fflag (suppress announcements) is not set, 2427c478bd9Sstevel@tonic-gate * print the job number that we are removing and the result of the access 2437c478bd9Sstevel@tonic-gate * check (either "permission denied" or "removed"). If we are running 2447c478bd9Sstevel@tonic-gate * interactively (iflag), prompt the user before we unlink the file. If 2457c478bd9Sstevel@tonic-gate * the super-user is removing jobs, inform him/her who owns each file before 2467c478bd9Sstevel@tonic-gate * it is removed. Return TRUE if file removed, else FALSE. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate int 249032624d5Sbasabi removentry(char *filename, struct stat *statptr, uid_t user) 2507c478bd9Sstevel@tonic-gate { 2517c478bd9Sstevel@tonic-gate struct passwd *pwd; 2527c478bd9Sstevel@tonic-gate char *pp; 2537c478bd9Sstevel@tonic-gate int r; 2547c478bd9Sstevel@tonic-gate 255*3d63ea05Sas145665 if (init_yes() < 0) { 256*3d63ea05Sas145665 (void) fprintf(stderr, gettext(ERR_MSG_INIT_YES), 257*3d63ea05Sas145665 strerror(errno)); 258*3d63ea05Sas145665 exit(1); 259*3d63ea05Sas145665 } 260*3d63ea05Sas145665 2617c478bd9Sstevel@tonic-gate if (!fflag) 2627c478bd9Sstevel@tonic-gate printf("%s: ", filename); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (user != statptr->st_uid && 2657c478bd9Sstevel@tonic-gate !chkauthattr(CRONADMIN_AUTH, login_authchk)) { 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate if (!fflag) { 2687c478bd9Sstevel@tonic-gate printf("permission denied\n"); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate return (0); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate } else { 2737c478bd9Sstevel@tonic-gate if (iflag) { 2747c478bd9Sstevel@tonic-gate if (chkauthattr(CRONADMIN_AUTH, login_authchk)) { 2757c478bd9Sstevel@tonic-gate printf("\t(owned by "); 2767c478bd9Sstevel@tonic-gate powner(filename); 2777c478bd9Sstevel@tonic-gate printf(") "); 2787c478bd9Sstevel@tonic-gate } 279*3d63ea05Sas145665 printf(gettext("remove it? ")); 280*3d63ea05Sas145665 if (yes() == 0) 2817c478bd9Sstevel@tonic-gate return (0); 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate if (chkauthattr(CRONADMIN_AUTH, login_authchk)) { 2857c478bd9Sstevel@tonic-gate pp = getuser((uid_t)statptr->st_uid); 2867c478bd9Sstevel@tonic-gate if (pp == NULL) 2877c478bd9Sstevel@tonic-gate atabort(INVALIDUSER); 2887c478bd9Sstevel@tonic-gate if (strlcpy(login, pp, sizeof (login)) >= 2897c478bd9Sstevel@tonic-gate sizeof (login)) 2907c478bd9Sstevel@tonic-gate atabort(NAMETOOLONG); 2917c478bd9Sstevel@tonic-gate } 2927c478bd9Sstevel@tonic-gate cron_sendmsg(DELETE, login, filename, AT); 2937c478bd9Sstevel@tonic-gate if ((r = unlink(filename)) < 0) { 2947c478bd9Sstevel@tonic-gate if (!fflag) { 2957c478bd9Sstevel@tonic-gate fputs("could not remove\n", stdout); 2967c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "atrm: %s: %s\n", 2977c478bd9Sstevel@tonic-gate filename, errmsg(errno)); 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate audit_at_delete(filename, NULL, r); 3007c478bd9Sstevel@tonic-gate return (0); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate audit_at_delete(filename, NULL, r); 3037c478bd9Sstevel@tonic-gate if (!fflag && !iflag) 3047c478bd9Sstevel@tonic-gate printf("removed\n"); 3057c478bd9Sstevel@tonic-gate return (1); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * Print the owner of the job. This is the owner of the spoolfile. 3117c478bd9Sstevel@tonic-gate * If we run into trouble getting the name, we'll just print "???". 3127c478bd9Sstevel@tonic-gate */ 313032624d5Sbasabi static void 314032624d5Sbasabi powner(char *file) 3157c478bd9Sstevel@tonic-gate { 3167c478bd9Sstevel@tonic-gate struct stat statb; 3177c478bd9Sstevel@tonic-gate char *getname(); 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate if (stat(file, &statb) < 0) { 3207c478bd9Sstevel@tonic-gate printf("%s", "???"); 3217c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "atrm: Couldn't stat spoolfile %s: %s\n", 3227c478bd9Sstevel@tonic-gate file, errmsg(errno)); 323032624d5Sbasabi return; 3247c478bd9Sstevel@tonic-gate } 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate printf("%s", getname(statb.st_uid)); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate int 331032624d5Sbasabi getjoblist(struct dirent ***namelistp, struct stat ***statlistp, 332032624d5Sbasabi int (*sortfunc)()) 3337c478bd9Sstevel@tonic-gate { 334032624d5Sbasabi int numjobs; 335032624d5Sbasabi struct dirent **namelist; 336032624d5Sbasabi int i; 337032624d5Sbasabi struct stat *statptr; /* pointer to file stat structure */ 338032624d5Sbasabi struct stat **statlist; 3397c478bd9Sstevel@tonic-gate extern int filewanted(); /* should a file be listed in queue? */ 3407c478bd9Sstevel@tonic-gate if (chdir(ATDIR) < 0) 3417c478bd9Sstevel@tonic-gate atabortperror(CANTCD); 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate /* 3447c478bd9Sstevel@tonic-gate * Get a list of the files in the spooling area. 3457c478bd9Sstevel@tonic-gate */ 3467c478bd9Sstevel@tonic-gate if ((numjobs = ascandir(".", namelistp, filewanted, sortfunc)) < 0) 3477c478bd9Sstevel@tonic-gate atabortperror(NOREADDIR); 3487c478bd9Sstevel@tonic-gate 349032624d5Sbasabi if ((statlist = 350032624d5Sbasabi (struct stat **)malloc(numjobs * sizeof (struct stat ***))) 351032624d5Sbasabi == NULL) 3527c478bd9Sstevel@tonic-gate atabort("Out of memory"); 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate namelist = *namelistp; 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate /* 3577c478bd9Sstevel@tonic-gate * Build an array of pointers to the file stats for all jobs in 3587c478bd9Sstevel@tonic-gate * the spooling area. 3597c478bd9Sstevel@tonic-gate */ 3607c478bd9Sstevel@tonic-gate for (i = 0; i < numjobs; ++i) { 3617c478bd9Sstevel@tonic-gate statptr = (struct stat *)malloc(sizeof (struct stat)); 3627c478bd9Sstevel@tonic-gate if (statptr == NULL) 3637c478bd9Sstevel@tonic-gate atabort("Out of memory"); 3647c478bd9Sstevel@tonic-gate if (stat(namelist[i]->d_name, statptr) < 0) { 365032624d5Sbasabi atperror2("Can't stat", namelist[i]->d_name); 3667c478bd9Sstevel@tonic-gate continue; 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate statlist[i] = statptr; 3697c478bd9Sstevel@tonic-gate } 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate *statlistp = statlist; 3727c478bd9Sstevel@tonic-gate return (numjobs); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate 3757c478bd9Sstevel@tonic-gate /* 3767c478bd9Sstevel@tonic-gate * Get the full login name of a person using his/her user id. 3777c478bd9Sstevel@tonic-gate */ 3787c478bd9Sstevel@tonic-gate char * 379032624d5Sbasabi getname(uid_t uid) 3807c478bd9Sstevel@tonic-gate { 381032624d5Sbasabi struct passwd *pwdinfo; /* password info structure */ 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate if ((pwdinfo = getpwuid(uid)) == 0) 3857c478bd9Sstevel@tonic-gate return ("???"); 3867c478bd9Sstevel@tonic-gate return (pwdinfo->pw_name); 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate 389032624d5Sbasabi static void 390032624d5Sbasabi aterror(char *msg) 3917c478bd9Sstevel@tonic-gate { 3927c478bd9Sstevel@tonic-gate fprintf(stderr, "atrm: %s\n", msg); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate 395032624d5Sbasabi static void 396032624d5Sbasabi atperror(char *msg) 3977c478bd9Sstevel@tonic-gate { 3987c478bd9Sstevel@tonic-gate fprintf(stderr, "atrm: %s: %s\n", msg, errmsg(errno)); 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 401032624d5Sbasabi static void 402032624d5Sbasabi atperror2(char *msg, char *name) 403032624d5Sbasabi { 404032624d5Sbasabi fprintf(stderr, "atrm: %s %s: %s\n", msg, name, errmsg(errno)); 405032624d5Sbasabi } 406032624d5Sbasabi 407032624d5Sbasabi static void 408032624d5Sbasabi atabort(char *msg) 4097c478bd9Sstevel@tonic-gate { 4107c478bd9Sstevel@tonic-gate aterror(msg); 4117c478bd9Sstevel@tonic-gate exit(1); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 414032624d5Sbasabi static void 415032624d5Sbasabi atabortperror(char *msg) 4167c478bd9Sstevel@tonic-gate { 4177c478bd9Sstevel@tonic-gate atperror(msg); 4187c478bd9Sstevel@tonic-gate exit(1); 4197c478bd9Sstevel@tonic-gate } 420