diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:37 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:18:37 +0000 |
commit | b6b00dd55e035bfbe311a527b567962ffa77ee43 (patch) | |
tree | cafc4d13785448e5a78bd40a51697ee07f07ac12 /src/groupmod.c | |
parent | Adding debian version 1:4.13+dfsg1-5. (diff) | |
download | shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.tar.xz shadow-b6b00dd55e035bfbe311a527b567962ffa77ee43.zip |
Merging upstream version 1:4.15.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/groupmod.c')
-rw-r--r-- | src/groupmod.c | 151 |
1 files changed, 54 insertions, 97 deletions
diff --git a/src/groupmod.c b/src/groupmod.c index 006eca1..989d7ea 100644 --- a/src/groupmod.c +++ b/src/groupmod.c @@ -15,7 +15,9 @@ #include <fcntl.h> #include <getopt.h> #include <grp.h> +#include <stdint.h> #include <stdio.h> +#include <strings.h> #include <sys/types.h> #ifdef ACCT_TOOLS_SETUID #ifdef USE_PAM @@ -23,6 +25,8 @@ #include <pwd.h> #endif /* USE_PAM */ #endif /* ACCT_TOOLS_SETUID */ + +#include "alloc.h" #include "chkname.h" #include "defines.h" #include "groupio.h" @@ -34,6 +38,8 @@ #include "sgroupio.h" #endif #include "shadowlog.h" +#include "string/stpecpy.h" +#include "string/stpeprintf.h" /* * exit status values */ @@ -53,7 +59,7 @@ /* * Global variables */ -const char *Prog; +static const char Prog[] = "groupmod"; #ifdef SHADOWGRP static bool is_shadow_grp; @@ -224,7 +230,7 @@ static void grp_update (void) * shadowed password, we force the creation of a * gshadow entry when a new password is requested. */ - memset (&sgrp, 0, sizeof sgrp); + bzero(&sgrp, sizeof sgrp); sgrp.sg_name = xstrdup (grp.gr_name); sgrp.sg_passwd = xstrdup (grp.gr_passwd); sgrp.sg_adm = ∅ @@ -244,10 +250,8 @@ static void grp_update (void) if (!aflg) { // requested to replace the existing groups - if (NULL != grp.gr_mem[0]) - gr_free_members(&grp); - grp.gr_mem = (char **)xmalloc(sizeof(char *)); - grp.gr_mem[0] = (char *)0; + grp.gr_mem = XMALLOC(1, char *); + grp.gr_mem[0] = NULL; } else { // append to existing groups if (NULL != grp.gr_mem[0]) @@ -333,7 +337,7 @@ static void check_new_gid (void) */ fprintf (stderr, _("%s: GID '%lu' already exists\n"), - Prog, (unsigned long int) group_newid); + Prog, (unsigned long) group_newid); exit (E_GID_IN_USE); } @@ -408,7 +412,7 @@ static void process_flags (int argc, char **argv) break; case 'g': gflg = true; - if ( (get_gid (optarg, &group_newid) == 0) + if ( (get_gid(optarg, &group_newid) == -1) || (group_newid == (gid_t)-1)) { fprintf (stderr, _("%s: invalid group ID '%s'\n"), @@ -542,95 +546,74 @@ static void close_files (void) */ static void prepare_failure_reports (void) { + char *gr, *gr_end; +#ifdef SHADOWGRP + char *sgr, *sgr_end; +#endif + char *pw, *pw_end; + info_group.name = group_name; #ifdef SHADOWGRP info_gshadow.name = group_name; #endif info_passwd.name = group_name; - info_group.audit_msg = xmalloc (512); + gr = XMALLOC(512, char); + info_group.audit_msg = gr; + gr_end = gr + 512; #ifdef SHADOWGRP - info_gshadow.audit_msg = xmalloc (512); + sgr = XMALLOC(512, char); + info_gshadow.audit_msg = sgr; + sgr_end = sgr + 512; #endif - info_passwd.audit_msg = xmalloc (512); + pw = XMALLOC(512, char); + info_passwd.audit_msg = pw; + pw_end = pw + 512; - (void) snprintf (info_group.audit_msg, 511, - "changing %s; ", gr_dbname ()); + gr = stpeprintf(gr, gr_end, "changing %s; ", gr_dbname ()); #ifdef SHADOWGRP - (void) snprintf (info_gshadow.audit_msg, 511, - "changing %s; ", sgr_dbname ()); + sgr = stpeprintf(sgr, sgr_end, "changing %s; ", sgr_dbname ()); #endif - (void) snprintf (info_passwd.audit_msg, 511, - "changing %s; ", pw_dbname ()); + pw = stpeprintf(pw, pw_end, "changing %s; ", pw_dbname ()); - info_group.action = info_group.audit_msg - + strlen (info_group.audit_msg); + info_group.action = gr; #ifdef SHADOWGRP - info_gshadow.action = info_gshadow.audit_msg - + strlen (info_gshadow.audit_msg); + info_gshadow.action = sgr; #endif - info_passwd.action = info_passwd.audit_msg - + strlen (info_passwd.audit_msg); + info_passwd.action = pw; - (void) snprintf (info_group.action, - 511 - strlen (info_group.audit_msg), - "group %s/%lu", - group_name, (unsigned long int) group_id); + gr = stpeprintf(gr, gr_end, + "group %s/%ju", group_name, (uintmax_t) group_id); #ifdef SHADOWGRP - (void) snprintf (info_gshadow.action, - 511 - strlen (info_group.audit_msg), + sgr = stpeprintf(sgr, sgr_end, "group %s", group_name); #endif - (void) snprintf (info_passwd.action, - 511 - strlen (info_group.audit_msg), - "group %s/%lu", - group_name, (unsigned long int) group_id); + pw = stpeprintf(pw, pw_end, + "group %s/%ju", group_name, (uintmax_t) group_id); if (nflg) { - strncat (info_group.action, ", new name: ", - 511 - strlen (info_group.audit_msg)); - strncat (info_group.action, group_newname, - 511 - strlen (info_group.audit_msg)); - + gr = stpecpy(gr, gr_end, ", new name: "); + gr = stpecpy(gr, gr_end, group_newname); #ifdef SHADOWGRP - strncat (info_gshadow.action, ", new name: ", - 511 - strlen (info_gshadow.audit_msg)); - strncat (info_gshadow.action, group_newname, - 511 - strlen (info_gshadow.audit_msg)); + sgr = stpecpy(sgr, sgr_end, ", new name: "); + sgr = stpecpy(sgr, sgr_end, group_newname); #endif - - strncat (info_passwd.action, ", new name: ", - 511 - strlen (info_passwd.audit_msg)); - strncat (info_passwd.action, group_newname, - 511 - strlen (info_passwd.audit_msg)); + pw = stpecpy(pw, pw_end, ", new name: "); + pw = stpecpy(pw, pw_end, group_newname); } if (pflg) { - strncat (info_group.action, ", new password", - 511 - strlen (info_group.audit_msg)); - + gr = stpecpy(gr, gr_end, ", new password"); #ifdef SHADOWGRP - strncat (info_gshadow.action, ", new password", - 511 - strlen (info_gshadow.audit_msg)); + sgr = stpecpy(sgr, sgr_end, ", new password"); #endif } if (gflg) { - strncat (info_group.action, ", new gid: ", - 511 - strlen (info_group.audit_msg)); - (void) snprintf (info_group.action+strlen (info_group.action), - 511 - strlen (info_group.audit_msg), - "%lu", (unsigned long int) group_newid); - - strncat (info_passwd.action, ", new gid: ", - 511 - strlen (info_passwd.audit_msg)); - (void) snprintf (info_passwd.action+strlen (info_passwd.action), - 511 - strlen (info_passwd.audit_msg), - "%lu", (unsigned long int) group_newid); - } - info_group.audit_msg[511] = '\0'; -#ifdef SHADOWGRP - info_gshadow.audit_msg[511] = '\0'; -#endif - info_passwd.audit_msg[511] = '\0'; + gr = stpecpy(gr, gr_end, ", new gid: "); + stpeprintf(gr, gr_end, "%ju", (uintmax_t) group_newid); + + pw = stpecpy(pw, pw_end, ", new gid: "); + stpeprintf(pw, pw_end, "%ju", (uintmax_t) group_newid); + } // FIXME: add a system cleanup add_cleanup (cleanup_report_mod_group, &info_group); @@ -766,10 +749,6 @@ int main (int argc, char **argv) #endif /* USE_PAM */ #endif /* ACCT_TOOLS_SETUID */ - /* - * Get my name so that I can use it to report errors. - */ - Prog = Basename (argv[0]); log_set_progname(Prog); log_set_logfd(stderr); @@ -780,7 +759,7 @@ int main (int argc, char **argv) process_root_flag ("-R", argc, argv); prefix = process_prefix_flag ("-P", argc, argv); - OPENLOG ("groupmod"); + OPENLOG (Prog); #ifdef WITH_AUDIT audit_help_open (); #endif @@ -806,7 +785,7 @@ int main (int argc, char **argv) exit (E_PAM_USERNAME); } - retval = pam_start ("groupmod", pampw->pw_name, &conv, &pamh); + retval = pam_start (Prog, pampw->pw_name, &conv, &pamh); } if (PAM_SUCCESS == retval) { @@ -849,28 +828,6 @@ int main (int argc, char **argv) } } -#ifdef USE_NIS - /* - * Now make sure it isn't an NIS group. - */ - if (__isgrNIS ()) { - char *nis_domain; - char *nis_master; - - fprintf (stderr, - _("%s: group %s is a NIS group\n"), - Prog, group_name); - - if (!yp_get_default_domain (&nis_domain) && - !yp_master (nis_domain, "group.byname", &nis_master)) { - fprintf (stderr, - _("%s: %s is the NIS master\n"), - Prog, nis_master); - } - exit (E_NOTFOUND); - } -#endif - if (gflg) { check_new_gid (); } |