summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2012-09-21 12:05:20 +0200
committerRoman Rakus <rrakus@redhat.com>2012-09-21 12:05:20 +0200
commit7faa01fbaed22c074afeab82c4de811f29d6e8d2 (patch)
tree69a154c97689faee584fc0d1c16dcfb7344efb7e
parentc6f1a3dcdcb0b0fb8e7d52c954b0b1c72d7acdf9 (diff)
downloadopenlmi-providers-7faa01fbaed22c074afeab82c4de811f29d6e8d2.tar.gz
openlmi-providers-7faa01fbaed22c074afeab82c4de811f29d6e8d2.tar.xz
openlmi-providers-7faa01fbaed22c074afeab82c4de811f29d6e8d2.zip
account: DeleteInstance of LMI_Identity
Signed-off-by: Roman Rakus <rrakus@redhat.com>
-rwxr-xr-xexamples/test_account.py22
-rw-r--r--src/account/LMI_IdentityProvider.c69
2 files changed, 88 insertions, 3 deletions
diff --git a/examples/test_account.py b/examples/test_account.py
index e3bca25..519a2f2 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_identity - delete user or group, parameter InstanceID of identity
create_account - creates a new account, parameters:
[0] = Name: required, user login name
@@ -111,8 +112,7 @@ elif command == "create_account":
System = computerSystems[0].path)
elif command == "delete_user":
-# Listintg users is simple, just query all instances from LMI_Account
-# or select only by given Name
+# Find user by given name and call DeleteInstance on the instance path
if not parameters:
usage()
sys.exit(1)
@@ -125,6 +125,24 @@ elif command == "delete_user":
else:
print >> sys.stderr, "User does not exist: %s" %parameters[0]
+elif command == "delete_identity":
+# Have to pass correct InstanceID
+# It is in format:
+# LMI:UID:user_id
+# or
+# LMI:GID:group_id
+ if not parameters:
+ usage()
+ sys.exit(1)
+
+ slct = 'select * from LMI_Identity where InstanceID = "%s"' % parameters[0]
+
+ instances = cliconn.ExecQuery('WQL', slct)
+ if instances:
+ print cliconn.DeleteInstance(instances[0].path)
+ else:
+ print >> sys.stderr, "Identity does not exist: %s" %parameters[0]
+
else:
# unknown command
print "Unknown command", command
diff --git a/src/account/LMI_IdentityProvider.c b/src/account/LMI_IdentityProvider.c
index 0e7a3b6..32bb0ee 100644
--- a/src/account/LMI_IdentityProvider.c
+++ b/src/account/LMI_IdentityProvider.c
@@ -136,7 +136,74 @@ static CMPIStatus LMI_IdentityDeleteInstance(
const CMPIResult* cr,
const CMPIObjectPath* cop)
{
- CMReturn(CMPI_RC_ERR_NOT_SUPPORTED);
+ LMI_Identity identity;
+ const char* instance_id = NULL;
+ id_t id;
+ char errmsg[256];
+ struct lu_context *luc = NULL;
+ struct lu_error *error = NULL;
+ struct lu_ent *lue = NULL;
+
+ LMI_Identity_InitFromObjectPath(&identity, _cb, cop);
+ lue = lu_ent_new();
+ instance_id = identity.InstanceID.chars;
+ id = atol(rindex(instance_id, ':') + 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 (strstr(instance_id, ":GID:"))
+ { /* It's a group */
+ if (!lu_group_lookup_id(luc, id, lue, &error))
+ { /* User with that ID is not present */
+ snprintf(errmsg, 256, "Non existing group id: %d\n", id);
+ lu_ent_free(lue);
+ lu_end(luc);
+ CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg);
+ }
+ else
+ {
+ if (!lu_group_delete(luc, lue, &error))
+ { /* user delete error */
+ snprintf(errmsg, 256,
+ "Group with id %d could not be deleted: %s\n", id,
+ lu_strerror(error));
+ lu_ent_free(lue);
+ lu_end(luc);
+ CMReturnWithChars(_cb, CMPI_RC_ERR_FAILED, errmsg);
+ }
+ }
+ }
+ else
+ { /* It's an user */
+ if (!lu_user_lookup_id(luc, id, lue, &error))
+ { /* User with that ID is not present */
+ snprintf(errmsg, 256, "Non existing user id: %d\n", id);
+ lu_ent_free(lue);
+ lu_end(luc);
+ CMReturnWithChars(_cb, CMPI_RC_ERR_NOT_FOUND, errmsg);
+ }
+ else
+ {
+ if (!lu_user_delete(luc, lue, &error))
+ { /* user delete error */
+ snprintf(errmsg, 256,
+ "User with id %d could not be deleted: %s\n", id,
+ 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_IdentityExecQuery(