sss_userdel.c revision b3292840ebaa747a9fd596ff47cc5d18198361d0
/*
SSSD
sss_userdel
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <nss.h>
#include <stdio.h>
#include <stdlib.h>
#include <talloc.h>
#include <popt.h>
#include "util/find_uid.h"
#include "tools/tools_util.h"
#include "tools/sss_sync_ops.h"
#ifndef KILL_CMD
#define KILL_CMD "killall"
#endif
#ifndef KILL_CMD_USER_FLAG
#define KILL_CMD_USER_FLAG "-u"
#endif
#ifndef KILL_CMD_SIGNAL_FLAG
#define KILL_CMD_SIGNAL_FLAG "-s"
#endif
#ifndef KILL_CMD_SIGNAL
#define KILL_CMD_SIGNAL "SIGKILL"
#endif
{
int ret;
return ret;
}
}
{
int ret;
int status;
return ret;
}
errno = 0;
if (pid == 0) {
/* child */
(char *) NULL);
} else {
/* parent */
if (pid == -1) {
return ret;
}
break;
}
}
if (child_pid == -1) {
return errno;
}
}
return EOK;
}
{
int ret = EXIT_SUCCESS;
const char *pc_username = NULL;
int pc_debug = SSSDBG_DEFAULT;
int pc_remove = 0;
int pc_force = 0;
int pc_kick = 0;
struct poptOption long_options[] = {
0, _("The debug level to run with"), NULL },
_("Remove home directory and mail spool"), NULL },
_("Do not remove home directory and mail spool"), NULL },
_("Force removal of files not owned by the user"), NULL },
_("Kill users' processes before removing him"), NULL },
};
debug_prg_name = argv[0];
ret = set_locale();
ERROR("Error setting the locale\n");
ret = EXIT_FAILURE;
goto fini;
}
/* parse parameters */
switch (ret) {
case 'r':
break;
case 'R':
break;
case 'f':
break;
case 'k':
pc_kick = 1;
break;
}
}
if (ret != -1) {
}
if (pc_username == NULL) {
}
ERROR("Error initializing the tools - no local domain\n");
} else {
ERROR("Error initializing the tools\n");
}
ret = EXIT_FAILURE;
goto fini;
}
/* if the domain was not given as part of FQDN, default to local domain */
ERROR("Invalid domain specified in FQDN\n");
ret = EXIT_FAILURE;
goto fini;
}
/*
* Fills in defaults for ops_ctx user did not specify.
*/
ERROR("Cannot set default values\n");
ret = EXIT_FAILURE;
goto fini;
}
/* Error message will be printed in the switch */
goto done;
}
ERROR("User %1$s is outside the defined ID range for domain\n",
ret = EXIT_FAILURE;
goto fini;
}
if (pc_kick) {
goto done;
}
}
/* userdel */
goto done;
}
/* Set SELinux login context - must be done after transaction is done
* b/c libselinux calls getpwnam */
ERROR("Cannot reset SELinux login context\n");
ret = EXIT_FAILURE;
goto fini;
}
if (!pc_kick) {
switch(ret) {
case ENOENT:
break;
case EOK:
ERROR("WARNING: The user (uid %1$lu) was still logged in when "
break;
case ENOSYS:
ERROR("Cannot determine if the user was logged in on this "
"platform");
break;
default:
ERROR("Error while checking if the user was logged in\n");
break;
}
}
goto fini;
}
/* Delete user from memory cache */
ERROR("NSS request failed (%1$d). Entry might remain in memory "
"cache.\n", ret);
/* Nothing we can do about it */
}
pc_force);
ERROR("Not removing home dir - not owned by user\n");
ret = EXIT_FAILURE;
goto fini;
}
}
done:
if (ret) {
switch (ret) {
case ENOENT:
ERROR("No such user in local domain. "
"Removing users only allowed in local domain.\n");
break;
default:
ERROR("Internal error. Could not remove user.\n");
break;
}
ret = EXIT_FAILURE;
goto fini;
}
ret = EXIT_SUCCESS;
fini:
}