summarylogtreecommitdiffstats
path: root/0024-sd-dhcp-chop-of-trailing-dot-of-DHCP-supplied-host-a.patch
blob: 113d20ef497df4cac4df366e159db27103a0dcd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From f50f01f4b738f2f00b30d0e02e8cf54ab99a9f27 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 28 Jan 2015 17:47:37 +0100
Subject: [PATCH] sd-dhcp: chop of trailing dot of DHCP supplied host and
 domain nams

---
 src/libsystemd-network/sd-dhcp-lease.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 00fef16..34aa36c 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -497,11 +497,20 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
         case DHCP_OPTION_DOMAIN_NAME:
         {
                 _cleanup_free_ char *domainname = NULL;
+                char *e;
 
                 r = lease_parse_string(option, len, &domainname);
                 if (r < 0)
                         return r;
 
+                /* Chop off trailing dot of domain name that some DHCP
+                 * servers send us back. Internally we want to store
+                 * host names without trailing dots and
+                 * host_name_is_valid() doesn't accept them. */
+                e = endswith(domainname, ".");
+                if (e)
+                        *e = 0;
+
                 if (!hostname_is_valid(domainname) || is_localhost(domainname))
                         break;
 
@@ -514,11 +523,16 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
         case DHCP_OPTION_HOST_NAME:
         {
                 _cleanup_free_ char *hostname = NULL;
+                char *e;
 
                 r = lease_parse_string(option, len, &hostname);
                 if (r < 0)
                         return r;
 
+                e = endswith(hostname, ".");
+                if (e)
+                        *e = 0;
+
                 if (!hostname_is_valid(hostname) || is_localhost(hostname))
                         break;
 
-- 
2.3.0