From 1beae32fc6232ceab2d426e189fa6a3f91a721fa Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Sat, 7 Mar 2009 00:33:10 +0100 Subject: sss_groupdel, delete by DN in sss_userdel Don't convert username->uid in userdel, use DN --- server/tools/sss_userdel.c | 83 ++++++---------------------------------------- 1 file changed, 10 insertions(+), 73 deletions(-) (limited to 'server/tools/sss_userdel.c') diff --git a/server/tools/sss_userdel.c b/server/tools/sss_userdel.c index 1fa00fb3f..e0f6300ee 100644 --- a/server/tools/sss_userdel.c +++ b/server/tools/sss_userdel.c @@ -33,7 +33,7 @@ struct user_del_ctx { sysdb_callback_t next_fn; const char *username; - uid_t uid; + struct ldb_dn *user_dn; struct sss_domain_info *domain; struct tools_ctx *ctx; @@ -42,38 +42,6 @@ struct user_del_ctx { bool done; }; -struct fetch_user { - uid_t uid; - int error; - bool done; -}; - -static void getpwnam_callback(void *ptr, int error, struct ldb_result *res) -{ - struct fetch_user *data = talloc_get_type(ptr, struct fetch_user); - - data->done = true; - - if (error) { - data->error = error; - return; - } - - switch (res->count) { - case 0: - data->error = ENOENT; - break; - - case 1: - data->uid = ldb_msg_find_attr_as_uint(res->msgs[0], SYSDB_UIDNUM, 0); - break; - - default: - data->error = EFAULT; - break; - } -} - /* sysdb callback */ static void userdel_done(void *pvt, int error, struct ldb_result *ignore) { @@ -96,10 +64,10 @@ static void user_del(struct sysdb_req *req, void *pvt) user_ctx = talloc_get_type(pvt, struct user_del_ctx); user_ctx->sysreq = req; - ret = sysdb_delete_user_by_uid(req, "LOCAL", - user_ctx->uid, - userdel_done, - user_ctx); + ret = sysdb_delete_entry(req, + user_ctx->user_dn, + userdel_done, + user_ctx); if(ret != EOK) userdel_done(user_ctx, ret, NULL); @@ -110,7 +78,6 @@ int main(int argc, const char **argv) int ret = EXIT_SUCCESS; struct user_del_ctx *user_ctx = NULL; struct tools_ctx *ctx = NULL; - struct fetch_user *fetch_ctx = NULL; poptContext pc; @@ -135,12 +102,6 @@ int main(int argc, const char **argv) } user_ctx->ctx = ctx; - fetch_ctx = talloc_zero(ctx, struct fetch_user); - if (fetch_ctx == NULL) { - DEBUG(0, ("Could not allocate memory for fetch_user context\n")); - return ENOMEM; - } - /* parse user_ctx */ pc = poptGetContext(NULL, argc, argv, long_options, 0); poptSetOtherOptionHelp(pc, "USERNAME"); @@ -166,39 +127,15 @@ int main(int argc, const char **argv) goto fini; } - /* Look up uid for given username */ - ret = sysdb_getpwnam(fetch_ctx, ctx->sysdb, - "LOCAL", - user_ctx->username, - false, - getpwnam_callback, - fetch_ctx); - if(ret != EOK) { - DEBUG(1, ("sysdb_getpwnam failed: %d\n", ret)); + user_ctx->user_dn = sysdb_user_dn(ctx->sysdb, ctx, + user_ctx->domain->name, + user_ctx->username); + if(user_ctx->user_dn == NULL) { + DEBUG(0, ("Could not construct an user DN\n")); ret = EXIT_FAILURE; goto fini; } - while (!fetch_ctx->done) { - tevent_loop_once(ctx->ev); - } - - if(fetch_ctx->error) { - ret = fetch_ctx->error; - switch(ret) { - case ENOENT: - DEBUG(0, ("No such user: %s\n", user_ctx->username)); - break; - - default: - DEBUG(0, ("sysdb_getpwnam failed: (%d) [%s]\n", - ret, strerror(ret))); - break; - } - goto fini; - } - - user_ctx->uid = fetch_ctx->uid; /* userdel */ ret = sysdb_transaction(ctx, ctx->sysdb, user_del, user_ctx); -- cgit