Merge pull request #479 from alejandro-colomar/getgroups

Remove HAVE_GETGROUPS ifdefs
This commit is contained in:
Serge Hallyn 2021-12-27 19:12:24 -06:00 committed by GitHub
commit e668c7e725
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 35 deletions

View File

@ -51,7 +51,7 @@ AC_CHECK_HEADERS(crypt.h errno.h fcntl.h limits.h unistd.h sys/time.h utmp.h \
dnl shadow now uses the libc's shadow implementation dnl shadow now uses the libc's shadow implementation
AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])]) AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
AC_CHECK_FUNCS(arc4random_buf l64a fchmod fchown fsync futimes getgroups \ AC_CHECK_FUNCS(arc4random_buf l64a fchmod fchown fsync futimes \
gethostname getentropy getrandom getspnam gettimeofday getusershell \ gethostname getentropy getrandom getspnam gettimeofday getusershell \
getutent initgroups lchown lckpwdf lstat lutimes \ getutent initgroups lchown lckpwdf lstat lutimes \
setgroups sigaction strchr updwtmp updwtmpx innetgr getpwnam_r \ setgroups sigaction strchr updwtmp updwtmpx innetgr getpwnam_r \

View File

@ -107,18 +107,12 @@ static void print_groups (const char *member)
*/ */
int main (int argc, char **argv) int main (int argc, char **argv)
{ {
#ifdef HAVE_GETGROUPS
long sys_ngroups; long sys_ngroups;
GETGROUPS_T *groups; GETGROUPS_T *groups;
#else
char *logname;
char *getlogin ();
#endif
#ifdef HAVE_GETGROUPS
sys_ngroups = sysconf (_SC_NGROUPS_MAX); sys_ngroups = sysconf (_SC_NGROUPS_MAX);
groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups); groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups);
#endif
(void) setlocale (LC_ALL, ""); (void) setlocale (LC_ALL, "");
(void) bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
(void) textdomain (PACKAGE); (void) textdomain (PACKAGE);
@ -137,7 +131,6 @@ int main (int argc, char **argv)
* current user. * current user.
*/ */
#ifdef HAVE_GETGROUPS
int i; int i;
int pri_grp; /* TODO: should be GETGROUPS_T */ int pri_grp; /* TODO: should be GETGROUPS_T */
/* /*
@ -196,18 +189,6 @@ int main (int argc, char **argv)
} }
} }
(void) putchar ('\n'); (void) putchar ('\n');
#else
/*
* This system does not have the getgroups() system call, so
* I must check the groups file directly.
*/
logname = getlogin ();
if (NULL != logname) {
print_groups (logname);
} else {
exit (EXIT_FAILURE);
}
#endif
} else { } else {
/* /*

View File

@ -52,11 +52,7 @@ static void usage (void);
static void usage (void) static void usage (void)
{ {
#ifdef HAVE_GETGROUPS
(void) fputs (_("Usage: id [-a]\n"), stderr); (void) fputs (_("Usage: id [-a]\n"), stderr);
#else
(void) fputs (_("Usage: id\n"), stderr);
#endif
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -73,11 +69,9 @@ static void usage (void)
* gid_t for everything. Some systems have a small and fixed NGROUPS, * gid_t for everything. Some systems have a small and fixed NGROUPS,
* usually about 16 or 32. Others use bigger values. * usually about 16 or 32. Others use bigger values.
*/ */
#ifdef HAVE_GETGROUPS
GETGROUPS_T *groups; GETGROUPS_T *groups;
int ngroups; int ngroups;
bool aflg = 0; bool aflg = 0;
#endif
struct passwd *pw; struct passwd *pw;
struct group *gr; struct group *gr;
@ -92,8 +86,8 @@ static void usage (void)
* work if the system library is recompiled. * work if the system library is recompiled.
*/ */
sys_ngroups = sysconf (_SC_NGROUPS_MAX); sys_ngroups = sysconf (_SC_NGROUPS_MAX);
#ifdef HAVE_GETGROUPS
groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups); groups = (GETGROUPS_T *) malloc (sizeof (GETGROUPS_T) * sys_ngroups);
/* /*
* See if the -a flag has been given to print out the concurrent * See if the -a flag has been given to print out the concurrent
* group set. * group set.
@ -106,11 +100,6 @@ static void usage (void)
aflg = true; aflg = true;
} }
} }
#else
if (argc > 1) {
usage ();
}
#endif
ruid = getuid (); ruid = getuid ();
euid = geteuid (); euid = geteuid ();
@ -161,7 +150,7 @@ static void usage (void)
(void) printf (" EGID=%lu", (unsigned long) egid); (void) printf (" EGID=%lu", (unsigned long) egid);
} }
} }
#ifdef HAVE_GETGROUPS
/* /*
* Print out the concurrent group set if the user has requested it. * Print out the concurrent group set if the user has requested it.
* The group numbers will be printed followed by their names. * The group numbers will be printed followed by their names.
@ -195,7 +184,6 @@ static void usage (void)
} }
} }
free (groups); free (groups);
#endif
/* /*
* Finish off the line. * Finish off the line.