2 * OS X and Netatalk interoperability VFS module for Samba-3.x
4 * Copyright (C) Ralph Boehme, 2013, 2014
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
21 #include "MacExtensions.h"
22 #include "smbd/smbd.h"
23 #include "system/filesys.h"
24 #include "lib/util/time.h"
25 #include "../lib/crypto/md5.h"
26 #include "system/shmem.h"
27 #include "locking/proto.h"
28 #include "smbd/globals.h"
30 #include "libcli/security/security.h"
31 #include "../libcli/smb/smb2_create_ctx.h"
32 #include "lib/util/sys_rw.h"
33 #include "lib/util/tevent_ntstatus.h"
34 #include "lib/util/tevent_unix.h"
35 #include "offload_token.h"
38 * Enhanced OS X and Netatalk compatibility
39 * ========================================
41 * This modules takes advantage of vfs_streams_xattr and
42 * vfs_catia. VFS modules vfs_fruit and vfs_streams_xattr must be
43 * loaded in the correct order:
45 * vfs modules = catia fruit streams_xattr
47 * The module intercepts the OS X special streams "AFP_AfpInfo" and
48 * "AFP_Resource" and handles them in a special way. All other named
49 * streams are deferred to vfs_streams_xattr.
51 * The OS X client maps all NTFS illegal characters to the Unicode
52 * private range. This module optionally stores the charcters using
53 * their native ASCII encoding using vfs_catia. If you're not enabling
54 * this feature, you can skip catia from vfs modules.
56 * Finally, open modes are optionally checked against Netatalk AFP
59 * The "AFP_AfpInfo" named stream is a binary blob containing OS X
60 * extended metadata for files and directories. This module optionally
61 * reads and stores this metadata in a way compatible with Netatalk 3
62 * which stores the metadata in an EA "org.netatalk.metadata". Cf
63 * source3/include/MacExtensions.h for a description of the binary
66 * The "AFP_Resource" named stream may be arbitrarily large, thus it
67 * can't be stored in an xattr on most filesystem. ZFS on Solaris is
68 * the only available filesystem where xattrs can be of any size and
69 * the OS supports using the file APIs for xattrs.
71 * The AFP_Resource stream is stored in an AppleDouble file prepending
72 * "._" to the filename. On Solaris with ZFS the stream is optionally
73 * stored in an EA "org.netatalk.resource".
79 * The OS X SMB client sends xattrs as ADS too. For xattr interop with
80 * other protocols you may want to adjust the xattr names the VFS
81 * module vfs_streams_xattr uses for storing ADS's. This defaults to
82 * user.DosStream.ADS_NAME:$DATA and can be changed by specifying
83 * these module parameters:
85 * streams_xattr:prefix = user.
86 * streams_xattr:store_stream_type = false
92 * - log diagnostic if any needed VFS module is not loaded
93 * (eg with lp_vfs_objects())
97 static int vfs_fruit_debug_level
= DBGC_VFS
;
99 static struct global_fruit_config
{
100 bool nego_aapl
; /* client negotiated AAPL */
102 } global_fruit_config
;
105 #define DBGC_CLASS vfs_fruit_debug_level
107 #define FRUIT_PARAM_TYPE_NAME "fruit"
108 #define ADOUBLE_NAME_PREFIX "._"
110 #define NETATALK_META_XATTR "org.netatalk.Metadata"
111 #define NETATALK_RSRC_XATTR "org.netatalk.ResourceFork"
113 #if defined(HAVE_ATTROPEN)
114 #define AFPINFO_EA_NETATALK NETATALK_META_XATTR
115 #define AFPRESOURCE_EA_NETATALK NETATALK_RSRC_XATTR
117 #define AFPINFO_EA_NETATALK "user." NETATALK_META_XATTR
118 #define AFPRESOURCE_EA_NETATALK "user." NETATALK_RSRC_XATTR
121 enum apple_fork
{APPLE_FORK_DATA
, APPLE_FORK_RSRC
};
123 enum fruit_rsrc
{FRUIT_RSRC_STREAM
, FRUIT_RSRC_ADFILE
, FRUIT_RSRC_XATTR
};
124 enum fruit_meta
{FRUIT_META_STREAM
, FRUIT_META_NETATALK
};
125 enum fruit_locking
{FRUIT_LOCKING_NETATALK
, FRUIT_LOCKING_NONE
};
126 enum fruit_encoding
{FRUIT_ENC_NATIVE
, FRUIT_ENC_PRIVATE
};
128 struct fruit_config_data
{
129 enum fruit_rsrc rsrc
;
130 enum fruit_meta meta
;
131 enum fruit_locking locking
;
132 enum fruit_encoding encoding
;
133 bool use_aapl
; /* config from smb.conf */
135 bool readdir_attr_enabled
;
136 bool unix_info_enabled
;
137 bool copyfile_enabled
;
138 bool veto_appledouble
;
140 bool aapl_zero_file_id
;
144 * Additional options, all enabled by default,
145 * possibly useful for analyzing performance. The associated
146 * operations with each of them may be expensive, so having
147 * the chance to disable them individually gives a chance
148 * tweaking the setup for the particular usecase.
150 bool readdir_attr_rsize
;
151 bool readdir_attr_finder_info
;
152 bool readdir_attr_max_access
;
155 static const struct enum_list fruit_rsrc
[] = {
156 {FRUIT_RSRC_STREAM
, "stream"}, /* pass on to vfs_streams_xattr */
157 {FRUIT_RSRC_ADFILE
, "file"}, /* ._ AppleDouble file */
158 {FRUIT_RSRC_XATTR
, "xattr"}, /* Netatalk compatible xattr (ZFS only) */
162 static const struct enum_list fruit_meta
[] = {
163 {FRUIT_META_STREAM
, "stream"}, /* pass on to vfs_streams_xattr */
164 {FRUIT_META_NETATALK
, "netatalk"}, /* Netatalk compatible xattr */
168 static const struct enum_list fruit_locking
[] = {
169 {FRUIT_LOCKING_NETATALK
, "netatalk"}, /* synchronize locks with Netatalk */
170 {FRUIT_LOCKING_NONE
, "none"},
174 static const struct enum_list fruit_encoding
[] = {
175 {FRUIT_ENC_NATIVE
, "native"}, /* map unicode private chars to ASCII */
176 {FRUIT_ENC_PRIVATE
, "private"}, /* keep unicode private chars */
180 /*****************************************************************************
181 * Defines, functions and data structures that deal with AppleDouble
182 *****************************************************************************/
185 * There are two AppleDouble blobs we deal with:
187 * - ADOUBLE_META - AppleDouble blob used by Netatalk for storing
188 * metadata in an xattr
190 * - ADOUBLE_RSRC - AppleDouble blob used by OS X and Netatalk in
193 typedef enum {ADOUBLE_META
, ADOUBLE_RSRC
} adouble_type_t
;
196 #define AD_VERSION2 0x00020000
197 #define AD_VERSION AD_VERSION2
200 * AppleDouble entry IDs.
202 #define ADEID_DFORK 1
203 #define ADEID_RFORK 2
205 #define ADEID_COMMENT 4
206 #define ADEID_ICONBW 5
207 #define ADEID_ICONCOL 6
208 #define ADEID_FILEI 7
209 #define ADEID_FILEDATESI 8
210 #define ADEID_FINDERI 9
211 #define ADEID_MACFILEI 10
212 #define ADEID_PRODOSFILEI 11
213 #define ADEID_MSDOSFILEI 12
214 #define ADEID_SHORTNAME 13
215 #define ADEID_AFPFILEI 14
218 /* Private Netatalk entries */
219 #define ADEID_PRIVDEV 16
220 #define ADEID_PRIVINO 17
221 #define ADEID_PRIVSYN 18
222 #define ADEID_PRIVID 19
223 #define ADEID_MAX (ADEID_PRIVID + 1)
226 * These are the real ids for the private entries,
227 * as stored in the adouble file
229 #define AD_DEV 0x80444556
230 #define AD_INO 0x80494E4F
231 #define AD_SYN 0x8053594E
232 #define AD_ID 0x8053567E
234 /* Number of actually used entries */
235 #define ADEID_NUM_XATTR 8
236 #define ADEID_NUM_DOT_UND 2
237 #define ADEID_NUM_RSRC_XATTR 1
239 /* AppleDouble magic */
240 #define AD_APPLESINGLE_MAGIC 0x00051600
241 #define AD_APPLEDOUBLE_MAGIC 0x00051607
242 #define AD_MAGIC AD_APPLEDOUBLE_MAGIC
244 /* Sizes of relevant entry bits */
245 #define ADEDLEN_MAGIC 4
246 #define ADEDLEN_VERSION 4
247 #define ADEDLEN_FILLER 16
248 #define AD_FILLER_TAG "Netatalk " /* should be 16 bytes */
249 #define ADEDLEN_NENTRIES 2
250 #define AD_HEADER_LEN (ADEDLEN_MAGIC + ADEDLEN_VERSION + \
251 ADEDLEN_FILLER + ADEDLEN_NENTRIES) /* 26 */
252 #define AD_ENTRY_LEN_EID 4
253 #define AD_ENTRY_LEN_OFF 4
254 #define AD_ENTRY_LEN_LEN 4
255 #define AD_ENTRY_LEN (AD_ENTRY_LEN_EID + AD_ENTRY_LEN_OFF + AD_ENTRY_LEN_LEN)
258 #define ADEDLEN_NAME 255
259 #define ADEDLEN_COMMENT 200
260 #define ADEDLEN_FILEI 16
261 #define ADEDLEN_FINDERI 32
262 #define ADEDLEN_FILEDATESI 16
263 #define ADEDLEN_SHORTNAME 12 /* length up to 8.3 */
264 #define ADEDLEN_AFPFILEI 4
265 #define ADEDLEN_MACFILEI 4
266 #define ADEDLEN_PRODOSFILEI 8
267 #define ADEDLEN_MSDOSFILEI 2
268 #define ADEDLEN_DID 4
269 #define ADEDLEN_PRIVDEV 8
270 #define ADEDLEN_PRIVINO 8
271 #define ADEDLEN_PRIVSYN 8
272 #define ADEDLEN_PRIVID 4
275 #define ADEDOFF_MAGIC 0
276 #define ADEDOFF_VERSION (ADEDOFF_MAGIC + ADEDLEN_MAGIC)
277 #define ADEDOFF_FILLER (ADEDOFF_VERSION + ADEDLEN_VERSION)
278 #define ADEDOFF_NENTRIES (ADEDOFF_FILLER + ADEDLEN_FILLER)
280 #define ADEDOFF_FINDERI_XATTR (AD_HEADER_LEN + \
281 (ADEID_NUM_XATTR * AD_ENTRY_LEN))
282 #define ADEDOFF_COMMENT_XATTR (ADEDOFF_FINDERI_XATTR + ADEDLEN_FINDERI)
283 #define ADEDOFF_FILEDATESI_XATTR (ADEDOFF_COMMENT_XATTR + ADEDLEN_COMMENT)
284 #define ADEDOFF_AFPFILEI_XATTR (ADEDOFF_FILEDATESI_XATTR + \
286 #define ADEDOFF_PRIVDEV_XATTR (ADEDOFF_AFPFILEI_XATTR + ADEDLEN_AFPFILEI)
287 #define ADEDOFF_PRIVINO_XATTR (ADEDOFF_PRIVDEV_XATTR + ADEDLEN_PRIVDEV)
288 #define ADEDOFF_PRIVSYN_XATTR (ADEDOFF_PRIVINO_XATTR + ADEDLEN_PRIVINO)
289 #define ADEDOFF_PRIVID_XATTR (ADEDOFF_PRIVSYN_XATTR + ADEDLEN_PRIVSYN)
291 #define ADEDOFF_FINDERI_DOT_UND (AD_HEADER_LEN + \
292 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN))
293 #define ADEDOFF_RFORK_DOT_UND (ADEDOFF_FINDERI_DOT_UND + ADEDLEN_FINDERI)
295 #define AD_DATASZ_XATTR (AD_HEADER_LEN + \
296 (ADEID_NUM_XATTR * AD_ENTRY_LEN) + \
297 ADEDLEN_FINDERI + ADEDLEN_COMMENT + \
298 ADEDLEN_FILEDATESI + ADEDLEN_AFPFILEI + \
299 ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + \
300 ADEDLEN_PRIVSYN + ADEDLEN_PRIVID)
302 #if AD_DATASZ_XATTR != 402
303 #error bad size for AD_DATASZ_XATTR
306 #define AD_DATASZ_DOT_UND (AD_HEADER_LEN + \
307 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN) + \
309 #if AD_DATASZ_DOT_UND != 82
310 #error bad size for AD_DATASZ_DOT_UND
314 * Sharemode locks fcntl() offsets
316 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
317 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
319 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
321 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
323 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
324 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
325 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
326 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
327 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
328 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
329 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
330 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
331 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
332 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
334 /* Time stuff we overload the bits a little */
335 #define AD_DATE_CREATE 0
336 #define AD_DATE_MODIFY 4
337 #define AD_DATE_BACKUP 8
338 #define AD_DATE_ACCESS 12
339 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
340 AD_DATE_BACKUP | AD_DATE_ACCESS)
341 #define AD_DATE_UNIX (1 << 10)
342 #define AD_DATE_START 0x80000000
343 #define AD_DATE_DELTA 946684800
344 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
345 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
347 #define AD_XATTR_HDR_MAGIC 0x41545452 /* 'ATTR' */
348 #define AD_XATTR_MAX_ENTRIES 1024 /* Some arbitrarily enforced limit */
349 #define AD_XATTR_HDR_SIZE 36
350 #define AD_XATTR_MAX_HDR_SIZE 65536
352 /* Accessor macros */
353 #define ad_getentrylen(ad,eid) ((ad)->ad_eid[(eid)].ade_len)
354 #define ad_getentryoff(ad,eid) ((ad)->ad_eid[(eid)].ade_off)
355 #define ad_setentrylen(ad,eid,len) ((ad)->ad_eid[(eid)].ade_len = (len))
356 #define ad_setentryoff(ad,eid,off) ((ad)->ad_eid[(eid)].ade_off = (off))
359 * Both struct ad_xattr_header and struct ad_xattr_entry describe the in memory
360 * representation as well as the on-disk format.
362 * The ad_xattr_header follows the FinderInfo data in the FinderInfo entry if
363 * the length of the FinderInfo entry is larger then 32 bytes. It is then
364 * preceeded with 2 bytes padding.
366 * Cf: https://opensource.apple.com/source/xnu/xnu-4570.1.46/bsd/vfs/vfs_xattr.c
369 struct ad_xattr_header
{
370 uint32_t adx_magic
; /* ATTR_HDR_MAGIC */
371 uint32_t adx_debug_tag
; /* for debugging == file id of owning file */
372 uint32_t adx_total_size
; /* file offset of end of attribute header + entries + data */
373 uint32_t adx_data_start
; /* file offset to attribute data area */
374 uint32_t adx_data_length
; /* length of attribute data area */
375 uint32_t adx_reserved
[3];
377 uint16_t adx_num_attrs
;
380 /* On-disk entries are aligned on 4 byte boundaries */
381 struct ad_xattr_entry
{
382 uint32_t adx_offset
; /* file offset to data */
383 uint32_t adx_length
; /* size of attribute data */
385 uint8_t adx_namelen
; /* included the NULL terminator */
386 char *adx_name
; /* NULL-terminated UTF-8 name */
395 vfs_handle_struct
*ad_handle
;
398 adouble_type_t ad_type
;
401 struct ad_entry ad_eid
[ADEID_MAX
];
403 struct ad_xattr_header adx_header
;
404 struct ad_xattr_entry
*adx_entries
;
407 struct ad_entry_order
{
408 uint32_t id
, offset
, len
;
411 /* Netatalk AppleDouble metadata xattr */
413 struct ad_entry_order entry_order_meta_xattr
[ADEID_NUM_XATTR
+ 1] = {
414 {ADEID_FINDERI
, ADEDOFF_FINDERI_XATTR
, ADEDLEN_FINDERI
},
415 {ADEID_COMMENT
, ADEDOFF_COMMENT_XATTR
, 0},
416 {ADEID_FILEDATESI
, ADEDOFF_FILEDATESI_XATTR
, ADEDLEN_FILEDATESI
},
417 {ADEID_AFPFILEI
, ADEDOFF_AFPFILEI_XATTR
, ADEDLEN_AFPFILEI
},
418 {ADEID_PRIVDEV
, ADEDOFF_PRIVDEV_XATTR
, 0},
419 {ADEID_PRIVINO
, ADEDOFF_PRIVINO_XATTR
, 0},
420 {ADEID_PRIVSYN
, ADEDOFF_PRIVSYN_XATTR
, 0},
421 {ADEID_PRIVID
, ADEDOFF_PRIVID_XATTR
, 0},
425 /* AppleDouble resource fork file (the ones prefixed by "._") */
427 struct ad_entry_order entry_order_dot_und
[ADEID_NUM_DOT_UND
+ 1] = {
428 {ADEID_FINDERI
, ADEDOFF_FINDERI_DOT_UND
, ADEDLEN_FINDERI
},
429 {ADEID_RFORK
, ADEDOFF_RFORK_DOT_UND
, 0},
434 * Fake AppleDouble entry oder for resource fork xattr. The xattr
435 * isn't an AppleDouble file, it simply contains the resource data,
436 * but in order to be able to use some API calls like ad_getentryoff()
437 * we build a fake/helper struct adouble with this entry order struct.
440 struct ad_entry_order entry_order_rsrc_xattr
[ADEID_NUM_RSRC_XATTR
+ 1] = {
445 /* Conversion from enumerated id to on-disk AppleDouble id */
446 #define AD_EID_DISK(a) (set_eid[a])
447 static const uint32_t set_eid
[] = {
448 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
449 AD_DEV
, AD_INO
, AD_SYN
, AD_ID
453 /* tcon config handle */
454 struct fruit_config_data
*config
;
456 /* Denote stream type, meta or rsrc */
461 * Forward declarations
463 static struct adouble
*ad_init(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
464 adouble_type_t type
);
465 static int ad_set(struct adouble
*ad
, const struct smb_filename
*smb_fname
);
466 static int ad_fset(struct adouble
*ad
, files_struct
*fsp
);
467 static int adouble_path(TALLOC_CTX
*ctx
,
468 const struct smb_filename
*smb_fname__in
,
469 struct smb_filename
**ppsmb_fname_out
);
472 * Return a pointer to an AppleDouble entry
474 * Returns NULL if the entry is not present
476 static char *ad_get_entry(const struct adouble
*ad
, int eid
)
478 off_t off
= ad_getentryoff(ad
, eid
);
479 size_t len
= ad_getentrylen(ad
, eid
);
481 if (off
== 0 || len
== 0) {
485 return ad
->ad_data
+ off
;
491 static int ad_getdate(const struct adouble
*ad
,
492 unsigned int dateoff
,
495 bool xlate
= (dateoff
& AD_DATE_UNIX
);
498 dateoff
&= AD_DATE_MASK
;
499 p
= ad_get_entry(ad
, ADEID_FILEDATESI
);
504 if (dateoff
> AD_DATE_ACCESS
) {
508 memcpy(date
, p
+ dateoff
, sizeof(uint32_t));
511 *date
= AD_DATE_TO_UNIX(*date
);
519 static int ad_setdate(struct adouble
*ad
, unsigned int dateoff
, uint32_t date
)
521 bool xlate
= (dateoff
& AD_DATE_UNIX
);
524 p
= ad_get_entry(ad
, ADEID_FILEDATESI
);
529 dateoff
&= AD_DATE_MASK
;
531 date
= AD_DATE_FROM_UNIX(date
);
534 if (dateoff
> AD_DATE_ACCESS
) {
538 memcpy(p
+ dateoff
, &date
, sizeof(date
));
545 * Map on-disk AppleDouble id to enumerated id
547 static uint32_t get_eid(uint32_t eid
)
555 return ADEID_PRIVDEV
;
557 return ADEID_PRIVINO
;
559 return ADEID_PRIVSYN
;
570 * Pack AppleDouble structure into data buffer
572 static bool ad_pack(struct adouble
*ad
)
579 bufsize
= talloc_get_size(ad
->ad_data
);
580 if (bufsize
< AD_DATASZ_DOT_UND
) {
581 DBG_ERR("bad buffer size [0x%" PRIx32
"]\n", bufsize
);
585 if (offset
+ ADEDLEN_MAGIC
< offset
||
586 offset
+ ADEDLEN_MAGIC
>= bufsize
) {
589 RSIVAL(ad
->ad_data
, offset
, ad
->ad_magic
);
590 offset
+= ADEDLEN_MAGIC
;
592 if (offset
+ ADEDLEN_VERSION
< offset
||
593 offset
+ ADEDLEN_VERSION
>= bufsize
) {
596 RSIVAL(ad
->ad_data
, offset
, ad
->ad_version
);
597 offset
+= ADEDLEN_VERSION
;
599 if (offset
+ ADEDLEN_FILLER
< offset
||
600 offset
+ ADEDLEN_FILLER
>= bufsize
) {
603 if (ad
->ad_type
== ADOUBLE_RSRC
) {
604 memcpy(ad
->ad_data
+ offset
, AD_FILLER_TAG
, ADEDLEN_FILLER
);
606 offset
+= ADEDLEN_FILLER
;
608 if (offset
+ ADEDLEN_NENTRIES
< offset
||
609 offset
+ ADEDLEN_NENTRIES
>= bufsize
) {
612 offset
+= ADEDLEN_NENTRIES
;
614 for (eid
= 0, nent
= 0; eid
< ADEID_MAX
; eid
++) {
615 if (ad
->ad_eid
[eid
].ade_off
== 0) {
617 * ade_off is also used as indicator whether a
618 * specific entry is used or not
623 if (offset
+ AD_ENTRY_LEN_EID
< offset
||
624 offset
+ AD_ENTRY_LEN_EID
>= bufsize
) {
627 RSIVAL(ad
->ad_data
, offset
, AD_EID_DISK(eid
));
628 offset
+= AD_ENTRY_LEN_EID
;
630 if (offset
+ AD_ENTRY_LEN_OFF
< offset
||
631 offset
+ AD_ENTRY_LEN_OFF
>= bufsize
) {
634 RSIVAL(ad
->ad_data
, offset
, ad
->ad_eid
[eid
].ade_off
);
635 offset
+= AD_ENTRY_LEN_OFF
;
637 if (offset
+ AD_ENTRY_LEN_LEN
< offset
||
638 offset
+ AD_ENTRY_LEN_LEN
>= bufsize
) {
641 RSIVAL(ad
->ad_data
, offset
, ad
->ad_eid
[eid
].ade_len
);
642 offset
+= AD_ENTRY_LEN_LEN
;
647 if (ADEDOFF_NENTRIES
+ 2 >= bufsize
) {
650 RSSVAL(ad
->ad_data
, ADEDOFF_NENTRIES
, nent
);
656 * Unpack an AppleDouble blob into a struct adoble
658 static bool ad_unpack(struct adouble
*ad
, const size_t nentries
,
661 size_t bufsize
= talloc_get_size(ad
->ad_data
);
663 uint32_t eid
, len
, off
;
666 * The size of the buffer ad->ad_data is checked when read, so
667 * we wouldn't have to check our own offsets, a few extra
668 * checks won't hurt though. We have to check the offsets we
669 * read from the buffer anyway.
672 if (bufsize
< (AD_HEADER_LEN
+ (AD_ENTRY_LEN
* nentries
))) {
673 DEBUG(1, ("bad size\n"));
677 ad
->ad_magic
= RIVAL(ad
->ad_data
, 0);
678 ad
->ad_version
= RIVAL(ad
->ad_data
, ADEDOFF_VERSION
);
679 if ((ad
->ad_magic
!= AD_MAGIC
) || (ad
->ad_version
!= AD_VERSION
)) {
680 DEBUG(1, ("wrong magic or version\n"));
684 adentries
= RSVAL(ad
->ad_data
, ADEDOFF_NENTRIES
);
685 if (adentries
!= nentries
) {
686 DEBUG(1, ("invalid number of entries: %zu\n",
691 /* now, read in the entry bits */
692 for (i
= 0; i
< adentries
; i
++) {
693 eid
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
));
695 off
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
) + 4);
696 len
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
) + 8);
698 if (!eid
|| eid
> ADEID_MAX
) {
699 DEBUG(1, ("bogus eid %d\n", eid
));
704 * All entries other than the resource fork are
705 * expected to be read into the ad_data buffer, so
706 * ensure the specified offset is within that bound
708 if ((off
> bufsize
) && (eid
!= ADEID_RFORK
)) {
709 DEBUG(1, ("bogus eid %d: off: %" PRIu32
", len: %" PRIu32
"\n",
715 * All entries besides FinderInfo and resource fork
716 * must fit into the buffer. FinderInfo is special as
717 * it may be larger then the default 32 bytes (if it
718 * contains marshalled xattrs), but we will fixup that
719 * in ad_convert(). And the resource fork is never
720 * accessed directly by the ad_data buf (also see
721 * comment above) anyway.
723 if ((eid
!= ADEID_RFORK
) &&
724 (eid
!= ADEID_FINDERI
) &&
725 ((off
+ len
) > bufsize
)) {
726 DEBUG(1, ("bogus eid %d: off: %" PRIu32
", len: %" PRIu32
"\n",
732 * That would be obviously broken
734 if (off
> filesize
) {
735 DEBUG(1, ("bogus eid %d: off: %" PRIu32
", len: %" PRIu32
"\n",
741 * Check for any entry that has its end beyond the
744 if (off
+ len
< off
) {
745 DEBUG(1, ("offset wrap in eid %d: off: %" PRIu32
746 ", len: %" PRIu32
"\n",
751 if (off
+ len
> filesize
) {
753 * If this is the resource fork entry, we fix
754 * up the length, for any other entry we bail
757 if (eid
!= ADEID_RFORK
) {
758 DEBUG(1, ("bogus eid %d: off: %" PRIu32
759 ", len: %" PRIu32
"\n",
765 * Fixup the resource fork entry by limiting
766 * the size to entryoffset - filesize.
768 len
= filesize
- off
;
769 DEBUG(1, ("Limiting ADEID_RFORK: off: %" PRIu32
770 ", len: %" PRIu32
"\n", off
, len
));
773 ad
->ad_eid
[eid
].ade_off
= off
;
774 ad
->ad_eid
[eid
].ade_len
= len
;
781 * Convert from Apple's ._ file to Netatalk
783 * Apple's AppleDouble may contain a FinderInfo entry longer then 32
784 * bytes containing packed xattrs. Netatalk can't deal with that, so
785 * we simply discard the packed xattrs.
787 * @return -1 in case an error occurred, 0 if no conversion was done, 1
790 static int ad_convert(struct adouble
*ad
, int fd
)
793 char *map
= MAP_FAILED
;
796 origlen
= ad_getentryoff(ad
, ADEID_RFORK
) +
797 ad_getentrylen(ad
, ADEID_RFORK
);
799 /* FIXME: direct use of mmap(), vfs_aio_fork does it too */
800 map
= mmap(NULL
, origlen
, PROT_READ
|PROT_WRITE
, MAP_SHARED
, fd
, 0);
801 if (map
== MAP_FAILED
) {
802 DEBUG(2, ("mmap AppleDouble: %s\n", strerror(errno
)));
807 if (ad_getentrylen(ad
, ADEID_RFORK
) > 0) {
808 memmove(map
+ ad_getentryoff(ad
, ADEID_FINDERI
) + ADEDLEN_FINDERI
,
809 map
+ ad_getentryoff(ad
, ADEID_RFORK
),
810 ad_getentrylen(ad
, ADEID_RFORK
));
813 ad_setentrylen(ad
, ADEID_FINDERI
, ADEDLEN_FINDERI
);
814 ad_setentryoff(ad
, ADEID_RFORK
,
815 ad_getentryoff(ad
, ADEID_FINDERI
) + ADEDLEN_FINDERI
);
818 * FIXME: direct ftruncate(), but we don't have a fsp for the
821 rc
= ftruncate(fd
, ad_getentryoff(ad
, ADEID_RFORK
)
822 + ad_getentrylen(ad
, ADEID_RFORK
));
825 if (map
!= MAP_FAILED
) {
826 munmap(map
, origlen
);
832 * Read and parse Netatalk AppleDouble metadata xattr
834 static ssize_t
ad_read_meta(struct adouble
*ad
,
835 const struct smb_filename
*smb_fname
)
841 DEBUG(10, ("reading meta xattr for %s\n", smb_fname
->base_name
));
843 ealen
= SMB_VFS_GETXATTR(ad
->ad_handle
->conn
, smb_fname
,
844 AFPINFO_EA_NETATALK
, ad
->ad_data
,
850 if (errno
== ENOATTR
) {
856 DEBUG(2, ("error reading meta xattr: %s\n",
862 if (ealen
!= AD_DATASZ_XATTR
) {
863 DEBUG(2, ("bad size %zd\n", ealen
));
869 /* Now parse entries */
870 ok
= ad_unpack(ad
, ADEID_NUM_XATTR
, AD_DATASZ_XATTR
);
872 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
878 if (!ad_getentryoff(ad
, ADEID_FINDERI
)
879 || !ad_getentryoff(ad
, ADEID_COMMENT
)
880 || !ad_getentryoff(ad
, ADEID_FILEDATESI
)
881 || !ad_getentryoff(ad
, ADEID_AFPFILEI
)
882 || !ad_getentryoff(ad
, ADEID_PRIVDEV
)
883 || !ad_getentryoff(ad
, ADEID_PRIVINO
)
884 || !ad_getentryoff(ad
, ADEID_PRIVSYN
)
885 || !ad_getentryoff(ad
, ADEID_PRIVID
)) {
886 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
893 DEBUG(10, ("reading meta xattr for %s, rc: %d\n",
894 smb_fname
->base_name
, rc
));
898 if (errno
== EINVAL
) {
900 removexattr(smb_fname
->base_name
, AFPINFO_EA_NETATALK
);
908 static int ad_open_rsrc_xattr(const struct smb_filename
*smb_fname
,
913 /* FIXME: direct Solaris xattr syscall */
914 return attropen(smb_fname
->base_name
,
915 AFPRESOURCE_EA_NETATALK
, flags
, mode
);
922 static int ad_open_rsrc_adouble(const struct smb_filename
*smb_fname
,
928 struct smb_filename
*adp_smb_fname
= NULL
;
930 ret
= adouble_path(talloc_tos(), smb_fname
, &adp_smb_fname
);
935 fd
= open(adp_smb_fname
->base_name
, flags
, mode
);
936 TALLOC_FREE(adp_smb_fname
);
941 static int ad_open_rsrc(vfs_handle_struct
*handle
,
942 const struct smb_filename
*smb_fname
,
946 struct fruit_config_data
*config
= NULL
;
949 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
950 struct fruit_config_data
, return -1);
952 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
953 fd
= ad_open_rsrc_xattr(smb_fname
, flags
, mode
);
955 fd
= ad_open_rsrc_adouble(smb_fname
, flags
, mode
);
962 * Here's the deal: for ADOUBLE_META we can do without an fd as we can issue
963 * path based xattr calls. For ADOUBLE_RSRC however we need a full-fledged fd
964 * for file IO on the ._ file.
966 static int ad_open(vfs_handle_struct
*handle
,
969 const struct smb_filename
*smb_fname
,
975 DBG_DEBUG("Path [%s] type [%s]\n", smb_fname
->base_name
,
976 ad
->ad_type
== ADOUBLE_META
? "meta" : "rsrc");
978 if (ad
->ad_type
== ADOUBLE_META
) {
982 if ((fsp
!= NULL
) && (fsp
->fh
!= NULL
) && (fsp
->fh
->fd
!= -1)) {
983 ad
->ad_fd
= fsp
->fh
->fd
;
984 ad
->ad_opened
= false;
988 fd
= ad_open_rsrc(handle
, smb_fname
, flags
, mode
);
992 ad
->ad_opened
= true;
995 DBG_DEBUG("Path [%s] type [%s] fd [%d]\n",
996 smb_fname
->base_name
,
997 ad
->ad_type
== ADOUBLE_META
? "meta" : "rsrc", fd
);
1002 static ssize_t
ad_read_rsrc_xattr(struct adouble
*ad
)
1007 /* FIXME: direct sys_fstat(), don't have an fsp */
1008 ret
= sys_fstat(ad
->ad_fd
, &st
,
1009 lp_fake_directory_create_times(
1010 SNUM(ad
->ad_handle
->conn
)));
1015 ad_setentrylen(ad
, ADEID_RFORK
, st
.st_ex_size
);
1016 return st
.st_ex_size
;
1019 static ssize_t
ad_read_rsrc_adouble(struct adouble
*ad
,
1020 const struct smb_filename
*smb_fname
)
1022 struct adouble
*meta_ad
= NULL
;
1023 SMB_STRUCT_STAT sbuf
;
1025 char *p_meta_ad
= NULL
;
1031 ret
= sys_fstat(ad
->ad_fd
, &sbuf
, lp_fake_directory_create_times(
1032 SNUM(ad
->ad_handle
->conn
)));
1038 * AppleDouble file header content and size, two cases:
1040 * - without xattrs it is exactly AD_DATASZ_DOT_UND (82) bytes large
1041 * - with embedded xattrs it can be larger, up to AD_XATTR_MAX_HDR_SIZE
1043 * Read as much as we can up to AD_XATTR_MAX_HDR_SIZE.
1045 size
= sbuf
.st_ex_size
;
1046 if (size
> talloc_array_length(ad
->ad_data
)) {
1047 if (size
> AD_XATTR_MAX_HDR_SIZE
) {
1048 size
= AD_XATTR_MAX_HDR_SIZE
;
1050 p_ad
= talloc_realloc(ad
, ad
->ad_data
, char, size
);
1057 len
= sys_pread(ad
->ad_fd
, ad
->ad_data
,
1058 talloc_array_length(ad
->ad_data
), 0);
1059 if (len
!= talloc_array_length(ad
->ad_data
)) {
1060 DBG_NOTICE("%s %s: bad size: %zd\n",
1061 smb_fname
->base_name
, strerror(errno
), len
);
1065 /* Now parse entries */
1066 ok
= ad_unpack(ad
, ADEID_NUM_DOT_UND
, sbuf
.st_ex_size
);
1068 DBG_ERR("invalid AppleDouble resource %s\n",
1069 smb_fname
->base_name
);
1074 if ((ad_getentryoff(ad
, ADEID_FINDERI
) != ADEDOFF_FINDERI_DOT_UND
)
1075 || (ad_getentrylen(ad
, ADEID_FINDERI
) < ADEDLEN_FINDERI
)
1076 || (ad_getentryoff(ad
, ADEID_RFORK
) < ADEDOFF_RFORK_DOT_UND
)) {
1077 DBG_ERR("invalid AppleDouble resource %s\n",
1078 smb_fname
->base_name
);
1083 if (ad_getentrylen(ad
, ADEID_FINDERI
) == ADEDLEN_FINDERI
) {
1088 * Try to fixup AppleDouble files created by OS X with xattrs
1089 * appended to the ADEID_FINDERI entry. We simply remove the
1090 * xattrs blob, this means any fancy xattr that was stored
1094 ret
= ad_convert(ad
, ad
->ad_fd
);
1096 DBG_WARNING("Failed to convert [%s]\n", smb_fname
->base_name
);
1102 DBG_WARNING("ad_pack [%s] failed\n", smb_fname
->base_name
);
1106 len
= sys_pwrite(ad
->ad_fd
, ad
->ad_data
, AD_DATASZ_DOT_UND
, 0);
1107 if (len
!= AD_DATASZ_DOT_UND
) {
1108 DBG_ERR("%s: bad size: %zd\n", smb_fname
->base_name
, len
);
1112 meta_ad
= ad_init(talloc_tos(), ad
->ad_handle
, ADOUBLE_META
);
1113 if (meta_ad
== NULL
) {
1117 p_ad
= ad_get_entry(ad
, ADEID_FINDERI
);
1119 TALLOC_FREE(meta_ad
);
1122 p_meta_ad
= ad_get_entry(meta_ad
, ADEID_FINDERI
);
1123 if (p_meta_ad
== NULL
) {
1124 TALLOC_FREE(meta_ad
);
1128 memcpy(p_meta_ad
, p_ad
, ADEDLEN_FINDERI
);
1130 ret
= ad_set(meta_ad
, smb_fname
);
1131 TALLOC_FREE(meta_ad
);
1140 * Read and parse resource fork, either ._ AppleDouble file or xattr
1142 static ssize_t
ad_read_rsrc(struct adouble
*ad
,
1143 const struct smb_filename
*smb_fname
)
1145 struct fruit_config_data
*config
= NULL
;
1148 SMB_VFS_HANDLE_GET_DATA(ad
->ad_handle
, config
,
1149 struct fruit_config_data
, return -1);
1151 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
1152 len
= ad_read_rsrc_xattr(ad
);
1154 len
= ad_read_rsrc_adouble(ad
, smb_fname
);
1161 * Read and unpack an AppleDouble metadata xattr or resource
1163 static ssize_t
ad_read(struct adouble
*ad
, const struct smb_filename
*smb_fname
)
1165 switch (ad
->ad_type
) {
1167 return ad_read_meta(ad
, smb_fname
);
1169 return ad_read_rsrc(ad
, smb_fname
);
1175 static int adouble_destructor(struct adouble
*ad
)
1177 if ((ad
->ad_fd
!= -1) && ad
->ad_opened
) {
1185 * Allocate a struct adouble without initialiing it
1187 * The struct is either hang of the fsp extension context or if fsp is
1190 * @param[in] ctx talloc context
1191 * @param[in] handle vfs handle
1192 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1194 * @return adouble handle
1196 static struct adouble
*ad_alloc(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
1197 adouble_type_t type
)
1202 struct fruit_config_data
*config
;
1204 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1205 struct fruit_config_data
, return NULL
);
1209 adsize
= AD_DATASZ_XATTR
;
1212 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
1213 adsize
= AD_DATASZ_DOT_UND
;
1220 ad
= talloc_zero(ctx
, struct adouble
);
1227 ad
->ad_data
= talloc_zero_array(ad
, char, adsize
);
1228 if (ad
->ad_data
== NULL
) {
1234 ad
->ad_handle
= handle
;
1236 ad
->ad_magic
= AD_MAGIC
;
1237 ad
->ad_version
= AD_VERSION
;
1240 talloc_set_destructor(ad
, adouble_destructor
);
1250 * Allocate and initialize a new struct adouble
1252 * @param[in] ctx talloc context
1253 * @param[in] handle vfs handle
1254 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1256 * @return adouble handle, initialized
1258 static struct adouble
*ad_init(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
1259 adouble_type_t type
)
1262 const struct ad_entry_order
*eid
;
1263 struct adouble
*ad
= NULL
;
1264 struct fruit_config_data
*config
;
1265 time_t t
= time(NULL
);
1267 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1268 struct fruit_config_data
, return NULL
);
1272 eid
= entry_order_meta_xattr
;
1275 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
1276 eid
= entry_order_dot_und
;
1278 eid
= entry_order_rsrc_xattr
;
1285 ad
= ad_alloc(ctx
, handle
, type
);
1291 ad
->ad_eid
[eid
->id
].ade_off
= eid
->offset
;
1292 ad
->ad_eid
[eid
->id
].ade_len
= eid
->len
;
1296 /* put something sane in the date fields */
1297 ad_setdate(ad
, AD_DATE_CREATE
| AD_DATE_UNIX
, t
);
1298 ad_setdate(ad
, AD_DATE_MODIFY
| AD_DATE_UNIX
, t
);
1299 ad_setdate(ad
, AD_DATE_ACCESS
| AD_DATE_UNIX
, t
);
1300 ad_setdate(ad
, AD_DATE_BACKUP
, htonl(AD_DATE_START
));
1308 static struct adouble
*ad_get_internal(TALLOC_CTX
*ctx
,
1309 vfs_handle_struct
*handle
,
1311 const struct smb_filename
*smb_fname
,
1312 adouble_type_t type
)
1316 struct adouble
*ad
= NULL
;
1320 smb_fname
= fsp
->base_fsp
->fsp_name
;
1323 DEBUG(10, ("ad_get(%s) called for %s\n",
1324 type
== ADOUBLE_META
? "meta" : "rsrc",
1325 smb_fname
->base_name
));
1327 ad
= ad_alloc(ctx
, handle
, type
);
1333 /* Try rw first so we can use the fd in ad_convert() */
1336 rc
= ad_open(handle
, ad
, fsp
, smb_fname
, mode
, 0);
1337 if (rc
== -1 && ((errno
== EROFS
) || (errno
== EACCES
))) {
1339 rc
= ad_open(handle
, ad
, fsp
, smb_fname
, mode
, 0);
1342 DBG_DEBUG("ad_open [%s] error [%s]\n",
1343 smb_fname
->base_name
, strerror(errno
));
1348 len
= ad_read(ad
, smb_fname
);
1350 DEBUG(10, ("error reading AppleDouble for %s\n",
1351 smb_fname
->base_name
));
1357 DEBUG(10, ("ad_get(%s) for %s returning %d\n",
1358 type
== ADOUBLE_META
? "meta" : "rsrc",
1359 smb_fname
->base_name
, rc
));
1368 * Return AppleDouble data for a file
1370 * @param[in] ctx talloc context
1371 * @param[in] handle vfs handle
1372 * @param[in] smb_fname pathname to file or directory
1373 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1375 * @return talloced struct adouble or NULL on error
1377 static struct adouble
*ad_get(TALLOC_CTX
*ctx
,
1378 vfs_handle_struct
*handle
,
1379 const struct smb_filename
*smb_fname
,
1380 adouble_type_t type
)
1382 return ad_get_internal(ctx
, handle
, NULL
, smb_fname
, type
);
1386 * Return AppleDouble data for a file
1388 * @param[in] ctx talloc context
1389 * @param[in] handle vfs handle
1390 * @param[in] fsp fsp to use for IO
1391 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1393 * @return talloced struct adouble or NULL on error
1395 static struct adouble
*ad_fget(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
1396 files_struct
*fsp
, adouble_type_t type
)
1398 return ad_get_internal(ctx
, handle
, fsp
, NULL
, type
);
1402 * Set AppleDouble metadata on a file or directory
1404 * @param[in] ad adouble handle
1406 * @param[in] smb_fname pathname to file or directory
1408 * @return status code, 0 means success
1410 static int ad_set(struct adouble
*ad
, const struct smb_filename
*smb_fname
)
1415 DBG_DEBUG("Path [%s]\n", smb_fname
->base_name
);
1417 if (ad
->ad_type
!= ADOUBLE_META
) {
1418 DBG_ERR("ad_set on [%s] used with ADOUBLE_RSRC\n",
1419 smb_fname
->base_name
);
1428 ret
= SMB_VFS_SETXATTR(ad
->ad_handle
->conn
,
1430 AFPINFO_EA_NETATALK
,
1432 AD_DATASZ_XATTR
, 0);
1434 DBG_DEBUG("Path [%s] ret [%d]\n", smb_fname
->base_name
, ret
);
1440 * Set AppleDouble metadata on a file or directory
1442 * @param[in] ad adouble handle
1443 * @param[in] fsp file handle
1445 * @return status code, 0 means success
1447 static int ad_fset(struct adouble
*ad
, files_struct
*fsp
)
1453 DBG_DEBUG("Path [%s]\n", fsp_str_dbg(fsp
));
1456 || (fsp
->fh
== NULL
)
1457 || (fsp
->fh
->fd
== -1))
1459 smb_panic("bad fsp");
1467 switch (ad
->ad_type
) {
1469 rc
= SMB_VFS_NEXT_SETXATTR(ad
->ad_handle
,
1471 AFPINFO_EA_NETATALK
,
1473 AD_DATASZ_XATTR
, 0);
1477 len
= SMB_VFS_NEXT_PWRITE(ad
->ad_handle
,
1482 if (len
!= AD_DATASZ_DOT_UND
) {
1483 DBG_ERR("short write on %s: %zd", fsp_str_dbg(fsp
), len
);
1493 DBG_DEBUG("Path [%s] rc [%d]\n", fsp_str_dbg(fsp
), rc
);
1498 /*****************************************************************************
1500 *****************************************************************************/
1502 static bool is_afpinfo_stream(const struct smb_filename
*smb_fname
)
1504 if (strncasecmp_m(smb_fname
->stream_name
,
1505 AFPINFO_STREAM_NAME
,
1506 strlen(AFPINFO_STREAM_NAME
)) == 0) {
1512 static bool is_afpresource_stream(const struct smb_filename
*smb_fname
)
1514 if (strncasecmp_m(smb_fname
->stream_name
,
1515 AFPRESOURCE_STREAM_NAME
,
1516 strlen(AFPRESOURCE_STREAM_NAME
)) == 0) {
1523 * Test whether stream is an Apple stream, not used atm
1526 static bool is_apple_stream(const struct smb_filename
*smb_fname
)
1528 if (is_afpinfo_stream(smb_fname
)) {
1531 if (is_afpresource_stream(smb_fname
)) {
1539 * Initialize config struct from our smb.conf config parameters
1541 static int init_fruit_config(vfs_handle_struct
*handle
)
1543 struct fruit_config_data
*config
;
1546 config
= talloc_zero(handle
->conn
, struct fruit_config_data
);
1548 DEBUG(1, ("talloc_zero() failed\n"));
1554 * Versions up to Samba 4.5.x had a spelling bug in the
1555 * fruit:resource option calling lp_parm_enum with
1556 * "res*s*ource" (ie two s).
1558 * In Samba 4.6 we accept both the wrong and the correct
1559 * spelling, in Samba 4.7 the bad spelling will be removed.
1561 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1562 "ressource", fruit_rsrc
, FRUIT_RSRC_ADFILE
);
1563 if (enumval
== -1) {
1564 DEBUG(1, ("value for %s: resource type unknown\n",
1565 FRUIT_PARAM_TYPE_NAME
));
1568 config
->rsrc
= (enum fruit_rsrc
)enumval
;
1570 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1571 "resource", fruit_rsrc
, enumval
);
1572 if (enumval
== -1) {
1573 DEBUG(1, ("value for %s: resource type unknown\n",
1574 FRUIT_PARAM_TYPE_NAME
));
1577 config
->rsrc
= (enum fruit_rsrc
)enumval
;
1579 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1580 "metadata", fruit_meta
, FRUIT_META_NETATALK
);
1581 if (enumval
== -1) {
1582 DEBUG(1, ("value for %s: metadata type unknown\n",
1583 FRUIT_PARAM_TYPE_NAME
));
1586 config
->meta
= (enum fruit_meta
)enumval
;
1588 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1589 "locking", fruit_locking
, FRUIT_LOCKING_NONE
);
1590 if (enumval
== -1) {
1591 DEBUG(1, ("value for %s: locking type unknown\n",
1592 FRUIT_PARAM_TYPE_NAME
));
1595 config
->locking
= (enum fruit_locking
)enumval
;
1597 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1598 "encoding", fruit_encoding
, FRUIT_ENC_PRIVATE
);
1599 if (enumval
== -1) {
1600 DEBUG(1, ("value for %s: encoding type unknown\n",
1601 FRUIT_PARAM_TYPE_NAME
));
1604 config
->encoding
= (enum fruit_encoding
)enumval
;
1606 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
1607 config
->veto_appledouble
= lp_parm_bool(SNUM(handle
->conn
),
1608 FRUIT_PARAM_TYPE_NAME
,
1613 config
->use_aapl
= lp_parm_bool(
1614 -1, FRUIT_PARAM_TYPE_NAME
, "aapl", true);
1616 config
->unix_info_enabled
= lp_parm_bool(
1617 -1, FRUIT_PARAM_TYPE_NAME
, "nfs_aces", true);
1619 config
->use_copyfile
= lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME
,
1622 config
->posix_rename
= lp_parm_bool(
1623 SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
, "posix_rename", true);
1625 config
->aapl_zero_file_id
=
1626 lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME
, "zero_file_id", true);
1628 config
->readdir_attr_rsize
= lp_parm_bool(
1629 SNUM(handle
->conn
), "readdir_attr", "aapl_rsize", true);
1631 config
->readdir_attr_finder_info
= lp_parm_bool(
1632 SNUM(handle
->conn
), "readdir_attr", "aapl_finder_info", true);
1634 config
->readdir_attr_max_access
= lp_parm_bool(
1635 SNUM(handle
->conn
), "readdir_attr", "aapl_max_access", true);
1637 config
->model
= lp_parm_const_string(
1638 -1, FRUIT_PARAM_TYPE_NAME
, "model", "MacSamba");
1640 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1641 NULL
, struct fruit_config_data
,
1648 * Prepend "._" to a basename
1649 * Return a new struct smb_filename with stream_name == NULL.
1651 static int adouble_path(TALLOC_CTX
*ctx
,
1652 const struct smb_filename
*smb_fname_in
,
1653 struct smb_filename
**pp_smb_fname_out
)
1657 struct smb_filename
*smb_fname
= cp_smb_filename(ctx
,
1660 if (smb_fname
== NULL
) {
1664 /* We need streamname to be NULL */
1665 TALLOC_FREE(smb_fname
->stream_name
);
1667 /* And we're replacing base_name. */
1668 TALLOC_FREE(smb_fname
->base_name
);
1670 if (!parent_dirname(smb_fname
, smb_fname_in
->base_name
,
1672 TALLOC_FREE(smb_fname
);
1676 smb_fname
->base_name
= talloc_asprintf(smb_fname
,
1677 "%s/._%s", parent
, base
);
1678 if (smb_fname
->base_name
== NULL
) {
1679 TALLOC_FREE(smb_fname
);
1683 *pp_smb_fname_out
= smb_fname
;
1689 * Allocate and initialize an AfpInfo struct
1691 static AfpInfo
*afpinfo_new(TALLOC_CTX
*ctx
)
1693 AfpInfo
*ai
= talloc_zero(ctx
, AfpInfo
);
1697 ai
->afpi_Signature
= AFP_Signature
;
1698 ai
->afpi_Version
= AFP_Version
;
1699 ai
->afpi_BackupTime
= AD_DATE_START
;
1704 * Pack an AfpInfo struct into a buffer
1706 * Buffer size must be at least AFP_INFO_SIZE
1707 * Returns size of packed buffer
1709 static ssize_t
afpinfo_pack(const AfpInfo
*ai
, char *buf
)
1711 memset(buf
, 0, AFP_INFO_SIZE
);
1713 RSIVAL(buf
, 0, ai
->afpi_Signature
);
1714 RSIVAL(buf
, 4, ai
->afpi_Version
);
1715 RSIVAL(buf
, 12, ai
->afpi_BackupTime
);
1716 memcpy(buf
+ 16, ai
->afpi_FinderInfo
, sizeof(ai
->afpi_FinderInfo
));
1718 return AFP_INFO_SIZE
;
1722 * Unpack a buffer into a AfpInfo structure
1724 * Buffer size must be at least AFP_INFO_SIZE
1725 * Returns allocated AfpInfo struct
1727 static AfpInfo
*afpinfo_unpack(TALLOC_CTX
*ctx
, const void *data
)
1729 AfpInfo
*ai
= talloc_zero(ctx
, AfpInfo
);
1734 ai
->afpi_Signature
= RIVAL(data
, 0);
1735 ai
->afpi_Version
= RIVAL(data
, 4);
1736 ai
->afpi_BackupTime
= RIVAL(data
, 12);
1737 memcpy(ai
->afpi_FinderInfo
, (const char *)data
+ 16,
1738 sizeof(ai
->afpi_FinderInfo
));
1740 if (ai
->afpi_Signature
!= AFP_Signature
1741 || ai
->afpi_Version
!= AFP_Version
) {
1742 DEBUG(1, ("Bad AfpInfo signature or version\n"));
1750 * Fake an inode number from the md5 hash of the (xattr) name
1752 static SMB_INO_T
fruit_inode(const SMB_STRUCT_STAT
*sbuf
, const char *sname
)
1755 unsigned char hash
[16];
1759 upper_sname
= talloc_strdup_upper(talloc_tos(), sname
);
1760 SMB_ASSERT(upper_sname
!= NULL
);
1763 MD5Update(&ctx
, (const unsigned char *)&(sbuf
->st_ex_dev
),
1764 sizeof(sbuf
->st_ex_dev
));
1765 MD5Update(&ctx
, (const unsigned char *)&(sbuf
->st_ex_ino
),
1766 sizeof(sbuf
->st_ex_ino
));
1767 MD5Update(&ctx
, (unsigned char *)upper_sname
,
1768 talloc_get_size(upper_sname
)-1);
1769 MD5Final(hash
, &ctx
);
1771 TALLOC_FREE(upper_sname
);
1773 /* Hopefully all the variation is in the lower 4 (or 8) bytes! */
1774 memcpy(&result
, hash
, sizeof(result
));
1776 DEBUG(10, ("fruit_inode \"%s\": ino=0x%llu\n",
1777 sname
, (unsigned long long)result
));
1782 static bool add_fruit_stream(TALLOC_CTX
*mem_ctx
, unsigned int *num_streams
,
1783 struct stream_struct
**streams
,
1784 const char *name
, off_t size
,
1787 struct stream_struct
*tmp
;
1789 tmp
= talloc_realloc(mem_ctx
, *streams
, struct stream_struct
,
1795 tmp
[*num_streams
].name
= talloc_asprintf(tmp
, "%s:$DATA", name
);
1796 if (tmp
[*num_streams
].name
== NULL
) {
1800 tmp
[*num_streams
].size
= size
;
1801 tmp
[*num_streams
].alloc_size
= alloc_size
;
1808 static bool filter_empty_rsrc_stream(unsigned int *num_streams
,
1809 struct stream_struct
**streams
)
1811 struct stream_struct
*tmp
= *streams
;
1814 if (*num_streams
== 0) {
1818 for (i
= 0; i
< *num_streams
; i
++) {
1819 if (strequal_m(tmp
[i
].name
, AFPRESOURCE_STREAM
)) {
1824 if (i
== *num_streams
) {
1828 if (tmp
[i
].size
> 0) {
1832 TALLOC_FREE(tmp
[i
].name
);
1833 if (*num_streams
- 1 > i
) {
1834 memmove(&tmp
[i
], &tmp
[i
+1],
1835 (*num_streams
- i
- 1) * sizeof(struct stream_struct
));
1842 static bool del_fruit_stream(TALLOC_CTX
*mem_ctx
, unsigned int *num_streams
,
1843 struct stream_struct
**streams
,
1846 struct stream_struct
*tmp
= *streams
;
1849 if (*num_streams
== 0) {
1853 for (i
= 0; i
< *num_streams
; i
++) {
1854 if (strequal_m(tmp
[i
].name
, name
)) {
1859 if (i
== *num_streams
) {
1863 TALLOC_FREE(tmp
[i
].name
);
1864 if (*num_streams
- 1 > i
) {
1865 memmove(&tmp
[i
], &tmp
[i
+1],
1866 (*num_streams
- i
- 1) * sizeof(struct stream_struct
));
1873 static bool ad_empty_finderinfo(const struct adouble
*ad
)
1876 char emptybuf
[ADEDLEN_FINDERI
] = {0};
1879 fi
= ad_get_entry(ad
, ADEID_FINDERI
);
1881 DBG_ERR("Missing FinderInfo in struct adouble [%p]\n", ad
);
1885 cmp
= memcmp(emptybuf
, fi
, ADEDLEN_FINDERI
);
1889 static bool ai_empty_finderinfo(const AfpInfo
*ai
)
1892 char emptybuf
[ADEDLEN_FINDERI
] = {0};
1894 cmp
= memcmp(emptybuf
, &ai
->afpi_FinderInfo
[0], ADEDLEN_FINDERI
);
1899 * Update btime with btime from Netatalk
1901 static void update_btime(vfs_handle_struct
*handle
,
1902 struct smb_filename
*smb_fname
)
1905 struct timespec creation_time
= {0};
1907 struct fruit_config_data
*config
= NULL
;
1909 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
1912 switch (config
->meta
) {
1913 case FRUIT_META_STREAM
:
1915 case FRUIT_META_NETATALK
:
1919 DBG_ERR("Unexpected meta config [%d]\n", config
->meta
);
1923 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_META
);
1927 if (ad_getdate(ad
, AD_DATE_UNIX
| AD_DATE_CREATE
, &t
) != 0) {
1933 creation_time
.tv_sec
= convert_uint32_t_to_time_t(t
);
1934 update_stat_ex_create_time(&smb_fname
->st
, creation_time
);
1940 * Map an access mask to a Netatalk single byte byte range lock
1942 static off_t
access_to_netatalk_brl(enum apple_fork fork_type
,
1943 uint32_t access_mask
)
1947 switch (access_mask
) {
1948 case FILE_READ_DATA
:
1949 offset
= AD_FILELOCK_OPEN_RD
;
1952 case FILE_WRITE_DATA
:
1953 case FILE_APPEND_DATA
:
1954 offset
= AD_FILELOCK_OPEN_WR
;
1958 offset
= AD_FILELOCK_OPEN_NONE
;
1962 if (fork_type
== APPLE_FORK_RSRC
) {
1963 if (offset
== AD_FILELOCK_OPEN_NONE
) {
1964 offset
= AD_FILELOCK_RSRC_OPEN_NONE
;
1974 * Map a deny mode to a Netatalk brl
1976 static off_t
denymode_to_netatalk_brl(enum apple_fork fork_type
,
1981 switch (deny_mode
) {
1983 offset
= AD_FILELOCK_DENY_RD
;
1987 offset
= AD_FILELOCK_DENY_WR
;
1991 smb_panic("denymode_to_netatalk_brl: bad deny mode\n");
1994 if (fork_type
== APPLE_FORK_RSRC
) {
2002 * Call fcntl() with an exclusive F_GETLK request in order to
2003 * determine if there's an exisiting shared lock
2005 * @return true if the requested lock was found or any error occurred
2006 * false if the lock was not found
2008 static bool test_netatalk_lock(files_struct
*fsp
, off_t in_offset
)
2011 off_t offset
= in_offset
;
2016 result
= SMB_VFS_GETLOCK(fsp
, &offset
, &len
, &type
, &pid
);
2017 if (result
== false) {
2021 if (type
!= F_UNLCK
) {
2028 static NTSTATUS
fruit_check_access(vfs_handle_struct
*handle
,
2030 uint32_t access_mask
,
2033 NTSTATUS status
= NT_STATUS_OK
;
2034 struct byte_range_lock
*br_lck
= NULL
;
2035 bool open_for_reading
, open_for_writing
, deny_read
, deny_write
;
2037 bool have_read
= false;
2040 /* FIXME: hardcoded data fork, add resource fork */
2041 enum apple_fork fork_type
= APPLE_FORK_DATA
;
2043 DEBUG(10, ("fruit_check_access: %s, am: %s/%s, dm: %s/%s\n",
2045 access_mask
& FILE_READ_DATA
? "READ" :"-",
2046 access_mask
& FILE_WRITE_DATA
? "WRITE" : "-",
2047 deny_mode
& DENY_READ
? "DENY_READ" : "-",
2048 deny_mode
& DENY_WRITE
? "DENY_WRITE" : "-"));
2050 if (fsp
->fh
->fd
== -1) {
2051 return NT_STATUS_OK
;
2054 flags
= fcntl(fsp
->fh
->fd
, F_GETFL
);
2056 DBG_ERR("fcntl get flags [%s] fd [%d] failed [%s]\n",
2057 fsp_str_dbg(fsp
), fsp
->fh
->fd
, strerror(errno
));
2058 return map_nt_error_from_unix(errno
);
2061 if (flags
& (O_RDONLY
|O_RDWR
)) {
2063 * Applying fcntl read locks requires an fd opened for
2064 * reading. This means we won't be applying locks for
2065 * files openend write-only, but what can we do...
2071 * Check read access and deny read mode
2073 if ((access_mask
& FILE_READ_DATA
) || (deny_mode
& DENY_READ
)) {
2075 open_for_reading
= test_netatalk_lock(
2076 fsp
, access_to_netatalk_brl(fork_type
, FILE_READ_DATA
));
2078 deny_read
= test_netatalk_lock(
2079 fsp
, denymode_to_netatalk_brl(fork_type
, DENY_READ
));
2081 DEBUG(10, ("read: %s, deny_write: %s\n",
2082 open_for_reading
== true ? "yes" : "no",
2083 deny_read
== true ? "yes" : "no"));
2085 if (((access_mask
& FILE_READ_DATA
) && deny_read
)
2086 || ((deny_mode
& DENY_READ
) && open_for_reading
)) {
2087 return NT_STATUS_SHARING_VIOLATION
;
2091 if ((access_mask
& FILE_READ_DATA
) && have_read
) {
2092 off
= access_to_netatalk_brl(fork_type
, FILE_READ_DATA
);
2094 handle
->conn
->sconn
->msg_ctx
, fsp
,
2095 fsp
->op
->global
->open_persistent_id
, 1, off
,
2096 READ_LOCK
, POSIX_LOCK
, false,
2099 if (!NT_STATUS_IS_OK(status
)) {
2102 TALLOC_FREE(br_lck
);
2105 if ((deny_mode
& DENY_READ
) && have_read
) {
2106 off
= denymode_to_netatalk_brl(fork_type
, DENY_READ
);
2108 handle
->conn
->sconn
->msg_ctx
, fsp
,
2109 fsp
->op
->global
->open_persistent_id
, 1, off
,
2110 READ_LOCK
, POSIX_LOCK
, false,
2113 if (!NT_STATUS_IS_OK(status
)) {
2116 TALLOC_FREE(br_lck
);
2121 * Check write access and deny write mode
2123 if ((access_mask
& FILE_WRITE_DATA
) || (deny_mode
& DENY_WRITE
)) {
2125 open_for_writing
= test_netatalk_lock(
2126 fsp
, access_to_netatalk_brl(fork_type
, FILE_WRITE_DATA
));
2128 deny_write
= test_netatalk_lock(
2129 fsp
, denymode_to_netatalk_brl(fork_type
, DENY_WRITE
));
2131 DEBUG(10, ("write: %s, deny_write: %s\n",
2132 open_for_writing
== true ? "yes" : "no",
2133 deny_write
== true ? "yes" : "no"));
2135 if (((access_mask
& FILE_WRITE_DATA
) && deny_write
)
2136 || ((deny_mode
& DENY_WRITE
) && open_for_writing
)) {
2137 return NT_STATUS_SHARING_VIOLATION
;
2141 if ((access_mask
& FILE_WRITE_DATA
) && have_read
) {
2142 off
= access_to_netatalk_brl(fork_type
, FILE_WRITE_DATA
);
2144 handle
->conn
->sconn
->msg_ctx
, fsp
,
2145 fsp
->op
->global
->open_persistent_id
, 1, off
,
2146 READ_LOCK
, POSIX_LOCK
, false,
2149 if (!NT_STATUS_IS_OK(status
)) {
2152 TALLOC_FREE(br_lck
);
2155 if ((deny_mode
& DENY_WRITE
) && have_read
) {
2156 off
= denymode_to_netatalk_brl(fork_type
, DENY_WRITE
);
2158 handle
->conn
->sconn
->msg_ctx
, fsp
,
2159 fsp
->op
->global
->open_persistent_id
, 1, off
,
2160 READ_LOCK
, POSIX_LOCK
, false,
2163 if (!NT_STATUS_IS_OK(status
)) {
2166 TALLOC_FREE(br_lck
);
2170 TALLOC_FREE(br_lck
);
2175 static NTSTATUS
check_aapl(vfs_handle_struct
*handle
,
2176 struct smb_request
*req
,
2177 const struct smb2_create_blobs
*in_context_blobs
,
2178 struct smb2_create_blobs
*out_context_blobs
)
2180 struct fruit_config_data
*config
;
2182 struct smb2_create_blob
*aapl
= NULL
;
2186 DATA_BLOB blob
= data_blob_talloc(req
, NULL
, 0);
2187 uint64_t req_bitmap
, client_caps
;
2188 uint64_t server_caps
= SMB2_CRTCTX_AAPL_UNIX_BASED
;
2192 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
2193 return NT_STATUS_UNSUCCESSFUL
);
2195 if (!config
->use_aapl
2196 || in_context_blobs
== NULL
2197 || out_context_blobs
== NULL
) {
2198 return NT_STATUS_OK
;
2201 aapl
= smb2_create_blob_find(in_context_blobs
,
2202 SMB2_CREATE_TAG_AAPL
);
2204 return NT_STATUS_OK
;
2207 if (aapl
->data
.length
!= 24) {
2208 DEBUG(1, ("unexpected AAPL ctxt length: %ju\n",
2209 (uintmax_t)aapl
->data
.length
));
2210 return NT_STATUS_INVALID_PARAMETER
;
2213 cmd
= IVAL(aapl
->data
.data
, 0);
2214 if (cmd
!= SMB2_CRTCTX_AAPL_SERVER_QUERY
) {
2215 DEBUG(1, ("unsupported AAPL cmd: %d\n", cmd
));
2216 return NT_STATUS_INVALID_PARAMETER
;
2219 req_bitmap
= BVAL(aapl
->data
.data
, 8);
2220 client_caps
= BVAL(aapl
->data
.data
, 16);
2222 SIVAL(p
, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY
);
2224 SBVAL(p
, 8, req_bitmap
);
2225 ok
= data_blob_append(req
, &blob
, p
, 16);
2227 return NT_STATUS_UNSUCCESSFUL
;
2230 if (req_bitmap
& SMB2_CRTCTX_AAPL_SERVER_CAPS
) {
2231 if ((client_caps
& SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR
) &&
2232 (handle
->conn
->tcon
->compat
->fs_capabilities
& FILE_NAMED_STREAMS
)) {
2233 server_caps
|= SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR
;
2234 config
->readdir_attr_enabled
= true;
2237 if (config
->use_copyfile
) {
2238 server_caps
|= SMB2_CRTCTX_AAPL_SUPPORTS_OSX_COPYFILE
;
2239 config
->copyfile_enabled
= true;
2243 * The client doesn't set the flag, so we can't check
2244 * for it and just set it unconditionally
2246 if (config
->unix_info_enabled
) {
2247 server_caps
|= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE
;
2250 SBVAL(p
, 0, server_caps
);
2251 ok
= data_blob_append(req
, &blob
, p
, 8);
2253 return NT_STATUS_UNSUCCESSFUL
;
2257 if (req_bitmap
& SMB2_CRTCTX_AAPL_VOLUME_CAPS
) {
2258 int val
= lp_case_sensitive(SNUM(handle
->conn
->tcon
->compat
));
2266 caps
|= SMB2_CRTCTX_AAPL_CASE_SENSITIVE
;
2275 ok
= data_blob_append(req
, &blob
, p
, 8);
2277 return NT_STATUS_UNSUCCESSFUL
;
2281 if (req_bitmap
& SMB2_CRTCTX_AAPL_MODEL_INFO
) {
2282 ok
= convert_string_talloc(req
,
2283 CH_UNIX
, CH_UTF16LE
,
2284 config
->model
, strlen(config
->model
),
2287 return NT_STATUS_UNSUCCESSFUL
;
2291 SIVAL(p
+ 4, 0, modellen
);
2292 ok
= data_blob_append(req
, &blob
, p
, 8);
2295 return NT_STATUS_UNSUCCESSFUL
;
2298 ok
= data_blob_append(req
, &blob
, model
, modellen
);
2301 return NT_STATUS_UNSUCCESSFUL
;
2305 status
= smb2_create_blob_add(out_context_blobs
,
2307 SMB2_CREATE_TAG_AAPL
,
2309 if (NT_STATUS_IS_OK(status
)) {
2310 global_fruit_config
.nego_aapl
= true;
2311 if (config
->aapl_zero_file_id
) {
2312 aapl_force_zero_file_id(handle
->conn
->sconn
);
2319 static bool readdir_attr_meta_finderi_stream(
2320 struct vfs_handle_struct
*handle
,
2321 const struct smb_filename
*smb_fname
,
2324 struct smb_filename
*stream_name
= NULL
;
2325 files_struct
*fsp
= NULL
;
2330 uint8_t buf
[AFP_INFO_SIZE
];
2332 stream_name
= synthetic_smb_fname(talloc_tos(),
2333 smb_fname
->base_name
,
2334 AFPINFO_STREAM_NAME
,
2335 NULL
, smb_fname
->flags
);
2336 if (stream_name
== NULL
) {
2340 ret
= SMB_VFS_STAT(handle
->conn
, stream_name
);
2345 status
= SMB_VFS_CREATE_FILE(
2346 handle
->conn
, /* conn */
2348 0, /* root_dir_fid */
2349 stream_name
, /* fname */
2350 FILE_READ_DATA
, /* access_mask */
2351 (FILE_SHARE_READ
| FILE_SHARE_WRITE
| /* share_access */
2353 FILE_OPEN
, /* create_disposition*/
2354 0, /* create_options */
2355 0, /* file_attributes */
2356 INTERNAL_OPEN_ONLY
, /* oplock_request */
2358 0, /* allocation_size */
2359 0, /* private_flags */
2364 NULL
, NULL
); /* create context */
2366 TALLOC_FREE(stream_name
);
2368 if (!NT_STATUS_IS_OK(status
)) {
2372 nread
= SMB_VFS_PREAD(fsp
, &buf
[0], AFP_INFO_SIZE
, 0);
2373 if (nread
!= AFP_INFO_SIZE
) {
2374 DBG_ERR("short read [%s] [%zd/%d]\n",
2375 smb_fname_str_dbg(stream_name
), nread
, AFP_INFO_SIZE
);
2380 memcpy(&ai
->afpi_FinderInfo
[0], &buf
[AFP_OFF_FinderInfo
],
2387 close_file(NULL
, fsp
, NORMAL_CLOSE
);
2393 static bool readdir_attr_meta_finderi_netatalk(
2394 struct vfs_handle_struct
*handle
,
2395 const struct smb_filename
*smb_fname
,
2398 struct adouble
*ad
= NULL
;
2401 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_META
);
2406 p
= ad_get_entry(ad
, ADEID_FINDERI
);
2408 DBG_ERR("No ADEID_FINDERI for [%s]\n", smb_fname
->base_name
);
2413 memcpy(&ai
->afpi_FinderInfo
[0], p
, AFP_FinderSize
);
2418 static bool readdir_attr_meta_finderi(struct vfs_handle_struct
*handle
,
2419 const struct smb_filename
*smb_fname
,
2420 struct readdir_attr_data
*attr_data
)
2422 struct fruit_config_data
*config
= NULL
;
2423 uint32_t date_added
;
2427 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2428 struct fruit_config_data
,
2431 switch (config
->meta
) {
2432 case FRUIT_META_NETATALK
:
2433 ok
= readdir_attr_meta_finderi_netatalk(
2434 handle
, smb_fname
, &ai
);
2437 case FRUIT_META_STREAM
:
2438 ok
= readdir_attr_meta_finderi_stream(
2439 handle
, smb_fname
, &ai
);
2443 DBG_ERR("Unexpected meta config [%d]\n", config
->meta
);
2448 /* Don't bother with errors, it's likely ENOENT */
2452 if (S_ISREG(smb_fname
->st
.st_ex_mode
)) {
2454 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0],
2455 &ai
.afpi_FinderInfo
[0], 4);
2457 /* finder_creator */
2458 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 4,
2459 &ai
.afpi_FinderInfo
[4], 4);
2463 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 8,
2464 &ai
.afpi_FinderInfo
[8], 2);
2466 /* finder_ext_flags */
2467 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 10,
2468 &ai
.afpi_FinderInfo
[24], 2);
2471 date_added
= convert_time_t_to_uint32_t(
2472 smb_fname
->st
.st_ex_btime
.tv_sec
- AD_DATE_DELTA
);
2474 RSIVAL(&attr_data
->attr_data
.aapl
.finder_info
[0], 12, date_added
);
2479 static uint64_t readdir_attr_rfork_size_adouble(
2480 struct vfs_handle_struct
*handle
,
2481 const struct smb_filename
*smb_fname
)
2483 struct adouble
*ad
= NULL
;
2484 uint64_t rfork_size
;
2486 ad
= ad_get(talloc_tos(), handle
, smb_fname
,
2492 rfork_size
= ad_getentrylen(ad
, ADEID_RFORK
);
2498 static uint64_t readdir_attr_rfork_size_stream(
2499 struct vfs_handle_struct
*handle
,
2500 const struct smb_filename
*smb_fname
)
2502 struct smb_filename
*stream_name
= NULL
;
2504 uint64_t rfork_size
;
2506 stream_name
= synthetic_smb_fname(talloc_tos(),
2507 smb_fname
->base_name
,
2508 AFPRESOURCE_STREAM_NAME
,
2510 if (stream_name
== NULL
) {
2514 ret
= SMB_VFS_STAT(handle
->conn
, stream_name
);
2516 TALLOC_FREE(stream_name
);
2520 rfork_size
= stream_name
->st
.st_ex_size
;
2521 TALLOC_FREE(stream_name
);
2526 static uint64_t readdir_attr_rfork_size(struct vfs_handle_struct
*handle
,
2527 const struct smb_filename
*smb_fname
)
2529 struct fruit_config_data
*config
= NULL
;
2530 uint64_t rfork_size
;
2532 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2533 struct fruit_config_data
,
2536 switch (config
->rsrc
) {
2537 case FRUIT_RSRC_ADFILE
:
2538 case FRUIT_RSRC_XATTR
:
2539 rfork_size
= readdir_attr_rfork_size_adouble(handle
,
2543 case FRUIT_META_STREAM
:
2544 rfork_size
= readdir_attr_rfork_size_stream(handle
,
2549 DBG_ERR("Unexpected rsrc config [%d]\n", config
->rsrc
);
2557 static NTSTATUS
readdir_attr_macmeta(struct vfs_handle_struct
*handle
,
2558 const struct smb_filename
*smb_fname
,
2559 struct readdir_attr_data
*attr_data
)
2561 NTSTATUS status
= NT_STATUS_OK
;
2562 struct fruit_config_data
*config
= NULL
;
2565 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2566 struct fruit_config_data
,
2567 return NT_STATUS_UNSUCCESSFUL
);
2570 /* Ensure we return a default value in the creation_date field */
2571 RSIVAL(&attr_data
->attr_data
.aapl
.finder_info
, 12, AD_DATE_START
);
2574 * Resource fork length
2577 if (config
->readdir_attr_rsize
) {
2578 uint64_t rfork_size
;
2580 rfork_size
= readdir_attr_rfork_size(handle
, smb_fname
);
2581 attr_data
->attr_data
.aapl
.rfork_size
= rfork_size
;
2588 if (config
->readdir_attr_finder_info
) {
2589 ok
= readdir_attr_meta_finderi(handle
, smb_fname
, attr_data
);
2591 status
= NT_STATUS_INTERNAL_ERROR
;
2598 /* Search MS NFS style ACE with UNIX mode */
2599 static NTSTATUS
check_ms_nfs(vfs_handle_struct
*handle
,
2601 const struct security_descriptor
*psd
,
2606 struct fruit_config_data
*config
= NULL
;
2610 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2611 struct fruit_config_data
,
2612 return NT_STATUS_UNSUCCESSFUL
);
2614 if (!global_fruit_config
.nego_aapl
) {
2615 return NT_STATUS_OK
;
2617 if (psd
->dacl
== NULL
|| !config
->unix_info_enabled
) {
2618 return NT_STATUS_OK
;
2621 for (i
= 0; i
< psd
->dacl
->num_aces
; i
++) {
2622 if (dom_sid_compare_domain(
2623 &global_sid_Unix_NFS_Mode
,
2624 &psd
->dacl
->aces
[i
].trustee
) == 0) {
2625 *pmode
= (mode_t
)psd
->dacl
->aces
[i
].trustee
.sub_auths
[2];
2626 *pmode
&= (S_IRWXU
| S_IRWXG
| S_IRWXO
);
2629 DEBUG(10, ("MS NFS chmod request %s, %04o\n",
2630 fsp_str_dbg(fsp
), (unsigned)(*pmode
)));
2635 return NT_STATUS_OK
;
2638 /****************************************************************************
2640 ****************************************************************************/
2642 static int fruit_connect(vfs_handle_struct
*handle
,
2643 const char *service
,
2647 char *list
= NULL
, *newlist
= NULL
;
2648 struct fruit_config_data
*config
;
2650 DEBUG(10, ("fruit_connect\n"));
2652 rc
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
2657 rc
= init_fruit_config(handle
);
2662 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2663 struct fruit_config_data
, return -1);
2665 if (config
->veto_appledouble
) {
2666 list
= lp_veto_files(talloc_tos(), SNUM(handle
->conn
));
2669 if (strstr(list
, "/" ADOUBLE_NAME_PREFIX
"*/") == NULL
) {
2670 newlist
= talloc_asprintf(
2672 "%s/" ADOUBLE_NAME_PREFIX
"*/",
2674 lp_do_parameter(SNUM(handle
->conn
),
2679 lp_do_parameter(SNUM(handle
->conn
),
2681 "/" ADOUBLE_NAME_PREFIX
"*/");
2687 if (config
->encoding
== FRUIT_ENC_NATIVE
) {
2691 "0x01:0xf001,0x02:0xf002,0x03:0xf003,0x04:0xf004,"
2692 "0x05:0xf005,0x06:0xf006,0x07:0xf007,0x08:0xf008,"
2693 "0x09:0xf009,0x0a:0xf00a,0x0b:0xf00b,0x0c:0xf00c,"
2694 "0x0d:0xf00d,0x0e:0xf00e,0x0f:0xf00f,0x10:0xf010,"
2695 "0x11:0xf011,0x12:0xf012,0x13:0xf013,0x14:0xf014,"
2696 "0x15:0xf015,0x16:0xf016,0x17:0xf017,0x18:0xf018,"
2697 "0x19:0xf019,0x1a:0xf01a,0x1b:0xf01b,0x1c:0xf01c,"
2698 "0x1d:0xf01d,0x1e:0xf01e,0x1f:0xf01f,"
2699 "0x22:0xf020,0x2a:0xf021,0x3a:0xf022,0x3c:0xf023,"
2700 "0x3e:0xf024,0x3f:0xf025,0x5c:0xf026,0x7c:0xf027,"
2707 static int fruit_open_meta_stream(vfs_handle_struct
*handle
,
2708 struct smb_filename
*smb_fname
,
2714 char afpinfo_buf
[AFP_INFO_SIZE
];
2715 ssize_t len
, written
;
2719 hostfd
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2724 if (!(flags
& (O_CREAT
| O_TRUNC
))) {
2728 ai
= afpinfo_new(talloc_tos());
2734 len
= afpinfo_pack(ai
, afpinfo_buf
);
2735 if (len
!= AFP_INFO_SIZE
) {
2740 /* Set fd, needed in SMB_VFS_NEXT_PWRITE() */
2741 fsp
->fh
->fd
= hostfd
;
2743 written
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, afpinfo_buf
,
2746 if (written
!= AFP_INFO_SIZE
) {
2747 DBG_ERR("bad write [%zd/%d]\n", written
, AFP_INFO_SIZE
);
2755 DBG_DEBUG("rc=%d, fd=%d\n", rc
, hostfd
);
2758 int saved_errno
= errno
;
2760 fsp
->fh
->fd
= hostfd
;
2761 SMB_VFS_NEXT_CLOSE(handle
, fsp
);
2764 errno
= saved_errno
;
2769 static int fruit_open_meta_netatalk(vfs_handle_struct
*handle
,
2770 struct smb_filename
*smb_fname
,
2777 struct adouble
*ad
= NULL
;
2780 DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname
));
2783 * Return a valid fd, but ensure any attempt to use it returns an error
2784 * (EPIPE). All operations on the smb_fname or the fsp will use path
2794 if (flags
& (O_CREAT
| O_TRUNC
)) {
2796 * The attribute does not exist or needs to be truncated,
2797 * create an AppleDouble EA
2799 ad
= ad_init(fsp
, handle
, ADOUBLE_META
);
2805 rc
= ad_set(ad
, fsp
->fsp_name
);
2815 DEBUG(10, ("fruit_open meta rc=%d, fd=%d\n", rc
, fakefd
));
2817 int saved_errno
= errno
;
2822 errno
= saved_errno
;
2827 static int fruit_open_meta(vfs_handle_struct
*handle
,
2828 struct smb_filename
*smb_fname
,
2829 files_struct
*fsp
, int flags
, mode_t mode
)
2832 struct fruit_config_data
*config
= NULL
;
2833 struct fio
*fio
= NULL
;
2835 DBG_DEBUG("path [%s]\n", smb_fname_str_dbg(smb_fname
));
2837 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2838 struct fruit_config_data
, return -1);
2840 switch (config
->meta
) {
2841 case FRUIT_META_STREAM
:
2842 fd
= fruit_open_meta_stream(handle
, smb_fname
,
2846 case FRUIT_META_NETATALK
:
2847 fd
= fruit_open_meta_netatalk(handle
, smb_fname
,
2852 DBG_ERR("Unexpected meta config [%d]\n", config
->meta
);
2856 DBG_DEBUG("path [%s] fd [%d]\n", smb_fname_str_dbg(smb_fname
), fd
);
2862 fio
= (struct fio
*)VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct fio
, NULL
);
2863 fio
->type
= ADOUBLE_META
;
2864 fio
->config
= config
;
2869 static int fruit_open_rsrc_adouble(vfs_handle_struct
*handle
,
2870 struct smb_filename
*smb_fname
,
2876 struct adouble
*ad
= NULL
;
2877 struct smb_filename
*smb_fname_base
= NULL
;
2878 struct fruit_config_data
*config
= NULL
;
2881 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2882 struct fruit_config_data
, return -1);
2884 if ((!(flags
& O_CREAT
)) &&
2885 S_ISDIR(fsp
->base_fsp
->fsp_name
->st
.st_ex_mode
))
2887 /* sorry, but directories don't habe a resource fork */
2892 rc
= adouble_path(talloc_tos(), smb_fname
, &smb_fname_base
);
2897 /* Sanitize flags */
2898 if (flags
& O_WRONLY
) {
2899 /* We always need read access for the metadata header too */
2904 hostfd
= SMB_VFS_NEXT_OPEN(handle
, smb_fname_base
, fsp
,
2911 if (flags
& (O_CREAT
| O_TRUNC
)) {
2912 ad
= ad_init(fsp
, handle
, ADOUBLE_RSRC
);
2918 fsp
->fh
->fd
= hostfd
;
2920 rc
= ad_fset(ad
, fsp
);
2931 TALLOC_FREE(smb_fname_base
);
2933 DEBUG(10, ("fruit_open resource fork: rc=%d, fd=%d\n", rc
, hostfd
));
2935 int saved_errno
= errno
;
2938 * BUGBUGBUG -- we would need to call
2939 * fd_close_posix here, but we don't have a
2942 fsp
->fh
->fd
= hostfd
;
2946 errno
= saved_errno
;
2951 static int fruit_open_rsrc_xattr(vfs_handle_struct
*handle
,
2952 struct smb_filename
*smb_fname
,
2957 #ifdef HAVE_ATTROPEN
2960 fd
= attropen(smb_fname
->base_name
,
2961 AFPRESOURCE_EA_NETATALK
,
2976 static int fruit_open_rsrc(vfs_handle_struct
*handle
,
2977 struct smb_filename
*smb_fname
,
2978 files_struct
*fsp
, int flags
, mode_t mode
)
2981 struct fruit_config_data
*config
= NULL
;
2982 struct fio
*fio
= NULL
;
2984 DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname
));
2986 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2987 struct fruit_config_data
, return -1);
2989 if (((flags
& O_ACCMODE
) == O_RDONLY
)
2990 && (flags
& O_CREAT
)
2991 && !VALID_STAT(fsp
->fsp_name
->st
))
2994 * This means the stream doesn't exist. macOS SMB server fails
2995 * this with NT_STATUS_OBJECT_NAME_NOT_FOUND, so must we. Cf bug
2996 * 12565 and the test for this combination in
2997 * test_rfork_create().
3003 switch (config
->rsrc
) {
3004 case FRUIT_RSRC_STREAM
:
3005 fd
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
3008 case FRUIT_RSRC_ADFILE
:
3009 fd
= fruit_open_rsrc_adouble(handle
, smb_fname
,
3013 case FRUIT_RSRC_XATTR
:
3014 fd
= fruit_open_rsrc_xattr(handle
, smb_fname
,
3019 DBG_ERR("Unexpected rsrc config [%d]\n", config
->rsrc
);
3023 DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(smb_fname
), fd
);
3029 fio
= (struct fio
*)VFS_ADD_FSP_EXTENSION(handle
, fsp
, struct fio
, NULL
);
3030 fio
->type
= ADOUBLE_RSRC
;
3031 fio
->config
= config
;
3036 static int fruit_open(vfs_handle_struct
*handle
,
3037 struct smb_filename
*smb_fname
,
3038 files_struct
*fsp
, int flags
, mode_t mode
)
3042 DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname
));
3044 if (!is_ntfs_stream_smb_fname(smb_fname
)) {
3045 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
3048 if (is_afpinfo_stream(smb_fname
)) {
3049 fd
= fruit_open_meta(handle
, smb_fname
, fsp
, flags
, mode
);
3050 } else if (is_afpresource_stream(smb_fname
)) {
3051 fd
= fruit_open_rsrc(handle
, smb_fname
, fsp
, flags
, mode
);
3053 fd
= SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
3056 DBG_DEBUG("Path [%s] fd [%d]\n", smb_fname_str_dbg(smb_fname
), fd
);
3061 static int fruit_rename(struct vfs_handle_struct
*handle
,
3062 const struct smb_filename
*smb_fname_src
,
3063 const struct smb_filename
*smb_fname_dst
)
3066 struct fruit_config_data
*config
= NULL
;
3067 struct smb_filename
*src_adp_smb_fname
= NULL
;
3068 struct smb_filename
*dst_adp_smb_fname
= NULL
;
3070 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3071 struct fruit_config_data
, return -1);
3073 if (!VALID_STAT(smb_fname_src
->st
)) {
3074 DBG_ERR("Need valid stat for [%s]\n",
3075 smb_fname_str_dbg(smb_fname_src
));
3079 rc
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
3084 if ((config
->rsrc
!= FRUIT_RSRC_ADFILE
) ||
3085 (!S_ISREG(smb_fname_src
->st
.st_ex_mode
)))
3090 rc
= adouble_path(talloc_tos(), smb_fname_src
, &src_adp_smb_fname
);
3095 rc
= adouble_path(talloc_tos(), smb_fname_dst
, &dst_adp_smb_fname
);
3100 DBG_DEBUG("%s -> %s\n",
3101 smb_fname_str_dbg(src_adp_smb_fname
),
3102 smb_fname_str_dbg(dst_adp_smb_fname
));
3104 rc
= SMB_VFS_NEXT_RENAME(handle
, src_adp_smb_fname
, dst_adp_smb_fname
);
3105 if (errno
== ENOENT
) {
3110 TALLOC_FREE(src_adp_smb_fname
);
3111 TALLOC_FREE(dst_adp_smb_fname
);
3115 static int fruit_unlink_meta_stream(vfs_handle_struct
*handle
,
3116 const struct smb_filename
*smb_fname
)
3118 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
3121 static int fruit_unlink_meta_netatalk(vfs_handle_struct
*handle
,
3122 const struct smb_filename
*smb_fname
)
3124 return SMB_VFS_REMOVEXATTR(handle
->conn
,
3126 AFPINFO_EA_NETATALK
);
3129 static int fruit_unlink_meta(vfs_handle_struct
*handle
,
3130 const struct smb_filename
*smb_fname
)
3132 struct fruit_config_data
*config
= NULL
;
3135 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3136 struct fruit_config_data
, return -1);
3138 switch (config
->meta
) {
3139 case FRUIT_META_STREAM
:
3140 rc
= fruit_unlink_meta_stream(handle
, smb_fname
);
3143 case FRUIT_META_NETATALK
:
3144 rc
= fruit_unlink_meta_netatalk(handle
, smb_fname
);
3148 DBG_ERR("Unsupported meta config [%d]\n", config
->meta
);
3155 static int fruit_unlink_rsrc_stream(vfs_handle_struct
*handle
,
3156 const struct smb_filename
*smb_fname
,
3161 if (!force_unlink
) {
3162 struct smb_filename
*smb_fname_cp
= NULL
;
3165 smb_fname_cp
= cp_smb_filename(talloc_tos(), smb_fname
);
3166 if (smb_fname_cp
== NULL
) {
3171 * 0 byte resource fork streams are not listed by
3172 * vfs_streaminfo, as a result stream cleanup/deletion of file
3173 * deletion doesn't remove the resourcefork stream.
3176 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname_cp
);
3178 TALLOC_FREE(smb_fname_cp
);
3179 DBG_ERR("stat [%s] failed [%s]\n",
3180 smb_fname_str_dbg(smb_fname_cp
), strerror(errno
));
3184 size
= smb_fname_cp
->st
.st_ex_size
;
3185 TALLOC_FREE(smb_fname_cp
);
3188 /* OS X ignores resource fork stream delete requests */
3193 ret
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
3194 if ((ret
!= 0) && (errno
== ENOENT
) && force_unlink
) {
3201 static int fruit_unlink_rsrc_adouble(vfs_handle_struct
*handle
,
3202 const struct smb_filename
*smb_fname
,
3206 struct adouble
*ad
= NULL
;
3207 struct smb_filename
*adp_smb_fname
= NULL
;
3209 if (!force_unlink
) {
3210 ad
= ad_get(talloc_tos(), handle
, smb_fname
,
3219 * 0 byte resource fork streams are not listed by
3220 * vfs_streaminfo, as a result stream cleanup/deletion of file
3221 * deletion doesn't remove the resourcefork stream.
3224 if (ad_getentrylen(ad
, ADEID_RFORK
) > 0) {
3225 /* OS X ignores resource fork stream delete requests */
3233 rc
= adouble_path(talloc_tos(), smb_fname
, &adp_smb_fname
);
3238 rc
= SMB_VFS_NEXT_UNLINK(handle
, adp_smb_fname
);
3239 TALLOC_FREE(adp_smb_fname
);
3240 if ((rc
!= 0) && (errno
== ENOENT
) && force_unlink
) {
3247 static int fruit_unlink_rsrc_xattr(vfs_handle_struct
*handle
,
3248 const struct smb_filename
*smb_fname
,
3252 * OS X ignores resource fork stream delete requests, so nothing to do
3253 * here. Removing the file will remove the xattr anyway, so we don't
3254 * have to take care of removing 0 byte resource forks that could be
3260 static int fruit_unlink_rsrc(vfs_handle_struct
*handle
,
3261 const struct smb_filename
*smb_fname
,
3264 struct fruit_config_data
*config
= NULL
;
3267 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3268 struct fruit_config_data
, return -1);
3270 switch (config
->rsrc
) {
3271 case FRUIT_RSRC_STREAM
:
3272 rc
= fruit_unlink_rsrc_stream(handle
, smb_fname
, force_unlink
);
3275 case FRUIT_RSRC_ADFILE
:
3276 rc
= fruit_unlink_rsrc_adouble(handle
, smb_fname
, force_unlink
);
3279 case FRUIT_RSRC_XATTR
:
3280 rc
= fruit_unlink_rsrc_xattr(handle
, smb_fname
, force_unlink
);
3284 DBG_ERR("Unsupported rsrc config [%d]\n", config
->rsrc
);
3291 static int fruit_unlink(vfs_handle_struct
*handle
,
3292 const struct smb_filename
*smb_fname
)
3295 struct fruit_config_data
*config
= NULL
;
3296 struct smb_filename
*rsrc_smb_fname
= NULL
;
3298 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3299 struct fruit_config_data
, return -1);
3301 if (is_afpinfo_stream(smb_fname
)) {
3302 return fruit_unlink_meta(handle
, smb_fname
);
3303 } else if (is_afpresource_stream(smb_fname
)) {
3304 return fruit_unlink_rsrc(handle
, smb_fname
, false);
3305 } if (is_ntfs_stream_smb_fname(smb_fname
)) {
3306 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
3310 * A request to delete the base file. Because 0 byte resource
3311 * fork streams are not listed by fruit_streaminfo,
3312 * delete_all_streams() can't remove 0 byte resource fork
3313 * streams, so we have to cleanup this here.
3315 rsrc_smb_fname
= synthetic_smb_fname(talloc_tos(),
3316 smb_fname
->base_name
,
3317 AFPRESOURCE_STREAM_NAME
,
3320 if (rsrc_smb_fname
== NULL
) {
3324 rc
= fruit_unlink_rsrc(handle
, rsrc_smb_fname
, true);
3325 if ((rc
!= 0) && (errno
!= ENOENT
)) {
3326 DBG_ERR("Forced unlink of [%s] failed [%s]\n",
3327 smb_fname_str_dbg(rsrc_smb_fname
), strerror(errno
));
3328 TALLOC_FREE(rsrc_smb_fname
);
3331 TALLOC_FREE(rsrc_smb_fname
);
3333 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
3336 static int fruit_chmod(vfs_handle_struct
*handle
,
3337 const struct smb_filename
*smb_fname
,
3341 struct fruit_config_data
*config
= NULL
;
3342 struct smb_filename
*smb_fname_adp
= NULL
;
3344 rc
= SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
3349 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3350 struct fruit_config_data
, return -1);
3352 if (config
->rsrc
!= FRUIT_RSRC_ADFILE
) {
3356 if (!VALID_STAT(smb_fname
->st
)) {
3360 if (!S_ISREG(smb_fname
->st
.st_ex_mode
)) {
3364 rc
= adouble_path(talloc_tos(), smb_fname
, &smb_fname_adp
);
3369 DEBUG(10, ("fruit_chmod: %s\n", smb_fname_adp
->base_name
));
3371 rc
= SMB_VFS_NEXT_CHMOD(handle
, smb_fname_adp
, mode
);
3372 if (errno
== ENOENT
) {
3376 TALLOC_FREE(smb_fname_adp
);
3380 static int fruit_chown(vfs_handle_struct
*handle
,
3381 const struct smb_filename
*smb_fname
,
3386 struct fruit_config_data
*config
= NULL
;
3387 struct smb_filename
*adp_smb_fname
= NULL
;
3389 rc
= SMB_VFS_NEXT_CHOWN(handle
, smb_fname
, uid
, gid
);
3394 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3395 struct fruit_config_data
, return -1);
3397 if (config
->rsrc
!= FRUIT_RSRC_ADFILE
) {
3401 if (!VALID_STAT(smb_fname
->st
)) {
3405 if (!S_ISREG(smb_fname
->st
.st_ex_mode
)) {
3409 rc
= adouble_path(talloc_tos(), smb_fname
, &adp_smb_fname
);
3414 DEBUG(10, ("fruit_chown: %s\n", adp_smb_fname
->base_name
));
3416 rc
= SMB_VFS_NEXT_CHOWN(handle
, adp_smb_fname
, uid
, gid
);
3417 if (errno
== ENOENT
) {
3422 TALLOC_FREE(adp_smb_fname
);
3426 static int fruit_rmdir(struct vfs_handle_struct
*handle
,
3427 const struct smb_filename
*smb_fname
)
3431 struct fruit_config_data
*config
;
3433 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3434 struct fruit_config_data
, return -1);
3436 if (config
->rsrc
!= FRUIT_RSRC_ADFILE
) {
3441 * Due to there is no way to change bDeleteVetoFiles variable
3442 * from this module, need to clean up ourselves
3445 dh
= SMB_VFS_OPENDIR(handle
->conn
, smb_fname
, NULL
, 0);
3450 while ((de
= SMB_VFS_READDIR(handle
->conn
, dh
, NULL
)) != NULL
) {
3452 struct adouble
*ad
= NULL
;
3454 struct smb_filename
*ad_smb_fname
= NULL
;
3457 match
= strncmp(de
->d_name
,
3458 ADOUBLE_NAME_PREFIX
,
3459 strlen(ADOUBLE_NAME_PREFIX
));
3464 p
= talloc_asprintf(talloc_tos(), "%s/%s",
3465 smb_fname
->base_name
, de
->d_name
);
3467 DBG_ERR("talloc_asprintf failed\n");
3471 ad_smb_fname
= synthetic_smb_fname(talloc_tos(), p
,
3475 if (ad_smb_fname
== NULL
) {
3476 DBG_ERR("synthetic_smb_fname failed\n");
3481 * Check whether it's a valid AppleDouble file, if
3482 * yes, delete it, ignore it otherwise.
3484 ad
= ad_get(talloc_tos(), handle
, ad_smb_fname
, ADOUBLE_RSRC
);
3486 TALLOC_FREE(ad_smb_fname
);
3492 ret
= SMB_VFS_NEXT_UNLINK(handle
, ad_smb_fname
);
3493 TALLOC_FREE(ad_smb_fname
);
3495 DBG_ERR("Deleting [%s] failed\n",
3496 smb_fname_str_dbg(ad_smb_fname
));
3504 return SMB_VFS_NEXT_RMDIR(handle
, smb_fname
);
3507 static ssize_t
fruit_pread_meta_stream(vfs_handle_struct
*handle
,
3508 files_struct
*fsp
, void *data
,
3509 size_t n
, off_t offset
)
3514 nread
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
3520 DBG_ERR("Removing [%s] after short read [%zd]\n",
3521 fsp_str_dbg(fsp
), nread
);
3523 ret
= SMB_VFS_NEXT_UNLINK(handle
, fsp
->fsp_name
);
3525 DBG_ERR("Removing [%s] failed\n", fsp_str_dbg(fsp
));
3533 static ssize_t
fruit_pread_meta_adouble(vfs_handle_struct
*handle
,
3534 files_struct
*fsp
, void *data
,
3535 size_t n
, off_t offset
)
3538 struct adouble
*ad
= NULL
;
3539 char afpinfo_buf
[AFP_INFO_SIZE
];
3543 ai
= afpinfo_new(talloc_tos());
3548 ad
= ad_fget(talloc_tos(), handle
, fsp
, ADOUBLE_META
);
3554 p
= ad_get_entry(ad
, ADEID_FINDERI
);
3556 DBG_ERR("No ADEID_FINDERI for [%s]\n", fsp_str_dbg(fsp
));
3561 memcpy(&ai
->afpi_FinderInfo
[0], p
, ADEDLEN_FINDERI
);
3563 nread
= afpinfo_pack(ai
, afpinfo_buf
);
3564 if (nread
!= AFP_INFO_SIZE
) {
3569 memcpy(data
, afpinfo_buf
, n
);
3577 static ssize_t
fruit_pread_meta(vfs_handle_struct
*handle
,
3578 files_struct
*fsp
, void *data
,
3579 size_t n
, off_t offset
)
3581 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3586 * OS X has a off-by-1 error in the offset calculation, so we're
3587 * bug compatible here. It won't hurt, as any relevant real
3588 * world read requests from the AFP_AfpInfo stream will be
3589 * offset=0 n=60. offset is ignored anyway, see below.
3591 if ((offset
< 0) || (offset
>= AFP_INFO_SIZE
+ 1)) {
3595 /* Yes, macOS always reads from offset 0 */
3597 to_return
= MIN(n
, AFP_INFO_SIZE
);
3599 switch (fio
->config
->meta
) {
3600 case FRUIT_META_STREAM
:
3601 nread
= fruit_pread_meta_stream(handle
, fsp
, data
,
3605 case FRUIT_META_NETATALK
:
3606 nread
= fruit_pread_meta_adouble(handle
, fsp
, data
,
3611 DBG_ERR("Unexpected meta config [%d]\n", fio
->config
->meta
);
3618 static ssize_t
fruit_pread_rsrc_stream(vfs_handle_struct
*handle
,
3619 files_struct
*fsp
, void *data
,
3620 size_t n
, off_t offset
)
3622 return SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
3625 static ssize_t
fruit_pread_rsrc_xattr(vfs_handle_struct
*handle
,
3626 files_struct
*fsp
, void *data
,
3627 size_t n
, off_t offset
)
3629 return SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
3632 static ssize_t
fruit_pread_rsrc_adouble(vfs_handle_struct
*handle
,
3633 files_struct
*fsp
, void *data
,
3634 size_t n
, off_t offset
)
3636 struct adouble
*ad
= NULL
;
3639 ad
= ad_fget(talloc_tos(), handle
, fsp
, ADOUBLE_RSRC
);
3644 nread
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
,
3645 offset
+ ad_getentryoff(ad
, ADEID_RFORK
));
3651 static ssize_t
fruit_pread_rsrc(vfs_handle_struct
*handle
,
3652 files_struct
*fsp
, void *data
,
3653 size_t n
, off_t offset
)
3655 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3658 switch (fio
->config
->rsrc
) {
3659 case FRUIT_RSRC_STREAM
:
3660 nread
= fruit_pread_rsrc_stream(handle
, fsp
, data
, n
, offset
);
3663 case FRUIT_RSRC_ADFILE
:
3664 nread
= fruit_pread_rsrc_adouble(handle
, fsp
, data
, n
, offset
);
3667 case FRUIT_RSRC_XATTR
:
3668 nread
= fruit_pread_rsrc_xattr(handle
, fsp
, data
, n
, offset
);
3672 DBG_ERR("Unexpected rsrc config [%d]\n", fio
->config
->rsrc
);
3679 static ssize_t
fruit_pread(vfs_handle_struct
*handle
,
3680 files_struct
*fsp
, void *data
,
3681 size_t n
, off_t offset
)
3683 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3686 DBG_DEBUG("Path [%s] offset=%"PRIdMAX
", size=%zd\n",
3687 fsp_str_dbg(fsp
), (intmax_t)offset
, n
);
3690 return SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
3693 if (fio
->type
== ADOUBLE_META
) {
3694 nread
= fruit_pread_meta(handle
, fsp
, data
, n
, offset
);
3696 nread
= fruit_pread_rsrc(handle
, fsp
, data
, n
, offset
);
3699 DBG_DEBUG("Path [%s] nread [%zd]\n", fsp_str_dbg(fsp
), nread
);
3703 static bool fruit_must_handle_aio_stream(struct fio
*fio
)
3709 if ((fio
->type
== ADOUBLE_META
) &&
3710 (fio
->config
->meta
== FRUIT_META_NETATALK
))
3715 if ((fio
->type
== ADOUBLE_RSRC
) &&
3716 (fio
->config
->rsrc
== FRUIT_RSRC_ADFILE
))
3724 struct fruit_pread_state
{
3726 struct vfs_aio_state vfs_aio_state
;
3729 static void fruit_pread_done(struct tevent_req
*subreq
);
3731 static struct tevent_req
*fruit_pread_send(
3732 struct vfs_handle_struct
*handle
,
3733 TALLOC_CTX
*mem_ctx
,
3734 struct tevent_context
*ev
,
3735 struct files_struct
*fsp
,
3737 size_t n
, off_t offset
)
3739 struct tevent_req
*req
= NULL
;
3740 struct tevent_req
*subreq
= NULL
;
3741 struct fruit_pread_state
*state
= NULL
;
3742 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3744 req
= tevent_req_create(mem_ctx
, &state
,
3745 struct fruit_pread_state
);
3750 if (fruit_must_handle_aio_stream(fio
)) {
3751 state
->nread
= SMB_VFS_PREAD(fsp
, data
, n
, offset
);
3752 if (state
->nread
!= n
) {
3753 if (state
->nread
!= -1) {
3756 tevent_req_error(req
, errno
);
3757 return tevent_req_post(req
, ev
);
3759 tevent_req_done(req
);
3760 return tevent_req_post(req
, ev
);
3763 subreq
= SMB_VFS_NEXT_PREAD_SEND(state
, ev
, handle
, fsp
,
3765 if (tevent_req_nomem(req
, subreq
)) {
3766 return tevent_req_post(req
, ev
);
3768 tevent_req_set_callback(subreq
, fruit_pread_done
, req
);
3772 static void fruit_pread_done(struct tevent_req
*subreq
)
3774 struct tevent_req
*req
= tevent_req_callback_data(
3775 subreq
, struct tevent_req
);
3776 struct fruit_pread_state
*state
= tevent_req_data(
3777 req
, struct fruit_pread_state
);
3779 state
->nread
= SMB_VFS_PREAD_RECV(subreq
, &state
->vfs_aio_state
);
3780 TALLOC_FREE(subreq
);
3782 if (tevent_req_error(req
, state
->vfs_aio_state
.error
)) {
3785 tevent_req_done(req
);
3788 static ssize_t
fruit_pread_recv(struct tevent_req
*req
,
3789 struct vfs_aio_state
*vfs_aio_state
)
3791 struct fruit_pread_state
*state
= tevent_req_data(
3792 req
, struct fruit_pread_state
);
3794 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
3798 *vfs_aio_state
= state
->vfs_aio_state
;
3799 return state
->nread
;
3802 static ssize_t
fruit_pwrite_meta_stream(vfs_handle_struct
*handle
,
3803 files_struct
*fsp
, const void *data
,
3804 size_t n
, off_t offset
)
3809 ai
= afpinfo_unpack(talloc_tos(), data
);
3814 if (ai_empty_finderinfo(ai
)) {
3815 ret
= SMB_VFS_NEXT_UNLINK(handle
, fsp
->fsp_name
);
3816 if (ret
!= 0 && errno
!= ENOENT
&& errno
!= ENOATTR
) {
3817 DBG_ERR("Can't delete metadata for %s: %s\n",
3818 fsp_str_dbg(fsp
), strerror(errno
));
3826 return SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
3829 static ssize_t
fruit_pwrite_meta_netatalk(vfs_handle_struct
*handle
,
3830 files_struct
*fsp
, const void *data
,
3831 size_t n
, off_t offset
)
3833 struct adouble
*ad
= NULL
;
3838 ai
= afpinfo_unpack(talloc_tos(), data
);
3843 if (ai_empty_finderinfo(ai
)) {
3844 ret
= SMB_VFS_REMOVEXATTR(handle
->conn
,
3846 AFPINFO_EA_NETATALK
);
3848 if (ret
!= 0 && errno
!= ENOENT
&& errno
!= ENOATTR
) {
3849 DBG_ERR("Can't delete metadata for %s: %s\n",
3850 fsp_str_dbg(fsp
), strerror(errno
));
3857 ad
= ad_fget(talloc_tos(), handle
, fsp
, ADOUBLE_META
);
3859 ad
= ad_init(talloc_tos(), handle
, ADOUBLE_META
);
3864 p
= ad_get_entry(ad
, ADEID_FINDERI
);
3866 DBG_ERR("No ADEID_FINDERI for [%s]\n", fsp_str_dbg(fsp
));
3871 memcpy(p
, &ai
->afpi_FinderInfo
[0], ADEDLEN_FINDERI
);
3873 ret
= ad_fset(ad
, fsp
);
3875 DBG_ERR("ad_pwrite [%s] failed\n", fsp_str_dbg(fsp
));
3884 static ssize_t
fruit_pwrite_meta(vfs_handle_struct
*handle
,
3885 files_struct
*fsp
, const void *data
,
3886 size_t n
, off_t offset
)
3888 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3892 * Writing an all 0 blob to the metadata stream
3893 * results in the stream being removed on a macOS
3894 * server. This ensures we behave the same and it
3895 * verified by the "delete AFP_AfpInfo by writing all
3898 if (n
!= AFP_INFO_SIZE
|| offset
!= 0) {
3899 DBG_ERR("unexpected offset=%jd or size=%jd\n",
3900 (intmax_t)offset
, (intmax_t)n
);
3904 switch (fio
->config
->meta
) {
3905 case FRUIT_META_STREAM
:
3906 nwritten
= fruit_pwrite_meta_stream(handle
, fsp
, data
,
3910 case FRUIT_META_NETATALK
:
3911 nwritten
= fruit_pwrite_meta_netatalk(handle
, fsp
, data
,
3916 DBG_ERR("Unexpected meta config [%d]\n", fio
->config
->meta
);
3923 static ssize_t
fruit_pwrite_rsrc_stream(vfs_handle_struct
*handle
,
3924 files_struct
*fsp
, const void *data
,
3925 size_t n
, off_t offset
)
3927 return SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
3930 static ssize_t
fruit_pwrite_rsrc_xattr(vfs_handle_struct
*handle
,
3931 files_struct
*fsp
, const void *data
,
3932 size_t n
, off_t offset
)
3934 return SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
3937 static ssize_t
fruit_pwrite_rsrc_adouble(vfs_handle_struct
*handle
,
3938 files_struct
*fsp
, const void *data
,
3939 size_t n
, off_t offset
)
3941 struct adouble
*ad
= NULL
;
3945 ad
= ad_fget(talloc_tos(), handle
, fsp
, ADOUBLE_RSRC
);
3947 DBG_ERR("ad_get [%s] failed\n", fsp_str_dbg(fsp
));
3951 nwritten
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
,
3952 offset
+ ad_getentryoff(ad
, ADEID_RFORK
));
3953 if (nwritten
!= n
) {
3954 DBG_ERR("Short write on [%s] [%zd/%zd]\n",
3955 fsp_str_dbg(fsp
), nwritten
, n
);
3960 if ((n
+ offset
) > ad_getentrylen(ad
, ADEID_RFORK
)) {
3961 ad_setentrylen(ad
, ADEID_RFORK
, n
+ offset
);
3962 ret
= ad_fset(ad
, fsp
);
3964 DBG_ERR("ad_pwrite [%s] failed\n", fsp_str_dbg(fsp
));
3974 static ssize_t
fruit_pwrite_rsrc(vfs_handle_struct
*handle
,
3975 files_struct
*fsp
, const void *data
,
3976 size_t n
, off_t offset
)
3978 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3981 switch (fio
->config
->rsrc
) {
3982 case FRUIT_RSRC_STREAM
:
3983 nwritten
= fruit_pwrite_rsrc_stream(handle
, fsp
, data
, n
, offset
);
3986 case FRUIT_RSRC_ADFILE
:
3987 nwritten
= fruit_pwrite_rsrc_adouble(handle
, fsp
, data
, n
, offset
);
3990 case FRUIT_RSRC_XATTR
:
3991 nwritten
= fruit_pwrite_rsrc_xattr(handle
, fsp
, data
, n
, offset
);
3995 DBG_ERR("Unexpected rsrc config [%d]\n", fio
->config
->rsrc
);
4002 static ssize_t
fruit_pwrite(vfs_handle_struct
*handle
,
4003 files_struct
*fsp
, const void *data
,
4004 size_t n
, off_t offset
)
4006 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
4009 DBG_DEBUG("Path [%s] offset=%"PRIdMAX
", size=%zd\n",
4010 fsp_str_dbg(fsp
), (intmax_t)offset
, n
);
4013 return SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
4016 if (fio
->type
== ADOUBLE_META
) {
4017 nwritten
= fruit_pwrite_meta(handle
, fsp
, data
, n
, offset
);
4019 nwritten
= fruit_pwrite_rsrc(handle
, fsp
, data
, n
, offset
);
4022 DBG_DEBUG("Path [%s] nwritten=%zd\n", fsp_str_dbg(fsp
), nwritten
);
4026 struct fruit_pwrite_state
{
4028 struct vfs_aio_state vfs_aio_state
;
4031 static void fruit_pwrite_done(struct tevent_req
*subreq
);
4033 static struct tevent_req
*fruit_pwrite_send(
4034 struct vfs_handle_struct
*handle
,
4035 TALLOC_CTX
*mem_ctx
,
4036 struct tevent_context
*ev
,
4037 struct files_struct
*fsp
,
4039 size_t n
, off_t offset
)
4041 struct tevent_req
*req
= NULL
;
4042 struct tevent_req
*subreq
= NULL
;
4043 struct fruit_pwrite_state
*state
= NULL
;
4044 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
4046 req
= tevent_req_create(mem_ctx
, &state
,
4047 struct fruit_pwrite_state
);
4052 if (fruit_must_handle_aio_stream(fio
)) {
4053 state
->nwritten
= SMB_VFS_PWRITE(fsp
, data
, n
, offset
);
4054 if (state
->nwritten
!= n
) {
4055 if (state
->nwritten
!= -1) {
4058 tevent_req_error(req
, errno
);
4059 return tevent_req_post(req
, ev
);
4061 tevent_req_done(req
);
4062 return tevent_req_post(req
, ev
);
4065 subreq
= SMB_VFS_NEXT_PWRITE_SEND(state
, ev
, handle
, fsp
,
4067 if (tevent_req_nomem(req
, subreq
)) {
4068 return tevent_req_post(req
, ev
);
4070 tevent_req_set_callback(subreq
, fruit_pwrite_done
, req
);
4074 static void fruit_pwrite_done(struct tevent_req
*subreq
)
4076 struct tevent_req
*req
= tevent_req_callback_data(
4077 subreq
, struct tevent_req
);
4078 struct fruit_pwrite_state
*state
= tevent_req_data(
4079 req
, struct fruit_pwrite_state
);
4081 state
->nwritten
= SMB_VFS_PWRITE_RECV(subreq
, &state
->vfs_aio_state
);
4082 TALLOC_FREE(subreq
);
4084 if (tevent_req_error(req
, state
->vfs_aio_state
.error
)) {
4087 tevent_req_done(req
);
4090 static ssize_t
fruit_pwrite_recv(struct tevent_req
*req
,
4091 struct vfs_aio_state
*vfs_aio_state
)
4093 struct fruit_pwrite_state
*state
= tevent_req_data(
4094 req
, struct fruit_pwrite_state
);
4096 if (tevent_req_is_unix_error(req
, &vfs_aio_state
->error
)) {
4100 *vfs_aio_state
= state
->vfs_aio_state
;
4101 return state
->nwritten
;
4105 * Helper to stat/lstat the base file of an smb_fname.
4107 static int fruit_stat_base(vfs_handle_struct
*handle
,
4108 struct smb_filename
*smb_fname
,
4111 char *tmp_stream_name
;
4114 tmp_stream_name
= smb_fname
->stream_name
;
4115 smb_fname
->stream_name
= NULL
;
4117 rc
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
4119 rc
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
4121 smb_fname
->stream_name
= tmp_stream_name
;
4125 static int fruit_stat_meta_stream(vfs_handle_struct
*handle
,
4126 struct smb_filename
*smb_fname
,
4132 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
4134 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
4140 static int fruit_stat_meta_netatalk(vfs_handle_struct
*handle
,
4141 struct smb_filename
*smb_fname
,
4144 struct adouble
*ad
= NULL
;
4146 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_META
);
4148 DBG_INFO("fruit_stat_meta %s: %s\n",
4149 smb_fname_str_dbg(smb_fname
), strerror(errno
));
4155 /* Populate the stat struct with info from the base file. */
4156 if (fruit_stat_base(handle
, smb_fname
, follow_links
) == -1) {
4159 smb_fname
->st
.st_ex_size
= AFP_INFO_SIZE
;
4160 smb_fname
->st
.st_ex_ino
= fruit_inode(&smb_fname
->st
,
4161 smb_fname
->stream_name
);
4165 static int fruit_stat_meta(vfs_handle_struct
*handle
,
4166 struct smb_filename
*smb_fname
,
4169 struct fruit_config_data
*config
= NULL
;
4172 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
4173 struct fruit_config_data
, return -1);
4175 switch (config
->meta
) {
4176 case FRUIT_META_STREAM
:
4177 ret
= fruit_stat_meta_stream(handle
, smb_fname
, follow_links
);
4180 case FRUIT_META_NETATALK
:
4181 ret
= fruit_stat_meta_netatalk(handle
, smb_fname
, follow_links
);
4185 DBG_ERR("Unexpected meta config [%d]\n", config
->meta
);
4192 static int fruit_stat_rsrc_netatalk(vfs_handle_struct
*handle
,
4193 struct smb_filename
*smb_fname
,
4196 struct adouble
*ad
= NULL
;
4199 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_RSRC
);
4205 /* Populate the stat struct with info from the base file. */
4206 ret
= fruit_stat_base(handle
, smb_fname
, follow_links
);
4212 smb_fname
->st
.st_ex_size
= ad_getentrylen(ad
, ADEID_RFORK
);
4213 smb_fname
->st
.st_ex_ino
= fruit_inode(&smb_fname
->st
,
4214 smb_fname
->stream_name
);
4219 static int fruit_stat_rsrc_stream(vfs_handle_struct
*handle
,
4220 struct smb_filename
*smb_fname
,
4226 ret
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
4228 ret
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
4234 static int fruit_stat_rsrc_xattr(vfs_handle_struct
*handle
,
4235 struct smb_filename
*smb_fname
,
4238 #ifdef HAVE_ATTROPEN
4242 /* Populate the stat struct with info from the base file. */
4243 ret
= fruit_stat_base(handle
, smb_fname
, follow_links
);
4248 fd
= attropen(smb_fname
->base_name
,
4249 AFPRESOURCE_EA_NETATALK
,
4255 ret
= sys_fstat(fd
, &smb_fname
->st
, false);
4258 DBG_ERR("fstat [%s:%s] failed\n", smb_fname
->base_name
,
4259 AFPRESOURCE_EA_NETATALK
);
4265 smb_fname
->st
.st_ex_ino
= fruit_inode(&smb_fname
->st
,
4266 smb_fname
->stream_name
);
4276 static int fruit_stat_rsrc(vfs_handle_struct
*handle
,
4277 struct smb_filename
*smb_fname
,
4280 struct fruit_config_data
*config
= NULL
;
4283 DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname
));
4285 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
4286 struct fruit_config_data
, return -1);
4288 switch (config
->rsrc
) {
4289 case FRUIT_RSRC_STREAM
:
4290 ret
= fruit_stat_rsrc_stream(handle
, smb_fname
, follow_links
);
4293 case FRUIT_RSRC_XATTR
:
4294 ret
= fruit_stat_rsrc_xattr(handle
, smb_fname
, follow_links
);
4297 case FRUIT_RSRC_ADFILE
:
4298 ret
= fruit_stat_rsrc_netatalk(handle
, smb_fname
, follow_links
);
4302 DBG_ERR("Unexpected rsrc config [%d]\n", config
->rsrc
);
4309 static int fruit_stat(vfs_handle_struct
*handle
,
4310 struct smb_filename
*smb_fname
)
4314 DEBUG(10, ("fruit_stat called for %s\n",
4315 smb_fname_str_dbg(smb_fname
)));
4317 if (!is_ntfs_stream_smb_fname(smb_fname
)
4318 || is_ntfs_default_stream_smb_fname(smb_fname
)) {
4319 rc
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
4321 update_btime(handle
, smb_fname
);
4327 * Note if lp_posix_paths() is true, we can never
4328 * get here as is_ntfs_stream_smb_fname() is
4329 * always false. So we never need worry about
4330 * not following links here.
4333 if (is_afpinfo_stream(smb_fname
)) {
4334 rc
= fruit_stat_meta(handle
, smb_fname
, true);
4335 } else if (is_afpresource_stream(smb_fname
)) {
4336 rc
= fruit_stat_rsrc(handle
, smb_fname
, true);
4338 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
4342 update_btime(handle
, smb_fname
);
4343 smb_fname
->st
.st_ex_mode
&= ~S_IFMT
;
4344 smb_fname
->st
.st_ex_mode
|= S_IFREG
;
4345 smb_fname
->st
.st_ex_blocks
=
4346 smb_fname
->st
.st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
4351 static int fruit_lstat(vfs_handle_struct
*handle
,
4352 struct smb_filename
*smb_fname
)
4356 DEBUG(10, ("fruit_lstat called for %s\n",
4357 smb_fname_str_dbg(smb_fname
)));
4359 if (!is_ntfs_stream_smb_fname(smb_fname
)
4360 || is_ntfs_default_stream_smb_fname(smb_fname
)) {
4361 rc
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
4363 update_btime(handle
, smb_fname
);
4368 if (is_afpinfo_stream(smb_fname
)) {
4369 rc
= fruit_stat_meta(handle
, smb_fname
, false);
4370 } else if (is_afpresource_stream(smb_fname
)) {
4371 rc
= fruit_stat_rsrc(handle
, smb_fname
, false);
4373 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
4377 update_btime(handle
, smb_fname
);
4378 smb_fname
->st
.st_ex_mode
&= ~S_IFMT
;
4379 smb_fname
->st
.st_ex_mode
|= S_IFREG
;
4380 smb_fname
->st
.st_ex_blocks
=
4381 smb_fname
->st
.st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
4386 static int fruit_fstat_meta_stream(vfs_handle_struct
*handle
,
4388 SMB_STRUCT_STAT
*sbuf
)
4390 return SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
4393 static int fruit_fstat_meta_netatalk(vfs_handle_struct
*handle
,
4395 SMB_STRUCT_STAT
*sbuf
)
4399 ret
= fruit_stat_base(handle
, fsp
->base_fsp
->fsp_name
, false);
4404 *sbuf
= fsp
->base_fsp
->fsp_name
->st
;
4405 sbuf
->st_ex_size
= AFP_INFO_SIZE
;
4406 sbuf
->st_ex_ino
= fruit_inode(sbuf
, fsp
->fsp_name
->stream_name
);
4411 static int fruit_fstat_meta(vfs_handle_struct
*handle
,
4413 SMB_STRUCT_STAT
*sbuf
,
4418 DBG_DEBUG("Path [%s]\n", fsp_str_dbg(fsp
));
4420 switch (fio
->config
->meta
) {
4421 case FRUIT_META_STREAM
:
4422 ret
= fruit_fstat_meta_stream(handle
, fsp
, sbuf
);
4425 case FRUIT_META_NETATALK
:
4426 ret
= fruit_fstat_meta_netatalk(handle
, fsp
, sbuf
);
4430 DBG_ERR("Unexpected meta config [%d]\n", fio
->config
->meta
);
4434 DBG_DEBUG("Path [%s] ret [%d]\n", fsp_str_dbg(fsp
), ret
);
4438 static int fruit_fstat_rsrc_xattr(vfs_handle_struct
*handle
,
4440 SMB_STRUCT_STAT
*sbuf
)
4442 return SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
4445 static int fruit_fstat_rsrc_stream(vfs_handle_struct
*handle
,
4447 SMB_STRUCT_STAT
*sbuf
)
4449 return SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
4452 static int fruit_fstat_rsrc_adouble(vfs_handle_struct
*handle
,
4454 SMB_STRUCT_STAT
*sbuf
)
4456 struct adouble
*ad
= NULL
;
4459 /* Populate the stat struct with info from the base file. */
4460 ret
= fruit_stat_base(handle
, fsp
->base_fsp
->fsp_name
, false);
4465 ad
= ad_get(talloc_tos(), handle
,
4466 fsp
->base_fsp
->fsp_name
,
4469 DBG_ERR("ad_get [%s] failed [%s]\n",
4470 fsp_str_dbg(fsp
), strerror(errno
));
4474 *sbuf
= fsp
->base_fsp
->fsp_name
->st
;
4475 sbuf
->st_ex_size
= ad_getentrylen(ad
, ADEID_RFORK
);
4476 sbuf
->st_ex_ino
= fruit_inode(sbuf
, fsp
->fsp_name
->stream_name
);
4482 static int fruit_fstat_rsrc(vfs_handle_struct
*handle
, files_struct
*fsp
,
4483 SMB_STRUCT_STAT
*sbuf
, struct fio
*fio
)
4487 switch (fio
->config
->rsrc
) {
4488 case FRUIT_RSRC_STREAM
:
4489 ret
= fruit_fstat_rsrc_stream(handle
, fsp
, sbuf
);
4492 case FRUIT_RSRC_ADFILE
:
4493 ret
= fruit_fstat_rsrc_adouble(handle
, fsp
, sbuf
);
4496 case FRUIT_RSRC_XATTR
:
4497 ret
= fruit_fstat_rsrc_xattr(handle
, fsp
, sbuf
);
4501 DBG_ERR("Unexpected rsrc config [%d]\n", fio
->config
->rsrc
);
4508 static int fruit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
4509 SMB_STRUCT_STAT
*sbuf
)
4511 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
4515 return SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
4518 DBG_DEBUG("Path [%s]\n", fsp_str_dbg(fsp
));
4520 if (fio
->type
== ADOUBLE_META
) {
4521 rc
= fruit_fstat_meta(handle
, fsp
, sbuf
, fio
);
4523 rc
= fruit_fstat_rsrc(handle
, fsp
, sbuf
, fio
);
4527 sbuf
->st_ex_mode
&= ~S_IFMT
;
4528 sbuf
->st_ex_mode
|= S_IFREG
;
4529 sbuf
->st_ex_blocks
= sbuf
->st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
4532 DBG_DEBUG("Path [%s] rc [%d] size [%"PRIdMAX
"]\n",
4533 fsp_str_dbg(fsp
), rc
, (intmax_t)sbuf
->st_ex_size
);
4537 static NTSTATUS
fruit_streaminfo_meta_stream(
4538 vfs_handle_struct
*handle
,
4539 struct files_struct
*fsp
,
4540 const struct smb_filename
*smb_fname
,
4541 TALLOC_CTX
*mem_ctx
,
4542 unsigned int *pnum_streams
,
4543 struct stream_struct
**pstreams
)
4545 struct stream_struct
*stream
= *pstreams
;
4546 unsigned int num_streams
= *pnum_streams
;
4547 struct smb_filename
*sname
= NULL
;
4552 for (i
= 0; i
< num_streams
; i
++) {
4553 if (strequal_m(stream
[i
].name
, AFPINFO_STREAM
)) {
4558 if (i
== num_streams
) {
4559 return NT_STATUS_OK
;
4562 if (stream
[i
].size
== AFP_INFO_SIZE
) {
4563 return NT_STATUS_OK
;
4566 DBG_ERR("Removing invalid AFPINFO_STREAM size [%"PRIdMAX
"] "
4567 "from [%s]\n", (intmax_t)stream
[i
].size
,
4568 smb_fname_str_dbg(smb_fname
));
4570 ok
= del_fruit_stream(mem_ctx
, pnum_streams
, pstreams
, AFPINFO_STREAM
);
4572 return NT_STATUS_INTERNAL_ERROR
;
4575 sname
= synthetic_smb_fname(talloc_tos(),
4576 smb_fname
->base_name
,
4577 AFPINFO_STREAM_NAME
,
4579 if (sname
== NULL
) {
4580 return NT_STATUS_NO_MEMORY
;
4583 ret
= SMB_VFS_NEXT_UNLINK(handle
, sname
);
4586 DBG_ERR("Removing [%s] failed\n", smb_fname_str_dbg(sname
));
4587 return map_nt_error_from_unix(errno
);
4590 return NT_STATUS_OK
;
4593 static NTSTATUS
fruit_streaminfo_meta_netatalk(
4594 vfs_handle_struct
*handle
,
4595 struct files_struct
*fsp
,
4596 const struct smb_filename
*smb_fname
,
4597 TALLOC_CTX
*mem_ctx
,
4598 unsigned int *pnum_streams
,
4599 struct stream_struct
**pstreams
)
4601 struct stream_struct
*stream
= *pstreams
;
4602 unsigned int num_streams
= *pnum_streams
;
4603 struct adouble
*ad
= NULL
;
4608 /* Remove the Netatalk xattr from the list */
4609 ok
= del_fruit_stream(mem_ctx
, pnum_streams
, pstreams
,
4610 ":" NETATALK_META_XATTR
":$DATA");
4612 return NT_STATUS_NO_MEMORY
;
4616 * Check if there's a AFPINFO_STREAM from the VFS streams
4617 * backend and if yes, remove it from the list
4619 for (i
= 0; i
< num_streams
; i
++) {
4620 if (strequal_m(stream
[i
].name
, AFPINFO_STREAM
)) {
4625 if (i
< num_streams
) {
4626 DBG_WARNING("Unexpected AFPINFO_STREAM on [%s]\n",
4627 smb_fname_str_dbg(smb_fname
));
4629 ok
= del_fruit_stream(mem_ctx
, pnum_streams
, pstreams
,
4632 return NT_STATUS_INTERNAL_ERROR
;
4636 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_META
);
4638 return NT_STATUS_OK
;
4641 is_fi_empty
= ad_empty_finderinfo(ad
);
4645 return NT_STATUS_OK
;
4648 ok
= add_fruit_stream(mem_ctx
, pnum_streams
, pstreams
,
4649 AFPINFO_STREAM_NAME
, AFP_INFO_SIZE
,
4650 smb_roundup(handle
->conn
, AFP_INFO_SIZE
));
4652 return NT_STATUS_NO_MEMORY
;
4655 return NT_STATUS_OK
;
4658 static NTSTATUS
fruit_streaminfo_meta(vfs_handle_struct
*handle
,
4659 struct files_struct
*fsp
,
4660 const struct smb_filename
*smb_fname
,
4661 TALLOC_CTX
*mem_ctx
,
4662 unsigned int *pnum_streams
,
4663 struct stream_struct
**pstreams
)
4665 struct fruit_config_data
*config
= NULL
;
4668 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
4669 return NT_STATUS_INTERNAL_ERROR
);
4671 switch (config
->meta
) {
4672 case FRUIT_META_NETATALK
:
4673 status
= fruit_streaminfo_meta_netatalk(handle
, fsp
, smb_fname
,
4674 mem_ctx
, pnum_streams
,
4678 case FRUIT_META_STREAM
:
4679 status
= fruit_streaminfo_meta_stream(handle
, fsp
, smb_fname
,
4680 mem_ctx
, pnum_streams
,
4685 return NT_STATUS_INTERNAL_ERROR
;
4691 static NTSTATUS
fruit_streaminfo_rsrc_stream(
4692 vfs_handle_struct
*handle
,
4693 struct files_struct
*fsp
,
4694 const struct smb_filename
*smb_fname
,
4695 TALLOC_CTX
*mem_ctx
,
4696 unsigned int *pnum_streams
,
4697 struct stream_struct
**pstreams
)
4701 ok
= filter_empty_rsrc_stream(pnum_streams
, pstreams
);
4703 DBG_ERR("Filtering resource stream failed\n");
4704 return NT_STATUS_INTERNAL_ERROR
;
4706 return NT_STATUS_OK
;
4709 static NTSTATUS
fruit_streaminfo_rsrc_xattr(
4710 vfs_handle_struct
*handle
,
4711 struct files_struct
*fsp
,
4712 const struct smb_filename
*smb_fname
,
4713 TALLOC_CTX
*mem_ctx
,
4714 unsigned int *pnum_streams
,
4715 struct stream_struct
**pstreams
)
4719 ok
= filter_empty_rsrc_stream(pnum_streams
, pstreams
);
4721 DBG_ERR("Filtering resource stream failed\n");
4722 return NT_STATUS_INTERNAL_ERROR
;
4724 return NT_STATUS_OK
;
4727 static NTSTATUS
fruit_streaminfo_rsrc_adouble(
4728 vfs_handle_struct
*handle
,
4729 struct files_struct
*fsp
,
4730 const struct smb_filename
*smb_fname
,
4731 TALLOC_CTX
*mem_ctx
,
4732 unsigned int *pnum_streams
,
4733 struct stream_struct
**pstreams
)
4735 struct stream_struct
*stream
= *pstreams
;
4736 unsigned int num_streams
= *pnum_streams
;
4737 struct adouble
*ad
= NULL
;
4743 * Check if there's a AFPRESOURCE_STREAM from the VFS streams backend
4744 * and if yes, remove it from the list
4746 for (i
= 0; i
< num_streams
; i
++) {
4747 if (strequal_m(stream
[i
].name
, AFPRESOURCE_STREAM
)) {
4752 if (i
< num_streams
) {
4753 DBG_WARNING("Unexpected AFPRESOURCE_STREAM on [%s]\n",
4754 smb_fname_str_dbg(smb_fname
));
4756 ok
= del_fruit_stream(mem_ctx
, pnum_streams
, pstreams
,
4757 AFPRESOURCE_STREAM
);
4759 return NT_STATUS_INTERNAL_ERROR
;
4763 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_RSRC
);
4765 return NT_STATUS_OK
;
4768 rlen
= ad_getentrylen(ad
, ADEID_RFORK
);
4772 return NT_STATUS_OK
;
4775 ok
= add_fruit_stream(mem_ctx
, pnum_streams
, pstreams
,
4776 AFPRESOURCE_STREAM_NAME
, rlen
,
4777 smb_roundup(handle
->conn
, rlen
));
4779 return NT_STATUS_NO_MEMORY
;
4782 return NT_STATUS_OK
;
4785 static NTSTATUS
fruit_streaminfo_rsrc(vfs_handle_struct
*handle
,
4786 struct files_struct
*fsp
,
4787 const struct smb_filename
*smb_fname
,
4788 TALLOC_CTX
*mem_ctx
,
4789 unsigned int *pnum_streams
,
4790 struct stream_struct
**pstreams
)
4792 struct fruit_config_data
*config
= NULL
;
4795 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
4796 return NT_STATUS_INTERNAL_ERROR
);
4798 switch (config
->rsrc
) {
4799 case FRUIT_RSRC_STREAM
:
4800 status
= fruit_streaminfo_rsrc_stream(handle
, fsp
, smb_fname
,
4801 mem_ctx
, pnum_streams
,
4805 case FRUIT_RSRC_XATTR
:
4806 status
= fruit_streaminfo_rsrc_xattr(handle
, fsp
, smb_fname
,
4807 mem_ctx
, pnum_streams
,
4811 case FRUIT_RSRC_ADFILE
:
4812 status
= fruit_streaminfo_rsrc_adouble(handle
, fsp
, smb_fname
,
4813 mem_ctx
, pnum_streams
,
4818 return NT_STATUS_INTERNAL_ERROR
;
4824 static NTSTATUS
fruit_streaminfo(vfs_handle_struct
*handle
,
4825 struct files_struct
*fsp
,
4826 const struct smb_filename
*smb_fname
,
4827 TALLOC_CTX
*mem_ctx
,
4828 unsigned int *pnum_streams
,
4829 struct stream_struct
**pstreams
)
4831 struct fruit_config_data
*config
= NULL
;
4834 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
4835 return NT_STATUS_UNSUCCESSFUL
);
4837 DBG_DEBUG("Path [%s]\n", smb_fname_str_dbg(smb_fname
));
4839 status
= SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, smb_fname
, mem_ctx
,
4840 pnum_streams
, pstreams
);
4841 if (!NT_STATUS_IS_OK(status
)) {
4845 status
= fruit_streaminfo_meta(handle
, fsp
, smb_fname
,
4846 mem_ctx
, pnum_streams
, pstreams
);
4847 if (!NT_STATUS_IS_OK(status
)) {
4851 status
= fruit_streaminfo_rsrc(handle
, fsp
, smb_fname
,
4852 mem_ctx
, pnum_streams
, pstreams
);
4853 if (!NT_STATUS_IS_OK(status
)) {
4857 return NT_STATUS_OK
;
4860 static int fruit_ntimes(vfs_handle_struct
*handle
,
4861 const struct smb_filename
*smb_fname
,
4862 struct smb_file_time
*ft
)
4865 struct adouble
*ad
= NULL
;
4866 struct fruit_config_data
*config
= NULL
;
4868 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
4871 if ((config
->meta
!= FRUIT_META_NETATALK
) ||
4872 null_timespec(ft
->create_time
))
4874 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
4877 DEBUG(10,("set btime for %s to %s\n", smb_fname_str_dbg(smb_fname
),
4878 time_to_asc(convert_timespec_to_time_t(ft
->create_time
))));
4880 ad
= ad_get(talloc_tos(), handle
, smb_fname
, ADOUBLE_META
);
4885 ad_setdate(ad
, AD_DATE_CREATE
| AD_DATE_UNIX
,
4886 convert_time_t_to_uint32_t(ft
->create_time
.tv_sec
));
4888 rc
= ad_set(ad
, smb_fname
);
4894 DEBUG(1, ("fruit_ntimes: %s\n", smb_fname_str_dbg(smb_fname
)));
4897 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
4900 static int fruit_fallocate(struct vfs_handle_struct
*handle
,
4901 struct files_struct
*fsp
,
4906 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
4909 return SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
4912 /* Let the pwrite code path handle it. */
4917 static int fruit_ftruncate_rsrc_xattr(struct vfs_handle_struct
*handle
,
4918 struct files_struct
*fsp
,
4922 return SMB_VFS_FREMOVEXATTR(fsp
, AFPRESOURCE_EA_NETATALK
);
4925 #ifdef HAVE_ATTROPEN
4926 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, offset
);
4931 static int fruit_ftruncate_rsrc_adouble(struct vfs_handle_struct
*handle
,
4932 struct files_struct
*fsp
,
4936 struct adouble
*ad
= NULL
;
4939 ad
= ad_fget(talloc_tos(), handle
, fsp
, ADOUBLE_RSRC
);
4941 DBG_DEBUG("ad_get [%s] failed [%s]\n",
4942 fsp_str_dbg(fsp
), strerror(errno
));
4946 ad_off
= ad_getentryoff(ad
, ADEID_RFORK
);
4948 rc
= ftruncate(fsp
->fh
->fd
, offset
+ ad_off
);
4954 ad_setentrylen(ad
, ADEID_RFORK
, offset
);
4956 rc
= ad_fset(ad
, fsp
);
4958 DBG_ERR("ad_fset [%s] failed [%s]\n",
4959 fsp_str_dbg(fsp
), strerror(errno
));
4968 static int fruit_ftruncate_rsrc_stream(struct vfs_handle_struct
*handle
,
4969 struct files_struct
*fsp
,
4973 return SMB_VFS_NEXT_UNLINK(handle
, fsp
->fsp_name
);
4976 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, offset
);
4979 static int fruit_ftruncate_rsrc(struct vfs_handle_struct
*handle
,
4980 struct files_struct
*fsp
,
4983 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
4986 switch (fio
->config
->rsrc
) {
4987 case FRUIT_RSRC_XATTR
:
4988 ret
= fruit_ftruncate_rsrc_xattr(handle
, fsp
, offset
);
4991 case FRUIT_RSRC_ADFILE
:
4992 ret
= fruit_ftruncate_rsrc_adouble(handle
, fsp
, offset
);
4995 case FRUIT_RSRC_STREAM
:
4996 ret
= fruit_ftruncate_rsrc_stream(handle
, fsp
, offset
);
5000 DBG_ERR("Unexpected rsrc config [%d]\n", fio
->config
->rsrc
);
5008 static int fruit_ftruncate_meta(struct vfs_handle_struct
*handle
,
5009 struct files_struct
*fsp
,
5013 DBG_WARNING("ftruncate %s to %jd",
5014 fsp_str_dbg(fsp
), (intmax_t)offset
);
5015 /* OS X returns NT_STATUS_ALLOTTED_SPACE_EXCEEDED */
5020 /* OS X returns success but does nothing */
5021 DBG_INFO("ignoring ftruncate %s to %jd\n",
5022 fsp_str_dbg(fsp
), (intmax_t)offset
);
5026 static int fruit_ftruncate(struct vfs_handle_struct
*handle
,
5027 struct files_struct
*fsp
,
5030 struct fio
*fio
= (struct fio
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
5033 DBG_DEBUG("Path [%s] offset [%"PRIdMAX
"]\n", fsp_str_dbg(fsp
),
5037 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, offset
);
5040 if (fio
->type
== ADOUBLE_META
) {
5041 ret
= fruit_ftruncate_meta(handle
, fsp
, offset
);
5043 ret
= fruit_ftruncate_rsrc(handle
, fsp
, offset
);
5046 DBG_DEBUG("Path [%s] result [%d]\n", fsp_str_dbg(fsp
), ret
);
5050 static NTSTATUS
fruit_create_file(vfs_handle_struct
*handle
,
5051 struct smb_request
*req
,
5052 uint16_t root_dir_fid
,
5053 struct smb_filename
*smb_fname
,
5054 uint32_t access_mask
,
5055 uint32_t share_access
,
5056 uint32_t create_disposition
,
5057 uint32_t create_options
,
5058 uint32_t file_attributes
,
5059 uint32_t oplock_request
,
5060 struct smb2_lease
*lease
,
5061 uint64_t allocation_size
,
5062 uint32_t private_flags
,
5063 struct security_descriptor
*sd
,
5064 struct ea_list
*ea_list
,
5065 files_struct
**result
,
5067 const struct smb2_create_blobs
*in_context_blobs
,
5068 struct smb2_create_blobs
*out_context_blobs
)
5071 struct fruit_config_data
*config
= NULL
;
5072 files_struct
*fsp
= NULL
;
5074 status
= check_aapl(handle
, req
, in_context_blobs
, out_context_blobs
);
5075 if (!NT_STATUS_IS_OK(status
)) {
5079 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
5080 return NT_STATUS_UNSUCCESSFUL
);
5082 status
= SMB_VFS_NEXT_CREATE_FILE(
5083 handle
, req
, root_dir_fid
, smb_fname
,
5084 access_mask
, share_access
,
5085 create_disposition
, create_options
,
5086 file_attributes
, oplock_request
,
5088 allocation_size
, private_flags
,
5089 sd
, ea_list
, result
,
5090 pinfo
, in_context_blobs
, out_context_blobs
);
5091 if (!NT_STATUS_IS_OK(status
)) {
5097 if (global_fruit_config
.nego_aapl
) {
5098 if (config
->posix_rename
&& fsp
->is_directory
) {
5100 * Enable POSIX directory rename behaviour
5102 fsp
->posix_flags
|= FSP_POSIX_FLAGS_RENAME
;
5107 * If this is a plain open for existing files, opening an 0
5108 * byte size resource fork MUST fail with
5109 * NT_STATUS_OBJECT_NAME_NOT_FOUND.
5111 * Cf the vfs_fruit torture tests in test_rfork_create().
5113 if (is_afpresource_stream(fsp
->fsp_name
) &&
5114 create_disposition
== FILE_OPEN
)
5116 if (fsp
->fsp_name
->st
.st_ex_size
== 0) {
5117 status
= NT_STATUS_OBJECT_NAME_NOT_FOUND
;
5122 if (is_ntfs_stream_smb_fname(smb_fname
)
5123 || fsp
->is_directory
) {
5127 if (config
->locking
== FRUIT_LOCKING_NETATALK
) {
5128 status
= fruit_check_access(
5131 map_share_mode_to_deny_mode(share_access
, 0));
5132 if (!NT_STATUS_IS_OK(status
)) {
5140 DEBUG(10, ("fruit_create_file: %s\n", nt_errstr(status
)));
5143 close_file(req
, fsp
, ERROR_CLOSE
);
5144 *result
= fsp
= NULL
;
5150 static NTSTATUS
fruit_readdir_attr(struct vfs_handle_struct
*handle
,
5151 const struct smb_filename
*fname
,
5152 TALLOC_CTX
*mem_ctx
,
5153 struct readdir_attr_data
**pattr_data
)
5155 struct fruit_config_data
*config
= NULL
;
5156 struct readdir_attr_data
*attr_data
;
5159 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
5160 struct fruit_config_data
,
5161 return NT_STATUS_UNSUCCESSFUL
);
5163 if (!global_fruit_config
.nego_aapl
) {
5164 return SMB_VFS_NEXT_READDIR_ATTR(handle
, fname
, mem_ctx
, pattr_data
);
5167 DEBUG(10, ("fruit_readdir_attr %s\n", fname
->base_name
));
5169 *pattr_data
= talloc_zero(mem_ctx
, struct readdir_attr_data
);
5170 if (*pattr_data
== NULL
) {
5171 return NT_STATUS_UNSUCCESSFUL
;
5173 attr_data
= *pattr_data
;
5174 attr_data
->type
= RDATTR_AAPL
;
5177 * Mac metadata: compressed FinderInfo, resource fork length
5180 status
= readdir_attr_macmeta(handle
, fname
, attr_data
);
5181 if (!NT_STATUS_IS_OK(status
)) {
5183 * Error handling is tricky: if we return failure from
5184 * this function, the corresponding directory entry
5185 * will to be passed to the client, so we really just
5186 * want to error out on fatal errors.
5188 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
5196 if (config
->unix_info_enabled
) {
5197 attr_data
->attr_data
.aapl
.unix_mode
= fname
->st
.st_ex_mode
;
5203 if (!config
->readdir_attr_max_access
) {
5204 attr_data
->attr_data
.aapl
.max_access
= FILE_GENERIC_ALL
;
5206 status
= smbd_calculate_access_mask(
5210 SEC_FLAG_MAXIMUM_ALLOWED
,
5211 &attr_data
->attr_data
.aapl
.max_access
);
5212 if (!NT_STATUS_IS_OK(status
)) {
5217 return NT_STATUS_OK
;
5220 DEBUG(1, ("fruit_readdir_attr %s, error: %s\n",
5221 fname
->base_name
, nt_errstr(status
)));
5222 TALLOC_FREE(*pattr_data
);
5226 static NTSTATUS
fruit_fget_nt_acl(vfs_handle_struct
*handle
,
5228 uint32_t security_info
,
5229 TALLOC_CTX
*mem_ctx
,
5230 struct security_descriptor
**ppdesc
)
5233 struct security_ace ace
;
5235 struct fruit_config_data
*config
;
5237 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
5238 struct fruit_config_data
,
5239 return NT_STATUS_UNSUCCESSFUL
);
5241 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
5243 if (!NT_STATUS_IS_OK(status
)) {
5248 * Add MS NFS style ACEs with uid, gid and mode
5250 if (!global_fruit_config
.nego_aapl
) {
5251 return NT_STATUS_OK
;
5253 if (!config
->unix_info_enabled
) {
5254 return NT_STATUS_OK
;
5257 /* MS NFS style mode */
5258 sid_compose(&sid
, &global_sid_Unix_NFS_Mode
, fsp
->fsp_name
->st
.st_ex_mode
);
5259 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
5260 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
5261 if (!NT_STATUS_IS_OK(status
)) {
5262 DEBUG(1,("failed to add MS NFS style ACE\n"));
5266 /* MS NFS style uid */
5267 sid_compose(&sid
, &global_sid_Unix_NFS_Users
, fsp
->fsp_name
->st
.st_ex_uid
);
5268 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
5269 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
5270 if (!NT_STATUS_IS_OK(status
)) {
5271 DEBUG(1,("failed to add MS NFS style ACE\n"));
5275 /* MS NFS style gid */
5276 sid_compose(&sid
, &global_sid_Unix_NFS_Groups
, fsp
->fsp_name
->st
.st_ex_gid
);
5277 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
5278 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
5279 if (!NT_STATUS_IS_OK(status
)) {
5280 DEBUG(1,("failed to add MS NFS style ACE\n"));
5284 return NT_STATUS_OK
;
5287 static NTSTATUS
fruit_fset_nt_acl(vfs_handle_struct
*handle
,
5289 uint32_t security_info_sent
,
5290 const struct security_descriptor
*psd
)
5294 mode_t ms_nfs_mode
= 0;
5297 DBG_DEBUG("fruit_fset_nt_acl: %s\n", fsp_str_dbg(fsp
));
5299 status
= check_ms_nfs(handle
, fsp
, psd
, &ms_nfs_mode
, &do_chmod
);
5300 if (!NT_STATUS_IS_OK(status
)) {
5301 DEBUG(1, ("fruit_fset_nt_acl: check_ms_nfs failed%s\n", fsp_str_dbg(fsp
)));
5305 status
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
5306 if (!NT_STATUS_IS_OK(status
)) {
5307 DEBUG(1, ("fruit_fset_nt_acl: SMB_VFS_NEXT_FSET_NT_ACL failed%s\n", fsp_str_dbg(fsp
)));
5312 if (fsp
->fh
->fd
!= -1) {
5313 result
= SMB_VFS_FCHMOD(fsp
, ms_nfs_mode
);
5315 result
= SMB_VFS_CHMOD(fsp
->conn
,
5321 DEBUG(1, ("chmod: %s, result: %d, %04o error %s\n", fsp_str_dbg(fsp
),
5322 result
, (unsigned)ms_nfs_mode
,
5324 status
= map_nt_error_from_unix(errno
);
5329 return NT_STATUS_OK
;
5332 static struct vfs_offload_ctx
*fruit_offload_ctx
;
5334 struct fruit_offload_read_state
{
5335 struct vfs_handle_struct
*handle
;
5336 struct tevent_context
*ev
;
5342 static void fruit_offload_read_done(struct tevent_req
*subreq
);
5344 static struct tevent_req
*fruit_offload_read_send(
5345 TALLOC_CTX
*mem_ctx
,
5346 struct tevent_context
*ev
,
5347 struct vfs_handle_struct
*handle
,
5354 struct tevent_req
*req
= NULL
;
5355 struct tevent_req
*subreq
= NULL
;
5356 struct fruit_offload_read_state
*state
= NULL
;
5358 req
= tevent_req_create(mem_ctx
, &state
,
5359 struct fruit_offload_read_state
);
5363 *state
= (struct fruit_offload_read_state
) {
5370 subreq
= SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx
, ev
, handle
, fsp
,
5371 fsctl
, ttl
, offset
, to_copy
);
5372 if (tevent_req_nomem(subreq
, req
)) {
5373 return tevent_req_post(req
, ev
);
5375 tevent_req_set_callback(subreq
, fruit_offload_read_done
, req
);
5379 static void fruit_offload_read_done(struct tevent_req
*subreq
)
5381 struct tevent_req
*req
= tevent_req_callback_data(
5382 subreq
, struct tevent_req
);
5383 struct fruit_offload_read_state
*state
= tevent_req_data(
5384 req
, struct fruit_offload_read_state
);
5387 status
= SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq
,
5391 TALLOC_FREE(subreq
);
5392 if (tevent_req_nterror(req
, status
)) {
5396 if (state
->fsctl
!= FSCTL_SRV_REQUEST_RESUME_KEY
) {
5397 tevent_req_done(req
);
5401 status
= vfs_offload_token_ctx_init(state
->fsp
->conn
->sconn
->client
,
5402 &fruit_offload_ctx
);
5403 if (tevent_req_nterror(req
, status
)) {
5407 status
= vfs_offload_token_db_store_fsp(fruit_offload_ctx
,
5410 if (tevent_req_nterror(req
, status
)) {
5414 tevent_req_done(req
);
5418 static NTSTATUS
fruit_offload_read_recv(struct tevent_req
*req
,
5419 struct vfs_handle_struct
*handle
,
5420 TALLOC_CTX
*mem_ctx
,
5423 struct fruit_offload_read_state
*state
= tevent_req_data(
5424 req
, struct fruit_offload_read_state
);
5427 if (tevent_req_is_nterror(req
, &status
)) {
5428 tevent_req_received(req
);
5432 token
->length
= state
->token
.length
;
5433 token
->data
= talloc_move(mem_ctx
, &state
->token
.data
);
5435 tevent_req_received(req
);
5436 return NT_STATUS_OK
;
5439 struct fruit_offload_write_state
{
5440 struct vfs_handle_struct
*handle
;
5442 struct files_struct
*src_fsp
;
5443 struct files_struct
*dst_fsp
;
5447 static void fruit_offload_write_done(struct tevent_req
*subreq
);
5448 static struct tevent_req
*fruit_offload_write_send(struct vfs_handle_struct
*handle
,
5449 TALLOC_CTX
*mem_ctx
,
5450 struct tevent_context
*ev
,
5453 off_t transfer_offset
,
5454 struct files_struct
*dest_fsp
,
5458 struct tevent_req
*req
, *subreq
;
5459 struct fruit_offload_write_state
*state
;
5461 struct fruit_config_data
*config
;
5462 off_t src_off
= transfer_offset
;
5463 files_struct
*src_fsp
= NULL
;
5464 off_t to_copy
= num
;
5465 bool copyfile_enabled
= false;
5467 DEBUG(10,("soff: %ju, doff: %ju, len: %ju\n",
5468 (uintmax_t)src_off
, (uintmax_t)dest_off
, (uintmax_t)num
));
5470 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
5471 struct fruit_config_data
,
5474 req
= tevent_req_create(mem_ctx
, &state
,
5475 struct fruit_offload_write_state
);
5479 state
->handle
= handle
;
5480 state
->dst_fsp
= dest_fsp
;
5483 case FSCTL_SRV_COPYCHUNK
:
5484 case FSCTL_SRV_COPYCHUNK_WRITE
:
5485 copyfile_enabled
= config
->copyfile_enabled
;
5492 * Check if this a OS X copyfile style copychunk request with
5493 * a requested chunk count of 0 that was translated to a
5494 * offload_write_send VFS call overloading the parameters src_off
5495 * = dest_off = num = 0.
5497 if (copyfile_enabled
&& num
== 0 && src_off
== 0 && dest_off
== 0) {
5498 status
= vfs_offload_token_db_fetch_fsp(
5499 fruit_offload_ctx
, token
, &src_fsp
);
5500 if (tevent_req_nterror(req
, status
)) {
5501 return tevent_req_post(req
, ev
);
5503 state
->src_fsp
= src_fsp
;
5505 status
= vfs_stat_fsp(src_fsp
);
5506 if (tevent_req_nterror(req
, status
)) {
5507 return tevent_req_post(req
, ev
);
5510 to_copy
= src_fsp
->fsp_name
->st
.st_ex_size
;
5511 state
->is_copyfile
= true;
5514 subreq
= SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle
,
5523 if (tevent_req_nomem(subreq
, req
)) {
5524 return tevent_req_post(req
, ev
);
5527 tevent_req_set_callback(subreq
, fruit_offload_write_done
, req
);
5531 static void fruit_offload_write_done(struct tevent_req
*subreq
)
5533 struct tevent_req
*req
= tevent_req_callback_data(
5534 subreq
, struct tevent_req
);
5535 struct fruit_offload_write_state
*state
= tevent_req_data(
5536 req
, struct fruit_offload_write_state
);
5538 unsigned int num_streams
= 0;
5539 struct stream_struct
*streams
= NULL
;
5541 struct smb_filename
*src_fname_tmp
= NULL
;
5542 struct smb_filename
*dst_fname_tmp
= NULL
;
5544 status
= SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state
->handle
,
5547 TALLOC_FREE(subreq
);
5548 if (tevent_req_nterror(req
, status
)) {
5552 if (!state
->is_copyfile
) {
5553 tevent_req_done(req
);
5558 * Now copy all remaining streams. We know the share supports
5559 * streams, because we're in vfs_fruit. We don't do this async
5560 * because streams are few and small.
5562 status
= vfs_streaminfo(state
->handle
->conn
, state
->src_fsp
,
5563 state
->src_fsp
->fsp_name
,
5564 req
, &num_streams
, &streams
);
5565 if (tevent_req_nterror(req
, status
)) {
5569 if (num_streams
== 1) {
5570 /* There is always one stream, ::$DATA. */
5571 tevent_req_done(req
);
5575 for (i
= 0; i
< num_streams
; i
++) {
5576 DEBUG(10, ("%s: stream: '%s'/%zu\n",
5577 __func__
, streams
[i
].name
, (size_t)streams
[i
].size
));
5579 src_fname_tmp
= synthetic_smb_fname(
5581 state
->src_fsp
->fsp_name
->base_name
,
5584 state
->src_fsp
->fsp_name
->flags
);
5585 if (tevent_req_nomem(src_fname_tmp
, req
)) {
5589 if (is_ntfs_default_stream_smb_fname(src_fname_tmp
)) {
5590 TALLOC_FREE(src_fname_tmp
);
5594 dst_fname_tmp
= synthetic_smb_fname(
5596 state
->dst_fsp
->fsp_name
->base_name
,
5599 state
->dst_fsp
->fsp_name
->flags
);
5600 if (tevent_req_nomem(dst_fname_tmp
, req
)) {
5601 TALLOC_FREE(src_fname_tmp
);
5605 status
= copy_file(req
,
5606 state
->handle
->conn
,
5609 OPENX_FILE_CREATE_IF_NOT_EXIST
,
5611 if (!NT_STATUS_IS_OK(status
)) {
5612 DEBUG(1, ("%s: copy %s to %s failed: %s\n", __func__
,
5613 smb_fname_str_dbg(src_fname_tmp
),
5614 smb_fname_str_dbg(dst_fname_tmp
),
5615 nt_errstr(status
)));
5616 TALLOC_FREE(src_fname_tmp
);
5617 TALLOC_FREE(dst_fname_tmp
);
5618 tevent_req_nterror(req
, status
);
5622 TALLOC_FREE(src_fname_tmp
);
5623 TALLOC_FREE(dst_fname_tmp
);
5626 TALLOC_FREE(streams
);
5627 TALLOC_FREE(src_fname_tmp
);
5628 TALLOC_FREE(dst_fname_tmp
);
5629 tevent_req_done(req
);
5632 static NTSTATUS
fruit_offload_write_recv(struct vfs_handle_struct
*handle
,
5633 struct tevent_req
*req
,
5636 struct fruit_offload_write_state
*state
= tevent_req_data(
5637 req
, struct fruit_offload_write_state
);
5640 if (tevent_req_is_nterror(req
, &status
)) {
5641 DEBUG(1, ("server side copy chunk failed: %s\n",
5642 nt_errstr(status
)));
5644 tevent_req_received(req
);
5648 *copied
= state
->copied
;
5649 tevent_req_received(req
);
5651 return NT_STATUS_OK
;
5654 static struct vfs_fn_pointers vfs_fruit_fns
= {
5655 .connect_fn
= fruit_connect
,
5657 /* File operations */
5658 .chmod_fn
= fruit_chmod
,
5659 .chown_fn
= fruit_chown
,
5660 .unlink_fn
= fruit_unlink
,
5661 .rename_fn
= fruit_rename
,
5662 .rmdir_fn
= fruit_rmdir
,
5663 .open_fn
= fruit_open
,
5664 .pread_fn
= fruit_pread
,
5665 .pwrite_fn
= fruit_pwrite
,
5666 .pread_send_fn
= fruit_pread_send
,
5667 .pread_recv_fn
= fruit_pread_recv
,
5668 .pwrite_send_fn
= fruit_pwrite_send
,
5669 .pwrite_recv_fn
= fruit_pwrite_recv
,
5670 .stat_fn
= fruit_stat
,
5671 .lstat_fn
= fruit_lstat
,
5672 .fstat_fn
= fruit_fstat
,
5673 .streaminfo_fn
= fruit_streaminfo
,
5674 .ntimes_fn
= fruit_ntimes
,
5675 .ftruncate_fn
= fruit_ftruncate
,
5676 .fallocate_fn
= fruit_fallocate
,
5677 .create_file_fn
= fruit_create_file
,
5678 .readdir_attr_fn
= fruit_readdir_attr
,
5679 .offload_read_send_fn
= fruit_offload_read_send
,
5680 .offload_read_recv_fn
= fruit_offload_read_recv
,
5681 .offload_write_send_fn
= fruit_offload_write_send
,
5682 .offload_write_recv_fn
= fruit_offload_write_recv
,
5684 /* NT ACL operations */
5685 .fget_nt_acl_fn
= fruit_fget_nt_acl
,
5686 .fset_nt_acl_fn
= fruit_fset_nt_acl
,
5689 NTSTATUS
vfs_fruit_init(TALLOC_CTX
*);
5690 NTSTATUS
vfs_fruit_init(TALLOC_CTX
*ctx
)
5692 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "fruit",
5694 if (!NT_STATUS_IS_OK(ret
)) {
5698 vfs_fruit_debug_level
= debug_add_class("fruit");
5699 if (vfs_fruit_debug_level
== -1) {
5700 vfs_fruit_debug_level
= DBGC_VFS
;
5701 DEBUG(0, ("%s: Couldn't register custom debugging class!\n",
5704 DEBUG(10, ("%s: Debug class number of '%s': %d\n",
5705 "vfs_fruit_init","fruit",vfs_fruit_debug_level
));