Blame SOURCES/0003-dhclient-no-leading-zero-client-id-rh1556983.patch

7b922c
From bbee3b6833ab1792e75470db5f3b7022e9a965f5 Mon Sep 17 00:00:00 2001
7b922c
From: Beniamino Galvani <bgalvani@redhat.com>
7b922c
Date: Wed, 20 Jun 2018 11:49:22 +0200
7b922c
Subject: [PATCH 1/2] Revert "dhclient: write client-id with backslash and
7b922c
 quotes as hex"
7b922c
7b922c
This reverts commit 0e4b33ee7552b036332f1bdbfed78f8ee75f000e.
7b922c
---
7b922c
 src/dhcp/nm-dhcp-dhclient-utils.c   |  2 +-
7b922c
 src/dhcp/tests/test-dhcp-dhclient.c | 33 +----------------------------
7b922c
 2 files changed, 2 insertions(+), 33 deletions(-)
7b922c
7b922c
diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
index cbd706f..7324597 100644
7b922c
--- a/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
+++ b/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
@@ -124,7 +124,7 @@ add_ip4_config (GString *str, GBytes *client_id, const char *hostname, gboolean
7b922c
 		 * as long as all the characters are printable.
7b922c
 		 */
7b922c
 		for (i = 1; (p[0] == 0) && i < l; i++) {
7b922c
-			if (!g_ascii_isprint (p[i]) || p[i] == '\\' || p[i] == '"')
7b922c
+			if (!g_ascii_isprint (p[i]))
7b922c
 				break;
7b922c
 		}
7b922c
 
7b922c
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
index 55d712b..7df0720 100644
7b922c
--- a/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
+++ b/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
@@ -178,36 +178,6 @@ test_quote_client_id (void)
7b922c
 
7b922c
 /*****************************************************************************/
7b922c
 
7b922c
-static const char *quote_client_id_expected_2 = \
7b922c
-	"# Created by NetworkManager\n"
7b922c
-	"\n"
7b922c
-	"send dhcp-client-identifier 00:61:5c:62:63; # added by NetworkManager\n"
7b922c
-	"\n"
7b922c
-	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
-	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
-	"option wpad code 252 = string;\n"
7b922c
-	"\n"
7b922c
-	"also request rfc3442-classless-static-routes;\n"
7b922c
-	"also request ms-classless-static-routes;\n"
7b922c
-	"also request static-routes;\n"
7b922c
-	"also request wpad;\n"
7b922c
-	"also request ntp-servers;\n"
7b922c
-	"also request root-path;\n"
7b922c
-	"\n";
7b922c
-
7b922c
-static void
7b922c
-test_quote_client_id_2 (void)
7b922c
-{
7b922c
-	test_config (NULL, quote_client_id_expected_2,
7b922c
-	             AF_INET, NULL, 0, FALSE,
7b922c
-	             "a\\bc",
7b922c
-	             NULL,
7b922c
-	             "eth0",
7b922c
-	             NULL);
7b922c
-}
7b922c
-
7b922c
-/*****************************************************************************/
7b922c
-
7b922c
 static const char *hex_zero_client_id_expected = \
7b922c
 	"# Created by NetworkManager\n"
7b922c
 	"\n"
7b922c
@@ -1130,8 +1100,7 @@ main (int argc, char **argv)
7b922c
 
7b922c
 	g_test_add_func ("/dhcp/dhclient/orig_missing", test_orig_missing);
7b922c
 	g_test_add_func ("/dhcp/dhclient/override_client_id", test_override_client_id);
7b922c
-	g_test_add_func ("/dhcp/dhclient/quote_client_id/1", test_quote_client_id);
7b922c
-	g_test_add_func ("/dhcp/dhclient/quote_client_id/2", test_quote_client_id_2);
7b922c
+	g_test_add_func ("/dhcp/dhclient/quote_client_id", test_quote_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/hex_zero_client_id", test_hex_zero_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/ascii_client_id", test_ascii_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/hex_single_client_id", test_hex_single_client_id);
7b922c
-- 
7b922c
2.21.0
7b922c
7b922c
From 2049c9c861f262aa6c949f45cd401ec515c2f2d0 Mon Sep 17 00:00:00 2001
7b922c
From: Beniamino Galvani <bgalvani@redhat.com>
7b922c
Date: Wed, 20 Jun 2018 11:50:51 +0200
7b922c
Subject: [PATCH 2/2] Revert "dhcp: dhclient: set type 0 for printable client
7b922c
 IDs"
7b922c
7b922c
Keep the RHEL 7.5 behavior.
7b922c
7b922c
This reverts commit 8ffa22d10d3001405965826b46463663fd2dacc2.
7b922c
---
7b922c
 src/dhcp/nm-dhcp-dhclient-utils.c   | 46 +++------------
7b922c
 src/dhcp/tests/test-dhcp-dhclient.c | 87 +++--------------------------
7b922c
 2 files changed, 17 insertions(+), 116 deletions(-)
7b922c
7b922c
diff --git a/src/dhcp/nm-dhcp-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
index 7324597..4eb4c5d 100644
7b922c
--- a/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
+++ b/src/dhcp/nm-dhcp-dhclient-utils.c
7b922c
@@ -137,9 +137,8 @@ add_ip4_config (GString *str, GBytes *client_id, const char *hostname, gboolean
7b922c
 				g_string_append_printf (str, "%02x", (guint8) p[i]);
7b922c
 			}
7b922c
 		} else {
7b922c
-			/* Printable; just add to the line with type 0 */
7b922c
+			/* Printable; just add to the line minus the 'type' */
7b922c
 			g_string_append_c (str, '"');
7b922c
-			g_string_append (str, "\\x00");
7b922c
 			g_string_append_len (str, p + 1, l - 1);
7b922c
 			g_string_append_c (str, '"');
7b922c
 		}
7b922c
@@ -177,60 +176,31 @@ read_client_id (const char *str)
7b922c
 {
7b922c
 	gs_free char *s = NULL;
7b922c
 	char *p;
7b922c
-	int i = 0, j = 0;
7b922c
 
7b922c
 	nm_assert (!strncmp (str, CLIENTID_TAG, NM_STRLEN (CLIENTID_TAG)));
7b922c
-	str += NM_STRLEN (CLIENTID_TAG);
7b922c
 
7b922c
-	if (!g_ascii_isspace (*str))
7b922c
-		return NULL;
7b922c
+	str += NM_STRLEN (CLIENTID_TAG);
7b922c
 	while (g_ascii_isspace (*str))
7b922c
 		str++;
7b922c
 
7b922c
 	if (*str == '"') {
7b922c
-		/* Parse string literal with escape sequences */
7b922c
 		s = g_strdup (str + 1);
7b922c
 		p = strrchr (s, '"');
7b922c
 		if (p)
7b922c
 			*p = '\0';
7b922c
 		else
7b922c
 			return NULL;
7b922c
+	} else
7b922c
+		s = g_strdup (str);
7b922c
 
7b922c
-		if (!s[0])
7b922c
-			return NULL;
7b922c
-
7b922c
-		while (s[i]) {
7b922c
-			if (   s[i] == '\\'
7b922c
-			    && s[i + 1] == 'x'
7b922c
-			    && g_ascii_isxdigit (s[i + 2])
7b922c
-			    && g_ascii_isxdigit (s[i + 3])) {
7b922c
-				s[j++] =  (g_ascii_xdigit_value (s[i + 2]) << 4)
7b922c
-				         + g_ascii_xdigit_value (s[i + 3]);
7b922c
-				i += 4;
7b922c
-				continue;
7b922c
-			}
7b922c
-			if (   s[i] == '\\'
7b922c
-			    && s[i + 1] >= '0' && s[i + 1] <= '7'
7b922c
-			    && s[1 + 2] >= '0' && s[i + 2] <= '7'
7b922c
-			    && s[1 + 3] >= '0' && s[i + 3] <= '7') {
7b922c
-				s[j++] =    ((s[i + 1] - '0') << 6)
7b922c
-				          + ((s[i + 2] - '0') << 3)
7b922c
-				          + ( s[i + 3] - '0');
7b922c
-				i += 4;
7b922c
-				continue;
7b922c
-			}
7b922c
-			s[j++] = s[i++];
7b922c
-		}
7b922c
-		return g_bytes_new_take (g_steal_pointer (&s), j);
7b922c
-	}
7b922c
-
7b922c
-	/* Otherwise, try to read a hexadecimal sequence */
7b922c
-	s = g_strdup (str);
7b922c
 	g_strchomp (s);
7b922c
 	if (s[strlen (s) - 1] == ';')
7b922c
 		s[strlen (s) - 1] = '\0';
7b922c
 
7b922c
-	return nm_utils_hexstr2bin (s);
7b922c
+	if (!s[0])
7b922c
+		return NULL;
7b922c
+
7b922c
+	return nm_dhcp_utils_client_id_string_to_bytes (s);
7b922c
 }
