]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
newgrp: allow to specify a group with the GID
authorChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Sun, 29 Mar 2026 22:18:40 +0000 (18:18 -0400)
committerChristian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Mon, 30 Mar 2026 12:56:18 +0000 (08:56 -0400)
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
login-utils/Makemodule.am
login-utils/newgrp.1.adoc
login-utils/newgrp.c
meson.build

index cfb0e7708ad60eb6472c468c57ea90faa6acba88..d288a06c337b09fa34f93405e01db0017aa25174 100644 (file)
@@ -223,7 +223,7 @@ dist_noinst_DATA += login-utils/newgrp.1.adoc
 newgrp_SOURCES = login-utils/newgrp.c
 newgrp_CFLAGS = $(SUID_CFLAGS) $(AM_CFLAGS)
 newgrp_LDFLAGS = $(SUID_LDFLAGS) $(AM_LDFLAGS)
-newgrp_LDADD = $(LDADD)
+newgrp_LDADD = $(LDADD) libcommon.la
 if HAVE_LIBCRYPT
 newgrp_LDADD += -lcrypt
 endif
index 046bb6bec5e7bd3bdf6904c9a48ada76e7d94885..7fc0e9a72de09ec1286310a2bce3a4c1b0ff1c1b 100644 (file)
@@ -20,13 +20,14 @@ newgrp - log in to a new group
 
 == SYNOPSIS
 
-*newgrp* [_group_ [_command_]]
+*newgrp* [_group_|_GID_ [_command_]]
 
-*newgrp* [*-c* _command_] [_group_]
+*newgrp* [*-c* _command_] [_group_|_GID_]
 
 == DESCRIPTION
 
-*newgrp* changes the group identification of its caller, analogously to *login*(1). The same person remains logged in, and the current directory is unchanged, but calculations of access permissions to files are performed with respect to the new group ID.
+*newgrp* changes the group identification of its caller to the group specified either as a _name_ or _GID_, analogously to *login*(1).
+The same person remains logged in, and the current directory is unchanged, but calculations of access permissions to files are performed with respect to the new group ID.
 
 If no group is specified, the GID is changed to the login GID.
 
index 2bb4b55812bd137328eb40ee870894947791d14a..17c58e55eb64a9070a5654d55ab3eb4ef532a831 100644 (file)
@@ -29,6 +29,7 @@
 #include "nls.h"
 #include "pathnames.h"
 #include "xalloc.h"
+#include "pwdutils.h"
 
 static char *xgetpass(FILE *input, const char *prompt)
 {
@@ -172,7 +173,7 @@ static void __attribute__((__noreturn__)) usage(void)
 {
        FILE *out = stdout;
        fputs(USAGE_HEADER, out);
-       fprintf(out, _(" %s <group> [[-c] <command>]\n"), program_invocation_short_name);
+       fprintf(out, _(" %s <group|GID> [[-c] <command>]\n"), program_invocation_short_name);
 
        fputs(USAGE_SEPARATOR, out);
        fputs(_("Log in to a new group; optionally executing a shell command.\n"), out);
@@ -225,7 +226,7 @@ int main(int argc, char *argv[])
                        err(EXIT_FAILURE, _("setgid() failed"));
        } else {
                errno = 0;
-               if (!(gr_entry = getgrnam(argv[optind++]))) {
+               if (!(gr_entry = ul_getgrp_str(argv[optind++], NULL))) {
                        if (errno)
                                err(EXIT_FAILURE, _("no such group"));
                        else
index 582f2756472b23eec70e3d875d1b5885afb74567..d2a245c509a1379c8dd5f4034538445b8412c4c5 100644 (file)
@@ -1184,6 +1184,7 @@ exe = executable(
   'newgrp',
   'login-utils/newgrp.c',
   include_directories : includes,
+  link_with : [lib_common],
   dependencies : [lib_crypt],
   install_dir : usrbin_exec_dir,
   install_mode : 'rwsr-xr-x',