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

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