summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-12-20 15:54:02 +0100
committerRoman Rakus <rrakus@redhat.com>2012-12-20 15:54:02 +0100
commit614fafbd51250b4869b2e079ff45cf4eaab74aaf (patch)
tree947f6c5cb4f4bf41e8ace99692630b4ba587a413 /src
parent544e20ffff6da79a33947efd4413c84ec558ac42 (diff)
downloadopenlmi-providers-614fafbd51250b4869b2e079ff45cf4eaab74aaf.tar.gz
openlmi-providers-614fafbd51250b4869b2e079ff45cf4eaab74aaf.tar.xz
openlmi-providers-614fafbd51250b4869b2e079ff45cf4eaab74aaf.zip
Account: Allow to create instance of LMI_MemberOfGroup
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/account/LMI_MemberOfGroupProvider.c73
1 files changed, 72 insertions, 1 deletions
diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c
index e3480cd..2609e7a 100644
--- a/src/account/LMI_MemberOfGroupProvider.c
+++ b/src/account/LMI_MemberOfGroupProvider.c
@@ -22,6 +22,7 @@
#include "LMI_MemberOfGroup.h"
#include "LMI_Group.h"
#include "LMI_Identity.h"
+#include "LMI_AssignedAccountIdentity.h"
#include "aux_lu.h"
#include "macros.h"
@@ -151,7 +152,77 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance(
const CMPIObjectPath* cop,
const CMPIInstance* ci)
{
- CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+ CMPIStatus status;
+ CMPIEnumeration *instances = NULL;
+ char errmsg[256];
+
+ LMI_GroupRef lg_ref;
+ LMI_IdentityRef li_ref;
+ LMI_MemberOfGroup lmog;
+ LMI_Account la;
+
+ char *group_name = NULL;
+ char *user_name = NULL;
+ GValue val;
+
+ struct lu_context *luc = NULL;
+ struct lu_ent *lue = lu_ent_new();
+ struct lu_error *error = NULL;
+
+ LMI_MemberOfGroup_InitFromObjectPath(&lmog, _cb, cop);
+ LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb,
+ CMGetProperty(ci, "Collection", NULL).value.ref);
+ LMI_IdentityRef_InitFromObjectPath(&li_ref, _cb,
+ CMGetProperty(ci, "Member", NULL).value.ref);
+
+ if (!(instances = CBAssociators(_cb, cc,
+ LMI_IdentityRef_ToObjectPath(&li_ref, NULL),
+ LMI_AssignedAccountIdentity_ClassName, LMI_Account_ClassName, NULL,
+ NULL, NULL, &status)) || !CMHasNext(instances, &status)) {
+ snprintf(errmsg, 256, "Unable to find user: %s\n",
+ status.msg ? CMGetCharsPtr(status.msg, NULL) : "" );
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg);
+ }
+ LMI_Account_InitFromInstance(&la, _cb, CMGetNext(instances, &status).value.inst);
+
+ user_name = la.Name.chars;
+ group_name = lg_ref.Name.chars;
+
+ 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_group_lookup_name(luc, group_name, lue, &error)) {
+ snprintf(errmsg, 256, "Group with name %s not found: %s\n", group_name,
+ lu_strerror(error));
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg);
+ }
+
+ memset(&val, 0, sizeof(val));
+ g_value_init(&val, G_TYPE_STRING);
+ g_value_set_string(&val, user_name);
+ lu_ent_add(lue, LU_MEMBERNAME, &val);
+ if(!lu_group_modify(luc, lue, &error)) {
+ snprintf(errmsg, 256, "Modification of group %s failed: %s\n",
+ group_name, lu_strerror(error));
+ lu_ent_free(lue);
+ lu_end(luc);
+ g_value_unset(&val);
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg);
+ }
+
+ g_value_unset(&val);
+ lu_ent_free(lue);
+ lu_end(luc);
+
+ LMI_MemberOfGroup_Set_Collection(&lmog, &lg_ref);
+ LMI_MemberOfGroup_Set_Member(&lmog, &li_ref);
+
+
+ CMReturnObjectPath(cr, LMI_MemberOfGroup_ToObjectPath(&lmog, NULL));
+ CMReturn(CMPI_RC_OK);
}
static CMPIStatus LMI_MemberOfGroupModifyInstance(