diff options
| author | Toby Goodwin <tjg@star.le.ac.uk> | 1999-01-11 10:55:18 +0000 |
|---|---|---|
| committer | Toby Goodwin <toby@paccrat.org> | 2015-05-16 21:22:09 +0100 |
| commit | e11c7df86144bed383ac6bbeaecc3017d18b37db (patch) | |
| tree | 6fad44921723eab2f2eb1c76b7214b4e79b818f3 /which.c | |
| parent | 671e1e2d1599aa8c5f1010b3fe75c151c56a7403 (diff) | |
beta: rc-1.5b4
Diffstat (limited to 'which.c')
| -rw-r--r-- | which.c | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -9,18 +9,17 @@ */ #include "rc.h" + #include <errno.h> -#include <sys/types.h> #include <sys/stat.h> -#include <unistd.h> + +#include "getgroups.h" #define X_USR 0100 #define X_GRP 0010 #define X_OTH 0001 #define X_ALL (X_USR|X_GRP|X_OTH) -extern int stat(const char *, struct stat *); - static bool initialized = FALSE; static uid_t uid; static gid_t gid; @@ -32,7 +31,7 @@ static GETGROUPS_T *gidset; /* determine whether gid lies in gidset */ static int ingidset(gid_t g) { - gid_t i; + int i; for (i = 0; i < ngroups; ++i) if (g == gidset[i]) return 1; @@ -87,12 +86,17 @@ extern char *which(char *name, bool verbose) { uid = geteuid(); gid = getegid(); #if HAVE_GETGROUPS - ngroups = getgroups(0, (gid_t *)0); - gidset = malloc(ngroups * sizeof(gid_t)); - if (!gidset) - uerror("malloc"); - else - getgroups(ngroups, gidset); +#if HAVE_POSIX_GETGROUPS + ngroups = getgroups(0, (GETGROUPS_T *)0); + if (ngroups < 0) { + uerror("getgroups"); + rc_exit(1); + } +#else + ngroups = NGROUPS; +#endif + gidset = ealloc(ngroups * sizeof(GETGROUPS_T)); + getgroups(ngroups, gidset); #endif } if (isabsolute(name)) /* absolute pathname? */ |