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/sys_rw.h"
35 * Enhanced OS X and Netatalk compatibility
36 * ========================================
38 * This modules takes advantage of vfs_streams_xattr and
39 * vfs_catia. VFS modules vfs_fruit and vfs_streams_xattr must be
40 * loaded in the correct order:
42 * vfs modules = catia fruit streams_xattr
44 * The module intercepts the OS X special streams "AFP_AfpInfo" and
45 * "AFP_Resource" and handles them in a special way. All other named
46 * streams are deferred to vfs_streams_xattr.
48 * The OS X client maps all NTFS illegal characters to the Unicode
49 * private range. This module optionally stores the charcters using
50 * their native ASCII encoding using vfs_catia. If you're not enabling
51 * this feature, you can skip catia from vfs modules.
53 * Finally, open modes are optionally checked against Netatalk AFP
56 * The "AFP_AfpInfo" named stream is a binary blob containing OS X
57 * extended metadata for files and directories. This module optionally
58 * reads and stores this metadata in a way compatible with Netatalk 3
59 * which stores the metadata in an EA "org.netatalk.metadata". Cf
60 * source3/include/MacExtensions.h for a description of the binary
63 * The "AFP_Resource" named stream may be arbitrarily large, thus it
64 * can't be stored in an xattr on most filesystem. ZFS on Solaris is
65 * the only available filesystem where xattrs can be of any size and
66 * the OS supports using the file APIs for xattrs.
68 * The AFP_Resource stream is stored in an AppleDouble file prepending
69 * "._" to the filename. On Solaris with ZFS the stream is optionally
70 * stored in an EA "org.netatalk.ressource".
76 * The OS X SMB client sends xattrs as ADS too. For xattr interop with
77 * other protocols you may want to adjust the xattr names the VFS
78 * module vfs_streams_xattr uses for storing ADS's. This defaults to
79 * user.DosStream.ADS_NAME:$DATA and can be changed by specifying
80 * these module parameters:
82 * streams_xattr:prefix = user.
83 * streams_xattr:store_stream_type = false
89 * - log diagnostic if any needed VFS module is not loaded
90 * (eg with lp_vfs_objects())
94 static int vfs_fruit_debug_level = DBGC_VFS;
97 #define DBGC_CLASS vfs_fruit_debug_level
99 #define FRUIT_PARAM_TYPE_NAME "fruit"
100 #define ADOUBLE_NAME_PREFIX "._"
104 * This is hokey, but what else can we do?
106 #if defined(HAVE_ATTROPEN) || defined(FREEBSD)
107 #define AFPINFO_EA_NETATALK "org.netatalk.Metadata"
108 #define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
110 #define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata"
111 #define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
114 enum apple_fork {APPLE_FORK_DATA, APPLE_FORK_RSRC};
116 enum fruit_rsrc {FRUIT_RSRC_STREAM, FRUIT_RSRC_ADFILE, FRUIT_RSRC_XATTR};
117 enum fruit_meta {FRUIT_META_STREAM, FRUIT_META_NETATALK};
118 enum fruit_locking {FRUIT_LOCKING_NETATALK, FRUIT_LOCKING_NONE};
119 enum fruit_encoding {FRUIT_ENC_NATIVE, FRUIT_ENC_PRIVATE};
121 struct fruit_config_data {
122 enum fruit_rsrc rsrc;
123 enum fruit_meta meta;
124 enum fruit_locking locking;
125 enum fruit_encoding encoding;
127 bool readdir_attr_enabled;
128 bool unix_info_enabled;
129 bool veto_appledouble;
132 * Additional options, all enabled by default,
133 * possibly useful for analyzing performance. The associated
134 * operations with each of them may be expensive, so having
135 * the chance to disable them individually gives a chance
136 * tweaking the setup for the particular usecase.
138 bool readdir_attr_rsize;
139 bool readdir_attr_finder_info;
140 bool readdir_attr_max_access;
143 static const struct enum_list fruit_rsrc[] = {
144 {FRUIT_RSRC_STREAM, "stream"}, /* pass on to vfs_streams_xattr */
145 {FRUIT_RSRC_ADFILE, "file"}, /* ._ AppleDouble file */
146 {FRUIT_RSRC_XATTR, "xattr"}, /* Netatalk compatible xattr (ZFS only) */
150 static const struct enum_list fruit_meta[] = {
151 {FRUIT_META_STREAM, "stream"}, /* pass on to vfs_streams_xattr */
152 {FRUIT_META_NETATALK, "netatalk"}, /* Netatalk compatible xattr */
156 static const struct enum_list fruit_locking[] = {
157 {FRUIT_LOCKING_NETATALK, "netatalk"}, /* synchronize locks with Netatalk */
158 {FRUIT_LOCKING_NONE, "none"},
162 static const struct enum_list fruit_encoding[] = {
163 {FRUIT_ENC_NATIVE, "native"}, /* map unicode private chars to ASCII */
164 {FRUIT_ENC_PRIVATE, "private"}, /* keep unicode private chars */
168 /*****************************************************************************
169 * Defines, functions and data structures that deal with AppleDouble
170 *****************************************************************************/
173 * There are two AppleDouble blobs we deal with:
175 * - ADOUBLE_META - AppleDouble blob used by Netatalk for storing
176 * metadata in an xattr
178 * - ADOUBLE_RSRC - AppleDouble blob used by OS X and Netatalk in
181 typedef enum {ADOUBLE_META, ADOUBLE_RSRC} adouble_type_t;
184 #define AD_VERSION2 0x00020000
185 #define AD_VERSION AD_VERSION2
188 * AppleDouble entry IDs.
190 #define ADEID_DFORK 1
191 #define ADEID_RFORK 2
193 #define ADEID_COMMENT 4
194 #define ADEID_ICONBW 5
195 #define ADEID_ICONCOL 6
196 #define ADEID_FILEI 7
197 #define ADEID_FILEDATESI 8
198 #define ADEID_FINDERI 9
199 #define ADEID_MACFILEI 10
200 #define ADEID_PRODOSFILEI 11
201 #define ADEID_MSDOSFILEI 12
202 #define ADEID_SHORTNAME 13
203 #define ADEID_AFPFILEI 14
206 /* Private Netatalk entries */
207 #define ADEID_PRIVDEV 16
208 #define ADEID_PRIVINO 17
209 #define ADEID_PRIVSYN 18
210 #define ADEID_PRIVID 19
211 #define ADEID_MAX (ADEID_PRIVID + 1)
214 * These are the real ids for the private entries,
215 * as stored in the adouble file
217 #define AD_DEV 0x80444556
218 #define AD_INO 0x80494E4F
219 #define AD_SYN 0x8053594E
220 #define AD_ID 0x8053567E
222 /* Number of actually used entries */
223 #define ADEID_NUM_XATTR 8
224 #define ADEID_NUM_DOT_UND 2
225 #define ADEID_NUM_RSRC_XATTR 1
227 /* AppleDouble magic */
228 #define AD_APPLESINGLE_MAGIC 0x00051600
229 #define AD_APPLEDOUBLE_MAGIC 0x00051607
230 #define AD_MAGIC AD_APPLEDOUBLE_MAGIC
232 /* Sizes of relevant entry bits */
233 #define ADEDLEN_MAGIC 4
234 #define ADEDLEN_VERSION 4
235 #define ADEDLEN_FILLER 16
236 #define AD_FILLER_TAG "Netatalk " /* should be 16 bytes */
237 #define ADEDLEN_NENTRIES 2
238 #define AD_HEADER_LEN (ADEDLEN_MAGIC + ADEDLEN_VERSION + \
239 ADEDLEN_FILLER + ADEDLEN_NENTRIES) /* 26 */
240 #define AD_ENTRY_LEN_EID 4
241 #define AD_ENTRY_LEN_OFF 4
242 #define AD_ENTRY_LEN_LEN 4
243 #define AD_ENTRY_LEN (AD_ENTRY_LEN_EID + AD_ENTRY_LEN_OFF + AD_ENTRY_LEN_LEN)
246 #define ADEDLEN_NAME 255
247 #define ADEDLEN_COMMENT 200
248 #define ADEDLEN_FILEI 16
249 #define ADEDLEN_FINDERI 32
250 #define ADEDLEN_FILEDATESI 16
251 #define ADEDLEN_SHORTNAME 12 /* length up to 8.3 */
252 #define ADEDLEN_AFPFILEI 4
253 #define ADEDLEN_MACFILEI 4
254 #define ADEDLEN_PRODOSFILEI 8
255 #define ADEDLEN_MSDOSFILEI 2
256 #define ADEDLEN_DID 4
257 #define ADEDLEN_PRIVDEV 8
258 #define ADEDLEN_PRIVINO 8
259 #define ADEDLEN_PRIVSYN 8
260 #define ADEDLEN_PRIVID 4
263 #define ADEDOFF_MAGIC 0
264 #define ADEDOFF_VERSION (ADEDOFF_MAGIC + ADEDLEN_MAGIC)
265 #define ADEDOFF_FILLER (ADEDOFF_VERSION + ADEDLEN_VERSION)
266 #define ADEDOFF_NENTRIES (ADEDOFF_FILLER + ADEDLEN_FILLER)
268 #define ADEDOFF_FINDERI_XATTR (AD_HEADER_LEN + \
269 (ADEID_NUM_XATTR * AD_ENTRY_LEN))
270 #define ADEDOFF_COMMENT_XATTR (ADEDOFF_FINDERI_XATTR + ADEDLEN_FINDERI)
271 #define ADEDOFF_FILEDATESI_XATTR (ADEDOFF_COMMENT_XATTR + ADEDLEN_COMMENT)
272 #define ADEDOFF_AFPFILEI_XATTR (ADEDOFF_FILEDATESI_XATTR + \
274 #define ADEDOFF_PRIVDEV_XATTR (ADEDOFF_AFPFILEI_XATTR + ADEDLEN_AFPFILEI)
275 #define ADEDOFF_PRIVINO_XATTR (ADEDOFF_PRIVDEV_XATTR + ADEDLEN_PRIVDEV)
276 #define ADEDOFF_PRIVSYN_XATTR (ADEDOFF_PRIVINO_XATTR + ADEDLEN_PRIVINO)
277 #define ADEDOFF_PRIVID_XATTR (ADEDOFF_PRIVSYN_XATTR + ADEDLEN_PRIVSYN)
279 #define ADEDOFF_FINDERI_DOT_UND (AD_HEADER_LEN + \
280 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN))
281 #define ADEDOFF_RFORK_DOT_UND (ADEDOFF_FINDERI_DOT_UND + ADEDLEN_FINDERI)
283 #define AD_DATASZ_XATTR (AD_HEADER_LEN + \
284 (ADEID_NUM_XATTR * AD_ENTRY_LEN) + \
285 ADEDLEN_FINDERI + ADEDLEN_COMMENT + \
286 ADEDLEN_FILEDATESI + ADEDLEN_AFPFILEI + \
287 ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + \
288 ADEDLEN_PRIVSYN + ADEDLEN_PRIVID)
290 #if AD_DATASZ_XATTR != 402
291 #error bad size for AD_DATASZ_XATTR
294 #define AD_DATASZ_DOT_UND (AD_HEADER_LEN + \
295 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN) + \
297 #if AD_DATASZ_DOT_UND != 82
298 #error bad size for AD_DATASZ_DOT_UND
302 * Sharemode locks fcntl() offsets
304 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
305 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
307 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
309 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
311 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
312 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
313 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
314 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
315 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
316 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
317 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
318 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
319 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
320 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
322 /* Time stuff we overload the bits a little */
323 #define AD_DATE_CREATE 0
324 #define AD_DATE_MODIFY 4
325 #define AD_DATE_BACKUP 8
326 #define AD_DATE_ACCESS 12
327 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
328 AD_DATE_BACKUP | AD_DATE_ACCESS)
329 #define AD_DATE_UNIX (1 << 10)
330 #define AD_DATE_START 0x80000000
331 #define AD_DATE_DELTA 946684800
332 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
333 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
335 /* Accessor macros */
336 #define ad_getentrylen(ad,eid) ((ad)->ad_eid[(eid)].ade_len)
337 #define ad_getentryoff(ad,eid) ((ad)->ad_eid[(eid)].ade_off)
338 #define ad_setentrylen(ad,eid,len) ((ad)->ad_eid[(eid)].ade_len = (len))
339 #define ad_setentryoff(ad,eid,off) ((ad)->ad_eid[(eid)].ade_off = (off))
340 #define ad_entry(ad,eid) ((ad)->ad_data + ad_getentryoff((ad),(eid)))
348 vfs_handle_struct *ad_handle;
349 files_struct *ad_fsp;
350 adouble_type_t ad_type;
353 struct ad_entry ad_eid[ADEID_MAX];
357 struct ad_entry_order {
358 uint32_t id, offset, len;
361 /* Netatalk AppleDouble metadata xattr */
363 struct ad_entry_order entry_order_meta_xattr[ADEID_NUM_XATTR + 1] = {
364 {ADEID_FINDERI, ADEDOFF_FINDERI_XATTR, ADEDLEN_FINDERI},
365 {ADEID_COMMENT, ADEDOFF_COMMENT_XATTR, 0},
366 {ADEID_FILEDATESI, ADEDOFF_FILEDATESI_XATTR, ADEDLEN_FILEDATESI},
367 {ADEID_AFPFILEI, ADEDOFF_AFPFILEI_XATTR, ADEDLEN_AFPFILEI},
368 {ADEID_PRIVDEV, ADEDOFF_PRIVDEV_XATTR, 0},
369 {ADEID_PRIVINO, ADEDOFF_PRIVINO_XATTR, 0},
370 {ADEID_PRIVSYN, ADEDOFF_PRIVSYN_XATTR, 0},
371 {ADEID_PRIVID, ADEDOFF_PRIVID_XATTR, 0},
375 /* AppleDouble ressource fork file (the ones prefixed by "._") */
377 struct ad_entry_order entry_order_dot_und[ADEID_NUM_DOT_UND + 1] = {
378 {ADEID_FINDERI, ADEDOFF_FINDERI_DOT_UND, ADEDLEN_FINDERI},
379 {ADEID_RFORK, ADEDOFF_RFORK_DOT_UND, 0},
384 * Fake AppleDouble entry oder for ressource fork xattr. The xattr
385 * isn't an AppleDouble file, it simply contains the ressource data,
386 * but in order to be able to use some API calls like ad_getentryoff()
387 * we build a fake/helper struct adouble with this entry order struct.
390 struct ad_entry_order entry_order_rsrc_xattr[ADEID_NUM_RSRC_XATTR + 1] = {
395 /* Conversion from enumerated id to on-disk AppleDouble id */
396 #define AD_EID_DISK(a) (set_eid[a])
397 static const uint32_t set_eid[] = {
398 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
399 AD_DEV, AD_INO, AD_SYN, AD_ID
403 * Forward declarations
405 static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
406 adouble_type_t type, files_struct *fsp);
407 static int ad_write(struct adouble *ad, const char *path);
408 static int adouble_path(TALLOC_CTX *ctx, const char *path_in, char **path_out);
413 static int ad_getdate(const struct adouble *ad,
414 unsigned int dateoff,
417 bool xlate = (dateoff & AD_DATE_UNIX);
419 dateoff &= AD_DATE_MASK;
420 if (!ad_getentryoff(ad, ADEID_FILEDATESI)) {
424 if (dateoff > AD_DATE_ACCESS) {
428 ad_entry(ad, ADEID_FILEDATESI) + dateoff,
432 *date = AD_DATE_TO_UNIX(*date);
440 static int ad_setdate(struct adouble *ad, unsigned int dateoff, uint32_t date)
442 bool xlate = (dateoff & AD_DATE_UNIX);
444 if (!ad_getentryoff(ad, ADEID_FILEDATESI)) {
448 dateoff &= AD_DATE_MASK;
450 date = AD_DATE_FROM_UNIX(date);
453 if (dateoff > AD_DATE_ACCESS) {
457 memcpy(ad_entry(ad, ADEID_FILEDATESI) + dateoff, &date, sizeof(date));
464 * Map on-disk AppleDouble id to enumerated id
466 static uint32_t get_eid(uint32_t eid)
474 return ADEID_PRIVDEV;
476 return ADEID_PRIVINO;
478 return ADEID_PRIVSYN;
489 * Pack AppleDouble structure into data buffer
491 static bool ad_pack(struct adouble *ad)
498 bufsize = talloc_get_size(ad->ad_data);
500 if (offset + ADEDLEN_MAGIC < offset ||
501 offset + ADEDLEN_MAGIC >= bufsize) {
504 RSIVAL(ad->ad_data, offset, ad->ad_magic);
505 offset += ADEDLEN_MAGIC;
507 if (offset + ADEDLEN_VERSION < offset ||
508 offset + ADEDLEN_VERSION >= bufsize) {
511 RSIVAL(ad->ad_data, offset, ad->ad_version);
512 offset += ADEDLEN_VERSION;
514 if (offset + ADEDLEN_FILLER < offset ||
515 offset + ADEDLEN_FILLER >= bufsize) {
518 if (ad->ad_type == ADOUBLE_RSRC) {
519 memcpy(ad->ad_data + offset, AD_FILLER_TAG, ADEDLEN_FILLER);
521 offset += ADEDLEN_FILLER;
523 if (offset + ADEDLEN_NENTRIES < offset ||
524 offset + ADEDLEN_NENTRIES >= bufsize) {
527 offset += ADEDLEN_NENTRIES;
529 for (eid = 0, nent = 0; eid < ADEID_MAX; eid++) {
530 if (ad->ad_eid[eid].ade_off == 0) {
532 * ade_off is also used as indicator whether a
533 * specific entry is used or not
538 if (offset + AD_ENTRY_LEN_EID < offset ||
539 offset + AD_ENTRY_LEN_EID >= bufsize) {
542 RSIVAL(ad->ad_data, offset, AD_EID_DISK(eid));
543 offset += AD_ENTRY_LEN_EID;
545 if (offset + AD_ENTRY_LEN_OFF < offset ||
546 offset + AD_ENTRY_LEN_OFF >= bufsize) {
549 RSIVAL(ad->ad_data, offset, ad->ad_eid[eid].ade_off);
550 offset += AD_ENTRY_LEN_OFF;
552 if (offset + AD_ENTRY_LEN_LEN < offset ||
553 offset + AD_ENTRY_LEN_LEN >= bufsize) {
556 RSIVAL(ad->ad_data, offset, ad->ad_eid[eid].ade_len);
557 offset += AD_ENTRY_LEN_LEN;
562 if (ADEDOFF_NENTRIES + 2 >= bufsize) {
565 RSSVAL(ad->ad_data, ADEDOFF_NENTRIES, nent);
571 * Unpack an AppleDouble blob into a struct adoble
573 static bool ad_unpack(struct adouble *ad, const int nentries, size_t filesize)
575 size_t bufsize = talloc_get_size(ad->ad_data);
577 uint32_t eid, len, off;
580 * The size of the buffer ad->ad_data is checked when read, so
581 * we wouldn't have to check our own offsets, a few extra
582 * checks won't hurt though. We have to check the offsets we
583 * read from the buffer anyway.
586 if (bufsize < (AD_HEADER_LEN + (AD_ENTRY_LEN * nentries))) {
587 DEBUG(1, ("bad size\n"));
591 ad->ad_magic = RIVAL(ad->ad_data, 0);
592 ad->ad_version = RIVAL(ad->ad_data, ADEDOFF_VERSION);
593 if ((ad->ad_magic != AD_MAGIC) || (ad->ad_version != AD_VERSION)) {
594 DEBUG(1, ("wrong magic or version\n"));
598 adentries = RSVAL(ad->ad_data, ADEDOFF_NENTRIES);
599 if (adentries != nentries) {
600 DEBUG(1, ("invalid number of entries: %d\n", adentries));
604 /* now, read in the entry bits */
605 for (i = 0; i < adentries; i++) {
606 eid = RIVAL(ad->ad_data, AD_HEADER_LEN + (i * AD_ENTRY_LEN));
608 off = RIVAL(ad->ad_data, AD_HEADER_LEN + (i * AD_ENTRY_LEN) + 4);
609 len = RIVAL(ad->ad_data, AD_HEADER_LEN + (i * AD_ENTRY_LEN) + 8);
611 if (!eid || eid > ADEID_MAX) {
612 DEBUG(1, ("bogus eid %d\n", eid));
617 * All entries other than the resource fork are
618 * expected to be read into the ad_data buffer, so
619 * ensure the specified offset is within that bound
621 if ((off > bufsize) && (eid != ADEID_RFORK)) {
622 DEBUG(1, ("bogus eid %d: off: %" PRIu32 ", len: %" PRIu32 "\n",
628 * All entries besides FinderInfo and resource fork
629 * must fit into the buffer. FinderInfo is special as
630 * it may be larger then the default 32 bytes (if it
631 * contains marshalled xattrs), but we will fixup that
632 * in ad_convert(). And the resource fork is never
633 * accessed directly by the ad_data buf (also see
634 * comment above) anyway.
636 if ((eid != ADEID_RFORK) &&
637 (eid != ADEID_FINDERI) &&
638 ((off + len) > bufsize)) {
639 DEBUG(1, ("bogus eid %d: off: %" PRIu32 ", len: %" PRIu32 "\n",
645 * That would be obviously broken
647 if (off > filesize) {
648 DEBUG(1, ("bogus eid %d: off: %" PRIu32 ", len: %" PRIu32 "\n",
654 * Check for any entry that has its end beyond the
657 if (off + len < off) {
658 DEBUG(1, ("offset wrap in eid %d: off: %" PRIu32
659 ", len: %" PRIu32 "\n",
664 if (off + len > filesize) {
666 * If this is the resource fork entry, we fix
667 * up the length, for any other entry we bail
670 if (eid != ADEID_RFORK) {
671 DEBUG(1, ("bogus eid %d: off: %" PRIu32
672 ", len: %" PRIu32 "\n",
678 * Fixup the resource fork entry by limiting
679 * the size to entryoffset - filesize.
681 len = filesize - off;
682 DEBUG(1, ("Limiting ADEID_RFORK: off: %" PRIu32
683 ", len: %" PRIu32 "\n", off, len));
686 ad->ad_eid[eid].ade_off = off;
687 ad->ad_eid[eid].ade_len = len;
694 * Convert from Apple's ._ file to Netatalk
696 * Apple's AppleDouble may contain a FinderInfo entry longer then 32
697 * bytes containing packed xattrs. Netatalk can't deal with that, so
698 * we simply discard the packed xattrs.
700 * @return -1 in case an error occured, 0 if no conversion was done, 1
703 static int ad_convert(struct adouble *ad, int fd)
706 char *map = MAP_FAILED;
709 origlen = ad_getentryoff(ad, ADEID_RFORK) +
710 ad_getentrylen(ad, ADEID_RFORK);
712 /* FIXME: direct use of mmap(), vfs_aio_fork does it too */
713 map = mmap(NULL, origlen, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
714 if (map == MAP_FAILED) {
715 DEBUG(2, ("mmap AppleDouble: %s\n", strerror(errno)));
720 if (ad_getentrylen(ad, ADEID_RFORK) > 0) {
721 memmove(map + ad_getentryoff(ad, ADEID_FINDERI) + ADEDLEN_FINDERI,
722 map + ad_getentryoff(ad, ADEID_RFORK),
723 ad_getentrylen(ad, ADEID_RFORK));
726 ad_setentrylen(ad, ADEID_FINDERI, ADEDLEN_FINDERI);
727 ad_setentryoff(ad, ADEID_RFORK,
728 ad_getentryoff(ad, ADEID_FINDERI) + ADEDLEN_FINDERI);
731 * FIXME: direct ftruncate(), but we don't have a fsp for the
734 rc = ftruncate(fd, ad_getentryoff(ad, ADEID_RFORK)
735 + ad_getentrylen(ad, ADEID_RFORK));
738 if (map != MAP_FAILED) {
739 munmap(map, origlen);
745 * Read and parse Netatalk AppleDouble metadata xattr
747 static ssize_t ad_header_read_meta(struct adouble *ad, const char *path)
753 DEBUG(10, ("reading meta xattr for %s\n", path));
755 ealen = SMB_VFS_GETXATTR(ad->ad_handle->conn, path,
756 AFPINFO_EA_NETATALK, ad->ad_data,
762 if (errno == ENOATTR) {
768 DEBUG(2, ("error reading meta xattr: %s\n",
774 if (ealen != AD_DATASZ_XATTR) {
775 DEBUG(2, ("bad size %zd\n", ealen));
781 /* Now parse entries */
782 ok = ad_unpack(ad, ADEID_NUM_XATTR, AD_DATASZ_XATTR);
784 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
790 if (!ad_getentryoff(ad, ADEID_FINDERI)
791 || !ad_getentryoff(ad, ADEID_COMMENT)
792 || !ad_getentryoff(ad, ADEID_FILEDATESI)
793 || !ad_getentryoff(ad, ADEID_AFPFILEI)
794 || !ad_getentryoff(ad, ADEID_PRIVDEV)
795 || !ad_getentryoff(ad, ADEID_PRIVINO)
796 || !ad_getentryoff(ad, ADEID_PRIVSYN)
797 || !ad_getentryoff(ad, ADEID_PRIVID)) {
798 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
805 DEBUG(10, ("reading meta xattr for %s, rc: %d\n", path, rc));
809 if (errno == EINVAL) {
811 removexattr(path, AFPINFO_EA_NETATALK);
820 * Read and parse resource fork, either ._ AppleDouble file or xattr
822 static ssize_t ad_header_read_rsrc(struct adouble *ad, const char *path)
824 struct fruit_config_data *config = NULL;
831 struct adouble *meta_ad = NULL;
832 SMB_STRUCT_STAT sbuf;
836 SMB_VFS_HANDLE_GET_DATA(ad->ad_handle, config,
837 struct fruit_config_data, return -1);
839 /* Try rw first so we can use the fd in ad_convert() */
842 if (ad->ad_fsp && ad->ad_fsp->fh && (ad->ad_fsp->fh->fd != -1)) {
843 fd = ad->ad_fsp->fh->fd;
845 if (config->rsrc == FRUIT_RSRC_XATTR) {
846 adpath = talloc_strdup(talloc_tos(), path);
848 rc = adouble_path(talloc_tos(), path, &adpath);
855 if (config->rsrc == FRUIT_RSRC_XATTR) {
856 #ifndef HAVE_ATTROPEN
861 /* FIXME: direct Solaris xattr syscall */
862 fd = attropen(adpath, AFPRESOURCE_EA_NETATALK,
866 /* FIXME: direct open(), don't have an fsp */
867 fd = open(adpath, mode);
874 if (mode == O_RDWR) {
878 /* fall through ... */
880 DEBUG(2, ("open AppleDouble: %s, %s\n",
881 adpath, strerror(errno)));
889 if (config->rsrc == FRUIT_RSRC_XATTR) {
890 /* FIXME: direct sys_fstat(), don't have an fsp */
893 lp_fake_directory_create_times(
894 SNUM(ad->ad_handle->conn)));
898 len = sbuf.st_ex_size;
899 ad_setentrylen(ad, ADEID_RFORK, len);
901 /* FIXME: direct sys_pread(), don't have an fsp */
902 len = sys_pread(fd, ad->ad_data, AD_DATASZ_DOT_UND, 0);
903 if (len != AD_DATASZ_DOT_UND) {
904 DEBUG(2, ("%s: bad size: %zd\n",
905 strerror(errno), len));
910 /* FIXME: direct sys_fstat(), we don't have an fsp */
911 rc = sys_fstat(fd, &sbuf,
912 lp_fake_directory_create_times(
913 SNUM(ad->ad_handle->conn)));
918 /* Now parse entries */
919 ok = ad_unpack(ad, ADEID_NUM_DOT_UND, sbuf.st_ex_size);
921 DEBUG(1, ("invalid AppleDouble ressource %s\n", path));
927 if ((ad_getentryoff(ad, ADEID_FINDERI)
928 != ADEDOFF_FINDERI_DOT_UND)
929 || (ad_getentrylen(ad, ADEID_FINDERI)
931 || (ad_getentryoff(ad, ADEID_RFORK)
932 < ADEDOFF_RFORK_DOT_UND)) {
933 DEBUG(2, ("invalid AppleDouble ressource %s\n", path));
940 && (ad_getentrylen(ad, ADEID_FINDERI) > ADEDLEN_FINDERI)) {
941 rc = ad_convert(ad, fd);
947 * Can't use ad_write() because we might not have a fsp
953 /* FIXME: direct sys_pwrite(), don't have an fsp */
954 len = sys_pwrite(fd, ad->ad_data,
955 AD_DATASZ_DOT_UND, 0);
956 if (len != AD_DATASZ_DOT_UND) {
957 DEBUG(2, ("%s: bad size: %zd\n", adpath, len));
962 meta_ad = ad_init(talloc_tos(), ad->ad_handle,
964 if (meta_ad == NULL) {
969 memcpy(ad_entry(meta_ad, ADEID_FINDERI),
970 ad_entry(ad, ADEID_FINDERI),
973 rc = ad_write(meta_ad, path);
981 DEBUG(10, ("opened AppleDouble: %s\n", path));
988 if (opened && fd != -1) {
992 TALLOC_FREE(meta_ad);
1000 * Read and unpack an AppleDouble metadata xattr or resource
1002 static ssize_t ad_read(struct adouble *ad, const char *path)
1004 switch (ad->ad_type) {
1006 return ad_header_read_meta(ad, path);
1008 return ad_header_read_rsrc(ad, path);
1015 * Allocate a struct adouble without initialiing it
1017 * The struct is either hang of the fsp extension context or if fsp is
1020 * @param[in] ctx talloc context
1021 * @param[in] handle vfs handle
1022 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1024 * @param[in] fsp if not NULL (for stream IO), the adouble handle is
1025 * added as an fsp extension
1027 * @return adouble handle
1029 static struct adouble *ad_alloc(TALLOC_CTX *ctx, vfs_handle_struct *handle,
1030 adouble_type_t type, files_struct *fsp)
1035 struct fruit_config_data *config;
1037 SMB_VFS_HANDLE_GET_DATA(handle, config,
1038 struct fruit_config_data, return NULL);
1042 adsize = AD_DATASZ_XATTR;
1045 if (config->rsrc == FRUIT_RSRC_ADFILE) {
1046 adsize = AD_DATASZ_DOT_UND;
1054 ad = talloc_zero(ctx, struct adouble);
1060 ad->ad_data = talloc_zero_array(ad, char, adsize);
1063 ad = (struct adouble *)VFS_ADD_FSP_EXTENSION(handle, fsp,
1071 ad->ad_data = talloc_zero_array(
1072 VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
1078 if (adsize && ad->ad_data == NULL) {
1082 ad->ad_handle = handle;
1084 ad->ad_magic = AD_MAGIC;
1085 ad->ad_version = AD_VERSION;
1095 * Allocate and initialize a new struct adouble
1097 * @param[in] ctx talloc context
1098 * @param[in] handle vfs handle
1099 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1100 * @param[in] fsp file handle, may be NULL for a type of e_ad_meta
1102 * @return adouble handle, initialized
1104 static struct adouble *ad_init(TALLOC_CTX *ctx, vfs_handle_struct *handle,
1105 adouble_type_t type, files_struct *fsp)
1108 const struct ad_entry_order *eid;
1109 struct adouble *ad = NULL;
1110 struct fruit_config_data *config;
1111 time_t t = time(NULL);
1113 SMB_VFS_HANDLE_GET_DATA(handle, config,
1114 struct fruit_config_data, return NULL);
1118 eid = entry_order_meta_xattr;
1121 if (config->rsrc == FRUIT_RSRC_ADFILE) {
1122 eid = entry_order_dot_und;
1124 eid = entry_order_rsrc_xattr;
1131 ad = ad_alloc(ctx, handle, type, fsp);
1137 ad->ad_eid[eid->id].ade_off = eid->offset;
1138 ad->ad_eid[eid->id].ade_len = eid->len;
1142 /* put something sane in the date fields */
1143 ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX, t);
1144 ad_setdate(ad, AD_DATE_MODIFY | AD_DATE_UNIX, t);
1145 ad_setdate(ad, AD_DATE_ACCESS | AD_DATE_UNIX, t);
1146 ad_setdate(ad, AD_DATE_BACKUP, htonl(AD_DATE_START));
1155 * Return AppleDouble data for a file
1157 * @param[in] ctx talloc context
1158 * @param[in] handle vfs handle
1159 * @param[in] path pathname to file or directory
1160 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1162 * @return talloced struct adouble or NULL on error
1164 static struct adouble *ad_get(TALLOC_CTX *ctx, vfs_handle_struct *handle,
1165 const char *path, adouble_type_t type)
1169 struct adouble *ad = NULL;
1171 DEBUG(10, ("ad_get(%s) called for %s\n",
1172 type == ADOUBLE_META ? "meta" : "rsrc", path));
1174 ad = ad_alloc(ctx, handle, type, NULL);
1180 len = ad_read(ad, path);
1182 DEBUG(10, ("error reading AppleDouble for %s\n", path));
1188 DEBUG(10, ("ad_get(%s) for %s returning %d\n",
1189 type == ADOUBLE_META ? "meta" : "rsrc", path, rc));
1198 * Set AppleDouble metadata on a file or directory
1200 * @param[in] ad adouble handle
1202 * @param[in] path pathname to file or directory, may be NULL for a
1205 * @return status code, 0 means success
1207 static int ad_write(struct adouble *ad, const char *path)
1217 switch (ad->ad_type) {
1219 rc = SMB_VFS_SETXATTR(ad->ad_handle->conn, path,
1220 AFPINFO_EA_NETATALK, ad->ad_data,
1221 AD_DATASZ_XATTR, 0);
1224 if ((ad->ad_fsp == NULL)
1225 || (ad->ad_fsp->fh == NULL)
1226 || (ad->ad_fsp->fh->fd == -1)) {
1230 /* FIXME: direct sys_pwrite(), don't have an fsp */
1231 len = sys_pwrite(ad->ad_fsp->fh->fd, ad->ad_data,
1232 talloc_get_size(ad->ad_data), 0);
1233 if (len != talloc_get_size(ad->ad_data)) {
1234 DEBUG(1, ("short write on %s: %zd",
1235 fsp_str_dbg(ad->ad_fsp), len));
1247 /*****************************************************************************
1249 *****************************************************************************/
1251 static bool is_afpinfo_stream(const struct smb_filename *smb_fname)
1253 if (strncasecmp_m(smb_fname->stream_name,
1254 AFPINFO_STREAM_NAME,
1255 strlen(AFPINFO_STREAM_NAME)) == 0) {
1261 static bool is_afpresource_stream(const struct smb_filename *smb_fname)
1263 if (strncasecmp_m(smb_fname->stream_name,
1264 AFPRESOURCE_STREAM_NAME,
1265 strlen(AFPRESOURCE_STREAM_NAME)) == 0) {
1272 * Test whether stream is an Apple stream, not used atm
1275 static bool is_apple_stream(const struct smb_filename *smb_fname)
1277 if (is_afpinfo_stream(smb_fname)) {
1280 if (is_afpresource_stream(smb_fname)) {
1288 * Initialize config struct from our smb.conf config parameters
1290 static int init_fruit_config(vfs_handle_struct *handle)
1292 struct fruit_config_data *config;
1295 config = talloc_zero(handle->conn, struct fruit_config_data);
1297 DEBUG(1, ("talloc_zero() failed\n"));
1302 enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
1303 "ressource", fruit_rsrc, FRUIT_RSRC_ADFILE);
1304 if (enumval == -1) {
1305 DEBUG(1, ("value for %s: ressource type unknown\n",
1306 FRUIT_PARAM_TYPE_NAME));
1309 config->rsrc = (enum fruit_rsrc)enumval;
1311 enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
1312 "metadata", fruit_meta, FRUIT_META_NETATALK);
1313 if (enumval == -1) {
1314 DEBUG(1, ("value for %s: metadata type unknown\n",
1315 FRUIT_PARAM_TYPE_NAME));
1318 config->meta = (enum fruit_meta)enumval;
1320 enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
1321 "locking", fruit_locking, FRUIT_LOCKING_NONE);
1322 if (enumval == -1) {
1323 DEBUG(1, ("value for %s: locking type unknown\n",
1324 FRUIT_PARAM_TYPE_NAME));
1327 config->locking = (enum fruit_locking)enumval;
1329 enumval = lp_parm_enum(SNUM(handle->conn), FRUIT_PARAM_TYPE_NAME,
1330 "encoding", fruit_encoding, FRUIT_ENC_PRIVATE);
1331 if (enumval == -1) {
1332 DEBUG(1, ("value for %s: encoding type unknown\n",
1333 FRUIT_PARAM_TYPE_NAME));
1336 config->encoding = (enum fruit_encoding)enumval;
1338 if (lp_parm_bool(SNUM(handle->conn),
1339 FRUIT_PARAM_TYPE_NAME, "veto_appledouble", true)) {
1340 config->veto_appledouble = true;
1343 if (lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME, "aapl", true)) {
1344 config->use_aapl = true;
1347 if (lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME, "nfs_aces", true)) {
1348 config->unix_info_enabled = true;
1351 if (lp_parm_bool(SNUM(handle->conn),
1352 "readdir_attr", "aapl_rsize", true)) {
1353 config->readdir_attr_rsize = true;
1356 if (lp_parm_bool(SNUM(handle->conn),
1357 "readdir_attr", "aapl_finder_info", true)) {
1358 config->readdir_attr_finder_info = true;
1361 if (lp_parm_bool(SNUM(handle->conn),
1362 "readdir_attr", "aapl_max_access", true)) {
1363 config->readdir_attr_max_access = true;
1366 SMB_VFS_HANDLE_SET_DATA(handle, config,
1367 NULL, struct fruit_config_data,
1374 * Prepend "._" to a basename
1376 static int adouble_path(TALLOC_CTX *ctx, const char *path_in, char **path_out)
1381 if (!parent_dirname(ctx, path_in, &parent, &base)) {
1385 *path_out = talloc_asprintf(ctx, "%s/._%s", parent, base);
1386 if (*path_out == NULL) {
1394 * Allocate and initialize an AfpInfo struct
1396 static AfpInfo *afpinfo_new(TALLOC_CTX *ctx)
1398 AfpInfo *ai = talloc_zero(ctx, AfpInfo);
1402 ai->afpi_Signature = AFP_Signature;
1403 ai->afpi_Version = AFP_Version;
1404 ai->afpi_BackupTime = AD_DATE_START;
1409 * Pack an AfpInfo struct into a buffer
1411 * Buffer size must be at least AFP_INFO_SIZE
1412 * Returns size of packed buffer
1414 static ssize_t afpinfo_pack(const AfpInfo *ai, char *buf)
1416 memset(buf, 0, AFP_INFO_SIZE);
1418 RSIVAL(buf, 0, ai->afpi_Signature);
1419 RSIVAL(buf, 4, ai->afpi_Version);
1420 RSIVAL(buf, 12, ai->afpi_BackupTime);
1421 memcpy(buf + 16, ai->afpi_FinderInfo, sizeof(ai->afpi_FinderInfo));
1423 return AFP_INFO_SIZE;
1427 * Unpack a buffer into a AfpInfo structure
1429 * Buffer size must be at least AFP_INFO_SIZE
1430 * Returns allocated AfpInfo struct
1432 static AfpInfo *afpinfo_unpack(TALLOC_CTX *ctx, const void *data)
1434 AfpInfo *ai = talloc_zero(ctx, AfpInfo);
1439 ai->afpi_Signature = RIVAL(data, 0);
1440 ai->afpi_Version = RIVAL(data, 4);
1441 ai->afpi_BackupTime = RIVAL(data, 12);
1442 memcpy(ai->afpi_FinderInfo, (const char *)data + 16,
1443 sizeof(ai->afpi_FinderInfo));
1445 if (ai->afpi_Signature != AFP_Signature
1446 || ai->afpi_Version != AFP_Version) {
1447 DEBUG(1, ("Bad AfpInfo signature or version\n"));
1455 * Fake an inode number from the md5 hash of the (xattr) name
1457 static SMB_INO_T fruit_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
1460 unsigned char hash[16];
1464 upper_sname = talloc_strdup_upper(talloc_tos(), sname);
1465 SMB_ASSERT(upper_sname != NULL);
1468 MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_dev),
1469 sizeof(sbuf->st_ex_dev));
1470 MD5Update(&ctx, (const unsigned char *)&(sbuf->st_ex_ino),
1471 sizeof(sbuf->st_ex_ino));
1472 MD5Update(&ctx, (unsigned char *)upper_sname,
1473 talloc_get_size(upper_sname)-1);
1474 MD5Final(hash, &ctx);
1476 TALLOC_FREE(upper_sname);
1478 /* Hopefully all the variation is in the lower 4 (or 8) bytes! */
1479 memcpy(&result, hash, sizeof(result));
1481 DEBUG(10, ("fruit_inode \"%s\": ino=0x%llu\n",
1482 sname, (unsigned long long)result));
1488 * Ensure ad_fsp is still valid
1490 static bool fruit_fsp_recheck(struct adouble *ad, files_struct *fsp)
1492 if (ad->ad_fsp == fsp) {
1500 static bool add_fruit_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
1501 struct stream_struct **streams,
1502 const char *name, off_t size,
1505 struct stream_struct *tmp;
1507 tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
1513 tmp[*num_streams].name = talloc_asprintf(tmp, "%s:$DATA", name);
1514 if (tmp[*num_streams].name == NULL) {
1518 tmp[*num_streams].size = size;
1519 tmp[*num_streams].alloc_size = alloc_size;
1526 static bool empty_finderinfo(const struct adouble *ad)
1529 char emptybuf[ADEDLEN_FINDERI] = {0};
1530 if (memcmp(emptybuf,
1531 ad_entry(ad, ADEID_FINDERI),
1532 ADEDLEN_FINDERI) == 0) {
1539 * Update btime with btime from Netatalk
1541 static void update_btime(vfs_handle_struct *handle,
1542 struct smb_filename *smb_fname)
1545 struct timespec creation_time = {0};
1548 ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_META);
1552 if (ad_getdate(ad, AD_DATE_UNIX | AD_DATE_CREATE, &t) != 0) {
1558 creation_time.tv_sec = convert_uint32_t_to_time_t(t);
1559 update_stat_ex_create_time(&smb_fname->st, creation_time);
1565 * Map an access mask to a Netatalk single byte byte range lock
1567 static off_t access_to_netatalk_brl(enum apple_fork fork_type,
1568 uint32_t access_mask)
1572 switch (access_mask) {
1573 case FILE_READ_DATA:
1574 offset = AD_FILELOCK_OPEN_RD;
1577 case FILE_WRITE_DATA:
1578 case FILE_APPEND_DATA:
1579 offset = AD_FILELOCK_OPEN_WR;
1583 offset = AD_FILELOCK_OPEN_NONE;
1587 if (fork_type == APPLE_FORK_RSRC) {
1588 if (offset == AD_FILELOCK_OPEN_NONE) {
1589 offset = AD_FILELOCK_RSRC_OPEN_NONE;
1599 * Map a deny mode to a Netatalk brl
1601 static off_t denymode_to_netatalk_brl(enum apple_fork fork_type,
1606 switch (deny_mode) {
1608 offset = AD_FILELOCK_DENY_RD;
1612 offset = AD_FILELOCK_DENY_WR;
1616 smb_panic("denymode_to_netatalk_brl: bad deny mode\n");
1619 if (fork_type == APPLE_FORK_RSRC) {
1627 * Call fcntl() with an exclusive F_GETLK request in order to
1628 * determine if there's an exisiting shared lock
1630 * @return true if the requested lock was found or any error occured
1631 * false if the lock was not found
1633 static bool test_netatalk_lock(files_struct *fsp, off_t in_offset)
1636 off_t offset = in_offset;
1641 result = SMB_VFS_GETLOCK(fsp, &offset, &len, &type, &pid);
1642 if (result == false) {
1646 if (type != F_UNLCK) {
1653 static NTSTATUS fruit_check_access(vfs_handle_struct *handle,
1655 uint32_t access_mask,
1658 NTSTATUS status = NT_STATUS_OK;
1659 struct byte_range_lock *br_lck = NULL;
1660 bool open_for_reading, open_for_writing, deny_read, deny_write;
1663 /* FIXME: hardcoded data fork, add resource fork */
1664 enum apple_fork fork_type = APPLE_FORK_DATA;
1666 DEBUG(10, ("fruit_check_access: %s, am: %s/%s, dm: %s/%s\n",
1668 access_mask & FILE_READ_DATA ? "READ" :"-",
1669 access_mask & FILE_WRITE_DATA ? "WRITE" : "-",
1670 deny_mode & DENY_READ ? "DENY_READ" : "-",
1671 deny_mode & DENY_WRITE ? "DENY_WRITE" : "-"));
1674 * Check read access and deny read mode
1676 if ((access_mask & FILE_READ_DATA) || (deny_mode & DENY_READ)) {
1678 open_for_reading = test_netatalk_lock(
1679 fsp, access_to_netatalk_brl(fork_type, FILE_READ_DATA));
1681 deny_read = test_netatalk_lock(
1682 fsp, denymode_to_netatalk_brl(fork_type, DENY_READ));
1684 DEBUG(10, ("read: %s, deny_write: %s\n",
1685 open_for_reading == true ? "yes" : "no",
1686 deny_read == true ? "yes" : "no"));
1688 if (((access_mask & FILE_READ_DATA) && deny_read)
1689 || ((deny_mode & DENY_READ) && open_for_reading)) {
1690 return NT_STATUS_SHARING_VIOLATION;
1694 if (access_mask & FILE_READ_DATA) {
1695 off = access_to_netatalk_brl(fork_type, FILE_READ_DATA);
1697 handle->conn->sconn->msg_ctx, fsp,
1698 fsp->op->global->open_persistent_id, 1, off,
1699 READ_LOCK, POSIX_LOCK, false,
1702 if (!NT_STATUS_IS_OK(status)) {
1705 TALLOC_FREE(br_lck);
1708 if (deny_mode & DENY_READ) {
1709 off = denymode_to_netatalk_brl(fork_type, DENY_READ);
1711 handle->conn->sconn->msg_ctx, fsp,
1712 fsp->op->global->open_persistent_id, 1, off,
1713 READ_LOCK, POSIX_LOCK, false,
1716 if (!NT_STATUS_IS_OK(status)) {
1719 TALLOC_FREE(br_lck);
1724 * Check write access and deny write mode
1726 if ((access_mask & FILE_WRITE_DATA) || (deny_mode & DENY_WRITE)) {
1728 open_for_writing = test_netatalk_lock(
1729 fsp, access_to_netatalk_brl(fork_type, FILE_WRITE_DATA));
1731 deny_write = test_netatalk_lock(
1732 fsp, denymode_to_netatalk_brl(fork_type, DENY_WRITE));
1734 DEBUG(10, ("write: %s, deny_write: %s\n",
1735 open_for_writing == true ? "yes" : "no",
1736 deny_write == true ? "yes" : "no"));
1738 if (((access_mask & FILE_WRITE_DATA) && deny_write)
1739 || ((deny_mode & DENY_WRITE) && open_for_writing)) {
1740 return NT_STATUS_SHARING_VIOLATION;
1744 if (access_mask & FILE_WRITE_DATA) {
1745 off = access_to_netatalk_brl(fork_type, FILE_WRITE_DATA);
1747 handle->conn->sconn->msg_ctx, fsp,
1748 fsp->op->global->open_persistent_id, 1, off,
1749 READ_LOCK, POSIX_LOCK, false,
1752 if (!NT_STATUS_IS_OK(status)) {
1755 TALLOC_FREE(br_lck);
1758 if (deny_mode & DENY_WRITE) {
1759 off = denymode_to_netatalk_brl(fork_type, DENY_WRITE);
1761 handle->conn->sconn->msg_ctx, fsp,
1762 fsp->op->global->open_persistent_id, 1, off,
1763 READ_LOCK, POSIX_LOCK, false,
1766 if (!NT_STATUS_IS_OK(status)) {
1769 TALLOC_FREE(br_lck);
1773 TALLOC_FREE(br_lck);
1778 static NTSTATUS check_aapl(vfs_handle_struct *handle,
1779 struct smb_request *req,
1780 const struct smb2_create_blobs *in_context_blobs,
1781 struct smb2_create_blobs *out_context_blobs)
1783 struct fruit_config_data *config;
1785 struct smb2_create_blob *aapl = NULL;
1789 DATA_BLOB blob = data_blob_talloc(req, NULL, 0);
1790 uint64_t req_bitmap, client_caps;
1791 uint64_t server_caps = SMB2_CRTCTX_AAPL_UNIX_BASED;
1795 SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
1796 return NT_STATUS_UNSUCCESSFUL);
1798 if (!config->use_aapl
1799 || in_context_blobs == NULL
1800 || out_context_blobs == NULL) {
1801 return NT_STATUS_OK;
1804 aapl = smb2_create_blob_find(in_context_blobs,
1805 SMB2_CREATE_TAG_AAPL);
1807 return NT_STATUS_OK;
1810 if (aapl->data.length != 24) {
1811 DEBUG(1, ("unexpected AAPL ctxt legnth: %ju\n",
1812 (uintmax_t)aapl->data.length));
1813 return NT_STATUS_INVALID_PARAMETER;
1816 cmd = IVAL(aapl->data.data, 0);
1817 if (cmd != SMB2_CRTCTX_AAPL_SERVER_QUERY) {
1818 DEBUG(1, ("unsupported AAPL cmd: %d\n", cmd));
1819 return NT_STATUS_INVALID_PARAMETER;
1822 req_bitmap = BVAL(aapl->data.data, 8);
1823 client_caps = BVAL(aapl->data.data, 16);
1825 SIVAL(p, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY);
1827 SBVAL(p, 8, req_bitmap);
1828 ok = data_blob_append(req, &blob, p, 16);
1830 return NT_STATUS_UNSUCCESSFUL;
1833 if (req_bitmap & SMB2_CRTCTX_AAPL_SERVER_CAPS) {
1834 if ((client_caps & SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR) &&
1835 (handle->conn->tcon->compat->fs_capabilities & FILE_NAMED_STREAMS)) {
1836 server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR;
1837 config->readdir_attr_enabled = true;
1841 * The client doesn't set the flag, so we can't check
1842 * for it and just set it unconditionally
1844 if (config->unix_info_enabled) {
1845 server_caps |= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE;
1848 SBVAL(p, 0, server_caps);
1849 ok = data_blob_append(req, &blob, p, 8);
1851 return NT_STATUS_UNSUCCESSFUL;
1855 if (req_bitmap & SMB2_CRTCTX_AAPL_VOLUME_CAPS) {
1857 lp_case_sensitive(SNUM(handle->conn->tcon->compat)) ?
1858 SMB2_CRTCTX_AAPL_CASE_SENSITIVE : 0);
1859 ok = data_blob_append(req, &blob, p, 8);
1861 return NT_STATUS_UNSUCCESSFUL;
1865 if (req_bitmap & SMB2_CRTCTX_AAPL_MODEL_INFO) {
1866 ok = convert_string_talloc(req,
1867 CH_UNIX, CH_UTF16LE,
1868 "Samba", strlen("Samba"),
1871 return NT_STATUS_UNSUCCESSFUL;
1875 SIVAL(p + 4, 0, modellen);
1876 ok = data_blob_append(req, &blob, p, 8);
1879 return NT_STATUS_UNSUCCESSFUL;
1882 ok = data_blob_append(req, &blob, model, modellen);
1885 return NT_STATUS_UNSUCCESSFUL;
1889 status = smb2_create_blob_add(out_context_blobs,
1891 SMB2_CREATE_TAG_AAPL,
1897 static NTSTATUS readdir_attr_macmeta(struct vfs_handle_struct *handle,
1898 const struct smb_filename *smb_fname,
1899 struct readdir_attr_data *attr_data)
1901 NTSTATUS status = NT_STATUS_OK;
1902 uint32_t date_added;
1903 struct adouble *ad = NULL;
1904 struct fruit_config_data *config = NULL;
1906 SMB_VFS_HANDLE_GET_DATA(handle, config,
1907 struct fruit_config_data,
1908 return NT_STATUS_UNSUCCESSFUL);
1911 /* Ensure we return a default value in the creation_date field */
1912 RSIVAL(&attr_data->attr_data.aapl.finder_info, 12, AD_DATE_START);
1915 * Resource fork length
1918 if (config->readdir_attr_rsize) {
1919 ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
1922 attr_data->attr_data.aapl.rfork_size = ad_getentrylen(
1932 if (config->readdir_attr_finder_info) {
1933 ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
1936 if (S_ISREG(smb_fname->st.st_ex_mode)) {
1938 memcpy(&attr_data->attr_data.aapl.finder_info[0],
1939 ad_entry(ad, ADEID_FINDERI), 4);
1941 /* finder_creator */
1942 memcpy(&attr_data->attr_data.aapl.finder_info[0] + 4,
1943 ad_entry(ad, ADEID_FINDERI) + 4, 4);
1947 memcpy(&attr_data->attr_data.aapl.finder_info[0] + 8,
1948 ad_entry(ad, ADEID_FINDERI) + 8, 2);
1950 /* finder_ext_flags */
1951 memcpy(&attr_data->attr_data.aapl.finder_info[0] + 10,
1952 ad_entry(ad, ADEID_FINDERI) + 24, 2);
1955 date_added = convert_time_t_to_uint32_t(
1956 smb_fname->st.st_ex_btime.tv_sec - AD_DATE_DELTA);
1957 RSIVAL(&attr_data->attr_data.aapl.finder_info[0], 12, date_added);
1967 /* Search MS NFS style ACE with UNIX mode */
1968 static NTSTATUS check_ms_nfs(vfs_handle_struct *handle,
1970 const struct security_descriptor *psd,
1975 struct fruit_config_data *config = NULL;
1979 SMB_VFS_HANDLE_GET_DATA(handle, config,
1980 struct fruit_config_data,
1981 return NT_STATUS_UNSUCCESSFUL);
1983 if (psd->dacl == NULL || !config->unix_info_enabled) {
1984 return NT_STATUS_OK;
1987 for (i = 0; i < psd->dacl->num_aces; i++) {
1988 if (dom_sid_compare_domain(
1989 &global_sid_Unix_NFS_Mode,
1990 &psd->dacl->aces[i].trustee) == 0) {
1991 *pmode = (mode_t)psd->dacl->aces[i].trustee.sub_auths[2];
1992 *pmode &= (S_IRWXU | S_IRWXG | S_IRWXO);
1995 DEBUG(10, ("MS NFS chmod request %s, %04o\n",
1996 fsp_str_dbg(fsp), (unsigned)(*pmode)));
2001 return NT_STATUS_OK;
2004 /****************************************************************************
2006 ****************************************************************************/
2008 static int fruit_connect(vfs_handle_struct *handle,
2009 const char *service,
2013 char *list = NULL, *newlist = NULL;
2014 struct fruit_config_data *config;
2016 DEBUG(10, ("fruit_connect\n"));
2018 rc = SMB_VFS_NEXT_CONNECT(handle, service, user);
2023 rc = init_fruit_config(handle);
2028 SMB_VFS_HANDLE_GET_DATA(handle, config,
2029 struct fruit_config_data, return -1);
2031 if (config->veto_appledouble) {
2032 list = lp_veto_files(talloc_tos(), SNUM(handle->conn));
2035 if (strstr(list, "/" ADOUBLE_NAME_PREFIX "*/") == NULL) {
2036 newlist = talloc_asprintf(
2038 "%s/" ADOUBLE_NAME_PREFIX "*/",
2040 lp_do_parameter(SNUM(handle->conn),
2045 lp_do_parameter(SNUM(handle->conn),
2047 "/" ADOUBLE_NAME_PREFIX "*/");
2053 if (config->encoding == FRUIT_ENC_NATIVE) {
2057 "0x01:0xf001,0x02:0xf002,0x03:0xf003,0x04:0xf004,"
2058 "0x05:0xf005,0x06:0xf006,0x07:0xf007,0x08:0xf008,"
2059 "0x09:0xf009,0x0a:0xf00a,0x0b:0xf00b,0x0c:0xf00c,"
2060 "0x0d:0xf00d,0x0e:0xf00e,0x0f:0xf00f,0x10:0xf010,"
2061 "0x11:0xf011,0x12:0xf012,0x13:0xf013,0x14:0xf014,"
2062 "0x15:0xf015,0x16:0xf016,0x17:0xf017,0x18:0xf018,"
2063 "0x19:0xf019,0x1a:0xf01a,0x1b:0xf01b,0x1c:0xf01c,"
2064 "0x1d:0xf01d,0x1e:0xf01e,0x1f:0xf01f,"
2065 "0x22:0xf020,0x2a:0xf021,0x3a:0xf022,0x3c:0xf023,"
2066 "0x3e:0xf024,0x3f:0xf025,0x5c:0xf026,0x7c:0xf027,"
2073 static int fruit_open_meta(vfs_handle_struct *handle,
2074 struct smb_filename *smb_fname,
2075 files_struct *fsp, int flags, mode_t mode)
2078 struct fruit_config_data *config = NULL;
2079 struct smb_filename *smb_fname_base = NULL;
2082 struct adouble *ad = NULL;
2084 DEBUG(10, ("fruit_open_meta for %s\n", smb_fname_str_dbg(smb_fname)));
2086 SMB_VFS_HANDLE_GET_DATA(handle, config,
2087 struct fruit_config_data, return -1);
2089 if (config->meta == FRUIT_META_STREAM) {
2090 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2093 /* Create an smb_filename with stream_name == NULL. */
2094 smb_fname_base = synthetic_smb_fname(talloc_tos(),
2095 smb_fname->base_name, NULL, NULL);
2097 if (smb_fname_base == NULL) {
2104 * We use baseflags to turn off nasty side-effects when opening the
2108 baseflags &= ~O_TRUNC;
2109 baseflags &= ~O_EXCL;
2110 baseflags &= ~O_CREAT;
2112 hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
2116 * It is legit to open a stream on a directory, but the base
2117 * fd has to be read-only.
2119 if ((hostfd == -1) && (errno == EISDIR)) {
2120 baseflags &= ~O_ACCMODE;
2121 baseflags |= O_RDONLY;
2122 hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
2126 TALLOC_FREE(smb_fname_base);
2133 if (flags & (O_CREAT | O_TRUNC)) {
2135 * The attribute does not exist or needs to be truncated,
2136 * create an AppleDouble EA
2138 ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
2139 handle, ADOUBLE_META, fsp);
2145 rc = ad_write(ad, smb_fname->base_name);
2151 ad = ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
2152 handle, ADOUBLE_META, fsp);
2157 if (ad_read(ad, smb_fname->base_name) == -1) {
2164 DEBUG(10, ("fruit_open meta rc=%d, fd=%d\n", rc, hostfd));
2166 int saved_errno = errno;
2169 * BUGBUGBUG -- we would need to call
2170 * fd_close_posix here, but we don't have a
2173 fsp->fh->fd = hostfd;
2177 errno = saved_errno;
2182 static int fruit_open_rsrc(vfs_handle_struct *handle,
2183 struct smb_filename *smb_fname,
2184 files_struct *fsp, int flags, mode_t mode)
2187 struct fruit_config_data *config = NULL;
2188 struct adouble *ad = NULL;
2189 struct smb_filename *smb_fname_base = NULL;
2190 char *adpath = NULL;
2193 DEBUG(10, ("fruit_open_rsrc for %s\n", smb_fname_str_dbg(smb_fname)));
2195 SMB_VFS_HANDLE_GET_DATA(handle, config,
2196 struct fruit_config_data, return -1);
2198 switch (config->rsrc) {
2199 case FRUIT_RSRC_STREAM:
2200 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2201 case FRUIT_RSRC_XATTR:
2202 #ifdef HAVE_ATTROPEN
2203 hostfd = attropen(smb_fname->base_name,
2204 AFPRESOURCE_EA_NETATALK, flags, mode);
2208 ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
2209 handle, ADOUBLE_RSRC, fsp);
2223 if (!(flags & O_CREAT) && !VALID_STAT(smb_fname->st)) {
2224 rc = SMB_VFS_NEXT_STAT(handle, smb_fname);
2231 if (VALID_STAT(smb_fname->st) && S_ISDIR(smb_fname->st.st_ex_mode)) {
2232 /* sorry, but directories don't habe a resource fork */
2237 rc = adouble_path(talloc_tos(), smb_fname->base_name, &adpath);
2242 /* Create an smb_filename with stream_name == NULL. */
2243 smb_fname_base = synthetic_smb_fname(talloc_tos(),
2244 adpath, NULL, NULL);
2245 if (smb_fname_base == NULL) {
2251 /* Sanitize flags */
2252 if (flags & O_WRONLY) {
2253 /* We always need read access for the metadata header too */
2258 hostfd = SMB_VFS_OPEN(handle->conn, smb_fname_base, fsp,
2265 /* REVIEW: we need this in ad_write() */
2266 fsp->fh->fd = hostfd;
2268 if (flags & (O_CREAT | O_TRUNC)) {
2269 ad = ad_init(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
2270 handle, ADOUBLE_RSRC, fsp);
2275 rc = ad_write(ad, smb_fname->base_name);
2281 ad = ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle, fsp),
2282 handle, ADOUBLE_RSRC, fsp);
2287 if (ad_read(ad, smb_fname->base_name) == -1) {
2295 TALLOC_FREE(adpath);
2296 TALLOC_FREE(smb_fname_base);
2298 DEBUG(10, ("fruit_open resource fork: rc=%d, fd=%d\n", rc, hostfd));
2300 int saved_errno = errno;
2303 * BUGBUGBUG -- we would need to call
2304 * fd_close_posix here, but we don't have a
2307 fsp->fh->fd = hostfd;
2311 errno = saved_errno;
2316 static int fruit_open(vfs_handle_struct *handle,
2317 struct smb_filename *smb_fname,
2318 files_struct *fsp, int flags, mode_t mode)
2320 DEBUG(10, ("fruit_open called for %s\n",
2321 smb_fname_str_dbg(smb_fname)));
2323 if (!is_ntfs_stream_smb_fname(smb_fname)) {
2324 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2327 if (is_afpinfo_stream(smb_fname)) {
2328 return fruit_open_meta(handle, smb_fname, fsp, flags, mode);
2329 } else if (is_afpresource_stream(smb_fname)) {
2330 return fruit_open_rsrc(handle, smb_fname, fsp, flags, mode);
2333 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
2336 static int fruit_rename(struct vfs_handle_struct *handle,
2337 const struct smb_filename *smb_fname_src,
2338 const struct smb_filename *smb_fname_dst)
2341 char *src_adouble_path = NULL;
2342 char *dst_adouble_path = NULL;
2343 struct fruit_config_data *config = NULL;
2345 rc = SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
2347 if (!VALID_STAT(smb_fname_src->st)
2348 || !S_ISREG(smb_fname_src->st.st_ex_mode)) {
2352 SMB_VFS_HANDLE_GET_DATA(handle, config,
2353 struct fruit_config_data, return -1);
2355 if (config->rsrc == FRUIT_RSRC_XATTR) {
2359 rc = adouble_path(talloc_tos(), smb_fname_src->base_name,
2364 rc = adouble_path(talloc_tos(), smb_fname_dst->base_name,
2370 DEBUG(10, ("fruit_rename: %s -> %s\n",
2371 src_adouble_path, dst_adouble_path));
2373 rc = rename(src_adouble_path, dst_adouble_path);
2374 if (errno == ENOENT) {
2378 TALLOC_FREE(src_adouble_path);
2379 TALLOC_FREE(dst_adouble_path);
2385 static int fruit_unlink(vfs_handle_struct *handle,
2386 const struct smb_filename *smb_fname)
2389 struct fruit_config_data *config = NULL;
2392 if (!is_ntfs_stream_smb_fname(smb_fname)) {
2393 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
2396 SMB_VFS_HANDLE_GET_DATA(handle, config,
2397 struct fruit_config_data, return -1);
2399 if (is_afpinfo_stream(smb_fname)) {
2400 if (config->meta == FRUIT_META_STREAM) {
2401 rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
2403 rc = SMB_VFS_REMOVEXATTR(handle->conn,
2404 smb_fname->base_name,
2405 AFPINFO_EA_NETATALK);
2407 } else if (is_afpresource_stream(smb_fname)) {
2408 if (config->rsrc == FRUIT_RSRC_ADFILE) {
2409 rc = adouble_path(talloc_tos(),
2410 smb_fname->base_name, &adp);
2414 /* FIXME: direct unlink(), missing smb_fname */
2416 if ((rc == -1) && (errno == ENOENT)) {
2420 rc = SMB_VFS_REMOVEXATTR(handle->conn,
2421 smb_fname->base_name,
2422 AFPRESOURCE_EA_NETATALK);
2425 rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
2432 static int fruit_chmod(vfs_handle_struct *handle,
2438 struct fruit_config_data *config = NULL;
2441 rc = SMB_VFS_NEXT_CHMOD(handle, path, mode);
2446 SMB_VFS_HANDLE_GET_DATA(handle, config,
2447 struct fruit_config_data, return -1);
2449 if (config->rsrc == FRUIT_RSRC_XATTR) {
2453 /* FIXME: direct sys_lstat(), missing smb_fname */
2454 rc = sys_lstat(path, &sb, false);
2455 if (rc != 0 || !S_ISREG(sb.st_ex_mode)) {
2459 rc = adouble_path(talloc_tos(), path, &adp);
2464 DEBUG(10, ("fruit_chmod: %s\n", adp));
2466 rc = SMB_VFS_NEXT_CHMOD(handle, adp, mode);
2467 if (errno == ENOENT) {
2475 static int fruit_chown(vfs_handle_struct *handle,
2482 struct fruit_config_data *config = NULL;
2485 rc = SMB_VFS_NEXT_CHOWN(handle, path, uid, gid);
2490 SMB_VFS_HANDLE_GET_DATA(handle, config,
2491 struct fruit_config_data, return -1);
2493 if (config->rsrc == FRUIT_RSRC_XATTR) {
2497 /* FIXME: direct sys_lstat(), missing smb_fname */
2498 rc = sys_lstat(path, &sb, false);
2499 if (rc != 0 || !S_ISREG(sb.st_ex_mode)) {
2503 rc = adouble_path(talloc_tos(), path, &adp);
2508 DEBUG(10, ("fruit_chown: %s\n", adp));
2510 rc = SMB_VFS_NEXT_CHOWN(handle, adp, uid, gid);
2511 if (errno == ENOENT) {
2520 static int fruit_rmdir(struct vfs_handle_struct *handle, const char *path)
2524 struct fruit_config_data *config;
2526 SMB_VFS_HANDLE_GET_DATA(handle, config,
2527 struct fruit_config_data, return -1);
2529 if (!handle->conn->cwd || !path || (config->rsrc == FRUIT_RSRC_XATTR)) {
2534 * Due to there is no way to change bDeleteVetoFiles variable
2535 * from this module, need to clean up ourselves
2542 while ((de = readdir(dh)) != NULL) {
2543 if ((strncmp(de->d_name,
2544 ADOUBLE_NAME_PREFIX,
2545 strlen(ADOUBLE_NAME_PREFIX))) == 0) {
2546 char *p = talloc_asprintf(talloc_tos(),
2552 DEBUG(10, ("fruit_rmdir: delete %s\n", p));
2562 return SMB_VFS_NEXT_RMDIR(handle, path);
2565 static ssize_t fruit_pread(vfs_handle_struct *handle,
2566 files_struct *fsp, void *data,
2567 size_t n, off_t offset)
2570 struct adouble *ad = (struct adouble *)VFS_FETCH_FSP_EXTENSION(
2572 struct fruit_config_data *config = NULL;
2576 char *tmp_base_name = NULL;
2579 DEBUG(10, ("fruit_pread: offset=%d, size=%d\n", (int)offset, (int)n));
2581 if (!fsp->base_fsp) {
2582 return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2585 SMB_VFS_HANDLE_GET_DATA(handle, config,
2586 struct fruit_config_data, return -1);
2588 /* fsp_name is not converted with vfs_catia */
2589 tmp_base_name = fsp->base_fsp->fsp_name->base_name;
2590 status = SMB_VFS_TRANSLATE_NAME(handle->conn,
2591 fsp->base_fsp->fsp_name->base_name,
2592 vfs_translate_to_unix,
2593 talloc_tos(), &name);
2594 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
2595 name = talloc_strdup(talloc_tos(), tmp_base_name);
2600 } else if (!NT_STATUS_IS_OK(status)) {
2601 errno = map_errno_from_nt_status(status);
2605 fsp->base_fsp->fsp_name->base_name = name;
2608 len = SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
2616 if (!fruit_fsp_recheck(ad, fsp)) {
2621 if (ad->ad_type == ADOUBLE_META) {
2622 ai = afpinfo_new(talloc_tos());
2628 len = ad_read(ad, fsp->base_fsp->fsp_name->base_name);
2634 memcpy(&ai->afpi_FinderInfo[0],
2635 ad_entry(ad, ADEID_FINDERI),
2637 len = afpinfo_pack(ai, data);
2638 if (len != AFP_INFO_SIZE) {
2643 len = SMB_VFS_NEXT_PREAD(
2644 handle, fsp, data, n,
2645 offset + ad_getentryoff(ad, ADEID_RFORK));
2652 fsp->base_fsp->fsp_name->base_name = tmp_base_name;
2658 DEBUG(10, ("fruit_pread: rc=%d, len=%zd\n", rc, len));
2662 static ssize_t fruit_pwrite(vfs_handle_struct *handle,
2663 files_struct *fsp, const void *data,
2664 size_t n, off_t offset)
2667 struct adouble *ad = (struct adouble *)VFS_FETCH_FSP_EXTENSION(
2669 struct fruit_config_data *config = NULL;
2673 char *tmp_base_name = NULL;
2676 DEBUG(10, ("fruit_pwrite: offset=%d, size=%d\n", (int)offset, (int)n));
2678 if (!fsp->base_fsp) {
2679 return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2682 SMB_VFS_HANDLE_GET_DATA(handle, config,
2683 struct fruit_config_data, return -1);
2685 tmp_base_name = fsp->base_fsp->fsp_name->base_name;
2686 status = SMB_VFS_TRANSLATE_NAME(handle->conn,
2687 fsp->base_fsp->fsp_name->base_name,
2688 vfs_translate_to_unix,
2689 talloc_tos(), &name);
2690 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
2691 name = talloc_strdup(talloc_tos(), tmp_base_name);
2696 } else if (!NT_STATUS_IS_OK(status)) {
2697 errno = map_errno_from_nt_status(status);
2701 fsp->base_fsp->fsp_name->base_name = name;
2704 len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
2712 if (!fruit_fsp_recheck(ad, fsp)) {
2717 if (ad->ad_type == ADOUBLE_META) {
2718 if (n != AFP_INFO_SIZE || offset != 0) {
2719 DEBUG(1, ("unexpected offset=%jd or size=%jd\n",
2720 (intmax_t)offset, (intmax_t)n));
2724 ai = afpinfo_unpack(talloc_tos(), data);
2729 memcpy(ad_entry(ad, ADEID_FINDERI),
2730 &ai->afpi_FinderInfo[0], ADEDLEN_FINDERI);
2731 rc = ad_write(ad, name);
2733 len = SMB_VFS_NEXT_PWRITE(handle, fsp, data, n,
2734 offset + ad_getentryoff(ad, ADEID_RFORK));
2740 if (config->rsrc == FRUIT_RSRC_ADFILE) {
2741 rc = ad_read(ad, name);
2747 if ((len + offset) > ad_getentrylen(ad, ADEID_RFORK)) {
2748 ad_setentrylen(ad, ADEID_RFORK, len + offset);
2749 rc = ad_write(ad, name);
2755 fsp->base_fsp->fsp_name->base_name = tmp_base_name;
2765 * Helper to stat/lstat the base file of an smb_fname.
2767 static int fruit_stat_base(vfs_handle_struct *handle,
2768 struct smb_filename *smb_fname,
2771 char *tmp_stream_name;
2774 tmp_stream_name = smb_fname->stream_name;
2775 smb_fname->stream_name = NULL;
2777 rc = SMB_VFS_NEXT_STAT(handle, smb_fname);
2779 rc = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
2781 smb_fname->stream_name = tmp_stream_name;
2785 static int fruit_stat_meta(vfs_handle_struct *handle,
2786 struct smb_filename *smb_fname,
2789 /* Populate the stat struct with info from the base file. */
2790 if (fruit_stat_base(handle, smb_fname, follow_links) == -1) {
2793 smb_fname->st.st_ex_size = AFP_INFO_SIZE;
2794 smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
2795 smb_fname->stream_name);
2799 static int fruit_stat_rsrc(vfs_handle_struct *handle,
2800 struct smb_filename *smb_fname,
2804 struct adouble *ad = NULL;
2806 DEBUG(10, ("fruit_stat_rsrc called for %s\n",
2807 smb_fname_str_dbg(smb_fname)));
2809 ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_RSRC);
2815 /* Populate the stat struct with info from the base file. */
2816 if (fruit_stat_base(handle, smb_fname, follow_links) == -1) {
2821 smb_fname->st.st_ex_size = ad_getentrylen(ad, ADEID_RFORK);
2822 smb_fname->st.st_ex_ino = fruit_inode(&smb_fname->st,
2823 smb_fname->stream_name);
2828 static int fruit_stat(vfs_handle_struct *handle,
2829 struct smb_filename *smb_fname)
2833 DEBUG(10, ("fruit_stat called for %s\n",
2834 smb_fname_str_dbg(smb_fname)));
2836 if (!is_ntfs_stream_smb_fname(smb_fname)
2837 || is_ntfs_default_stream_smb_fname(smb_fname)) {
2838 rc = SMB_VFS_NEXT_STAT(handle, smb_fname);
2840 update_btime(handle, smb_fname);
2846 * Note if lp_posix_paths() is true, we can never
2847 * get here as is_ntfs_stream_smb_fname() is
2848 * always false. So we never need worry about
2849 * not following links here.
2852 if (is_afpinfo_stream(smb_fname)) {
2853 rc = fruit_stat_meta(handle, smb_fname, true);
2854 } else if (is_afpresource_stream(smb_fname)) {
2855 rc = fruit_stat_rsrc(handle, smb_fname, true);
2857 return SMB_VFS_NEXT_STAT(handle, smb_fname);
2861 update_btime(handle, smb_fname);
2862 smb_fname->st.st_ex_mode &= ~S_IFMT;
2863 smb_fname->st.st_ex_mode |= S_IFREG;
2864 smb_fname->st.st_ex_blocks =
2865 smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
2870 static int fruit_lstat(vfs_handle_struct *handle,
2871 struct smb_filename *smb_fname)
2875 DEBUG(10, ("fruit_lstat called for %s\n",
2876 smb_fname_str_dbg(smb_fname)));
2878 if (!is_ntfs_stream_smb_fname(smb_fname)
2879 || is_ntfs_default_stream_smb_fname(smb_fname)) {
2880 rc = SMB_VFS_NEXT_LSTAT(handle, smb_fname);
2882 update_btime(handle, smb_fname);
2887 if (is_afpinfo_stream(smb_fname)) {
2888 rc = fruit_stat_meta(handle, smb_fname, false);
2889 } else if (is_afpresource_stream(smb_fname)) {
2890 rc = fruit_stat_rsrc(handle, smb_fname, false);
2892 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
2896 update_btime(handle, smb_fname);
2897 smb_fname->st.st_ex_mode &= ~S_IFMT;
2898 smb_fname->st.st_ex_mode |= S_IFREG;
2899 smb_fname->st.st_ex_blocks =
2900 smb_fname->st.st_ex_size / STAT_ST_BLOCKSIZE + 1;
2905 static int fruit_fstat_meta(vfs_handle_struct *handle,
2907 SMB_STRUCT_STAT *sbuf)
2909 DEBUG(10, ("fruit_fstat_meta called for %s\n",
2910 smb_fname_str_dbg(fsp->base_fsp->fsp_name)));
2912 /* Populate the stat struct with info from the base file. */
2913 if (fruit_stat_base(handle, fsp->base_fsp->fsp_name, false) == -1) {
2916 *sbuf = fsp->base_fsp->fsp_name->st;
2917 sbuf->st_ex_size = AFP_INFO_SIZE;
2918 sbuf->st_ex_ino = fruit_inode(sbuf, fsp->fsp_name->stream_name);
2923 static int fruit_fstat_rsrc(vfs_handle_struct *handle, files_struct *fsp,
2924 SMB_STRUCT_STAT *sbuf)
2926 struct fruit_config_data *config;
2927 struct adouble *ad = (struct adouble *)VFS_FETCH_FSP_EXTENSION(
2930 DEBUG(10, ("fruit_fstat_rsrc called for %s\n",
2931 smb_fname_str_dbg(fsp->base_fsp->fsp_name)));
2933 SMB_VFS_HANDLE_GET_DATA(handle, config,
2934 struct fruit_config_data, return -1);
2936 if (config->rsrc == FRUIT_RSRC_STREAM) {
2937 return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
2940 /* Populate the stat struct with info from the base file. */
2941 if (fruit_stat_base(handle, fsp->base_fsp->fsp_name, false) == -1) {
2944 *sbuf = fsp->base_fsp->fsp_name->st;
2945 sbuf->st_ex_size = ad_getentrylen(ad, ADEID_RFORK);
2946 sbuf->st_ex_ino = fruit_inode(sbuf, fsp->fsp_name->stream_name);
2948 DEBUG(10, ("fruit_fstat_rsrc %s, size: %zd\n",
2949 smb_fname_str_dbg(fsp->fsp_name),
2950 (ssize_t)sbuf->st_ex_size));
2955 static int fruit_fstat(vfs_handle_struct *handle, files_struct *fsp,
2956 SMB_STRUCT_STAT *sbuf)
2960 char *tmp_base_name = NULL;
2962 struct adouble *ad = (struct adouble *)
2963 VFS_FETCH_FSP_EXTENSION(handle, fsp);
2965 DEBUG(10, ("fruit_fstat called for %s\n",
2966 smb_fname_str_dbg(fsp->fsp_name)));
2968 if (fsp->base_fsp) {
2969 tmp_base_name = fsp->base_fsp->fsp_name->base_name;
2970 /* fsp_name is not converted with vfs_catia */
2971 status = SMB_VFS_TRANSLATE_NAME(
2973 fsp->base_fsp->fsp_name->base_name,
2974 vfs_translate_to_unix,
2975 talloc_tos(), &name);
2977 if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
2978 name = talloc_strdup(talloc_tos(), tmp_base_name);
2983 } else if (!NT_STATUS_IS_OK(status)) {
2984 errno = map_errno_from_nt_status(status);
2988 fsp->base_fsp->fsp_name->base_name = name;
2991 if (ad == NULL || fsp->base_fsp == NULL) {
2992 rc = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
2996 if (!fruit_fsp_recheck(ad, fsp)) {
3001 switch (ad->ad_type) {
3003 rc = fruit_fstat_meta(handle, fsp, sbuf);
3006 rc = fruit_fstat_rsrc(handle, fsp, sbuf);
3009 DEBUG(10, ("fruit_fstat %s: bad type\n",
3010 smb_fname_str_dbg(fsp->fsp_name)));
3016 sbuf->st_ex_mode &= ~S_IFMT;
3017 sbuf->st_ex_mode |= S_IFREG;
3018 sbuf->st_ex_blocks = sbuf->st_ex_size / STAT_ST_BLOCKSIZE + 1;
3022 DEBUG(10, ("fruit_fstat %s, size: %zd\n",
3023 smb_fname_str_dbg(fsp->fsp_name),
3024 (ssize_t)sbuf->st_ex_size));
3025 if (tmp_base_name) {
3026 fsp->base_fsp->fsp_name->base_name = tmp_base_name;
3032 static NTSTATUS fruit_streaminfo(vfs_handle_struct *handle,
3033 struct files_struct *fsp,
3035 TALLOC_CTX *mem_ctx,
3036 unsigned int *pnum_streams,
3037 struct stream_struct **pstreams)
3039 struct fruit_config_data *config = NULL;
3040 struct smb_filename *smb_fname = NULL;
3041 struct adouble *ad = NULL;
3043 SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
3044 return NT_STATUS_UNSUCCESSFUL);
3045 DEBUG(10, ("fruit_streaminfo called for %s\n", fname));
3047 smb_fname = synthetic_smb_fname(talloc_tos(), fname, NULL, NULL);
3048 if (smb_fname == NULL) {
3049 return NT_STATUS_NO_MEMORY;
3052 if (config->meta == FRUIT_META_NETATALK) {
3053 ad = ad_get(talloc_tos(), handle,
3054 smb_fname->base_name, ADOUBLE_META);
3055 if (ad && !empty_finderinfo(ad)) {
3056 if (!add_fruit_stream(
3057 mem_ctx, pnum_streams, pstreams,
3058 AFPINFO_STREAM_NAME, AFP_INFO_SIZE,
3059 smb_roundup(handle->conn,
3062 TALLOC_FREE(smb_fname);
3063 return NT_STATUS_NO_MEMORY;
3069 if (config->rsrc != FRUIT_RSRC_STREAM) {
3070 ad = ad_get(talloc_tos(), handle, smb_fname->base_name,
3073 if (!add_fruit_stream(
3074 mem_ctx, pnum_streams, pstreams,
3075 AFPRESOURCE_STREAM_NAME,
3076 ad_getentrylen(ad, ADEID_RFORK),
3077 smb_roundup(handle->conn,
3079 ad, ADEID_RFORK)))) {
3081 TALLOC_FREE(smb_fname);
3082 return NT_STATUS_NO_MEMORY;
3088 TALLOC_FREE(smb_fname);
3090 return SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx,
3091 pnum_streams, pstreams);
3094 static int fruit_ntimes(vfs_handle_struct *handle,
3095 const struct smb_filename *smb_fname,
3096 struct smb_file_time *ft)
3099 struct adouble *ad = NULL;
3101 if (null_timespec(ft->create_time)) {
3105 DEBUG(10,("set btime for %s to %s\n", smb_fname_str_dbg(smb_fname),
3106 time_to_asc(convert_timespec_to_time_t(ft->create_time))));
3108 ad = ad_get(talloc_tos(), handle, smb_fname->base_name, ADOUBLE_META);
3113 ad_setdate(ad, AD_DATE_CREATE | AD_DATE_UNIX,
3114 convert_time_t_to_uint32_t(ft->create_time.tv_sec));
3116 rc = ad_write(ad, smb_fname->base_name);
3122 DEBUG(1, ("fruit_ntimes: %s\n", smb_fname_str_dbg(smb_fname)));
3125 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
3128 static int fruit_fallocate(struct vfs_handle_struct *handle,
3129 struct files_struct *fsp,
3134 struct adouble *ad =
3135 (struct adouble *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
3138 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
3141 if (!fruit_fsp_recheck(ad, fsp)) {
3145 /* Let the pwrite code path handle it. */
3150 static int fruit_ftruncate(struct vfs_handle_struct *handle,
3151 struct files_struct *fsp,
3155 struct adouble *ad =
3156 (struct adouble *)VFS_FETCH_FSP_EXTENSION(handle, fsp);
3157 struct fruit_config_data *config;
3159 DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
3160 fsp_str_dbg(fsp), (double)offset));
3163 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
3166 if (!fruit_fsp_recheck(ad, fsp)) {
3170 SMB_VFS_HANDLE_GET_DATA(handle, config,
3171 struct fruit_config_data, return -1);
3173 switch (ad->ad_type) {
3176 * As this request hasn't been seen in the wild,
3177 * the only sensible use I can imagine is the client
3178 * truncating the stream to 0 bytes size.
3179 * We simply remove the metadata on such a request.
3182 rc = SMB_VFS_FREMOVEXATTR(fsp,
3183 AFPRESOURCE_EA_NETATALK);
3187 if (config->rsrc == FRUIT_RSRC_XATTR && offset == 0) {
3188 rc = SMB_VFS_FREMOVEXATTR(fsp,
3189 AFPRESOURCE_EA_NETATALK);
3191 rc = SMB_VFS_NEXT_FTRUNCATE(
3193 offset + ad_getentryoff(ad, ADEID_RFORK));
3197 ad_setentrylen(ad, ADEID_RFORK, offset);
3198 rc = ad_write(ad, NULL);
3211 static NTSTATUS fruit_create_file(vfs_handle_struct *handle,
3212 struct smb_request *req,
3213 uint16_t root_dir_fid,
3214 struct smb_filename *smb_fname,
3215 uint32_t access_mask,
3216 uint32_t share_access,
3217 uint32_t create_disposition,
3218 uint32_t create_options,
3219 uint32_t file_attributes,
3220 uint32_t oplock_request,
3221 struct smb2_lease *lease,
3222 uint64_t allocation_size,
3223 uint32_t private_flags,
3224 struct security_descriptor *sd,
3225 struct ea_list *ea_list,
3226 files_struct **result,
3228 const struct smb2_create_blobs *in_context_blobs,
3229 struct smb2_create_blobs *out_context_blobs)
3232 struct fruit_config_data *config = NULL;
3234 status = check_aapl(handle, req, in_context_blobs, out_context_blobs);
3235 if (!NT_STATUS_IS_OK(status)) {
3239 SMB_VFS_HANDLE_GET_DATA(handle, config, struct fruit_config_data,
3240 return NT_STATUS_UNSUCCESSFUL);
3242 status = SMB_VFS_NEXT_CREATE_FILE(
3243 handle, req, root_dir_fid, smb_fname,
3244 access_mask, share_access,
3245 create_disposition, create_options,
3246 file_attributes, oplock_request,
3248 allocation_size, private_flags,
3249 sd, ea_list, result,
3250 pinfo, in_context_blobs, out_context_blobs);
3251 if (!NT_STATUS_IS_OK(status)) {
3255 if (is_ntfs_stream_smb_fname(smb_fname)
3256 || (*result == NULL)
3257 || ((*result)->is_directory)) {
3261 if (config->locking == FRUIT_LOCKING_NETATALK) {
3262 status = fruit_check_access(
3265 map_share_mode_to_deny_mode(share_access, 0));
3266 if (!NT_STATUS_IS_OK(status)) {
3274 DEBUG(1, ("fruit_create_file: %s\n", nt_errstr(status)));
3277 close_file(req, *result, ERROR_CLOSE);
3284 static NTSTATUS fruit_readdir_attr(struct vfs_handle_struct *handle,
3285 const struct smb_filename *fname,
3286 TALLOC_CTX *mem_ctx,
3287 struct readdir_attr_data **pattr_data)
3289 struct fruit_config_data *config = NULL;
3290 struct readdir_attr_data *attr_data;
3293 SMB_VFS_HANDLE_GET_DATA(handle, config,
3294 struct fruit_config_data,
3295 return NT_STATUS_UNSUCCESSFUL);
3297 if (!config->use_aapl) {
3298 return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
3301 DEBUG(10, ("fruit_readdir_attr %s\n", fname->base_name));
3303 *pattr_data = talloc_zero(mem_ctx, struct readdir_attr_data);
3304 if (*pattr_data == NULL) {
3305 return NT_STATUS_UNSUCCESSFUL;
3307 attr_data = *pattr_data;
3308 attr_data->type = RDATTR_AAPL;
3311 * Mac metadata: compressed FinderInfo, resource fork length
3314 status = readdir_attr_macmeta(handle, fname, attr_data);
3315 if (!NT_STATUS_IS_OK(status)) {
3317 * Error handling is tricky: if we return failure from
3318 * this function, the corresponding directory entry
3319 * will to be passed to the client, so we really just
3320 * want to error out on fatal errors.
3322 if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED)) {
3330 if (config->unix_info_enabled) {
3331 attr_data->attr_data.aapl.unix_mode = fname->st.st_ex_mode;
3337 if (!config->readdir_attr_max_access) {
3338 attr_data->attr_data.aapl.max_access = FILE_GENERIC_ALL;
3340 status = smbd_calculate_access_mask(
3344 SEC_FLAG_MAXIMUM_ALLOWED,
3345 &attr_data->attr_data.aapl.max_access);
3346 if (!NT_STATUS_IS_OK(status)) {
3351 return NT_STATUS_OK;
3354 DEBUG(1, ("fruit_readdir_attr %s, error: %s\n",
3355 fname->base_name, nt_errstr(status)));
3356 TALLOC_FREE(*pattr_data);
3360 static NTSTATUS fruit_fget_nt_acl(vfs_handle_struct *handle,
3362 uint32_t security_info,
3363 TALLOC_CTX *mem_ctx,
3364 struct security_descriptor **ppdesc)
3367 struct security_ace ace;
3369 struct fruit_config_data *config;
3371 SMB_VFS_HANDLE_GET_DATA(handle, config,
3372 struct fruit_config_data,
3373 return NT_STATUS_UNSUCCESSFUL);
3375 status = SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info,
3377 if (!NT_STATUS_IS_OK(status)) {
3382 * Add MS NFS style ACEs with uid, gid and mode
3384 if (!config->unix_info_enabled) {
3385 return NT_STATUS_OK;
3388 /* MS NFS style mode */
3389 sid_compose(&sid, &global_sid_Unix_NFS_Mode, fsp->fsp_name->st.st_ex_mode);
3390 init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
3391 status = security_descriptor_dacl_add(*ppdesc, &ace);
3392 if (!NT_STATUS_IS_OK(status)) {
3393 DEBUG(1,("failed to add MS NFS style ACE\n"));
3397 /* MS NFS style uid */
3398 sid_compose(&sid, &global_sid_Unix_NFS_Users, fsp->fsp_name->st.st_ex_uid);
3399 init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
3400 status = security_descriptor_dacl_add(*ppdesc, &ace);
3401 if (!NT_STATUS_IS_OK(status)) {
3402 DEBUG(1,("failed to add MS NFS style ACE\n"));
3406 /* MS NFS style gid */
3407 sid_compose(&sid, &global_sid_Unix_NFS_Groups, fsp->fsp_name->st.st_ex_gid);
3408 init_sec_ace(&ace, &sid, SEC_ACE_TYPE_ACCESS_DENIED, 0, 0);
3409 status = security_descriptor_dacl_add(*ppdesc, &ace);
3410 if (!NT_STATUS_IS_OK(status)) {
3411 DEBUG(1,("failed to add MS NFS style ACE\n"));
3415 return NT_STATUS_OK;
3418 static NTSTATUS fruit_fset_nt_acl(vfs_handle_struct *handle,
3420 uint32_t security_info_sent,
3421 const struct security_descriptor *psd)
3428 DEBUG(1, ("fruit_fset_nt_acl: %s\n", fsp_str_dbg(fsp)));
3430 status = check_ms_nfs(handle, fsp, psd, &ms_nfs_mode, &do_chmod);
3431 if (!NT_STATUS_IS_OK(status)) {
3432 DEBUG(1, ("fruit_fset_nt_acl: check_ms_nfs failed%s\n", fsp_str_dbg(fsp)));
3436 status = SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
3437 if (!NT_STATUS_IS_OK(status)) {
3438 DEBUG(1, ("fruit_fset_nt_acl: SMB_VFS_NEXT_FSET_NT_ACL failed%s\n", fsp_str_dbg(fsp)));
3443 if (fsp->fh->fd != -1) {
3444 DEBUG(1, ("fchmod: %s\n", fsp_str_dbg(fsp)));
3445 result = SMB_VFS_FCHMOD(fsp, ms_nfs_mode);
3447 DEBUG(1, ("chmod: %s\n", fsp_str_dbg(fsp)));
3448 result = SMB_VFS_CHMOD(fsp->conn,
3449 fsp->fsp_name->base_name,
3454 DEBUG(1, ("chmod: %s, result: %d, %04o error %s\n", fsp_str_dbg(fsp),
3455 result, (unsigned)ms_nfs_mode,
3457 status = map_nt_error_from_unix(errno);
3462 return NT_STATUS_OK;
3465 static struct vfs_fn_pointers vfs_fruit_fns = {
3466 .connect_fn = fruit_connect,
3468 /* File operations */
3469 .chmod_fn = fruit_chmod,
3470 .chown_fn = fruit_chown,
3471 .unlink_fn = fruit_unlink,
3472 .rename_fn = fruit_rename,
3473 .rmdir_fn = fruit_rmdir,
3474 .open_fn = fruit_open,
3475 .pread_fn = fruit_pread,
3476 .pwrite_fn = fruit_pwrite,
3477 .stat_fn = fruit_stat,
3478 .lstat_fn = fruit_lstat,
3479 .fstat_fn = fruit_fstat,
3480 .streaminfo_fn = fruit_streaminfo,
3481 .ntimes_fn = fruit_ntimes,
3482 .ftruncate_fn = fruit_ftruncate,
3483 .fallocate_fn = fruit_fallocate,
3484 .create_file_fn = fruit_create_file,
3485 .readdir_attr_fn = fruit_readdir_attr,
3487 /* NT ACL operations */
3488 .fget_nt_acl_fn = fruit_fget_nt_acl,
3489 .fset_nt_acl_fn = fruit_fset_nt_acl,
3492 NTSTATUS vfs_fruit_init(void);
3493 NTSTATUS vfs_fruit_init(void)
3495 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fruit",
3497 if (!NT_STATUS_IS_OK(ret)) {
3501 vfs_fruit_debug_level = debug_add_class("fruit");
3502 if (vfs_fruit_debug_level == -1) {
3503 vfs_fruit_debug_level = DBGC_VFS;
3504 DEBUG(0, ("%s: Couldn't register custom debugging class!\n",
3507 DEBUG(10, ("%s: Debug class number of '%s': %d\n",
3508 "vfs_fruit_init","fruit",vfs_fruit_debug_level));