[SCM] Samba Shared Repository - branch v4-7-test updated

Karolin Seeger kseeger at samba.org
Mon Aug 14 12:36:03 UTC 2017


The branch, v4-7-test has been updated
       via  11a6fd3 source3/client: Fix typo in help message displayed by default
       via  d7ab149 vfs_fruit: factor out common code from ad_get() and ad_fget()
       via  67649b7 vfs_fruit: return fake pipe fd in fruit_open_meta_netatalk()
       via  6f00dc7 vfs_fruit: don't open basefile in ad_open() and simplify API
       via  dafa192 vfs_fruit: use path based setxattr call in ad_fset()
       via  4a742a6 s4/torture: additional tests for kernel-oplocks
       via  60a551e s4/torture: reproducer for kernel oplocks issue with streams
       via  a89dca2 vfs_streams_xattr: return a fake fd in streams_xattr_open()
       via  715bae3 vfs_streams_xattr: implement all missing handle based VFS functions
       via  577a3c1 vfs_streams_xattr: always pass NULL as fsp arg to get_ea_value()
       via  cc0ada5 vfs_streams_xattr: remove fsp argument from get_xattr_size()
       via  2987e49 vfs_streams_xattr: remove all uses of fd, use name based functions
       via  a0727ee vfs_streams_xattr: invalidate stat info if xattr was not found
       via  ca32a25 s3: torture: Add a test for cli_setpathinfo_basic() to smbtorture3.
       via  4cc812b s3: libsmb: Implement cli_smb2_setatr() by calling cli_smb2_setpathinfo().
       via  a899335 s3: libsmb: Add cli_smb2_setpathinfo(), to be called by cli_setpathinfo_basic().
       via  527d1aa s3: libsmbclient: Fix cli_setpathinfo_basic() to treat mode == -1 as no change.
      from  53643ac vfs_gpfs: handle EACCES when fetching DOS attributes from xattr

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-7-test


- Log -----------------------------------------------------------------
commit 11a6fd32c36ff7159445a871fd97b3b80d1f7ae6
Author: Anoop C S <anoopcs at redhat.com>
Date:   Mon Jul 31 15:39:19 2017 +0530

    source3/client: Fix typo in help message displayed by default
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12936
    
    Signed-off-by: Anoop C S <anoopcs at redhat.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit 90487259e365d5b966ccc47ac51eadb4733f3197)
    
    Autobuild-User(v4-7-test): Karolin Seeger <kseeger at samba.org>
    Autobuild-Date(v4-7-test): Mon Aug 14 14:35:34 CEST 2017 on sn-devel-144

commit d7ab149b68d84ed58cd69af607c451e5c70feebd
Author: Ralph Boehme <slow at samba.org>
Date:   Wed May 24 09:17:19 2017 +0200

    vfs_fruit: factor out common code from ad_get() and ad_fget()
    
    As a result of the previous changes ad_get() and ad_fget() do completey
    the same, so factor out the common code to a new helper function. No
    change in behaviour.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Wed Aug  9 22:33:36 CEST 2017 on sn-devel-144
    
    (cherry picked from commit d55c27abc5a7357f740c7065bbe12e7f36b57125)

commit 67649b72d551d95d8fefc0f417d295be7a9c29ce
Author: Ralph Boehme <slow at samba.org>
Date:   Tue May 23 17:44:16 2017 +0200

    vfs_fruit: return fake pipe fd in fruit_open_meta_netatalk()
    
    Do not open the basefile, that conflict with "kernel oplocks = yes". We
    just return a fake file fd based on dup'ing a pipe fd and ensure all VFS
    functions that go through vfs_fruit and work on the metadata stream can
    deal with it.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit 7583ee6e1c558067e4c7a7351085fcc0e4240366)

