avahi/fruit: _device-info._tcp not propagated

Günther Deschner gd at samba.org
Tue Jan 15 14:37:11 UTC 2019


Hi Rouven,

sorry. I wrote my patch before I saw this mail. Your change is exactly
right, here is a 2nd version of the patch I sent earlier (with better
memory management just like you proposed here). Please test.

Thanks,
Guenther

On 15/01/2019 14:26, Rouven WEILER via samba-technical wrote:
> I would like to recommend a change in the avahi part propagating the Finder Device Icon to MacOS.
> Therefore, I would change the avahi_register.c to include parts for sending "_device-info._tcp" when the vfs_object fruit is loaded.
>  
> For adding this info to avahi the entry
> --
> <service> <type>_device-info._tcp</type> <port>0</port> <txt-record>model=RackMac</txt-record> </service>
> 
> --
> has to be put into the avahi service file (see: https://jonathanmumm.com/tech-it/mdns-bonjour-bible-common-service-strings-for-various-vendors/ and https://simonwheatley.co.uk/2008/04/avahi-finder-icons/).
> This works fine when doing that manually with avahi.
>  
> I thought of adding that now into samba.
> As a first try I added a new avahi_register.c file showing the first ideas.
>  
> If that sounds good too you I would appreciate some help concerning:
> - How would I chech whether fruit has been loaded to start the _device-info propagation?
> - Is the coding/error handling etc okay?
>  
> If my changes are not necessary, please tell me how to change the "MacSamba" Icon to e.g. "RackMac".
> I actually do not see this change on my Mac using samba internals. Avahi as standalone works. (Maybe a bug?)
>  
> Thanks in advance.
>  
> Here the changes I thought of in "avahi_register.c", function "avahi_client_callback":
> 
> static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
>                   void *userdata)
> {   
>  
>         ...
>  
>         state->entry_group = avahi_entry_group_new(
>             c, avahi_entry_group_callback, state);
>         if (state->entry_group == NULL) {
>             error = avahi_client_errno(c);
>             DBG_DEBUG("avahi_entry_group_new failed: %s\n",
>                   avahi_strerror(error));
>             break;
>         }
>         error = avahi_entry_group_add_service(
>                 state->entry_group, AVAHI_IF_UNSPEC,
>                 AVAHI_PROTO_UNSPEC, 0, hostname,
>                 "_smb._tcp", NULL, NULL, state->port, NULL);
>         error = avahi_entry_group_add_service(
>                 state->entry_group, AVAHI_IF_UNSPEC,
>                 AVAHI_PROTO_UNSPEC, 0, hostname,
>                 "_device-info._tcp", NULL, NULL, 0, NULL);
>         if (error != AVAHI_OK) {
>             DBG_DEBUG("avahi_entry_group_add_service failed: %s\n",
>                   avahi_strerror(error));
>             avahi_entry_group_free(state->entry_group);
>             state->entry_group = NULL;
>             break;
>         }
>         device_info = avahi_string_list_add_printf(
>                      device_info, "model=%s",
>                      lp_parm_const_string(-1, FRUIT_PARAM_TYPE_NAME, "model", "MacSamba");
>         if (device_info == NULL) {
>             DBG_DEBUG("avahi_string_list_add_printf"
>                   "failed: returned NULL\n");
>             avahi_string_list_free(adisk);
>             avahi_entry_group_free(state->entry_group);
>             state->entry_group = NULL;
>             break;
>         }
>         ...
> }
> 


-- 
Günther Deschner                    GPG-ID: 8EE11688
Red Hat                         gdeschner at redhat.com
Samba Team                              gd at samba.org
-------------- next part --------------
From 9829e50054294c0c3bc1b092b560b2393a65c54c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCnther=20Deschner?= <gd at samba.org>
Date: Tue, 15 Jan 2019 14:26:17 +0100
Subject: [PATCH] s3-smbd: use fruit:model string for mDNS registration

With this change we now allow to modify the icon to represent Samba in
Finder. Possible values are at least:

fruit:model = iMac
fruit:model = MacBook
fruit:model = MacPro
fruit:model = Xserve
fruit:model = RackMac

Prior to this change we only displayed the correct icon when nmbd and
not avahi mDNS was used.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13746

Based on proposed patch from Rouven WEILER <Rouven_Weiler at gmx.net>

Guenther

Signed-off-by: Guenther Deschner <gd at samba.org>
---
 source3/smbd/avahi_register.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/source3/smbd/avahi_register.c b/source3/smbd/avahi_register.c
index 6c87669ba36..6b134619d85 100644
--- a/source3/smbd/avahi_register.c
+++ b/source3/smbd/avahi_register.c
@@ -111,8 +111,10 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 		size_t dk = 0;
 		AvahiStringList *adisk = NULL;
 		AvahiStringList *adisk2 = NULL;
+		AvahiStringList *dinfo = NULL;
 		const char *hostname = NULL;
 		enum mdns_name_values mdns_name = lp_mdns_name();
+		const char *model;
 
 		DBG_DEBUG("AVAHI_CLIENT_S_RUNNING\n");
 
@@ -194,6 +196,31 @@ static void avahi_client_callback(AvahiClient *c, AvahiClientState status,
 				state->entry_group = NULL;
 				break;
 			}
+
+		}
+
+		model = lp_parm_const_string(-1, "fruit", "model", "MacSamba");
+
+		dinfo = avahi_string_list_add_printf(NULL, "model=%s", model);
+		if (dinfo == NULL) {
+			DBG_DEBUG("out of memory\n");
+			avahi_entry_group_free(state->entry_group);
+			state->entry_group = NULL;
+			break;
+		}
+
+		error = avahi_entry_group_add_service_strlst(
+			    state->entry_group, AVAHI_IF_UNSPEC,
+			    AVAHI_PROTO_UNSPEC, 0, hostname,
+			    "_device-info._tcp", NULL, NULL, 0,
+			    dinfo);
+		avahi_string_list_free(dinfo);
+		if (error != AVAHI_OK) {
+			DBG_DEBUG("avahi_entry_group_add_service failed: %s\n",
+				  avahi_strerror(error));
+			avahi_entry_group_free(state->entry_group);
+			state->entry_group = NULL;
+			break;
 		}
 
 		error = avahi_entry_group_commit(state->entry_group);
-- 
2.20.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20190115/0ba51c8b/signature.sig>


More information about the samba-technical mailing list