summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-09-21 14:19:59 +0200
committerRoman Rakus <rrakus@redhat.com>2012-09-21 14:19:59 +0200
commit029fdf1051c2992e4a08202589ddf3067bb512b9 (patch)
tree9c6a67353251b254cb9f0fd98a71c99f06c30bfc /src
parent1285ef838782a6399606fc5af96e288236edf8e2 (diff)
downloadopenlmi-providers-029fdf1051c2992e4a08202589ddf3067bb512b9.tar.gz
openlmi-providers-029fdf1051c2992e4a08202589ddf3067bb512b9.tar.xz
openlmi-providers-029fdf1051c2992e4a08202589ddf3067bb512b9.zip
account: CreateGroup implemented
Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/account/LMI_AccountManagementServiceProvider.c107
1 files changed, 106 insertions, 1 deletions
diff --git a/src/account/LMI_AccountManagementServiceProvider.c b/src/account/LMI_AccountManagementServiceProvider.c
index a33df80..ae96b33 100644
--- a/src/account/LMI_AccountManagementServiceProvider.c
+++ b/src/account/LMI_AccountManagementServiceProvider.c
@@ -4,6 +4,7 @@
#include "CIM_ComputerSystem.h"
#include "LMI_Account.h"
#include "LMI_Identity.h"
+#include "LMI_Group.h"
#include "macros.h"
#include "globals.h"
@@ -194,6 +195,109 @@ KUint32 LMI_AccountManagementService_StopService(
return result;
}
+KUint32 LMI_AccountManagementService_CreateGroup(
+ const CMPIBroker* cb,
+ CMPIMethodMI* mi,
+ const CMPIContext* context,
+ const LMI_AccountManagementServiceRef* self,
+ const KRef* System,
+ const KString* Name,
+ const KUint32* GID,
+ const KBoolean* SystemAccount,
+ KRef* Group,
+ KRefA* Identities,
+ CMPIStatus* status)
+{
+ char errmsg[256], instanceid[256];
+ struct lu_context *luc = NULL;
+ struct lu_error *error = NULL;
+ struct lu_ent *lue = NULL;
+ GValue value;
+ const char *nameSpace = LMI_AccountManagementServiceRef_NameSpace(self);
+ CMPIEnumeration *instances = NULL;
+ LMI_GroupRef Groupref;
+ LMI_IdentityRef Identityref;
+ CMPIObjectPath *GroupOP = NULL, *IdentityOP = NULL;
+ KUint32 result = KUINT32_INIT;
+
+ KSetStatus(status, OK);
+ KUint32_Set(&result, 0);
+#define FAIL(MSG, ERROR, STATUS, RETVAL)\
+ snprintf(errmsg, 256, (MSG), (ERROR));\
+ KSetStatus2(cb, status, STATUS, errmsg);\
+ KUint32_Set(&result, (RETVAL));\
+
+ if (!(Name->exists && !Name->null) || !(System->exists && !System->null))
+ {
+ FAIL("Required parameters not specified%s\n", "", ERR_FAILED, 2);
+ goto clean;
+ }
+
+ luc = lu_start(NULL, lu_user, NULL, NULL, lu_prompt_console_quiet, NULL,
+ &error);
+ if (!luc)
+ {
+ FAIL("Error initializing: %s\n", lu_strerror(error), ERR_FAILED, 2);
+ goto clean;
+ }
+
+ instances = cb->bft->associatorNames(cb, context,
+ LMI_AccountManagementServiceRef_ToObjectPath(self, NULL),
+ LMI_HostedAccountManagementService_ClassName,
+ NULL, NULL, NULL, NULL);
+ if (!instances ||
+ !instances->ft->hasNext(instances, NULL) ||
+ !KMatch(System->value,
+ instances->ft->getNext(instances,NULL).value.ref))
+ { /* This service is not linked with provided system */
+ FAIL("Unable to create group on the given System%s\n", "",
+ ERR_FAILED, 2);
+ goto clean;
+ }
+
+ lue = lu_ent_new();
+ lu_group_default(luc, Name->chars,
+ SystemAccount->exists && !SystemAccount->null && SystemAccount->value,
+ lue);
+
+ if (GID->exists && !GID->null)
+ { /* GID number passed */
+ memset(&value, 0, sizeof(value));
+ lu_value_init_set_id(&value, GID->value);
+ lu_ent_clear(lue, LU_GIDNUMBER);
+ lu_ent_add(lue, LU_GIDNUMBER, &value);
+ g_value_unset(&value);
+ }
+
+ if (!lu_group_add(luc, lue, &error))
+ { /* Add group failed */
+ FAIL("Group Creation failed: %s\n", lu_strerror(error), ERR_FAILED, 2);
+ goto clean;
+ }
+
+ /* Output created Group reference */
+ LMI_GroupRef_Init(&Groupref, cb, nameSpace);
+ LMI_GroupRef_Set_Name(&Groupref, Name->chars);
+ LMI_GroupRef_Set_CreationClassName(&Groupref, LMI_Group_ClassName);
+ GroupOP = LMI_GroupRef_ToObjectPath(&Groupref, NULL);
+ KRef_SetObjectPath(Group, GroupOP);
+
+ /* Output created group identity */
+ KRefA_Init(Identities, cb, 1);
+ LMI_IdentityRef_Init(&Identityref, cb, nameSpace);
+ snprintf(instanceid, 255, ORGID":GID:%ld",
+ aux_lu_get_long(lue, LU_GIDNUMBER));
+ LMI_IdentityRef_Set_InstanceID(&Identityref, instanceid);
+ IdentityOP = LMI_IdentityRef_ToObjectPath(&Identityref, NULL);
+ KRefA_Set(Identities, 0, IdentityOP);
+
+clean:
+#undef FAIL
+ if (lue) lu_ent_free(lue);
+ if (luc) lu_end(luc);
+ return result;
+}
+
KUint32 LMI_AccountManagementService_CreateAccount(
const CMPIBroker* cb,
CMPIMethodMI* mi,
@@ -270,7 +374,8 @@ KUint32 LMI_AccountManagementService_CreateAccount(
!KMatch(System->value,
instances->ft->getNext(instances,NULL).value.ref))
{ /* This service is not linked with provided system */
- FAIL("Unable to create account on the System%s\n", "", ERR_FAILED, 2);
+ FAIL("Unable to create account on the given System%s\n", "",
+ ERR_FAILED, 2);
goto clean;
}