commit 6f00dc7f9e9b14d0a018c22f75115d35e7cb22ad
Author: Ralph Boehme <slow at samba.org>
Date:   Tue May 23 17:31:47 2017 +0200

    vfs_fruit: don't open basefile in ad_open() and simplify API
    
    We never need an fd on the basefile when operating on the metadata, as
    we can always use path based syscalls. Opening the basefile conflicts
    with "kernel oplocks" so just don't do it.
    
    Additional changes:
    
    - remove the adouble_type_t argument to ad_open(), the type is passed
      and set when allocating a struct adouble with ad_alloc()
    
    - additionally pass an optional fsp to ad_open() (so the caller can pass
      NULL). With this change we can move the fd inheritance from fsp to ad
      into ad_open() itself where it belongs and remove it from the caller
      ad_fget()
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit e92a39255e66f655e2758f0a71a01eaf258cf711)

commit dafa1922d161255ae340b8ef6f9c23f04bad0523
Author: Ralph Boehme <slow at samba.org>
Date:   Tue May 23 17:39:46 2017 +0200

    vfs_fruit: use path based setxattr call in ad_fset()
    
    This allows later commits to remove opening of the basefile which
    conflict with "kernel oplocks = yes".
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit aff6fc49f4ac244aef162200a37bd846719e1e4f)

commit 4a742a6452ad96d245cdfe04ed1725b53e837dd4
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 18 13:17:38 2017 +0200

    s4/torture: additional tests for kernel-oplocks
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit bbc225de83e7b0e5eaeb1b843532d1f0fca91a3c)

commit 60a551ea4a57ee48ec7fe093b5403ef4dbf0b6b1
Author: Ralph Boehme <slow at samba.org>
Date:   Wed May 10 11:38:06 2017 +0200

    s4/torture: reproducer for kernel oplocks issue with streams
    
    test_smb2_kernel_oplocks3() wouldn't have failed without the patches,
    I'm just adding it to have at least one test that tests with 2
    clients. All other tests use just one client.
    
    test_smb2_kernel_oplocks4() is the reproducer.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    (cherry picked from commit a334fff8a8c779704ee04ae784024efb67a6e9c9)

commit a89dca276807544db0cd7f2e40a8fc447eed28c6
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 18:08:56 2017 +0200

    vfs_streams_xattr: return a fake fd in streams_xattr_open()
    
    The final step in changing vfs_streams_xattr to not call open() on the
    basefile anymore. Instead, we just return a fake file fd based on
    dup'ing a pipe fd. Previous commits ensured all calls to VFS API
    functions use pathname based versions to do their work.
    
    This ensures we don't trigger kernel oplock breaks for client "open
    stream" requests when needlessly opening the basefile.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit 0a8559d4c9e4fc73c30a06b5f45f3b870afe4439)

commit 715bae3cb39a580b1ec0f6ac5409617d75f02c4a
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 18:05:18 2017 +0200

    vfs_streams_xattr: implement all missing handle based VFS functions
    
    Implement all missing handle based VFS function. If the call is on a
    named stream, implement the appropriate action for the VFS function, in
    most cases a no-op.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit 9647af6bec62c9f61d541aad4a9b8f25fd5bc627)

commit 577a3c1f2966f324275b8a747d42f1a7c88c757d
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 17:38:00 2017 +0200

    vfs_streams_xattr: always pass NULL as fsp arg to get_ea_value()
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit 0ed3075ee7edfecde7455a2c64e9df882828343b)

commit cc0ada5782089295bd08efbf1354f5720533ea4f
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 17:36:15 2017 +0200

    vfs_streams_xattr: remove fsp argument from get_xattr_size()
    
    Still in the process of changing all handle based operations to use path
    based operations.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit 4cc59e6d011cd3804499ba82bb4071973aa9d494)

commit 2987e4979436161dbdfe89cb3bce51e90d3cbfc0
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 15:05:23 2017 +0200

    vfs_streams_xattr: remove all uses of fd, use name based functions
    
    We don't really need an fd in this module, all calls to the VFS xattr
    API can just use the name based versions.
    
    This paves the way for removing the open of the basefile in
    streams_xattr_open() in a later commit.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit ea906bb476516c05e7cbda478afd32acb443c03e)

