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"
34 * Enhanced OS X and Netatalk compatibility
35 * ========================================
37 * This modules takes advantage of vfs_streams_xattr and
38 * vfs_catia. VFS modules vfs_fruit and vfs_streams_xattr must be
39 * loaded in the correct order:
41 * vfs modules = catia fruit streams_xattr
43 * The module intercepts the OS X special streams "AFP_AfpInfo" and
44 * "AFP_Resource" and handles them in a special way. All other named
45 * streams are deferred to vfs_streams_xattr.
47 * The OS X client maps all NTFS illegal characters to the Unicode
48 * private range. This module optionally stores the charcters using
49 * their native ASCII encoding using vfs_catia. If you're not enabling
50 * this feature, you can skip catia from vfs modules.
52 * Finally, open modes are optionally checked against Netatalk AFP
55 * The "AFP_AfpInfo" named stream is a binary blob containing OS X
56 * extended metadata for files and directories. This module optionally
57 * reads and stores this metadata in a way compatible with Netatalk 3
58 * which stores the metadata in an EA "org.netatalk.metadata". Cf
59 * source3/include/MacExtensions.h for a description of the binary
62 * The "AFP_Resource" named stream may be arbitrarily large, thus it
63 * can't be stored in an xattr on most filesystem. ZFS on Solaris is
64 * the only available filesystem where xattrs can be of any size and
65 * the OS supports using the file APIs for xattrs.
67 * The AFP_Resource stream is stored in an AppleDouble file prepending
68 * "._" to the filename. On Solaris with ZFS the stream is optionally
69 * stored in an EA "org.netatalk.ressource".
75 * The OS X SMB client sends xattrs as ADS too. For xattr interop with
76 * other protocols you may want to adjust the xattr names the VFS
77 * module vfs_streams_xattr uses for storing ADS's. This defaults to
78 * user.DosStream.ADS_NAME:$DATA and can be changed by specifying
79 * these module parameters:
81 * streams_xattr:prefix = user.
82 * streams_xattr:store_stream_type = false
88 * - log diagnostic if any needed VFS module is not loaded
89 * (eg with lp_vfs_objects())
93 static int vfs_fruit_debug_level
= DBGC_VFS
;
96 #define DBGC_CLASS vfs_fruit_debug_level
98 #define FRUIT_PARAM_TYPE_NAME "fruit"
99 #define ADOUBLE_NAME_PREFIX "._"
103 * This is hokey, but what else can we do?
105 #if defined(HAVE_ATTROPEN) || defined(FREEBSD)
106 #define AFPINFO_EA_NETATALK "org.netatalk.Metadata"
107 #define AFPRESOURCE_EA_NETATALK "org.netatalk.ResourceFork"
109 #define AFPINFO_EA_NETATALK "user.org.netatalk.Metadata"
110 #define AFPRESOURCE_EA_NETATALK "user.org.netatalk.ResourceFork"
113 enum apple_fork
{APPLE_FORK_DATA
, APPLE_FORK_RSRC
};
115 enum fruit_rsrc
{FRUIT_RSRC_STREAM
, FRUIT_RSRC_ADFILE
, FRUIT_RSRC_XATTR
};
116 enum fruit_meta
{FRUIT_META_STREAM
, FRUIT_META_NETATALK
};
117 enum fruit_locking
{FRUIT_LOCKING_NETATALK
, FRUIT_LOCKING_NONE
};
118 enum fruit_encoding
{FRUIT_ENC_NATIVE
, FRUIT_ENC_PRIVATE
};
120 struct fruit_config_data
{
121 enum fruit_rsrc rsrc
;
122 enum fruit_meta meta
;
123 enum fruit_locking locking
;
124 enum fruit_encoding encoding
;
126 bool readdir_attr_enabled
;
127 bool unix_info_enabled
;
130 * Additional undocumented options, all enabled by default,
131 * possibly useful for analyzing performance. The associated
132 * operations with each of them may be expensive, so having
133 * the chance to disable them individually gives a chance
134 * tweaking the setup for the particular usecase.
136 bool readdir_attr_rsize
;
137 bool readdir_attr_finder_info
;
138 bool readdir_attr_max_access
;
141 static const struct enum_list fruit_rsrc
[] = {
142 {FRUIT_RSRC_STREAM
, "stream"}, /* pass on to vfs_streams_xattr */
143 {FRUIT_RSRC_ADFILE
, "file"}, /* ._ AppleDouble file */
144 {FRUIT_RSRC_XATTR
, "xattr"}, /* Netatalk compatible xattr (ZFS only) */
148 static const struct enum_list fruit_meta
[] = {
149 {FRUIT_META_STREAM
, "stream"}, /* pass on to vfs_streams_xattr */
150 {FRUIT_META_NETATALK
, "netatalk"}, /* Netatalk compatible xattr */
154 static const struct enum_list fruit_locking
[] = {
155 {FRUIT_LOCKING_NETATALK
, "netatalk"}, /* synchronize locks with Netatalk */
156 {FRUIT_LOCKING_NONE
, "none"},
160 static const struct enum_list fruit_encoding
[] = {
161 {FRUIT_ENC_NATIVE
, "native"}, /* map unicode private chars to ASCII */
162 {FRUIT_ENC_PRIVATE
, "private"}, /* keep unicode private chars */
166 /*****************************************************************************
167 * Defines, functions and data structures that deal with AppleDouble
168 *****************************************************************************/
171 * There are two AppleDouble blobs we deal with:
173 * - ADOUBLE_META - AppleDouble blob used by Netatalk for storing
174 * metadata in an xattr
176 * - ADOUBLE_RSRC - AppleDouble blob used by OS X and Netatalk in
179 typedef enum {ADOUBLE_META
, ADOUBLE_RSRC
} adouble_type_t
;
182 #define AD_VERSION2 0x00020000
183 #define AD_VERSION AD_VERSION2
186 * AppleDouble entry IDs.
188 #define ADEID_DFORK 1
189 #define ADEID_RFORK 2
191 #define ADEID_COMMENT 4
192 #define ADEID_ICONBW 5
193 #define ADEID_ICONCOL 6
194 #define ADEID_FILEI 7
195 #define ADEID_FILEDATESI 8
196 #define ADEID_FINDERI 9
197 #define ADEID_MACFILEI 10
198 #define ADEID_PRODOSFILEI 11
199 #define ADEID_MSDOSFILEI 12
200 #define ADEID_SHORTNAME 13
201 #define ADEID_AFPFILEI 14
204 /* Private Netatalk entries */
205 #define ADEID_PRIVDEV 16
206 #define ADEID_PRIVINO 17
207 #define ADEID_PRIVSYN 18
208 #define ADEID_PRIVID 19
209 #define ADEID_MAX (ADEID_PRIVID + 1)
212 * These are the real ids for the private entries,
213 * as stored in the adouble file
215 #define AD_DEV 0x80444556
216 #define AD_INO 0x80494E4F
217 #define AD_SYN 0x8053594E
218 #define AD_ID 0x8053567E
220 /* Number of actually used entries */
221 #define ADEID_NUM_XATTR 8
222 #define ADEID_NUM_DOT_UND 2
223 #define ADEID_NUM_RSRC_XATTR 1
225 /* AppleDouble magic */
226 #define AD_APPLESINGLE_MAGIC 0x00051600
227 #define AD_APPLEDOUBLE_MAGIC 0x00051607
228 #define AD_MAGIC AD_APPLEDOUBLE_MAGIC
230 /* Sizes of relevant entry bits */
231 #define ADEDLEN_MAGIC 4
232 #define ADEDLEN_VERSION 4
233 #define ADEDLEN_FILLER 16
234 #define AD_FILLER_TAG "Netatalk " /* should be 16 bytes */
235 #define ADEDLEN_NENTRIES 2
236 #define AD_HEADER_LEN (ADEDLEN_MAGIC + ADEDLEN_VERSION + \
237 ADEDLEN_FILLER + ADEDLEN_NENTRIES) /* 26 */
238 #define AD_ENTRY_LEN_EID 4
239 #define AD_ENTRY_LEN_OFF 4
240 #define AD_ENTRY_LEN_LEN 4
241 #define AD_ENTRY_LEN (AD_ENTRY_LEN_EID + AD_ENTRY_LEN_OFF + AD_ENTRY_LEN_LEN)
244 #define ADEDLEN_NAME 255
245 #define ADEDLEN_COMMENT 200
246 #define ADEDLEN_FILEI 16
247 #define ADEDLEN_FINDERI 32
248 #define ADEDLEN_FILEDATESI 16
249 #define ADEDLEN_SHORTNAME 12 /* length up to 8.3 */
250 #define ADEDLEN_AFPFILEI 4
251 #define ADEDLEN_MACFILEI 4
252 #define ADEDLEN_PRODOSFILEI 8
253 #define ADEDLEN_MSDOSFILEI 2
254 #define ADEDLEN_DID 4
255 #define ADEDLEN_PRIVDEV 8
256 #define ADEDLEN_PRIVINO 8
257 #define ADEDLEN_PRIVSYN 8
258 #define ADEDLEN_PRIVID 4
261 #define ADEDOFF_MAGIC 0
262 #define ADEDOFF_VERSION (ADEDOFF_MAGIC + ADEDLEN_MAGIC)
263 #define ADEDOFF_FILLER (ADEDOFF_VERSION + ADEDLEN_VERSION)
264 #define ADEDOFF_NENTRIES (ADEDOFF_FILLER + ADEDLEN_FILLER)
266 #define ADEDOFF_FINDERI_XATTR (AD_HEADER_LEN + \
267 (ADEID_NUM_XATTR * AD_ENTRY_LEN))
268 #define ADEDOFF_COMMENT_XATTR (ADEDOFF_FINDERI_XATTR + ADEDLEN_FINDERI)
269 #define ADEDOFF_FILEDATESI_XATTR (ADEDOFF_COMMENT_XATTR + ADEDLEN_COMMENT)
270 #define ADEDOFF_AFPFILEI_XATTR (ADEDOFF_FILEDATESI_XATTR + \
272 #define ADEDOFF_PRIVDEV_XATTR (ADEDOFF_AFPFILEI_XATTR + ADEDLEN_AFPFILEI)
273 #define ADEDOFF_PRIVINO_XATTR (ADEDOFF_PRIVDEV_XATTR + ADEDLEN_PRIVDEV)
274 #define ADEDOFF_PRIVSYN_XATTR (ADEDOFF_PRIVINO_XATTR + ADEDLEN_PRIVINO)
275 #define ADEDOFF_PRIVID_XATTR (ADEDOFF_PRIVSYN_XATTR + ADEDLEN_PRIVSYN)
277 #define ADEDOFF_FINDERI_DOT_UND (AD_HEADER_LEN + \
278 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN))
279 #define ADEDOFF_RFORK_DOT_UND (ADEDOFF_FINDERI_DOT_UND + ADEDLEN_FINDERI)
281 #define AD_DATASZ_XATTR (AD_HEADER_LEN + \
282 (ADEID_NUM_XATTR * AD_ENTRY_LEN) + \
283 ADEDLEN_FINDERI + ADEDLEN_COMMENT + \
284 ADEDLEN_FILEDATESI + ADEDLEN_AFPFILEI + \
285 ADEDLEN_PRIVDEV + ADEDLEN_PRIVINO + \
286 ADEDLEN_PRIVSYN + ADEDLEN_PRIVID)
288 #if AD_DATASZ_XATTR != 402
289 #error bad size for AD_DATASZ_XATTR
292 #define AD_DATASZ_DOT_UND (AD_HEADER_LEN + \
293 (ADEID_NUM_DOT_UND * AD_ENTRY_LEN) + \
295 #if AD_DATASZ_DOT_UND != 82
296 #error bad size for AD_DATASZ_DOT_UND
300 * Sharemode locks fcntl() offsets
302 #if _FILE_OFFSET_BITS == 64 || defined(HAVE_LARGEFILE)
303 #define AD_FILELOCK_BASE (UINT64_C(0x7FFFFFFFFFFFFFFF) - 9)
305 #define AD_FILELOCK_BASE (UINT32_C(0x7FFFFFFF) - 9)
307 #define BYTELOCK_MAX (AD_FILELOCK_BASE - 1)
309 #define AD_FILELOCK_OPEN_WR (AD_FILELOCK_BASE + 0)
310 #define AD_FILELOCK_OPEN_RD (AD_FILELOCK_BASE + 1)
311 #define AD_FILELOCK_RSRC_OPEN_WR (AD_FILELOCK_BASE + 2)
312 #define AD_FILELOCK_RSRC_OPEN_RD (AD_FILELOCK_BASE + 3)
313 #define AD_FILELOCK_DENY_WR (AD_FILELOCK_BASE + 4)
314 #define AD_FILELOCK_DENY_RD (AD_FILELOCK_BASE + 5)
315 #define AD_FILELOCK_RSRC_DENY_WR (AD_FILELOCK_BASE + 6)
316 #define AD_FILELOCK_RSRC_DENY_RD (AD_FILELOCK_BASE + 7)
317 #define AD_FILELOCK_OPEN_NONE (AD_FILELOCK_BASE + 8)
318 #define AD_FILELOCK_RSRC_OPEN_NONE (AD_FILELOCK_BASE + 9)
320 /* Time stuff we overload the bits a little */
321 #define AD_DATE_CREATE 0
322 #define AD_DATE_MODIFY 4
323 #define AD_DATE_BACKUP 8
324 #define AD_DATE_ACCESS 12
325 #define AD_DATE_MASK (AD_DATE_CREATE | AD_DATE_MODIFY | \
326 AD_DATE_BACKUP | AD_DATE_ACCESS)
327 #define AD_DATE_UNIX (1 << 10)
328 #define AD_DATE_START 0x80000000
329 #define AD_DATE_DELTA 946684800
330 #define AD_DATE_FROM_UNIX(x) (htonl((x) - AD_DATE_DELTA))
331 #define AD_DATE_TO_UNIX(x) (ntohl(x) + AD_DATE_DELTA)
333 /* Accessor macros */
334 #define ad_getentrylen(ad,eid) ((ad)->ad_eid[(eid)].ade_len)
335 #define ad_getentryoff(ad,eid) ((ad)->ad_eid[(eid)].ade_off)
336 #define ad_setentrylen(ad,eid,len) ((ad)->ad_eid[(eid)].ade_len = (len))
337 #define ad_setentryoff(ad,eid,off) ((ad)->ad_eid[(eid)].ade_off = (off))
338 #define ad_entry(ad,eid) ((ad)->ad_data + ad_getentryoff((ad),(eid)))
346 vfs_handle_struct
*ad_handle
;
347 files_struct
*ad_fsp
;
348 adouble_type_t ad_type
;
351 struct ad_entry ad_eid
[ADEID_MAX
];
355 struct ad_entry_order
{
356 uint32_t id
, offset
, len
;
359 /* Netatalk AppleDouble metadata xattr */
361 struct ad_entry_order entry_order_meta_xattr
[ADEID_NUM_XATTR
+ 1] = {
362 {ADEID_FINDERI
, ADEDOFF_FINDERI_XATTR
, ADEDLEN_FINDERI
},
363 {ADEID_COMMENT
, ADEDOFF_COMMENT_XATTR
, 0},
364 {ADEID_FILEDATESI
, ADEDOFF_FILEDATESI_XATTR
, ADEDLEN_FILEDATESI
},
365 {ADEID_AFPFILEI
, ADEDOFF_AFPFILEI_XATTR
, ADEDLEN_AFPFILEI
},
366 {ADEID_PRIVDEV
, ADEDOFF_PRIVDEV_XATTR
, 0},
367 {ADEID_PRIVINO
, ADEDOFF_PRIVINO_XATTR
, 0},
368 {ADEID_PRIVSYN
, ADEDOFF_PRIVSYN_XATTR
, 0},
369 {ADEID_PRIVID
, ADEDOFF_PRIVID_XATTR
, 0},
373 /* AppleDouble ressource fork file (the ones prefixed by "._") */
375 struct ad_entry_order entry_order_dot_und
[ADEID_NUM_DOT_UND
+ 1] = {
376 {ADEID_FINDERI
, ADEDOFF_FINDERI_DOT_UND
, ADEDLEN_FINDERI
},
377 {ADEID_RFORK
, ADEDOFF_RFORK_DOT_UND
, 0},
382 * Fake AppleDouble entry oder for ressource fork xattr. The xattr
383 * isn't an AppleDouble file, it simply contains the ressource data,
384 * but in order to be able to use some API calls like ad_getentryoff()
385 * we build a fake/helper struct adouble with this entry order struct.
388 struct ad_entry_order entry_order_rsrc_xattr
[ADEID_NUM_RSRC_XATTR
+ 1] = {
393 /* Conversion from enumerated id to on-disk AppleDouble id */
394 #define AD_EID_DISK(a) (set_eid[a])
395 static const uint32_t set_eid
[] = {
396 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
397 AD_DEV
, AD_INO
, AD_SYN
, AD_ID
401 * Forward declarations
403 static struct adouble
*ad_init(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
404 adouble_type_t type
, files_struct
*fsp
);
405 static int ad_write(struct adouble
*ad
, const char *path
);
406 static int adouble_path(TALLOC_CTX
*ctx
, const char *path_in
, char **path_out
);
411 static int ad_getdate(const struct adouble
*ad
,
412 unsigned int dateoff
,
415 bool xlate
= (dateoff
& AD_DATE_UNIX
);
417 dateoff
&= AD_DATE_MASK
;
418 if (!ad_getentryoff(ad
, ADEID_FILEDATESI
)) {
422 if (dateoff
> AD_DATE_ACCESS
) {
426 ad_entry(ad
, ADEID_FILEDATESI
) + dateoff
,
430 *date
= AD_DATE_TO_UNIX(*date
);
438 static int ad_setdate(struct adouble
*ad
, unsigned int dateoff
, uint32_t date
)
440 bool xlate
= (dateoff
& AD_DATE_UNIX
);
442 if (!ad_getentryoff(ad
, ADEID_FILEDATESI
)) {
446 dateoff
&= AD_DATE_MASK
;
448 date
= AD_DATE_FROM_UNIX(date
);
451 if (dateoff
> AD_DATE_ACCESS
) {
455 memcpy(ad_entry(ad
, ADEID_FILEDATESI
) + dateoff
, &date
, sizeof(date
));
462 * Map on-disk AppleDouble id to enumerated id
464 static uint32_t get_eid(uint32_t eid
)
472 return ADEID_PRIVDEV
;
474 return ADEID_PRIVINO
;
476 return ADEID_PRIVSYN
;
487 * Pack AppleDouble structure into data buffer
489 static bool ad_pack(struct adouble
*ad
)
496 bufsize
= talloc_get_size(ad
->ad_data
);
498 if (offset
+ ADEDLEN_MAGIC
< offset
||
499 offset
+ ADEDLEN_MAGIC
>= bufsize
) {
502 RSIVAL(ad
->ad_data
, offset
, ad
->ad_magic
);
503 offset
+= ADEDLEN_MAGIC
;
505 if (offset
+ ADEDLEN_VERSION
< offset
||
506 offset
+ ADEDLEN_VERSION
>= bufsize
) {
509 RSIVAL(ad
->ad_data
, offset
, ad
->ad_version
);
510 offset
+= ADEDLEN_VERSION
;
512 if (offset
+ ADEDLEN_FILLER
< offset
||
513 offset
+ ADEDLEN_FILLER
>= bufsize
) {
516 if (ad
->ad_type
== ADOUBLE_RSRC
) {
517 memcpy(ad
->ad_data
+ offset
, AD_FILLER_TAG
, ADEDLEN_FILLER
);
519 offset
+= ADEDLEN_FILLER
;
521 if (offset
+ ADEDLEN_NENTRIES
< offset
||
522 offset
+ ADEDLEN_NENTRIES
>= bufsize
) {
525 offset
+= ADEDLEN_NENTRIES
;
527 for (eid
= 0, nent
= 0; eid
< ADEID_MAX
; eid
++) {
528 if ((ad
->ad_eid
[eid
].ade_off
== 0)) {
530 * ade_off is also used as indicator whether a
531 * specific entry is used or not
536 if (offset
+ AD_ENTRY_LEN_EID
< offset
||
537 offset
+ AD_ENTRY_LEN_EID
>= bufsize
) {
540 RSIVAL(ad
->ad_data
, offset
, AD_EID_DISK(eid
));
541 offset
+= AD_ENTRY_LEN_EID
;
543 if (offset
+ AD_ENTRY_LEN_OFF
< offset
||
544 offset
+ AD_ENTRY_LEN_OFF
>= bufsize
) {
547 RSIVAL(ad
->ad_data
, offset
, ad
->ad_eid
[eid
].ade_off
);
548 offset
+= AD_ENTRY_LEN_OFF
;
550 if (offset
+ AD_ENTRY_LEN_LEN
< offset
||
551 offset
+ AD_ENTRY_LEN_LEN
>= bufsize
) {
554 RSIVAL(ad
->ad_data
, offset
, ad
->ad_eid
[eid
].ade_len
);
555 offset
+= AD_ENTRY_LEN_LEN
;
560 if (ADEDOFF_NENTRIES
+ 2 >= bufsize
) {
563 RSSVAL(ad
->ad_data
, ADEDOFF_NENTRIES
, nent
);
569 * Unpack an AppleDouble blob into a struct adoble
571 static bool ad_unpack(struct adouble
*ad
, const int nentries
)
573 size_t bufsize
= talloc_get_size(ad
->ad_data
);
575 uint32_t eid
, len
, off
;
578 * The size of the buffer ad->ad_data is checked when read, so
579 * we wouldn't have to check our own offsets, a few extra
580 * checks won't hurt though. We have to check the offsets we
581 * read from the buffer anyway.
584 if (bufsize
< (AD_HEADER_LEN
+ (AD_ENTRY_LEN
* nentries
))) {
585 DEBUG(1, ("bad size\n"));
589 ad
->ad_magic
= RIVAL(ad
->ad_data
, 0);
590 ad
->ad_version
= RIVAL(ad
->ad_data
, ADEDOFF_VERSION
);
591 if ((ad
->ad_magic
!= AD_MAGIC
) || (ad
->ad_version
!= AD_VERSION
)) {
592 DEBUG(1, ("wrong magic or version\n"));
596 adentries
= RSVAL(ad
->ad_data
, ADEDOFF_NENTRIES
);
597 if (adentries
!= nentries
) {
598 DEBUG(1, ("invalid number of entries: %d\n", adentries
));
602 /* now, read in the entry bits */
603 for (i
= 0; i
< adentries
; i
++) {
604 eid
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
));
606 off
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
) + 4);
607 len
= RIVAL(ad
->ad_data
, AD_HEADER_LEN
+ (i
* AD_ENTRY_LEN
) + 8);
609 if (!eid
|| eid
> ADEID_MAX
) {
610 DEBUG(1, ("bogus eid %d\n", eid
));
614 if ((off
> bufsize
) && (eid
!= ADEID_RFORK
)) {
615 DEBUG(1, ("bogus eid %d: off: %" PRIu32
", len: %" PRIu32
"\n",
619 if ((eid
!= ADEID_RFORK
) &&
620 (eid
!= ADEID_FINDERI
) &&
621 ((off
+ len
) > bufsize
)) {
622 DEBUG(1, ("bogus eid %d: off: %" PRIu32
", len: %" PRIu32
"\n",
627 ad
->ad_eid
[eid
].ade_off
= off
;
628 ad
->ad_eid
[eid
].ade_len
= len
;
635 * Convert from Apple's ._ file to Netatalk
637 * Apple's AppleDouble may contain a FinderInfo entry longer then 32
638 * bytes containing packed xattrs. Netatalk can't deal with that, so
639 * we simply discard the packed xattrs.
641 * @return -1 in case an error occured, 0 if no conversion was done, 1
644 static int ad_convert(struct adouble
*ad
, int fd
)
647 char *map
= MAP_FAILED
;
650 origlen
= ad_getentryoff(ad
, ADEID_RFORK
) +
651 ad_getentrylen(ad
, ADEID_RFORK
);
653 /* FIXME: direct use of mmap(), vfs_aio_fork does it too */
654 map
= mmap(NULL
, origlen
, PROT_WRITE
, MAP_SHARED
, fd
, 0);
655 if (map
== MAP_FAILED
) {
656 DEBUG(2, ("mmap AppleDouble: %s\n", strerror(errno
)));
661 memmove(map
+ ad_getentryoff(ad
, ADEID_FINDERI
) + ADEDLEN_FINDERI
,
662 map
+ ad_getentryoff(ad
, ADEID_RFORK
),
663 ad_getentrylen(ad
, ADEID_RFORK
));
665 ad_setentrylen(ad
, ADEID_FINDERI
, ADEDLEN_FINDERI
);
666 ad_setentryoff(ad
, ADEID_RFORK
,
667 ad_getentryoff(ad
, ADEID_FINDERI
) + ADEDLEN_FINDERI
);
670 * FIXME: direct ftruncate(), but we don't have a fsp for the
673 rc
= ftruncate(fd
, ad_getentryoff(ad
, ADEID_RFORK
)
674 + ad_getentrylen(ad
, ADEID_RFORK
));
677 if (map
!= MAP_FAILED
) {
678 munmap(map
, origlen
);
684 * Read and parse Netatalk AppleDouble metadata xattr
686 static ssize_t
ad_header_read_meta(struct adouble
*ad
, const char *path
)
692 DEBUG(10, ("reading meta xattr for %s\n", path
));
694 ealen
= SMB_VFS_GETXATTR(ad
->ad_handle
->conn
, path
,
695 AFPINFO_EA_NETATALK
, ad
->ad_data
,
701 if (errno
== ENOATTR
) {
707 DEBUG(2, ("error reading meta xattr: %s\n",
713 if (ealen
!= AD_DATASZ_XATTR
) {
714 DEBUG(2, ("bad size %zd\n", ealen
));
720 /* Now parse entries */
721 ok
= ad_unpack(ad
, ADEID_NUM_XATTR
);
723 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
729 if (!ad_getentryoff(ad
, ADEID_FINDERI
)
730 || !ad_getentryoff(ad
, ADEID_COMMENT
)
731 || !ad_getentryoff(ad
, ADEID_FILEDATESI
)
732 || !ad_getentryoff(ad
, ADEID_AFPFILEI
)
733 || !ad_getentryoff(ad
, ADEID_PRIVDEV
)
734 || !ad_getentryoff(ad
, ADEID_PRIVINO
)
735 || !ad_getentryoff(ad
, ADEID_PRIVSYN
)
736 || !ad_getentryoff(ad
, ADEID_PRIVID
)) {
737 DEBUG(2, ("invalid AppleDouble metadata xattr\n"));
744 DEBUG(10, ("reading meta xattr for %s, rc: %d\n", path
, rc
));
748 if (errno
== EINVAL
) {
750 removexattr(path
, AFPINFO_EA_NETATALK
);
759 * Read and parse resource fork, either ._ AppleDouble file or xattr
761 static ssize_t
ad_header_read_rsrc(struct adouble
*ad
, const char *path
)
763 struct fruit_config_data
*config
= NULL
;
770 struct adouble
*meta_ad
= NULL
;
771 SMB_STRUCT_STAT sbuf
;
775 SMB_VFS_HANDLE_GET_DATA(ad
->ad_handle
, config
,
776 struct fruit_config_data
, return -1);
778 /* Try rw first so we can use the fd in ad_convert() */
781 if (ad
->ad_fsp
&& ad
->ad_fsp
->fh
&& (ad
->ad_fsp
->fh
->fd
!= -1)) {
782 fd
= ad
->ad_fsp
->fh
->fd
;
784 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
785 adpath
= talloc_strdup(talloc_tos(), path
);
787 rc
= adouble_path(talloc_tos(), path
, &adpath
);
794 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
795 #ifndef HAVE_ATTROPEN
800 /* FIXME: direct Solaris xattr syscall */
801 fd
= attropen(adpath
, AFPRESOURCE_EA_NETATALK
,
805 /* FIXME: direct open(), don't have an fsp */
806 fd
= open(adpath
, mode
);
813 if (mode
== O_RDWR
) {
817 /* fall through ... */
819 DEBUG(2, ("open AppleDouble: %s, %s\n",
820 adpath
, strerror(errno
)));
828 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
829 /* FIXME: direct sys_fstat(), don't have an fsp */
832 lp_fake_directory_create_times(
833 SNUM(ad
->ad_handle
->conn
)));
837 ad_setentrylen(ad
, ADEID_RFORK
, sbuf
.st_ex_size
);
839 /* FIXME: direct sys_pread(), don't have an fsp */
840 len
= sys_pread(fd
, ad
->ad_data
, AD_DATASZ_DOT_UND
, 0);
841 if (len
!= AD_DATASZ_DOT_UND
) {
842 DEBUG(2, ("%s: bad size: %zd\n",
843 strerror(errno
), len
));
848 /* Now parse entries */
849 ok
= ad_unpack(ad
, ADEID_NUM_DOT_UND
);
851 DEBUG(1, ("invalid AppleDouble ressource %s\n", path
));
857 if ((ad_getentryoff(ad
, ADEID_FINDERI
)
858 != ADEDOFF_FINDERI_DOT_UND
)
859 || (ad_getentrylen(ad
, ADEID_FINDERI
)
861 || (ad_getentryoff(ad
, ADEID_RFORK
)
862 < ADEDOFF_RFORK_DOT_UND
)) {
863 DEBUG(2, ("invalid AppleDouble ressource %s\n", path
));
870 && (ad_getentrylen(ad
, ADEID_FINDERI
) > ADEDLEN_FINDERI
)) {
871 rc
= ad_convert(ad
, fd
);
877 * Can't use ad_write() because we might not have a fsp
883 /* FIXME: direct sys_pwrite(), don't have an fsp */
884 len
= sys_pwrite(fd
, ad
->ad_data
,
885 AD_DATASZ_DOT_UND
, 0);
886 if (len
!= AD_DATASZ_DOT_UND
) {
887 DEBUG(2, ("%s: bad size: %zd\n", adpath
, len
));
892 meta_ad
= ad_init(talloc_tos(), ad
->ad_handle
,
894 if (meta_ad
== NULL
) {
899 memcpy(ad_entry(meta_ad
, ADEID_FINDERI
),
900 ad_entry(ad
, ADEID_FINDERI
),
903 rc
= ad_write(meta_ad
, path
);
911 DEBUG(10, ("opened AppleDouble: %s\n", path
));
918 if (opened
&& fd
!= -1) {
922 TALLOC_FREE(meta_ad
);
930 * Read and unpack an AppleDouble metadata xattr or resource
932 static ssize_t
ad_read(struct adouble
*ad
, const char *path
)
934 switch (ad
->ad_type
) {
936 return ad_header_read_meta(ad
, path
);
938 return ad_header_read_rsrc(ad
, path
);
945 * Allocate a struct adouble without initialiing it
947 * The struct is either hang of the fsp extension context or if fsp is
950 * @param[in] ctx talloc context
951 * @param[in] handle vfs handle
952 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
954 * @param[in] fsp if not NULL (for stream IO), the adouble handle is
955 * added as an fsp extension
957 * @return adouble handle
959 static struct adouble
*ad_alloc(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
960 adouble_type_t type
, files_struct
*fsp
)
965 struct fruit_config_data
*config
;
967 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
968 struct fruit_config_data
, return NULL
);
972 adsize
= AD_DATASZ_XATTR
;
975 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
976 adsize
= AD_DATASZ_DOT_UND
;
984 ad
= talloc_zero(ctx
, struct adouble
);
990 ad
->ad_data
= talloc_zero_array(ad
, char, adsize
);
993 ad
= (struct adouble
*)VFS_ADD_FSP_EXTENSION(handle
, fsp
,
1001 ad
->ad_data
= talloc_zero_array(
1002 VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
1008 if (adsize
&& ad
->ad_data
== NULL
) {
1012 ad
->ad_handle
= handle
;
1014 ad
->ad_magic
= AD_MAGIC
;
1015 ad
->ad_version
= AD_VERSION
;
1025 * Allocate and initialize a new struct adouble
1027 * @param[in] ctx talloc context
1028 * @param[in] handle vfs handle
1029 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1030 * @param[in] fsp file handle, may be NULL for a type of e_ad_meta
1032 * @return adouble handle, initialized
1034 static struct adouble
*ad_init(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
1035 adouble_type_t type
, files_struct
*fsp
)
1038 const struct ad_entry_order
*eid
;
1039 struct adouble
*ad
= NULL
;
1040 struct fruit_config_data
*config
;
1041 time_t t
= time(NULL
);
1043 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1044 struct fruit_config_data
, return NULL
);
1048 eid
= entry_order_meta_xattr
;
1051 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
1052 eid
= entry_order_dot_und
;
1054 eid
= entry_order_rsrc_xattr
;
1061 ad
= ad_alloc(ctx
, handle
, type
, fsp
);
1067 ad
->ad_eid
[eid
->id
].ade_off
= eid
->offset
;
1068 ad
->ad_eid
[eid
->id
].ade_len
= eid
->len
;
1072 /* put something sane in the date fields */
1073 ad_setdate(ad
, AD_DATE_CREATE
| AD_DATE_UNIX
, t
);
1074 ad_setdate(ad
, AD_DATE_MODIFY
| AD_DATE_UNIX
, t
);
1075 ad_setdate(ad
, AD_DATE_ACCESS
| AD_DATE_UNIX
, t
);
1076 ad_setdate(ad
, AD_DATE_BACKUP
, htonl(AD_DATE_START
));
1085 * Return AppleDouble data for a file
1087 * @param[in] ctx talloc context
1088 * @param[in] handle vfs handle
1089 * @param[in] path pathname to file or directory
1090 * @param[in] type type of AppleDouble, ADOUBLE_META or ADOUBLE_RSRC
1092 * @return talloced struct adouble or NULL on error
1094 static struct adouble
*ad_get(TALLOC_CTX
*ctx
, vfs_handle_struct
*handle
,
1095 const char *path
, adouble_type_t type
)
1099 struct adouble
*ad
= NULL
;
1101 DEBUG(10, ("ad_get(%s) called for %s\n",
1102 type
== ADOUBLE_META
? "meta" : "rsrc", path
));
1104 ad
= ad_alloc(ctx
, handle
, type
, NULL
);
1110 len
= ad_read(ad
, path
);
1112 DEBUG(10, ("error reading AppleDouble for %s\n", path
));
1118 DEBUG(10, ("ad_get(%s) for %s returning %d\n",
1119 type
== ADOUBLE_META
? "meta" : "rsrc", path
, rc
));
1128 * Set AppleDouble metadata on a file or directory
1130 * @param[in] ad adouble handle
1132 * @param[in] path pathname to file or directory, may be NULL for a
1135 * @return status code, 0 means success
1137 static int ad_write(struct adouble
*ad
, const char *path
)
1147 switch (ad
->ad_type
) {
1149 rc
= SMB_VFS_SETXATTR(ad
->ad_handle
->conn
, path
,
1150 AFPINFO_EA_NETATALK
, ad
->ad_data
,
1151 AD_DATASZ_XATTR
, 0);
1154 if ((ad
->ad_fsp
== NULL
)
1155 || (ad
->ad_fsp
->fh
== NULL
)
1156 || (ad
->ad_fsp
->fh
->fd
== -1)) {
1160 /* FIXME: direct sys_pwrite(), don't have an fsp */
1161 len
= sys_pwrite(ad
->ad_fsp
->fh
->fd
, ad
->ad_data
,
1162 talloc_get_size(ad
->ad_data
), 0);
1163 if (len
!= talloc_get_size(ad
->ad_data
)) {
1164 DEBUG(1, ("short write on %s: %zd",
1165 fsp_str_dbg(ad
->ad_fsp
), len
));
1177 /*****************************************************************************
1179 *****************************************************************************/
1181 static bool is_afpinfo_stream(const struct smb_filename
*smb_fname
)
1183 if (strncasecmp_m(smb_fname
->stream_name
,
1184 AFPINFO_STREAM_NAME
,
1185 strlen(AFPINFO_STREAM_NAME
)) == 0) {
1191 static bool is_afpresource_stream(const struct smb_filename
*smb_fname
)
1193 if (strncasecmp_m(smb_fname
->stream_name
,
1194 AFPRESOURCE_STREAM_NAME
,
1195 strlen(AFPRESOURCE_STREAM_NAME
)) == 0) {
1202 * Test whether stream is an Apple stream, not used atm
1205 static bool is_apple_stream(const struct smb_filename
*smb_fname
)
1207 if (is_afpinfo_stream(smb_fname
)) {
1210 if (is_afpresource_stream(smb_fname
)) {
1218 * Initialize config struct from our smb.conf config parameters
1220 static int init_fruit_config(vfs_handle_struct
*handle
)
1222 struct fruit_config_data
*config
;
1225 config
= talloc_zero(handle
->conn
, struct fruit_config_data
);
1227 DEBUG(1, ("talloc_zero() failed\n"));
1232 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1233 "ressource", fruit_rsrc
, FRUIT_RSRC_ADFILE
);
1234 if (enumval
== -1) {
1235 DEBUG(1, ("value for %s: ressource type unknown\n",
1236 FRUIT_PARAM_TYPE_NAME
));
1239 config
->rsrc
= (enum fruit_rsrc
)enumval
;
1241 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1242 "metadata", fruit_meta
, FRUIT_META_NETATALK
);
1243 if (enumval
== -1) {
1244 DEBUG(1, ("value for %s: metadata type unknown\n",
1245 FRUIT_PARAM_TYPE_NAME
));
1248 config
->meta
= (enum fruit_meta
)enumval
;
1250 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1251 "locking", fruit_locking
, FRUIT_LOCKING_NONE
);
1252 if (enumval
== -1) {
1253 DEBUG(1, ("value for %s: locking type unknown\n",
1254 FRUIT_PARAM_TYPE_NAME
));
1257 config
->locking
= (enum fruit_locking
)enumval
;
1259 enumval
= lp_parm_enum(SNUM(handle
->conn
), FRUIT_PARAM_TYPE_NAME
,
1260 "encoding", fruit_encoding
, FRUIT_ENC_PRIVATE
);
1261 if (enumval
== -1) {
1262 DEBUG(1, ("value for %s: encoding type unknown\n",
1263 FRUIT_PARAM_TYPE_NAME
));
1266 config
->encoding
= (enum fruit_encoding
)enumval
;
1268 if (lp_parm_bool(-1, FRUIT_PARAM_TYPE_NAME
, "aapl", true)) {
1269 config
->use_aapl
= true;
1272 if (lp_parm_bool(SNUM(handle
->conn
),
1273 "readdir_attr", "aapl_rsize", true)) {
1274 config
->readdir_attr_rsize
= true;
1277 if (lp_parm_bool(SNUM(handle
->conn
),
1278 "readdir_attr", "aapl_finder_info", true)) {
1279 config
->readdir_attr_finder_info
= true;
1282 if (lp_parm_bool(SNUM(handle
->conn
),
1283 "readdir_attr", "aapl_max_access", true)) {
1284 config
->readdir_attr_max_access
= true;
1287 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1288 NULL
, struct fruit_config_data
,
1295 * Prepend "._" to a basename
1297 static int adouble_path(TALLOC_CTX
*ctx
, const char *path_in
, char **path_out
)
1302 if (!parent_dirname(ctx
, path_in
, &parent
, &base
)) {
1306 *path_out
= talloc_asprintf(ctx
, "%s/._%s", parent
, base
);
1307 if (*path_out
== NULL
) {
1315 * Allocate and initialize an AfpInfo struct
1317 static AfpInfo
*afpinfo_new(TALLOC_CTX
*ctx
)
1319 AfpInfo
*ai
= talloc_zero(ctx
, AfpInfo
);
1323 ai
->afpi_Signature
= AFP_Signature
;
1324 ai
->afpi_Version
= AFP_Version
;
1325 ai
->afpi_BackupTime
= AD_DATE_START
;
1330 * Pack an AfpInfo struct into a buffer
1332 * Buffer size must be at least AFP_INFO_SIZE
1333 * Returns size of packed buffer
1335 static ssize_t
afpinfo_pack(const AfpInfo
*ai
, char *buf
)
1337 memset(buf
, 0, AFP_INFO_SIZE
);
1339 RSIVAL(buf
, 0, ai
->afpi_Signature
);
1340 RSIVAL(buf
, 4, ai
->afpi_Version
);
1341 RSIVAL(buf
, 12, ai
->afpi_BackupTime
);
1342 memcpy(buf
+ 16, ai
->afpi_FinderInfo
, sizeof(ai
->afpi_FinderInfo
));
1344 return AFP_INFO_SIZE
;
1348 * Unpack a buffer into a AfpInfo structure
1350 * Buffer size must be at least AFP_INFO_SIZE
1351 * Returns allocated AfpInfo struct
1353 static AfpInfo
*afpinfo_unpack(TALLOC_CTX
*ctx
, const void *data
)
1355 AfpInfo
*ai
= talloc_zero(ctx
, AfpInfo
);
1360 ai
->afpi_Signature
= RIVAL(data
, 0);
1361 ai
->afpi_Version
= RIVAL(data
, 4);
1362 ai
->afpi_BackupTime
= RIVAL(data
, 12);
1363 memcpy(ai
->afpi_FinderInfo
, (const char *)data
+ 16,
1364 sizeof(ai
->afpi_FinderInfo
));
1366 if (ai
->afpi_Signature
!= AFP_Signature
1367 || ai
->afpi_Version
!= AFP_Version
) {
1368 DEBUG(1, ("Bad AfpInfo signature or version\n"));
1376 * Fake an inode number from the md5 hash of the (xattr) name
1378 static SMB_INO_T
fruit_inode(const SMB_STRUCT_STAT
*sbuf
, const char *sname
)
1381 unsigned char hash
[16];
1385 upper_sname
= talloc_strdup_upper(talloc_tos(), sname
);
1386 SMB_ASSERT(upper_sname
!= NULL
);
1389 MD5Update(&ctx
, (const unsigned char *)&(sbuf
->st_ex_dev
),
1390 sizeof(sbuf
->st_ex_dev
));
1391 MD5Update(&ctx
, (const unsigned char *)&(sbuf
->st_ex_ino
),
1392 sizeof(sbuf
->st_ex_ino
));
1393 MD5Update(&ctx
, (unsigned char *)upper_sname
,
1394 talloc_get_size(upper_sname
)-1);
1395 MD5Final(hash
, &ctx
);
1397 TALLOC_FREE(upper_sname
);
1399 /* Hopefully all the variation is in the lower 4 (or 8) bytes! */
1400 memcpy(&result
, hash
, sizeof(result
));
1402 DEBUG(10, ("fruit_inode \"%s\": ino=0x%llu\n",
1403 sname
, (unsigned long long)result
));
1409 * Ensure ad_fsp is still valid
1411 static bool fruit_fsp_recheck(struct adouble
*ad
, files_struct
*fsp
)
1413 if (ad
->ad_fsp
== fsp
) {
1421 static bool add_fruit_stream(TALLOC_CTX
*mem_ctx
, unsigned int *num_streams
,
1422 struct stream_struct
**streams
,
1423 const char *name
, off_t size
,
1426 struct stream_struct
*tmp
;
1428 tmp
= talloc_realloc(mem_ctx
, *streams
, struct stream_struct
,
1434 tmp
[*num_streams
].name
= talloc_asprintf(tmp
, "%s:$DATA", name
);
1435 if (tmp
[*num_streams
].name
== NULL
) {
1439 tmp
[*num_streams
].size
= size
;
1440 tmp
[*num_streams
].alloc_size
= alloc_size
;
1447 static bool empty_finderinfo(const struct adouble
*ad
)
1450 char emptybuf
[ADEDLEN_FINDERI
] = {0};
1451 if (memcmp(emptybuf
,
1452 ad_entry(ad
, ADEID_FINDERI
),
1453 ADEDLEN_FINDERI
) == 0) {
1460 * Update btime with btime from Netatalk
1462 static void update_btime(vfs_handle_struct
*handle
,
1463 struct smb_filename
*smb_fname
)
1466 struct timespec creation_time
= {0};
1469 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
, ADOUBLE_META
);
1473 if (ad_getdate(ad
, AD_DATE_UNIX
| AD_DATE_CREATE
, &t
) != 0) {
1479 creation_time
.tv_sec
= convert_uint32_t_to_time_t(t
);
1480 update_stat_ex_create_time(&smb_fname
->st
, creation_time
);
1486 * Map an access mask to a Netatalk single byte byte range lock
1488 static off_t
access_to_netatalk_brl(enum apple_fork fork_type
,
1489 uint32_t access_mask
)
1493 switch (access_mask
) {
1494 case FILE_READ_DATA
:
1495 offset
= AD_FILELOCK_OPEN_RD
;
1498 case FILE_WRITE_DATA
:
1499 case FILE_APPEND_DATA
:
1500 offset
= AD_FILELOCK_OPEN_WR
;
1504 offset
= AD_FILELOCK_OPEN_NONE
;
1508 if (fork_type
== APPLE_FORK_RSRC
) {
1509 if (offset
== AD_FILELOCK_OPEN_NONE
) {
1510 offset
= AD_FILELOCK_RSRC_OPEN_NONE
;
1520 * Map a deny mode to a Netatalk brl
1522 static off_t
denymode_to_netatalk_brl(enum apple_fork fork_type
,
1527 switch (deny_mode
) {
1529 offset
= AD_FILELOCK_DENY_RD
;
1533 offset
= AD_FILELOCK_DENY_WR
;
1537 smb_panic("denymode_to_netatalk_brl: bad deny mode\n");
1540 if (fork_type
== APPLE_FORK_RSRC
) {
1548 * Call fcntl() with an exclusive F_GETLK request in order to
1549 * determine if there's an exisiting shared lock
1551 * @return true if the requested lock was found or any error occured
1552 * false if the lock was not found
1554 static bool test_netatalk_lock(files_struct
*fsp
, off_t in_offset
)
1557 off_t offset
= in_offset
;
1562 result
= SMB_VFS_GETLOCK(fsp
, &offset
, &len
, &type
, &pid
);
1563 if (result
== false) {
1567 if (type
!= F_UNLCK
) {
1574 static NTSTATUS
fruit_check_access(vfs_handle_struct
*handle
,
1576 uint32_t access_mask
,
1579 NTSTATUS status
= NT_STATUS_OK
;
1580 struct byte_range_lock
*br_lck
= NULL
;
1581 bool open_for_reading
, open_for_writing
, deny_read
, deny_write
;
1584 /* FIXME: hardcoded data fork, add resource fork */
1585 enum apple_fork fork_type
= APPLE_FORK_DATA
;
1587 DEBUG(10, ("fruit_check_access: %s, am: %s/%s, dm: %s/%s\n",
1589 access_mask
& FILE_READ_DATA
? "READ" :"-",
1590 access_mask
& FILE_WRITE_DATA
? "WRITE" : "-",
1591 deny_mode
& DENY_READ
? "DENY_READ" : "-",
1592 deny_mode
& DENY_WRITE
? "DENY_WRITE" : "-"));
1595 * Check read access and deny read mode
1597 if ((access_mask
& FILE_READ_DATA
) || (deny_mode
& DENY_READ
)) {
1599 open_for_reading
= test_netatalk_lock(
1600 fsp
, access_to_netatalk_brl(fork_type
, FILE_READ_DATA
));
1602 deny_read
= test_netatalk_lock(
1603 fsp
, denymode_to_netatalk_brl(fork_type
, DENY_READ
));
1605 DEBUG(10, ("read: %s, deny_write: %s\n",
1606 open_for_reading
== true ? "yes" : "no",
1607 deny_read
== true ? "yes" : "no"));
1609 if (((access_mask
& FILE_READ_DATA
) && deny_read
)
1610 || ((deny_mode
& DENY_READ
) && open_for_reading
)) {
1611 return NT_STATUS_SHARING_VIOLATION
;
1615 if (access_mask
& FILE_READ_DATA
) {
1616 off
= access_to_netatalk_brl(fork_type
, FILE_READ_DATA
);
1618 handle
->conn
->sconn
->msg_ctx
, fsp
,
1619 fsp
->op
->global
->open_persistent_id
, 1, off
,
1620 READ_LOCK
, POSIX_LOCK
, false,
1623 if (!NT_STATUS_IS_OK(status
)) {
1626 TALLOC_FREE(br_lck
);
1629 if (deny_mode
& DENY_READ
) {
1630 off
= denymode_to_netatalk_brl(fork_type
, DENY_READ
);
1632 handle
->conn
->sconn
->msg_ctx
, fsp
,
1633 fsp
->op
->global
->open_persistent_id
, 1, off
,
1634 READ_LOCK
, POSIX_LOCK
, false,
1637 if (!NT_STATUS_IS_OK(status
)) {
1640 TALLOC_FREE(br_lck
);
1645 * Check write access and deny write mode
1647 if ((access_mask
& FILE_WRITE_DATA
) || (deny_mode
& DENY_WRITE
)) {
1649 open_for_writing
= test_netatalk_lock(
1650 fsp
, access_to_netatalk_brl(fork_type
, FILE_WRITE_DATA
));
1652 deny_write
= test_netatalk_lock(
1653 fsp
, denymode_to_netatalk_brl(fork_type
, DENY_WRITE
));
1655 DEBUG(10, ("write: %s, deny_write: %s\n",
1656 open_for_writing
== true ? "yes" : "no",
1657 deny_write
== true ? "yes" : "no"));
1659 if (((access_mask
& FILE_WRITE_DATA
) && deny_write
)
1660 || ((deny_mode
& DENY_WRITE
) && open_for_writing
)) {
1661 return NT_STATUS_SHARING_VIOLATION
;
1665 if (access_mask
& FILE_WRITE_DATA
) {
1666 off
= access_to_netatalk_brl(fork_type
, FILE_WRITE_DATA
);
1668 handle
->conn
->sconn
->msg_ctx
, fsp
,
1669 fsp
->op
->global
->open_persistent_id
, 1, off
,
1670 READ_LOCK
, POSIX_LOCK
, false,
1673 if (!NT_STATUS_IS_OK(status
)) {
1676 TALLOC_FREE(br_lck
);
1679 if (deny_mode
& DENY_WRITE
) {
1680 off
= denymode_to_netatalk_brl(fork_type
, DENY_WRITE
);
1682 handle
->conn
->sconn
->msg_ctx
, fsp
,
1683 fsp
->op
->global
->open_persistent_id
, 1, off
,
1684 READ_LOCK
, POSIX_LOCK
, false,
1687 if (!NT_STATUS_IS_OK(status
)) {
1690 TALLOC_FREE(br_lck
);
1694 TALLOC_FREE(br_lck
);
1699 static NTSTATUS
check_aapl(vfs_handle_struct
*handle
,
1700 struct smb_request
*req
,
1701 const struct smb2_create_blobs
*in_context_blobs
,
1702 struct smb2_create_blobs
*out_context_blobs
)
1704 struct fruit_config_data
*config
;
1706 struct smb2_create_blob
*aapl
= NULL
;
1710 DATA_BLOB blob
= data_blob_talloc(req
, NULL
, 0);
1711 uint64_t req_bitmap
, client_caps
;
1712 uint64_t server_caps
= SMB2_CRTCTX_AAPL_UNIX_BASED
;
1716 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
1717 return NT_STATUS_UNSUCCESSFUL
);
1719 if (!config
->use_aapl
1720 || in_context_blobs
== NULL
1721 || out_context_blobs
== NULL
) {
1722 return NT_STATUS_OK
;
1725 aapl
= smb2_create_blob_find(in_context_blobs
,
1726 SMB2_CREATE_TAG_AAPL
);
1728 return NT_STATUS_OK
;
1731 if (aapl
->data
.length
!= 24) {
1732 DEBUG(1, ("unexpected AAPL ctxt legnth: %ju\n",
1733 (uintmax_t)aapl
->data
.length
));
1734 return NT_STATUS_INVALID_PARAMETER
;
1737 cmd
= IVAL(aapl
->data
.data
, 0);
1738 if (cmd
!= SMB2_CRTCTX_AAPL_SERVER_QUERY
) {
1739 DEBUG(1, ("unsupported AAPL cmd: %d\n", cmd
));
1740 return NT_STATUS_INVALID_PARAMETER
;
1743 req_bitmap
= BVAL(aapl
->data
.data
, 8);
1744 client_caps
= BVAL(aapl
->data
.data
, 16);
1746 SIVAL(p
, 0, SMB2_CRTCTX_AAPL_SERVER_QUERY
);
1748 SBVAL(p
, 8, req_bitmap
);
1749 ok
= data_blob_append(req
, &blob
, p
, 16);
1751 return NT_STATUS_UNSUCCESSFUL
;
1754 if (req_bitmap
& SMB2_CRTCTX_AAPL_SERVER_CAPS
) {
1755 if ((client_caps
& SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR
) &&
1756 (handle
->conn
->tcon
->compat
->fs_capabilities
& FILE_NAMED_STREAMS
)) {
1757 server_caps
|= SMB2_CRTCTX_AAPL_SUPPORTS_READ_DIR_ATTR
;
1758 config
->readdir_attr_enabled
= true;
1762 * The client doesn't set the flag, so we can't check
1763 * for it and just set it unconditionally
1765 server_caps
|= SMB2_CRTCTX_AAPL_SUPPORTS_NFS_ACE
;
1766 config
->unix_info_enabled
= true;
1768 SBVAL(p
, 0, server_caps
);
1769 ok
= data_blob_append(req
, &blob
, p
, 8);
1771 return NT_STATUS_UNSUCCESSFUL
;
1775 if (req_bitmap
& SMB2_CRTCTX_AAPL_VOLUME_CAPS
) {
1777 lp_case_sensitive(SNUM(handle
->conn
->tcon
->compat
)) ?
1778 SMB2_CRTCTX_AAPL_CASE_SENSITIVE
: 0);
1779 ok
= data_blob_append(req
, &blob
, p
, 8);
1781 return NT_STATUS_UNSUCCESSFUL
;
1785 if (req_bitmap
& SMB2_CRTCTX_AAPL_MODEL_INFO
) {
1786 ok
= convert_string_talloc(req
,
1787 CH_UNIX
, CH_UTF16LE
,
1788 "Samba", strlen("Samba"),
1791 return NT_STATUS_UNSUCCESSFUL
;
1795 SIVAL(p
+ 4, 0, modellen
);
1796 ok
= data_blob_append(req
, &blob
, p
, 8);
1799 return NT_STATUS_UNSUCCESSFUL
;
1802 ok
= data_blob_append(req
, &blob
, model
, modellen
);
1805 return NT_STATUS_UNSUCCESSFUL
;
1809 status
= smb2_create_blob_add(out_context_blobs
,
1811 SMB2_CREATE_TAG_AAPL
,
1817 static NTSTATUS
readdir_attr_macmeta(struct vfs_handle_struct
*handle
,
1818 const struct smb_filename
*smb_fname
,
1819 struct readdir_attr_data
*attr_data
)
1821 NTSTATUS status
= NT_STATUS_OK
;
1822 uint32_t date_added
;
1823 struct adouble
*ad
= NULL
;
1824 struct fruit_config_data
*config
= NULL
;
1826 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1827 struct fruit_config_data
,
1828 return NT_STATUS_UNSUCCESSFUL
);
1831 /* Ensure we return a default value in the creation_date field */
1832 RSIVAL(&attr_data
->attr_data
.aapl
.finder_info
, 12, AD_DATE_START
);
1835 * Resource fork length
1838 if (config
->readdir_attr_rsize
) {
1839 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
,
1842 attr_data
->attr_data
.aapl
.rfork_size
= ad_getentrylen(
1852 if (config
->readdir_attr_finder_info
) {
1853 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
,
1856 if (S_ISREG(smb_fname
->st
.st_ex_mode
)) {
1858 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0],
1859 ad_entry(ad
, ADEID_FINDERI
), 4);
1861 /* finder_creator */
1862 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 4,
1863 ad_entry(ad
, ADEID_FINDERI
) + 4, 4);
1867 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 8,
1868 ad_entry(ad
, ADEID_FINDERI
) + 8, 2);
1870 /* finder_ext_flags */
1871 memcpy(&attr_data
->attr_data
.aapl
.finder_info
[0] + 10,
1872 ad_entry(ad
, ADEID_FINDERI
) + 24, 2);
1875 date_added
= convert_time_t_to_uint32_t(
1876 smb_fname
->st
.st_ex_btime
.tv_sec
- AD_DATE_DELTA
);
1877 RSIVAL(&attr_data
->attr_data
.aapl
.finder_info
[0], 12, date_added
);
1887 /* Search MS NFS style ACE with UNIX mode */
1888 static NTSTATUS
check_ms_nfs(vfs_handle_struct
*handle
,
1890 const struct security_descriptor
*psd
,
1895 struct fruit_config_data
*config
= NULL
;
1899 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1900 struct fruit_config_data
,
1901 return NT_STATUS_UNSUCCESSFUL
);
1903 if (psd
->dacl
== NULL
|| !config
->unix_info_enabled
) {
1904 return NT_STATUS_OK
;
1907 for (i
= 0; i
< psd
->dacl
->num_aces
; i
++) {
1908 if (dom_sid_compare_domain(
1909 &global_sid_Unix_NFS_Mode
,
1910 &psd
->dacl
->aces
[i
].trustee
) == 0) {
1911 *pmode
= (mode_t
)psd
->dacl
->aces
[i
].trustee
.sub_auths
[2];
1912 *pmode
&= (S_IRWXU
| S_IRWXG
| S_IRWXO
);
1915 DEBUG(10, ("MS NFS chmod request %s, %04o\n",
1916 fsp_str_dbg(fsp
), *pmode
));
1921 return NT_STATUS_OK
;
1924 /****************************************************************************
1926 ****************************************************************************/
1928 static int fruit_connect(vfs_handle_struct
*handle
,
1929 const char *service
,
1933 char *list
= NULL
, *newlist
= NULL
;
1934 struct fruit_config_data
*config
;
1936 DEBUG(10, ("fruit_connect\n"));
1938 rc
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1943 list
= lp_veto_files(talloc_tos(), SNUM(handle
->conn
));
1946 if (strstr(list
, "/" ADOUBLE_NAME_PREFIX
"*/") == NULL
) {
1947 newlist
= talloc_asprintf(
1949 "%s/" ADOUBLE_NAME_PREFIX
"*/",
1951 lp_do_parameter(SNUM(handle
->conn
),
1956 lp_do_parameter(SNUM(handle
->conn
),
1958 "/" ADOUBLE_NAME_PREFIX
"*/");
1963 rc
= init_fruit_config(handle
);
1968 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1969 struct fruit_config_data
, return -1);
1971 if (config
->encoding
== FRUIT_ENC_NATIVE
) {
1975 "0x22:0xf020,0x2a:0xf021,0x3a:0xf022,0x3c:0xf023,"
1976 "0x3e:0xf024,0x3f:0xf025,0x5c:0xf026,0x7c:0xf027,"
1983 static int fruit_open_meta(vfs_handle_struct
*handle
,
1984 struct smb_filename
*smb_fname
,
1985 files_struct
*fsp
, int flags
, mode_t mode
)
1988 struct fruit_config_data
*config
= NULL
;
1989 struct smb_filename
*smb_fname_base
= NULL
;
1992 struct adouble
*ad
= NULL
;
1994 DEBUG(10, ("fruit_open_meta for %s\n", smb_fname_str_dbg(smb_fname
)));
1996 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
1997 struct fruit_config_data
, return -1);
1999 if (config
->meta
== FRUIT_META_STREAM
) {
2000 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2003 /* Create an smb_filename with stream_name == NULL. */
2004 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
2005 smb_fname
->base_name
, NULL
, NULL
);
2007 if (smb_fname_base
== NULL
) {
2014 * We use baseflags to turn off nasty side-effects when opening the
2018 baseflags
&= ~O_TRUNC
;
2019 baseflags
&= ~O_EXCL
;
2020 baseflags
&= ~O_CREAT
;
2022 hostfd
= SMB_VFS_OPEN(handle
->conn
, smb_fname_base
, fsp
,
2026 * It is legit to open a stream on a directory, but the base
2027 * fd has to be read-only.
2029 if ((hostfd
== -1) && (errno
== EISDIR
)) {
2030 baseflags
&= ~O_ACCMODE
;
2031 baseflags
|= O_RDONLY
;
2032 hostfd
= SMB_VFS_OPEN(handle
->conn
, smb_fname_base
, fsp
,
2036 TALLOC_FREE(smb_fname_base
);
2043 if (flags
& (O_CREAT
| O_TRUNC
)) {
2045 * The attribute does not exist or needs to be truncated,
2046 * create an AppleDouble EA
2048 ad
= ad_init(VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
2049 handle
, ADOUBLE_META
, fsp
);
2055 rc
= ad_write(ad
, smb_fname
->base_name
);
2061 ad
= ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
2062 handle
, ADOUBLE_META
, fsp
);
2067 if (ad_read(ad
, smb_fname
->base_name
) == -1) {
2074 DEBUG(10, ("fruit_open meta rc=%d, fd=%d\n", rc
, hostfd
));
2076 int saved_errno
= errno
;
2079 * BUGBUGBUG -- we would need to call
2080 * fd_close_posix here, but we don't have a
2083 fsp
->fh
->fd
= hostfd
;
2087 errno
= saved_errno
;
2092 static int fruit_open_rsrc(vfs_handle_struct
*handle
,
2093 struct smb_filename
*smb_fname
,
2094 files_struct
*fsp
, int flags
, mode_t mode
)
2097 struct fruit_config_data
*config
= NULL
;
2098 struct adouble
*ad
= NULL
;
2099 struct smb_filename
*smb_fname_base
= NULL
;
2100 char *adpath
= NULL
;
2103 DEBUG(10, ("fruit_open_rsrc for %s\n", smb_fname_str_dbg(smb_fname
)));
2105 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2106 struct fruit_config_data
, return -1);
2108 switch (config
->rsrc
) {
2109 case FRUIT_RSRC_STREAM
:
2110 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2111 case FRUIT_RSRC_XATTR
:
2112 #ifdef HAVE_ATTROPEN
2113 hostfd
= attropen(smb_fname
->base_name
,
2114 AFPRESOURCE_EA_NETATALK
, flags
, mode
);
2118 ad
= ad_init(VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
2119 handle
, ADOUBLE_RSRC
, fsp
);
2133 if (!(flags
& O_CREAT
) && !VALID_STAT(smb_fname
->st
)) {
2134 rc
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
2141 if (VALID_STAT(smb_fname
->st
) && S_ISDIR(smb_fname
->st
.st_ex_mode
)) {
2142 /* sorry, but directories don't habe a resource fork */
2147 rc
= adouble_path(talloc_tos(), smb_fname
->base_name
, &adpath
);
2152 /* Create an smb_filename with stream_name == NULL. */
2153 smb_fname_base
= synthetic_smb_fname(talloc_tos(),
2154 adpath
, NULL
, NULL
);
2155 if (smb_fname_base
== NULL
) {
2161 /* Sanitize flags */
2162 if (flags
& O_WRONLY
) {
2163 /* We always need read access for the metadata header too */
2168 hostfd
= SMB_VFS_OPEN(handle
->conn
, smb_fname_base
, fsp
,
2175 /* REVIEW: we need this in ad_write() */
2176 fsp
->fh
->fd
= hostfd
;
2178 if (flags
& (O_CREAT
| O_TRUNC
)) {
2179 ad
= ad_init(VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
2180 handle
, ADOUBLE_RSRC
, fsp
);
2185 rc
= ad_write(ad
, smb_fname
->base_name
);
2191 ad
= ad_alloc(VFS_MEMCTX_FSP_EXTENSION(handle
, fsp
),
2192 handle
, ADOUBLE_RSRC
, fsp
);
2197 if (ad_read(ad
, smb_fname
->base_name
) == -1) {
2205 TALLOC_FREE(adpath
);
2206 TALLOC_FREE(smb_fname_base
);
2208 DEBUG(10, ("fruit_open resource fork: rc=%d, fd=%d\n", rc
, hostfd
));
2210 int saved_errno
= errno
;
2213 * BUGBUGBUG -- we would need to call
2214 * fd_close_posix here, but we don't have a
2217 fsp
->fh
->fd
= hostfd
;
2221 errno
= saved_errno
;
2226 static int fruit_open(vfs_handle_struct
*handle
,
2227 struct smb_filename
*smb_fname
,
2228 files_struct
*fsp
, int flags
, mode_t mode
)
2230 DEBUG(10, ("fruit_open called for %s\n",
2231 smb_fname_str_dbg(smb_fname
)));
2233 if (!is_ntfs_stream_smb_fname(smb_fname
)) {
2234 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2237 if (is_afpinfo_stream(smb_fname
)) {
2238 return fruit_open_meta(handle
, smb_fname
, fsp
, flags
, mode
);
2239 } else if (is_afpresource_stream(smb_fname
)) {
2240 return fruit_open_rsrc(handle
, smb_fname
, fsp
, flags
, mode
);
2243 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
2246 static int fruit_rename(struct vfs_handle_struct
*handle
,
2247 const struct smb_filename
*smb_fname_src
,
2248 const struct smb_filename
*smb_fname_dst
)
2251 char *src_adouble_path
= NULL
;
2252 char *dst_adouble_path
= NULL
;
2253 struct fruit_config_data
*config
= NULL
;
2255 rc
= SMB_VFS_NEXT_RENAME(handle
, smb_fname_src
, smb_fname_dst
);
2257 if (!VALID_STAT(smb_fname_src
->st
)
2258 || !S_ISREG(smb_fname_src
->st
.st_ex_mode
)) {
2262 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2263 struct fruit_config_data
, return -1);
2265 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
2269 rc
= adouble_path(talloc_tos(), smb_fname_src
->base_name
,
2274 rc
= adouble_path(talloc_tos(), smb_fname_dst
->base_name
,
2280 DEBUG(10, ("fruit_rename: %s -> %s\n",
2281 src_adouble_path
, dst_adouble_path
));
2283 rc
= rename(src_adouble_path
, dst_adouble_path
);
2284 if (errno
== ENOENT
) {
2288 TALLOC_FREE(src_adouble_path
);
2289 TALLOC_FREE(dst_adouble_path
);
2295 static int fruit_unlink(vfs_handle_struct
*handle
,
2296 const struct smb_filename
*smb_fname
)
2299 struct fruit_config_data
*config
= NULL
;
2302 if (!is_ntfs_stream_smb_fname(smb_fname
)) {
2303 return SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
2306 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2307 struct fruit_config_data
, return -1);
2309 if (is_afpinfo_stream(smb_fname
)) {
2310 if (config
->meta
== FRUIT_META_STREAM
) {
2311 rc
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
2313 rc
= SMB_VFS_REMOVEXATTR(handle
->conn
,
2314 smb_fname
->base_name
,
2315 AFPINFO_EA_NETATALK
);
2317 } else if (is_afpresource_stream(smb_fname
)) {
2318 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
2319 rc
= adouble_path(talloc_tos(),
2320 smb_fname
->base_name
, &adp
);
2324 /* FIXME: direct unlink(), missing smb_fname */
2326 if ((rc
== -1) && (errno
== ENOENT
)) {
2330 rc
= SMB_VFS_REMOVEXATTR(handle
->conn
,
2331 smb_fname
->base_name
,
2332 AFPRESOURCE_EA_NETATALK
);
2335 rc
= SMB_VFS_NEXT_UNLINK(handle
, smb_fname
);
2342 static int fruit_chmod(vfs_handle_struct
*handle
,
2348 struct fruit_config_data
*config
= NULL
;
2351 rc
= SMB_VFS_NEXT_CHMOD(handle
, path
, mode
);
2356 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2357 struct fruit_config_data
, return -1);
2359 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
2363 /* FIXME: direct sys_lstat(), missing smb_fname */
2364 rc
= sys_lstat(path
, &sb
, false);
2365 if (rc
!= 0 || !S_ISREG(sb
.st_ex_mode
)) {
2369 rc
= adouble_path(talloc_tos(), path
, &adp
);
2374 DEBUG(10, ("fruit_chmod: %s\n", adp
));
2376 rc
= SMB_VFS_NEXT_CHMOD(handle
, adp
, mode
);
2377 if (errno
== ENOENT
) {
2385 static int fruit_chown(vfs_handle_struct
*handle
,
2392 struct fruit_config_data
*config
= NULL
;
2395 rc
= SMB_VFS_NEXT_CHOWN(handle
, path
, uid
, gid
);
2400 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2401 struct fruit_config_data
, return -1);
2403 if (config
->rsrc
== FRUIT_RSRC_XATTR
) {
2407 /* FIXME: direct sys_lstat(), missing smb_fname */
2408 rc
= sys_lstat(path
, &sb
, false);
2409 if (rc
!= 0 || !S_ISREG(sb
.st_ex_mode
)) {
2413 rc
= adouble_path(talloc_tos(), path
, &adp
);
2418 DEBUG(10, ("fruit_chown: %s\n", adp
));
2420 rc
= SMB_VFS_NEXT_CHOWN(handle
, adp
, uid
, gid
);
2421 if (errno
== ENOENT
) {
2430 static int fruit_rmdir(struct vfs_handle_struct
*handle
, const char *path
)
2434 struct fruit_config_data
*config
;
2436 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2437 struct fruit_config_data
, return -1);
2439 if (!handle
->conn
->cwd
|| !path
|| (config
->rsrc
== FRUIT_RSRC_XATTR
)) {
2444 * Due to there is no way to change bDeleteVetoFiles variable
2445 * from this module, need to clean up ourselves
2452 while ((de
= readdir(dh
)) != NULL
) {
2453 if ((strncmp(de
->d_name
,
2454 ADOUBLE_NAME_PREFIX
,
2455 strlen(ADOUBLE_NAME_PREFIX
))) == 0) {
2456 char *p
= talloc_asprintf(talloc_tos(),
2462 DEBUG(10, ("fruit_rmdir: delete %s\n", p
));
2472 return SMB_VFS_NEXT_RMDIR(handle
, path
);
2475 static ssize_t
fruit_pread(vfs_handle_struct
*handle
,
2476 files_struct
*fsp
, void *data
,
2477 size_t n
, off_t offset
)
2480 struct adouble
*ad
= (struct adouble
*)VFS_FETCH_FSP_EXTENSION(
2482 struct fruit_config_data
*config
= NULL
;
2486 char *tmp_base_name
= NULL
;
2489 DEBUG(10, ("fruit_pread: offset=%d, size=%d\n", (int)offset
, (int)n
));
2491 if (!fsp
->base_fsp
) {
2492 return SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2495 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2496 struct fruit_config_data
, return -1);
2498 /* fsp_name is not converted with vfs_catia */
2499 tmp_base_name
= fsp
->base_fsp
->fsp_name
->base_name
;
2500 status
= SMB_VFS_TRANSLATE_NAME(handle
->conn
,
2501 fsp
->base_fsp
->fsp_name
->base_name
,
2502 vfs_translate_to_unix
,
2503 talloc_tos(), &name
);
2504 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
2505 name
= talloc_strdup(talloc_tos(), tmp_base_name
);
2510 } else if (!NT_STATUS_IS_OK(status
)) {
2511 errno
= map_errno_from_nt_status(status
);
2515 fsp
->base_fsp
->fsp_name
->base_name
= name
;
2518 len
= SMB_VFS_NEXT_PREAD(handle
, fsp
, data
, n
, offset
);
2526 if (!fruit_fsp_recheck(ad
, fsp
)) {
2531 if (ad
->ad_type
== ADOUBLE_META
) {
2532 ai
= afpinfo_new(talloc_tos());
2538 len
= ad_read(ad
, fsp
->base_fsp
->fsp_name
->base_name
);
2544 memcpy(&ai
->afpi_FinderInfo
[0],
2545 ad_entry(ad
, ADEID_FINDERI
),
2547 len
= afpinfo_pack(ai
, data
);
2548 if (len
!= AFP_INFO_SIZE
) {
2553 len
= SMB_VFS_NEXT_PREAD(
2554 handle
, fsp
, data
, n
,
2555 offset
+ ad_getentryoff(ad
, ADEID_RFORK
));
2562 fsp
->base_fsp
->fsp_name
->base_name
= tmp_base_name
;
2568 DEBUG(10, ("fruit_pread: rc=%d, len=%zd\n", rc
, len
));
2572 static ssize_t
fruit_pwrite(vfs_handle_struct
*handle
,
2573 files_struct
*fsp
, const void *data
,
2574 size_t n
, off_t offset
)
2577 struct adouble
*ad
= (struct adouble
*)VFS_FETCH_FSP_EXTENSION(
2579 struct fruit_config_data
*config
= NULL
;
2583 char *tmp_base_name
= NULL
;
2586 DEBUG(10, ("fruit_pwrite: offset=%d, size=%d\n", (int)offset
, (int)n
));
2588 if (!fsp
->base_fsp
) {
2589 return SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2592 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2593 struct fruit_config_data
, return -1);
2595 tmp_base_name
= fsp
->base_fsp
->fsp_name
->base_name
;
2596 status
= SMB_VFS_TRANSLATE_NAME(handle
->conn
,
2597 fsp
->base_fsp
->fsp_name
->base_name
,
2598 vfs_translate_to_unix
,
2599 talloc_tos(), &name
);
2600 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
2601 name
= talloc_strdup(talloc_tos(), tmp_base_name
);
2606 } else if (!NT_STATUS_IS_OK(status
)) {
2607 errno
= map_errno_from_nt_status(status
);
2611 fsp
->base_fsp
->fsp_name
->base_name
= name
;
2614 len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
, offset
);
2622 if (!fruit_fsp_recheck(ad
, fsp
)) {
2627 if (ad
->ad_type
== ADOUBLE_META
) {
2628 if (n
!= AFP_INFO_SIZE
|| offset
!= 0) {
2629 DEBUG(1, ("unexpected offset=%jd or size=%jd\n",
2630 (intmax_t)offset
, (intmax_t)n
));
2634 ai
= afpinfo_unpack(talloc_tos(), data
);
2639 memcpy(ad_entry(ad
, ADEID_FINDERI
),
2640 &ai
->afpi_FinderInfo
[0], ADEDLEN_FINDERI
);
2641 rc
= ad_write(ad
, name
);
2643 len
= SMB_VFS_NEXT_PWRITE(handle
, fsp
, data
, n
,
2644 offset
+ ad_getentryoff(ad
, ADEID_RFORK
));
2650 if (config
->rsrc
== FRUIT_RSRC_ADFILE
) {
2651 rc
= ad_read(ad
, name
);
2657 if ((len
+ offset
) > ad_getentrylen(ad
, ADEID_RFORK
)) {
2658 ad_setentrylen(ad
, ADEID_RFORK
, len
+ offset
);
2659 rc
= ad_write(ad
, name
);
2665 fsp
->base_fsp
->fsp_name
->base_name
= tmp_base_name
;
2675 * Helper to stat/lstat the base file of an smb_fname.
2677 static int fruit_stat_base(vfs_handle_struct
*handle
,
2678 struct smb_filename
*smb_fname
,
2681 char *tmp_stream_name
;
2684 tmp_stream_name
= smb_fname
->stream_name
;
2685 smb_fname
->stream_name
= NULL
;
2687 rc
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
2689 rc
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
2691 smb_fname
->stream_name
= tmp_stream_name
;
2695 static int fruit_stat_meta(vfs_handle_struct
*handle
,
2696 struct smb_filename
*smb_fname
,
2699 /* Populate the stat struct with info from the base file. */
2700 if (fruit_stat_base(handle
, smb_fname
, follow_links
) == -1) {
2703 smb_fname
->st
.st_ex_size
= AFP_INFO_SIZE
;
2704 smb_fname
->st
.st_ex_ino
= fruit_inode(&smb_fname
->st
,
2705 smb_fname
->stream_name
);
2709 static int fruit_stat_rsrc(vfs_handle_struct
*handle
,
2710 struct smb_filename
*smb_fname
,
2714 struct adouble
*ad
= NULL
;
2716 DEBUG(10, ("fruit_stat_rsrc called for %s\n",
2717 smb_fname_str_dbg(smb_fname
)));
2719 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
, ADOUBLE_RSRC
);
2725 /* Populate the stat struct with info from the base file. */
2726 if (fruit_stat_base(handle
, smb_fname
, follow_links
) == -1) {
2731 smb_fname
->st
.st_ex_size
= ad_getentrylen(ad
, ADEID_RFORK
);
2732 smb_fname
->st
.st_ex_ino
= fruit_inode(&smb_fname
->st
,
2733 smb_fname
->stream_name
);
2738 static int fruit_stat(vfs_handle_struct
*handle
,
2739 struct smb_filename
*smb_fname
)
2743 DEBUG(10, ("fruit_stat called for %s\n",
2744 smb_fname_str_dbg(smb_fname
)));
2746 if (!is_ntfs_stream_smb_fname(smb_fname
)
2747 || is_ntfs_default_stream_smb_fname(smb_fname
)) {
2748 rc
= SMB_VFS_NEXT_STAT(handle
, smb_fname
);
2750 update_btime(handle
, smb_fname
);
2756 * Note if lp_posix_paths() is true, we can never
2757 * get here as is_ntfs_stream_smb_fname() is
2758 * always false. So we never need worry about
2759 * not following links here.
2762 if (is_afpinfo_stream(smb_fname
)) {
2763 rc
= fruit_stat_meta(handle
, smb_fname
, true);
2764 } else if (is_afpresource_stream(smb_fname
)) {
2765 rc
= fruit_stat_rsrc(handle
, smb_fname
, true);
2767 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
2771 update_btime(handle
, smb_fname
);
2772 smb_fname
->st
.st_ex_mode
&= ~S_IFMT
;
2773 smb_fname
->st
.st_ex_mode
|= S_IFREG
;
2774 smb_fname
->st
.st_ex_blocks
=
2775 smb_fname
->st
.st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
2780 static int fruit_lstat(vfs_handle_struct
*handle
,
2781 struct smb_filename
*smb_fname
)
2785 DEBUG(10, ("fruit_lstat called for %s\n",
2786 smb_fname_str_dbg(smb_fname
)));
2788 if (!is_ntfs_stream_smb_fname(smb_fname
)
2789 || is_ntfs_default_stream_smb_fname(smb_fname
)) {
2790 rc
= SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
2792 update_btime(handle
, smb_fname
);
2797 if (is_afpinfo_stream(smb_fname
)) {
2798 rc
= fruit_stat_meta(handle
, smb_fname
, false);
2799 } else if (is_afpresource_stream(smb_fname
)) {
2800 rc
= fruit_stat_rsrc(handle
, smb_fname
, false);
2802 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
2806 update_btime(handle
, smb_fname
);
2807 smb_fname
->st
.st_ex_mode
&= ~S_IFMT
;
2808 smb_fname
->st
.st_ex_mode
|= S_IFREG
;
2809 smb_fname
->st
.st_ex_blocks
=
2810 smb_fname
->st
.st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
2815 static int fruit_fstat_meta(vfs_handle_struct
*handle
,
2817 SMB_STRUCT_STAT
*sbuf
)
2819 DEBUG(10, ("fruit_fstat_meta called for %s\n",
2820 smb_fname_str_dbg(fsp
->base_fsp
->fsp_name
)));
2822 /* Populate the stat struct with info from the base file. */
2823 if (fruit_stat_base(handle
, fsp
->base_fsp
->fsp_name
, false) == -1) {
2826 *sbuf
= fsp
->base_fsp
->fsp_name
->st
;
2827 sbuf
->st_ex_size
= AFP_INFO_SIZE
;
2828 sbuf
->st_ex_ino
= fruit_inode(sbuf
, fsp
->fsp_name
->stream_name
);
2833 static int fruit_fstat_rsrc(vfs_handle_struct
*handle
, files_struct
*fsp
,
2834 SMB_STRUCT_STAT
*sbuf
)
2836 struct fruit_config_data
*config
;
2837 struct adouble
*ad
= (struct adouble
*)VFS_FETCH_FSP_EXTENSION(
2840 DEBUG(10, ("fruit_fstat_rsrc called for %s\n",
2841 smb_fname_str_dbg(fsp
->base_fsp
->fsp_name
)));
2843 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
2844 struct fruit_config_data
, return -1);
2846 if (config
->rsrc
== FRUIT_RSRC_STREAM
) {
2847 return SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
2850 /* Populate the stat struct with info from the base file. */
2851 if (fruit_stat_base(handle
, fsp
->base_fsp
->fsp_name
, false) == -1) {
2854 *sbuf
= fsp
->base_fsp
->fsp_name
->st
;
2855 sbuf
->st_ex_size
= ad_getentrylen(ad
, ADEID_RFORK
);
2856 sbuf
->st_ex_ino
= fruit_inode(sbuf
, fsp
->fsp_name
->stream_name
);
2858 DEBUG(10, ("fruit_fstat_rsrc %s, size: %zd\n",
2859 smb_fname_str_dbg(fsp
->fsp_name
),
2860 (ssize_t
)sbuf
->st_ex_size
));
2865 static int fruit_fstat(vfs_handle_struct
*handle
, files_struct
*fsp
,
2866 SMB_STRUCT_STAT
*sbuf
)
2870 char *tmp_base_name
= NULL
;
2872 struct adouble
*ad
= (struct adouble
*)
2873 VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
2875 DEBUG(10, ("fruit_fstat called for %s\n",
2876 smb_fname_str_dbg(fsp
->fsp_name
)));
2878 if (fsp
->base_fsp
) {
2879 tmp_base_name
= fsp
->fsp_name
->base_name
;
2880 /* fsp_name is not converted with vfs_catia */
2881 status
= SMB_VFS_TRANSLATE_NAME(
2883 fsp
->base_fsp
->fsp_name
->base_name
,
2884 vfs_translate_to_unix
,
2885 talloc_tos(), &name
);
2887 if (NT_STATUS_EQUAL(status
, NT_STATUS_NONE_MAPPED
)) {
2888 name
= talloc_strdup(talloc_tos(), tmp_base_name
);
2893 } else if (!NT_STATUS_IS_OK(status
)) {
2894 errno
= map_errno_from_nt_status(status
);
2898 fsp
->base_fsp
->fsp_name
->base_name
= name
;
2901 if (ad
== NULL
|| fsp
->base_fsp
== NULL
) {
2902 rc
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
2906 if (!fruit_fsp_recheck(ad
, fsp
)) {
2911 switch (ad
->ad_type
) {
2913 rc
= fruit_fstat_meta(handle
, fsp
, sbuf
);
2916 rc
= fruit_fstat_rsrc(handle
, fsp
, sbuf
);
2919 DEBUG(10, ("fruit_fstat %s: bad type\n",
2920 smb_fname_str_dbg(fsp
->fsp_name
)));
2926 sbuf
->st_ex_mode
&= ~S_IFMT
;
2927 sbuf
->st_ex_mode
|= S_IFREG
;
2928 sbuf
->st_ex_blocks
= sbuf
->st_ex_size
/ STAT_ST_BLOCKSIZE
+ 1;
2932 DEBUG(10, ("fruit_fstat %s, size: %zd\n",
2933 smb_fname_str_dbg(fsp
->fsp_name
),
2934 (ssize_t
)sbuf
->st_ex_size
));
2935 if (tmp_base_name
) {
2936 fsp
->base_fsp
->fsp_name
->base_name
= tmp_base_name
;
2942 static NTSTATUS
fruit_streaminfo(vfs_handle_struct
*handle
,
2943 struct files_struct
*fsp
,
2945 TALLOC_CTX
*mem_ctx
,
2946 unsigned int *pnum_streams
,
2947 struct stream_struct
**pstreams
)
2949 struct fruit_config_data
*config
= NULL
;
2950 struct smb_filename
*smb_fname
= NULL
;
2951 struct adouble
*ad
= NULL
;
2953 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
2954 return NT_STATUS_UNSUCCESSFUL
);
2955 DEBUG(10, ("fruit_streaminfo called for %s\n", fname
));
2957 smb_fname
= synthetic_smb_fname(talloc_tos(), fname
, NULL
, NULL
);
2958 if (smb_fname
== NULL
) {
2959 return NT_STATUS_NO_MEMORY
;
2962 if (config
->meta
== FRUIT_META_NETATALK
) {
2963 ad
= ad_get(talloc_tos(), handle
,
2964 smb_fname
->base_name
, ADOUBLE_META
);
2965 if (ad
&& !empty_finderinfo(ad
)) {
2966 if (!add_fruit_stream(
2967 mem_ctx
, pnum_streams
, pstreams
,
2968 AFPINFO_STREAM_NAME
, AFP_INFO_SIZE
,
2969 smb_roundup(handle
->conn
,
2972 TALLOC_FREE(smb_fname
);
2973 return NT_STATUS_NO_MEMORY
;
2979 if (config
->rsrc
!= FRUIT_RSRC_STREAM
) {
2980 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
,
2983 if (!add_fruit_stream(
2984 mem_ctx
, pnum_streams
, pstreams
,
2985 AFPRESOURCE_STREAM_NAME
,
2986 ad_getentrylen(ad
, ADEID_RFORK
),
2987 smb_roundup(handle
->conn
,
2989 ad
, ADEID_RFORK
)))) {
2991 TALLOC_FREE(smb_fname
);
2992 return NT_STATUS_NO_MEMORY
;
2998 TALLOC_FREE(smb_fname
);
3000 return SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, fname
, mem_ctx
,
3001 pnum_streams
, pstreams
);
3004 static int fruit_ntimes(vfs_handle_struct
*handle
,
3005 const struct smb_filename
*smb_fname
,
3006 struct smb_file_time
*ft
)
3009 struct adouble
*ad
= NULL
;
3011 if (null_timespec(ft
->create_time
)) {
3015 DEBUG(10,("set btime for %s to %s\n", smb_fname_str_dbg(smb_fname
),
3016 time_to_asc(convert_timespec_to_time_t(ft
->create_time
))));
3018 ad
= ad_get(talloc_tos(), handle
, smb_fname
->base_name
, ADOUBLE_META
);
3023 ad_setdate(ad
, AD_DATE_CREATE
| AD_DATE_UNIX
,
3024 convert_time_t_to_uint32_t(ft
->create_time
.tv_sec
));
3026 rc
= ad_write(ad
, smb_fname
->base_name
);
3032 DEBUG(1, ("fruit_ntimes: %s\n", smb_fname_str_dbg(smb_fname
)));
3035 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
3038 static int fruit_fallocate(struct vfs_handle_struct
*handle
,
3039 struct files_struct
*fsp
,
3040 enum vfs_fallocate_mode mode
,
3044 struct adouble
*ad
=
3045 (struct adouble
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3048 return SMB_VFS_NEXT_FALLOCATE(handle
, fsp
, mode
, offset
, len
);
3051 if (!fruit_fsp_recheck(ad
, fsp
)) {
3055 /* Let the pwrite code path handle it. */
3059 static int fruit_ftruncate(struct vfs_handle_struct
*handle
,
3060 struct files_struct
*fsp
,
3064 struct adouble
*ad
=
3065 (struct adouble
*)VFS_FETCH_FSP_EXTENSION(handle
, fsp
);
3066 struct fruit_config_data
*config
;
3068 DEBUG(10, ("streams_xattr_ftruncate called for file %s offset %.0f\n",
3069 fsp_str_dbg(fsp
), (double)offset
));
3072 return SMB_VFS_NEXT_FTRUNCATE(handle
, fsp
, offset
);
3075 if (!fruit_fsp_recheck(ad
, fsp
)) {
3079 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3080 struct fruit_config_data
, return -1);
3082 switch (ad
->ad_type
) {
3085 * As this request hasn't been seen in the wild,
3086 * the only sensible use I can imagine is the client
3087 * truncating the stream to 0 bytes size.
3088 * We simply remove the metadata on such a request.
3091 rc
= SMB_VFS_FREMOVEXATTR(fsp
,
3092 AFPRESOURCE_EA_NETATALK
);
3096 if (config
->rsrc
== FRUIT_RSRC_XATTR
&& offset
== 0) {
3097 rc
= SMB_VFS_FREMOVEXATTR(fsp
,
3098 AFPRESOURCE_EA_NETATALK
);
3100 rc
= SMB_VFS_NEXT_FTRUNCATE(
3102 offset
+ ad_getentryoff(ad
, ADEID_RFORK
));
3106 ad_setentrylen(ad
, ADEID_RFORK
, offset
);
3107 rc
= ad_write(ad
, NULL
);
3120 static NTSTATUS
fruit_create_file(vfs_handle_struct
*handle
,
3121 struct smb_request
*req
,
3122 uint16_t root_dir_fid
,
3123 struct smb_filename
*smb_fname
,
3124 uint32_t access_mask
,
3125 uint32_t share_access
,
3126 uint32_t create_disposition
,
3127 uint32_t create_options
,
3128 uint32_t file_attributes
,
3129 uint32_t oplock_request
,
3130 struct smb2_lease
*lease
,
3131 uint64_t allocation_size
,
3132 uint32_t private_flags
,
3133 struct security_descriptor
*sd
,
3134 struct ea_list
*ea_list
,
3135 files_struct
**result
,
3137 const struct smb2_create_blobs
*in_context_blobs
,
3138 struct smb2_create_blobs
*out_context_blobs
)
3141 struct fruit_config_data
*config
= NULL
;
3143 status
= check_aapl(handle
, req
, in_context_blobs
, out_context_blobs
);
3144 if (!NT_STATUS_IS_OK(status
)) {
3148 SMB_VFS_HANDLE_GET_DATA(handle
, config
, struct fruit_config_data
,
3149 return NT_STATUS_UNSUCCESSFUL
);
3151 status
= SMB_VFS_NEXT_CREATE_FILE(
3152 handle
, req
, root_dir_fid
, smb_fname
,
3153 access_mask
, share_access
,
3154 create_disposition
, create_options
,
3155 file_attributes
, oplock_request
,
3157 allocation_size
, private_flags
,
3158 sd
, ea_list
, result
,
3159 pinfo
, in_context_blobs
, out_context_blobs
);
3160 if (!NT_STATUS_IS_OK(status
)) {
3164 if (is_ntfs_stream_smb_fname(smb_fname
)
3165 || (*result
== NULL
)
3166 || ((*result
)->is_directory
)) {
3170 if (config
->locking
== FRUIT_LOCKING_NETATALK
) {
3171 status
= fruit_check_access(
3174 map_share_mode_to_deny_mode(share_access
, 0));
3175 if (!NT_STATUS_IS_OK(status
)) {
3183 DEBUG(1, ("fruit_create_file: %s\n", nt_errstr(status
)));
3186 close_file(req
, *result
, ERROR_CLOSE
);
3193 static NTSTATUS
fruit_readdir_attr(struct vfs_handle_struct
*handle
,
3194 const struct smb_filename
*fname
,
3195 TALLOC_CTX
*mem_ctx
,
3196 struct readdir_attr_data
**pattr_data
)
3198 struct fruit_config_data
*config
= NULL
;
3199 struct readdir_attr_data
*attr_data
;
3202 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3203 struct fruit_config_data
,
3204 return NT_STATUS_UNSUCCESSFUL
);
3206 if (!config
->use_aapl
) {
3207 return SMB_VFS_NEXT_READDIR_ATTR(handle
, fname
, mem_ctx
, pattr_data
);
3210 DEBUG(10, ("fruit_readdir_attr %s\n", fname
->base_name
));
3212 *pattr_data
= talloc_zero(mem_ctx
, struct readdir_attr_data
);
3213 if (*pattr_data
== NULL
) {
3214 return NT_STATUS_UNSUCCESSFUL
;
3216 attr_data
= *pattr_data
;
3217 attr_data
->type
= RDATTR_AAPL
;
3220 * Mac metadata: compressed FinderInfo, resource fork length
3223 status
= readdir_attr_macmeta(handle
, fname
, attr_data
);
3224 if (!NT_STATUS_IS_OK(status
)) {
3226 * Error handling is tricky: if we return failure from
3227 * this function, the corresponding directory entry
3228 * will to be passed to the client, so we really just
3229 * want to error out on fatal errors.
3231 if (!NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
3239 if (config
->unix_info_enabled
) {
3240 attr_data
->attr_data
.aapl
.unix_mode
= fname
->st
.st_ex_mode
;
3246 if (!config
->readdir_attr_max_access
) {
3247 attr_data
->attr_data
.aapl
.max_access
= FILE_GENERIC_ALL
;
3249 status
= smbd_calculate_access_mask(
3253 SEC_FLAG_MAXIMUM_ALLOWED
,
3254 &attr_data
->attr_data
.aapl
.max_access
);
3255 if (!NT_STATUS_IS_OK(status
)) {
3260 return NT_STATUS_OK
;
3263 DEBUG(1, ("fruit_readdir_attr %s, error: %s\n",
3264 fname
->base_name
, nt_errstr(status
)));
3265 TALLOC_FREE(*pattr_data
);
3269 static NTSTATUS
fruit_fget_nt_acl(vfs_handle_struct
*handle
,
3271 uint32 security_info
,
3272 TALLOC_CTX
*mem_ctx
,
3273 struct security_descriptor
**ppdesc
)
3276 struct security_ace ace
;
3278 struct fruit_config_data
*config
;
3280 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
3281 struct fruit_config_data
,
3282 return NT_STATUS_UNSUCCESSFUL
);
3284 status
= SMB_VFS_NEXT_FGET_NT_ACL(handle
, fsp
, security_info
,
3286 if (!NT_STATUS_IS_OK(status
)) {
3291 * Add MS NFS style ACEs with uid, gid and mode
3293 if (!config
->unix_info_enabled
) {
3294 return NT_STATUS_OK
;
3297 /* MS NFS style mode */
3298 sid_compose(&sid
, &global_sid_Unix_NFS_Mode
, fsp
->fsp_name
->st
.st_ex_mode
);
3299 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
3300 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
3301 if (!NT_STATUS_IS_OK(status
)) {
3302 DEBUG(1,("failed to add MS NFS style ACE\n"));
3306 /* MS NFS style uid */
3307 sid_compose(&sid
, &global_sid_Unix_NFS_Users
, fsp
->fsp_name
->st
.st_ex_uid
);
3308 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
3309 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
3310 if (!NT_STATUS_IS_OK(status
)) {
3311 DEBUG(1,("failed to add MS NFS style ACE\n"));
3315 /* MS NFS style gid */
3316 sid_compose(&sid
, &global_sid_Unix_NFS_Groups
, fsp
->fsp_name
->st
.st_ex_gid
);
3317 init_sec_ace(&ace
, &sid
, SEC_ACE_TYPE_ACCESS_DENIED
, 0, 0);
3318 status
= security_descriptor_dacl_add(*ppdesc
, &ace
);
3319 if (!NT_STATUS_IS_OK(status
)) {
3320 DEBUG(1,("failed to add MS NFS style ACE\n"));
3324 return NT_STATUS_OK
;
3327 static NTSTATUS
fruit_fset_nt_acl(vfs_handle_struct
*handle
,
3329 uint32 security_info_sent
,
3330 const struct security_descriptor
*psd
)
3337 DEBUG(1, ("fruit_fset_nt_acl: %s\n", fsp_str_dbg(fsp
)));
3339 status
= check_ms_nfs(handle
, fsp
, psd
, &ms_nfs_mode
, &do_chmod
);
3340 if (!NT_STATUS_IS_OK(status
)) {
3341 DEBUG(1, ("fruit_fset_nt_acl: check_ms_nfs failed%s\n", fsp_str_dbg(fsp
)));
3345 status
= SMB_VFS_NEXT_FSET_NT_ACL(handle
, fsp
, security_info_sent
, psd
);
3346 if (!NT_STATUS_IS_OK(status
)) {
3347 DEBUG(1, ("fruit_fset_nt_acl: SMB_VFS_NEXT_FSET_NT_ACL failed%s\n", fsp_str_dbg(fsp
)));
3352 if (fsp
->fh
->fd
!= -1) {
3353 DEBUG(1, ("fchmod: %s\n", fsp_str_dbg(fsp
)));
3354 result
= SMB_VFS_FCHMOD(fsp
, ms_nfs_mode
);
3356 DEBUG(1, ("chmod: %s\n", fsp_str_dbg(fsp
)));
3357 result
= SMB_VFS_CHMOD(fsp
->conn
,
3358 fsp
->fsp_name
->base_name
,
3363 DEBUG(1, ("chmod: %s, result: %d, %04o error %s\n", fsp_str_dbg(fsp
),
3364 result
, ms_nfs_mode
, strerror(errno
)));
3365 status
= map_nt_error_from_unix(errno
);
3370 return NT_STATUS_OK
;
3373 static struct vfs_fn_pointers vfs_fruit_fns
= {
3374 .connect_fn
= fruit_connect
,
3376 /* File operations */
3377 .chmod_fn
= fruit_chmod
,
3378 .chown_fn
= fruit_chown
,
3379 .unlink_fn
= fruit_unlink
,
3380 .rename_fn
= fruit_rename
,
3381 .rmdir_fn
= fruit_rmdir
,
3382 .open_fn
= fruit_open
,
3383 .pread_fn
= fruit_pread
,
3384 .pwrite_fn
= fruit_pwrite
,
3385 .stat_fn
= fruit_stat
,
3386 .lstat_fn
= fruit_lstat
,
3387 .fstat_fn
= fruit_fstat
,
3388 .streaminfo_fn
= fruit_streaminfo
,
3389 .ntimes_fn
= fruit_ntimes
,
3390 .unlink_fn
= fruit_unlink
,
3391 .ftruncate_fn
= fruit_ftruncate
,
3392 .fallocate_fn
= fruit_fallocate
,
3393 .create_file_fn
= fruit_create_file
,
3394 .readdir_attr_fn
= fruit_readdir_attr
,
3396 /* NT ACL operations */
3397 .fget_nt_acl_fn
= fruit_fget_nt_acl
,
3398 .fset_nt_acl_fn
= fruit_fset_nt_acl
,
3401 NTSTATUS
vfs_fruit_init(void);
3402 NTSTATUS
vfs_fruit_init(void)
3404 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "fruit",
3406 if (!NT_STATUS_IS_OK(ret
)) {
3410 vfs_fruit_debug_level
= debug_add_class("fruit");
3411 if (vfs_fruit_debug_level
== -1) {
3412 vfs_fruit_debug_level
= DBGC_VFS
;
3413 DEBUG(0, ("%s: Couldn't register custom debugging class!\n",
3416 DEBUG(10, ("%s: Debug class number of '%s': %d\n",
3417 "vfs_fruit_init","fruit",vfs_fruit_debug_level
));