From 7faa01fbaed22c074afeab82c4de811f29d6e8d2 Mon Sep 17 00:00:00 2001 From: Roman Rakus Date: Fri, 21 Sep 2012 12:05:20 +0200 Subject: account: DeleteInstance of LMI_Identity Signed-off-by: Roman Rakus --- src/account/LMI_IdentityProvider.c | 69 +++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/account/LMI_IdentityProvider.c b/src/account/LMI_IdentityProvider.c index 0e7a3b6..32bb0ee 100644 --- a/src/account/LMI_IdentityProvider.c +++ b/src/account/LMI_IdentityProvider.c @@ -136,7 +136,74 @@ static CMPIStatus LMI_IdentityDeleteInstance( const CMPIResult* cr, const CMPIObjectPath* cop) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + LMI_Identity identity; + const char* instance_id = NULL; + id_t id; + char errmsg[256]; + struct lu_context *luc = NULL; + struct lu_error *error = NULL; + struct lu_ent *lue = NULL; + + LMI_Identity_InitFromObjectPath(&identity, _cb, cop); + lue = lu_ent_new(); + instance_id = identity.InstanceID.chars; + id = atol(rindex(instance_id, ':') + 1); + + luc = lu_start(NULL, 0, NULL, NULL, lu_prompt_console_quiet, NULL, &error); + if (!luc) + { + fprintf(stderr, "Error initializing: %s\n", lu_strerror(error)); + exit(1); + } + + if (strstr(instance_id, ":GID:")) + { /* It's a group */ + if (!lu_group_lookup_id(luc, id, lue, &error)) + { /* User with that ID is not present */ + snprintf(errmsg, 256, "Non existing group id: %d\n", id); + lu_ent_free(lue); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + } + else + { + if (!lu_group_delete(luc, lue, &error)) + { /* user delete error */ + snprintf(errmsg, 256, + "Group with id %d could not be deleted: %s\n", id, + lu_strerror(error)); + lu_ent_free(lue); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + } + } + else + { /* It's an user */ + if (!lu_user_lookup_id(luc, id, lue, &error)) + { /* User with that ID is not present */ + snprintf(errmsg, 256, "Non existing user id: %d\n", id); + lu_ent_free(lue); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg); + } + else + { + if (!lu_user_delete(luc, lue, &error)) + { /* user delete error */ + snprintf(errmsg, 256, + "User with id %d could not be deleted: %s\n", id, + lu_strerror(error)); + lu_ent_free(lue); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + } + } + lu_ent_free(lue); + lu_end(luc); + + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_IdentityExecQuery( -- cgit