diff options
Diffstat (limited to '')
-rw-r--r-- | src/groupadd.c | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/src/groupadd.c b/src/groupadd.c index 66ccb53..46e6550 100644 --- a/src/groupadd.c +++ b/src/groupadd.c @@ -27,6 +27,7 @@ #include "defines.h" #include "getdef.h" #include "groupio.h" +#include "memzero.h" #include "nscd.h" #include "sssd.h" #include "prototypes.h" @@ -34,6 +35,7 @@ #include "sgroupio.h" #endif #include "shadowlog.h" +#include "run_part.h" /* * exit status values @@ -49,7 +51,7 @@ /* * Global variables */ -const char *Prog; +static const char Prog[] = "groupadd"; static /*@null@*/char *group_name; static gid_t group_id; @@ -70,7 +72,7 @@ static bool is_shadow_grp; #endif /* local function prototypes */ -static /*@noreturn@*/void usage (int status); +NORETURN static void usage (int status); static void new_grent (struct group *grent); #ifdef SHADOWGRP @@ -87,7 +89,9 @@ static void check_perms (void); /* * usage - display usage message and exit */ -static /*@noreturn@*/void usage (int status) +NORETURN +static void +usage (int status) { FILE *usageout = (E_SUCCESS != status) ? stderr : stdout; (void) fprintf (usageout, @@ -105,7 +109,7 @@ static /*@noreturn@*/void usage (int status) (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout); (void) fputs (_(" -r, --system create a system account\n"), usageout); (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout); - (void) fputs (_(" -P, --prefix PREFIX_DI directory prefix\n"), usageout); + (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout); (void) fputs (_(" -U, --users USERS list of user members of this group\n"), usageout); (void) fputs ("\n", usageout); exit (status); @@ -262,8 +266,7 @@ static void close_files (void) #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, "adding group to /etc/group", - group_name, (unsigned int) group_id, - SHADOW_AUDIT_SUCCESS); + group_name, group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group added to %s: name=%s, GID=%u", gr_dbname (), group_name, (unsigned int) group_id)); @@ -284,8 +287,7 @@ static void close_files (void) #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, "adding group to /etc/gshadow", - group_name, (unsigned int) group_id, - SHADOW_AUDIT_SUCCESS); + group_name, group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "group added to %s: name=%s", sgr_dbname (), group_name)); @@ -299,9 +301,7 @@ static void close_files (void) /* Report success at the system level */ #ifdef WITH_AUDIT audit_logger (AUDIT_ADD_GROUP, Prog, - "", - group_name, (unsigned int) group_id, - SHADOW_AUDIT_SUCCESS); + "", group_name, group_id, SHADOW_AUDIT_SUCCESS); #endif SYSLOG ((LOG_INFO, "new group: name=%s, GID=%u", group_name, (unsigned int) group_id)); @@ -344,8 +344,8 @@ static void open_files (void) /* And now open the databases */ if (gr_open (O_CREAT | O_RDWR) == 0) { - fprintf (stderr, _("%s: cannot open %s\n"), Prog, gr_dbname ()); - SYSLOG ((LOG_WARN, "cannot open %s", gr_dbname ())); + fprintf (stderr, _("%s: cannot open %s: %s\n"), Prog, gr_dbname (), strerror(errno)); + SYSLOG ((LOG_WARN, "cannot open %s: %s", gr_dbname (), strerror(errno))); exit (E_GRP_UPDATE); } @@ -353,9 +353,9 @@ static void open_files (void) if (is_shadow_grp) { if (sgr_open (O_CREAT | O_RDWR) == 0) { fprintf (stderr, - _("%s: cannot open %s\n"), - Prog, sgr_dbname ()); - SYSLOG ((LOG_WARN, "cannot open %s", sgr_dbname ())); + _("%s: cannot open %s: %s\n"), + Prog, sgr_dbname (), strerror(errno)); + SYSLOG ((LOG_WARN, "cannot open %s: %s", sgr_dbname (), strerror(errno))); exit (E_GRP_UPDATE); } } @@ -403,7 +403,7 @@ static void process_flags (int argc, char **argv) break; case 'g': gflg = true; - if ( (get_gid (optarg, &group_id) == 0) + if ( (get_gid(optarg, &group_id) == -1) || (group_id == (gid_t)-1)) { fprintf (stderr, _("%s: invalid group ID '%s'\n"), @@ -429,7 +429,7 @@ static void process_flags (int argc, char **argv) } /* terminate name, point to value */ *cp++ = '\0'; - if (putdef_str (optarg, cp) < 0) { + if (putdef_str (optarg, cp, NULL) < 0) { exit (E_BAD_ARG); } break; @@ -511,7 +511,7 @@ static void check_flags (void) } else { fprintf (stderr, _("%s: GID '%lu' already exists\n"), - Prog, (unsigned long int) group_id); + Prog, (unsigned long) group_id); exit (E_GID_IN_USE); } } @@ -543,7 +543,7 @@ static void check_perms (void) exit (1); } - retval = pam_start ("groupadd", pampw->pw_name, &conv, &pamh); + retval = pam_start (Prog, pampw->pw_name, &conv, &pamh); if (PAM_SUCCESS == retval) { retval = pam_authenticate (pamh, 0); @@ -572,10 +572,6 @@ static void check_perms (void) */ int main (int argc, char **argv) { - /* - * Get my name so that I can use it to report errors. - */ - Prog = Basename (argv[0]); log_set_progname(Prog); log_set_logfd(stderr); @@ -586,7 +582,7 @@ int main (int argc, char **argv) process_root_flag ("-R", argc, argv); prefix = process_prefix_flag ("-P", argc, argv); - OPENLOG ("groupadd"); + OPENLOG (Prog); #ifdef WITH_AUDIT audit_help_open (); #endif @@ -605,6 +601,11 @@ int main (int argc, char **argv) check_perms (); + if (run_parts ("/etc/shadow-maint/groupadd-pre.d", group_name, + Prog)) { + exit(1); + } + #ifdef SHADOWGRP is_shadow_grp = sgr_file_present (); #endif @@ -623,6 +624,11 @@ int main (int argc, char **argv) grp_update (); close_files (); + if (run_parts ("/etc/shadow-maint/groupadd-post.d", group_name, + Prog)) { + exit(1); + } + nscd_flush_cache ("group"); sssd_flush_cache (SSSD_DB_GROUP); |