summaryrefslogtreecommitdiffstats
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
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>
-rwxr-xr-xexamples/test_account.py41
-rw-r--r--mof/LMI_Account.mof25
-rw-r--r--src/account/LMI_AccountManagementServiceProvider.c107
3 files changed, 170 insertions, 3 deletions
diff --git a/examples/test_account.py b/examples/test_account.py
index d35da78..143a3c4 100755
--- a/examples/test_account.py
+++ b/examples/test_account.py
@@ -14,8 +14,8 @@ Available commands and their parameters:
delete_user - delete account, needed parameter is account name
delete_group - delete group, needed parameter is group name
delete_identity - delete user or group, parameter InstanceID of identity
- create_account - creates a new account, parameters:
- [0] = Name: required, user login name
+ create_account - creates a new account, parameter required, user login name
+ create_group - creates a new group, parameter required, group name
Example: %s https://127.0.0.1:5989 root redhat list_user""" % (sys.argv[0], sys.argv[0])
@@ -112,6 +112,43 @@ elif command == "create_account":
Name = parameters[0],
System = computerSystems[0].path)
+elif command == "create_group":
+# create a new group
+# Firstly find system name, which is necessary parameter for method
+# then invoke the method
+ if not parameters:
+ usage()
+ sys.exit(1)
+
+ computerSystems = cliconn.ExecQuery('WQL', 'select * from Linux_ComputerSystem')
+ if not computerSystems:
+ print >>sys.stderr, "No usable Linux_ComputerSystem instance found."
+ sys.exit(2)
+
+ if len(computerSystems) > 1:
+ print >>sys.stderr, "More than one Linux_ComputerSystem instance found, don't know which to use."
+ sys.exit(3)
+
+ lams = cliconn.ExecQuery('WQL', 'select * from LMI_AccountManagementService')[0]
+
+ print cliconn.InvokeMethod("CreateGroup", lams.path,
+ Name = parameters[0],
+ System = computerSystems[0].path)
+
+elif command == "delete_user":
+# Find user by given name and call DeleteInstance on the instance path
+ if not parameters:
+ usage()
+ sys.exit(1)
+
+ slct = 'select * from LMI_Account where Name = "%s"' % parameters[0]
+
+ instances = cliconn.ExecQuery('WQL', slct)
+ if instances:
+ print cliconn.DeleteInstance(instances[0].path)
+ else:
+ print >> sys.stderr, "User does not exist: %s" %parameters[0]
+
elif command == "delete_user":
# Find user by given name and call DeleteInstance on the instance path
if not parameters:
diff --git a/mof/LMI_Account.mof b/mof/LMI_Account.mof
index b2cbc00..75f0cf1 100644
--- a/mof/LMI_Account.mof
+++ b/mof/LMI_Account.mof
@@ -94,6 +94,31 @@ class LMI_AccountManagementService: CIM_SecurityService
"such instances are created." )]
CIM_Identity REF Identities[]);
+ [ Description ( "Create a new group on the system") ]
+ uint32 CreateGroup(
+ [Required, IN, Description (
+ "The scoping ComputerSystem in which to create the Account."
+ )]
+ CIM_ComputerSystem REF System,
+ [Required, IN, Description (
+ "Desired group name for the account to be created." ) ]
+ string Name,
+ [IN, Description (
+ "Pick a specific group id for new user" ) ]
+ uint32 GID,
+ [IN, Description (
+ "True for creating system account" ) ]
+ boolean SystemAccount,
+ [IN ( false ), OUT, Description (
+ "Reference to the instance of CIM_Group created "
+ "when the method returns a value of 0." )]
+ CIM_Group REF Group,
+ [IN ( false ), OUT, Description (
+ "Reference to the instances of CIM_Identity created "
+ "when the method returns a value of 0. NULL if no "
+ "such instances are created." )]
+ CIM_Identity REF Identities[]);
+
};
[ Provider("cmpi:cmpiCura_Account") ]
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;
}