diff options
author | Michal Minar <miminar@redhat.com> | 2012-12-13 13:28:37 +0100 |
---|---|---|
committer | Michal Minar <miminar@redhat.com> | 2012-12-13 13:28:37 +0100 |
commit | 7446295de4c5507ef5865c0806a63f107810e206 (patch) | |
tree | 885cf3d7b5d4442f8391afb28527b8eb53b91a43 /src | |
parent | 54e501a7225d30695bdcc2edb3b406986290e6e6 (diff) | |
parent | 544e20ffff6da79a33947efd4413c84ec558ac42 (diff) | |
download | openlmi-providers-7446295de4c5507ef5865c0806a63f107810e206.tar.gz openlmi-providers-7446295de4c5507ef5865c0806a63f107810e206.tar.xz openlmi-providers-7446295de4c5507ef5865c0806a63f107810e206.zip |
Merge branch 'master' of ssh://git.fedorahosted.org/git/openlmi-providers
Diffstat (limited to 'src')
-rw-r--r-- | src/account/LMI_MemberOfGroupProvider.c | 77 |
1 files changed, 76 insertions, 1 deletions
diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c index a2bd1c8..e3480cd 100644 --- a/src/account/LMI_MemberOfGroupProvider.c +++ b/src/account/LMI_MemberOfGroupProvider.c @@ -171,7 +171,82 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance( const CMPIResult* cr, const CMPIObjectPath* cop) { - CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); + LMI_MemberOfGroup lmog; + LMI_GroupRef lg_ref; + LMI_IdentityRef li_ref; + + struct lu_context *luc = NULL; + struct lu_ent *lue_g = lu_ent_new(); + struct lu_ent *lue_u = lu_ent_new(); + struct lu_error *error = NULL; + + char *group_name = NULL; + uid_t user_id = -1; + GValueArray *groups = NULL; + char errmsg[256]; + unsigned int i = 0; /* iterator */ + int found = 0; /* indicator */ + + LMI_MemberOfGroup_InitFromObjectPath(&lmog, _cb, cop); + LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb, lmog.Collection.value); + LMI_IdentityRef_InitFromObjectPath(&li_ref, _cb, lmog.Member.value); + + group_name = lg_ref.Name.chars; + user_id = (uid_t)atol(strrchr(li_ref.InstanceID.chars, ':') + 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 (!lu_user_lookup_id(luc, user_id, lue_u, &error)) { + snprintf(errmsg, 256, "User with id %d not found: %s\n", user_id, + lu_strerror(error)); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + + if (!lu_group_lookup_name(luc, group_name, lue_g, &error)) { + snprintf(errmsg, 256, "Group with name %s not found: %s\n", group_name, + lu_strerror(error)); + lu_ent_free(lue_u); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + groups = lu_ent_get(lue_g, LU_MEMBERNAME); + for (found = 0, i = 0; groups && i < groups->n_values; i++) { + if (0 != strcmp(group_name, g_value_get_string(g_value_array_get_nth( + groups, i)))) { + found = 1; + break; + } + } + if (!found) { + snprintf(errmsg, 256, "User with id %d is not in group %s or is " + "users' primary group\n", user_id, group_name); + lu_ent_free(lue_u); + lu_ent_free(lue_g); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } else { + /* And now remove the user from the group */ + g_value_array_remove(groups, i); + lu_ent_set(lue_g, LU_MEMBERNAME, groups); + if(!lu_group_modify(luc, lue_g, &error)) { + snprintf(errmsg, 256, "Modification of group %s failed: %s\n", + group_name, lu_strerror(error)); + lu_ent_free(lue_u); + lu_ent_free(lue_g); + lu_end(luc); + CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg); + } + } + + lu_ent_free(lue_u); + lu_ent_free(lue_g); + lu_end(luc); + CMReturn(CMPI_RC_OK); } static CMPIStatus LMI_MemberOfGroupExecQuery( |