Blame SOURCES/omshell-hmac-sha512-support.patch

a65bc7
diff --git a/omapip/connection.c b/omapip/connection.c
a65bc7
index 014ff21..6800514 100644
a65bc7
--- a/omapip/connection.c
a65bc7
+++ b/omapip/connection.c
a65bc7
@@ -44,6 +44,9 @@ extern omapi_array_t *trace_listeners;
a65bc7
 #endif
a65bc7
 static isc_result_t omapi_connection_connect_internal (omapi_object_t *);
a65bc7
 
a65bc7
+static isc_result_t ctring_from_attribute(omapi_object_t *obj, char *attr_name,
a65bc7
+                                          char **cstr);
a65bc7
+
a65bc7
 OMAPI_OBJECT_ALLOC (omapi_connection,
a65bc7
 		    omapi_connection_object_t, omapi_type_connection)
a65bc7
 
a65bc7
@@ -763,64 +766,41 @@ isc_result_t omapi_connection_reaper (omapi_object_t *h)
a65bc7
 }
a65bc7
 
a65bc7
 static isc_result_t make_dst_key (dst_key_t **dst_key, omapi_object_t *a) {
a65bc7
-	omapi_value_t *name      = (omapi_value_t *)0;
a65bc7
-	omapi_value_t *algorithm = (omapi_value_t *)0;
a65bc7
-	omapi_value_t *key       = (omapi_value_t *)0;
a65bc7
-	char *name_str = NULL;
a65bc7
+	omapi_value_t *key = 0;
a65bc7
+	char *name_str = 0;
a65bc7
+	char *algorithm_str = 0;
a65bc7
 	isc_result_t status = ISC_R_SUCCESS;
a65bc7
 
a65bc7
-	if (status == ISC_R_SUCCESS)
a65bc7
-		status = omapi_get_value_str
a65bc7
-			(a, (omapi_object_t *)0, "name", &name);
a65bc7
-
a65bc7
-	if (status == ISC_R_SUCCESS)
a65bc7
-		status = omapi_get_value_str
a65bc7
-			(a, (omapi_object_t *)0, "algorithm", &algorithm);
a65bc7
-
a65bc7
-	if (status == ISC_R_SUCCESS)
a65bc7
-		status = omapi_get_value_str
a65bc7
-			(a, (omapi_object_t *)0, "key", &key);
a65bc7
-
a65bc7
+	/* Get the key name as a C string. */
a65bc7
+	status = ctring_from_attribute(a, "name", &name_str);
a65bc7
 	if (status == ISC_R_SUCCESS) {
a65bc7
-		if ((algorithm->value->type != omapi_datatype_data &&
a65bc7
-		     algorithm->value->type != omapi_datatype_string) ||
a65bc7
-		    strncasecmp((char *)algorithm->value->u.buffer.value,
a65bc7
-				NS_TSIG_ALG_HMAC_MD5 ".",
a65bc7
-				algorithm->value->u.buffer.len) != 0) {
a65bc7
-			status = DHCP_R_INVALIDARG;
a65bc7
+		/* Get the algorithm name as a C string. */
a65bc7
+		status = ctring_from_attribute(a, "algorithm", &algorithm_str);
a65bc7
+		if (status == ISC_R_SUCCESS) {
a65bc7
+			/* Get the key secret value */
a65bc7
+			status = omapi_get_value_str(a, 0, "key", &key);
a65bc7
+			if (status == ISC_R_SUCCESS) {
a65bc7
+				/* Now let's try and create the key */
a65bc7
+				status = isclib_make_dst_key(
a65bc7
+						name_str,
a65bc7
+						algorithm_str,
a65bc7
+						key->value->u.buffer.value,
a65bc7
+						key->value->u.buffer.len,
a65bc7
+						dst_key);
a65bc7
+
a65bc7
+				if (*dst_key == NULL) {
a65bc7
+					status = ISC_R_NOMEMORY;
a65bc7
+				}
a65bc7
+			}
a65bc7
 		}
a65bc7
 	}
a65bc7
 
a65bc7
-	if (status == ISC_R_SUCCESS) {
a65bc7
-		name_str = dmalloc (name -> value -> u.buffer.len + 1, MDL);
a65bc7
-		if (!name_str)
a65bc7
-			status = ISC_R_NOMEMORY;
a65bc7
-	}
a65bc7
-
a65bc7
-	if (status == ISC_R_SUCCESS) {
a65bc7
-		memcpy (name_str,
a65bc7
-			name -> value -> u.buffer.value,
a65bc7
-			name -> value -> u.buffer.len);
a65bc7
-		name_str [name -> value -> u.buffer.len] = 0;
a65bc7
-
a65bc7
-		status = isclib_make_dst_key(name_str,
a65bc7
-					     DHCP_HMAC_MD5_NAME,
a65bc7
-					     key->value->u.buffer.value,
a65bc7
-					     key->value->u.buffer.len,
a65bc7
-					     dst_key);
a65bc7
-
a65bc7
-		if (*dst_key == NULL)
a65bc7
-			status = ISC_R_NOMEMORY;
a65bc7
-	}
a65bc7
-
a65bc7
 	if (name_str)
a65bc7
 		dfree (name_str, MDL);
a65bc7
+	if (algorithm_str)
a65bc7
+		dfree (algorithm_str, MDL);
a65bc7
 	if (key)
a65bc7
 		omapi_value_dereference (&key, MDL);
a65bc7
-	if (algorithm)
a65bc7
-		omapi_value_dereference (&algorithm, MDL);
a65bc7
-	if (name)
a65bc7
-		omapi_value_dereference (&name, MDL);
a65bc7
 
a65bc7
 	return status;
a65bc7
 }
a65bc7
@@ -1103,3 +1083,50 @@ isc_result_t omapi_connection_stuff_values (omapi_object_t *c,
a65bc7
 								m -> inner);
a65bc7
 	return ISC_R_SUCCESS;
a65bc7
 }