commit a0727ee3a5aec5dcb0b92a07ef1f36115e0e5e93
Author: Ralph Boehme <slow at samba.org>
Date:   Thu May 11 07:59:20 2017 +0200

    vfs_streams_xattr: invalidate stat info if xattr was not found
    
    We stat the basefile so we leave valid stat info from the base file
    behind, even though the xattr for the stream was not there.
    
    Bug: https://bugzilla.samba.org/show_bug.cgi?id=12791
    
    Signed-off-by: Ralph Boehme <slow at samba.org>
    Reviewed-by: Richard Sharpe <realrichardsharpe at gmail.com>
    Reviewed-by: Volker Lendecke <vl at samba.org>
    (cherry picked from commit ec32f33ea6d50d9cb504400c3ef1e78643502e1a)

commit ca32a2506672550418ca0add1ce9e87c0dac9c4b
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 21 15:11:08 2017 -0700

    s3: torture: Add a test for cli_setpathinfo_basic() to smbtorture3.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12913
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit bfa07323590357542eb06ad5faa2dc5a5736e3f1)

commit 4cc812b36a7fd951e870602ec40b99a875e97888
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 21 12:46:23 2017 -0700

    s3: libsmb: Implement cli_smb2_setatr() by calling cli_smb2_setpathinfo().
    
    This removes duplicate code paths and ensures we have only one
    function calling the underlying smb2cli_set_info() for setting
    info levels by path.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12913
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit b1e5b894b089433e59c96915a27559d179bdb6c5)

commit a8993359cf325197d873243d895d95c70879883c
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 21 12:41:11 2017 -0700

    s3: libsmb: Add cli_smb2_setpathinfo(), to be called by cli_setpathinfo_basic().
    
    Fix to prevent libsmbclient from accidently making SMB1 calls inside an SMB2
    connection.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12913
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit 2a15c70603bb23a68a2e3de0b00bfd98508f78e0)

commit 527d1aaac89653a1a9453901e5ec224359aa1c9f
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Jul 21 09:56:45 2017 -0700

    s3: libsmbclient: Fix cli_setpathinfo_basic() to treat mode == -1 as no change.
    
    This is only called from SMBC_setatr(), so bring it into line with
    the specification for that function.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12913
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>
    (cherry picked from commit 812006fa8f26004609901b0ddef1c3ed05eff35e)

-----------------------------------------------------------------------

Summary of changes:
 source3/client/client.c                   |   2 +-
 source3/libsmb/cli_smb2_fnum.c            |  73 ++--
 source3/libsmb/cli_smb2_fnum.h            |   5 +
 source3/libsmb/clirap.c                   |  27 +-
 source3/modules/vfs_fruit.c               | 268 +++++---------
 source3/modules/vfs_streams_xattr.c       | 558 +++++++++++++++++++++++++-----
 source3/script/tests/test_smbclient_s3.sh |   4 +-
 source3/torture/torture.c                 | 137 ++++++++
 source4/torture/smb2/oplock.c             | 346 ++++++++++++++++++
 9 files changed, 1115 insertions(+), 305 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/client.c b/source3/client/client.c
