summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-09-21 13:06:24 +0200
committerRoman Rakus <rrakus@redhat.com>2012-09-21 13:06:24 +0200
commit1285ef838782a6399606fc5af96e288236edf8e2 (patch)
tree0edba1d4488e50e0409e559dedf59ba2f3219b7c
parent7faa01fbaed22c074afeab82c4de811f29d6e8d2 (diff)
downloadopenlmi-providers-1285ef838782a6399606fc5af96e288236edf8e2.tar.gz
openlmi-providers-1285ef838782a6399606fc5af96e288236edf8e2.tar.xz
openlmi-providers-1285ef838782a6399606fc5af96e288236edf8e2.zip
account: DeleteInstance on LMI_Group
Signed-off-by: Roman Rakus <rrakus@redhat.com>
-rwxr-xr-xexamples/test_account.py15
-rw-r--r--src/account/LMI_GroupProvider.c40
2 files changed, 54 insertions, 1 deletions
diff --git a/examples/test_account.py b/examples/test_account.py
index 519a2f2..d35da78 100755
--- a/examples/test_account.py
+++ b/examples/test_account.py
@@ -12,6 +12,7 @@ Available commands and their parameters:
list_group - list groups, parameter is group name or empty for all
group_members - list members of group, parameter is group name
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
@@ -125,6 +126,20 @@ elif command == "delete_user":
else:
print >> sys.stderr, "User does not exist: %s" %parameters[0]
+elif command == "delete_group":
+# Find group by given name and call DeleteInstance on the instance path
+ if not parameters:
+ usage()
+ sys.exit(1)
+
+ slct = 'select * from LMI_Group where Name = "%s"' % parameters[0]
+
+ instances = cliconn.ExecQuery('WQL', slct)
+ if instances:
+ print cliconn.DeleteInstance(instances[0].path)
+ else:
+ print >> sys.stderr, "Group does not exist: %s" %parameters[0]
+
elif command == "delete_identity":
# Have to pass correct InstanceID
# It is in format:
diff --git a/src/account/LMI_GroupProvider.c b/src/account/LMI_GroupProvider.c
index 5de5318..3ffec5a 100644
--- a/src/account/LMI_GroupProvider.c
+++ b/src/account/LMI_GroupProvider.c
@@ -122,7 +122,45 @@ static CMPIStatus LMI_GroupDeleteInstance(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+ LMI_Group lg;
+ const char *name = NULL;
+ struct lu_context *luc = NULL;
+ struct lu_error *error = NULL;
+ struct lu_ent *lue = NULL;
+ char errmsg[256];
+
+ LMI_Group_InitFromObjectPath(&lg, _cb, cop);
+ name = lg.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);
+ }
+
+ lue = lu_ent_new();
+ if (!lu_group_lookup_name(luc, name, lue, &error))
+ { /* Group not found */
+ snprintf(errmsg, 256, "Non existing group: %s\n", name);
+ lu_ent_free(lue);
+ lu_end(luc);
+ CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg);
+ }
+
+ if (!lu_group_delete(luc, lue, &error))
+ {
+ snprintf(errmsg, 256, "Group %s could not be deleted: %s\n", name,
+ 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_GroupExecQuery(