Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Feb 2019 00:36:32 +0000 (UTC)
From:      "Timur I. Bakeyev" <timur@FreeBSD.org>
To:        ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org
Subject:   svn commit: r492474 - in head/net/samba48: . files
Message-ID:  <201902090036.x190aWqL040572@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: timur
Date: Sat Feb  9 00:36:32 2019
New Revision: 492474
URL: https://svnweb.freebsd.org/changeset/ports/492474

Log:
  Update port to the latest 4.8.9 version
  
  Sponsored by:	CyberSecure

Added:
  head/net/samba48/files/patch-python_samba_provision_sambadns.py   (contents, props changed)
  head/net/samba48/files/patch-source3__lib__sysquotas_4B.c   (contents, props changed)
  head/net/samba48/files/patch-source3_modules_vfs__freebsd.c   (contents, props changed)
  head/net/samba48/files/patch-source3_modules_vfs__streams__xattr.c   (contents, props changed)
  head/net/samba48/files/patch-source4_setup_named.conf.dlz   (contents, props changed)
Deleted:
  head/net/samba48/files/0001-bug-13175.patch
  head/net/samba48/files/patch-source3__modules__vfs_streams_xattr.c
  head/net/samba48/files/patch-vfs_freebsd.c
Modified:
  head/net/samba48/Makefile
  head/net/samba48/distinfo
  head/net/samba48/files/0001-bug-228462.patch
  head/net/samba48/files/samba_server.in
  head/net/samba48/pkg-plist

Modified: head/net/samba48/Makefile
==============================================================================
--- head/net/samba48/Makefile	Sat Feb  9 00:36:20 2019	(r492473)
+++ head/net/samba48/Makefile	Sat Feb  9 00:36:32 2019	(r492474)
@@ -13,7 +13,6 @@ COMMENT=			Free SMB/CIFS and AD/DC server and client f
 
 LICENSE=			GPLv3
 
-BROKEN_powerpc64=		fails to compile: auth.idl:107: Unable to determine origin of type struct cli_credentials
 IGNORE_NONTHREAD_PYTHON=	needs port lang/python${PYTHON_SUFFIX} to be build with THREADS support
 
 CONFLICTS_INSTALL?=		samba4-4.0.* samba4[1-79]-4.* p5-Parse-Pidl-4.*
@@ -21,12 +20,11 @@ CONFLICTS_INSTALL?=		samba4-4.0.* samba4[1-79]-4.* p5-
 EXTRA_PATCHES+=			${PATCHDIR}/0001-Zfs-provision-1.patch:-p1
 EXTRA_PATCHES+=			${PATCHDIR}/0001-Freenas-master-mdns-fixes-22.patch:-p1
 EXTRA_PATCHES+=			${PATCHDIR}/0001-audit.patch:-p1
-EXTRA_PATCHES+=			${PATCHDIR}/0001-bug-13175.patch:-p1
 EXTRA_PATCHES+=			${PATCHDIR}/0001-bug-228462.patch:-p1
 
 SAMBA4_BASENAME=		samba
 SAMBA4_PORTNAME=		${SAMBA4_BASENAME}4
-SAMBA4_VERSION=			4.8.7
+SAMBA4_VERSION=			4.8.9
 SAMBA4_DISTNAME=		${SAMBA4_BASENAME}-${SAMBA4_VERSION:S|.p|pre|:S|.r|rc|:S|.t|tp|:S|.a|alpha|}
 
 WRKSRC?=			${WRKDIR}/${DISTNAME}
@@ -69,11 +67,9 @@ CONFIGURE_ARGS+=		--mandir="${MANPREFIX}/man" \
 				--with-logfilebase="${SAMBA4_LOGDIR}"
 # XXX: Flags
 CONFIGURE_ENV+=			PTHREAD_LDFLAGS="-lpthread"
-CPPFLAGS+=			-I${LOCALBASE}/include
-LDFLAGS+=			-L${LOCALBASE}/lib
 
-USES=				cpe compiler waf pkgconfig perl5 \
-				iconv shebangfix
+USES=				compiler:c++11-lang cpe iconv \
+				localbase:ldflags perl5 pkgconfig shebangfix waf
 USE_PERL5=			build
 USE_LDCONFIG=			${SAMBA4_LIBDIR}
 WAF_CMD=			buildtools/bin/waf
@@ -97,7 +93,7 @@ OPTIONS_DEFINE+=		DEVELOPER MANDOC
 OPTIONS_DEFINE_amd64=		AESNI
 OPTIONS_DEFAULT_amd64=		AESNI
 
-OPTIONS_DEFINE+=		CLUSTER CUPS GPGME NTVFS SPOTLIGHT
+OPTIONS_DEFINE+=		CLUSTER CUPS GLUSTERFS GPGME NTVFS SPOTLIGHT
 #OPTIONS_DEFINE+=		MEMORY_DEBUG
 
 OPTIONS_SINGLE=			GSSAPI
