#include "string/strtok/stpsep.h"
#include "string/strtok/strsep2arr.h"
+struct option_flags {
+ bool chroot;
+};
+
/*
* Global variables
static int update_passwd (struct passwd *, const char *);
#endif /* !USE_PAM */
static int add_passwd (struct passwd *, const char *);
-static void process_flags (int argc, char **argv);
+static void process_flags (int argc, char **argv, struct option_flags *flags);
static void check_flags (void);
static void check_perms (void);
static void open_files (void);
-static void close_files (void);
+static void close_files (struct option_flags *flags);
extern int allow_bad_names;
*
* It will not return if an error is encountered.
*/
-static void process_flags (int argc, char **argv)
+static void process_flags (int argc, char **argv, struct option_flags *flags)
{
int c;
#ifndef USE_PAM
rflg = true;
break;
case 'R': /* no-op, handled in process_root_flag () */
+ flags->chroot = true;
break;
#ifndef USE_PAM
#if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT) || defined(USE_YESCRYPT)
/*
* close_files - close and unlock the password, group and shadow databases
*/
-static void close_files (void)
+static void close_files (struct option_flags *flags)
{
- if (pw_close (true) == 0) {
+ bool process_selinux;
+
+ process_selinux = !flags->chroot;
+
+ if (pw_close (process_selinux) == 0) {
fprintf (stderr, _("%s: failure while writing changes to %s\n"), Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", pw_dbname ()));
fail_exit (EXIT_FAILURE);
}
- if (pw_unlock (true) == 0) {
+ if (pw_unlock (process_selinux) == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, pw_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", pw_dbname ()));
/* continue */
pw_locked = false;
if (is_shadow) {
- if (spw_close (true) == 0) {
+ if (spw_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, spw_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", spw_dbname ()));
fail_exit (EXIT_FAILURE);
}
- if (spw_unlock (true) == 0) {
+ if (spw_unlock (process_selinux) == 0) {
fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
spw_locked = false;
}
- if (gr_close (true) == 0) {
+ if (gr_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, gr_dbname ());
fail_exit (EXIT_FAILURE);
}
#ifdef ENABLE_SUBIDS
- if (is_sub_uid && (sub_uid_close (true) == 0)) {
+ if (is_sub_uid && (sub_uid_close (process_selinux) == 0)) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"), Prog, sub_uid_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_uid_dbname ()));
fail_exit (EXIT_FAILURE);
}
- if (is_sub_gid && (sub_gid_close (true) == 0)) {
+ if (is_sub_gid && (sub_gid_close (process_selinux) == 0)) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"), Prog, sub_gid_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", sub_gid_dbname ()));
}
#endif /* ENABLE_SUBIDS */
- if (gr_unlock (true) == 0) {
+ if (gr_unlock (process_selinux) == 0) {
fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, gr_dbname ());
#ifdef SHADOWGRP
if (is_shadow_grp) {
- if (sgr_close (true) == 0) {
+ if (sgr_close (process_selinux) == 0) {
fprintf (stderr,
_("%s: failure while writing changes to %s\n"),
Prog, sgr_dbname ());
SYSLOG ((LOG_ERR, "failure while writing changes to %s", sgr_dbname ()));
fail_exit (EXIT_FAILURE);
}
- if (sgr_unlock (true) == 0) {
+ if (sgr_unlock (process_selinux) == 0) {
fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, sgr_dbname ());
#endif
#ifdef ENABLE_SUBIDS
if (is_sub_uid) {
- if (sub_uid_unlock (true) == 0) {
+ if (sub_uid_unlock (process_selinux) == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_uid_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", sub_uid_dbname ()));
/* continue */
sub_uid_locked = false;
}
if (is_sub_gid) {
- if (sub_gid_unlock (true) == 0) {
+ if (sub_gid_unlock (process_selinux) == 0) {
fprintf (stderr, _("%s: failed to unlock %s\n"), Prog, sub_gid_dbname ());
SYSLOG ((LOG_ERR, "failed to unlock %s", sub_gid_dbname ()));
/* continue */
char **passwords = NULL;
size_t nusers = 0;
#endif /* USE_PAM */
+ struct option_flags flags;
log_set_progname(Prog);
log_set_logfd(stderr);
OPENLOG ("newusers");
- process_flags (argc, argv);
+ process_flags (argc, argv, &flags);
check_perms ();
* changes to be written out all at once, and then unlocked
* afterwards.
*/
- close_files ();
+ close_files (&flags);
nscd_flush_cache ("passwd");
nscd_flush_cache ("group");