* src/userdel.c: Use a bool for the is_shadow_pwd, is_shadow_grp,

deleted_user_group, was_member, was_admin, and the
	options' flags.
	* src/userdel.c: Change path_prefix() prototype to return a bool.
	* src/userdel.c: Ignore return value of setlocale(),
	bindtextdomain(), and textdomain().
	* src/userdel.c: Ignore the return value from pam_end() since we
	are exiting anyway just afterwards.
	* src/userdel.c: Avoid implicit conversion of pointers /
	integers / chars to booleans.
	* src/userdel.c: Add brackets and parenthesis.
	* src/userdel.c: Avoid assignments in comparisons.
	* src/userdel.c: Do not ignore the return value of the *_unlock()
	functions.
This commit is contained in:
nekral-guest 2008-06-09 19:10:44 +00:00
parent 46466a8fcc
commit 8b98a2e829
2 changed files with 126 additions and 82 deletions

View File

@ -1,3 +1,20 @@
2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/userdel.c: Use a bool for the is_shadow_pwd, is_shadow_grp,
deleted_user_group, was_member, was_admin, and the
options' flags.
* src/userdel.c: Change path_prefix() prototype to return a bool.
* src/userdel.c: Ignore return value of setlocale(),
bindtextdomain(), and textdomain().
* src/userdel.c: Ignore the return value from pam_end() since we
are exiting anyway just afterwards.
* src/userdel.c: Avoid implicit conversion of pointers /
integers / chars to booleans.
* src/userdel.c: Add brackets and parenthesis.
* src/userdel.c: Avoid assignments in comparisons.
* src/userdel.c: Do not ignore the return value of the *_unlock()
functions.
2008-06-09 Nicolas François <nicolas.francois@centraliens.net> 2008-06-09 Nicolas François <nicolas.francois@centraliens.net>
* src/login_nopam.c: Do not use the YES and NO macros. Use the * src/login_nopam.c: Do not use the YES and NO macros. Use the

View File

