s3:lib: move Mac streams util functions to s3/lib
authorRalph Boehme <slow@samba.org>
Mon, 1 Jul 2019 13:53:36 +0000 (15:53 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 12 Jul 2019 21:31:29 +0000 (21:31 +0000)
While at it, change the functions to work on the stream name directly instead of
struct smb_filename. A later commit wants to use the function on the resulting
stream names coming from vfs_streaminfo().

Also use the simple string compare version, not the multibyte ones, as the afp*
stream names are simple ASCII string, so there's no need to become fancy.

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/lib/util_macstreams.c [new file with mode: 0644]
source3/lib/util_macstreams.h [new file with mode: 0644]
source3/modules/vfs_fruit.c
source3/wscript_build

diff --git a/source3/lib/util_macstreams.c b/source3/lib/util_macstreams.c
new file mode 100644 (file)
index 0000000..787ad88
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Ralph Boehme 2019
+
+   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 "MacExtensions.h"
+#include "util_macstreams.h"
+
+/* Yes, I have considered multibyte */
+#undef strncasecmp
+
+bool is_afpinfo_stream(const char *sname)
+{
+       int cmp;
+
+       if (sname == NULL) {
+               return false;
+       }
+
+       cmp = strncasecmp(sname,
+                         AFPINFO_STREAM_NAME,
+                         strlen(AFPINFO_STREAM_NAME));
+       if (cmp == 0) {
+               return true;
+       }
+       return false;
+}
+
+bool is_afpresource_stream(const char *sname)
+{
+       int cmp;
+
+       if (sname == NULL) {
+               return false;
+       }
+
+       cmp = strncasecmp(sname,
+                         AFPRESOURCE_STREAM_NAME,
+                         strlen(AFPRESOURCE_STREAM_NAME));
+       if (cmp == 0) {
+               return true;
+       }
+       return false;
+}
+
+/**
+ * Test whether stream is an Apple stream.
+ **/
+bool is_apple_stream(const char *sname)
+{
+       if (is_afpinfo_stream(sname)) {
+               return true;
+       }
+       if (is_afpresource_stream(sname)) {
+               return true;
+       }
+       return false;
+}
diff --git a/source3/lib/util_macstreams.h b/source3/lib/util_macstreams.h
new file mode 100644 (file)
index 0000000..ad50abc
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+   Unix SMB/CIFS implementation.
+   Samba utility functions
+   Copyright (C) Ralph Boehme 2019
+
+   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/>.
+*/
+
+#ifndef _UTIL_MACSTREAMS_H_
+#define _UTIL_MACSTREAMS_H_
+
+bool is_afpinfo_stream(const char *sname);
+bool is_afpresource_stream(const char *sname);
+bool is_apple_stream(const char *sname);
+
+#endif
index 2dbbaefba8ff07b5de2798766f8bb99203fedc44..58119e09559e64334dc5b87cdc68552b3c3eaf63 100644 (file)
@@ -34,6 +34,7 @@
 #include "string_replace.h"
 #include "hash_inode.h"
 #include "lib/adouble.h"
+#include "lib/util_macstreams.h"
 
 /*
  * Enhanced OS X and Netatalk compatibility
@@ -209,40 +210,6 @@ struct fio {
  * Helper functions
  *****************************************************************************/
 
-static bool is_afpinfo_stream(const struct smb_filename *smb_fname)
-{
-       if (strncasecmp_m(smb_fname->stream_name,
-                         AFPINFO_STREAM_NAME,
-                         strlen(AFPINFO_STREAM_NAME)) == 0) {
-               return true;
-       }
-       return false;
-}
-
-static bool is_afpresource_stream(const struct smb_filename *smb_fname)
-{
-       if (strncasecmp_m(smb_fname->stream_name,
-                         AFPRESOURCE_STREAM_NAME,
-                         strlen(AFPRESOURCE_STREAM_NAME)) == 0) {
-               return true;
-       }
-       return false;
-}
-
-/**
- * Test whether stream is an Apple stream.
- **/
-static bool is_apple_stream(const struct smb_filename *smb_fname)
-{
-       if (is_afpinfo_stream(smb_fname)) {
-               return true;
-       }
-       if (is_afpresource_stream(smb_fname)) {
-               return true;
-       }
-       return false;
-}
-
 /**
  * Initialize config struct from our smb.conf config parameters
  **/
@@ -1650,9 +1617,9 @@ static int fruit_open(vfs_handle_struct *handle,
                return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
        }
 
-       if (is_afpinfo_stream(smb_fname)) {
+       if (is_afpinfo_stream(smb_fname->stream_name)) {
                fd = fruit_open_meta(handle, smb_fname, fsp, flags, mode);
-       } else if (is_afpresource_stream(smb_fname)) {
+       } else if (is_afpresource_stream(smb_fname->stream_name)) {
                fd = fruit_open_rsrc(handle, smb_fname, fsp, flags, mode);
        } else {
                fd = SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
@@ -1733,9 +1700,9 @@ static int fruit_close(vfs_handle_struct *handle,
                return SMB_VFS_NEXT_CLOSE(handle, fsp);
        }
 
-       if (is_afpinfo_stream(fsp->fsp_name)) {
+       if (is_afpinfo_stream(fsp->fsp_name->stream_name)) {
                ret = fruit_close_meta(handle, fsp);
-       } else if (is_afpresource_stream(fsp->fsp_name)) {
+       } else if (is_afpresource_stream(fsp->fsp_name->stream_name)) {
                ret = fruit_close_rsrc(handle, fsp);
        } else {
                ret = SMB_VFS_NEXT_CLOSE(handle, fsp);
@@ -1984,9 +1951,9 @@ static int fruit_unlink(vfs_handle_struct *handle,
        SMB_VFS_HANDLE_GET_DATA(handle, config,
                                struct fruit_config_data, return -1);
 
-       if (is_afpinfo_stream(smb_fname)) {
+       if (is_afpinfo_stream(smb_fname->stream_name)) {
                return fruit_unlink_meta(handle, smb_fname);
-       } else if (is_afpresource_stream(smb_fname)) {
+       } else if (is_afpresource_stream(smb_fname->stream_name)) {
                return fruit_unlink_rsrc(handle, smb_fname, false);
        } else if (is_ntfs_stream_smb_fname(smb_fname)) {
                return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
@@ -3169,9 +3136,9 @@ static int fruit_stat(vfs_handle_struct *handle,
         * not following links here.
         */
 
-       if (is_afpinfo_stream(smb_fname)) {
+       if (is_afpinfo_stream(smb_fname->stream_name)) {
                rc = fruit_stat_meta(handle, smb_fname, true);
-       } else if (is_afpresource_stream(smb_fname)) {
+       } else if (is_afpresource_stream(smb_fname->stream_name)) {
                rc = fruit_stat_rsrc(handle, smb_fname, true);
        } else {
                return SMB_VFS_NEXT_STAT(handle, smb_fname);
@@ -3204,9 +3171,9 @@ static int fruit_lstat(vfs_handle_struct *handle,
                return rc;
        }
 
-       if (is_afpinfo_stream(smb_fname)) {
+       if (is_afpinfo_stream(smb_fname->stream_name)) {
                rc = fruit_stat_meta(handle, smb_fname, false);
-       } else if (is_afpresource_stream(smb_fname)) {
+       } else if (is_afpresource_stream(smb_fname->stream_name)) {
                rc = fruit_stat_rsrc(handle, smb_fname, false);
        } else {
                return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
@@ -4010,7 +3977,7 @@ static NTSTATUS fruit_create_file(vfs_handle_struct *handle,
        SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
                                return NT_STATUS_UNSUCCESSFUL);
 
-       if (is_apple_stream(smb_fname) && !internal_open) {
+       if (is_apple_stream(smb_fname->stream_name) && !internal_open) {
                uint32_t conv_flags  = 0;
 
                if (config->wipe_intentionally_left_blank_rfork) {
index db29a7d2a1528997fb7b126728d27c243a208f4a..a3f3521b6ce7d991ebc5b5ee3ee09b76fb33fb65 100644 (file)
@@ -304,6 +304,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
                           lib/util_sock.c
                           lib/util_tsock.c
                           lib/util_transfer_file.c
+                          lib/util_macstreams.c
                           ''',
                    deps='''
                         CHARSET3