From: Ralph Boehme Date: Mon, 1 Jul 2019 13:53:36 +0000 (+0200) Subject: s3:lib: move Mac streams util functions to s3/lib X-Git-Tag: talloc-2.3.0~107 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3093c374f2fe16efd765b485bf86599feff1f6a7;p=thirdparty%2Fsamba.git s3:lib: move Mac streams util functions to s3/lib 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 Reviewed-by: Jeremy Allison --- diff --git a/source3/lib/util_macstreams.c b/source3/lib/util_macstreams.c new file mode 100644 index 00000000000..787ad881568 --- /dev/null +++ b/source3/lib/util_macstreams.c @@ -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 . +*/ + +#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 index 00000000000..ad50abc2c3a --- /dev/null +++ b/source3/lib/util_macstreams.h @@ -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 . +*/ + +#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 diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c index 2dbbaefba8f..58119e09559 100644 --- a/source3/modules/vfs_fruit.c +++ b/source3/modules/vfs_fruit.c @@ -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) { diff --git a/source3/wscript_build b/source3/wscript_build index db29a7d2a15..a3f3521b6ce 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -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