7b922c
 
7b922c
 static gboolean
7b922c
diff --git a/src/dhcp/tests/test-dhcp-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
index 7df0720..acdd276 100644
7b922c
--- a/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
+++ b/src/dhcp/tests/test-dhcp-dhclient.c
7b922c
@@ -151,7 +151,7 @@ test_override_client_id (void)
7b922c
 static const char *quote_client_id_expected = \
7b922c
 	"# Created by NetworkManager\n"
7b922c
 	"\n"
7b922c
-	"send dhcp-client-identifier \"\\x00abcd\"; # added by NetworkManager\n"
7b922c
+	"send dhcp-client-identifier \"1234\"; # added by NetworkManager\n"
7b922c
 	"\n"
7b922c
 	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
 	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
@@ -170,37 +170,7 @@ test_quote_client_id (void)
7b922c
 {
7b922c
 	test_config (NULL, quote_client_id_expected,
7b922c
 	             AF_INET, NULL, 0, FALSE,
7b922c
-	             "abcd",
7b922c
-	             NULL,
7b922c
-	             "eth0",
7b922c
-	             NULL);
7b922c
-}
7b922c
-
7b922c
-/*****************************************************************************/
7b922c
-
7b922c
-static const char *hex_zero_client_id_expected = \
7b922c
-	"# Created by NetworkManager\n"
7b922c
-	"\n"
7b922c
-	"send dhcp-client-identifier 00:11:22:33; # added by NetworkManager\n"
7b922c
-	"\n"
7b922c
-	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
-	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
-	"option wpad code 252 = string;\n"
7b922c
-	"\n"
7b922c
-	"also request rfc3442-classless-static-routes;\n"
7b922c
-	"also request ms-classless-static-routes;\n"
7b922c
-	"also request static-routes;\n"
7b922c
-	"also request wpad;\n"
7b922c
-	"also request ntp-servers;\n"
7b922c
-	"also request root-path;\n"
7b922c
-	"\n";
7b922c
-
7b922c
-static void
7b922c
-test_hex_zero_client_id (void)
7b922c
-{
7b922c
-	test_config (NULL, hex_zero_client_id_expected,
7b922c
-	             AF_INET, NULL, 0, FALSE,
7b922c
-	             "00:11:22:33",
7b922c
+	             "1234",
7b922c
 	             NULL,
7b922c
 	             "eth0",
7b922c
 	             NULL);
7b922c
@@ -211,7 +181,7 @@ test_hex_zero_client_id (void)
7b922c
 static const char *ascii_client_id_expected = \
7b922c
 	"# Created by NetworkManager\n"
7b922c
 	"\n"
7b922c
-	"send dhcp-client-identifier \"\\x00qb:cd:ef:12:34:56\"; # added by NetworkManager\n"
7b922c
+	"send dhcp-client-identifier \"qb:cd:ef:12:34:56\"; # added by NetworkManager\n"
7b922c
 	"\n"
7b922c
 	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
 	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
@@ -269,13 +239,13 @@ test_hex_single_client_id (void)
7b922c
 /*****************************************************************************/
7b922c
 
7b922c
 static const char *existing_hex_client_id_orig = \
7b922c
-	"send dhcp-client-identifier 10:30:04:20:7A:08;\n";
7b922c
+	"send dhcp-client-identifier 00:30:04:20:7A:08;\n";
7b922c
 
7b922c
 static const char *existing_hex_client_id_expected = \
7b922c
 	"# Created by NetworkManager\n"
7b922c
 	"# Merged from /path/to/dhclient.conf\n"
7b922c
 	"\n"
7b922c
-	"send dhcp-client-identifier 10:30:04:20:7A:08;\n"
7b922c
+	"send dhcp-client-identifier 00:30:04:20:7A:08;\n"
7b922c
 	"\n"
7b922c
 	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
 	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
@@ -293,7 +263,7 @@ static void
7b922c
 test_existing_hex_client_id (void)
7b922c
 {
7b922c
 	gs_unref_bytes GBytes *new_client_id = NULL;
7b922c
-	const guint8 bytes[] = { 0x10, 0x30, 0x04, 0x20, 0x7A, 0x08 };
7b922c
+	const guint8 bytes[] = { 0x00, 0x30, 0x04,0x20, 0x7A, 0x08 };
7b922c
 
7b922c
 	new_client_id = g_bytes_new (bytes, sizeof (bytes));
7b922c
 	test_config (existing_hex_client_id_orig, existing_hex_client_id_expected,
7b922c
@@ -306,53 +276,16 @@ test_existing_hex_client_id (void)
7b922c
 
7b922c
 /*****************************************************************************/
7b922c
 
7b922c
-static const char *existing_escaped_client_id_orig = \
7b922c
-	"send dhcp-client-identifier \"\\044test\\xfe\";\n";
7b922c
-
7b922c
-static const char *existing_escaped_client_id_expected = \
7b922c
-	"# Created by NetworkManager\n"
7b922c
-	"# Merged from /path/to/dhclient.conf\n"
7b922c
-	"\n"
7b922c
-	"send dhcp-client-identifier \"\\044test\\xfe\";\n"
7b922c
-	"\n"
7b922c
-	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
-	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
-	"option wpad code 252 = string;\n"
7b922c
-	"\n"
7b922c
-	"also request rfc3442-classless-static-routes;\n"
7b922c
-	"also request ms-classless-static-routes;\n"
7b922c
-	"also request static-routes;\n"
7b922c
-	"also request wpad;\n"
7b922c
-	"also request ntp-servers;\n"
7b922c
-	"also request root-path;\n"
7b922c
-	"\n";
7b922c
-
7b922c
-static void
7b922c
-test_existing_escaped_client_id (void)
7b922c
-{
7b922c
-	gs_unref_bytes GBytes *new_client_id = NULL;
7b922c
-
7b922c
-	new_client_id = g_bytes_new ("$test\xfe", 6);
7b922c
-	test_config (existing_escaped_client_id_orig, existing_escaped_client_id_expected,
7b922c
-	             AF_INET, NULL, 0, FALSE,
7b922c
-	             NULL,
7b922c
-	             new_client_id,
7b922c
-	             "eth0",
7b922c
-	             NULL);
7b922c
-}
7b922c
-
7b922c
-/*****************************************************************************/
7b922c
-
7b922c
 #define EACID "qb:cd:ef:12:34:56"
7b922c
 
7b922c
 static const char *existing_ascii_client_id_orig = \
7b922c
-	"send dhcp-client-identifier \"\\x00" EACID "\";\n";
7b922c
+	"send dhcp-client-identifier \"" EACID "\";\n";
7b922c
 
7b922c
 static const char *existing_ascii_client_id_expected = \
7b922c
 	"# Created by NetworkManager\n"
7b922c
 	"# Merged from /path/to/dhclient.conf\n"
7b922c
 	"\n"
7b922c
-	"send dhcp-client-identifier \"\\x00" EACID "\";\n"
7b922c
+	"send dhcp-client-identifier \"" EACID "\";\n"
7b922c
 	"\n"
7b922c
 	"option rfc3442-classless-static-routes code 121 = array of unsigned integer 8;\n"
7b922c
 	"option ms-classless-static-routes code 249 = array of unsigned integer 8;\n"
7b922c
@@ -944,7 +877,7 @@ static void
7b922c
 test_structured (void)
7b922c
 {
7b922c
 	gs_unref_bytes GBytes *new_client_id = NULL;
7b922c
-	const guint8 bytes[] = "sad-and-useless";
7b922c
+	const guint8 bytes[] = "\x00sad-and-useless";
7b922c
 
7b922c
 	static const char *const orig = \
7b922c
 		"interface \"eth0\"   {  \n"
7b922c
@@ -1101,11 +1034,9 @@ main (int argc, char **argv)
7b922c
 	g_test_add_func ("/dhcp/dhclient/orig_missing", test_orig_missing);
7b922c
 	g_test_add_func ("/dhcp/dhclient/override_client_id", test_override_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/quote_client_id", test_quote_client_id);
7b922c
-	g_test_add_func ("/dhcp/dhclient/hex_zero_client_id", test_hex_zero_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/ascii_client_id", test_ascii_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/hex_single_client_id", test_hex_single_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/existing-hex-client-id", test_existing_hex_client_id);
7b922c
-	g_test_add_func ("/dhcp/dhclient/existing-client-id", test_existing_escaped_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/existing-ascii-client-id", test_existing_ascii_client_id);
7b922c
 	g_test_add_func ("/dhcp/dhclient/fqdn", test_fqdn);
7b922c
 	g_test_add_func ("/dhcp/dhclient/fqdn_options_override", test_fqdn_options_override);
7b922c
-- 
7b922c
2.21.0
7b922c