summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2013-09-04 15:25:02 +0200
committerRoman Rakus <rrakus@redhat.com>2013-09-04 16:45:15 +0200
commit23c7f0b6a4dbd86b6e80ba095110742ef79e7a28 (patch)
treef70e4ca7d22ab0f564f87913476267d382fe9c71 /src
parent66fee3cfd9736b860872f0e6a757f11404015193 (diff)
downloadopenlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.tar.gz
openlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.tar.xz
openlmi-providers-23c7f0b6a4dbd86b6e80ba095110742ef79e7a28.zip
Account: Fix memory corruption
There was false assumption that lu_end doesn't free error messages. The code is restructured to copy error message to temporary string holder, which is freed after and error message is correctly returned, all in one place. Signed-off-by: Roman Rakus <rrakus@redhat.com>
Diffstat (limited to 'src')
-rw-r--r--src/account/LMI_AccountProvider.c45
-rw-r--r--src/account/LMI_GroupProvider.c25
-rw-r--r--src/account/LMI_IdentityProvider.c41
-rw-r--r--src/account/LMI_MemberOfGroupProvider.c73
4 files changed, 117 insertions, 67 deletions
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c
index c58b001..c7c16bb 100644
--- a/src/account/LMI_AccountProvider.c
+++ b/src/account/LMI_AccountProvider.c
@@ -263,6 +263,9 @@ static CMPIStatus LMI_AccountModifyInstance(
date_time_prop expiration, warning, inactive_password, inactive_account;
date_time_prop possible_change;
+ CMPIrc rc = CMPI_RC_OK;
+ char *errmsg = NULL;
+
LMI_Account la;
LMI_Account_InitFromObjectPath(&la, _cb, cop);
@@ -277,10 +280,10 @@ static CMPIStatus LMI_AccountModifyInstance(
lue = lu_ent_new();
if (!lu_user_lookup_name(luc, la.Name.chars, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_NOT_FOUND, "User %s not found: %s",
- la.Name.chars, lu_strerror(error));
+ rc = CMPI_RC_ERR_NOT_FOUND;
+ asprintf(&errmsg, "User %s not found: %s",
+ la.Name.chars, lu_strerror(error));
+ goto fail;
}
data = ci->ft->getProperty(ci, "UserPassword", NULL);
@@ -294,10 +297,10 @@ static CMPIStatus LMI_AccountModifyInstance(
{
if (!lu_user_setpass(luc, lue, value, TRUE, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "Error setting password: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Error setting password: %s",
+ lu_strerror(error));
+ goto fail;
}
}
}
@@ -305,10 +308,10 @@ static CMPIStatus LMI_AccountModifyInstance(
{
if (!lu_user_removepass(luc, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "Error removing password: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Error removing password: %s",
+ lu_strerror(error));
+ goto fail;
}
}
@@ -442,15 +445,23 @@ static CMPIStatus LMI_AccountModifyInstance(
if (!lu_user_modify(luc, lue, &error))
{
- lu_end(luc);
- lu_ent_free(lue);
- KReturn2(_cb, ERR_FAILED, "User modification failed: %s",
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "User modification failed: %s",
+ lu_strerror(error));
+ goto fail;
}
+fail:
lu_ent_free(lue);
lu_end(luc);
- CMReturn(CMPI_RC_OK);
+
+ if (errmsg) {
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
+ } else {
+ CMReturn(rc);
+ }
}
/*
diff --git a/src/account/LMI_GroupProvider.c b/src/account/LMI_GroupProvider.c
index d3263f4..0dd548d 100644
--- a/src/account/LMI_GroupProvider.c
+++ b/src/account/LMI_GroupProvider.c
@@ -146,6 +146,8 @@ static CMPIStatus LMI_GroupDeleteInstance(
struct lu_context *luc = NULL;
struct lu_error *error = NULL;
struct lu_ent *lue = NULL;
+ CMPIrc rc = CMPI_RC_OK;
+ char *errmsg = NULL;
LMI_Group_InitFromObjectPath(&lg, _cb, cop);
name = lg.Name.chars;
@@ -160,23 +162,30 @@ static CMPIStatus LMI_GroupDeleteInstance(
lue = lu_ent_new();
if (!lu_group_lookup_name(luc, name, lue, &error))
{ /* Group not found */
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_NOT_FOUND, "Non existing group: %s\n", name);
+ asprintf(&errmsg, "Non existing group: %s\n", name);
+ rc = CMPI_RC_ERR_NOT_FOUND;
+ goto fail;
}
if (!lu_group_delete(luc, lue, &error))
{
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED, "Group %s could not be deleted: %s\n", name,
- lu_strerror(error));
+ asprintf(&errmsg, "Group %s could not be deleted: %s\n", name,
+ lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ goto fail;
}
+fail:
lu_ent_free(lue);
lu_end(luc);
- CMReturn(CMPI_RC_OK);
+ if (errmsg) {
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
+ } else {
+ CMReturn(rc);
+ }
}
static CMPIStatus LMI_GroupExecQuery(
diff --git a/src/account/LMI_IdentityProvider.c b/src/account/LMI_IdentityProvider.c
index e008746..11e3de5 100644
--- a/src/account/LMI_IdentityProvider.c
+++ b/src/account/LMI_IdentityProvider.c
@@ -162,6 +162,8 @@ static CMPIStatus LMI_IdentityDeleteInstance(
struct lu_context *luc = NULL;
struct lu_error *error = NULL;
struct lu_ent *lue = NULL;
+ char *errmsg = NULL;
+ CMPIrc rc = CMPI_RC_OK;
LMI_Identity_InitFromObjectPath(&identity, _cb, cop);
instance_id = identity.InstanceID.chars;
@@ -179,46 +181,51 @@ static CMPIStatus LMI_IdentityDeleteInstance(
{ /* It's a group */
if (!lu_group_lookup_id(luc, id, lue, &error))
{ /* User with that ID is not present */
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_NOT_FOUND, "Non existing group id: %d\n", id);
+ asprintf(&errmsg, "Non existing group id: %d\n", id);
+ rc = CMPI_RC_ERR_NOT_FOUND;
+ goto fail;
}
else
{
if (!lu_group_delete(luc, lue, &error))
{ /* user delete error */
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED,
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg,
"Group with id %d could not be deleted: %s\n", id,
lu_strerror(error));
+ goto fail;
}
}
}
else
- { /* It's an user */
+ { /* It's a user */
if (!lu_user_lookup_id(luc, id, lue, &error))
{ /* User with that ID is not present */
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_NOT_FOUND, "Non existing user id: %d\n", id);
+ rc = CMPI_RC_ERR_NOT_FOUND;
+ asprintf(&errmsg, "Non existing user id: %d\n", id);
+ goto fail;
}
else
{
if (!lu_user_delete(luc, lue, &error))
{ /* user delete error */
- lu_ent_free(lue);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED,
- "User with id %d could not be deleted: %s\n", id,
- lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "User with id %d could not be deleted: %s\n",
+ id, lu_strerror(error));
+ goto fail;
}
}
}
+fail:
lu_ent_free(lue);
lu_end(luc);
-
- CMReturn(CMPI_RC_OK);
+ if (errmsg) {
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
+ } else {
+ CMReturn(rc);
+ }
}
static CMPIStatus LMI_IdentityExecQuery(
diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c
index b06cd43..0ea9160 100644
--- a/src/account/LMI_MemberOfGroupProvider.c
+++ b/src/account/LMI_MemberOfGroupProvider.c
@@ -166,6 +166,9 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance(
struct lu_context *luc = NULL;
struct lu_error *error = NULL;
+ CMPIrc rc = CMPI_RC_OK;
+ char *errmsg = NULL;
+
LMI_MemberOfGroup_InitFromObjectPath(&lmog, _cb, cop);
LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb,
CMGetProperty(ci, "Collection", NULL).value.ref);
@@ -192,8 +195,10 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance(
struct lu_ent *lue = lu_ent_new();
if (!lu_group_lookup_name(luc, group_name, lue, &error)) {
- KReturn2(_cb, ERR_FAILED, "Group with name %s not found: %s\n",
- group_name, lu_strerror(error));
+ asprintf(&errmsg, "Group with name %s not found: %s\n", group_name,
+ lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ goto fail;
}
memset(&val, 0, sizeof(val));
@@ -201,11 +206,10 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance(
g_value_set_string(&val, user_name);
lu_ent_add(lue, LU_MEMBERNAME, &val);
if(!lu_group_modify(luc, lue, &error)) {
- lu_ent_free(lue);
- lu_end(luc);
- g_value_unset(&val);
- KReturn2(_cb, ERR_FAILED, "Modification of group %s failed: %s\n",
- group_name, lu_strerror(error));
+ asprintf(&errmsg, "Modification of group %s failed: %s\n", group_name,
+ lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ goto fail;
}
g_value_unset(&val);
@@ -218,6 +222,15 @@ static CMPIStatus LMI_MemberOfGroupCreateInstance(
CMReturnObjectPath(cr, LMI_MemberOfGroup_ToObjectPath(&lmog, NULL));
CMReturn(CMPI_RC_OK);
+
+fail:
+ lu_ent_free(lue);
+ lu_end(luc);
+ g_value_unset(&val);
+
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
}
static CMPIStatus LMI_MemberOfGroupModifyInstance(
@@ -250,6 +263,9 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance(
unsigned int i = 0; /* iterator */
int found = 0; /* indicator */
+ CMPIrc rc = CMPI_RC_OK;
+ char *errmsg = NULL;
+
LMI_MemberOfGroup_InitFromObjectPath(&lmog, _cb, cop);
LMI_GroupRef_InitFromObjectPath(&lg_ref, _cb, lmog.Collection.value);
LMI_IdentityRef_InitFromObjectPath(&li_ref, _cb, lmog.Member.value);
@@ -267,15 +283,17 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance(
if (!lu_user_lookup_id(luc, user_id, lue_u, &error)) {
lu_end(luc);
- KReturn2(_cb, ERR_FAILED, "User with id %d not found: %s\n", user_id,
- lu_strerror(error));
+ asprintf(&errmsg, "User with id %d not found: %s\n", user_id,
+ lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ goto fail;
}
if (!lu_group_lookup_name(luc, group_name, lue_g, &error)) {
- lu_ent_free(lue_u);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED, "Group with name %s not found: %s\n",
- group_name, lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Group with name %s not found: %s\n",
+ group_name, lu_strerror(error));
+ goto fail;
}
groups = lu_ent_get(lue_g, LU_MEMBERNAME);
for (found = 0, i = 0; groups && i < groups->n_values; i++) {
@@ -286,29 +304,34 @@ static CMPIStatus LMI_MemberOfGroupDeleteInstance(
}
}
if (!found) {
- lu_ent_free(lue_u);
- lu_ent_free(lue_g);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED,
- "User with id %d is not in group %s or is users' primary group\n",
- user_id, group_name);
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg,
+ "User with id %d is not in group %s or is users' primary group\n",
+ user_id, group_name);
+ goto fail;
} else {
/* And now remove the user from the group */
g_value_array_remove(groups, i);
lu_ent_set(lue_g, LU_MEMBERNAME, groups);
if(!lu_group_modify(luc, lue_g, &error)) {
- lu_ent_free(lue_u);
- lu_ent_free(lue_g);
- lu_end(luc);
- KReturn2(_cb, ERR_FAILED, "Modification of group %s failed: %s\n",
- group_name, lu_strerror(error));
+ rc = CMPI_RC_ERR_FAILED;
+ asprintf(&errmsg, "Modification of group %s failed: %s\n",
+ group_name, lu_strerror(error));
+ goto fail;
}
}
+fail:
lu_ent_free(lue_u);
lu_ent_free(lue_g);
lu_end(luc);
- CMReturn(CMPI_RC_OK);
+ if (errmsg) {
+ CMPIString *errstr = CMNewString(_cb, errmsg, NULL);
+ free(errmsg);
+ CMReturnWithString(rc, errstr);
+ } else {
+ CMReturn(CMPI_RC_OK);
+ }
}
static CMPIStatus LMI_MemberOfGroupExecQuery(