index d8c96e6..83d9b9d 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -5706,7 +5706,7 @@ static int process_stdin(void)
 {
 	int rc = 0;
 
-	d_printf("Try \"help\" do get a list of possible commands.\n");
+	d_printf("Try \"help\" to get a list of possible commands.\n");
 
 	while (!finished) {
 		TALLOC_CTX *frame = talloc_stackframe();
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 6967555..8ee97ca 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -1646,20 +1646,20 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli,
 }
 
 /***************************************************************
- Wrapper that allows SMB2 to set pathname attributes.
+ Wrapper that allows SMB2 to set SMB_FILE_BASIC_INFORMATION on
+ a pathname.
  Synchronous only.
 ***************************************************************/
 
-NTSTATUS cli_smb2_setatr(struct cli_state *cli,
+NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli,
 			const char *name,
-			uint16_t attr,
-			time_t mtime)
+			uint8_t in_info_type,
+			uint8_t in_file_info_class,
+			const DATA_BLOB *p_in_data)
 {
 	NTSTATUS status;
 	uint16_t fnum = 0xffff;
 	struct smb2_hnd *ph = NULL;
-	uint8_t inbuf_store[40];
-	DATA_BLOB inbuf = data_blob_null;
 	TALLOC_CTX *frame = talloc_stackframe();
 
 	if (smbXcli_conn_has_async_calls(cli->conn)) {
@@ -1691,6 +1691,42 @@ NTSTATUS cli_smb2_setatr(struct cli_state *cli,
 		goto fail;
 	}
 
+	status = smb2cli_set_info(cli->conn,
+				cli->timeout,
+				cli->smb2.session,
+				cli->smb2.tcon,
+				in_info_type,
+				in_file_info_class,
+				p_in_data, /* in_input_buffer */
+				0, /* in_additional_info */
+				ph->fid_persistent,
+				ph->fid_volatile);
+  fail:
+
+	if (fnum != 0xffff) {
+		cli_smb2_close_fnum(cli, fnum);
+	}
+
+	cli->raw_status = status;
+
+	TALLOC_FREE(frame);
+	return status;
+}
+
+
+/***************************************************************
+ Wrapper that allows SMB2 to set pathname attributes.
+ Synchronous only.
+***************************************************************/
+
+NTSTATUS cli_smb2_setatr(struct cli_state *cli,
+			const char *name,
+			uint16_t attr,
+			time_t mtime)
+{
+	uint8_t inbuf_store[40];
+	DATA_BLOB inbuf = data_blob_null;
+
 	/* setinfo on the handle with info_type SMB2_SETINFO_FILE (1),
 	   level 4 (SMB_FILE_BASIC_INFORMATION - 1000). */
 
@@ -1730,28 +1766,15 @@ NTSTATUS cli_smb2_setatr(struct cli_state *cli,
 	SBVAL(inbuf.data, 8, 0xFFFFFFFFFFFFFFFFLL);
 	SBVAL(inbuf.data, 24, 0xFFFFFFFFFFFFFFFFLL);
 
-	status = smb2cli_set_info(cli->conn,
-				cli->timeout,
-				cli->smb2.session,
-				cli->smb2.tcon,
+	return cli_smb2_setpathinfo(cli,
+				name,
 				1, /* in_info_type */
-				SMB_FILE_BASIC_INFORMATION - 1000, /* in_file_info_class */
-				&inbuf, /* in_input_buffer */
-				0, /* in_additional_info */
-				ph->fid_persistent,
-				ph->fid_volatile);
-  fail:
-
-	if (fnum != 0xffff) {
-		cli_smb2_close_fnum(cli, fnum);
-	}
-
-	cli->raw_status = status;
-
-	TALLOC_FREE(frame);
-	return status;
+				/* in_file_info_class */
+				SMB_FILE_BASIC_INFORMATION - 1000,
+				&inbuf);
 }
 
+
 /***************************************************************
  Wrapper that allows SMB2 to set file handle times.
  Synchronous only.
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index 190ec59..8e240c6 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -114,6 +114,11 @@ NTSTATUS cli_smb2_qpathinfo_streams(struct cli_state *cli,
 			TALLOC_CTX *mem_ctx,
 			unsigned int *pnum_streams,
 			struct stream_struct **pstreams);
+NTSTATUS cli_smb2_setpathinfo(struct cli_state *cli,
+			const char *name,
+			uint8_t in_info_type,
+			uint8_t in_file_info_class,
+			const DATA_BLOB *p_in_data);
 NTSTATUS cli_smb2_setatr(struct cli_state *cli,
 			const char *fname,
 			uint16_t attr,
diff --git a/source3/libsmb/clirap.c b/source3/libsmb/clirap.c
index dd2c30e..e80dfc9 100644
--- a/source3/libsmb/clirap.c
+++ b/source3/libsmb/clirap.c
@@ -29,6 +29,7 @@
 #include "libsmb/clirap.h"
 #include "trans2.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "cli_smb2_fnum.h"
 
 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
 
@@ -732,8 +733,17 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
         put_long_date(p, change_time);
         p += 8;
 
-        /* Add attributes */
-        SIVAL(p, 0, mode);
+	if (mode == (uint16_t)-1 || mode == FILE_ATTRIBUTE_NORMAL) {
+		/* No change. */
+		mode = 0;
+	} else if (mode == 0) {
+		/* Clear all existing attributes. */
+		mode = FILE_ATTRIBUTE_NORMAL;
+	}
+
+	/* Add attributes */
+	SIVAL(p, 0, mode);
+
         p += 4;
 
         /* Add padding */
@@ -742,6 +752,19 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
 
         data_len = PTR_DIFF(p, data);
 
+	if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+		DATA_BLOB in_data = data_blob_const(data, data_len);
+		/*
+		 * Split out SMB2 here as we need to select
+		 * the correct info type and level.
+		 */
+		return cli_smb2_setpathinfo(cli,
+				fname,
+				1, /* SMB2_SETINFO_FILE */
+				SMB_FILE_BASIC_INFORMATION - 1000,
+				&in_data);
+	}
+
 	return cli_setpathinfo(cli, SMB_FILE_BASIC_INFORMATION, fname,
 			       (uint8_t *)data, data_len);
 }
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index 7c481cd..09e0fcd 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -863,13 +863,6 @@ exit:
 	return ealen;
 }
 
