[PATCH 2/2] add special machine-id parse function



The original used uuid_parse() but that function did not
work properly since the format of the machine-id is
not compatable with a real uuid.  This patch adds a new
machine_id_parse() routine to correctly convert the
character string of hex digits to a 16 byte binary string.
Signed-off-by: Gene Czarcinski <gene czarc net>
---
 src/dhcp-manager/nm-dhcp-client.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/dhcp-manager/nm-dhcp-client.c b/src/dhcp-manager/nm-dhcp-client.c
index 2cdd304..a74f2ad 100644
--- a/src/dhcp-manager/nm-dhcp-client.c
+++ b/src/dhcp-manager/nm-dhcp-client.c
@@ -20,6 +20,7 @@
 #include <config.h>
 #include <glib.h>
 #include <string.h>
+#include <ctype.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <errno.h>
@@ -323,6 +324,32 @@ nm_dhcp_client_start_ip4 (NMDHCPClient *self,
 	return priv->pid ? TRUE : FALSE;
 }
 
+/* uuid_parse does not work for machine-id, so we use our own converter */
+static int
+machine_id_parse (const char *in, uuid_t uu)
+{
+	const char *cp;
+	int i;
+	unsigned char buf[3];
+
+	if (strlen(in) != 32)
+		return -1;
+	for (i = 0, cp = in; i < 32; i++, cp++)
+	{
+		if (!isxdigit(*cp))
+			return -1;
+	}
+	buf[2] = 0;
+	cp = in;
+	for (i = 0; i < 16; i++)
+	{
+		buf[0] = *cp++;
+		buf[1] = *cp++;
+		uu[i] = strtoul (buf, NULL, 16);
+	}
+	return 0;
+}
+
 static GByteArray *
 generate_duid_from_machine_id (void)
 {
@@ -348,7 +375,8 @@ generate_duid_from_machine_id (void)
 	}
 
 	contents = g_strstrip (contents);
-	ret = uuid_parse (contents, uuid);
+	nm_log_dbg (LOGD_DHCP6, "/etc/machine-id len= %d, value= '%s'", strlen(contents), contents);
+	ret = machine_id_parse (contents, uuid);
 	g_free (contents);
 
 	if (ret != 0) {
-- 
1.8.1.2



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]