sss_userdel.c revision 95cc95749a5e783f2b5d2124d783f85820baf937
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen This program is free software; you can redistribute it and/or modify
a85473f7c11c8734bdee9c2cbe4b767f144a18aaTimo Sirainen it under the terms of the GNU General Public License as published by
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen the Free Software Foundation; either version 3 of the License, or
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen (at your option) any later version.
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen This program is distributed in the hope that it will be useful,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen GNU General Public License for more details.
de3175adb4094086dc8ba13132a39567f9c42e54Timo Sirainen You should have received a copy of the GNU General Public License
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainenstatic int is_logged_in(TALLOC_CTX *mem_ctx, uid_t uid)
ce0e25f26d6e67480ee39b5ca0ad634fa60c4605Timo Sirainen DEBUG(1, ("Cannot initialize hash table.\n"));
c307328f59c963eba21091ecd36c9435d42b47d8Timo Sirainen while((child_pid = waitpid(pid, &status, 0)) > 0) {
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &pc_debug,
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen _("Remove home directory and mail spool"), NULL },
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen _("Do not remove home directory and mail spool"), NULL },
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen _("Force removal of files not owned by the user"), NULL },
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen _("Kill users' processes before removing him"), NULL },
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
9f240e2ce97176146b63506a8ee04034f712cf45Timo Sirainen /* parse parameters */
9f240e2ce97176146b63506a8ee04034f712cf45Timo Sirainen pc = poptGetContext(NULL, argc, argv, long_options, 0);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen debug_level = debug_convert_old_level(pc_debug);
6abf66a3731d52889517bd644595c540e3a9b3ecTimo Sirainen BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen BAD_POPT_PARAMS(pc, _("Specify user to delete\n"), ret, fini);
9f240e2ce97176146b63506a8ee04034f712cf45Timo Sirainen DEBUG(1, ("init_sss_tools failed (%d): %s\n", ret, strerror(ret)));
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen ERROR("Error initializing the tools - no local domain\n");
6abf66a3731d52889517bd644595c540e3a9b3ecTimo Sirainen /* if the domain was not given as part of FQDN, default to local domain */
307ec6c2c319e3335ddb1a7aca2d2884fe17fae0Timo Sirainen * Fills in defaults for ops_ctx user did not specify.
14f6fe5d6c4834f273ca573c23c0659a93123363Timo Sirainen ret = userdel_defaults(tctx, tctx->confdb, tctx->octx, pc_remove);
afd6d387ea65843b59fb6051fb567719d2a5279cAki Tuomi /* Error message will be printed in the switch */
70df8f39fb3db7c49b18c855178f8172176a037aTimo Sirainen if ((tctx->octx->uid < tctx->local->id_min) ||
7bd5b1c64cc987715bdaf8cc4907c3c37d5d7b29Timo Sirainen (tctx->local->id_max && tctx->octx->uid > tctx->local->id_max)) {
6abf66a3731d52889517bd644595c540e3a9b3ecTimo Sirainen ERROR("User %1$s is outside the defined ID range for domain\n",
40440c0fee87be994ba7eb60fc3512a9355708aaTimo Sirainen /* userdel */
40440c0fee87be994ba7eb60fc3512a9355708aaTimo Sirainen /* Set SELinux login context - must be done after transaction is done
979d89c147520f2934c14c31aeb9310fd2d62a46Timo Sirainen * b/c libselinux calls getpwnam */
979d89c147520f2934c14c31aeb9310fd2d62a46Timo Sirainen ERROR("Cannot reset SELinux login context\n");
40440c0fee87be994ba7eb60fc3512a9355708aaTimo Sirainen ERROR("WARNING: The user (uid %1$lu) was still logged in when "
979d89c147520f2934c14c31aeb9310fd2d62a46Timo Sirainen "deleted.\n", (unsigned long) tctx->octx->uid);
979d89c147520f2934c14c31aeb9310fd2d62a46Timo Sirainen ERROR("Cannot determine if the user was logged in on this "
70058d29cf8c77501741ddbc39178cfc87ca459eTimo Sirainen ERROR("Error while checking if the user was logged in\n");
979d89c147520f2934c14c31aeb9310fd2d62a46Timo Sirainen ERROR("The post-delete command failed: %1$s\n", strerror(ret));
70058d29cf8c77501741ddbc39178cfc87ca459eTimo Sirainen ERROR("Not removing home dir - not owned by user\n");
70058d29cf8c77501741ddbc39178cfc87ca459eTimo Sirainen ERROR("Cannot remove homedir: %1$s\n", strerror(ret));
40440c0fee87be994ba7eb60fc3512a9355708aaTimo Sirainen DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret)));
70058d29cf8c77501741ddbc39178cfc87ca459eTimo Sirainen "Removing users only allowed in local domain.\n");
464e82904c6670bd6c96b8793ceb294d776d6f44Timo Sirainen ERROR("Internal error. Could not remove user.\n");