diff --git a/ChangeLog b/ChangeLog index e40db48a..55362860 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2011-06-04 Nicolas François + + * NEWS, src/userdel.c: Check the existence of the user's mail + spool before trying to remove it. If it does not exist, a warning + is issued, but no failure. + 2011-06-03 Nicolas François * src/sulogin.c: Added Prog, needed because of the last xmalloc() diff --git a/NEWS b/NEWS index d6698c76..0dd82107 100644 --- a/NEWS +++ b/NEWS @@ -44,6 +44,9 @@ shadow-4.1.4.3 -> shadow-4.1.5 UNRELEASED - useradd * If the skeleton directory contained hardlinked files, copies of the hardlink were removed from the skeleton directory. +- userdel + * Check the existence of the user's mail spool before trying to remove + it. If it does not exist, a warning is issued, but no failure. - usermod * Accept options in any order (username not necessarily at the end) diff --git a/src/userdel.c b/src/userdel.c index 49edac70..7c9463ca 100644 --- a/src/userdel.c +++ b/src/userdel.c @@ -2,7 +2,7 @@ * Copyright (c) 1991 - 1994, Julianne Frances Haugh * Copyright (c) 1996 - 2000, Marek Michałkiewicz * Copyright (c) 2000 - 2006, Tomasz Kłoczko - * Copyright (c) 2007 - 2010, Nicolas François + * Copyright (c) 2007 - 2011, Nicolas François * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -668,6 +668,28 @@ static int remove_mailbox (void) return 0; } snprintf (mailfile, sizeof mailfile, "%s/%s", maildir, user_name); + + if (access (mailfile, F_OK) != 0) { + if (ENOENT == errno) { + fprintf (stderr, + _("%s: %s mail spool (%s) not found\n"), + Prog, user_name, user_home); + return 0; + } else { + fprintf (stderr, + _("%s: warning: can't remove %s: %s\n"), + Prog, mailfile, strerror (errno)); + SYSLOG ((LOG_ERR, "Cannot remove %s: %s", mailfile, strerror (errno))); +#ifdef WITH_AUDIT + audit_logger (AUDIT_DEL_USER, Prog, + "deleting mail file", + user_name, (unsigned int) user_id, + SHADOW_AUDIT_FAILURE); +#endif /* WITH_AUDIT */ + return -1; + } + } + if (fflg) { if (unlink (mailfile) != 0) { fprintf (stderr,