a65bc7
+
a65bc7
+/* @brief Fetches the value of an attribute in an object as an allocated
a65bc7
+ * C string
a65bc7
+ *
a65bc7
+ * @param obj ompapi object containing the desire attribute
a65bc7
+ * @param attr_name  name of the desired attribute
a65bc7
+ * @param[out] cstr pointer in which to place the allocated C string's address
a65bc7
+ *
a65bc7
+ * Caller is responsible for freeing (via dfree) the allocated string.
a65bc7
+ *
a65bc7
+ * @return ISC_R_SUCCESS if successful, otherwise indicates the type of failure
a65bc7
+*/
a65bc7
+static isc_result_t ctring_from_attribute(omapi_object_t *obj, char *attr_name,
a65bc7
+                                          char **cstr) {
a65bc7
+	isc_result_t status = ISC_R_SUCCESS;
a65bc7
+	omapi_value_t *attr = 0;
a65bc7
+
a65bc7
+	/* Find the attribute in the object. */
a65bc7
+	status = omapi_get_value_str(obj, (omapi_object_t *)0, attr_name,
a65bc7
+                                 &attr);
a65bc7
+	if (status != ISC_R_SUCCESS) {
a65bc7
+		return (status);
a65bc7
+	}
a65bc7
+
a65bc7
+	/* Got it, let's make sure it's either data or string type. */
a65bc7
+	if (attr->value->type != omapi_datatype_data &&
a65bc7
+            attr->value->type != omapi_datatype_string) {
a65bc7
+		return (DHCP_R_INVALIDARG);
a65bc7
+        }
a65bc7
+
a65bc7
+	/* Make a C string from the attribute value. */
a65bc7
+	*cstr = dmalloc (attr->value->u.buffer.len + 1, MDL);
a65bc7
+	if (!(*cstr)) {
a65bc7
+		status = ISC_R_NOMEMORY;
a65bc7
+        } else {
a65bc7
+	        memcpy (*cstr, attr->value->u.buffer.value,
a65bc7
+		            attr->value->u.buffer.len);
a65bc7
+	        (*cstr)[attr->value->u.buffer.len] = 0;
a65bc7
+	}
a65bc7
+
a65bc7
+	/* Get rid of the attribute reference */
a65bc7
+	if (attr) {
a65bc7
+		omapi_value_dereference (&attr, MDL);
a65bc7
+	}
a65bc7
+
a65bc7
+	return (status);
a65bc7
+}