summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoman Rakus <rrakus@redhat.com>2013-06-12 15:48:43 +0200
committerRoman Rakus <rrakus@redhat.com>2013-06-12 15:51:11 +0200
commit7057f8c9ed6f51044a853710defde4ef14f2a340 (patch)
treed712bc7682fcf677c6d473047caf7fd78dd7f8b7
parentec58653e83ba32cba3a3f51d9fcedca4873c7ab7 (diff)
downloadopenlmi-providers-7057f8c9ed6f51044a853710defde4ef14f2a340.tar.gz
openlmi-providers-7057f8c9ed6f51044a853710defde4ef14f2a340.tar.xz
openlmi-providers-7057f8c9ed6f51044a853710defde4ef14f2a340.zip
Account: Use asprintf instead of snprintf
Signed-off-by: Roman Rakus <rrakus@redhat.com>
-rw-r--r--src/account/LMI_AccountManagementServiceProvider.c22
-rw-r--r--src/account/LMI_AccountProvider.c5
-rw-r--r--src/account/LMI_AssignedAccountIdentityProvider.c6
-rw-r--r--src/account/LMI_AssignedGroupIdentityProvider.c6
-rw-r--r--src/account/LMI_GroupProvider.c5
-rw-r--r--src/account/LMI_IdentityProvider.c8
-rw-r--r--src/account/LMI_MemberOfGroupProvider.c5
-rw-r--r--src/account/LMI_ServiceAffectsIdentityProvider.c10
8 files changed, 30 insertions, 37 deletions
diff --git a/src/account/LMI_AccountManagementServiceProvider.c b/src/account/LMI_AccountManagementServiceProvider.c
index f4a925e..22c3663 100644
--- a/src/account/LMI_AccountManagementServiceProvider.c
+++ b/src/account/LMI_AccountManagementServiceProvider.c
@@ -228,7 +228,7 @@ KUint32 LMI_AccountManagementService_CreateGroup(
KRefA* Identities,
CMPIStatus* status)
{
- char errmsg[256], instanceid[256];
+ char *errmsg = NULL, *instanceid = NULL;
struct lu_context *luc = NULL;
struct lu_error *error = NULL;
struct lu_ent *lue = NULL;
@@ -243,8 +243,9 @@ KUint32 LMI_AccountManagementService_CreateGroup(
KSetStatus(status, OK);
KUint32_Set(&result, 0);
#define FAIL(MSG, ERROR, STATUS, RETVAL)\
- snprintf(errmsg, 256, (MSG), (ERROR));\
+ asprintf(&errmsg, (MSG), (ERROR));\
KSetStatus2(cb, status, STATUS, errmsg);\
+ free(errmsg);\
KUint32_Set(&result, (RETVAL));\
if (!(Name->exists && !Name->null) || !(System->exists && !System->null))
@@ -305,9 +306,9 @@ KUint32 LMI_AccountManagementService_CreateGroup(
/* 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));
+ asprintf(&instanceid, ORGID":GID:%ld", aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&Identityref, instanceid);
+ free(instanceid);
IdentityOP = LMI_IdentityRef_ToObjectPath(&Identityref, NULL);
KRefA_Set(Identities, 0, IdentityOP);
@@ -340,11 +341,12 @@ KUint32 LMI_AccountManagementService_CreateAccount(
{
/* TODO - Use embedded instance? */
- char errmsg[256];
+ char *errmsg = NULL;
#define FAIL(MSG, ERROR, STATUS, RETVAL)\
- snprintf(errmsg, 256, (MSG), (ERROR));\
+ asprintf(&errmsg, (MSG), (ERROR));\
KSetStatus2(cb, status, STATUS, errmsg);\
+ free(errmsg);\
KUint32_Set(&result, (RETVAL));\
KUint32 result = KUINT32_INIT;
@@ -533,27 +535,27 @@ KUint32 LMI_AccountManagementService_CreateAccount(
* it means reference to Identity of Account and Group
*/
KRefA_Init(Identities, cb, 2);
- instanceid = malloc(256 * sizeof(char));
/* Identity of Account */
LMI_IdentityRef_Init(&Identityref, cb, nameSpace);
- snprintf(instanceid, 255, ORGID":UID:%ld",
+ asprintf(&instanceid, ORGID":UID:%ld",
aux_lu_get_long(lue, LU_UIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&Identityref, instanceid);
+ free(instanceid);
IdentityOP = LMI_IdentityRef_ToObjectPath(&Identityref, &st);
KRefA_Set(Identities, 0, IdentityOP);
/* Identity of Group */
- snprintf(instanceid, 255, ORGID":GID:%ld",
+ asprintf(&instanceid, ORGID":GID:%ld",
aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&Identityref, instanceid);
+ free(instanceid);
IdentityOP = LMI_IdentityRef_ToObjectPath(&Identityref, &st);
KRefA_Set(Identities, 1, IdentityOP);
clean:
#undef FAIL
free(group_name);
- free(instanceid);
if (lue) lu_ent_free(lue);
if (lue_group) lu_ent_free(lue_group);
if (luc) lu_end(luc);
diff --git a/src/account/LMI_AccountProvider.c b/src/account/LMI_AccountProvider.c
index ef7cbf7..a34593e 100644
--- a/src/account/LMI_AccountProvider.c
+++ b/src/account/LMI_AccountProvider.c
@@ -93,7 +93,6 @@ static CMPIStatus LMI_AccountEnumInstances(
exit(1);
}
- uid = malloc(256 * sizeof(char));
accounts = lu_users_enumerate_full(luc, "*", &error);
for (i = 0; (accounts != NULL) && (i < accounts->len); i++)
{
@@ -109,8 +108,9 @@ static CMPIStatus LMI_AccountEnumInstances(
LMI_Account_Set_OrganizationName(&la, 0, ""); /* XXX */
/* Need to convert long int UID to the string */
- snprintf(uid, 255, "%ld", aux_lu_get_long(lue, LU_UIDNUMBER));
+ asprintf(&uid, "%ld", aux_lu_get_long(lue, LU_UIDNUMBER));
LMI_Account_Set_UserID(&la, uid);
+ free(uid);
LMI_Account_Init_Host(&la, 1);
LMI_Account_Set_Host(&la, 0, hostname);
@@ -184,7 +184,6 @@ static CMPIStatus LMI_AccountEnumInstances(
KReturnInstance(cr, la);
lu_ent_free(lue);
} /* for */
- free(uid);
if (accounts)
{
diff --git a/src/account/LMI_AssignedAccountIdentityProvider.c b/src/account/LMI_AssignedAccountIdentityProvider.c
index 323a582..72f5d1e 100644
--- a/src/account/LMI_AssignedAccountIdentityProvider.c
+++ b/src/account/LMI_AssignedAccountIdentityProvider.c
@@ -81,16 +81,15 @@ static CMPIStatus LMI_AssignedAccountIdentityEnumInstances(
fprintf(stderr, "Error initializing: %s\n", lu_strerror(error));
exit(1);
}
- uid = malloc(256 * sizeof(char));
accounts = lu_users_enumerate_full(luc, "*", &error);
for (i = 0; (accounts != NULL) && (i < accounts->len); i++)
{
lue = g_ptr_array_index(accounts, i);
LMI_IdentityRef_Init(&liref, _cb, nameSpace);
- snprintf(uid, 255, ORGID":UID:%ld",
- aux_lu_get_long(lue, LU_UIDNUMBER));
+ asprintf(&uid, ORGID":UID:%ld", aux_lu_get_long(lue, LU_UIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&liref, uid);
+ free(uid);
LMI_AccountRef_Init(&laref, _cb, nameSpace);
LMI_AccountRef_Set_Name(&laref, aux_lu_get_str(lue, LU_USERNAME));
@@ -105,7 +104,6 @@ static CMPIStatus LMI_AssignedAccountIdentityEnumInstances(
KReturnInstance(cr, laai);
lu_ent_free(lue);
} /* for */
- free(uid);
if (accounts)
{
diff --git a/src/account/LMI_AssignedGroupIdentityProvider.c b/src/account/LMI_AssignedGroupIdentityProvider.c
index a9037f1..c474bf9 100644
--- a/src/account/LMI_AssignedGroupIdentityProvider.c
+++ b/src/account/LMI_AssignedGroupIdentityProvider.c
@@ -80,7 +80,6 @@ static CMPIStatus LMI_AssignedGroupIdentityEnumInstances(
fprintf(stderr, "Error initializing: %s\n", lu_strerror(error));
exit(1);
}
- gid = malloc(256 * sizeof(char));
groups = lu_groups_enumerate_full(luc, "*", &error);
for (i = 0; (groups != NULL) && (i < groups->len); i++)
{
@@ -91,9 +90,9 @@ static CMPIStatus LMI_AssignedGroupIdentityEnumInstances(
LMI_GroupRef_Set_Name(&lgref, aux_lu_get_str(lue, LU_GROUPNAME));
LMI_IdentityRef_Init(&liref, _cb, nameSpace);
- snprintf(gid, 255, ORGID":GID:%ld",
- aux_lu_get_long(lue, LU_GIDNUMBER));
+ asprintf(&gid, ORGID":GID:%ld", aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&liref, gid);
+ free(gid);
LMI_AssignedGroupIdentity_Init(&lagi, _cb, nameSpace);
LMI_AssignedGroupIdentity_Set_IdentityInfo(&lagi, &liref);
@@ -102,7 +101,6 @@ static CMPIStatus LMI_AssignedGroupIdentityEnumInstances(
KReturnInstance(cr, lagi);
lu_ent_free(lue);
} /* for */
- free(gid);
CMReturn(CMPI_RC_OK);
}
diff --git a/src/account/LMI_GroupProvider.c b/src/account/LMI_GroupProvider.c
index c9d8ebb..5356eac 100644
--- a/src/account/LMI_GroupProvider.c
+++ b/src/account/LMI_GroupProvider.c
@@ -75,7 +75,6 @@ static CMPIStatus LMI_GroupEnumInstances(
exit(1);
}
- instanceid = malloc(256 * sizeof(char));
groups = lu_groups_enumerate_full(luc, "*", &error);
for (i = 0; (groups != NULL) && (i < groups->len); i++)
{
@@ -86,13 +85,13 @@ static CMPIStatus LMI_GroupEnumInstances(
LMI_Group_Set_Name(&lg, aux_lu_get_str(lue, LU_GROUPNAME));
LMI_Group_Set_ElementName(&lg, aux_lu_get_str(lue, LU_GROUPNAME));
LMI_Group_Set_CommonName(&lg, aux_lu_get_str(lue, LU_GROUPNAME));
- snprintf(instanceid, 255, ORGID":GID:%ld",
+ asprintf(&instanceid, ORGID":GID:%ld",
aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_Group_Set_InstanceID(&lg, instanceid);
+ free(instanceid);
KReturnInstance(cr, lg);
lu_ent_free(lue);
} /* for */
- free(instanceid);
if (groups)
{
diff --git a/src/account/LMI_IdentityProvider.c b/src/account/LMI_IdentityProvider.c
index b359a69..81cd68e 100644
--- a/src/account/LMI_IdentityProvider.c
+++ b/src/account/LMI_IdentityProvider.c
@@ -75,7 +75,6 @@ static CMPIStatus LMI_IdentityEnumInstances(
exit(1);
}
- instanceid = malloc(256 * sizeof(char));
/* USERS */
accounts = lu_users_enumerate_full(luc, "*", &error);
@@ -85,9 +84,10 @@ static CMPIStatus LMI_IdentityEnumInstances(
LMI_Identity_Init(&li, _cb, nameSpace);
/* Need to convert long int UID to the string */
- snprintf(instanceid, 255, ORGID":UID:%ld",
+ asprintf(&instanceid, ORGID":UID:%ld",
aux_lu_get_long(lue, LU_UIDNUMBER));
LMI_Identity_Set_InstanceID(&li, instanceid);
+ free(instanceid);
LMI_Identity_Set_ElementName(&li, aux_lu_get_str(lue, LU_GECOS));
KReturnInstance(cr, li);
}
@@ -100,15 +100,15 @@ static CMPIStatus LMI_IdentityEnumInstances(
LMI_Identity_Init(&li, _cb, nameSpace);
/* Need to convert long int UID to the string */
- snprintf(instanceid, 255, ORGID":GID:%ld",
+ asprintf(&instanceid, ORGID":GID:%ld",
aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_Identity_Set_InstanceID(&li, instanceid);
+ free(instanceid);
LMI_Identity_Set_ElementName(&li, aux_lu_get_str(lue, LU_GROUPNAME));
KReturnInstance(cr, li);
lu_ent_free(lue);
}
- free(instanceid);
if (accounts)
{
g_ptr_array_free(accounts, TRUE);
diff --git a/src/account/LMI_MemberOfGroupProvider.c b/src/account/LMI_MemberOfGroupProvider.c
index 06f835c..beb5edd 100644
--- a/src/account/LMI_MemberOfGroupProvider.c
+++ b/src/account/LMI_MemberOfGroupProvider.c
@@ -83,7 +83,6 @@ static CMPIStatus LMI_MemberOfGroupEnumInstances(
fprintf(stderr, "Error initializing: %s\n", lu_strerror(error));
exit(1);
}
- uid = malloc(256 * sizeof(char));
/* Go through each group */
groups = lu_groups_enumerate_full(luc, "*", &error);
for (i = 0; (groups != NULL) && (i < groups->len); i++)
@@ -102,10 +101,11 @@ static CMPIStatus LMI_MemberOfGroupEnumInstances(
lu_user_lookup_name(luc,
g_value_get_string(g_value_array_get_nth(accounts, j)),
luea, &error);
- snprintf(uid, 255, ORGID":UID:%ld",
+ asprintf(&uid, ORGID":UID:%ld",
aux_lu_get_long(luea, LU_UIDNUMBER));
LMI_IdentityRef_Init(&liref, _cb, nameSpace);
LMI_IdentityRef_Set_InstanceID(&liref, uid);
+ free(uid);
LMI_MemberOfGroup_Init(&lmog, _cb, nameSpace);
LMI_MemberOfGroup_Set_Collection(&lmog, &lgref);
@@ -122,7 +122,6 @@ static CMPIStatus LMI_MemberOfGroupEnumInstances(
lu_ent_free(lueg);
} /* for groups */
- free(uid);
if (groups)
{
diff --git a/src/account/LMI_ServiceAffectsIdentityProvider.c b/src/account/LMI_ServiceAffectsIdentityProvider.c
index 64e218b..6155010 100644
--- a/src/account/LMI_ServiceAffectsIdentityProvider.c
+++ b/src/account/LMI_ServiceAffectsIdentityProvider.c
@@ -90,7 +90,6 @@ static CMPIStatus LMI_ServiceAffectsIdentityEnumInstances(
exit(1);
}
- id = malloc(256 * sizeof(char));
/* Go through every accounts first */
accounts = lu_users_enumerate_full(luc, "*", &error);
@@ -99,9 +98,9 @@ static CMPIStatus LMI_ServiceAffectsIdentityEnumInstances(
lue = g_ptr_array_index(accounts, i);
LMI_IdentityRef_Init(&liref, _cb, nameSpace);
- snprintf(id, 255, ORGID":UID:%ld",
- aux_lu_get_long(lue, LU_UIDNUMBER));
+ asprintf(&id, ORGID":UID:%ld", aux_lu_get_long(lue, LU_UIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&liref, id);
+ free(id);
LMI_ServiceAffectsIdentity_Init(&lsai, _cb, nameSpace);
LMI_ServiceAffectsIdentity_Set_AffectedElement(&lsai, &liref);
@@ -126,9 +125,9 @@ static CMPIStatus LMI_ServiceAffectsIdentityEnumInstances(
lue = g_ptr_array_index(accounts, i);
LMI_IdentityRef_Init(&liref, _cb, nameSpace);
- snprintf(id, 255, ORGID":GID:%ld",
- aux_lu_get_long(lue, LU_GIDNUMBER));
+ asprintf(&id, ORGID":GID:%ld", aux_lu_get_long(lue, LU_GIDNUMBER));
LMI_IdentityRef_Set_InstanceID(&liref, id);
+ free(id);
LMI_ServiceAffectsIdentity_Init(&lsai, _cb, nameSpace);
LMI_ServiceAffectsIdentity_Set_AffectedElement(&lsai, &liref);
@@ -147,7 +146,6 @@ static CMPIStatus LMI_ServiceAffectsIdentityEnumInstances(
g_ptr_array_free(accounts, TRUE);
}
- free(id);
lu_end(luc);
CMReturn(CMPI_RC_OK);