@ -73,12 +73,13 @@ static uid_t user_id;
static char *user_home; static char *user_home;
static char *Prog; static char *Prog;
static int fflg = 0, rflg = 0; static bool fflg = false;
static bool rflg = false;
static int is_shadow_pwd; static bool is_shadow_pwd;
#ifdef SHADOWGRP #ifdef SHADOWGRP
static int is_shadow_grp; static bool is_shadow_grp;
#endif #endif
/* local function prototypes */ /* local function prototypes */
@ -92,7 +93,7 @@ static void user_busy (const char *, uid_t);
static void user_cancel (const char *); static void user_cancel (const char *);
#ifdef EXTRA_CHECK_HOME_DIR #ifdef EXTRA_CHECK_HOME_DIR
static int path_prefix (const char *, const char *); static bool path_prefix (const char *, const char *);
#endif #endif
static int is_owner (uid_t, const char *); static int is_owner (uid_t, const char *);
static void remove_mailbox (void); static void remove_mailbox (void);
@ -130,7 +131,7 @@ static void update_groups (void)
struct passwd *pwd; struct passwd *pwd;
#ifdef SHADOWGRP #ifdef SHADOWGRP
int deleted_user_group = 0; bool deleted_user_group = false;
const struct sgrp *sgrp; const struct sgrp *sgrp;
struct sgrp *nsgrp; struct sgrp *nsgrp;
#endif /* SHADOWGRP */ #endif /* SHADOWGRP */
@ -139,7 +140,7 @@ static void update_groups (void)
* Scan through the entire group file looking for the groups that * Scan through the entire group file looking for the groups that
* the user is a member of. * the user is a member of.
*/ */
for (gr_rewind (), grp = gr_next (); grp; grp = gr_next ()) { for (gr_rewind (), grp = gr_next (); NULL != grp; grp = gr_next ()) {
/* /*
* See if the user specified this group as one of their * See if the user specified this group as one of their
@ -153,14 +154,14 @@ static void update_groups (void)
* update the group entry to reflect the change. * update the group entry to reflect the change.
*/ */
ngrp = __gr_dup (grp); ngrp = __gr_dup (grp);
if (!ngrp) { if (NULL == ngrp) {
fprintf (stderr, fprintf (stderr,
_("%s: Out of memory. Cannot update the group database.\n"), _("%s: Out of memory. Cannot update the group database.\n"),
Prog); Prog);
exit (13); /* XXX */ exit (13); /* XXX */
} }
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name); ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
if (!gr_update (ngrp)) { if (gr_update (ngrp) == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: error updating group entry\n"), Prog); _("%s: error updating group entry\n"), Prog);
exit (E_GRP_UPDATE); exit (E_GRP_UPDATE);
@ -184,8 +185,9 @@ static void update_groups (void)
* user name, with no members, we delete it. * user name, with no members, we delete it.
*/ */
grp = xgetgrnam (user_name); grp = xgetgrnam (user_name);
if (grp && getdef_bool ("USERGROUPS_ENAB") if ( (NULL != grp)
&& (grp->gr_mem[0] == NULL)) { && getdef_bool ("USERGROUPS_ENAB")
&& (NULL == grp->gr_mem[0])) {
pwd = NULL; pwd = NULL;
if (!fflg) { if (!fflg) {
@ -194,9 +196,10 @@ static void update_groups (void)
* used as a primary group. * used as a primary group.
*/ */
setpwent (); setpwent ();
while ((pwd = getpwent ())) { while ((pwd = getpwent ()) != NULL) {
if (strcmp (pwd->pw_name, user_name) == 0) if (strcmp (pwd->pw_name, user_name) == 0) {
continue; continue;
}
if (pwd->pw_gid == grp->gr_gid) { if (pwd->pw_gid == grp->gr_gid) {
fprintf (stderr, fprintf (stderr,
_ _
@ -208,7 +211,7 @@ static void update_groups (void)
endpwent (); endpwent ();
} }
if (pwd == NULL) { if (NULL == pwd) {
/* /*
* We can remove this group, it is not the primary * We can remove this group, it is not the primary
* group of any remaining user. * group of any remaining user.
@ -216,7 +219,7 @@ static void update_groups (void)
gr_remove (grp->gr_name); gr_remove (grp->gr_name);
#ifdef SHADOWGRP #ifdef SHADOWGRP
deleted_user_group = 1; deleted_user_group = true;
#endif #endif
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -229,16 +232,19 @@ static void update_groups (void)
} }
} }
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (!is_shadow_grp) if (!is_shadow_grp) {
return; return;
}
/* /*
* Scan through the entire shadow group file looking for the groups * Scan through the entire shadow group file looking for the groups
* that the user is a member of. Both the administrative list and * that the user is a member of. Both the administrative list and
* the ordinary membership list is checked. * the ordinary membership list is checked.
*/ */
for (sgr_rewind (), sgrp = sgr_next (); sgrp; sgrp = sgr_next ()) { for (sgr_rewind (), sgrp = sgr_next ();
int was_member, was_admin; NULL != sgrp;
sgrp = sgr_next ()) {
bool was_member, was_admin;
/* /*
* See if the user specified this group as one of their * See if the user specified this group as one of their
@ -247,24 +253,27 @@ static void update_groups (void)
was_member = is_on_list (sgrp->sg_mem, user_name); was_member = is_on_list (sgrp->sg_mem, user_name);
was_admin = is_on_list (sgrp->sg_adm, user_name); was_admin = is_on_list (sgrp->sg_adm, user_name);
if (!was_member && !was_admin) if (!was_member && !was_admin) {
continue; continue;
}
nsgrp = __sgr_dup (sgrp); nsgrp = __sgr_dup (sgrp);
if (!nsgrp) { if (NULL == nsgrp) {
fprintf (stderr, fprintf (stderr,
_("%s: Out of memory. Cannot update the shadow group database.\n"), _("%s: Out of memory. Cannot update the shadow group database.\n"),
Prog); Prog);
exit (13); /* XXX */ exit (13); /* XXX */
} }
if (was_member) if (was_member) {
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name); nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
}
if (was_admin) if (was_admin) {
nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name); nsgrp->sg_adm = del_list (nsgrp->sg_adm, user_name);
}
if (!sgr_update (nsgrp)) { if (sgr_update (nsgrp) == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: error updating shadow group entry\n"), Prog); _("%s: error updating shadow group entry\n"), Prog);
exit (E_GRP_UPDATE); exit (E_GRP_UPDATE);
@ -291,26 +300,28 @@ static void update_groups (void)
*/ */
static void close_files (void) static void close_files (void)
{ {
if (!pw_close ()) if (pw_close () == 0)
fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog); fprintf (stderr, _("%s: cannot rewrite password file\n"), Prog);
if (is_shadow_pwd && !spw_close ()) if (is_shadow_pwd && (spw_close () == 0))
fprintf (stderr, fprintf (stderr,
_("%s: cannot rewrite shadow password file\n"), Prog); _("%s: cannot rewrite shadow password file\n"), Prog);
if (!gr_close ()) if (gr_close () == 0)
fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog); fprintf (stderr, _("%s: cannot rewrite group file\n"), Prog);
(void) gr_unlock (); gr_unlock ();
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (is_shadow_grp && !sgr_close ()) if (is_shadow_grp && (sgr_close () == 0))
fprintf (stderr, fprintf (stderr,
_("%s: cannot rewrite shadow group file\n"), Prog); _("%s: cannot rewrite shadow group file\n"), Prog);
if (is_shadow_grp) if (is_shadow_grp) {
(void) sgr_unlock (); sgr_unlock ();
}
#endif #endif
if (is_shadow_pwd) if (is_shadow_pwd) {
(void) spw_unlock (); spw_unlock ();
(void) pw_unlock (); }
pw_unlock ();
} }
/* /*
@ -318,13 +329,15 @@ static void close_files (void)
*/ */
static void fail_exit (int code) static void fail_exit (int code)
{ {
(void) pw_unlock (); pw_unlock ();
(void) gr_unlock (); gr_unlock ();
if (is_shadow_pwd) if (is_shadow_pwd) {
spw_unlock (); spw_unlock ();
}
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (is_shadow_grp) if (is_shadow_grp) {
sgr_unlock (); sgr_unlock ();
}
#endif #endif
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting user", user_name, audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "deleting user", user_name,
@ -341,7 +354,7 @@ static void fail_exit (int code)
static void open_files (void) static void open_files (void)
{ {
if (!pw_lock ()) { if (pw_lock () == 0) {
fprintf (stderr, _("%s: unable to lock password file\n"), Prog); fprintf (stderr, _("%s: unable to lock password file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
@ -349,7 +362,7 @@ static void open_files (void)
#endif #endif
exit (E_PW_UPDATE); exit (E_PW_UPDATE);
} }
if (!pw_open (O_RDWR)) { if (pw_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: unable to open password file\n"), Prog); fprintf (stderr, _("%s: unable to open password file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
@ -357,7 +370,7 @@ static void open_files (void)
#endif #endif
fail_exit (E_PW_UPDATE); fail_exit (E_PW_UPDATE);
} }
if (is_shadow_pwd && !spw_lock ()) { if (is_shadow_pwd && (spw_lock () == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: cannot lock shadow password file\n"), Prog); _("%s: cannot lock shadow password file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -367,7 +380,7 @@ static void open_files (void)
#endif #endif
fail_exit (E_PW_UPDATE); fail_exit (E_PW_UPDATE);
} }
if (is_shadow_pwd && !spw_open (O_RDWR)) { if (is_shadow_pwd && (spw_open (O_RDWR) == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: cannot open shadow password file\n"), Prog); _("%s: cannot open shadow password file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -377,7 +390,7 @@ static void open_files (void)
#endif #endif
fail_exit (E_PW_UPDATE); fail_exit (E_PW_UPDATE);
} }
if (!gr_lock ()) { if (gr_lock () == 0) {
fprintf (stderr, _("%s: unable to lock group file\n"), Prog); fprintf (stderr, _("%s: unable to lock group file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking group file", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "locking group file",
@ -385,7 +398,7 @@ static void open_files (void)
#endif #endif
fail_exit (E_GRP_UPDATE); fail_exit (E_GRP_UPDATE);
} }
if (!gr_open (O_RDWR)) { if (gr_open (O_RDWR) == 0) {
fprintf (stderr, _("%s: cannot open group file\n"), Prog); fprintf (stderr, _("%s: cannot open group file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening group file", audit_logger (AUDIT_USER_CHAUTHTOK, Prog, "opening group file",
@ -394,7 +407,7 @@ static void open_files (void)
fail_exit (E_GRP_UPDATE); fail_exit (E_GRP_UPDATE);
} }
#ifdef SHADOWGRP #ifdef SHADOWGRP
if (is_shadow_grp && !sgr_lock ()) { if (is_shadow_grp && (sgr_lock () == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: unable to lock shadow group file\n"), Prog); _("%s: unable to lock shadow group file\n"), Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -404,7 +417,7 @@ static void open_files (void)
#endif #endif
fail_exit (E_GRP_UPDATE); fail_exit (E_GRP_UPDATE);
} }
if (is_shadow_grp && !sgr_open (O_RDWR)) { if (is_shadow_grp && (sgr_open (O_RDWR) == 0)) {
fprintf (stderr, _("%s: cannot open shadow group file\n"), fprintf (stderr, _("%s: cannot open shadow group file\n"),
Prog); Prog);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -425,12 +438,12 @@ static void open_files (void)
*/ */
static void update_user (void) static void update_user (void)
{ {
if (!pw_remove (user_name)) { if (pw_remove (user_name) == 0) {
fprintf (stderr, fprintf (stderr,
_("%s: error deleting password entry\n"), Prog); _("%s: error deleting password entry\n"), Prog);
fail_exit (E_PW_UPDATE); fail_exit (E_PW_UPDATE);
} }
if (is_shadow_pwd && !spw_remove (user_name)) { if (is_shadow_pwd && (spw_remove (user_name) == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: error deleting shadow password entry\n"), Prog); _("%s: error deleting shadow password entry\n"), Prog);
fail_exit (E_PW_UPDATE); fail_exit (E_PW_UPDATE);
@ -460,18 +473,19 @@ static void user_busy (const char *name, uid_t uid)
struct utmpx *utent; struct utmpx *utent;
setutxent (); setutxent ();
while ((utent = getutxent ())) { while ((utent = getutxent ()) != NULL) {
#else #else
struct utmp *utent; struct utmp *utent;
setutent (); setutent ();
while ((utent = getutent ())) { while ((utent = getutent ()) != NULL) {
#endif #endif
if (utent->ut_type != USER_PROCESS) if (utent->ut_type != USER_PROCESS)
continue; continue;
if (strncmp (utent->ut_user, name, sizeof utent->ut_user)) if (strncmp (utent->ut_user, name, sizeof utent->ut_user) != 0) {
continue; continue;
}
fprintf (stderr, fprintf (stderr,
_("%s: user %s is currently logged in\n"), Prog, name); _("%s: user %s is currently logged in\n"), Prog, name);
if (!fflg) { if (!fflg) {
@ -527,8 +541,10 @@ static void user_cancel (const char *user)
int pid, wpid; int pid, wpid;
int status; int status;
if (!(cmd = getdef_str ("USERDEL_CMD"))) cmd = getdef_str ("USERDEL_CMD");
if (NUll == cmd) {
return; return;
}
pid = fork (); pid = fork ();
if (pid == 0) { if (pid == 0) {
execl (cmd, cmd, user, (char *) 0); execl (cmd, cmd, user, (char *) 0);
@ -540,14 +556,15 @@ static void user_cancel (const char *user)
} }
do { do {
wpid = wait (&status); wpid = wait (&status);
} while (wpid != pid && wpid != -1); } while ((wpid != pid) && (-1 != wpid));
} }
#ifdef EXTRA_CHECK_HOME_DIR #ifdef EXTRA_CHECK_HOME_DIR
static int path_prefix (const char *s1, const char *s2) static bool path_prefix (const char *s1, const char *s2)
{ {
return (strncmp (s2, s1, strlen (s1)) == 0 && return ( (strncmp (s2, s1, strlen (s1)) == 0)
(s2[strlen (s1)] == '\0' || s2[strlen (s1)] == '/')); && ( ('\0' == s2[strlen (s1)])
|| ('/' == s2[strlen (s1)])));
} }
#endif #endif
@ -555,8 +572,9 @@ static int is_owner (uid_t uid, const char *path)
{ {
struct stat st; struct stat st;
if (stat (path, &st)) if (stat (path, &st) != 0) {
return -1; return -1;
}
return (st.st_uid == uid); return (st.st_uid == uid);
} }
@ -568,11 +586,13 @@ static void remove_mailbox (void)
maildir = getdef_str ("MAIL_DIR"); maildir = getdef_str ("MAIL_DIR");
#ifdef MAIL_SPOOL_DIR #ifdef MAIL_SPOOL_DIR
if (!maildir && !getdef_str ("MAIL_FILE")) if ((NULL == maildir) && (getdef_str ("MAIL_FILE") == NULL)) {
maildir = MAIL_SPOOL_DIR; maildir = MAIL_SPOOL_DIR;
}
#endif #endif
if (!maildir) if (NULL == maildir) {
return; return;
}
snprintf (mailfile, sizeof mailfile, "%s/%s", maildir, user_name); snprintf (mailfile, sizeof mailfile, "%s/%s", maildir, user_name);
if (fflg) { if (fflg) {
unlink (mailfile); /* always remove, ignore errors */ unlink (mailfile); /* always remove, ignore errors */
@ -595,7 +615,7 @@ static void remove_mailbox (void)
return; return;
} else if (i == -1) } else if (i == -1)
return; /* mailbox doesn't exist */ return; /* mailbox doesn't exist */
if (unlink (mailfile)) { if (unlink (mailfile) != 0) {
fprintf (stderr, _("%s: warning: can't remove "), Prog); fprintf (stderr, _("%s: warning: can't remove "), Prog);
perror (mailfile); perror (mailfile);
} }
@ -627,9 +647,9 @@ int main (int argc, char **argv)
* Get my name so that I can use it to report errors. * Get my name so that I can use it to report errors.
*/ */
Prog = Basename (argv[0]); Prog = Basename (argv[0]);
setlocale (LC_ALL, ""); (void) setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR); (void) bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE); (void) textdomain (PACKAGE);
{ {
/* /*
@ -642,15 +662,14 @@ int main (int argc, char **argv)
{"remove", no_argument, NULL, 'r'}, {"remove", no_argument, NULL, 'r'},
{NULL, 0, NULL, '\0'} {NULL, 0, NULL, '\0'}
}; };
while ((c = while ((c = getopt_long (argc, argv, "fhr",
getopt_long (argc, argv, "fhr", long_options, NULL)) != -1) {
long_options, NULL)) != -1) {
switch (c) { switch (c) {
case 'f': /* force remove even if not owned by user */ case 'f': /* force remove even if not owned by user */
fflg++; fflg = true;
break; break;
case 'r': /* remove home dir and mailbox */ case 'r': /* remove home dir and mailbox */
rflg++; rflg = true;
break; break;
default: default:
usage (); usage ();
@ -658,8 +677,9 @@ int main (int argc, char **argv)
} }
} }
if (optind + 1 != argc) if ((optind + 1) != argc) {
usage (); usage ();
}
OPENLOG ("userdel"); OPENLOG ("userdel");
@ -681,14 +701,16 @@ int main (int argc, char **argv)
if (retval == PAM_SUCCESS) { if (retval == PAM_SUCCESS) {
retval = pam_authenticate (pamh, 0); retval = pam_authenticate (pamh, 0);
if (retval != PAM_SUCCESS) if (retval != PAM_SUCCESS) {
pam_end (pamh, retval); (void) pam_end (pamh, retval);
}
} }
if (retval == PAM_SUCCESS) { if (retval == PAM_SUCCESS) {
retval = pam_acct_mgmt (pamh, 0); retval = pam_acct_mgmt (pamh, 0);
if (retval != PAM_SUCCESS) if (retval != PAM_SUCCESS) {
pam_end (pamh, retval); (void) pam_end (pamh, retval);
}
} }
if (retval != PAM_SUCCESS) { if (retval != PAM_SUCCESS) {
@ -708,8 +730,8 @@ int main (int argc, char **argv)
user_name = argv[argc - 1]; user_name = argv[argc - 1];
{ {
struct passwd *pwd; struct passwd *pwd;
/* local, no need for xgetpwnam */ pwd = getpwnam (user_name); /* local, no need for xgetpwnam */
if (!(pwd = getpwnam (user_name))) { if (NULL == pwd) {
fprintf (stderr, _("%s: user %s does not exist\n"), fprintf (stderr, _("%s: user %s does not exist\n"),
Prog, user_name); Prog, user_name);
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
@ -732,7 +754,7 @@ int main (int argc, char **argv)
fprintf (stderr, fprintf (stderr,
_("%s: user %s is a NIS user\n"), Prog, user_name); _("%s: user %s is a NIS user\n"), Prog, user_name);
if (!yp_get_default_domain (&nis_domain) if ( !yp_get_default_domain (&nis_domain)
&& !yp_master (nis_domain, "passwd.byname", &nis_master)) { && !yp_master (nis_domain, "passwd.byname", &nis_master)) {
fprintf (stderr, fprintf (stderr,
_("%s: %s is the NIS master\n"), _("%s: %s is the NIS master\n"),
@ -754,9 +776,10 @@ int main (int argc, char **argv)
update_user (); update_user ();
update_groups (); update_groups ();
if (rflg) if (rflg) {
remove_mailbox (); remove_mailbox ();
if (rflg && !fflg && !is_owner (user_id, user_home)) { }
if (rflg && !fflg && (is_owner (user_id, user_home) == 0)) {
fprintf (stderr, fprintf (stderr,
_("%s: %s not owned by %s, not removing\n"), _("%s: %s not owned by %s, not removing\n"),
Prog, user_home, user_name); Prog, user_home, user_name);
@ -777,14 +800,15 @@ int main (int argc, char **argv)
*/ */
setpwent (); setpwent ();
while ((pwd = getpwent ())) { while ((pwd = getpwent ())) {
if (strcmp (pwd->pw_name, user_name) == 0) if (strcmp (pwd->pw_name, user_name) == 0) {
continue; continue;
}
if (path_prefix (user_home, pwd->pw_dir)) { if (path_prefix (user_home, pwd->pw_dir)) {
fprintf (stderr, fprintf (stderr,
_ _
("%s: not removing directory %s (would remove home of user %s)\n"), ("%s: not removing directory %s (would remove home of user %s)\n"),
Prog, user_home, pwd->pw_name); Prog, user_home, pwd->pw_name);
rflg = 0; rflg = false;
errors++; errors++;
break; break;
} }
@ -822,14 +846,17 @@ int main (int argc, char **argv)
nscd_flush_cache ("group"); nscd_flush_cache ("group");
#ifdef USE_PAM #ifdef USE_PAM
if (retval == PAM_SUCCESS) if (retval == PAM_SUCCESS) {
pam_end (pamh, PAM_SUCCESS); (void) pam_end (pamh, PAM_SUCCESS);
}
#endif /* USE_PAM */ #endif /* USE_PAM */
#ifdef WITH_AUDIT #ifdef WITH_AUDIT
if (errors) if (0 != errors) {
audit_logger (AUDIT_USER_CHAUTHTOK, Prog, audit_logger (AUDIT_USER_CHAUTHTOK, Prog,
"deleting home directory", user_name, -1, 0); "deleting home directory", user_name, -1, 0);
}
#endif #endif
exit (errors ? E_HOMEDIR : E_SUCCESS); exit ((0 != errors) ? E_HOMEDIR : E_SUCCESS);
/* NOT REACHED */ /* NOT REACHED */
} }