@@ -105,7 +101,7 @@ OPTIONS_SINGLE=			GSSAPI
 OPTIONS_SINGLE_GSSAPI=		GSSAPI_BUILTIN GSSAPI_MIT
 
 OPTIONS_RADIO=			DNS ZEROCONF
-OPTIONS_RADIO_DNS=		NSUPDATE BIND911
+OPTIONS_RADIO_DNS=		NSUPDATE BIND911 BIND912
 OPTIONS_RADIO_ZEROCONF=		MDNSRESPONDER AVAHI
 ##############################################################################
 AD_DC_DESC=			Active Directory Domain Controller
@@ -130,6 +126,7 @@ UTMP_DESC=			UTMP accounting
 GSSAPI_BUILTIN_DESC=		GSSAPI support via bundled Heimdal
 
 BIND911_DESC=			Use Bind 9.11 as AD DC DNS server frontend
+BIND912_DESC=			Use Bind 9.12 as AD DC DNS server frontend
 NSUPDATE_DESC=			Use samba NSUPDATE utility for AD DC
 ##############################################################################
 # XXX: Unconditional dependencies which can't be switched off(if present in
@@ -272,13 +269,16 @@ CONFIGURE_ARGS+=		\
 				${ICONV_CONFIGURE_BASE}
 ##############################################################################
 BIND911_RUN_DEPENDS=		bind911>=9.11.0.0:dns/bind911
+BIND912_RUN_DEPENDS=		bind911>=9.12.0.0:dns/bind912
 NSUPDATE_RUN_DEPENDS=		samba-nsupdate:dns/samba-nsupdate
 
 AVAHI_CONFIGURE_ENABLE=		avahi
 AVAHI_LIB_DEPENDS=		libavahi-client.so:net/avahi-app
+AVAHI_VARS=			SAMBA4_SERVICES+=avahi_daemon
 
 MDNSRESPONDER_CONFIGURE_ENABLE=	dnssd
 MDNSRESPONDER_LIB_DEPENDS=	libdns_sd.so:net/mDNSResponder
+MDNSRESPONDER_VARS=		SAMBA4_SERVICES+=mdnsd
 ##############################################################################
 DEBUG_CONFIGURE_ON=		--verbose --enable-debug
 DEBUG_MAKE_ARGS=		--verbose
@@ -509,7 +509,8 @@ SAMBA4_SUB=			SAMBA4_LOGDIR="${SAMBA4_LOGDIR}" \
 				SAMBA4_BINDDNSDIR="${SAMBA4_BINDDNSDIR}" \
 				SAMBA4_PRIVATEDIR="${SAMBA4_PRIVATEDIR}" \
 				SAMBA4_CONFDIR="${SAMBA4_CONFDIR}" \
-				SAMBA4_CONFIG="${SAMBA4_CONFIG}"
+				SAMBA4_CONFIG="${SAMBA4_CONFIG}" \
+				SAMBA4_SERVICES="${SAMBA4_SERVICES}"
 
 PLIST_SUB+=			${SAMBA4_SUB}
 SUB_LIST+=			${SAMBA4_SUB}

Modified: head/net/samba48/distinfo
==============================================================================
--- head/net/samba48/distinfo	Sat Feb  9 00:36:20 2019	(r492473)
+++ head/net/samba48/distinfo	Sat Feb  9 00:36:32 2019	(r492474)
@@ -1,3 +1,3 @@
-TIMESTAMP = 1543311377
-SHA256 (samba-4.8.7.tar.gz) = 0f6f67932e8bb23ab83b43070037ac452f9fc5f20763857d2b67e209ee7cd362
-SIZE (samba-4.8.7.tar.gz) = 17724232
+TIMESTAMP = 1549652430
+SHA256 (samba-4.8.9.tar.gz) = ad2acf6bed436c125314a054f0589308eb664ac3d96cfb02d05e654a44e09c80
+SIZE (samba-4.8.9.tar.gz) = 17750151

Modified: head/net/samba48/files/0001-bug-228462.patch
==============================================================================
--- head/net/samba48/files/0001-bug-228462.patch	Sat Feb  9 00:36:20 2019	(r492473)
+++ head/net/samba48/files/0001-bug-228462.patch	Sat Feb  9 00:36:32 2019	(r492474)
@@ -13,25 +13,13 @@ FreeBSD Bug: https://bugs.freebsd.org/bugzilla/show_bu
 Signed-off-by: Ralph Boehme <slow@samba.org>
 ---
  source3/modules/vfs_fruit.c | 32 ++++++++++++++++++++++++--------
- 1 file changed, 24 insertions(+), 8 deletions(-)
+ 1 file changed, 27 insertions(+), 4 deletions(-)
 
 diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
 index df3cd0c899e..d84e6991036 100644
 --- a/source3/modules/vfs_fruit.c
 +++ b/source3/modules/vfs_fruit.c
-@@ -485,8 +485,9 @@ static int adouble_path(TALLOC_CTX *ctx,
- 			struct smb_filename **ppsmb_fname_out);
- static AfpInfo *afpinfo_new(TALLOC_CTX *ctx);
- static ssize_t afpinfo_pack(const AfpInfo *ai, char *buf);
--static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data);
--
-+static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx,
-+			       const void *data,
-+			       const struct smb_filename *smb_fname);
- 
- /**
-  * Return a pointer to an AppleDouble entry
-@@ -2073,13 +2074,17 @@ static ssize_t afpinfo_pack(const AfpInfo *ai, char *buf)
+@@ -2350,6 +2350,8 @@ static ssize_t afpinfo_pack(const AfpInf
  	return AFP_INFO_SIZE;
  }
  
@@ -40,17 +28,7 @@ index df3cd0c899e..d84e6991036 100644
  /**
   * Unpack a buffer into a AfpInfo structure
   *
-  * Buffer size must be at least AFP_INFO_SIZE
-  * Returns allocated AfpInfo struct
-  **/
--static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data)
-+static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx,
-+			       const void *data,
-+			       const struct smb_filename *smb_fname)
- {
- 	AfpInfo *ai = talloc_zero(ctx, AfpInfo);
- 	if (ai == NULL) {
-@@ -2092,10 +2097,21 @@ static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data)
+@@ -2369,10 +2371,20 @@ static AfpInfo *afpinfo_unpack(TALLOC_CT
  	memcpy(ai->afpi_FinderInfo, (const char *)data + 16,
  	       sizeof(ai->afpi_FinderInfo));
  
@@ -58,8 +36,7 @@ index df3cd0c899e..d84e6991036 100644
 -	    || ai->afpi_Version != AFP_Version) {
 -		DEBUG(1, ("Bad AfpInfo signature or version\n"));
 +	if (ai->afpi_Signature != AFP_Signature) {
-+		DBG_WARNING("Bad signature [%x] on [%s]\n",
-+			    ai->afpi_Signature, smb_fname_str_dbg(smb_fname));
++		DBG_WARNING("Bad AFP signature [%x]\n", ai->afpi_Signature);
 +
 +		if (ai->afpi_Signature != BROKEN_FREEBSD_AFP_Signature) {
 +			DBG_ERR("Bad AfpInfo signature\n");
@@ -75,100 +52,20 @@ index df3cd0c899e..d84e6991036 100644
  	}
  
  	return ai;
-@@ -4222,7 +4238,7 @@ static ssize_t fruit_pwrite_meta_stream(vfs_handle_struct *handle,
- 	size_t nwritten;
- 	bool ok;
- 
--	ai = afpinfo_unpack(talloc_tos(), data);
-+	ai = afpinfo_unpack(talloc_tos(), data, fsp->fsp_name);
- 	if (ai == NULL) {
- 		return -1;
- 	}
-@@ -4260,7 +4276,7 @@ static ssize_t fruit_pwrite_meta_netatalk(vfs_handle_struct *handle,
- 	int ret;
- 	bool ok;
- 
--	ai = afpinfo_unpack(talloc_tos(), data);
-+	ai = afpinfo_unpack(talloc_tos(), data, fsp->fsp_name);
- 	if (ai == NULL) {
- 		return -1;
- 	}
--- 
-2.16.3
-
-
-From 83ce03a278ec9d15b595f4daf8da1641d27ebdd6 Mon Sep 17 00:00:00 2001
-From: "Timur I. Bakeyev" <timur@iXsystems.com>
-Date: Fri, 1 Jun 2018 01:35:58 +0800
-Subject: [PATCH 2/2] vfs_streams_xattr: don't append 0 byte when creating
- xattr
-
-Upstream Samba always appends an internal 0-byte to xattrs to cope
-with filesytems or systems that don't support 0-byte sized xattrs.
-
-An older patch already remove this behaviour from the read and write
-code paths, but didn't remove it from the create codepath.
-
-FreeBSD Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=228462
-
-Signed-off-by: Ralph Boehme <slow@samba.org>
----
- source3/modules/vfs_streams_xattr.c | 8 +-------
- 1 file changed, 1 insertion(+), 7 deletions(-)
-
-diff --git a/source3/modules/vfs_streams_xattr.c b/source3/modules/vfs_streams_xattr.c
-index 8714007cb8d..5f3dfb30beb 100644
---- a/source3/modules/vfs_streams_xattr.c
-+++ b/source3/modules/vfs_streams_xattr.c
-@@ -476,19 +476,13 @@ static int streams_xattr_open(vfs_handle_struct *handle,
- 		/*
- 		 * The attribute does not exist or needs to be truncated
- 		 */
--
--		/*
--		 * Darn, xattrs need at least 1 byte
--		 */
--		char null = '\0';
--
- 		DEBUG(10, ("creating or truncating attribute %s on file %s\n",
- 			   xattr_name, smb_fname->base_name));
- 
- 		ret = SMB_VFS_SETXATTR(fsp->conn,
- 				       smb_fname,
- 				       xattr_name,
--				       &null, sizeof(null),
-+				       NULL, 0,
- 				       flags & O_EXCL ? XATTR_CREATE : 0);
- 		if (ret != 0) {
- 			goto fail;
--- 
-2.16.3
-
-From daa9930fc10459f0567931622e2ffbb636e365f0 Mon Sep 17 00:00:00 2001
-From: Ralph Boehme <slow@samba.org>
-Date: Sat, 19 May 2018 01:35:45 +0200
-Subject: [PATCH] vfs_fruit: fixup broken AFP_Signatures
-
-FreeBSD Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=228462
-
-Signed-off-by: Ralph Boehme <slow@samba.org>
----
- source3/modules/vfs_fruit.c | 6 ++++++
- 1 file changed, 6 insertions(+)
-
-diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
-index d92049cc899..0594fd7a538 100644
---- a/source3/modules/vfs_fruit.c
-+++ b/source3/modules/vfs_fruit.c
-@@ -3935,10 +3935,16 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_struct *handle,
+@@ -4171,9 +4183,20 @@ static ssize_t fruit_pread_meta_stream(v
  {
  	ssize_t nread;
  	int ret;
 +	char *p = (char *)data;
  
  	nread = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
- 
- 	if (nread == n) {
+-	if (nread == -1 || nread == n) {
++
++	if (nread == -1) {
++		return -1;
++	}
++
++	if (nread == n) {
 +		if (offset == 0 && nread > 3 && p[0] == 0 && p[1] == 'F' && p[2] == 'P') {
 +			DBG_NOTICE("Fixing AFP_Info of [%s]\n",
 +				    fsp_str_dbg(fsp));
@@ -177,6 +74,3 @@ index d92049cc899..0594fd7a538 100644
  		return nread;
  	}
  
--- 
-2.17.0
-

Added: head/net/samba48/files/patch-python_samba_provision_sambadns.py
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/samba48/files/patch-python_samba_provision_sambadns.py	Sat Feb  9 00:36:32 2019	(r492474)
@@ -0,0 +1,29 @@
+--- python/samba/provision/sambadns.py.orig	2018-01-17 09:08:39 UTC
++++ python/samba/provision/sambadns.py
+@@ -937,6 +937,7 @@ def create_named_conf(paths, realm, dnsd
+         bind9_9 = '#'
+         bind9_10 = '#'
+         bind9_11 = '#'
++        bind9_12 = '#'
+         if bind_info.upper().find('BIND 9.8') != -1:
+             bind9_8 = ''
+         elif bind_info.upper().find('BIND 9.9') != -1:
+@@ -945,6 +946,8 @@ def create_named_conf(paths, realm, dnsd
+             bind9_10 = ''
+         elif bind_info.upper().find('BIND 9.11') != -1:
+             bind9_11 = ''
++        elif bind_info.upper().find('BIND 9.12') != -1:
++            bind9_12 = ''
+         elif bind_info.upper().find('BIND 9.7') != -1:
+             raise ProvisioningError("DLZ option incompatible with BIND 9.7.")
+         else:
+@@ -955,7 +958,8 @@ def create_named_conf(paths, realm, dnsd
+                     "BIND9_8" : bind9_8,
+                     "BIND9_9" : bind9_9,
+                     "BIND9_10" : bind9_10,
+-                    "BIND9_11" : bind9_11
++                    "BIND9_11" : bind9_11,
++                    "BIND9_12" : bind9_12
+                     })
+ 
+ 

Added: head/net/samba48/files/patch-source3__lib__sysquotas_4B.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/samba48/files/patch-source3__lib__sysquotas_4B.c	Sat Feb  9 00:36:32 2019	(r492474)
@@ -0,0 +1,18 @@
+--- source3/lib/sysquotas_4B.c.orig	2019-01-28 03:56:23 UTC
++++ source3/lib/sysquotas_4B.c
+@@ -141,7 +141,14 @@ static int sys_quotactl_4B(const char * 
+ 		/* ENOTSUP means quota support is not compiled in. EINVAL
+ 		 * means that quotas are not configured (commonly).
+ 		 */
+-		if (errno != ENOTSUP && errno != EINVAL) {
++		if (errno != ENOTSUP && errno != EINVAL
++/*
++ * FreeBSD 12 between r336017 and r342928 wrongfuly return ENOENT for the not enabled qoutas on ZFS.
++ */
++#if defined(__FreeBSD__) && ((__FreeBSD_version >= 1102503 && __FreeBSD_version <= 1102506) || (__FreeBSD_version >= 1200072 && __FreeBSD_version <= 1200503) || (__FreeBSD_version >= 1300000 && __FreeBSD_version <= 1300009))
++			&& errno != ENOENT
++#endif
++		) {
+ 			DEBUG(0, ("failed to %s quota for %s ID %u on %s: %s\n",
+ 				    (cmd & QCMD(Q_GETQUOTA, 0)) ? "get" : "set",
+ 				    (cmd & QCMD(0, GRPQUOTA)) ? "group" : "user",

Added: head/net/samba48/files/patch-source3_modules_vfs__freebsd.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/net/samba48/files/patch-source3_modules_vfs__freebsd.c	Sat Feb  9 00:36:32 2019	(r492474)
@@ -0,0 +1,798 @@
+--- /dev/null	2018-11-29 02:13:13 UTC
++++ source3/modules/vfs_freebsd.c
+@@ -0,0 +1,795 @@
++/*
++ * This module implements VFS calls specific to FreeBSD
++ *
++ * Copyright (C) Timur I. Bakeyev, 2018
++ *
++ * This program is free software; you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License as published by
++ * the Free Software Foundation; either version 3 of the License, or
++ * (at your option) any later version.
++ *  
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *  
++ * You should have received a copy of the GNU General Public License
++ * along with this program; if not, see <http://www.gnu.org/licenses/>.
++ */
++
++#include "includes.h"
++
++#include "lib/util/tevent_unix.h"
++#include "lib/util/tevent_ntstatus.h"
++#include "system/filesys.h"
++
++#include <sys/sysctl.h>
++
++static int vfs_freebsd_debug_level = DBGC_VFS;
++
++#undef DBGC_CLASS
++#define DBGC_CLASS vfs_freebsd_debug_level
++
++#ifndef EXTATTR_MAXNAMELEN
++#define EXTATTR_MAXNAMELEN		UINT8_MAX
++#endif
++
++#define EXTATTR_NAMESPACE(NS)		EXTATTR_NAMESPACE_ ## NS, \
++					EXTATTR_NAMESPACE_ ## NS ## _STRING ".", \
++					.data.len = (sizeof(EXTATTR_NAMESPACE_ ## NS ## _STRING ".") - 1)
++
++#define EXTATTR_EMPTY			0x00
++#define EXTATTR_USER			0x01
++#define EXTATTR_SYSTEM			0x02
++#define EXTATTR_SECURITY		0x03
++#define EXTATTR_TRUSTED			0x04
++
++enum extattr_mode {
++	FREEBSD_EXTATTR_SECURE,
++	FREEBSD_EXTATTR_COMPAT,
++	FREEBSD_EXTATTR_LEGACY
++};
++
++typedef struct {
++	int namespace;
++	char name[EXTATTR_MAXNAMELEN+1];
++	union {
++		uint16_t len;
++		uint16_t flags;
++	} data;
++} extattr_attr;
++
++typedef struct {
++	enum {
++		EXTATTR_FILE, EXTATTR_LINK, EXTATTR_FDES
++	} method;
++	union {
++		const char *path;
++		int filedes;
++	} param;
++} extattr_arg;
++
++static const struct enum_list extattr_mode_param[] = {
++	{ FREEBSD_EXTATTR_SECURE, "secure" },		/*  */
++	{ FREEBSD_EXTATTR_COMPAT, "compat" },		/*  */
++	{ FREEBSD_EXTATTR_LEGACY, "legacy" },		/*  */
++	{ -1, NULL }
++};
++
++
++/* */
++struct freebsd_handle_data {
++	enum extattr_mode extattr_mode;
++};
++
++
++/* XXX: This order doesn't match namespace ids order! */
++static extattr_attr extattr[] = {
++	{ EXTATTR_NAMESPACE(EMPTY) },
++	{ EXTATTR_NAMESPACE(SYSTEM) },
++	{ EXTATTR_NAMESPACE(USER) },
++};
++
++
++static bool freebsd_in_jail(void) {
++	int val = 0;
++	size_t val_len = sizeof(val);
++
++	if((sysctlbyname("security.jail.jailed", &val, &val_len, NULL, 0) != -1) && val == 1) {
++		return true;
++	}
++	return false;
++}
++
++static uint16_t freebsd_map_attrname(const char *name)
++{
++	if(name == NULL || name[0] == '\0') {
++		return EXTATTR_EMPTY;
++	}
++
++	switch(name[0]) {
++		case 'u':
++			if(strncmp(name, "user.", 5) == 0)
++				return EXTATTR_USER;
++			break;
++		case 't':
++			if(strncmp(name, "trusted.", 8) == 0)
++				return EXTATTR_TRUSTED;
++			break;
++		case 's':
++			/* name[1] could be any character, including '\0' */
++			switch(name[1]) {
++				case 'e':
++					if(strncmp(name, "security.", 9) == 0)
++						return EXTATTR_SECURITY;
++					break;
++				case 'y':
++					if(strncmp(name, "system.", 7) == 0)
++						return EXTATTR_SYSTEM;
++					break;
++			}
++			break;
++	}
++	return EXTATTR_USER;
++}
++
++/* security, system, trusted or user */
++static extattr_attr* freebsd_map_xattr(enum extattr_mode extattr_mode, const char *name, extattr_attr *attr)
++{
++	int attrnamespace = EXTATTR_NAMESPACE_EMPTY;
++	const char *attrname = name;
++
++	if(name == NULL || name[0] == '\0') {
++		return NULL;
++	}
++
++	if(attr == NULL) {
++		return NULL;
++	}
++
++	uint16_t flags = freebsd_map_attrname(name);
++
++	switch(flags) {
++		case EXTATTR_USER:
++			attrnamespace = EXTATTR_NAMESPACE_USER;
++			if(extattr_mode == FREEBSD_EXTATTR_LEGACY)
++				attrname = name + 5;
++			break;
++		case EXTATTR_SECURITY:
++		case EXTATTR_TRUSTED:
++			attrnamespace = (extattr_mode == FREEBSD_EXTATTR_SECURE) ?
++					EXTATTR_NAMESPACE_SYSTEM :
++					EXTATTR_NAMESPACE_USER;
++			break;
++		case EXTATTR_SYSTEM:
++			attrnamespace = (extattr_mode == FREEBSD_EXTATTR_SECURE) ?
++					EXTATTR_NAMESPACE_SYSTEM :
++					EXTATTR_NAMESPACE_USER;
++			if (extattr_mode == FREEBSD_EXTATTR_LEGACY)
++				attrname = name + 7;
++			break;
++		default:
++			/* Default to "user" namespace if nothing else was specified */
++			attrnamespace = EXTATTR_NAMESPACE_USER;
++			flags = EXTATTR_USER;
++	}
++
++	attr->namespace = attrnamespace;
++	attr->data.flags = flags;
++	strlcpy(attr->name, attrname, EXTATTR_MAXNAMELEN+1);
++
++	return attr;
++}
++
++static ssize_t extattr_size(extattr_arg arg, extattr_attr *attr)
++{
++	ssize_t result;
++
++	switch(arg.method) {
++#if defined(HAVE_EXTATTR_GET_FILE)
++		case EXTATTR_FILE:
++			result = extattr_get_file(arg.param.path, attr->namespace, attr->name, NULL, 0);
++			break;
++#endif
++#if defined(HAVE_EXTATTR_GET_LINK)
++		case EXTATTR_LINK:
++			result = extattr_get_link(arg.param.path, attr->namespace, attr->name, NULL, 0);
++			break;
++#endif
++#if defined(HAVE_EXTATTR_GET_FD)
++		case EXTATTR_FDES:
++			result = extattr_get_fd(arg.param.filedes, attr->namespace, attr->name, NULL, 0);
++			break;
++#endif
++		default:
++			errno = ENOSYS;
++			return -1;
++	}
++
++	if(result < 0) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	return result;
++}
++
++
++/*
++ * The list of names is returned as an unordered array of NULL-terminated
++ * character strings (attribute names are separated by NULL characters),
++ * like this:
++ *      user.name1\0system.name1\0user.name2\0
++ *
++ * Filesystems like ext2, ext3 and XFS which implement POSIX ACLs using
++ * extended attributes, might return a list like this:
++ *      system.posix_acl_access\0system.posix_acl_default\0
++ */
++/*
++ * The extattr_list_file() returns a list of attributes present in the
++ * requested namespace. Each list entry consists of a single byte containing
++ * the length of the attribute name, followed by the attribute name. The
++ * attribute name is not terminated by ASCII 0 (nul).
++*/
++
++static ssize_t freebsd_extattr_list(extattr_arg arg, enum extattr_mode extattr_mode, char *list, size_t size)
++{
++	ssize_t list_size, total_size = 0;
++	char *p, *q, *list_end;
++	int len;
++	/*
++	 Ignore all but user namespace when we are not root or in jail
++	 See: https://bugzilla.samba.org/show_bug.cgi?id=10247
++	*/
++	bool as_root = (geteuid() == 0);
++
++	int ns = (extattr_mode == FREEBSD_EXTATTR_SECURE && as_root) ? 1 : 2;
++
++	/* Iterate through extattr(2) namespaces */
++	for(; ns < ARRAY_SIZE(extattr); ns++) {
++		switch(arg.method) {
++#if defined(HAVE_EXTATTR_LIST_FILE)
++			case EXTATTR_FILE:
++				list_size = extattr_list_file(arg.param.path, extattr[ns].namespace, list, size);
++				break;
++#endif
++#if defined(HAVE_EXTATTR_LIST_LINK)
++			case EXTATTR_LINK:
++				list_size = extattr_list_link(arg.param.path, extattr[ns].namespace, list, size);
++				break;
++#endif
++#if defined(HAVE_EXTATTR_LIST_FD)
++			case EXTATTR_FDES:
++				list_size = extattr_list_fd(arg.param.filedes, extattr[ns].namespace, list, size);
++				break;
++#endif
++			default:
++				errno = ENOSYS;
++				return -1;
++		}
++		/* Some error happend. Errno should be set by the previous call */
++		if(list_size < 0)
++			return -1;
++		/* No attributes in this namespace */
++		if(list_size == 0)
++			continue;
++		/*
++		 Call with an empty buffer may be used to calculate
++		 necessary buffer size.
++		*/
++		if(list == NULL) {
++			/*
++			 XXX: Unfortunately, we can't say, how many attributes were
++			 returned, so here is the potential problem with the emulation.
++			*/
++			if(extattr_mode == FREEBSD_EXTATTR_LEGACY) {
++				/*
++				 Take the worse case of one char attribute names -
++				 two bytes per name plus one more for sanity.
++				*/
++				total_size += list_size + (list_size/2 + 1)*extattr[ns].data.len;
++			}
++			else {
++				total_size += list_size;
++			}
++			continue;
++		}
++
++		if(extattr_mode == FREEBSD_EXTATTR_LEGACY) {
++			/* Count necessary offset to fit namespace prefixes */
++			int extra_len = 0;
++			uint16_t flags;
++			list_end = list + list_size;
++			for(list_size = 0, p = q = list; p < list_end; p += len) {
++				len = p[0] + 1;
++				(void)strlcpy(q, p + 1, len);
++				flags = freebsd_map_attrname(q);
++				/* Skip secure attributes for non-root user */
++				if(extattr_mode != FREEBSD_EXTATTR_SECURE && !as_root && flags > EXTATTR_USER) {
++					continue;
++				}
++				if(flags <= EXTATTR_USER) {
++					/* Don't count trailing '\0' */
++					extra_len += extattr[ns].data.len;
++				}
++				list_size += len;
++				q += len;
++			}
++			total_size += list_size + extra_len;
++			/* Buffer is too small to fit the results */
++			if(total_size > size) {
++				errno = ERANGE;
++				return -1;
++			}
++			/* Shift results backwards, so we can prepend prefixes */
++			list_end = list + extra_len;
++			p = (char*)memmove(list_end, list, list_size);
++			/*
++			 We enter the loop with `p` pointing to the shifted list and
++			 `extra_len` having the total margin between `list` and `p`
++			*/
++			for(list_end += list_size; p < list_end; p += len) {
++				len = strlen(p) + 1;
++				flags = freebsd_map_attrname(p);
++				if(flags <= EXTATTR_USER) {
++					/* Add namespace prefix */
++					(void)strncpy(list, extattr[ns].name, extattr[ns].data.len);
++					list += extattr[ns].data.len;
++				}
++				/* Append attribute name */
++				(void)strlcpy(list, p, len);
++				list += len;
++			}
++		}
++		else {
++			/* Convert UCSD strings into nul-terminated strings */
++			for(list_end = list + list_size; list < list_end; list += len) {
++				len = list[0] + 1;
++				(void)strlcpy(list, list + 1, len);
++			}
++			total_size += list_size;
++		}
++	}
++	return total_size;
++}
++
++/*
++static ssize_t freebsd_getxattr_size(vfs_handle_struct *handle,
++				const struct smb_filename *smb_fname,
++				const char *name)
++{
++	struct freebsd_handle_data *data;
++	extattr_arg arg = { EXTATTR_FILE, smb_fname->base_name };
++	extattr_attr attr;
++
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	return extattr_size(arg, &attr);
++}
++*/
++
++/* VFS entries */
++static ssize_t freebsd_getxattr(vfs_handle_struct *handle,
++				const struct smb_filename *smb_fname,
++				const char *name,
++				void *value,
++				size_t size)
++{
++#if defined(HAVE_EXTATTR_GET_FILE)
++	struct freebsd_handle_data *data;
++	extattr_arg arg = { EXTATTR_FILE, .param.path = smb_fname->base_name };
++	extattr_attr attr;
++	ssize_t res;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	/* Filter out 'secure' entries */
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	/*
++	 * The BSD implementation has a nasty habit of silently truncating
++	 * the returned value to the size of the buffer, so we have to check
++	 * that the buffer is large enough to fit the returned value.
++	 */
++	if((res=extattr_size(arg, &attr)) < 0) {
++		return -1;
++	}
++
++	if (size == 0) {
++		return res;
++	}
++	else if (res > size) {
++		errno = ERANGE;
++		return -1;
++	}
++
++	if((res=extattr_get_file(smb_fname->base_name, attr.namespace, attr.name, value, size)) >= 0) {
++		return res;
++	}
++	return -1;
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static ssize_t freebsd_fgetxattr(vfs_handle_struct *handle,
++			      struct files_struct *fsp, const char *name,
++			      void *value, size_t size)
++{
++#if defined(HAVE_EXTATTR_GET_FD)
++	struct freebsd_handle_data *data;
++	extattr_arg arg = { EXTATTR_FDES, .param.filedes = fsp->fh->fd };
++	extattr_attr attr;
++	ssize_t res;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	/* Filter out 'secure' entries */
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	/*
++	 * The BSD implementation has a nasty habit of silently truncating
++	 * the returned value to the size of the buffer, so we have to check
++	 * that the buffer is large enough to fit the returned value.
++	 */
++	if((res=extattr_size(arg, &attr)) < 0) {
++		return -1;
++	}
++
++	if (size == 0) {
++		return res;
++	}
++	else if (res > size) {
++		errno = ERANGE;
++		return -1;
++	}
++
++	if((res=extattr_get_fd(fsp->fh->fd, attr.namespace, attr.name, value, size)) >= 0) {
++		return res;
++	}
++	return -1;
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static ssize_t freebsd_listxattr(vfs_handle_struct *handle,
++				const struct smb_filename *smb_fname,
++				char *list,
++				size_t size)
++{
++#if defined(HAVE_EXTATTR_LIST_FILE)
++	struct freebsd_handle_data *data;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	extattr_arg arg = { EXTATTR_FILE, .param.path = smb_fname->base_name };
++
++	return freebsd_extattr_list(arg, data->extattr_mode, list, size);
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static ssize_t freebsd_flistxattr(vfs_handle_struct *handle,
++			       struct files_struct *fsp, char *list,
++			       size_t size)
++{
++#if defined(HAVE_EXTATTR_LIST_FD)
++	struct freebsd_handle_data *data;
++	extattr_arg arg = { EXTATTR_FDES, .param.filedes = fsp->fh->fd };
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	return freebsd_extattr_list(arg, data->extattr_mode, list, size);
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++static int freebsd_removexattr(vfs_handle_struct *handle,
++			const struct smb_filename *smb_fname,
++			const char *name)
++{
++#if defined(HAVE_EXTATTR_DELETE_FILE)
++	struct freebsd_handle_data *data;
++	extattr_attr attr;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++
++	/* Filter out 'secure' entries */
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	return extattr_delete_file(smb_fname->base_name, attr.namespace, attr.name);
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static int freebsd_fremovexattr(vfs_handle_struct *handle,
++			     struct files_struct *fsp, const char *name)
++{
++#if defined(HAVE_EXTATTR_DELETE_FD)
++	struct freebsd_handle_data *data;
++	extattr_attr attr;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	/* Filter out 'secure' entries */
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	return extattr_delete_fd(fsp->fh->fd, attr.namespace, attr.name);
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static int freebsd_setxattr(vfs_handle_struct *handle,
++			const struct smb_filename *smb_fname,
++			const char *name,
++			const void *value,
++			size_t size,
++			int flags)
++{
++#if defined(HAVE_EXTATTR_SET_FILE)
++	struct freebsd_handle_data *data;
++	extattr_attr attr;
++	ssize_t res;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	/* Filter out 'secure' entries */
++	if(data->extattr_mode != FREEBSD_EXTATTR_SECURE && geteuid() != 0 && attr.data.flags > EXTATTR_USER) {
++		errno = ENOATTR;
++		return -1;
++	}
++
++	if (flags) {
++		extattr_arg arg = { EXTATTR_FILE, .param.path = smb_fname->base_name };
++		/* Check attribute existence */
++		res = extattr_size(arg, &attr);
++		if (res < 0) {
++			/* REPLACE attribute, that doesn't exist */
++			if ((flags & XATTR_REPLACE) && errno == ENOATTR) {
++				errno = ENOATTR;
++				return -1;
++			}
++			/* Ignore other errors */
++		}
++		else {
++			/* CREATE attribute, that already exists */
++			if (flags & XATTR_CREATE) {
++				errno = EEXIST;
++				return -1;
++			}
++		}
++	}
++	res = extattr_set_file(smb_fname->base_name, attr.namespace, attr.name, value, size);
++
++	return (res >= 0) ? 0 : -1;
++#else
++	errno = ENOSYS;
++	return -1;
++#endif
++}
++
++
++static int freebsd_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,
++			  const char *name, const void *value, size_t size,
++			  int flags)
++{
++#if defined(HAVE_EXTATTR_SET_FD)
++	struct freebsd_handle_data *data;
++	extattr_attr attr;
++	ssize_t res;
++
++	SMB_VFS_HANDLE_GET_DATA(handle, data,
++				struct freebsd_handle_data,
++				return -1);
++
++	if(!freebsd_map_xattr(data->extattr_mode, name, &attr)) {
++		errno = EINVAL;
++		return -1;
++	}
++
++	/* Filter out 'secure' entries */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201902090036.x190aWqL040572>