Index: lib/getdef.c =================================================================== --- lib/getdef.c.orig +++ lib/getdef.c @@ -127,6 +127,8 @@ static struct itemdef def_table[] = { {"UID_MIN", NULL}, {"UMASK", NULL}, {"USERDEL_CMD", NULL}, + {"USERDEL_PRECMD", NULL}, + {"USERDEL_POSTCMD", NULL}, {"USERGROUPS_ENAB", NULL}, #ifndef USE_PAM PAMDEFS Index: etc/login.defs =================================================================== --- etc/login.defs.orig +++ etc/login.defs @@ -216,9 +216,25 @@ DEFAULT_HOME yes # It should remove any at/cron/print jobs etc. owned by # the user to be removed (passed as the first argument). # +# See also USERDEL_PRECMD and USERDEL_POSTCMD below. +# #USERDEL_CMD /usr/sbin/userdel_local # +# If defined, this command is run before removing a user. +# It should remove any at/cron/print jobs etc. owned by +# the user to be removed. +# +USERDEL_PRECMD /usr/sbin/userdel-pre.local + +# +# If defined, this command is run after removing a user. +# It should rebuild any NIS database etc. to remove the +# account from it. +# +USERDEL_POSTCMD /usr/sbin/userdel-post.local + +# # Enable setting of the umask group bits to be the same as owner bits # (examples: 022 -> 002, 077 -> 007) for non-root users, if the uid is # the same as gid, and username is the same as the primary group name. Index: src/userdel.c =================================================================== --- src/userdel.c.orig +++ src/userdel.c @@ -126,7 +126,7 @@ static void close_files (void); static void fail_exit (int); static void open_files (void); static void update_user (void); -static void user_cancel (const char *); +static void call_script (const char *, const char *); #ifdef EXTRA_CHECK_HOME_DIR static bool path_prefix (const char *, const char *); @@ -768,13 +768,13 @@ static void update_user (void) * cron, at, or print jobs. */ -static void user_cancel (const char *user) +static void call_script (const char *program, const char *user) { const char *cmd; const char *argv[3]; int status; - cmd = getdef_str ("USERDEL_CMD"); + cmd = getdef_str (program); if (NULL == cmd) { return; } @@ -1214,9 +1214,10 @@ int main (int argc, char **argv) } /* - * Do the hard stuff - open the files, create the user entries, - * create the home directory, then close and update the files. + * Do the hard stuff - open the files, remove the user entries, + * remove the home directory, then close and update the files. */ + call_script ("USERDEL_PRECMD", user_name); open_files (); update_user (); update_groups (); @@ -1337,7 +1338,7 @@ int main (int argc, char **argv) * the entry from /etc/passwd. */ if(prefix[0] == '\0') - user_cancel (user_name); + call_script ("USERDEL_CMD", user_name); close_files (); #ifdef WITH_TCB @@ -1348,6 +1349,9 @@ int main (int argc, char **argv) nscd_flush_cache ("group"); sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); + /* Call the post script, for example to rebuild NIS database */ + call_script ("USERDEL_POSTCMD", user_name); + return ((0 != errors) ? E_HOMEDIR : E_SUCCESS); }