Deleted Added
full compact
test.c (50189) test.c (50302)
1/* $NetBSD: test.c,v 1.21 1999/04/05 09:48:38 kleink Exp $ */
2
3/*
4 * test(1); version 7-like -- author Erik Baalbergen
5 * modified by Eric Gisin to be used as built-in.
6 * modified by Arnold Robbins to add SVR3 compatibility
7 * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
8 * modified by J.T. Conklin for NetBSD.
9 *
10 * This program is in the Public Domain.
11 */
12
13#ifndef lint
14static const char rcsid[] =
1/* $NetBSD: test.c,v 1.21 1999/04/05 09:48:38 kleink Exp $ */
2
3/*
4 * test(1); version 7-like -- author Erik Baalbergen
5 * modified by Eric Gisin to be used as built-in.
6 * modified by Arnold Robbins to add SVR3 compatibility
7 * (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
8 * modified by J.T. Conklin for NetBSD.
9 *
10 * This program is in the Public Domain.
11 */
12
13#ifndef lint
14static const char rcsid[] =
15 "$Id: test.c,v 1.25 1999/08/20 16:19:26 green Exp $";
15 "$Id: test.c,v 1.26 1999/08/22 22:32:41 green Exp $";
16#endif /* not lint */
17
18#include <sys/types.h>
19#include <sys/stat.h>
20
21#include <ctype.h>
22#include <err.h>
23#include <errno.h>

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

165 int res;
166
167 if (strcmp(argv[0], "[") == 0) {
168 if (strcmp(argv[--argc], "]"))
169 errx(2, "missing ]");
170 argv[argc] = NULL;
171 }
172
16#endif /* not lint */
17
18#include <sys/types.h>
19#include <sys/stat.h>
20
21#include <ctype.h>
22#include <err.h>
23#include <errno.h>

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

165 int res;
166
167 if (strcmp(argv[0], "[") == 0) {
168 if (strcmp(argv[--argc], "]"))
169 errx(2, "missing ]");
170 argv[argc] = NULL;
171 }
172
173 /*
174 * We need to set our real user and group so that when we call
175 * access(2), it actually reflects our effective credentials,
176 * not the real credentials it wants to use.
177 */
173 /* XXX work around the absence of an eaccess(2) syscall */
178 (void)setgid(getegid());
179 (void)setuid(geteuid());
180
181 t_wp = &argv[1];
182 res = !oexpr(t_lex(*t_wp));
183
184 if (*t_wp != NULL && *++t_wp != NULL)
185 syntax(*t_wp, "unexpected operator");

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

331 return 0;
332
333 switch (mode) {
334 case FILRD:
335 return access(nm, R_OK) == 0;
336 case FILWR:
337 return access(nm, W_OK) == 0;
338 case FILEX:
174 (void)setgid(getegid());
175 (void)setuid(geteuid());
176
177 t_wp = &argv[1];
178 res = !oexpr(t_lex(*t_wp));
179
180 if (*t_wp != NULL && *++t_wp != NULL)
181 syntax(*t_wp, "unexpected operator");

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

327 return 0;
328
329 switch (mode) {
330 case FILRD:
331 return access(nm, R_OK) == 0;
332 case FILWR:
333 return access(nm, W_OK) == 0;
334 case FILEX:
339 /*
340 * We cannot simply use access(2) for this specific case
341 * since it can always return false positives for root.
342 */
335 /* XXX work around access(2) false positives for superuser */
343 if (access(nm, X_OK) != 0)
344 return 0;
345 if (S_ISDIR(s.st_mode) || getuid() != 0)
346 return 1;
347 return (s.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0;
348 case FILEXIST:
349 return access(nm, F_OK) == 0;
350 case FILREG:

--- 130 unchanged lines hidden ---
336 if (access(nm, X_OK) != 0)
337 return 0;
338 if (S_ISDIR(s.st_mode) || getuid() != 0)
339 return 1;
340 return (s.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0;
341 case FILEXIST:
342 return access(nm, F_OK) == 0;
343 case FILREG:

--- 130 unchanged lines hidden ---