-static int ad_open_meta(const struct smb_filename *smb_fname,
-			int flags,
-			mode_t mode)
-{
-	return open(smb_fname->base_name, flags, mode);
-}
-
 static int ad_open_rsrc_xattr(const struct smb_filename *smb_fname,
 				int flags,
 				mode_t mode)
@@ -923,34 +916,45 @@ static int ad_open_rsrc(vfs_handle_struct *handle,
 	return fd;
 }
 
+/*
+ * Here's the deal: for ADOUBLE_META we can do without an fd as we can issue
+ * path based xattr calls. For ADOUBLE_RSRC however we need a full-fledged fd
+ * for file IO on the ._ file.
+ */
 static int ad_open(vfs_handle_struct *handle,
 		   struct adouble *ad,
+		   files_struct *fsp,
 		   const struct smb_filename *smb_fname,
-		   adouble_type_t t,
 		   int flags,
 		   mode_t mode)
 {
 	int fd;
 
-	DBG_DEBUG("Path [%s] type [%s]\n",
-		  smb_fname->base_name, t == ADOUBLE_META ? "meta" : "rsrc");
+	DBG_DEBUG("Path [%s] type [%s]\n", smb_fname->base_name,
+		  ad->ad_type == ADOUBLE_META ? "meta" : "rsrc");
 
-	if (t == ADOUBLE_META) {
-		fd = ad_open_meta(smb_fname, flags, mode);
-	} else {
-		fd = ad_open_rsrc(handle, smb_fname, flags, mode);
+	if (ad->ad_type == ADOUBLE_META) {
+		return 0;
+	}
+
+	if ((fsp != NULL) && (fsp->fh != NULL) && (fsp->fh->fd != -1)) {
+		ad->ad_fd = fsp->fh->fd;
+		ad->ad_opened = false;
+		return 0;
 	}
 
-	if (fd != -1) {
-		ad->ad_opened = true;
-		ad->ad_fd = fd;
+	fd = ad_open_rsrc(handle, smb_fname, flags, mode);
+	if (fd == -1) {
+		return -1;
 	}
+	ad->ad_opened = true;
+	ad->ad_fd = fd;
 
 	DBG_DEBUG("Path [%s] type [%s] fd [%d]\n",
 		  smb_fname->base_name,
-		  t == ADOUBLE_META ? "meta" : "rsrc", fd);
+		  ad->ad_type == ADOUBLE_META ? "meta" : "rsrc", fd);
 
-	return fd;
+	return 0;
 }
 
 static ssize_t ad_read_rsrc_xattr(struct adouble *ad)
@@ -1237,26 +1241,21 @@ static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
 	return ad;
 }
 
