summaryrefslogtreecommitdiffstats
path: root/server/tools/sss_userdel.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/tools/sss_userdel.c')
-rw-r--r--server/tools/sss_userdel.c100
1 files changed, 6 insertions, 94 deletions
diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c
index 3454e8bbf..00ccc8672 100644
--- a/server/tools/sss_userdel.c
+++ b/server/tools/sss_userdel.c
@@ -32,14 +32,6 @@
#include "util/util.h"
#include "tools/tools_util.h"
-#ifndef USERDEL
-#define USERDEL SHADOW_UTILS_PATH"/userdel "
-#endif
-
-#ifndef USERDEL_USERNAME
-#define USERDEL_USERNAME "%s "
-#endif
-
static void userdel_req_done(struct tevent_req *req)
{
struct ops_ctx *data = tevent_req_callback_data(req, struct ops_ctx);
@@ -115,40 +107,14 @@ static void user_del_done(struct tevent_req *subreq)
return userdel_done(data, ret, NULL);
}
-static int userdel_legacy(struct ops_ctx *ctx)
-{
- int ret = EOK;
- char *command = NULL;
-
- APPEND_STRING(command, USERDEL);
- APPEND_PARAM(command, USERDEL_USERNAME, ctx->name);
-
- ret = system(command);
- if (ret) {
- if (ret == -1) {
- DEBUG(1, ("system(3) failed\n"));
- } else {
- DEBUG(1, ("Could not exec '%s', return code: %d\n",
- command, WEXITSTATUS(ret)));
- }
- talloc_free(command);
- return EFAULT;
- }
-
- talloc_free(command);
- return ret;
-}
-
int main(int argc, const char **argv)
{
int ret = EXIT_SUCCESS;
struct ops_ctx *data = NULL;
struct tools_ctx *ctx = NULL;
struct tevent_req *req;
- struct sss_domain_info *dom;
struct passwd *pwd_info;
const char *pc_username = NULL;
- enum id_domain domain_type;
int pc_debug = 0;
poptContext pc = NULL;
@@ -205,8 +171,10 @@ int main(int argc, const char **argv)
goto fini;
}
- ret = parse_name_domain(data, pc_username);
+ /* if the domain was not given as part of FQDN, default to local domain */
+ ret = get_domain(data, pc_username);
if (ret != EOK) {
+ ERROR("Cannot get domain information\n");
ret = EXIT_FAILURE;
goto fini;
}
@@ -217,53 +185,11 @@ int main(int argc, const char **argv)
data->uid = pwd_info->pw_uid;
}
- ret = get_domain_by_id(data->ctx, data->uid, &dom);
- if (ret != EOK) {
- ERROR("Cannot get domain info\n");
- ret = EXIT_FAILURE;
- goto fini;
- }
- if (data->domain && data->uid && data->domain != dom) {
- ERROR("Selected domain %s conflicts with selected UID %llu\n",
- data->domain->name, (unsigned long long int) data->uid);
+ if (id_in_range(data->uid, data->domain) != EOK) {
+ ERROR("The selected UID is outside the allowed range\n");
ret = EXIT_FAILURE;
goto fini;
}
- if (data->domain == NULL && dom) {
- data->domain = dom;
- }
-
- domain_type = get_domain_type(data->ctx, data->domain);
- switch (domain_type) {
- case ID_IN_LOCAL:
- break;
-
- case ID_IN_LEGACY_LOCAL:
- ret = userdel_legacy(data);
- if(ret != EOK) {
- ERROR("Cannot delete user from domain using the legacy tools\n");
- ret = EXIT_FAILURE;
- goto fini;
- }
- break; /* Also delete possible cached entries in sysdb */
-
- case ID_OUTSIDE:
- ERROR("The selected UID is outside all domain ranges\n");
- ret = EXIT_FAILURE;
- goto fini;
-
- case ID_IN_OTHER:
- DEBUG(1, ("Cannot remove user from domain %s\n", dom->name));
- ERROR("Unsupported domain type\n");
- ret = EXIT_FAILURE;
- goto fini;
-
- default:
- DEBUG(1, ("Unknown return code %d from get_domain_type\n", domain_type));
- ERROR("Error looking up domain\n");
- ret = EXIT_FAILURE;
- goto fini;
- }
/* userdel */
req = sysdb_transaction_send(ctx, ctx->ev, data->ctx->sysdb);
@@ -282,21 +208,7 @@ int main(int argc, const char **argv)
if (data->error) {
ret = data->error;
DEBUG(1, ("sysdb operation failed (%d)[%s]\n", ret, strerror(ret)));
- switch (ret) {
- case ENOENT:
- /* if we got ENOENT after deleting user from legacy domain
- * that just means there was no cached entry to delete */
- if (domain_type == ID_IN_LEGACY_LOCAL) {
- ret = EXIT_SUCCESS;
- goto fini;
- }
- ERROR("No such user\n");
- break;
-
- default:
- ERROR("Internal error. Could not remove user.\n");
- break;
- }
+ ERROR("Internal error. Could not remove user.\n");
ret = EXIT_FAILURE;
goto fini;
}