#define E_PAM_USERNAME 12 /* can't determine your username for use with pam */
#define E_PAM_ERROR 13 /* pam returned an error, see Syslog facility id groupmod */
+struct option_flags {
+ bool chroot;
+ bool prefix;
+};
/*
* Global variables
static void grp_update (void);
static void check_new_gid (void);
static void check_new_name (void);
-static void process_flags (int, char **);
-static void lock_files (void);
+static void process_flags (int, char **, struct option_flags *);
+static void lock_files (struct option_flags *flags);
static void prepare_failure_reports (void);
static void open_files (void);
-static void close_files (void);
+static void close_files (struct option_flags *flags);
static void update_primary_groups (gid_t ogid, gid_t ngid);
* values that the user will be created with accordingly. The values
* are checked for sanity.
*/
-static void process_flags (int argc, char **argv)
+static void process_flags (int argc, char **argv, struct option_flags *flags)
{
int c;
static struct option long_options[] = {
pflg = true;
break;
case 'R': /* no-op, handled in process_root_flag () */
+ flags->chroot = true;
break;
case 'P': /* no-op, handled in process_prefix_flag () */
+ flags->prefix = true;
break;
case 'U':
user_list = optarg;
* close_files() closes all of the files that were opened for this new
* group. This causes any modified entries to be written out.
*/
-static void close_files (void)
+static void close_files (struct option_flags *flags)
{
- if (gr_close (true) == 0) {
+ bool process_selinux;
+
+ process_selinux = !flags->chroot && !flags->prefix;
+
+ if (gr_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, gr_dbname ());
gr_dbname (), info_group.action));
del_cleanup (cleanup_report_mod_group);
- cleanup_unlock_group (NULL);
+ cleanup_unlock_group (&process_selinux);
del_cleanup (cleanup_unlock_group);
#ifdef SHADOWGRP
if ( is_shadow_grp
&& (pflg || nflg || user_list)) {
- if (sgr_close (true) == 0) {
+ if (sgr_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, sgr_dbname ());
sgr_dbname (), info_gshadow.action));
del_cleanup (cleanup_report_mod_gshadow);
- cleanup_unlock_gshadow (NULL);
+ cleanup_unlock_gshadow (&process_selinux);
del_cleanup (cleanup_unlock_gshadow);
}
#endif /* SHADOWGRP */
if (gflg) {
- if (pw_close (true) == 0) {
+ if (pw_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, pw_dbname ());
pw_dbname (), info_passwd.action));
del_cleanup (cleanup_report_mod_passwd);
- cleanup_unlock_passwd (NULL);
+ cleanup_unlock_passwd (&process_selinux);
del_cleanup (cleanup_unlock_passwd);
}
*
* lock_files() locks the group, gshadow, and passwd databases.
*/
-static void lock_files (void)
+static void lock_files (struct option_flags *flags)
{
+ bool process_selinux;
+
+ process_selinux = !flags->chroot && !flags->prefix;
+
if (gr_lock () == 0) {
fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"),
Prog, gr_dbname ());
exit (E_GRP_UPDATE);
}
- add_cleanup (cleanup_unlock_group, NULL);
+ add_cleanup (cleanup_unlock_group, &process_selinux);
#ifdef SHADOWGRP
if ( is_shadow_grp
Prog, sgr_dbname ());
exit (E_GRP_UPDATE);
}
- add_cleanup (cleanup_unlock_gshadow, NULL);
+ add_cleanup (cleanup_unlock_gshadow, &process_selinux);
}
#endif
Prog, pw_dbname ());
exit (E_GRP_UPDATE);
}
- add_cleanup (cleanup_unlock_passwd, NULL);
+ add_cleanup (cleanup_unlock_passwd, &process_selinux);
}
}
int retval;
#endif /* USE_PAM */
#endif /* ACCT_TOOLS_SETUID */
+ struct option_flags flags;
log_set_progname(Prog);
log_set_logfd(stderr);
exit (E_CLEANUP_SERVICE);
}
- process_flags (argc, argv);
+ process_flags (argc, argv, &flags);
#ifdef ACCT_TOOLS_SETUID
#ifdef USE_PAM
check_new_name ();
}
- lock_files ();
+ lock_files (&flags);
/*
* Now if the group is not changed, it's our fault.
grp_update ();
- close_files ();
+ close_files (&flags);
nscd_flush_cache ("group");
sssd_flush_cache (SSSD_DB_GROUP);