version 1.2, 1997/04/08 02:44:07 |
version 1.3, 1998/01/28 17:18:53 |
|
|
|
|
extern char *__progname; |
extern char *__progname; |
|
|
int findprog __P((char *, char *, int)); |
int findprog __P((char *, char *, int, int)); |
void usage __P((void)); |
void usage __P((void)); |
|
|
/* |
/* |
|
|
{ |
{ |
char *path; |
char *path; |
size_t n; |
size_t n; |
int ch, notfound = 0, progmode = PROG_WHICH; |
int ch, allmatches = 0, notfound = 0, progmode = PROG_WHICH; |
|
|
(void)setlocale(LC_ALL, ""); |
(void)setlocale(LC_ALL, ""); |
|
|
|
|
usage(); |
usage(); |
|
|
/* Don't accept command args but check since old whereis(1) used to */ |
/* Don't accept command args but check since old whereis(1) used to */ |
while ((ch = getopt(argc, argv, "")) != -1) { |
while ((ch = getopt(argc, argv, "a")) != -1) { |
switch (ch) { |
switch (ch) { |
|
case 'a': |
|
allmatches = 1; |
|
break; |
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
if (setuid(geteuid())) |
if (setuid(geteuid())) |
err(-1, "Can't set uid to %u", geteuid()); |
err(-1, "Can't set uid to %u", geteuid()); |
|
|
for (n = 1; n < argc; n++) |
for (n = optind; n < argc; n++) |
if (findprog(argv[n], path, progmode) == 0) |
if (findprog(argv[n], path, progmode, allmatches) == 0) |
notfound++; |
notfound++; |
|
|
exit((notfound == 0) ? 0 : ((notfound == argc - 1) ? 2 : 1)); |
exit((notfound == 0) ? 0 : ((notfound == argc - 1) ? 2 : 1)); |
} |
} |
|
|
int |
int |
findprog(prog, path, progmode) |
findprog(prog, path, progmode, allmatches) |
char *prog; |
char *prog; |
char *path; |
char *path; |
int progmode; |
int progmode; |
|
int allmatches; |
{ |
{ |
char *p, filename[MAXPATHLEN]; |
char *p, filename[MAXPATHLEN]; |
int proglen, plen; |
int proglen, plen, rval = 0; |
struct stat sbuf; |
struct stat sbuf; |
|
|
/* Special case if prog contains '/' */ |
/* Special case if prog contains '/' */ |
|
|
if ((stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && |
if ((stat(filename, &sbuf) == 0) && S_ISREG(sbuf.st_mode) && |
access(filename, X_OK) == 0) { |
access(filename, X_OK) == 0) { |
(void)puts(filename); |
(void)puts(filename); |
return(1); |
rval = 1; |
|
if (!allmatches) |
|
return(rval); |
} |
} |
} |
} |
(void)free(path); |
(void)free(path); |
|
|
/* whereis(1) is silent on failure. */ |
/* whereis(1) is silent on failure. */ |
if (progmode != PROG_WHEREIS) |
if (!rval && progmode != PROG_WHEREIS) |
(void)printf("%s: Command not found.\n", prog); |
(void)printf("%s: Command not found.\n", prog); |
return(0); |
return(rval); |
} |
} |
|
|
void |
void |
usage() |
usage() |
{ |
{ |
(void) fprintf(stderr, "Usage: %s name [...]\n", __progname); |
(void) fprintf(stderr, "Usage: %s [-a] name [...]\n", __progname); |
exit(1); |
exit(1); |
} |
} |