Skip to contentSkip to conversation

Allow DNS autoconf by passing hostname by IV variables when using push-peer-info

PATCH In review Ricardo Manriquez 3 participants 3 messages Sep 18, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow DNS autoconf by passing hostname by IV variables when using push-peer-info

Author: Ricardo Manríquez <[email protected]...>

To enable the possibility of DNS autoconfiguration the IP address and hostname of the client are needed to register at the DNS level, this patch adds this information when using push-peer-info.

The motivation is that the domain name is as intrusive as the MAC address and DNS autoconfiguration is helpful to be able to communicate back to the clients, this generates a problem when the client connects to the network directly and then uses the VPN connection, now the DNS records do not match and when using remote assistance or remote management tools the benefits of DNS are negated.

---
 src/openvpn/ssl.c | 5 +++++
 1 file changed, 5 insertions(+)
src/openvpn/ssl.c +0 -0
index 80e0d5acb4..3031566585 100644
@@ -2321,6 +2321,11 @@ push_peer_info(struct buffer *buf, struct

tls_session *session)

             {
                 buf_printf(&out, "IV_HWADDR=%s\n",
format_hex_ex(rgi.hwaddr, 6, 0, 1, ":", &gc));
             }
+
+            char hostname[64];
+            gethostname(hostname, 63);
+            buf_printf(&out, "IV_HOSTNAME=%s\n", hostname );
+
             buf_printf(&out, "IV_SSL=%s\n", get_ssl_library_version() );
 #if defined(_WIN32)
             buf_printf(&out, "IV_PLAT_VER=%s\n",

win32_version_string(&gc, false));

#1 lore raw

Hi,

Review

Quoted 4 lines · Ricardo Manriquez
(quoted diff) +4 -0
+
+            char hostname[64];
+            gethostname(hostname, 63);
+            buf_printf(&out, "IV_HOSTNAME=%s\n", hostname );

Without entering the discussion if this is a useful addition, the implementation definitely lacks error handling - gethostname() can fail, and then we have an unintialized buffer passed to buf_printf().

gert

Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you 
 feed honest figures into a computer, honest figures come out. Never doubted 
 it myself till I met a computer with a sense of humor."
                             Robert A. Heinlein, The Moon is a Harsh Mistress

Gert Doering - Munich, Germany                             [email protected]...
#2 lore raw
In reply to Ricardo Manriquez

Am 18.09.2022 um 03:23 schrieb Ricardo Manriquez:

Quoted 5 lines

Author: Ricardo Manríquez <[email protected]...>

To enable the possibility of DNS autoconfiguration the IP address and hostname of the client are needed to register at the DNS level, this patch adds this information when using push-peer-info.

The motivation is that the domain name is as intrusive as the MAC address and DNS autoconfiguration is helpful to be able to communicate back to the clients, this generates a problem when the client connects to the network directly and then uses the VPN connection, now the DNS records do not match and when using remote assistance or remote management tools the benefits of DNS are negated.

Could you expain why this needs to be in OpenVPN itself and cannot be done with something like starting openvpn with an additional parameter like --setenv UV_HOSTNAME "$(hostname)" or derived from another parameter/variable from the client like CN, username etc? Space in the packet carrying IV_/UV_ variables is already limited and I am not sure if spending another 64 for the hostname is a good thing.

Quoted 9 lines
---
  src/openvpn/ssl.c | 5 +++++
  1 file changed, 5 insertions(+)
src/openvpn/ssl.c +0 -0
index 80e0d5acb4..3031566585 100644

src/openvpn/ssl.c push_peer_info(struct buffer *buf, struct tls_session *session) · line 2327

Quoted 7 lines
src/openvpn/ssl.c +4 -0
@@ -2321,6 +2321,11 @@ push_peer_info(struct buffer *buf, struct tls_session *session)
              {
                  buf_printf(&out, "IV_HWADDR=%s\n", format_hex_ex(rgi.hwaddr, 6, 0, 1, ":", &gc));
              }
+
+            char hostname[64];
+            gethostname(hostname, 63);
+            buf_printf(&out, "IV_HOSTNAME=%s\n", hostname );

Isn't there a MAX_HOSTNAME define or similar instead of hardcoding 64 here?

The handling of the string of hostname is not very well here. The man page of the function (gethostname(2) - Linux manual page (man7.org) <https://man7.org/linux/man-pages/man2/sethostname.2.html>) says null termination is not guaranteed for long hostnames.

Quoted 10 lines
src/openvpn/ssl.c +1 -0
+
              buf_printf(&out, "IV_SSL=%s\n", get_ssl_library_version() );
  #if defined(_WIN32)
              buf_printf(&out, "IV_PLAT_VER=%s\n", win32_version_string(&gc, false));

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel