git: 17ce87864be8 - main - net/samba420: Update 4.20

From: Xavier Beaudouin <kiwi_at_FreeBSD.org>
Date: Thu, 30 Jan 2025 14:44:00 UTC
The branch main has been updated by kiwi:

URL: https://cgit.FreeBSD.org/ports/commit/?id=17ce87864be8150900baa87af7d175c53a906ed9

commit 17ce87864be8150900baa87af7d175c53a906ed9
Author:     Joshua Kinard <freebsd@kumba.dev>
AuthorDate: 2025-01-28 10:07:16 +0000
Commit:     Xavier Beaudouin <kiwi@FreeBSD.org>
CommitDate: 2025-01-30 14:42:00 +0000

    net/samba420: Update 4.20
    
    Changelog:      https://wiki.samba.org/index.php/Release_Planning_for_Samba_4.20
    
    PR:             280533
    Sponsored by:   Klara, Inc.
    Approved by:    0mp (mentor)
    Approved by:    samba (0mp, kiwi)
    Co-authored-by: Xavier Beaudouin <kiwi@FreeBSD.org>
---
 net/Makefile                                       |   1 +
 net/samba420/Makefile                              |  27 +-
 net/samba420/distinfo                              |   6 +-
 ...MP-handling-code-and-add-FreeBSD-support..patch |  84 ++--
 ...869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch |  75 ++-
 ...ule-vfs_freebsd-that-implements-FreeBSD-s.patch |  47 +-
 ...s3-lib-system-add-FreeBSD-proc_fd_pattern.patch | 100 ++--
 ...0-Fix-pathref-handling-for-FreeBSD-13plus.patch | 182 --------
 ...href-handling-for-FreeBSD-13plus_samba42x.patch | 508 +++++++++++++++++++++
 ...0101-FreeBSD-add-fdescfs-paths-workaround.patch |  71 +++
 ...BSD-vfs_freebsd-fix-sys_proc_fd_path-args.patch |  53 +++
 net/samba420/pkg-plist                             | 243 +++++-----
 net/samba420/pkg-plist.ad_dc                       |  22 +-
 net/samba420/pkg-plist.cluster                     |   2 +-
 net/samba420/pkg-plist.python                      |   7 +-
 15 files changed, 913 insertions(+), 515 deletions(-)

diff --git a/net/Makefile b/net/Makefile
index 879be0f13b68..97f7b96d9abe 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -1479,6 +1479,7 @@
     SUBDIR += sakisafecli
     SUBDIR += samba416
     SUBDIR += samba419
+    SUBDIR += samba420
     SUBDIR += samplicator
     SUBDIR += savvycan
     SUBDIR += sbm
diff --git a/net/samba420/Makefile b/net/samba420/Makefile
index 92cc5bb78f0c..c32635e1f11b 100644
--- a/net/samba420/Makefile
+++ b/net/samba420/Makefile
@@ -1,6 +1,5 @@
-PORTNAME=			${SAMBA4_BASENAME}419
+PORTNAME=			${SAMBA4_BASENAME}420
 PORTVERSION=			${SAMBA4_VERSION}
-PORTREVISION=			5
 CATEGORIES?=			net
 MASTER_SITES=			SAMBA/samba/stable SAMBA/samba/rc
 DISTNAME=			${SAMBA4_DISTNAME}
@@ -45,12 +44,14 @@ EXTRA_PATCHES=			\
 				${PATCHDIR}/0026-vfs-add-a-compatibility-option-to-the-vfs_streams_xa.patch:-p1 \
 				${PATCHDIR}/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch:-p1 \
 				${PATCHDIR}/0028-Fix-rl_completion_func_t.patch:-p1 \
-				${PATCHDIR}/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch:-p1 \
-				${PATCHDIR}/0100-Fix-pathref-handling-for-FreeBSD-13plus.patch
+				${PATCHDIR}/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch \
+				${PATCHDIR}/0100-Fix-pathref-handling-for-FreeBSD-13plus_samba42x.patch:-p1 \
+				${PATCHDIR}/0101-FreeBSD-add-fdescfs-paths-workaround.patch:-p1 \
+				${PATCHDIR}/0102-FreeBSD-vfs_freebsd-fix-sys_proc_fd_path-args.patch:-p1
 
 SAMBA4_BASENAME=		samba
 SAMBA4_PORTNAME=		${SAMBA4_BASENAME}4
-SAMBA4_VERSION=			4.19.9
+SAMBA4_VERSION=			4.20.7
 SAMBA4_DISTNAME=		${SAMBA4_BASENAME}-${SAMBA4_VERSION:S|.p|pre|:S|.r|rc|:S|.t|tp|:S|.a|alpha|}
 
 WRKSRC?=			${WRKDIR}/${DISTNAME}
@@ -219,8 +220,8 @@ PLIST_SUB+=			SAMBA4_BUNDLED_TALLOC=""
 SUB_LIST+=			SAMBA4_BUNDLED_TALLOC=""
 .else
 SAMBA4_BUNDLED_LIBS+=		!talloc
-BUILD_DEPENDS+=			talloc>=2.4.1:devel/talloc
-RUN_DEPENDS+=			talloc>=2.4.1:devel/talloc
+BUILD_DEPENDS+=			talloc>=2.4.2:devel/talloc242
+RUN_DEPENDS+=			talloc>=2.4.2:devel/talloc242
 PLIST_SUB+=			SAMBA4_BUNDLED_TALLOC="@comment "
 SUB_LIST+=			SAMBA4_BUNDLED_TALLOC="@comment "
 .endif
@@ -232,8 +233,8 @@ PLIST_SUB+=			SAMBA4_BUNDLED_TEVENT=""
 SUB_LIST+=			SAMBA4_BUNDLED_TEVENT=""
 .else
 SAMBA4_BUNDLED_LIBS+=		!tevent
-BUILD_DEPENDS+=			tevent>=0.15.0:devel/tevent
-RUN_DEPENDS+=			tevent>=0.15.0:devel/tevent
+BUILD_DEPENDS+=			tevent>=0.16.1:devel/tevent016
+RUN_DEPENDS+=			tevent>=0.16.1:devel/tevent016
 PLIST_SUB+=			SAMBA4_BUNDLED_TEVENT="@comment "
 SUB_LIST+=			SAMBA4_BUNDLED_TEVENT="@comment "
 .endif
@@ -245,8 +246,8 @@ PLIST_SUB+=			SAMBA4_BUNDLED_TDB=""
 SUB_LIST+=			SAMBA4_BUNDLED_TDB=""
 .else
 SAMBA4_BUNDLED_LIBS+=		!tdb
-BUILD_DEPENDS+=			tdb>=1.4.9:databases/tdb
-RUN_DEPENDS+=			tdb>=1.4.9:databases/tdb
+BUILD_DEPENDS+=			tdb>=1.4.10:databases/tdb1410
+RUN_DEPENDS+=			tdb>=1.4.10:databases/tdb1410
 PLIST_SUB+=			SAMBA4_BUNDLED_TDB="@comment "
 SUB_LIST+=			SAMBA4_BUNDLED_TDB="@comment "
 .endif
@@ -259,8 +260,8 @@ SUB_LIST+=			SAMBA4_BUNDLED_LDB=""
 SAMBA4_MODULEDIR=		${SAMBA4_LIBDIR}/modules
 .else
 SAMBA4_BUNDLED_LIBS+=		!ldb
-BUILD_DEPENDS+=			ldb28>=2.8.1:databases/ldb28
-RUN_DEPENDS+=			ldb28>=2.8.1:databases/ldb28
+BUILD_DEPENDS+=			ldb29>=2.9.1:databases/ldb29
+RUN_DEPENDS+=			ldb29>=2.9.1:databases/ldb29
 PLIST_SUB+=			SAMBA4_BUNDLED_LDB="@comment "
 SUB_LIST+=			SAMBA4_BUNDLED_LDB="@comment "
 SAMBA4_MODULEDIR=		${PREFIX}/lib/shared-modules
diff --git a/net/samba420/distinfo b/net/samba420/distinfo
index 9cb454e7bc0c..e6dc8bc2d49f 100644
--- a/net/samba420/distinfo
+++ b/net/samba420/distinfo
@@ -1,3 +1,3 @@
-TIMESTAMP = 1729258042
-SHA256 (samba-4.19.9.tar.gz) = 71ed406444714c90bb9d36c576d807b67af15449f297e91106d42b3ca2fa5549
-SIZE (samba-4.19.9.tar.gz) = 41877221
+TIMESTAMP = 1737565689
+SHA256 (samba-4.20.7.tar.gz) = 5afe8b66e612ab1c7e57c6146adfe98ec3ea9d40dee2962a2076a3d6d6973b78
+SIZE (samba-4.20.7.tar.gz) = 42523056
diff --git a/net/samba420/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch b/net/samba420/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch
index 9c430425138f..aadb084506eb 100644
--- a/net/samba420/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch
+++ b/net/samba420/files/0022-Clean-up-UTMP-handling-code-and-add-FreeBSD-support..patch
@@ -6,14 +6,13 @@ Subject: [PATCH 22/28] Clean up UTMP handling code and add FreeBSD support.
 
 Signed-off-by: Timur I. Bakeyev <timur@FreeBSD.org>
 ---
- source3/smbd/utmp.c | 156 ++++++++++++--------------------------------
- source3/wscript     |  37 ++++++-----
- 2 files changed, 63 insertions(+), 130 deletions(-)
+ source3/smbd/utmp.c |  152 +++++++++++-------------------------------
+ source3/wscript     |   36 +++++----
+ 2 files changed, 60 insertions(+), 128 deletions(-)
 
-diff --git a/source3/smbd/utmp.c b/source3/smbd/utmp.c
-index 4327301e3b1..f4a8362dd56 100644
---- a/source3/smbd/utmp.c
-+++ b/source3/smbd/utmp.c
+diff -Naurp a/source3/smbd/utmp.c b/source3/smbd/utmp.c
+--- a/source3/smbd/utmp.c	2024-02-02 04:33:51.316490200 -0500
++++ b/source3/smbd/utmp.c	2024-08-05 12:50:57.691687000 -0400
 @@ -257,7 +257,7 @@ static char *uw_pathname(TALLOC_CTX *ctx,
   Update utmp file directly.  No subroutine interface: probably a BSD system.
  ****************************************************************************/
@@ -23,7 +22,7 @@ index 4327301e3b1..f4a8362dd56 100644
  {
  	DEBUG(1,("pututline_my: not yet implemented\n"));
  	/* BSD implementor: may want to consider (or not) adjusting "lastlog" */
-@@ -271,7 +271,7 @@ static void pututline_my(const char *uname, struct utmp *u, bool claim)
+@@ -271,7 +271,7 @@ static void pututline_my(const char *uname, struct utm
   Credit: Michail Vidiassov <master@iaas.msu.ru>
  ****************************************************************************/
  
@@ -32,7 +31,7 @@ index 4327301e3b1..f4a8362dd56 100644
  {
  	int fd;
  	struct stat buf;
-@@ -303,7 +303,7 @@ static void updwtmp_my(const char *wname, struct utmp *u, bool claim)
+@@ -303,7 +303,7 @@ static void updwtmp_my(const char *wname, struct utmp 
  	if ((fd = open(wname, O_WRONLY|O_APPEND, 0)) < 0)
  		return;
  	if (fstat(fd, &buf) == 0) {
@@ -41,7 +40,7 @@ index 4327301e3b1..f4a8362dd56 100644
  		(void) ftruncate(fd, buf.st_size);
  	}
  	(void) close(fd);
-@@ -314,12 +314,12 @@ static void updwtmp_my(const char *wname, struct utmp *u, bool claim)
+@@ -314,12 +314,12 @@ static void updwtmp_my(const char *wname, struct utmp 
   Update via utmp/wtmp (not utmpx/wtmpx).
  ****************************************************************************/
  
@@ -56,7 +55,7 @@ index 4327301e3b1..f4a8362dd56 100644
  #endif /* PUTUTLINE_RETURNS_UTMP */
  
  	uname = uw_pathname(talloc_tos(), "utmp", ut_pathname);
-@@ -376,127 +376,52 @@ static void utmp_nox_update(struct utmp *u, bool claim)
+@@ -376,127 +376,52 @@ static void utmp_nox_update(struct utmp *u, bool claim
  	}
  }
  
@@ -67,7 +66,7 @@ index 4327301e3b1..f4a8362dd56 100644
 -static void utmp_strcpy(char *dest, const char *src, size_t n)
 -{
 -	size_t len = 0;
--
+ 
 -	memset(dest, '\0', n);
 -	if (src)
 -		len = strlen(src);
@@ -78,9 +77,8 @@ index 4327301e3b1..f4a8362dd56 100644
 -			memcpy(dest, src, len);
 -	}
 -}
-+
-+
  
++
  /****************************************************************************
   Update via utmpx/wtmpx (preferred) or via utmp/wtmp.
  ****************************************************************************/
@@ -107,7 +105,8 @@ index 4327301e3b1..f4a8362dd56 100644
 -	char *uname = NULL;
 -	char *wname = NULL;
 -	struct utmpx ux, *uxrc;
--
++	STRUCT_UTMP *urc;
+ 
 -	getutmpx(u, &ux);
 -
 -#if defined(HAVE_UX_UT_SYSLEN)
@@ -124,9 +123,14 @@ index 4327301e3b1..f4a8362dd56 100644
 -	wname = uw_pathname(talloc_tos(), "wtmpx", wx_pathname);
 -	if (uname && wname) {
 -		DEBUG(2,("utmp_update: uname:%s wname:%s\n", uname, wname));
--	}
-+	STRUCT_UTMP *urc;
- 
++	setutxent();
++	urc = pututxline(u);
++	endutxent();
++	if (urc == NULL) {
++		DEBUG(2,("utmp_update: pututxline() failed\n"));
++		return;
+ 	}
+-
 -	/*
 -	 * Check for either uname or wname being empty.
 -	 * Some systems, such as Redhat 6, have a "utmpx.h" which doesn't
@@ -146,13 +150,7 @@ index 4327301e3b1..f4a8362dd56 100644
 -			return;
 -		}
 -		updwtmpx(wname, &ux);
-+	setutxent();
-+	urc = pututxline(u);
-+	endutxent();
-+	if (urc == NULL) {
-+		DEBUG(2,("utmp_update: pututxline() failed\n"));
-+		return;
- 	}
+-	}
 -#endif /* HAVE_UTMPX_H */
  }
  
@@ -173,7 +171,12 @@ index 4327301e3b1..f4a8362dd56 100644
 - * Example: digits would produce the base-10 numbers from '001'.
 - */
 -	nbase = strlen(ut_id_encstr);
--
++	int nbase = sizeof(ut_id_encstr) - 1;
++	/*
++	 * 'ut_id_encstr' is the character set on which modulo arithmetic is done.
++	 * Example: digits would produce the base-10 numbers from '001'.
++	 */
+ 
 -	fourbyte[0] = ut_id_encstr[i % nbase];
 -	i /= nbase;
 -	fourbyte[1] = ut_id_encstr[i % nbase];
@@ -185,12 +188,6 @@ index 4327301e3b1..f4a8362dd56 100644
 -
 -	/* we do not care about overflows as i is a random number */
 -	return 0;
-+	int nbase = sizeof(ut_id_encstr) - 1;
-+	/*
-+	 * 'ut_id_encstr' is the character set on which modulo arithmetic is done.
-+	 * Example: digits would produce the base-10 numbers from '001'.
-+	 */
-+
 +	for(int i = 0; i < buf_size; i++) {
 +		buf[i] = ut_id_encstr[id % nbase];
 +		id /= nbase;
@@ -244,9 +241,9 @@ index 4327301e3b1..f4a8362dd56 100644
 +		strncpy(u->ut_host, hostname, sizeof(u->ut_host));
 +#if defined(HAVE_UT_UT_SYSLEN)
 +		u->ut_syslen = strlen(hostname) + 1;	/* include trailing NULL */
-+#endif
-+	}
  #endif
++	}
++#endif
  
  #if defined(HAVE_UT_UT_ID)
 -	if (ut_id_encode(id_num, u->ut_id) != 0) {
@@ -257,7 +254,7 @@ index 4327301e3b1..f4a8362dd56 100644
  #endif
  
  	return True;
-@@ -561,7 +489,7 @@ static bool sys_utmp_fill(struct utmp *u,
+@@ -561,7 +489,7 @@ void sys_utmp_yield(const char *username, const char *
  void sys_utmp_yield(const char *username, const char *hostname,
  		    const char *id_str, int id_num)
  {
@@ -266,7 +263,7 @@ index 4327301e3b1..f4a8362dd56 100644
  
  	ZERO_STRUCT(u);
  
-@@ -587,7 +515,7 @@ void sys_utmp_yield(const char *username, const char *hostname,
+@@ -587,7 +515,7 @@ void sys_utmp_claim(const char *username, const char *
  void sys_utmp_claim(const char *username, const char *hostname,
  		    const char *id_str, int id_num)
  {
@@ -275,16 +272,15 @@ index 4327301e3b1..f4a8362dd56 100644
  
  	ZERO_STRUCT(u);
  
-diff --git a/source3/wscript b/source3/wscript
-index 6209472c6c8..65961851e17 100644
---- a/source3/wscript
-+++ b/source3/wscript
-@@ -807,34 +807,39 @@ msg.msg_accrightslen = sizeof(fd);
+diff -Naurp a/source3/wscript b/source3/wscript
+--- a/source3/wscript	2024-08-05 12:50:16.286549000 -0400
++++ b/source3/wscript	2024-08-05 13:02:31.909769000 -0400
+@@ -804,34 +804,38 @@ msg.msg_accrightslen = sizeof(fd);
  
      if Options.options.with_utmp:
          conf.env.with_utmp = True
 -        if not conf.CHECK_HEADERS('utmp.h'): conf.env.with_utmp = False
--        conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx getutxent')
+-        conf.CHECK_FUNCS('pututline pututxline updwtmp updwtmpx getutmpx')
 -        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_name', headers='utmp.h',
 +        if not conf.CHECK_HEADERS('utmpx.h') and not conf.CHECK_HEADERS('utmp.h'):
 +            conf.env.with_utmp = False
@@ -297,7 +293,6 @@ index 6209472c6c8..65961851e17 100644
 +        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_name', headers='utmpx.h utmp.h',
                                      define='HAVE_UT_UT_NAME')
 -        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_user', headers='utmp.h',
-+
 +        conf.CHECK_STRUCTURE_MEMBER('STRUCT_UTMP', 'ut_user', headers='utmpx.h utmp.h',
                                      define='HAVE_UT_UT_USER')
 -        conf.CHECK_STRUCTURE_MEMBER('struct utmp', 'ut_id', headers='utmp.h',
@@ -335,6 +330,3 @@ index 6209472c6c8..65961851e17 100644
                            define='SIZEOF_UTMP_UT_LINE', critical=False)
          if not conf.CONFIG_SET('SIZEOF_UTMP_UT_LINE'):
              conf.env.with_utmp = False
--- 
-2.37.1
-
diff --git a/net/samba420/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch b/net/samba420/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch
index b66e24b27910..064eeb0cfa48 100644
--- a/net/samba420/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch
+++ b/net/samba420/files/0025-From-d9b748869a8f4018ebee302aae8246bf29f60309-Mon-Se.patch
@@ -15,15 +15,14 @@ FreeBSD Bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=228462
 Signed-off-by: Ralph Boehme <slow@samba.org>
 Signed-off-by: Timur I. Bakeyev <timur@FreeBSD.org>
 ---
- source3/lib/adouble.c       | 20 ++++++++++++++++----
- source3/modules/vfs_fruit.c | 19 ++++++++++++++++++-
- 2 files changed, 34 insertions(+), 5 deletions(-)
+ source3/lib/adouble.c       |   19 +++++++++++++++----
+ source3/modules/vfs_fruit.c |   19 ++++++++++++++++++-
+ 2 files changed, 33 insertions(+), 5 deletions(-)
 
-diff --git a/source3/lib/adouble.c b/source3/lib/adouble.c
-index aa78007dadd..ca99dcff193 100644
---- a/source3/lib/adouble.c
-+++ b/source3/lib/adouble.c
-@@ -2830,6 +2830,8 @@ ssize_t afpinfo_pack(const AfpInfo *ai, char *buf)
+diff -Naurp a/source3/lib/adouble.c b/source3/lib/adouble.c
+--- a/source3/lib/adouble.c	2024-02-02 04:33:51.172489400 -0500
++++ b/source3/lib/adouble.c	2024-08-05 13:53:43.952688000 -0400
+@@ -2821,6 +2821,8 @@ ssize_t afpinfo_pack(const AfpInfo *ai, char *buf)
  	return AFP_INFO_SIZE;
  }
  
@@ -32,38 +31,35 @@ index aa78007dadd..ca99dcff193 100644
  /**
   * Unpack a buffer into a AfpInfo structure
   *
-@@ -2847,12 +2849,22 @@ AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data)
- 	ai->afpi_Version = RIVAL(data, 4);
- 	ai->afpi_BackupTime = RIVAL(data, 12);
- 	memcpy(ai->afpi_FinderInfo, (const char *)data + 16,
--	       sizeof(ai->afpi_FinderInfo));
-+		sizeof(ai->afpi_FinderInfo));
+@@ -2841,11 +2843,20 @@ AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *d
+ 	       sizeof(ai->afpi_FinderInfo));
+ 
+ 	if (validate) {
+-		if (ai->afpi_Signature != AFP_Signature
+-		    || ai->afpi_Version != AFP_Version)
+-		{
+-			DEBUG(1, ("Bad AfpInfo signature or version\n"));
++		if (ai->afpi_Signature != AFP_Signature) {
++			DBG_WARNING("Bad AFP signature [%x]\n", ai->afpi_Signature);
 +
-+	if (ai->afpi_Signature != AFP_Signature) {
-+		DBG_WARNING("Bad AFP signature [%x]\n", ai->afpi_Signature);
++			if (ai->afpi_Signature != BROKEN_FREEBSD_AFP_Signature) {
++				DBG_ERR("Bad AfpInfo signature\n");
++				TALLOC_FREE(ai);
++				return NULL;
++			}
++		}
 +
-+		if (ai->afpi_Signature != BROKEN_FREEBSD_AFP_Signature) {
-+			DBG_ERR("Bad AfpInfo signature\n");
-+			TALLOC_FREE(ai);
++		if (ai->afpi_Version != AFP_Version) {
++			DBG_ERR("Bad AfpInfo version\n");
+ 			TALLOC_FREE(ai);
 +			return NULL;
-+		}
-+	}
- 
--	if (ai->afpi_Signature != AFP_Signature
--	    || ai->afpi_Version != AFP_Version) {
--		DEBUG(1, ("Bad AfpInfo signature or version\n"));
-+	if (ai->afpi_Version != AFP_Version) {
-+		DBG_ERR("Bad AfpInfo version\n");
- 		TALLOC_FREE(ai);
-+		return NULL;
- 	}
- 
- 	return ai;
-diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
-index 303df41258e..428f95fd7d9 100644
---- a/source3/modules/vfs_fruit.c
-+++ b/source3/modules/vfs_fruit.c
-@@ -2300,6 +2300,7 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_struct *handle,
+ 		}
+ 	} else {
+ 		ai->afpi_Signature = AFP_Signature;
+diff -Naurp a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
+--- a/source3/modules/vfs_fruit.c	2024-02-02 04:33:51.228489600 -0500
++++ b/source3/modules/vfs_fruit.c	2024-08-05 13:12:29.220129000 -0400
+@@ -2305,6 +2305,7 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_stru
  				       size_t n, off_t offset)
  {
  	struct fio *fio = fruit_get_complete_fio(handle, fsp);
@@ -71,7 +67,7 @@ index 303df41258e..428f95fd7d9 100644
  	ssize_t nread;
  	int ret;
  
-@@ -2308,7 +2309,23 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_struct *handle,
+@@ -2313,7 +2314,23 @@ static ssize_t fruit_pread_meta_stream(vfs_handle_stru
  	}
  
  	nread = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
@@ -96,6 +92,3 @@ index 303df41258e..428f95fd7d9 100644
  		return nread;
  	}
  
--- 
-2.37.1
-
diff --git a/net/samba420/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch b/net/samba420/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch
index 109b3eb82c79..f2dd827cabba 100644
--- a/net/samba420/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch
+++ b/net/samba420/files/0027-Add-VFS-module-vfs_freebsd-that-implements-FreeBSD-s.patch
@@ -9,19 +9,15 @@ FreeBSD extended attributes.
 
 Signed-off-by: Timur I. Bakeyev <timur@FreeBSD.org>
 ---
- docs-xml/manpages/vfs_freebsd.8.xml | 169 +++++++
- docs-xml/wscript_build              |   1 +
- source3/modules/vfs_freebsd.c       | 699 ++++++++++++++++++++++++++++
- source3/modules/wscript_build       |   7 +
+ docs-xml/manpages/vfs_freebsd.8.xml |  169 ++++++
+ docs-xml/wscript_build              |    1
+ source3/modules/vfs_freebsd.c       |  699 ++++++++++++++++++++++++++
+ source3/modules/wscript_build       |    7
  4 files changed, 876 insertions(+)
- create mode 100644 docs-xml/manpages/vfs_freebsd.8.xml
- create mode 100644 source3/modules/vfs_freebsd.c
 
-diff --git a/docs-xml/manpages/vfs_freebsd.8.xml b/docs-xml/manpages/vfs_freebsd.8.xml
-new file mode 100644
-index 00000000000..6640a1c51f7
---- /dev/null
-+++ b/docs-xml/manpages/vfs_freebsd.8.xml
+diff -Naurp a/docs-xml/manpages/vfs_freebsd.8.xml b/docs-xml/manpages/vfs_freebsd.8.xml
+--- a/docs-xml/manpages/vfs_freebsd.8.xml	1969-12-31 19:00:00.000000000 -0500
++++ b/docs-xml/manpages/vfs_freebsd.8.xml	2024-08-05 13:57:36.246690000 -0400
 @@ -0,0 +1,169 @@
 +<?xml version="1.0" encoding="iso-8859-1"?>
 +<!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
@@ -192,11 +188,10 @@ index 00000000000..6640a1c51f7
 +</refsect1>
 +
 +</refentry>
-diff --git a/docs-xml/wscript_build b/docs-xml/wscript_build
-index c8c4b68e514..4dc4b34ca40 100644
---- a/docs-xml/wscript_build
-+++ b/docs-xml/wscript_build
-@@ -86,6 +86,7 @@ vfs_module_manpages = ['vfs_acl_tdb',
+diff -Naurp a/docs-xml/wscript_build b/docs-xml/wscript_build
+--- a/docs-xml/wscript_build	2024-08-02 07:54:09.597892000 -0400
++++ b/docs-xml/wscript_build	2024-08-05 13:57:36.246975000 -0400
+@@ -87,6 +87,7 @@ vfs_module_manpages = ['vfs_acl_tdb',
                         'vfs_extd_audit',
                         'vfs_fake_perms',
                         'vfs_fileid',
@@ -204,11 +199,9 @@ index c8c4b68e514..4dc4b34ca40 100644
                         'vfs_fruit',
                         'vfs_full_audit',
                         'vfs_glusterfs',
-diff --git a/source3/modules/vfs_freebsd.c b/source3/modules/vfs_freebsd.c
-new file mode 100644
-index 00000000000..07d26d9c516
---- /dev/null
-+++ b/source3/modules/vfs_freebsd.c
+diff -Naurp a/source3/modules/vfs_freebsd.c b/source3/modules/vfs_freebsd.c
+--- a/source3/modules/vfs_freebsd.c	1969-12-31 19:00:00.000000000 -0500
++++ b/source3/modules/vfs_freebsd.c	2024-08-05 13:57:36.247358000 -0400
 @@ -0,0 +1,699 @@
 +/*
 + * This module implements VFS calls specific to FreeBSD
@@ -909,11 +902,10 @@ index 00000000000..07d26d9c516
 +
 +	return ret;
 +}
-diff --git a/source3/modules/wscript_build b/source3/modules/wscript_build
-index ff318c3fa06..f88d054d524 100644
---- a/source3/modules/wscript_build
-+++ b/source3/modules/wscript_build
-@@ -636,6 +636,13 @@ bld.SAMBA3_MODULE('vfs_delay_inject',
+diff -Naurp a/source3/modules/wscript_build b/source3/modules/wscript_build
+--- a/source3/modules/wscript_build	2024-02-02 04:33:51.236489800 -0500
++++ b/source3/modules/wscript_build	2024-08-05 13:57:36.247658000 -0400
+@@ -631,6 +631,13 @@ bld.SAMBA3_MODULE('vfs_delay_inject',
                   enabled=bld.SAMBA3_IS_ENABLED_MODULE('vfs_delay_inject'),
                   install=False)
  
@@ -927,6 +919,3 @@ index ff318c3fa06..f88d054d524 100644
  bld.SAMBA3_MODULE('vfs_widelinks',
                   subsystem='vfs',
                   source='vfs_widelinks.c',
--- 
-2.37.1
-
diff --git a/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch b/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch
index be1aedaa4473..cda9c7ed1c95 100644
--- a/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch
+++ b/net/samba420/files/0028-s3-lib-system-add-FreeBSD-proc_fd_pattern.patch
@@ -1,35 +1,14 @@
-From 584c69e77abb537a7345222648a397a9963c01b7 Mon Sep 17 00:00:00 2001
-From: "Timur I. Bakeyev" <timur@FreeBSD.org>
-Date: Sat, 15 Oct 2022 04:02:43 +0200
-Subject: [PATCH 28/28] s3:lib:system - add FreeBSD proc_fd_pattern
-
-Add support for FreeBSD equivalent of /proc/self/fd through a special
-fdescfs mount with option "nodup". This filesystem should be mounted
-either to the private $PIDDIR/fd/ directory or to /dev/fd in order to
-provide security and performance characteristics similar to Linux.
-
-Signed-off-by: Timur I. Bakeyev <timur@FreeBSD.org>
----
- source3/lib/system.c | 108 ++++++++++++++++++++++++++++++++++---------
- 1 file changed, 87 insertions(+), 21 deletions(-)
-
-diff --git a/source3/lib/system.c b/source3/lib/system.c
-index 00d31692e00..d22ec08361c 100644
---- a/source3/lib/system.c
-+++ b/source3/lib/system.c
-@@ -1094,39 +1094,105 @@ int sys_get_number_of_cores(void)
+--- source3/lib/system.c.orig	2024-02-02 10:33:51.188489400 +0100
++++ source3/lib/system.c	2025-01-22 17:39:58.625028000 +0100
+@@ -1047,22 +1047,108 @@
  }
  #endif
  
--static struct proc_fd_pattern {
--	const char *pattern;
--	const char *test_path;
--} proc_fd_patterns[] = {
--	/* Linux */
--	{ "/proc/self/fd/%d", "/proc/self/fd/0" },
--	{ NULL, NULL },
+-bool sys_have_proc_fds(void)
 +static bool freebsd_fdesc_check(const char *pattern)
-+{
+ {
+-	static bool checked = false;
+-	static bool have_proc_fds = false;
 +	char fdesc_path[PATH_MAX];
 +	int fd, fd2;
 +
@@ -74,16 +53,22 @@ index 00d31692e00..d22ec08361c 100644
 +{
 +	char proc_fd_path[PATH_MAX];
 +	const char *pattern = "/proc/self/fd/%lu";
-+	struct stat sb;
-+
+ 	struct stat sb;
+-	int ret;
+ 
+-	if (checked) {
+-		return have_proc_fds;
 +	snprintf(proc_fd_path, sizeof(proc_fd_path), pattern, 0);
 +	if(stat(proc_fd_path, &sb) == 0) {
 +		snprintf(buf, bufsize, "%s", pattern);
 +		return buf;
-+	}
+ 	}
 +	return NULL;
 +}
-+
+ 
+-	ret = stat("/proc/self/fd/0", &sb);
+-	have_proc_fds = (ret == 0);
+-	checked = true;
 +static char* freebsd_pattern(char *buf, size_t bufsize) {
 +	const char** base;
 +	const char* base_dir[] = {
@@ -91,7 +76,8 @@ index 00d31692e00..d22ec08361c 100644
 +		"/dev",
 +		NULL
 +	};
-+
+ 
+-	return have_proc_fds;
 +	for(base = &base_dir[0]; *base != NULL; base++) {
 +		snprintf(buf, bufsize, "%s/fd/%%lu", *base);
 +		if(freebsd_fdesc_check(buf)) {
@@ -105,45 +91,31 @@ index 00d31692e00..d22ec08361c 100644
 +	linux_pattern,
 +	freebsd_pattern,
 +	NULL
- };
- 
--static const char *proc_fd_pattern;
++};
++ 
 +static char proc_fd_pattern_buf[PATH_MAX];
 +static const char *proc_fd_pattern = NULL;
- 
- bool sys_have_proc_fds(void)
- {
--	static bool checked;
--	static bool have_proc_fds;
--	struct proc_fd_pattern *p = NULL;
--	struct stat sb;
--	int ret;
++ 
++bool sys_have_proc_fds(void)
++{
 +	static bool checked = false;
 +	static bool have_proc_fds = false;
 +	char* (**pattern_func)(char *, size_t) = NULL;
- 
- 	if (checked) {
- 		return have_proc_fds;
- 	}
- 
--	for (p = &proc_fd_patterns[0]; p->test_path != NULL; p++) {
--		ret = stat(p->test_path, &sb);
--		if (ret != 0) {
--			continue;
++ 
++ 	if (checked) {
++ 		return have_proc_fds;
++ 	}
++ 
 +	for (pattern_func = &proc_fd_patterns[0]; *pattern_func != NULL; pattern_func++) {
 +		if((*pattern_func)(proc_fd_pattern_buf, sizeof(proc_fd_pattern_buf)) != NULL) {
 +			have_proc_fds = true;
 +			proc_fd_pattern = proc_fd_pattern_buf;
 +			break;
- 		}
--		have_proc_fds = true;
--		proc_fd_pattern = p->pattern;
--		break;
- 	}
--
- 	checked = true;
- 	return have_proc_fds;
++ 		}
++ 	}
++
++ 	checked = true;
++ 	return have_proc_fds;
  }
--- 
-2.37.1
-
+ 
+ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf)
diff --git a/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus.patch b/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus.patch
deleted file mode 100644
index 601a1c1c79d8..000000000000
--- a/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus.patch
+++ /dev/null
@@ -1,182 +0,0 @@
-https://bugzilla.samba.org/show_bug.cgi?id=15376
-
---- source3/modules/vfs_zfsacl.c	2023-11-27 13:09:10.612012900 +0100
-+++ source3/modules/vfs_zfsacl.c	2025-01-07 18:53:05.292522000 +0100
-@@ -169,6 +169,7 @@ 
- 	bool must_add_empty_ace = false;
- 	struct zfsacl_config_data *config = NULL;
- 	int fd;
-+	char buf[PATH_MAX];
- 
- 	SMB_VFS_HANDLE_GET_DATA(handle, config,
- 				struct zfsacl_config_data,
-@@ -235,22 +236,49 @@ 
- 	SMB_ASSERT(i == naces);
- 
- 	/* store acl */
--	fd = fsp_get_pathref_fd(fsp);
--	if (fd == -1) {
-+	if (!fsp->fsp_flags.is_pathref) {
-+	    fd = fsp_get_io_fd(fsp);
-+	    
-+	    rv = facl(fd, ACE_SETACL, naces, acebuf);
-+	    if (rv != 0) {
-+		DEBUG(8, ("zfs_process_smbacl(%s): Not PATHREF: facl(ACE_SETACL, %d): %s\n",
-+			  fsp_str_dbg(fsp), naces,
-+			  strerror(errno)));
-+		return false;
-+	    }
-+	    DEBUG(10, ("zfs_process_smbacl(%s): Not PATHREF: facl(ACE_SETACL, %d) -> %d\n",
-+		      fsp_str_dbg(fsp), naces,
-+		      rv));
-+	    
-+	} else if (fsp->fsp_flags.have_proc_fds) {
-+	    fd = fsp_get_pathref_fd(fsp);
-+	    if (fd == -1) {
-+		DEBUG(8, ("zfs_process_smbacl(%s): PATHREF(proc_fd): fsp_get_pathref_fd=-1: %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
- 		errno = EBADF;
- 		return false;
--	}
--	rv = facl(fd, ACE_SETACL, naces, acebuf);
--	if (rv != 0) {
--		if(errno == ENOSYS) {
--			DEBUG(9, ("acl(ACE_SETACL, %s): Operation is not "
--				  "supported on the filesystem where the file "
--				  "reside", fsp_str_dbg(fsp)));
--		} else {
--			DEBUG(9, ("acl(ACE_SETACL, %s): %s ", fsp_str_dbg(fsp),
--				  strerror(errno)));
--		}
-+	    }
-+	    rv = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_SETACL, naces, acebuf);
-+	    if (rv != 0) {
-+		DEBUG(8, ("zfs_process_smbacl(%s): acl(ACE_SETACL, %d): %s\n",
-+			  fsp_str_dbg(fsp), naces,
-+			  strerror(errno)));
- 		return false;
-+	    }
-+	    DEBUG(10, ("zfs_process_smbacl(%s): PATHREF(proc_fd): acl(ACE_SETACL, %d) -> %d\n",
-+		      fsp_str_dbg(fsp), naces,
-+		      rv));
-+	} else {
-+	    rv = acl(fsp->fsp_name->base_name, ACE_SETACL, naces, acebuf);
-+	    if (rv != 0) {
-+		DEBUG(8, ("zfs_process_smbacl(%s): PATHREF(base_name): acl(ACE_SETACL, %d): %s\n",
-+			  fsp_str_dbg(fsp), naces,
-+			  strerror(errno)));
-+		return false;
-+	    }
-+	    DEBUG(10, ("zfs_process_smbacl(%s): PATHREF(base_name): facl(ACE_SETACL, %d) -> %d\n",
-+		      fsp_str_dbg(fsp), naces,
-+		      rv));
- 	}
- 
- 	return True;
-@@ -282,25 +310,48 @@ 
- 		       struct files_struct *fsp,
- 		       ace_t **outbuf)
- {
--	int naces, rv;
-+	int naces, rv = -1, fd = -1;
- 	ace_t *acebuf = NULL;
--	int fd;
- 
--	fd = fsp_get_pathref_fd(fsp);
--	if (fd == -1) {
-+
-+	char buf[PATH_MAX];
-+
-+
-+	if (!fsp->fsp_flags.is_pathref) {
-+	    fd = fsp_get_io_fd(fsp);
-+	    if (fd == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: fsp_get_io_fd=-1: %s\n",
-+				  fsp_str_dbg(fsp), strerror(errno)));
- 		errno = EBADF;
- 		return -1;
--	}
--	naces = facl(fd, ACE_GETACLCNT, 0, NULL);
--	if (naces == -1) {
--		int dbg_level = 10;
--
--		if (errno == ENOSYS) {
--			dbg_level = 1;
--		}
--		DEBUG(dbg_level, ("facl(ACE_GETACLCNT, %s): %s ",
-+	    }
-+	    naces = facl(fd, ACE_GETACLCNT, 0, NULL);
-+	    if (naces == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACLCNT): %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
-+		return -1;
-+	    }
-+	} else if (fsp->fsp_flags.have_proc_fds) {
-+	    fd = fsp_get_pathref_fd(fsp);
-+	    if (fd == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): fsp_get_pathref_fd=-1: %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
-+		errno = EBADF;
-+		return -1;
-+	    }
-+	    naces = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_GETACLCNT, 0, NULL);
-+	    if (naces == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACLCNT): %s\n",
- 				  fsp_str_dbg(fsp), strerror(errno)));
--		return naces;
-+		return -1;
-+	    }
-+	} else {
-+	    naces = acl(fsp->fsp_name->base_name, ACE_GETACLCNT, 0, NULL);
-+	    if (naces == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACLCNT): %s\n",
-+				  fsp_str_dbg(fsp), strerror(errno)));
-+		return -1;
-+	    }
- 	}
- 
- 	acebuf = talloc_size(mem_ctx, sizeof(ace_t)*naces);
-@@ -309,15 +360,37 @@ 
- 		return -1;
- 	}
- 
--	rv = facl(fd, ACE_GETACL, naces, acebuf);
--	if (rv == -1) {
--		DBG_DEBUG("acl(ACE_GETACL, %s): %s ",
--			  fsp_str_dbg(fsp), strerror(errno));
-+	if (!fsp->fsp_flags.is_pathref) {
-+	    rv = facl(fd, ACE_GETACL, naces, acebuf);
-+	    if (rv == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACL): %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
- 		return -1;
-+	    }
-+	    DEBUG(10, ("fget_zfsacl(%s): Not PATHREF: facl(ACE_GETACL) -> %d entries\n",
-+		      fsp_str_dbg(fsp), rv));
-+	} else if (fsp->fsp_flags.have_proc_fds) {
-+	    rv = acl(sys_proc_fd_path(fd, buf, sizeof(buf)), ACE_GETACL, naces, acebuf);
-+	    if (rv == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACL): %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
-+		return -1;
-+	    }
-+	    DEBUG(10, ("fget_zfsacl(%s): PATHREF(proc_fd): acl(ACE_GETACL) -> %d entries\n",
-+		      fsp_str_dbg(fsp), rv));
-+	} else {
-+	    rv = acl(fsp->fsp_name->base_name, ACE_GETACL, naces, acebuf);
-+	    if (rv == -1) {
-+		DEBUG(8, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACL): %s\n",
-+			  fsp_str_dbg(fsp), strerror(errno)));
-+		return -1;
-+	    }
-+	    DEBUG(10, ("fget_zfsacl(%s): PATHREF(base_name): acl(ACE_GETACL) -> %d entries\n",
-+		      fsp_str_dbg(fsp), rv));
- 	}
--
-+
- 	*outbuf = acebuf;
--	return naces;
-+	return rv;
- }
- 
- static NTSTATUS zfsacl_fget_nt_acl(struct vfs_handle_struct *handle,
diff --git a/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus_samba42x.patch b/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus_samba42x.patch
new file mode 100644
index 000000000000..3e2a44d1acab
--- /dev/null
+++ b/net/samba420/files/0100-Fix-pathref-handling-for-FreeBSD-13plus_samba42x.patch
@@ -0,0 +1,508 @@
+https://bugzilla.samba.org/show_bug.cgi?id=15376
+
+# 2024-08-05
+# NOTE: Patch is partially split apart from the copy in net/samba419 due to Samba upstream
+#	making some Linux-specific changes.  FreeBSD-specific linprocfs mount path bits are
+#	moved to a separate patch due to upstream hardcoding the Linux-specific procfs
+#	path in multiple places in commit 9f63fad392f3:
+#	https://git.samba.org/?p=samba.git;a=commitdiff;h=9f63fad392f3cff34d6a8e318e0427499170c417
+
+diff -Naurp a/source3/include/proto.h b/source3/include/proto.h
+--- a/source3/include/proto.h	2024-02-02 04:33:51.168489200 -0500
++++ b/source3/include/proto.h	2024-08-05 21:25:56.723092000 -0400
+@@ -211,6 +211,10 @@ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path
+ bool sys_have_proc_fds(void);
+ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path_buf *buf);
+ 
++int sys_open_real_fd_from_pathref_fd(int fd,
++				     int *mfd,
++				     int flags);
++
+ struct stat;
+ void init_stat_ex_from_stat (struct stat_ex *dst,
+ 			    const struct stat *src,
+diff -Naurp a/source3/lib/system.c b/source3/lib/system.c
+--- a/source3/lib/system.c	2024-02-02 04:33:51.188489400 -0500
++++ b/source3/lib/system.c	2024-08-05 21:25:56.723571000 -0400
+@@ -1074,3 +1074,23 @@ char *sys_proc_fd_path(int fd, struct sys_proc_fd_path
+ 
+ 	return buf->buf;
+ }
++
++/* Helper function that opens a usable fd for accessing data
++   (metadata & content) from a pathref fd */
++int sys_open_real_fd_from_pathref_fd(int fd, int *rfd, int flags)
++{
++	int tfd;
++
++#if defined(HAVE_OPENAT) && defined(O_EMPTY_PATH)
++	/* This works for FreeBSD 13+ atleast */
++	tfd = openat(fd, "", O_EMPTY_PATH|flags);
++	if (tfd < 0) {
++		return errno;
++	}
++
++	*rfd = tfd;
++	return 0;
++#else
++	return ENOSYS;
++#endif
++}
+diff -Naurp a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
+--- a/source3/modules/vfs_default.c	2024-08-02 07:54:09.629892300 -0400
++++ b/source3/modules/vfs_default.c	2024-08-05 21:25:56.724593000 -0400
+@@ -2688,7 +2688,7 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, f
+ 
+ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
+ {
+-	int result;
++	int result, fd, real_fd;
+ 
+ 	START_PROFILE(syscall_fchmod);
+ 
+@@ -2698,8 +2698,9 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, f
+ 		return result;
+ 	}
+ 
++	fd = fsp_get_pathref_fd(fsp);
++
+ 	if (fsp->fsp_flags.have_proc_fds) {
+-		int fd = fsp_get_pathref_fd(fsp);
+ 		struct sys_proc_fd_path_buf buf;
+ 
+ 		result = chmod(sys_proc_fd_path(fd, &buf), mode);
+@@ -2708,6 +2709,17 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, f
+ 		return result;
+ 	}
+ 
++	if (sys_open_real_fd_from_pathref_fd(fd, &real_fd, O_RDONLY|O_NONBLOCK) == 0) {
++		int saved_errno;
++
++		result = fchmod(real_fd, mode);
++		saved_errno = errno;
++		close(real_fd);
++		errno = saved_errno;
++		END_PROFILE(syscall_fchmod);
++		return result;
++	}
++
+ 	/*
+ 	 * This is no longer a handle based call.
+ 	 */
+@@ -2720,7 +2732,7 @@ static int vfswrap_fchown(vfs_handle_struct *handle, f
+ static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid)
+ {
+ #ifdef HAVE_FCHOWN
+-	int result;
++	int result, fd, real_fd;
+ 
+ 	START_PROFILE(syscall_fchown);
+ 	if (!fsp->fsp_flags.is_pathref) {
+@@ -2729,8 +2741,9 @@ static int vfswrap_fchown(vfs_handle_struct *handle, f
*** 951 LINES SKIPPED ***