Skip to content

Commit

Permalink
configure.ac, lib/, src/: Assume setgroups(2) exists
Browse files Browse the repository at this point in the history
It's available in every system I checked: glibc,musl,{Free,Net,Open}BSD.

Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and hallyn committed Jan 24, 2025
1 parent 3e4b3d3 commit 5068b2e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ AC_CHECK_HEADER([shadow.h],,[AC_MSG_ERROR([You need a libc with shadow.h])])
AC_CHECK_FUNCS(arc4random_buf futimes \
getentropy getrandom getspnam getusershell \
initgroups lckpwdf lutimes \
setgroups updwtmpx innetgr \
updwtmpx innetgr \
getspnam_r \
rpmatch \
memset_explicit explicit_bzero stpecpy stpeprintf)
Expand Down
7 changes: 3 additions & 4 deletions lib/addgrps.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include <config.h>

#if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
#if !defined(USE_PAM)

#include "prototypes.h"
#include "defines.h"
Expand Down Expand Up @@ -110,7 +110,6 @@ add_groups(const char *list)
free (grouplist);
return 0;
}
#else /* HAVE_SETGROUPS && !USE_PAM */
#else /* !USE_PAM */
extern int ISO_C_forbids_an_empty_translation_unit;
#endif /* HAVE_SETGROUPS && !USE_PAM */

#endif /* !USE_PAM */
2 changes: 1 addition & 1 deletion lib/prototypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "commonio.h"

/* addgrps.c */
#if defined (HAVE_SETGROUPS) && ! defined (USE_PAM)
#if !defined(USE_PAM)
extern int add_groups (const char *);
#endif

Expand Down
9 changes: 1 addition & 8 deletions src/newgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ static const char *Prog;

extern char **newenvp;

#ifdef HAVE_SETGROUPS
static int ngroups;
static /*@null@*/ /*@only@*/GETGROUPS_T *grouplist;
#endif

static bool is_newgrp;

Expand Down Expand Up @@ -551,7 +549,6 @@ int main (int argc, char **argv)
}
}

#ifdef HAVE_SETGROUPS
/*
* get the current user's groupset. The new group will be added to
* the concurrent groupset if there is room, otherwise you get a
Expand Down Expand Up @@ -584,7 +581,6 @@ int main (int argc, char **argv)
#endif
exit (EXIT_FAILURE);
}
#endif /* HAVE_SETGROUPS */

/*
* now we put her in the new group. The password file entry for her
Expand Down Expand Up @@ -632,7 +628,6 @@ int main (int argc, char **argv)
goto failure;
}

#ifdef HAVE_SETGROUPS
/* when using pam_group, she will not be listed in the groups
* database. However getgroups() will return the group. So
* if she is listed there already it is ok to grant membership.
Expand All @@ -643,7 +638,7 @@ int main (int argc, char **argv)
break;
}
}
#endif /* HAVE_SETGROUPS */

/*
* For split groups (due to limitations of NIS), check all
* groups of the same GID like the requested group for
Expand Down Expand Up @@ -688,7 +683,6 @@ int main (int argc, char **argv)

gid = grp->gr_gid;

#ifdef HAVE_SETGROUPS
/*
* I am going to try to add her new group id to her concurrent group
* set. If the group id is already present I'll just skip this part.
Expand All @@ -710,7 +704,6 @@ int main (int argc, char **argv)
}
}
}
#endif

/*
* Close all files before changing the user/group IDs.
Expand Down

0 comments on commit 5068b2e

Please sign in to comment.