-/**
- * Return AppleDouble data for a file
- *
- * @param[in] ctx      talloc context
- * @param[in] handle   vfs handle
- * @param[in] smb_fname     pathname to file or directory
- * @param[in] type     type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
- *
- * @return             talloced struct adouble or NULL on error
- **/
-static struct adouble *ad_get(TALLOC_CTX *ctx, vfs_handle_struct *handle,
-			const struct smb_filename *smb_fname,
-			adouble_type_t type)
+static struct adouble *ad_get_internal(TALLOC_CTX *ctx,
+				       vfs_handle_struct *handle,
+				       files_struct *fsp,
+				       const struct smb_filename *smb_fname,
+				       adouble_type_t type)
 {
 	int rc = 0;
 	ssize_t len;
 	struct adouble *ad = NULL;
-	int fd;
 	int mode;
 
+	if (fsp != NULL) {
+		smb_fname = fsp->base_fsp->fsp_name;
+	}
+
 	DEBUG(10, ("ad_get(%s) called for %s\n",
 		   type == ADOUBLE_META ? "meta" : "rsrc",
 		   smb_fname->base_name));
@@ -1267,29 +1266,19 @@ static struct adouble *ad_get(TALLOC_CTX *ctx, vfs_handle_struct *handle,
 		goto exit;
 	}
 
-	/*
-	 * Here's the deal: for ADOUBLE_META we can do without an fd
-	 * as we can issue path based xattr calls. For ADOUBLE_RSRC
-	 * however we need a full-fledged fd for file IO on the ._
-	 * file.
-	 */
-	if (type == ADOUBLE_RSRC) {
-		/* Try rw first so we can use the fd in ad_convert() */
-		mode = O_RDWR;
-
-		fd = ad_open(handle, ad, smb_fname, ADOUBLE_RSRC, mode, 0);
-		if (fd == -1 && ((errno == EROFS) || (errno == EACCES))) {
-			mode = O_RDONLY;
-			fd = ad_open(handle, ad, smb_fname,
-					ADOUBLE_RSRC, mode, 0);
-		}
+	/* Try rw first so we can use the fd in ad_convert() */
+	mode = O_RDWR;
+
+	rc = ad_open(handle, ad, fsp, smb_fname, mode, 0);
+	if (rc == -1 && ((errno == EROFS) || (errno == EACCES))) {
+		mode = O_RDONLY;
+		rc = ad_open(handle, ad, fsp, smb_fname, mode, 0);
+	}
+	if (rc == -1) {
+		DBG_DEBUG("ad_open [%s] error [%s]\n",
+			  smb_fname->base_name, strerror(errno));
+		goto exit;
 
-		if (fd == -1) {
-			DBG_DEBUG("ad_open [%s] error [%s]\n",
-				  smb_fname->base_name, strerror(errno));
-			rc = -1;
-			goto exit;
-		}
 	}
 
 	len = ad_read(ad, smb_fname);
@@ -1316,6 +1305,24 @@ exit:
  *
  * @param[in] ctx      talloc context
  * @param[in] handle   vfs handle
+ * @param[in] smb_fname pathname to file or directory
+ * @param[in] type     type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
+ *
+ * @return             talloced struct adouble or NULL on error
+ **/
+static struct adouble *ad_get(TALLOC_CTX *ctx,
+			      vfs_handle_struct *handle,
+			      const struct smb_filename *smb_fname,
+			      adouble_type_t type)
+{
+	return ad_get_internal(ctx, handle, NULL, smb_fname, type);
+}
+
+/**
+ * Return AppleDouble data for a file
+ *
+ * @param[in] ctx      talloc context
+ * @param[in] handle   vfs handle
  * @param[in] fsp      fsp to use for IO
  * @param[in] type     type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
  *
@@ -1324,73 +1331,7 @@ exit:
 static struct adouble *ad_fget(TALLOC_CTX *ctx, vfs_handle_struct *handle,
 			       files_struct *fsp, adouble_type_t type)
 {
-	int rc = 0;
-	ssize_t len;
-	struct adouble *ad = NULL;
-
-	DBG_DEBUG("ad_get(%s) path [%s]\n",
-		  type == ADOUBLE_META ? "meta" : "rsrc",
-		  fsp_str_dbg(fsp));
-
-	ad = ad_alloc(ctx, handle, type);
-	if (ad == NULL) {
-		rc = -1;
-		goto exit;
-	}
-
-	if ((fsp->fh != NULL) && (fsp->fh->fd != -1)) {
-		ad->ad_fd = fsp->fh->fd;
-	} else {
-		/*
-		 * Here's the deal: for ADOUBLE_META we can do without an fd
-		 * as we can issue path based xattr calls. For ADOUBLE_RSRC
-		 * however we need a full-fledged fd for file IO on the ._
-		 * file.
-		 */
-		int fd;
-		int mode;
-
-		if (type == ADOUBLE_RSRC) {
-			/* Try rw first so we can use the fd in ad_convert() */
-			mode = O_RDWR;
-
-			fd = ad_open(handle, ad, fsp->base_fsp->fsp_name,
-					ADOUBLE_RSRC, mode, 0);
-			if (fd == -1 &&
-			    ((errno == EROFS) || (errno == EACCES)))
-			{
-				mode = O_RDONLY;
-				fd = ad_open(handle, ad,
-					fsp->base_fsp->fsp_name, ADOUBLE_RSRC,
-					mode, 0);
-			}
-
-			if (fd == -1) {
-				DBG_DEBUG("error opening AppleDouble for %s\n",
-					fsp_str_dbg(fsp));
-				rc = -1;
-				goto exit;
-			}
-		}
-	}
-
-	len = ad_read(ad, fsp->base_fsp->fsp_name);
-	if (len == -1) {
-		DBG_DEBUG("error reading AppleDouble for %s\n",
-			fsp_str_dbg(fsp));
-		rc = -1;
-		goto exit;
-	}
-
-exit:
-	DBG_DEBUG("ad_get(%s) path [%s] rc [%d]\n",
-		  type == ADOUBLE_META ? "meta" : "rsrc",
-		  fsp_str_dbg(fsp), rc);
-
-	if (rc != 0) {
-		TALLOC_FREE(ad);
-	}
-	return ad;
+	return ad_get_internal(ctx, handle, fsp, NULL, type);
 }
 
 /**
@@ -1461,11 +1402,11 @@ static int ad_fset(struct adouble *ad, files_struct *fsp)
 
 	switch (ad->ad_type) {
 	case ADOUBLE_META:
-		rc = SMB_VFS_NEXT_FSETXATTR(ad->ad_handle,
-					    fsp,
-					    AFPINFO_EA_NETATALK,
-					    ad->ad_data,
-					    AD_DATASZ_XATTR, 0);
+		rc = SMB_VFS_NEXT_SETXATTR(ad->ad_handle,
+					   fsp->fsp_name,
+					   AFPINFO_EA_NETATALK,
+					   ad->ad_data,
+					   AD_DATASZ_XATTR, 0);
 		break;
 
 	case ADOUBLE_RSRC:
@@ -2767,56 +2708,24 @@ static int fruit_open_meta_netatalk(vfs_handle_struct *handle,
 				    int flags,
 				    mode_t mode)
 {
-	int rc = 0;
-	struct smb_filename *smb_fname_base = NULL;
-	int baseflags;
-	int hostfd = -1;
+	int rc;
+	int fakefd = -1;
 	struct adouble *ad = NULL;
+	int fds[2];
 
 	DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname));
 
-	/* Create an smb_filename with stream_name == NULL. */
-	smb_fname_base = synthetic_smb_fname(talloc_tos(),
-					smb_fname->base_name,
-					NULL,
-					NULL,
-					smb_fname->flags);
-
-	if (smb_fname_base == NULL) {
-		errno = ENOMEM;
-		rc = -1;
-		goto exit;
-	}
-
 	/*
-	 * We use baseflags to turn off nasty side-effects when opening the
-	 * underlying file.
+	 * Return a valid fd, but ensure any attempt to use it returns an error
+	 * (EPIPE). All operations on the smb_fname or the fsp will use path
+	 * based syscalls.
 	 */
-	baseflags = flags;
-	baseflags &= ~O_TRUNC;
-	baseflags &= ~O_EXCL;
-	baseflags &= ~O_CREAT;


-- 
Samba Shared Repository



More information about the samba-cvs mailing list