static bool silence_warnings = false;
/* local function prototypes */
-static void fail_exit (int status);
+static void fail_exit (int status, bool process_selinux);
NORETURN static void usage (int status);
static void delete_member (char **, const char *);
static void process_flags (int argc, char **argv, struct option_flags *flags);
-static void open_files (void);
+static void open_files (bool process_selinux);
static void close_files (bool changed, struct option_flags *flags);
static int check_members (const char *groupname,
char **members,
const char *fmt_prompt,
const char *fmt_syslog,
bool *errors);
-static void check_grp_file (bool *errors, bool *changed);
+static void check_grp_file (bool *errors, bool *changed,
+ struct option_flags *flags);
#ifdef SHADOWGRP
static void compare_members_lists (const char *groupname,
char **members,
/*
* fail_exit - exit with an error code after unlocking files
*/
-static void fail_exit (int status)
+static void fail_exit (int status, bool process_selinux)
{
if (gr_locked) {
- if (gr_unlock (true) == 0) {
+ if (gr_unlock (process_selinux) == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, gr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", gr_dbname ()));
/* continue */
#ifdef SHADOWGRP
if (sgr_locked) {
- if (sgr_unlock (true) == 0) {
+ if (sgr_unlock (process_selinux) == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sgr_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", sgr_dbname ()));
/* continue */
* In read-only mode, the databases are not locked and are opened
* only for reading.
*/
-static void open_files (void)
+static void open_files (bool process_selinux)
{
/*
* Lock the files if we aren't in "read-only" mode
fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"),
Prog, grp_file);
- fail_exit (E_CANT_LOCK);
+ fail_exit (E_CANT_LOCK, process_selinux);
}
gr_locked = true;
#ifdef SHADOWGRP
fprintf (stderr,
_("%s: cannot lock %s; try again later.\n"),
Prog, sgr_file);
- fail_exit (E_CANT_LOCK);
+ fail_exit (E_CANT_LOCK, process_selinux);
}
sgr_locked = true;
}
if (use_system_grp_file) {
SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
}
- fail_exit (E_CANT_OPEN);
+ fail_exit (E_CANT_OPEN, process_selinux);
}
#ifdef SHADOWGRP
if (is_shadow && (sgr_open (read_only ? O_RDONLY : O_CREAT | O_RDWR) == 0)) {
if (use_system_sgr_file) {
SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
}
- fail_exit (E_CANT_OPEN);
+ fail_exit (E_CANT_OPEN, process_selinux);
}
#endif
}
if (gr_close (process_selinux) == 0) {
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
Prog, grp_file);
- fail_exit (E_CANT_UPDATE);
+ fail_exit (E_CANT_UPDATE, process_selinux);
}
#ifdef SHADOWGRP
if (is_shadow && (sgr_close (process_selinux) == 0)) {
fprintf (stderr, _("%s: failure while writing changes to %s\n"),
Prog, sgr_file);
- fail_exit (E_CANT_UPDATE);
+ fail_exit (E_CANT_UPDATE, process_selinux);
}
#endif
}
/*
* check_grp_file - check the content of the group file
*/
-static void check_grp_file (bool *errors, bool *changed)
+static void check_grp_file (bool *errors, bool *changed, struct option_flags *flags)
{
struct commonio_entry *gre, *tgre;
struct group *grp;
#ifdef SHADOWGRP
const struct sgrp *sgr;
#endif
+ bool process_selinux;
+
+ process_selinux = !flags->chroot;
/*
* Loop through the entire group file.
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, sgr_dbname (), sg.sg_namp);
- fail_exit (E_CANT_UPDATE);
+ fail_exit (E_CANT_UPDATE, process_selinux);
}
/* remove password from /etc/group */
gr = *grp;
fprintf (stderr,
_("%s: failed to prepare the new %s entry '%s'\n"),
Prog, gr_dbname (), gr.gr_name);
- fail_exit (E_CANT_UPDATE);
+ fail_exit (E_CANT_UPDATE, process_selinux);
}
}
} else {
bool errors = false;
bool changed = false;
struct option_flags flags;
+ bool process_selinux;
log_set_progname(Prog);
log_set_logfd(stderr);
/* Parse the command line arguments */
process_flags (argc, argv, &flags);
+ process_selinux = !flags.chroot;
- open_files ();
+ open_files (process_selinux);
if (sort_mode) {
gr_sort ();
changed = true;
#endif
} else {
- check_grp_file (&errors, &changed);
+ check_grp_file (&errors, &changed, &flags);
#ifdef SHADOWGRP
if (is_shadow) {
check_sgr_file (&errors, &changed);