Use stack allocation when writing values during otp auth

Reviewed-By: Thierry Bordaz <tbordaz@redhat.com>
This commit is contained in:
Nathaniel McCallum
2014-09-19 12:17:32 -04:00
committed by Martin Kosek
parent fcce15d0bd
commit 35ec0f7e3d

View File

@@ -125,30 +125,26 @@ static const struct berval *entry_attr_get_berval(const Slapi_Entry* e,
} }
static bool writeattr(const struct otptoken *token, const char *attr, static bool writeattr(const struct otptoken *token, const char *attr,
int value) long long val)
{ {
Slapi_Value *svals[] = { NULL, NULL };
Slapi_PBlock *pb = NULL; Slapi_PBlock *pb = NULL;
Slapi_Mods *mods = NULL;
bool success = false; bool success = false;
char value[32];
int ret; int ret;
/* Create the value. */ LDAPMod *mods[] = {
svals[0] = slapi_value_new(); &(LDAPMod) {
if (slapi_value_set_int(svals[0], value) != 0) { LDAP_MOD_REPLACE, (char *) attr,
slapi_value_free(&svals[0]); .mod_values = (char *[]) { value, NULL }
return false; },
} NULL
};
/* Create the mods. */ snprintf(value, sizeof(value), "%lld", val);
mods = slapi_mods_new();
slapi_mods_add_mod_values(mods, LDAP_MOD_REPLACE, attr, svals);
/* Perform the modification. */
pb = slapi_pblock_new(); pb = slapi_pblock_new();
slapi_modify_internal_set_pb(pb, slapi_sdn_get_dn(token->sdn), slapi_modify_internal_set_pb(pb, slapi_sdn_get_dn(token->sdn),
slapi_mods_get_ldapmods_byref(mods), mods, NULL, NULL, token->plugin_id, 0);
NULL, NULL, token->plugin_id, 0);
if (slapi_modify_internal_pb(pb) != 0) if (slapi_modify_internal_pb(pb) != 0)
goto error; goto error;
if (slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret) != 0) if (slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &ret) != 0)
@@ -160,9 +156,7 @@ static bool writeattr(const struct otptoken *token, const char *attr,
error: error:
slapi_pblock_destroy(pb); slapi_pblock_destroy(pb);
slapi_mods_free(&mods);
return success; return success;
} }
/** /**