2 * Samba VFS module supporting multiple AVID clients sharing media.
4 * Copyright (C) 2005 Philip de Nier <philipn@users.sourceforge.net>
5 * Copyright (C) 2012 Andrew Klaassen <clawsoon@yahoo.com>
6 * Copyright (C) 2013 Milos Lukacek
7 * Copyright (C) 2013 Ralph Boehme <slow@samba.org>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 * Unityed Media is a Samba VFS module that allows multiple AVID
27 * clients to share media.
29 * Add this module to the vfs objects option in your Samba share
35 * vfs objects = unityed_media
38 * It is recommended that you separate out Samba shares for Mac
39 * and Windows clients, and add the following options to the shares
40 * for Windows clients (NOTE: replace @ with *):
42 * veto files = /.DS_Store/._@/.Trash@/.Spotlight@/.hidden/.hotfiles@/.vol/
43 * delete veto files = yes
45 * This prevents hidden files from Mac clients interfering with Windows
46 * clients. If you find any more problem hidden files then add them to
50 * This module is designed to work with AVID editing applications that
51 * look in the Avid MediaFiles or OMFI MediaFiles directory for media.
52 * It is not designed to work as expected in all circumstances for
58 #include "system/filesys.h"
59 #include "smbd/smbd.h"
60 #include "../smbd/globals.h"
62 #include "../lib/tsocket/tsocket.h"
65 #define UM_PARAM_TYPE_NAME "unityed_media"
67 static const char *AVID_MXF_DIRNAME
= "Avid MediaFiles/MXF";
68 static const size_t AVID_MXF_DIRNAME_LEN
= 19;
69 static const char *OMFI_MEDIAFILES_DIRNAME
= "OMFI MediaFiles";
70 static const size_t OMFI_MEDIAFILES_DIRNAME_LEN
= 15;
71 static const char *APPLE_DOUBLE_PREFIX
= "._";
72 static const size_t APPLE_DOUBLE_PREFIX_LEN
= 2;
73 static int vfs_um_debug_level
= DBGC_VFS
;
75 enum um_clientid
{UM_CLIENTID_NAME
, UM_CLIENTID_IP
, UM_CLIENTID_HOSTNAME
};
77 struct um_config_data
{
78 enum um_clientid clientid
;
81 static const struct enum_list um_clientid
[] = {
82 {UM_CLIENTID_NAME
, "user"},
83 {UM_CLIENTID_IP
, "ip"},
84 {UM_CLIENTID_HOSTNAME
, "hostname"},
88 /* supplements the directory list stream */
89 typedef struct um_dirinfo_struct
{
94 char *clientSubDirname
;
98 * Returns true and first group of digits in path, false and 0 otherwise
100 static bool get_digit_group(const char *path
, uintmax_t *digit
)
102 const char *p
= path
;
107 DEBUG(10, ("get_digit_group entering with path '%s'\n",
111 * Delibiretly initialize to 0 because callers use this result
112 * even though the string doesn't contain any number and we
118 cp
= next_codepoint(p
, &size
);
122 if ((size
== 1) && (isdigit(cp
))) {
123 *digit
= (uintmax_t)smb_strtoul(p
,
131 DEBUG(10, ("num_suffix = '%ju'\n",
141 /* Add "_<remote_name>.<number>" suffix to path or filename.
144 * Failure: set errno, path NULL, return -1
147 static int alloc_append_client_suffix(vfs_handle_struct
*handle
,
152 const char *clientid
;
153 struct um_config_data
*config
;
155 DEBUG(10, ("Entering with path '%s'\n", *path
));
157 SMB_VFS_HANDLE_GET_DATA(handle
, config
,
158 struct um_config_data
,
161 (void)get_digit_group(*path
, &number
);
163 switch (config
->clientid
) {
166 clientid
= tsocket_address_inet_addr_string(
167 handle
->conn
->sconn
->remote_address
, talloc_tos());
168 if (clientid
== NULL
) {
175 case UM_CLIENTID_HOSTNAME
:
176 clientid
= get_remote_machine_name();
179 case UM_CLIENTID_NAME
:
181 clientid
= get_current_username();
185 *path
= talloc_asprintf_append(*path
, "_%s.%ju",
188 DEBUG(1, ("alloc_append_client_suffix "
194 DEBUG(10, ("Leaving with *path '%s'\n", *path
));
199 /* Returns true if the file or directory begins with the appledouble
202 static bool is_apple_double(const char* fname
)
206 DEBUG(10, ("Entering with fname '%s'\n", fname
));
208 if (strnequal(APPLE_DOUBLE_PREFIX
, fname
, APPLE_DOUBLE_PREFIX_LEN
)) {
211 DEBUG(10, ("Leaving with ret '%s'\n",
212 ret
== true ? "true" : "false"));
216 static bool starts_with_media_dir(const char* media_dirname
,
217 size_t media_dirname_len
,
221 const char *path_start
= path
;
223 DEBUG(10, ("Entering with media_dirname '%s' "
224 "path '%s'\n", media_dirname
, path
));
226 /* Sometimes Samba gives us "./OMFI MediaFiles". */
227 if (strnequal(path
, "./", 2)) {
231 if (strnequal(media_dirname
, path_start
, media_dirname_len
)
233 ((path_start
[media_dirname_len
] == '\0') ||
234 (path_start
[media_dirname_len
] == '/'))) {
238 DEBUG(10, ("Leaving with ret '%s'\n",
239 ret
== true ? "true" : "false"));
244 * Returns true if the file or directory referenced by the path is ONE
245 * LEVEL below the AVID_MXF_DIRNAME or OMFI_MEDIAFILES_DIRNAME
248 static bool is_in_media_dir(const char *path
)
250 int transition_count
= 0;
251 const char *path_start
= path
;
253 const char *media_dirname
;
254 size_t media_dirname_len
;
256 DEBUG(10, ("Entering with path'%s' ", path
));
258 /* Sometimes Samba gives us "./OMFI MediaFiles". */
259 if (strnequal(path
, "./", 2)) {
263 if (strnequal(path_start
, AVID_MXF_DIRNAME
, AVID_MXF_DIRNAME_LEN
)) {
264 media_dirname
= AVID_MXF_DIRNAME
;
265 media_dirname_len
= AVID_MXF_DIRNAME_LEN
;
266 } else if (strnequal(path_start
,
267 OMFI_MEDIAFILES_DIRNAME
,
268 OMFI_MEDIAFILES_DIRNAME_LEN
)) {
269 media_dirname
= OMFI_MEDIAFILES_DIRNAME
;
270 media_dirname_len
= OMFI_MEDIAFILES_DIRNAME_LEN
;
275 if (path_start
[media_dirname_len
] == '\0') {
279 p
= path_start
+ media_dirname_len
+ 1;
282 if (*p
== '\0' || *p
== '/') {
283 if (strnequal(p
- 3, "/..", 3)) {
285 } else if ((p
[-1] != '/') || !strnequal(p
- 2, "/.", 2)) {
296 DEBUG(10, ("Going out with transition_count '%i'\n",
298 if (((transition_count
== 1) && (media_dirname
== AVID_MXF_DIRNAME
))
300 ((transition_count
== 0) && (media_dirname
== OMFI_MEDIAFILES_DIRNAME
))) {
307 * Returns true if the file or directory referenced by the path is
308 * below the AVID_MEDIAFILES_DIRNAME or OMFI_MEDIAFILES_DIRNAME
309 * directory The AVID_MEDIAFILES_DIRNAME and OMFI_MEDIAFILES_DIRNAME
310 * are assumed to be in the root directory, which is generally a safe
311 * assumption in the fixed-path world of Avid.
313 static bool is_in_media_files(const char *path
)
317 DEBUG(10, ("Entering with path '%s'\n", path
));
319 if (starts_with_media_dir(AVID_MXF_DIRNAME
,
320 AVID_MXF_DIRNAME_LEN
, path
) ||
321 starts_with_media_dir(OMFI_MEDIAFILES_DIRNAME
,
322 OMFI_MEDIAFILES_DIRNAME_LEN
, path
)) {
325 DEBUG(10, ("Leaving with ret '%s'\n",
326 ret
== true ? "true" : "false"));
331 /* Add client suffix to "pure-number" path.
333 * Caller must free newPath.
336 * Failure: set errno, newPath NULL, return -1
338 static int alloc_get_client_path(vfs_handle_struct
*handle
,
349 *path_out
= talloc_strdup(ctx
, path_in
);
350 if (*path_out
== NULL
) {
351 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
355 (void)get_digit_group(*path_out
, &number
);
357 digits
= talloc_asprintf(NULL
, "%ju", number
);
358 if (digits
== NULL
) {
359 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
362 digits_len
= strlen(digits
);
364 p
= strstr_m(path_in
, digits
);
367 ((p
[digits_len
] == '\0') || (p
[digits_len
] == '/'))
369 (((p
- path_in
> 0) && (p
[-1] == '/'))
371 (((p
- path_in
) > APPLE_DOUBLE_PREFIX_LEN
)
373 is_apple_double(p
- APPLE_DOUBLE_PREFIX_LEN
)
375 (p
[-(APPLE_DOUBLE_PREFIX_LEN
+ 1)] == '/'))))
377 (*path_out
)[p
- path_in
+ digits_len
] = '\0';
379 status
= alloc_append_client_suffix(handle
, path_out
);
384 *path_out
= talloc_strdup_append(*path_out
, p
+ digits_len
);
385 if (*path_out
== NULL
) {
386 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
392 /* path_out must be freed in caller. */
393 DEBUG(10, ("Result:'%s'\n", *path_out
));
399 * Failure: set errno, return -1
401 static int alloc_get_client_smb_fname(struct vfs_handle_struct
*handle
,
403 const struct smb_filename
*smb_fname
,
404 struct smb_filename
**client_fname
)
408 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
409 smb_fname
->base_name
));
411 *client_fname
= cp_smb_filename(ctx
, smb_fname
);
412 if (*client_fname
== NULL
) {
413 DEBUG(1, ("cp_smb_filename returned NULL\n"));
416 status
= alloc_get_client_path(handle
, ctx
,
417 smb_fname
->base_name
,
418 &(*client_fname
)->base_name
);
423 DEBUG(10, ("Leaving with (*client_fname)->base_name "
424 "'%s'\n", (*client_fname
)->base_name
));
432 * Failure: set errno, return -1
434 static int alloc_set_client_dirinfo_path(struct vfs_handle_struct
*handle
,
437 const char *suffix_number
)
441 DEBUG(10, ("Entering with suffix_number '%s'\n",
444 *path
= talloc_strdup(ctx
, suffix_number
);
446 DEBUG(1, ("alloc_set_client_dirinfo_path ENOMEM\n"));
449 status
= alloc_append_client_suffix(handle
, path
);
454 DEBUG(10, ("Leaving with *path '%s'\n", *path
));
459 static int alloc_set_client_dirinfo(vfs_handle_struct
*handle
,
461 struct um_dirinfo_struct
**di_result
)
466 struct um_dirinfo_struct
*dip
;
468 DEBUG(10, ("Entering with fname '%s'\n", fname
));
470 *di_result
= talloc(NULL
, struct um_dirinfo_struct
);
471 if (*di_result
== NULL
) {
476 dip
->dirpath
= talloc_strdup(dip
, fname
);
477 if (dip
->dirpath
== NULL
) {
481 if (!is_in_media_files(fname
)) {
482 dip
->isInMediaFiles
= false;
483 dip
->clientPath
= NULL
;
484 dip
->clientSubDirname
= NULL
;
488 dip
->isInMediaFiles
= true;
490 (void)get_digit_group(fname
, &number
);
491 digits
= talloc_asprintf(talloc_tos(), "%ju", number
);
492 if (digits
== NULL
) {
496 status
= alloc_set_client_dirinfo_path(handle
, dip
,
497 &dip
->clientSubDirname
,
503 status
= alloc_get_client_path(handle
, dip
, fname
,
505 if (status
!= 0 || dip
->clientPath
== NULL
) {
510 DEBUG(10, ("Leaving with (*dirInfo)->dirpath '%s', "
511 "(*dirInfo)->clientPath '%s'\n",
512 dip
->dirpath
, dip
->clientPath
));
516 DEBUG(1, ("Failing with fname '%s'\n", fname
));
517 TALLOC_FREE(*di_result
);
523 /**********************************************************************
525 **********************************************************************/
529 * Failure: set errno, return -1
531 static int um_statvfs(struct vfs_handle_struct
*handle
,
532 const struct smb_filename
*smb_fname
,
533 struct vfs_statvfs_struct
*statbuf
)
536 struct smb_filename
*client_fname
= NULL
;
538 DEBUG(10, ("Entering with path '%s'\n", smb_fname
->base_name
));
540 if (!is_in_media_files(smb_fname
->base_name
)) {
541 return SMB_VFS_NEXT_STATVFS(handle
, smb_fname
, statbuf
);
544 status
= alloc_get_client_smb_fname(handle
,
552 status
= SMB_VFS_NEXT_STATVFS(handle
, client_fname
, statbuf
);
554 TALLOC_FREE(client_fname
);
555 DEBUG(10, ("Leaving with path '%s'\n", smb_fname
->base_name
));
559 static DIR *um_fdopendir(vfs_handle_struct
*handle
,
564 struct um_dirinfo_struct
*dirInfo
= NULL
;
567 DEBUG(10, ("Entering with fsp->fsp_name->base_name '%s'\n",
568 fsp
->fsp_name
->base_name
));
570 dirstream
= SMB_VFS_NEXT_FDOPENDIR(handle
, fsp
, mask
, attr
);
575 if (alloc_set_client_dirinfo(handle
,
576 fsp
->fsp_name
->base_name
,
581 dirInfo
->dirstream
= dirstream
;
583 if (!dirInfo
->isInMediaFiles
) {
585 * FIXME: this is the original code, something must be
586 * missing here, but what? -slow
592 DEBUG(10, ("Leaving with dirInfo->dirpath '%s', "
593 "dirInfo->clientPath '%s', "
594 "fsp->fsp_name->st.st_ex_mtime %s",
597 ctime(&(fsp
->fsp_name
->st
.st_ex_mtime
.tv_sec
))));
598 return (DIR *) dirInfo
;
601 DEBUG(1, ("Failing with fsp->fsp_name->base_name '%s'\n",
602 fsp
->fsp_name
->base_name
));
603 TALLOC_FREE(dirInfo
);
608 * skip own suffixed directory
609 * replace own suffixed directory with non suffixed.
611 * Success: return dirent
612 * End of data: return NULL
613 * Failure: set errno, return NULL
615 static struct dirent
*um_readdir(vfs_handle_struct
*handle
,
617 SMB_STRUCT_STAT
*sbuf
)
619 um_dirinfo_struct
* dirInfo
= (um_dirinfo_struct
*)dirp
;
620 struct dirent
*d
= NULL
;
623 DEBUG(10, ("dirInfo->dirpath '%s', "
624 "dirInfo->clientPath '%s', "
625 "dirInfo->isInMediaFiles '%s', "
626 "dirInfo->clientSubDirname '%s'\n",
629 dirInfo
->isInMediaFiles
? "true" : "false",
630 dirInfo
->clientSubDirname
));
632 if (!dirInfo
->isInMediaFiles
) {
633 return SMB_VFS_NEXT_READDIR(handle
, dirInfo
->dirstream
, sbuf
);
644 d
= SMB_VFS_NEXT_READDIR(handle
, dirInfo
->dirstream
, sbuf
);
650 /* ignore apple double prefix for logic below */
651 if (is_apple_double(d
->d_name
)) {
652 dname
= &d
->d_name
[APPLE_DOUBLE_PREFIX_LEN
];
653 isAppleDouble
= true;
656 isAppleDouble
= false;
659 DEBUG(10, ("dname = '%s'\n", dname
));
661 (void)get_digit_group(dname
, &number
);
662 digits
= talloc_asprintf(talloc_tos(), "%ju", number
);
663 if (digits
== NULL
) {
664 DEBUG(1, ("out of memory"));
667 digits_len
= strlen(digits
);
669 if (alloc_set_client_dirinfo_path(handle
,
671 &((dirInfo
)->clientSubDirname
),
677 * If set to "true", vfs shows digits-only
678 * non-suffixed subdirectories. Normally, such
679 * subdirectories can exists only in non-media
680 * directories, so we set it to "false". Otherwise,
681 * if we have such subdirectories (probably created
682 * over not "unityed" connection), it can be little
685 if (strequal(dname
, digits
)) {
687 } else if (strequal(dname
, dirInfo
->clientSubDirname
)) {
689 * Remove suffix of this client's suffixed
693 d
->d_name
[digits_len
+ APPLE_DOUBLE_PREFIX_LEN
] = '\0';
695 d
->d_name
[digits_len
] = '\0';
697 } else if (strnequal(digits
, dname
, digits_len
)) {
699 * Set to false to see another clients subdirectories
705 DEBUG(10, ("Leaving um_readdir\n"));
708 TALLOC_FREE(dirInfo
);
712 static void um_seekdir(vfs_handle_struct
*handle
,
716 DEBUG(10, ("Entering and leaving um_seekdir\n"));
717 SMB_VFS_NEXT_SEEKDIR(handle
,
718 ((um_dirinfo_struct
*)dirp
)->dirstream
, offset
);
721 static long um_telldir(vfs_handle_struct
*handle
,
724 DEBUG(10, ("Entering and leaving um_telldir\n"));
725 return SMB_VFS_NEXT_TELLDIR(handle
,
726 ((um_dirinfo_struct
*)dirp
)->dirstream
);
729 static void um_rewinddir(vfs_handle_struct
*handle
,
732 DEBUG(10, ("Entering and leaving um_rewinddir\n"));
733 SMB_VFS_NEXT_REWINDDIR(handle
,
734 ((um_dirinfo_struct
*)dirp
)->dirstream
);
737 static int um_mkdirat(vfs_handle_struct
*handle
,
738 struct files_struct
*dirfsp
,
739 const struct smb_filename
*smb_fname
,
743 const char *path
= smb_fname
->base_name
;
744 struct smb_filename
*client_fname
= NULL
;
746 DEBUG(10, ("Entering with path '%s'\n", path
));
748 if (!is_in_media_files(path
) || !is_in_media_dir(path
)) {
749 return SMB_VFS_NEXT_MKDIRAT(handle
,
755 status
= alloc_get_client_smb_fname(handle
,
763 status
= SMB_VFS_NEXT_MKDIRAT(handle
,
768 TALLOC_FREE(client_fname
);
769 DEBUG(10, ("Leaving with path '%s'\n", path
));
773 static int um_closedir(vfs_handle_struct
*handle
,
776 DIR *realdirp
= ((um_dirinfo_struct
*)dirp
)->dirstream
;
780 return SMB_VFS_NEXT_CLOSEDIR(handle
, realdirp
);
783 static int um_open(vfs_handle_struct
*handle
,
784 struct smb_filename
*smb_fname
,
790 struct smb_filename
*client_fname
= NULL
;
792 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
793 smb_fname
->base_name
));
795 if (!is_in_media_files(smb_fname
->base_name
)) {
796 return SMB_VFS_NEXT_OPEN(handle
, smb_fname
, fsp
, flags
, mode
);
799 if (alloc_get_client_smb_fname(handle
, talloc_tos(),
808 * What about fsp->fsp_name? We also have to get correct stat
809 * info into fsp and smb_fname for DB files, don't we?
812 DEBUG(10, ("Leaving with smb_fname->base_name '%s' "
813 "smb_fname->st.st_ex_mtime %s"
814 "fsp->fsp_name->st.st_ex_mtime %s",
815 smb_fname
->base_name
,
816 ctime(&(smb_fname
->st
.st_ex_mtime
.tv_sec
)),
817 ctime(&(fsp
->fsp_name
->st
.st_ex_mtime
.tv_sec
))));
819 ret
= SMB_VFS_NEXT_OPEN(handle
, client_fname
, fsp
, flags
, mode
);
821 TALLOC_FREE(client_fname
);
822 DEBUG(10, ("Leaving with smb_fname->base_name '%s'\n",
823 smb_fname
->base_name
));
827 static NTSTATUS
um_create_file(vfs_handle_struct
*handle
,
828 struct smb_request
*req
,
829 struct smb_filename
*smb_fname
,
830 uint32_t access_mask
,
831 uint32_t share_access
,
832 uint32_t create_disposition
,
833 uint32_t create_options
,
834 uint32_t file_attributes
,
835 uint32_t oplock_request
,
836 const struct smb2_lease
*lease
,
837 uint64_t allocation_size
,
838 uint32_t private_flags
,
839 struct security_descriptor
*sd
,
840 struct ea_list
*ea_list
,
841 files_struct
**result_fsp
,
843 const struct smb2_create_blobs
*in_context_blobs
,
844 struct smb2_create_blobs
*out_context_blobs
)
847 struct smb_filename
*client_fname
= NULL
;
849 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
850 smb_fname
->base_name
));
852 if (!is_in_media_files(smb_fname
->base_name
)) {
853 return SMB_VFS_NEXT_CREATE_FILE(
874 if (alloc_get_client_smb_fname(handle
, talloc_tos(),
877 status
= map_nt_error_from_unix(errno
);
883 * This only creates files, so we don't have to worry about
884 * our fake directory stat'ing here. But we still need to
885 * route stat calls for DB files properly, right?
887 status
= SMB_VFS_NEXT_CREATE_FILE(
907 TALLOC_FREE(client_fname
);
908 DEBUG(10, ("Leaving with smb_fname->base_name '%s'"
909 "smb_fname->st.st_ex_mtime %s"
910 " fsp->fsp_name->st.st_ex_mtime %s",
911 smb_fname
->base_name
,
912 ctime(&(smb_fname
->st
.st_ex_mtime
.tv_sec
)),
913 (*result_fsp
) && VALID_STAT((*result_fsp
)->fsp_name
->st
) ?
914 ctime(&((*result_fsp
)->fsp_name
->st
.st_ex_mtime
.tv_sec
)) :
919 static int um_renameat(vfs_handle_struct
*handle
,
920 files_struct
*srcfsp
,
921 const struct smb_filename
*smb_fname_src
,
922 files_struct
*dstfsp
,
923 const struct smb_filename
*smb_fname_dst
)
926 struct smb_filename
*src_client_fname
= NULL
;
927 struct smb_filename
*dst_client_fname
= NULL
;
929 DEBUG(10, ("Entering with "
930 "smb_fname_src->base_name '%s', "
931 "smb_fname_dst->base_name '%s'\n",
932 smb_fname_src
->base_name
,
933 smb_fname_dst
->base_name
));
935 if (!is_in_media_files(smb_fname_src
->base_name
)
937 !is_in_media_files(smb_fname_dst
->base_name
)) {
938 return SMB_VFS_NEXT_RENAMEAT(handle
,
945 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
952 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
960 status
= SMB_VFS_NEXT_RENAMEAT(handle
,
967 TALLOC_FREE(dst_client_fname
);
968 TALLOC_FREE(src_client_fname
);
969 DEBUG(10, ("Leaving with smb_fname_src->base_name '%s',"
970 " smb_fname_dst->base_name '%s'\n",
971 smb_fname_src
->base_name
,
972 smb_fname_dst
->base_name
));
979 * Failure: set errno, return -1
981 static int um_stat(vfs_handle_struct
*handle
,
982 struct smb_filename
*smb_fname
)
985 struct smb_filename
*client_fname
= NULL
;
987 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
988 smb_fname
->base_name
));
990 if (!is_in_media_files(smb_fname
->base_name
)) {
991 return SMB_VFS_NEXT_STAT(handle
, smb_fname
);
994 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1000 DEBUG(10, ("Stat'ing client_fname->base_name '%s'\n",
1001 client_fname
->base_name
));
1003 status
= SMB_VFS_NEXT_STAT(handle
, client_fname
);
1009 * Unlike functions with const smb_filename, we have to modify
1010 * smb_fname itself to pass our info back up.
1012 DEBUG(10, ("Setting smb_fname '%s' stat from client_fname '%s'\n",
1013 smb_fname
->base_name
, client_fname
->base_name
));
1014 smb_fname
->st
= client_fname
->st
;
1017 TALLOC_FREE(client_fname
);
1018 DEBUG(10, ("Leaving with smb_fname->st.st_ex_mtime %s",
1019 ctime(&(smb_fname
->st
.st_ex_mtime
.tv_sec
))));
1023 static int um_lstat(vfs_handle_struct
*handle
,
1024 struct smb_filename
*smb_fname
)
1027 struct smb_filename
*client_fname
= NULL
;
1029 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
1030 smb_fname
->base_name
));
1032 if (!is_in_media_files(smb_fname
->base_name
)) {
1033 return SMB_VFS_NEXT_LSTAT(handle
, smb_fname
);
1036 client_fname
= NULL
;
1038 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1044 status
= SMB_VFS_NEXT_LSTAT(handle
, client_fname
);
1049 smb_fname
->st
= client_fname
->st
;
1052 TALLOC_FREE(client_fname
);
1053 DEBUG(10, ("Leaving with smb_fname->st.st_ex_mtime %s",
1054 ctime(&(smb_fname
->st
.st_ex_mtime
.tv_sec
))));
1058 static int um_fstat(vfs_handle_struct
*handle
,
1059 files_struct
*fsp
, SMB_STRUCT_STAT
*sbuf
)
1063 DEBUG(10, ("Entering with fsp->fsp_name->base_name "
1064 "'%s'\n", fsp_str_dbg(fsp
)));
1066 status
= SMB_VFS_NEXT_FSTAT(handle
, fsp
, sbuf
);
1071 if ((fsp
->fsp_name
== NULL
) ||
1072 !is_in_media_files(fsp
->fsp_name
->base_name
)) {
1076 status
= um_stat(handle
, fsp
->fsp_name
);
1081 *sbuf
= fsp
->fsp_name
->st
;
1084 DEBUG(10, ("Leaving with fsp->fsp_name->st.st_ex_mtime %s\n",
1085 fsp
->fsp_name
!= NULL
?
1086 ctime(&(fsp
->fsp_name
->st
.st_ex_mtime
.tv_sec
)) : "0"));
1090 static int um_unlinkat(vfs_handle_struct
*handle
,
1091 struct files_struct
*dirfsp
,
1092 const struct smb_filename
*smb_fname
,
1096 struct smb_filename
*client_fname
= NULL
;
1098 DEBUG(10, ("Entering um_unlinkat\n"));
1100 if (!is_in_media_files(smb_fname
->base_name
)) {
1101 return SMB_VFS_NEXT_UNLINKAT(handle
,
1107 ret
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1114 ret
= SMB_VFS_NEXT_UNLINKAT(handle
,
1120 TALLOC_FREE(client_fname
);
1124 static int um_chmod(vfs_handle_struct
*handle
,
1125 const struct smb_filename
*smb_fname
,
1129 struct smb_filename
*client_fname
= NULL
;
1131 DEBUG(10, ("Entering um_chmod\n"));
1133 if (!is_in_media_files(smb_fname
->base_name
)) {
1134 return SMB_VFS_NEXT_CHMOD(handle
, smb_fname
, mode
);
1137 status
= alloc_get_client_smb_fname(handle
,
1145 status
= SMB_VFS_NEXT_CHMOD(handle
, client_fname
, mode
);
1148 TALLOC_FREE(client_fname
);
1152 static int um_lchown(vfs_handle_struct
*handle
,
1153 const struct smb_filename
*smb_fname
,
1158 struct smb_filename
*client_fname
= NULL
;
1160 DEBUG(10, ("Entering um_lchown\n"));
1161 if (!is_in_media_files(smb_fname
->base_name
)) {
1162 return SMB_VFS_NEXT_LCHOWN(handle
, smb_fname
, uid
, gid
);
1165 status
= alloc_get_client_smb_fname(handle
,
1173 status
= SMB_VFS_NEXT_LCHOWN(handle
, client_fname
, uid
, gid
);
1176 TALLOC_FREE(client_fname
);
1180 static int um_chdir(vfs_handle_struct
*handle
,
1181 const struct smb_filename
*smb_fname
)
1184 struct smb_filename
*client_fname
= NULL
;
1186 DEBUG(10, ("Entering um_chdir\n"));
1188 if (!is_in_media_files(smb_fname
->base_name
)) {
1189 return SMB_VFS_NEXT_CHDIR(handle
, smb_fname
);
1192 status
= alloc_get_client_smb_fname(handle
,
1200 status
= SMB_VFS_NEXT_CHDIR(handle
, client_fname
);
1203 TALLOC_FREE(client_fname
);
1207 static int um_ntimes(vfs_handle_struct
*handle
,
1208 const struct smb_filename
*smb_fname
,
1209 struct smb_file_time
*ft
)
1212 struct smb_filename
*client_fname
= NULL
;
1214 DEBUG(10, ("Entering um_ntimes\n"));
1216 if (!is_in_media_files(smb_fname
->base_name
)) {
1217 return SMB_VFS_NEXT_NTIMES(handle
, smb_fname
, ft
);
1220 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1221 smb_fname
, &client_fname
);
1226 status
= SMB_VFS_NEXT_NTIMES(handle
, client_fname
, ft
);
1229 TALLOC_FREE(client_fname
);
1233 static int um_symlinkat(vfs_handle_struct
*handle
,
1234 const struct smb_filename
*link_contents
,
1235 struct files_struct
*dirfsp
,
1236 const struct smb_filename
*new_smb_fname
)
1239 struct smb_filename
*new_link_target
= NULL
;
1240 struct smb_filename
*new_client_fname
= NULL
;
1242 DEBUG(10, ("Entering um_symlinkat\n"));
1244 if (!is_in_media_files(link_contents
->base_name
) &&
1245 !is_in_media_files(new_smb_fname
->base_name
)) {
1246 return SMB_VFS_NEXT_SYMLINKAT(handle
,
1252 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1253 link_contents
, &new_link_target
);
1257 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1258 new_smb_fname
, &new_client_fname
);
1263 status
= SMB_VFS_NEXT_SYMLINKAT(handle
,
1269 TALLOC_FREE(new_link_target
);
1270 TALLOC_FREE(new_client_fname
);
1274 static int um_readlinkat(vfs_handle_struct
*handle
,
1275 files_struct
*dirfsp
,
1276 const struct smb_filename
*smb_fname
,
1281 struct smb_filename
*client_fname
= NULL
;
1283 DEBUG(10, ("Entering um_readlinkat\n"));
1285 if (!is_in_media_files(smb_fname
->base_name
)) {
1286 return SMB_VFS_NEXT_READLINKAT(handle
,
1293 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1294 smb_fname
, &client_fname
);
1299 status
= SMB_VFS_NEXT_READLINKAT(handle
,
1306 TALLOC_FREE(client_fname
);
1310 static int um_linkat(vfs_handle_struct
*handle
,
1311 files_struct
*srcfsp
,
1312 const struct smb_filename
*old_smb_fname
,
1313 files_struct
*dstfsp
,
1314 const struct smb_filename
*new_smb_fname
,
1318 struct smb_filename
*old_client_fname
= NULL
;
1319 struct smb_filename
*new_client_fname
= NULL
;
1321 DEBUG(10, ("Entering um_linkat\n"));
1322 if (!is_in_media_files(old_smb_fname
->base_name
) &&
1323 !is_in_media_files(new_smb_fname
->base_name
)) {
1324 return SMB_VFS_NEXT_LINKAT(handle
,
1332 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1333 old_smb_fname
, &old_client_fname
);
1337 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1338 new_smb_fname
, &new_client_fname
);
1343 status
= SMB_VFS_NEXT_LINKAT(handle
,
1351 TALLOC_FREE(old_client_fname
);
1352 TALLOC_FREE(new_client_fname
);
1356 static int um_mknodat(vfs_handle_struct
*handle
,
1357 files_struct
*dirfsp
,
1358 const struct smb_filename
*smb_fname
,
1363 struct smb_filename
*client_fname
= NULL
;
1365 DEBUG(10, ("Entering um_mknodat\n"));
1366 if (!is_in_media_files(smb_fname
->base_name
)) {
1367 return SMB_VFS_NEXT_MKNODAT(handle
,
1374 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1375 smb_fname
, &client_fname
);
1380 status
= SMB_VFS_NEXT_MKNODAT(handle
,
1387 TALLOC_FREE(client_fname
);
1391 static struct smb_filename
*um_realpath(vfs_handle_struct
*handle
,
1393 const struct smb_filename
*smb_fname
)
1395 struct smb_filename
*client_fname
= NULL
;
1396 struct smb_filename
*result_fname
= NULL
;
1399 DEBUG(10, ("Entering um_realpath\n"));
1401 if (!is_in_media_files(smb_fname
->base_name
)) {
1402 return SMB_VFS_NEXT_REALPATH(handle
, ctx
, smb_fname
);
1405 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1406 smb_fname
, &client_fname
);
1411 result_fname
= SMB_VFS_NEXT_REALPATH(handle
, ctx
, client_fname
);
1414 TALLOC_FREE(client_fname
);
1415 return result_fname
;
1418 static int um_chflags(vfs_handle_struct
*handle
,
1419 const struct smb_filename
*smb_fname
,
1423 struct smb_filename
*client_fname
= NULL
;
1425 DEBUG(10, ("Entering um_mknod\n"));
1426 if (!is_in_media_files(smb_fname
->base_name
)) {
1427 return SMB_VFS_NEXT_CHFLAGS(handle
, smb_fname
, flags
);
1430 status
= alloc_get_client_smb_fname(handle
, talloc_tos(),
1431 smb_fname
, &client_fname
);
1436 status
= SMB_VFS_NEXT_CHFLAGS(handle
, client_fname
, flags
);
1439 TALLOC_FREE(client_fname
);
1443 static NTSTATUS
um_streaminfo(struct vfs_handle_struct
*handle
,
1444 struct files_struct
*fsp
,
1445 const struct smb_filename
*smb_fname
,
1447 unsigned int *num_streams
,
1448 struct stream_struct
**streams
)
1452 struct smb_filename
*client_fname
= NULL
;
1454 DEBUG(10, ("Entering um_streaminfo\n"));
1456 if (!is_in_media_files(smb_fname
->base_name
)) {
1457 return SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, smb_fname
,
1458 ctx
, num_streams
, streams
);
1461 ret
= alloc_get_client_smb_fname(handle
,
1466 status
= NT_STATUS_NO_MEMORY
;
1471 * This only works on files, so we don't have to worry about
1472 * our fake directory stat'ing here. But what does this
1473 * function do, exactly? Does it need extra modifications for
1476 status
= SMB_VFS_NEXT_STREAMINFO(handle
, fsp
, client_fname
,
1477 ctx
, num_streams
, streams
);
1479 TALLOC_FREE(client_fname
);
1484 * Ignoring get_real_filename function because the default doesn't do
1488 static NTSTATUS
um_get_nt_acl_at(vfs_handle_struct
*handle
,
1489 struct files_struct
*dirfsp
,
1490 const struct smb_filename
*smb_fname
,
1491 uint32_t security_info
,
1492 TALLOC_CTX
*mem_ctx
,
1493 struct security_descriptor
**ppdesc
)
1496 char *client_path
= NULL
;
1497 struct smb_filename
*client_smb_fname
= NULL
;
1501 DBG_DEBUG("Entering um_get_nt_acl_at\n");
1503 ok
= is_in_media_files(smb_fname
->base_name
);
1505 return SMB_VFS_NEXT_GET_NT_ACL_AT(handle
,
1513 ret
= alloc_get_client_path(handle
,
1515 smb_fname
->base_name
,
1518 status
= map_nt_error_from_unix(errno
);
1522 client_smb_fname
= synthetic_smb_fname(talloc_tos(),
1528 if (client_smb_fname
== NULL
) {
1529 TALLOC_FREE(client_path
);
1530 return NT_STATUS_NO_MEMORY
;
1533 status
= SMB_VFS_NEXT_GET_NT_ACL_AT(handle
,
1540 TALLOC_FREE(client_smb_fname
);
1541 TALLOC_FREE(client_path
);
1545 static SMB_ACL_T
um_sys_acl_get_file(vfs_handle_struct
*handle
,
1546 const struct smb_filename
*smb_fname
,
1547 SMB_ACL_TYPE_T type
,
1548 TALLOC_CTX
*mem_ctx
)
1551 int saved_errno
= 0;
1552 struct smb_filename
*client_fname
= NULL
;
1555 DEBUG(10, ("Entering um_sys_acl_get_file\n"));
1557 if (!is_in_media_files(smb_fname
->base_name
)) {
1558 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, smb_fname
,
1562 status
= alloc_get_client_smb_fname(handle
,
1567 ret
= (SMB_ACL_T
)NULL
;
1571 ret
= SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle
, client_fname
,
1575 if (ret
== (SMB_ACL_T
)NULL
) {
1576 saved_errno
= errno
;
1578 TALLOC_FREE(client_fname
);
1579 if (saved_errno
!= 0) {
1580 errno
= saved_errno
;
1585 static int um_sys_acl_set_file(vfs_handle_struct
*handle
,
1586 const struct smb_filename
*smb_fname
,
1587 SMB_ACL_TYPE_T acltype
,
1591 int saved_errno
= 0;
1592 struct smb_filename
*client_fname
= NULL
;
1594 DEBUG(10, ("Entering um_sys_acl_set_file\n"));
1596 if (!is_in_media_files(smb_fname
->base_name
)) {
1597 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, smb_fname
,
1601 status
= alloc_get_client_smb_fname(handle
,
1609 status
= SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle
, client_fname
,
1614 saved_errno
= errno
;
1616 TALLOC_FREE(client_fname
);
1617 if (saved_errno
!= 0) {
1618 errno
= saved_errno
;
1623 static int um_sys_acl_delete_def_file(vfs_handle_struct
*handle
,
1624 const struct smb_filename
*smb_fname
)
1627 int saved_errno
= 0;
1628 struct smb_filename
*client_fname
= NULL
;
1630 DEBUG(10, ("Entering um_sys_acl_delete_def_file\n"));
1632 if (!is_in_media_files(smb_fname
->base_name
)) {
1633 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
,
1637 status
= alloc_get_client_smb_fname(handle
,
1645 status
= SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle
, client_fname
);
1649 saved_errno
= errno
;
1651 TALLOC_FREE(client_fname
);
1652 if (saved_errno
!= 0) {
1653 errno
= saved_errno
;
1658 static ssize_t
um_getxattr(struct vfs_handle_struct
*handle
,
1659 const struct smb_filename
*smb_fname
,
1665 struct smb_filename
*client_fname
= NULL
;
1668 DEBUG(10, ("Entering um_getxattr\n"));
1669 if (!is_in_media_files(smb_fname
->base_name
)) {
1670 return SMB_VFS_NEXT_GETXATTR(handle
, smb_fname
,
1674 status
= alloc_get_client_smb_fname(handle
,
1683 ret
= SMB_VFS_NEXT_GETXATTR(handle
, client_fname
, name
, value
, size
);
1685 TALLOC_FREE(client_fname
);
1689 static ssize_t
um_listxattr(struct vfs_handle_struct
*handle
,
1690 const struct smb_filename
*smb_fname
,
1695 struct smb_filename
*client_fname
= NULL
;
1698 DEBUG(10, ("Entering um_listxattr\n"));
1700 if (!is_in_media_files(smb_fname
->base_name
)) {
1701 return SMB_VFS_NEXT_LISTXATTR(handle
, smb_fname
, list
, size
);
1704 status
= alloc_get_client_smb_fname(handle
,
1713 ret
= SMB_VFS_NEXT_LISTXATTR(handle
, client_fname
, list
, size
);
1716 TALLOC_FREE(client_fname
);
1720 static int um_removexattr(struct vfs_handle_struct
*handle
,
1721 const struct smb_filename
*smb_fname
,
1725 struct smb_filename
*client_fname
= NULL
;
1727 DEBUG(10, ("Entering um_removexattr\n"));
1729 if (!is_in_media_files(smb_fname
->base_name
)) {
1730 return SMB_VFS_NEXT_REMOVEXATTR(handle
, smb_fname
, name
);
1733 status
= alloc_get_client_smb_fname(handle
,
1741 status
= SMB_VFS_NEXT_REMOVEXATTR(handle
, client_fname
, name
);
1744 TALLOC_FREE(client_fname
);
1748 static int um_setxattr(struct vfs_handle_struct
*handle
,
1749 const struct smb_filename
*smb_fname
,
1756 struct smb_filename
*client_fname
= NULL
;
1758 DEBUG(10, ("Entering um_setxattr\n"));
1760 if (!is_in_media_files(smb_fname
->base_name
)) {
1761 return SMB_VFS_NEXT_SETXATTR(handle
, smb_fname
, name
, value
,
1765 status
= alloc_get_client_smb_fname(handle
,
1773 status
= SMB_VFS_NEXT_SETXATTR(handle
, client_fname
, name
, value
,
1777 TALLOC_FREE(client_fname
);
1781 static int um_connect(vfs_handle_struct
*handle
,
1782 const char *service
,
1786 struct um_config_data
*config
;
1789 rc
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
1794 config
= talloc_zero(handle
->conn
, struct um_config_data
);
1796 DEBUG(1, ("talloc_zero() failed\n"));
1801 enumval
= lp_parm_enum(SNUM(handle
->conn
), UM_PARAM_TYPE_NAME
,
1802 "clientid", um_clientid
, UM_CLIENTID_NAME
);
1803 if (enumval
== -1) {
1804 DEBUG(1, ("value for %s: type unknown\n",
1805 UM_PARAM_TYPE_NAME
));
1808 config
->clientid
= (enum um_clientid
)enumval
;
1810 SMB_VFS_HANDLE_SET_DATA(handle
, config
,
1811 NULL
, struct um_config_data
,
1817 /* VFS operations structure */
1819 static struct vfs_fn_pointers vfs_um_fns
= {
1820 .connect_fn
= um_connect
,
1822 /* Disk operations */
1824 .statvfs_fn
= um_statvfs
,
1826 /* Directory operations */
1828 .fdopendir_fn
= um_fdopendir
,
1829 .readdir_fn
= um_readdir
,
1830 .seekdir_fn
= um_seekdir
,
1831 .telldir_fn
= um_telldir
,
1832 .rewind_dir_fn
= um_rewinddir
,
1833 .mkdirat_fn
= um_mkdirat
,
1834 .closedir_fn
= um_closedir
,
1836 /* File operations */
1839 .create_file_fn
= um_create_file
,
1840 .renameat_fn
= um_renameat
,
1842 .lstat_fn
= um_lstat
,
1843 .fstat_fn
= um_fstat
,
1844 .unlinkat_fn
= um_unlinkat
,
1845 .chmod_fn
= um_chmod
,
1846 .lchown_fn
= um_lchown
,
1847 .chdir_fn
= um_chdir
,
1848 .ntimes_fn
= um_ntimes
,
1849 .symlinkat_fn
= um_symlinkat
,
1850 .readlinkat_fn
= um_readlinkat
,
1851 .linkat_fn
= um_linkat
,
1852 .mknodat_fn
= um_mknodat
,
1853 .realpath_fn
= um_realpath
,
1854 .chflags_fn
= um_chflags
,
1855 .streaminfo_fn
= um_streaminfo
,
1857 /* NT ACL operations. */
1859 .get_nt_acl_at_fn
= um_get_nt_acl_at
,
1861 /* POSIX ACL operations. */
1863 .sys_acl_get_file_fn
= um_sys_acl_get_file
,
1864 .sys_acl_set_file_fn
= um_sys_acl_set_file
,
1865 .sys_acl_delete_def_file_fn
= um_sys_acl_delete_def_file
,
1867 /* EA operations. */
1868 .getxattr_fn
= um_getxattr
,
1869 .getxattrat_send_fn
= vfs_not_implemented_getxattrat_send
,
1870 .getxattrat_recv_fn
= vfs_not_implemented_getxattrat_recv
,
1871 .listxattr_fn
= um_listxattr
,
1872 .removexattr_fn
= um_removexattr
,
1873 .setxattr_fn
= um_setxattr
,
1877 NTSTATUS
vfs_unityed_media_init(TALLOC_CTX
*ctx
)
1879 NTSTATUS ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
,
1880 "unityed_media", &vfs_um_fns
);
1881 if (!NT_STATUS_IS_OK(ret
)) {
1885 vfs_um_debug_level
= debug_add_class("unityed_media");
1887 if (vfs_um_debug_level
== -1) {
1888 vfs_um_debug_level
= DBGC_VFS
;
1889 DEBUG(1, ("unityed_media_init: Couldn't register custom "
1890 "debugging class.\n"));