#define E_PWDBUSY 5 /* passwd file busy, try again later */
#define E_BAD_ARG 6 /* invalid argument to option */
#define E_PAM_ERR 10 /* PAM returned an error */
+
+struct option_flags {
+ bool chroot;
+ bool prefix;
+};
+
/*
* Global variables
*/
NORETURN static void fail_exit (int);
NORETURN static void oom (void);
static char *update_crypt_pw (char *);
-static void update_noshadow (void);
+static void update_noshadow (struct option_flags *flags);
-static void update_shadow (void);
+static void update_shadow (struct option_flags *flags);
/*
* usage - print command usage and exit
}
-static void update_noshadow (void)
+static void update_noshadow (struct option_flags *flags)
{
const struct passwd *pw;
struct passwd *npw;
+ bool process_selinux;
+
+ process_selinux = !flags->chroot && !flags->prefix;
if (pw_lock () == 0) {
(void) fprintf (stderr,
Prog, pw_dbname (), npw->pw_name);
fail_exit (E_FAILURE);
}
- if (pw_close (true) == 0) {
+ if (pw_close (process_selinux) == 0) {
(void) 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 (E_FAILURE);
}
- if (pw_unlock (true) == 0) {
+ if (pw_unlock (process_selinux) == 0) {
(void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, pw_dbname ());
pw_locked = false;
}
-static void update_shadow (void)
+static void update_shadow (struct option_flags *flags)
{
const struct spwd *sp;
struct spwd *nsp;
+ bool process_selinux;
+
+ process_selinux = !flags->chroot && !flags->prefix;
if (spw_lock () == 0) {
(void) fprintf (stderr,
sp = spw_locate (name);
if (NULL == sp) {
/* Try to update the password in /etc/passwd instead. */
- (void) spw_close (true);
- update_noshadow ();
- if (spw_unlock (true) == 0) {
+ (void) spw_close (process_selinux);
+ update_noshadow (flags);
+ if (spw_unlock (process_selinux) == 0) {
(void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
Prog, spw_dbname (), nsp->sp_namp);
fail_exit (E_FAILURE);
}
- if (spw_close (true) == 0) {
+ if (spw_close (process_selinux) == 0) {
(void) 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 (E_FAILURE);
}
- if (spw_unlock (true) == 0) {
+ if (spw_unlock (process_selinux) == 0) {
(void) fprintf (stderr,
_("%s: failed to unlock %s\n"),
Prog, spw_dbname ());
char *cp; /* Miscellaneous character pointing */
const struct spwd *sp; /* Shadow file entry for user */
+ struct option_flags flags;
sanitize_env ();
check_fds ();
}
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 'S':
Sflg = true; /* ok for users */
exit (E_NOPERM);
}
if (spw_file_present ()) {
- update_shadow ();
+ update_shadow (&flags);
} else {
- update_noshadow ();
+ update_noshadow (&flags);
}
nscd_flush_cache ("passwd");