This is an optimization from patch 0062 (rescinded) which I think is
worth keeping. There is no ticket for this.
From dd4f5f4849d99cabcc65f9d5bd53e9c8e1ce74df Mon Sep 17 00:00:00 2001
From: Nathaniel McCallum <[email protected]>
Date: Fri, 19 Sep 2014 12:17:32 -0400
Subject: [PATCH] Use stack allocation when writing values during otp auth

---
 daemons/ipa-slapi-plugins/libotp/libotp.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/daemons/ipa-slapi-plugins/libotp/libotp.c b/daemons/ipa-slapi-plugins/libotp/libotp.c
index 41f9e7b4809fbca82452d260b9aa7d1d3059fd2e..870e2415ff625bbe967a7f9aebbf9ec28d43a26c 100644
--- a/daemons/ipa-slapi-plugins/libotp/libotp.c
+++ b/daemons/ipa-slapi-plugins/libotp/libotp.c
@@ -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,
-                      int value)
+                      long long val)
 {
-    Slapi_Value *svals[] = { NULL, NULL };
     Slapi_PBlock *pb = NULL;
-    Slapi_Mods *mods = NULL;
     bool success = false;
+    char value[32];
     int ret;
 
-    /* Create the value. */
-    svals[0] = slapi_value_new();
-    if (slapi_value_set_int(svals[0], value) != 0) {
-        slapi_value_free(&svals[0]);
-        return false;
-    }
+    LDAPMod *mods[] = {
+        &(LDAPMod) {
+            LDAP_MOD_REPLACE, (char *) attr,
+            .mod_values = (char *[]) { value, NULL }
+        },
+        NULL
+    };
 
-    /* Create the mods. */
-    mods = slapi_mods_new();
-    slapi_mods_add_mod_values(mods, LDAP_MOD_REPLACE, attr, svals);
+    snprintf(value, sizeof(value), "%lld", val);
 
-    /* Perform the modification. */
     pb = slapi_pblock_new();
     slapi_modify_internal_set_pb(pb, slapi_sdn_get_dn(token->sdn),
-                                 slapi_mods_get_ldapmods_byref(mods),
-                                 NULL, NULL, token->plugin_id, 0);
+                                 mods, NULL, NULL, token->plugin_id, 0);
     if (slapi_modify_internal_pb(pb) != 0)
         goto error;
     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:
     slapi_pblock_destroy(pb);
-    slapi_mods_free(&mods);
     return success;
-
 }
 
 /**
-- 
2.1.0

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to