[PATCH] Add MDNS configuration option

Kevin Anderson andersonkw2 at gmail.com
Mon Dec 4 11:16:00 UTC 2017


Good morning,

On Sun, Nov 26, 2017 at 5:42 PM, Kevin Anderson <andersonkw2 at gmail.com> wrote:
>
> Good evening,
>     Attached is a patch that makes the MDNS name configurable.
> Right now it only affects Avahi and supports using the default
> of the NETBIOS name or deferring the name value to the Avahi
> server. This has the effect of lower casing the hostname
> on SMB registered Avahi services automatically.
>
> I would appreciate a review on it.
>
> -Kevin Anderson

Just a friendly ping for a review on this. :)

Thanks,
Kevin
-------------- next part --------------
From 73dca1363749b0ab0bd95af73acf8f75634f5989 Mon Sep 17 00:00:00 2001
From: Kevin Anderson <andersonkw2 at gmail.com>
Date: Sat, 25 Nov 2017 23:03:59 -0500
Subject: [PATCH] Add mdns name configuration option

Add the mdns name configuration variable to control the mdns hostname.
The default is to use the NETBIOS name of the system to match previous
versions which is typically the hostname in all capitals. A value of mdns
can be provided to defer the hostname to the mdns library.

Signed-off-by: Kevin Anderson <andersonkw2 at gmail.com>
---
 docs-xml/smbdotconf/base/mdnsname.xml | 19 +++++++++++++++++++
 lib/param/loadparm.c                  |  2 ++
 lib/param/loadparm.h                  |  3 +++
 lib/param/param_table.c               |  6 ++++++
 source3/smbd/avahi_register.c         | 15 +++++++++++++--
 5 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100644 docs-xml/smbdotconf/base/mdnsname.xml

diff --git a/docs-xml/smbdotconf/base/mdnsname.xml b/docs-xml/smbdotconf/base/mdnsname.xml
new file mode 100644
index 00000000000..fba90ff9b84
--- /dev/null
+++ b/docs-xml/smbdotconf/base/mdnsname.xml
@@ -0,0 +1,19 @@
+<samba:parameter name="mdns name"
+                 type="enum"
+                 context="G"
+                 enumlist="enum_mdns_name_values"
+                 xmlns:samba="http://www.samba.org/samba/DTD/samba-doc">
+
+<description>
+	<para>This parameter controls the name that multicast DNS
+	support advertises as its' hostname.</para>
+
+	<para>The default is to use the NETBIOS name which is typically
+	the hostname in all capital letters. </para>
+
+	<para>A setting of mdns will defer the hostname configuration
+	to the MDNS library that is used.</para>
+
+</description>
+<value type="default">netbios</value>
+</samba:parameter>
diff --git a/lib/param/loadparm.c b/lib/param/loadparm.c
index d788ffbe36f..73b7901d7f6 100644
--- a/lib/param/loadparm.c
+++ b/lib/param/loadparm.c
@@ -2906,6 +2906,8 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
 
 	lpcfg_do_global_parameter(lp_ctx, "client ldap sasl wrapping", "sign");
 
+	lpcfg_do_global_parameter(lp_ctx, "mdns name", "netbios");
+
 	lpcfg_do_global_parameter(lp_ctx, "ldap server require strong auth", "yes");
 
 	lpcfg_do_global_parameter(lp_ctx, "follow symlinks", "yes");
diff --git a/lib/param/loadparm.h b/lib/param/loadparm.h
index e3c82164ca4..b5d79b912c7 100644
--- a/lib/param/loadparm.h
+++ b/lib/param/loadparm.h
@@ -223,6 +223,9 @@ enum ldap_server_require_strong_auth {
 /* DNS update settings */
 enum dns_update_settings {DNS_UPDATE_OFF, DNS_UPDATE_ON, DNS_UPDATE_SIGNED};
 
+/* MDNS name sources */
+enum mdns_name_values {MDNS_NAME_NETBIOS, MDNS_NAME_MDNS};
+
 /* LDAP SSL options */
 enum ldap_ssl_types {LDAP_SSL_OFF, LDAP_SSL_START_TLS};
 
diff --git a/lib/param/param_table.c b/lib/param/param_table.c
index f9052304bda..f9d3b55adf2 100644
--- a/lib/param/param_table.c
+++ b/lib/param/param_table.c
@@ -127,6 +127,12 @@ static const struct enum_list enum_smb_signing_vals[] = {
 	{-1, NULL}
 };
 
+static const struct enum_list enum_mdns_name_values[] = {
+	{MDNS_NAME_NETBIOS, "netbios"},
+	{MDNS_NAME_MDNS, "mdns"},
+	{-1, NULL}
+};
+
 static const struct enum_list enum_tls_verify_peer_vals[] = {
 	{TLS_VERIFY_PEER_NO_CHECK,
 	 TLS_VERIFY_PEER_NO_CHECK_STRING},
diff --git a/source3/smbd/avahi_register.c b/source3/smbd/avahi_register.c
index 91e8a439b84..8733257fce6 100644
--- a/source3/smbd/avahi_register.c
+++ b/source3/smbd/avahi_register.c
@@ -103,12 +103,23 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 	struct avahi_state_struct *state = talloc_get_type_abort(
 		userdata, struct avahi_state_struct);
 	int error;
+	const char *hostname = NULL;
 
 	switch (status) {
 	case AVAHI_CLIENT_S_RUNNING: {
 		int snum;
 		int num_services = lp_numservices();
 		int dk = 0;
+
+		if (hostname == NULL) {
+			if (lp_mdns_name() == MDNS_NAME_MDNS) {
+				hostname = avahi_client_get_host_name (c);;
+			}
+			if (lp_mdns_name() == MDNS_NAME_NETBIOS) {
+				hostname = lp_netbios_name();
+			}
+		}
+
 		AvahiStringList *adisk = NULL;
 		AvahiStringList *adisk2 = NULL;
 
@@ -125,7 +136,7 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 
 		error = avahi_entry_group_add_service(
 			    state->entry_group, AVAHI_IF_UNSPEC,
-			    AVAHI_PROTO_UNSPEC, 0, lp_netbios_name(),
+			    AVAHI_PROTO_UNSPEC, 0, hostname,
 			    "_smb._tcp", NULL, NULL, state->port, NULL);
 		if (error != AVAHI_OK) {
 			DBG_DEBUG("avahi_entry_group_add_service failed: %s\n",
@@ -169,7 +180,7 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 
 			error = avahi_entry_group_add_service_strlst(
 				    state->entry_group, AVAHI_IF_UNSPEC,
-				    AVAHI_PROTO_UNSPEC, 0, lp_netbios_name(),
+				    AVAHI_PROTO_UNSPEC, 0, hostname,
 				    "_adisk._tcp", NULL, NULL, 0, adisk);
 			avahi_string_list_free(adisk);
 			adisk = NULL;
-- 
2.14.3



More information about the samba-technical mailing list