s4:selftest: explicitly set NSS/RESOLV_WAPPER_* in wait_for_start
[Samba.git] / source3 / modules / vfs_unityed_media.c
blob9859037722e4218aec899ff779bac1b0a09700c3
1 /*
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
22 * 02110-1301, USA.
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
30 * configuration.
31 * eg.
33 * [avid_win]
34 * path = /video
35 * vfs objects = unityed_media
36 * ...
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
47 * the list.
49 * Notes:
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
53 * general use.
57 #include "includes.h"
58 #include "system/filesys.h"
59 #include "smbd/smbd.h"
60 #include "../smbd/globals.h"
61 #include "auth.h"
62 #include "../lib/tsocket/tsocket.h"
63 #include <libgen.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"},
85 {-1, NULL}
88 /* supplements the directory list stream */
89 typedef struct um_dirinfo_struct {
90 DIR* dirstream;
91 char *dirpath;
92 char *clientPath;
93 bool isInMediaFiles;
94 char *clientSubDirname;
95 } um_dirinfo_struct;
97 /**
98 * Returns true and first group of digits in path, false and 0 otherwise
99 **/
100 static bool get_digit_group(const char *path, uintmax_t *digit)
102 const char *p = path;
103 char *endp = NULL;
104 codepoint_t cp;
105 size_t size;
107 DEBUG(10, ("get_digit_group entering with path '%s'\n",
108 path));
111 * Delibiretly initialize to 0 because callers use this result
112 * even though the string doesn't contain any number and we
113 * returned false
115 *digit = 0;
117 while (*p) {
118 cp = next_codepoint(p, &size);
119 if (cp == -1) {
120 return false;
122 if ((size == 1) && (isdigit(cp))) {
123 *digit = (uintmax_t)strtoul(p, &endp, 10);
124 DEBUG(10, ("num_suffix = '%ju'\n",
125 *digit));
126 return true;
128 p += size;
131 return false;
134 /* Add "_<remote_name>.<number>" suffix to path or filename.
136 * Success: return 0
137 * Failure: set errno, path NULL, return -1
140 static int alloc_append_client_suffix(vfs_handle_struct *handle,
141 char **path)
143 int status = 0;
144 uintmax_t number;
145 const char *clientid;
146 struct um_config_data *config;
148 DEBUG(10, ("Entering with path '%s'\n", *path));
150 SMB_VFS_HANDLE_GET_DATA(handle, config,
151 struct um_config_data,
152 return -1);
154 (void)get_digit_group(*path, &number);
156 switch (config->clientid) {
158 case UM_CLIENTID_IP:
159 clientid = tsocket_address_inet_addr_string(
160 handle->conn->sconn->remote_address, talloc_tos());
161 if (clientid == NULL) {
162 errno = ENOMEM;
163 status = -1;
164 goto err;
166 break;
168 case UM_CLIENTID_HOSTNAME:
169 clientid = get_remote_machine_name();
170 break;
172 case UM_CLIENTID_NAME:
173 default:
174 clientid = get_current_username();
175 break;
178 *path = talloc_asprintf_append(*path, "_%s.%ju",
179 clientid, number);
180 if (*path == NULL) {
181 DEBUG(1, ("alloc_append_client_suffix "
182 "out of memory\n"));
183 errno = ENOMEM;
184 status = -1;
185 goto err;
187 DEBUG(10, ("Leaving with *path '%s'\n", *path));
188 err:
189 return status;
192 /* Returns true if the file or directory begins with the appledouble
193 * prefix.
195 static bool is_apple_double(const char* fname)
197 bool ret = false;
199 DEBUG(10, ("Entering with fname '%s'\n", fname));
201 if (strnequal(APPLE_DOUBLE_PREFIX, fname, APPLE_DOUBLE_PREFIX_LEN)) {
202 ret = true;
204 DEBUG(10, ("Leaving with ret '%s'\n",
205 ret == true ? "true" : "false"));
206 return ret;
209 static bool starts_with_media_dir(const char* media_dirname,
210 size_t media_dirname_len,
211 const char *path)
213 bool ret = false;
214 const char *path_start = path;
216 DEBUG(10, ("Entering with media_dirname '%s' "
217 "path '%s'\n", media_dirname, path));
219 /* Sometimes Samba gives us "./OMFI MediaFiles". */
220 if (strnequal(path, "./", 2)) {
221 path_start += 2;
224 if (strnequal(media_dirname, path_start, media_dirname_len)
226 ((path_start[media_dirname_len] == '\0') ||
227 (path_start[media_dirname_len] == '/'))) {
228 ret = true;
231 DEBUG(10, ("Leaving with ret '%s'\n",
232 ret == true ? "true" : "false"));
233 return ret;
237 * Returns true if the file or directory referenced by the path is ONE
238 * LEVEL below the AVID_MXF_DIRNAME or OMFI_MEDIAFILES_DIRNAME
239 * directory
241 static bool is_in_media_dir(const char *path)
243 int transition_count = 0;
244 const char *path_start = path;
245 const char *p;
246 const char *media_dirname;
247 size_t media_dirname_len;
249 DEBUG(10, ("Entering with path'%s' ", path));
251 /* Sometimes Samba gives us "./OMFI MediaFiles". */
252 if (strnequal(path, "./", 2)) {
253 path_start += 2;
256 if (strnequal(path_start, AVID_MXF_DIRNAME, AVID_MXF_DIRNAME_LEN)) {
257 media_dirname = AVID_MXF_DIRNAME;
258 media_dirname_len = AVID_MXF_DIRNAME_LEN;
259 } else if (strnequal(path_start,
260 OMFI_MEDIAFILES_DIRNAME,
261 OMFI_MEDIAFILES_DIRNAME_LEN)) {
262 media_dirname = OMFI_MEDIAFILES_DIRNAME;
263 media_dirname_len = OMFI_MEDIAFILES_DIRNAME_LEN;
264 } else {
265 return false;
268 if (path_start[media_dirname_len] == '\0') {
269 goto out;
272 p = path_start + media_dirname_len + 1;
274 while (true) {
275 if (*p == '\0' || *p == '/') {
276 if (strnequal(p - 3, "/..", 3)) {
277 transition_count--;
278 } else if ((p[-1] != '/') || !strnequal(p - 2, "/.", 2)) {
279 transition_count++;
282 if (*p == '\0') {
283 break;
285 p++;
288 out:
289 DEBUG(10, ("Going out with transition_count '%i'\n",
290 transition_count));
291 if (((transition_count == 1) && (media_dirname == AVID_MXF_DIRNAME))
293 ((transition_count == 0) && (media_dirname == OMFI_MEDIAFILES_DIRNAME))) {
294 return true;
296 else return false;
300 * Returns true if the file or directory referenced by the path is
301 * below the AVID_MEDIAFILES_DIRNAME or OMFI_MEDIAFILES_DIRNAME
302 * directory The AVID_MEDIAFILES_DIRNAME and OMFI_MEDIAFILES_DIRNAME
303 * are assumed to be in the root directory, which is generally a safe
304 * assumption in the fixed-path world of Avid.
306 static bool is_in_media_files(const char *path)
308 bool ret = false;
310 DEBUG(10, ("Entering with path '%s'\n", path));
312 if (starts_with_media_dir(AVID_MXF_DIRNAME,
313 AVID_MXF_DIRNAME_LEN, path) ||
314 starts_with_media_dir(OMFI_MEDIAFILES_DIRNAME,
315 OMFI_MEDIAFILES_DIRNAME_LEN, path)) {
316 ret = true;
318 DEBUG(10, ("Leaving with ret '%s'\n",
319 ret == true ? "true" : "false"));
320 return ret;
324 /* Add client suffix to "pure-number" path.
326 * Caller must free newPath.
328 * Success: return 0
329 * Failure: set errno, newPath NULL, return -1
331 static int alloc_get_client_path(vfs_handle_struct *handle,
332 TALLOC_CTX *ctx,
333 const char *path_in,
334 char **path_out)
336 int status = 0;
337 char *p;
338 char *digits;
339 size_t digits_len;
340 uintmax_t number;
342 *path_out = talloc_strdup(ctx, path_in);
343 if (*path_out == NULL) {
344 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
345 return -1;
348 (void)get_digit_group(*path_out, &number);
350 digits = talloc_asprintf(NULL, "%ju", number);
351 if (digits == NULL) {
352 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
353 return -1;
355 digits_len = strlen(digits);
357 p = strstr_m(path_in, digits);
358 if ((p)
360 ((p[digits_len] == '\0') || (p[digits_len] == '/'))
362 (((p - path_in > 0) && (p[-1] == '/'))
364 (((p - path_in) > APPLE_DOUBLE_PREFIX_LEN)
366 is_apple_double(p - APPLE_DOUBLE_PREFIX_LEN)
368 (p[-(APPLE_DOUBLE_PREFIX_LEN + 1)] == '/'))))
370 (*path_out)[p - path_in + digits_len] = '\0';
372 status = alloc_append_client_suffix(handle, path_out);
373 if (status != 0) {
374 goto out;
377 *path_out = talloc_strdup_append(*path_out, p + digits_len);
378 if (*path_out == NULL) {
379 DEBUG(1, ("alloc_get_client_path ENOMEM\n"));
380 status = -1;
381 goto out;
384 out:
385 /* path_out must be freed in caller. */
386 DEBUG(10, ("Result:'%s'\n", *path_out));
387 return status;
391 * Success: return 0
392 * Failure: set errno, return -1
394 static int alloc_get_client_smb_fname(struct vfs_handle_struct *handle,
395 TALLOC_CTX *ctx,
396 const struct smb_filename *smb_fname,
397 struct smb_filename **client_fname)
399 int status ;
401 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
402 smb_fname->base_name));
404 *client_fname = cp_smb_filename(ctx, smb_fname);
405 if (*client_fname == NULL) {
406 DEBUG(1, ("cp_smb_filename returned NULL\n"));
407 return -1;
409 status = alloc_get_client_path(handle, ctx,
410 smb_fname->base_name,
411 &(*client_fname)->base_name);
412 if (status != 0) {
413 return -1;
416 DEBUG(10, ("Leaving with (*client_fname)->base_name "
417 "'%s'\n", (*client_fname)->base_name));
419 return 0;
424 * Success: return 0
425 * Failure: set errno, return -1
427 static int alloc_set_client_dirinfo_path(struct vfs_handle_struct *handle,
428 TALLOC_CTX *ctx,
429 char **path,
430 const char *suffix_number)
432 int status;
434 DEBUG(10, ("Entering with suffix_number '%s'\n",
435 suffix_number));
437 *path = talloc_strdup(ctx, suffix_number);
438 if (*path == NULL) {
439 DEBUG(1, ("alloc_set_client_dirinfo_path ENOMEM\n"));
440 return -1;
442 status = alloc_append_client_suffix(handle, path);
443 if (status != 0) {
444 return -1;
447 DEBUG(10, ("Leaving with *path '%s'\n", *path));
449 return 0;
452 static int alloc_set_client_dirinfo(vfs_handle_struct *handle,
453 const char *fname,
454 struct um_dirinfo_struct **di_result)
456 int status = 0;
457 char *digits;
458 uintmax_t number;
459 struct um_dirinfo_struct *dip;
461 DEBUG(10, ("Entering with fname '%s'\n", fname));
463 *di_result = talloc(NULL, struct um_dirinfo_struct);
464 if (*di_result == NULL) {
465 goto err;
467 dip = *di_result;
469 dip->dirpath = talloc_strdup(dip, fname);
470 if (dip->dirpath == NULL) {
471 goto err;
474 if (!is_in_media_files(fname)) {
475 dip->isInMediaFiles = false;
476 dip->clientPath = NULL;
477 dip->clientSubDirname = NULL;
478 goto out;
481 dip->isInMediaFiles = true;
483 (void)get_digit_group(fname, &number);
484 digits = talloc_asprintf(talloc_tos(), "%ju", number);
485 if (digits == NULL) {
486 goto err;
489 status = alloc_set_client_dirinfo_path(handle, dip,
490 &dip->clientSubDirname,
491 digits);
492 if (status != 0) {
493 goto err;
496 status = alloc_get_client_path(handle, dip, fname,
497 &dip->clientPath);
498 if (status != 0 || dip->clientPath == NULL) {
499 goto err;
502 out:
503 DEBUG(10, ("Leaving with (*dirInfo)->dirpath '%s', "
504 "(*dirInfo)->clientPath '%s'\n",
505 dip->dirpath, dip->clientPath));
506 return status;
508 err:
509 DEBUG(1, ("Failing with fname '%s'\n", fname));
510 TALLOC_FREE(*di_result);
511 status = -1;
512 errno = ENOMEM;
513 return status;
516 /**********************************************************************
517 * VFS functions
518 **********************************************************************/
521 * Success: return 0
522 * Failure: set errno, return -1
524 static int um_statvfs(struct vfs_handle_struct *handle,
525 const struct smb_filename *smb_fname,
526 struct vfs_statvfs_struct *statbuf)
528 int status;
529 struct smb_filename *client_fname = NULL;
531 DEBUG(10, ("Entering with path '%s'\n", smb_fname->base_name));
533 if (!is_in_media_files(smb_fname->base_name)) {
534 return SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
537 status = alloc_get_client_smb_fname(handle,
538 talloc_tos(),
539 smb_fname,
540 &client_fname);
541 if (status != 0) {
542 goto err;
545 status = SMB_VFS_NEXT_STATVFS(handle, client_fname, statbuf);
546 err:
547 TALLOC_FREE(client_fname);
548 DEBUG(10, ("Leaving with path '%s'\n", smb_fname->base_name));
549 return status;
552 /* Success: return a um_dirinfo_struct cast as a DIR
553 * Failure: set errno, return NULL
555 static DIR *um_opendir(vfs_handle_struct *handle,
556 const struct smb_filename *smb_fname,
557 const char *mask,
558 uint32_t attr)
560 struct um_dirinfo_struct *dirInfo;
562 DEBUG(10, ("Entering with fname '%s'\n", smb_fname->base_name));
564 if (alloc_set_client_dirinfo(handle, smb_fname->base_name, &dirInfo)) {
565 goto err;
568 if (!dirInfo->isInMediaFiles) {
569 dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(
570 handle, smb_fname, mask, attr);
571 } else {
572 struct smb_filename *client_smb_fname =
573 synthetic_smb_fname(talloc_tos(),
574 dirInfo->clientPath,
575 NULL,
576 NULL,
577 smb_fname->flags);
578 if (client_smb_fname == NULL) {
579 goto err;
582 dirInfo->dirstream = SMB_VFS_NEXT_OPENDIR(
583 handle, client_smb_fname, mask, attr);
585 TALLOC_FREE(client_smb_fname);
588 if (dirInfo->dirstream == NULL) {
589 goto err;
592 DEBUG(10, ("Leaving with dirInfo->dirpath '%s', "
593 "dirInfo->clientPath '%s'\n",
594 dirInfo->dirpath,
595 dirInfo->clientPath));
596 return (DIR*)dirInfo;
598 err:
599 DEBUG(1, ("Failing with fname '%s'\n", smb_fname->base_name));
600 TALLOC_FREE(dirInfo);
601 return NULL;
604 static DIR *um_fdopendir(vfs_handle_struct *handle,
605 files_struct *fsp,
606 const char *mask,
607 uint32_t attr)
609 struct um_dirinfo_struct *dirInfo = NULL;
610 DIR *dirstream;
612 DEBUG(10, ("Entering with fsp->fsp_name->base_name '%s'\n",
613 fsp->fsp_name->base_name));
615 dirstream = SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
616 if (!dirstream) {
617 goto err;
620 if (alloc_set_client_dirinfo(handle,
621 fsp->fsp_name->base_name,
622 &dirInfo)) {
623 goto err;
626 dirInfo->dirstream = dirstream;
628 if (!dirInfo->isInMediaFiles) {
630 * FIXME: this is the original code, something must be
631 * missing here, but what? -slow
633 goto out;
636 out:
637 DEBUG(10, ("Leaving with dirInfo->dirpath '%s', "
638 "dirInfo->clientPath '%s', "
639 "fsp->fsp_name->st.st_ex_mtime %s",
640 dirInfo->dirpath,
641 dirInfo->clientPath,
642 ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
643 return (DIR *) dirInfo;
645 err:
646 DEBUG(1, ("Failing with fsp->fsp_name->base_name '%s'\n",
647 fsp->fsp_name->base_name));
648 TALLOC_FREE(dirInfo);
649 return NULL;
653 * skip own suffixed directory
654 * replace own suffixed directory with non suffixed.
656 * Success: return dirent
657 * End of data: return NULL
658 * Failure: set errno, return NULL
660 static struct dirent *um_readdir(vfs_handle_struct *handle,
661 DIR *dirp,
662 SMB_STRUCT_STAT *sbuf)
664 um_dirinfo_struct* dirInfo = (um_dirinfo_struct*)dirp;
665 struct dirent *d = NULL;
666 int skip;
668 DEBUG(10, ("dirInfo->dirpath '%s', "
669 "dirInfo->clientPath '%s', "
670 "dirInfo->isInMediaFiles '%s', "
671 "dirInfo->clientSubDirname '%s'\n",
672 dirInfo->dirpath,
673 dirInfo->clientPath,
674 dirInfo->isInMediaFiles ? "true" : "false",
675 dirInfo->clientSubDirname));
677 if (!dirInfo->isInMediaFiles) {
678 return SMB_VFS_NEXT_READDIR(handle, dirInfo->dirstream, sbuf);
681 do {
682 const char* dname;
683 bool isAppleDouble;
684 char *digits;
685 size_t digits_len;
686 uintmax_t number;
688 skip = false;
689 d = SMB_VFS_NEXT_READDIR(handle, dirInfo->dirstream, sbuf);
691 if (d == NULL) {
692 break;
695 /* ignore apple double prefix for logic below */
696 if (is_apple_double(d->d_name)) {
697 dname = &d->d_name[APPLE_DOUBLE_PREFIX_LEN];
698 isAppleDouble = true;
699 } else {
700 dname = d->d_name;
701 isAppleDouble = false;
704 DEBUG(10, ("dname = '%s'\n", dname));
706 (void)get_digit_group(dname, &number);
707 digits = talloc_asprintf(talloc_tos(), "%ju", number);
708 if (digits == NULL) {
709 DEBUG(1, ("out of memory"));
710 goto err;
712 digits_len = strlen(digits);
714 if (alloc_set_client_dirinfo_path(handle,
715 dirInfo,
716 &((dirInfo)->clientSubDirname),
717 digits)) {
718 goto err;
722 * If set to "true", vfs shows digits-only
723 * non-suffixed subdirectories. Normally, such
724 * subdirectories can exists only in non-media
725 * directories, so we set it to "false". Otherwise,
726 * if we have such subdirectories (probably created
727 * over not "unityed" connection), it can be little
728 * bit confusing.
730 if (strequal(dname, digits)) {
731 skip = false;
732 } else if (strequal(dname, dirInfo->clientSubDirname)) {
734 * Remove suffix of this client's suffixed
735 * subdirectories
737 if (isAppleDouble) {
738 d->d_name[digits_len + APPLE_DOUBLE_PREFIX_LEN] = '\0';
739 } else {
740 d->d_name[digits_len] = '\0';
742 } else if (strnequal(digits, dname, digits_len)) {
744 * Set to false to see another clients subdirectories
746 skip = false;
748 } while (skip);
750 DEBUG(10, ("Leaving um_readdir\n"));
751 return d;
752 err:
753 TALLOC_FREE(dirInfo);
754 return NULL;
757 static void um_seekdir(vfs_handle_struct *handle,
758 DIR *dirp,
759 long offset)
761 DEBUG(10, ("Entering and leaving um_seekdir\n"));
762 SMB_VFS_NEXT_SEEKDIR(handle,
763 ((um_dirinfo_struct*)dirp)->dirstream, offset);
766 static long um_telldir(vfs_handle_struct *handle,
767 DIR *dirp)
769 DEBUG(10, ("Entering and leaving um_telldir\n"));
770 return SMB_VFS_NEXT_TELLDIR(handle,
771 ((um_dirinfo_struct*)dirp)->dirstream);
774 static void um_rewinddir(vfs_handle_struct *handle,
775 DIR *dirp)
777 DEBUG(10, ("Entering and leaving um_rewinddir\n"));
778 SMB_VFS_NEXT_REWINDDIR(handle,
779 ((um_dirinfo_struct*)dirp)->dirstream);
782 static int um_mkdir(vfs_handle_struct *handle,
783 const struct smb_filename *smb_fname,
784 mode_t mode)
786 int status;
787 const char *path = smb_fname->base_name;
788 struct smb_filename *client_fname = NULL;
790 DEBUG(10, ("Entering with path '%s'\n", path));
792 if (!is_in_media_files(path) || !is_in_media_dir(path)) {
793 return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
796 status = alloc_get_client_smb_fname(handle,
797 talloc_tos(),
798 smb_fname,
799 &client_fname);
800 if (status != 0) {
801 goto err;
804 status = SMB_VFS_NEXT_MKDIR(handle, client_fname, mode);
805 err:
806 TALLOC_FREE(client_fname);
807 DEBUG(10, ("Leaving with path '%s'\n", path));
808 return status;
811 static int um_rmdir(vfs_handle_struct *handle,
812 const struct smb_filename *smb_fname)
814 int status;
815 const char *path = smb_fname->base_name;
816 struct smb_filename *client_fname = NULL;
818 DEBUG(10, ("Entering with path '%s'\n", path));
820 if (!is_in_media_files(path)) {
821 return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
824 status = alloc_get_client_smb_fname(handle,
825 talloc_tos(),
826 smb_fname,
827 &client_fname);
828 if (status != 0) {
829 goto err;
832 status = SMB_VFS_NEXT_RMDIR(handle, client_fname);
833 err:
834 TALLOC_FREE(client_fname);
835 DEBUG(10, ("Leaving with path '%s'\n", path));
836 return status;
839 static int um_closedir(vfs_handle_struct *handle,
840 DIR *dirp)
842 DIR *realdirp = ((um_dirinfo_struct*)dirp)->dirstream;
844 TALLOC_FREE(dirp);
846 return SMB_VFS_NEXT_CLOSEDIR(handle, realdirp);
849 static int um_open(vfs_handle_struct *handle,
850 struct smb_filename *smb_fname,
851 files_struct *fsp,
852 int flags,
853 mode_t mode)
855 int ret;
856 struct smb_filename *client_fname = NULL;
858 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
859 smb_fname->base_name));
861 if (!is_in_media_files(smb_fname->base_name)) {
862 return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
865 if (alloc_get_client_smb_fname(handle, talloc_tos(),
866 smb_fname,
867 &client_fname)) {
868 ret = -1;
869 goto err;
873 * FIXME:
874 * What about fsp->fsp_name? We also have to get correct stat
875 * info into fsp and smb_fname for DB files, don't we?
878 DEBUG(10, ("Leaving with smb_fname->base_name '%s' "
879 "smb_fname->st.st_ex_mtime %s"
880 "fsp->fsp_name->st.st_ex_mtime %s",
881 smb_fname->base_name,
882 ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
883 ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec))));
885 ret = SMB_VFS_NEXT_OPEN(handle, client_fname, fsp, flags, mode);
886 err:
887 TALLOC_FREE(client_fname);
888 DEBUG(10, ("Leaving with smb_fname->base_name '%s'\n",
889 smb_fname->base_name));
890 return ret;
893 static NTSTATUS um_create_file(vfs_handle_struct *handle,
894 struct smb_request *req,
895 uint16_t root_dir_fid,
896 struct smb_filename *smb_fname,
897 uint32_t access_mask,
898 uint32_t share_access,
899 uint32_t create_disposition,
900 uint32_t create_options,
901 uint32_t file_attributes,
902 uint32_t oplock_request,
903 struct smb2_lease *lease,
904 uint64_t allocation_size,
905 uint32_t private_flags,
906 struct security_descriptor *sd,
907 struct ea_list *ea_list,
908 files_struct **result_fsp,
909 int *pinfo,
910 const struct smb2_create_blobs *in_context_blobs,
911 struct smb2_create_blobs *out_context_blobs)
913 NTSTATUS status;
914 struct smb_filename *client_fname = NULL;
916 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
917 smb_fname->base_name));
919 if (!is_in_media_files(smb_fname->base_name)) {
920 return SMB_VFS_NEXT_CREATE_FILE(
921 handle,
922 req,
923 root_dir_fid,
924 smb_fname,
925 access_mask,
926 share_access,
927 create_disposition,
928 create_options,
929 file_attributes,
930 oplock_request,
931 lease,
932 allocation_size,
933 private_flags,
935 ea_list,
936 result_fsp,
937 pinfo,
938 in_context_blobs,
939 out_context_blobs);
942 if (alloc_get_client_smb_fname(handle, talloc_tos(),
943 smb_fname,
944 &client_fname)) {
945 status = map_nt_error_from_unix(errno);
946 goto err;
950 * FIXME:
951 * This only creates files, so we don't have to worry about
952 * our fake directory stat'ing here. But we still need to
953 * route stat calls for DB files properly, right?
955 status = SMB_VFS_NEXT_CREATE_FILE(
956 handle,
957 req,
958 root_dir_fid,
959 client_fname,
960 access_mask,
961 share_access,
962 create_disposition,
963 create_options,
964 file_attributes,
965 oplock_request,
966 lease,
967 allocation_size,
968 private_flags,
970 ea_list,
971 result_fsp,
972 pinfo,
973 in_context_blobs,
974 out_context_blobs);
975 err:
976 TALLOC_FREE(client_fname);
977 DEBUG(10, ("Leaving with smb_fname->base_name '%s'"
978 "smb_fname->st.st_ex_mtime %s"
979 " fsp->fsp_name->st.st_ex_mtime %s",
980 smb_fname->base_name,
981 ctime(&(smb_fname->st.st_ex_mtime.tv_sec)),
982 (*result_fsp) && VALID_STAT((*result_fsp)->fsp_name->st) ?
983 ctime(&((*result_fsp)->fsp_name->st.st_ex_mtime.tv_sec)) :
984 "No fsp time\n"));
985 return status;
988 static int um_rename(vfs_handle_struct *handle,
989 const struct smb_filename *smb_fname_src,
990 const struct smb_filename *smb_fname_dst)
992 int status;
993 struct smb_filename *src_client_fname = NULL;
994 struct smb_filename *dst_client_fname = NULL;
996 DEBUG(10, ("Entering with "
997 "smb_fname_src->base_name '%s', "
998 "smb_fname_dst->base_name '%s'\n",
999 smb_fname_src->base_name,
1000 smb_fname_dst->base_name));
1002 if (!is_in_media_files(smb_fname_src->base_name)
1004 !is_in_media_files(smb_fname_dst->base_name)) {
1005 return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
1006 smb_fname_dst);
1009 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1010 smb_fname_src,
1011 &src_client_fname);
1012 if (status != 0) {
1013 goto err;
1016 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1017 smb_fname_dst,
1018 &dst_client_fname);
1020 if (status != 0) {
1021 goto err;
1024 status = SMB_VFS_NEXT_RENAME(handle, src_client_fname,
1025 dst_client_fname);
1026 err:
1027 TALLOC_FREE(dst_client_fname);
1028 TALLOC_FREE(src_client_fname);
1029 DEBUG(10, ("Leaving with smb_fname_src->base_name '%s',"
1030 " smb_fname_dst->base_name '%s'\n",
1031 smb_fname_src->base_name,
1032 smb_fname_dst->base_name));
1033 return status;
1037 * Success: return 0
1038 * Failure: set errno, return -1
1040 static int um_stat(vfs_handle_struct *handle,
1041 struct smb_filename *smb_fname)
1043 int status = 0;
1044 struct smb_filename *client_fname = NULL;
1046 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
1047 smb_fname->base_name));
1049 if (!is_in_media_files(smb_fname->base_name)) {
1050 return SMB_VFS_NEXT_STAT(handle, smb_fname);
1053 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1054 smb_fname,
1055 &client_fname);
1056 if (status != 0) {
1057 goto err;
1059 DEBUG(10, ("Stat'ing client_fname->base_name '%s'\n",
1060 client_fname->base_name));
1062 status = SMB_VFS_NEXT_STAT(handle, client_fname);
1063 if (status != 0) {
1064 goto err;
1068 * Unlike functions with const smb_filename, we have to modify
1069 * smb_fname itself to pass our info back up.
1071 DEBUG(10, ("Setting smb_fname '%s' stat from client_fname '%s'\n",
1072 smb_fname->base_name, client_fname->base_name));
1073 smb_fname->st = client_fname->st;
1075 err:
1076 TALLOC_FREE(client_fname);
1077 DEBUG(10, ("Leaving with smb_fname->st.st_ex_mtime %s",
1078 ctime(&(smb_fname->st.st_ex_mtime.tv_sec))));
1079 return status;
1082 static int um_lstat(vfs_handle_struct *handle,
1083 struct smb_filename *smb_fname)
1085 int status = 0;
1086 struct smb_filename *client_fname = NULL;
1088 DEBUG(10, ("Entering with smb_fname->base_name '%s'\n",
1089 smb_fname->base_name));
1091 if (!is_in_media_files(smb_fname->base_name)) {
1092 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
1095 client_fname = NULL;
1097 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1098 smb_fname,
1099 &client_fname);
1100 if (status != 0) {
1101 goto err;
1103 status = SMB_VFS_NEXT_LSTAT(handle, client_fname);
1104 if (status != 0) {
1105 goto err;
1108 smb_fname->st = client_fname->st;
1110 err:
1111 TALLOC_FREE(client_fname);
1112 DEBUG(10, ("Leaving with smb_fname->st.st_ex_mtime %s",
1113 ctime(&(smb_fname->st.st_ex_mtime.tv_sec))));
1114 return status;
1117 static int um_fstat(vfs_handle_struct *handle,
1118 files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1120 int status = 0;
1122 DEBUG(10, ("Entering with fsp->fsp_name->base_name "
1123 "'%s'\n", fsp_str_dbg(fsp)));
1125 status = SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
1126 if (status != 0) {
1127 goto out;
1130 if ((fsp->fsp_name == NULL) ||
1131 !is_in_media_files(fsp->fsp_name->base_name)) {
1132 goto out;
1135 status = um_stat(handle, fsp->fsp_name);
1136 if (status != 0) {
1137 goto out;
1140 *sbuf = fsp->fsp_name->st;
1142 out:
1143 DEBUG(10, ("Leaving with fsp->fsp_name->st.st_ex_mtime %s\n",
1144 fsp->fsp_name != NULL ?
1145 ctime(&(fsp->fsp_name->st.st_ex_mtime.tv_sec)) : "0"));
1146 return status;
1149 static int um_unlink(vfs_handle_struct *handle,
1150 const struct smb_filename *smb_fname)
1152 int status;
1153 struct smb_filename *client_fname = NULL;
1155 DEBUG(10, ("Entering um_unlink\n"));
1157 if (!is_in_media_files(smb_fname->base_name)) {
1158 return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
1161 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1162 smb_fname,
1163 &client_fname);
1164 if (status != 0) {
1165 goto err;
1168 status = SMB_VFS_NEXT_UNLINK(handle, client_fname);
1170 err:
1171 TALLOC_FREE(client_fname);
1172 return status;
1175 static int um_chmod(vfs_handle_struct *handle,
1176 const struct smb_filename *smb_fname,
1177 mode_t mode)
1179 int status;
1180 struct smb_filename *client_fname = NULL;
1182 DEBUG(10, ("Entering um_chmod\n"));
1184 if (!is_in_media_files(smb_fname->base_name)) {
1185 return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
1188 status = alloc_get_client_smb_fname(handle,
1189 talloc_tos(),
1190 smb_fname,
1191 &client_fname);
1192 if (status != 0) {
1193 goto err;
1196 status = SMB_VFS_NEXT_CHMOD(handle, client_fname, mode);
1198 err:
1199 TALLOC_FREE(client_fname);
1200 return status;
1203 static int um_chown(vfs_handle_struct *handle,
1204 const struct smb_filename *smb_fname,
1205 uid_t uid,
1206 gid_t gid)
1208 int status;
1209 struct smb_filename *client_fname = NULL;
1211 DEBUG(10, ("Entering um_chown\n"));
1213 if (!is_in_media_files(smb_fname->base_name)) {
1214 return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
1217 status = alloc_get_client_smb_fname(handle,
1218 talloc_tos(),
1219 smb_fname,
1220 &client_fname);
1221 if (status != 0) {
1222 goto err;
1225 status = SMB_VFS_NEXT_CHOWN(handle, client_fname, uid, gid);
1227 err:
1228 TALLOC_FREE(client_fname);
1229 return status;
1232 static int um_lchown(vfs_handle_struct *handle,
1233 const struct smb_filename *smb_fname,
1234 uid_t uid,
1235 gid_t gid)
1237 int status;
1238 struct smb_filename *client_fname = NULL;
1240 DEBUG(10, ("Entering um_lchown\n"));
1241 if (!is_in_media_files(smb_fname->base_name)) {
1242 return SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
1245 status = alloc_get_client_smb_fname(handle,
1246 talloc_tos(),
1247 smb_fname,
1248 &client_fname);
1249 if (status != 0) {
1250 goto err;
1253 status = SMB_VFS_NEXT_LCHOWN(handle, client_fname, uid, gid);
1255 err:
1256 TALLOC_FREE(client_fname);
1257 return status;
1260 static int um_chdir(vfs_handle_struct *handle,
1261 const struct smb_filename *smb_fname)
1263 int status;
1264 struct smb_filename *client_fname = NULL;
1266 DEBUG(10, ("Entering um_chdir\n"));
1268 if (!is_in_media_files(smb_fname->base_name)) {
1269 return SMB_VFS_NEXT_CHDIR(handle, smb_fname);
1272 status = alloc_get_client_smb_fname(handle,
1273 talloc_tos(),
1274 smb_fname,
1275 &client_fname);
1276 if (status != 0) {
1277 goto err;
1280 status = SMB_VFS_NEXT_CHDIR(handle, client_fname);
1282 err:
1283 TALLOC_FREE(client_fname);
1284 return status;
1287 static int um_ntimes(vfs_handle_struct *handle,
1288 const struct smb_filename *smb_fname,
1289 struct smb_file_time *ft)
1291 int status;
1292 struct smb_filename *client_fname = NULL;
1294 DEBUG(10, ("Entering um_ntimes\n"));
1296 if (!is_in_media_files(smb_fname->base_name)) {
1297 return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
1300 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1301 smb_fname, &client_fname);
1302 if (status != 0) {
1303 goto err;
1306 status = SMB_VFS_NEXT_NTIMES(handle, client_fname, ft);
1308 err:
1309 TALLOC_FREE(client_fname);
1310 return status;
1313 static int um_symlink(vfs_handle_struct *handle,
1314 const char *link_contents,
1315 const struct smb_filename *new_smb_fname)
1317 int status;
1318 char *client_link_contents = NULL;
1319 struct smb_filename *new_client_fname = NULL;
1321 DEBUG(10, ("Entering um_symlink\n"));
1323 if (!is_in_media_files(link_contents) &&
1324 !is_in_media_files(new_smb_fname->base_name)) {
1325 return SMB_VFS_NEXT_SYMLINK(handle,
1326 link_contents,
1327 new_smb_fname);
1330 status = alloc_get_client_path(handle, talloc_tos(),
1331 link_contents, &client_link_contents);
1332 if (status != 0) {
1333 goto err;
1335 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1336 new_smb_fname, &new_client_fname);
1337 if (status != 0) {
1338 goto err;
1341 status = SMB_VFS_NEXT_SYMLINK(handle,
1342 client_link_contents,
1343 new_client_fname);
1345 err:
1346 TALLOC_FREE(client_link_contents);
1347 TALLOC_FREE(new_client_fname);
1348 return status;
1351 static int um_readlink(vfs_handle_struct *handle,
1352 const struct smb_filename *smb_fname,
1353 char *buf,
1354 size_t bufsiz)
1356 int status;
1357 struct smb_filename *client_fname = NULL;
1359 DEBUG(10, ("Entering um_readlink\n"));
1361 if (!is_in_media_files(smb_fname->base_name)) {
1362 return SMB_VFS_NEXT_READLINK(handle, smb_fname,
1363 buf, bufsiz);
1366 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1367 smb_fname, &client_fname);
1368 if (status != 0) {
1369 goto err;
1372 status = SMB_VFS_NEXT_READLINK(handle, client_fname, buf, bufsiz);
1374 err:
1375 TALLOC_FREE(client_fname);
1376 return status;
1379 static int um_link(vfs_handle_struct *handle,
1380 const struct smb_filename *old_smb_fname,
1381 const struct smb_filename *new_smb_fname)
1383 int status;
1384 struct smb_filename *old_client_fname = NULL;
1385 struct smb_filename *new_client_fname = NULL;
1387 DEBUG(10, ("Entering um_link\n"));
1388 if (!is_in_media_files(old_smb_fname->base_name) &&
1389 !is_in_media_files(new_smb_fname->base_name)) {
1390 return SMB_VFS_NEXT_LINK(handle, old_smb_fname, new_smb_fname);
1393 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1394 old_smb_fname, &old_client_fname);
1395 if (status != 0) {
1396 goto err;
1398 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1399 new_smb_fname, &new_client_fname);
1400 if (status != 0) {
1401 goto err;
1404 status = SMB_VFS_NEXT_LINK(handle, old_client_fname, new_client_fname);
1406 err:
1407 TALLOC_FREE(old_client_fname);
1408 TALLOC_FREE(new_client_fname);
1409 return status;
1412 static int um_mknod(vfs_handle_struct *handle,
1413 const struct smb_filename *smb_fname,
1414 mode_t mode,
1415 SMB_DEV_T dev)
1417 int status;
1418 struct smb_filename *client_fname = NULL;
1420 DEBUG(10, ("Entering um_mknod\n"));
1421 if (!is_in_media_files(smb_fname->base_name)) {
1422 return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
1425 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1426 smb_fname, &client_fname);
1427 if (status != 0) {
1428 goto err;
1431 status = SMB_VFS_NEXT_MKNOD(handle, client_fname, mode, dev);
1433 err:
1434 TALLOC_FREE(client_fname);
1435 return status;
1438 static struct smb_filename *um_realpath(vfs_handle_struct *handle,
1439 TALLOC_CTX *ctx,
1440 const struct smb_filename *smb_fname)
1442 struct smb_filename *client_fname = NULL;
1443 struct smb_filename *result_fname = NULL;
1444 int status;
1446 DEBUG(10, ("Entering um_realpath\n"));
1448 if (!is_in_media_files(smb_fname->base_name)) {
1449 return SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
1452 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1453 smb_fname, &client_fname);
1454 if (status != 0) {
1455 goto err;
1458 result_fname = SMB_VFS_NEXT_REALPATH(handle, ctx, client_fname);
1460 err:
1461 TALLOC_FREE(client_fname);
1462 return result_fname;
1465 static int um_chflags(vfs_handle_struct *handle,
1466 const struct smb_filename *smb_fname,
1467 unsigned int flags)
1469 int status;
1470 struct smb_filename *client_fname = NULL;
1472 DEBUG(10, ("Entering um_mknod\n"));
1473 if (!is_in_media_files(smb_fname->base_name)) {
1474 return SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
1477 status = alloc_get_client_smb_fname(handle, talloc_tos(),
1478 smb_fname, &client_fname);
1479 if (status != 0) {
1480 goto err;
1483 status = SMB_VFS_NEXT_CHFLAGS(handle, client_fname, flags);
1485 err:
1486 TALLOC_FREE(client_fname);
1487 return status;
1490 static NTSTATUS um_streaminfo(struct vfs_handle_struct *handle,
1491 struct files_struct *fsp,
1492 const struct smb_filename *smb_fname,
1493 TALLOC_CTX *ctx,
1494 unsigned int *num_streams,
1495 struct stream_struct **streams)
1497 NTSTATUS status;
1498 int ret;
1499 struct smb_filename *client_fname = NULL;
1501 DEBUG(10, ("Entering um_streaminfo\n"));
1503 if (!is_in_media_files(smb_fname->base_name)) {
1504 return SMB_VFS_NEXT_STREAMINFO(handle, fsp, smb_fname,
1505 ctx, num_streams, streams);
1508 ret = alloc_get_client_smb_fname(handle,
1509 talloc_tos(),
1510 smb_fname,
1511 &client_fname);
1512 if (ret != 0) {
1513 status = NT_STATUS_NO_MEMORY;
1514 goto err;
1518 * This only works on files, so we don't have to worry about
1519 * our fake directory stat'ing here. But what does this
1520 * function do, exactly? Does it need extra modifications for
1521 * the Avid stuff?
1523 status = SMB_VFS_NEXT_STREAMINFO(handle, fsp, client_fname,
1524 ctx, num_streams, streams);
1525 err:
1526 TALLOC_FREE(client_fname);
1527 return status;
1531 * Ignoring get_real_filename function because the default doesn't do
1532 * anything.
1535 static NTSTATUS um_get_nt_acl(vfs_handle_struct *handle,
1536 const struct smb_filename *smb_fname,
1537 uint32_t security_info,
1538 TALLOC_CTX *mem_ctx,
1539 struct security_descriptor **ppdesc)
1541 NTSTATUS status;
1542 char *client_path = NULL;
1543 struct smb_filename *client_smb_fname = NULL;
1544 int ret;
1546 DEBUG(10, ("Entering um_get_nt_acl\n"));
1548 if (!is_in_media_files(smb_fname->base_name)) {
1549 return SMB_VFS_NEXT_GET_NT_ACL(handle, smb_fname,
1550 security_info,
1551 mem_ctx, ppdesc);
1554 ret = alloc_get_client_path(handle, talloc_tos(),
1555 smb_fname->base_name, &client_path);
1556 if (ret != 0) {
1557 status = map_nt_error_from_unix(errno);
1558 goto err;
1561 client_smb_fname = synthetic_smb_fname(talloc_tos(),
1562 client_path,
1563 NULL,
1564 NULL,
1565 smb_fname->flags);
1566 if (client_smb_fname == NULL) {
1567 TALLOC_FREE(client_path);
1568 return NT_STATUS_NO_MEMORY;
1571 status = SMB_VFS_NEXT_GET_NT_ACL(handle, client_smb_fname,
1572 security_info,
1573 mem_ctx, ppdesc);
1574 err:
1575 TALLOC_FREE(client_smb_fname);
1576 TALLOC_FREE(client_path);
1577 return status;
1580 static int um_chmod_acl(vfs_handle_struct *handle,
1581 const struct smb_filename *smb_fname,
1582 mode_t mode)
1584 int status;
1585 int saved_errno;
1586 struct smb_filename *client_fname = NULL;
1588 DEBUG(10, ("Entering um_chmod_acl\n"));
1590 if (!is_in_media_files(smb_fname->base_name)) {
1591 return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
1594 status = alloc_get_client_smb_fname(handle,
1595 talloc_tos(),
1596 smb_fname,
1597 &client_fname);
1598 if (status != 0) {
1599 goto err;
1601 status = SMB_VFS_NEXT_CHMOD_ACL(handle, client_fname, mode);
1603 err:
1604 saved_errno = errno;
1605 TALLOC_FREE(client_fname);
1606 errno = saved_errno;
1607 return status;
1610 static SMB_ACL_T um_sys_acl_get_file(vfs_handle_struct *handle,
1611 const struct smb_filename *smb_fname,
1612 SMB_ACL_TYPE_T type,
1613 TALLOC_CTX *mem_ctx)
1615 SMB_ACL_T ret;
1616 int saved_errno = 0;
1617 struct smb_filename *client_fname = NULL;
1618 int status;
1620 DEBUG(10, ("Entering um_sys_acl_get_file\n"));
1622 if (!is_in_media_files(smb_fname->base_name)) {
1623 return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname,
1624 type, mem_ctx);
1627 status = alloc_get_client_smb_fname(handle,
1628 talloc_tos(),
1629 smb_fname,
1630 &client_fname);
1631 if (status != 0) {
1632 ret = (SMB_ACL_T)NULL;
1633 goto err;
1636 ret = SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, client_fname,
1637 type, mem_ctx);
1639 err:
1640 if (ret == (SMB_ACL_T)NULL) {
1641 saved_errno = errno;
1643 TALLOC_FREE(client_fname);
1644 if (saved_errno != 0) {
1645 errno = saved_errno;
1647 return ret;
1650 static int um_sys_acl_set_file(vfs_handle_struct *handle,
1651 const struct smb_filename *smb_fname,
1652 SMB_ACL_TYPE_T acltype,
1653 SMB_ACL_T theacl)
1655 int status;
1656 int saved_errno = 0;
1657 struct smb_filename *client_fname = NULL;
1659 DEBUG(10, ("Entering um_sys_acl_set_file\n"));
1661 if (!is_in_media_files(smb_fname->base_name)) {
1662 return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname,
1663 acltype, theacl);
1666 status = alloc_get_client_smb_fname(handle,
1667 talloc_tos(),
1668 smb_fname,
1669 &client_fname);
1670 if (status != 0) {
1671 goto err;
1674 status = SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, client_fname,
1675 acltype, theacl);
1677 err:
1678 if (status == -1) {
1679 saved_errno = errno;
1681 TALLOC_FREE(client_fname);
1682 if (saved_errno != 0) {
1683 errno = saved_errno;
1685 return status;
1688 static int um_sys_acl_delete_def_file(vfs_handle_struct *handle,
1689 const struct smb_filename *smb_fname)
1691 int status;
1692 int saved_errno = 0;
1693 struct smb_filename *client_fname = NULL;
1695 DEBUG(10, ("Entering um_sys_acl_delete_def_file\n"));
1697 if (!is_in_media_files(smb_fname->base_name)) {
1698 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle,
1699 smb_fname);
1702 status = alloc_get_client_smb_fname(handle,
1703 talloc_tos(),
1704 smb_fname,
1705 &client_fname);
1706 if (status != 0) {
1707 goto err;
1710 status = SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, client_fname);
1712 err:
1713 if (status == -1) {
1714 saved_errno = errno;
1716 TALLOC_FREE(client_fname);
1717 if (saved_errno != 0) {
1718 errno = saved_errno;
1720 return status;
1723 static ssize_t um_getxattr(struct vfs_handle_struct *handle,
1724 const struct smb_filename *smb_fname,
1725 const char *name,
1726 void *value,
1727 size_t size)
1729 ssize_t ret;
1730 struct smb_filename *client_fname = NULL;
1731 int status;
1733 DEBUG(10, ("Entering um_getxattr\n"));
1734 if (!is_in_media_files(smb_fname->base_name)) {
1735 return SMB_VFS_NEXT_GETXATTR(handle, smb_fname,
1736 name, value, size);
1739 status = alloc_get_client_smb_fname(handle,
1740 talloc_tos(),
1741 smb_fname,
1742 &client_fname);
1743 if (status != 0) {
1744 ret = -1;
1745 goto err;
1748 ret = SMB_VFS_NEXT_GETXATTR(handle, client_fname, name, value, size);
1749 err:
1750 TALLOC_FREE(client_fname);
1751 return ret;
1754 static ssize_t um_listxattr(struct vfs_handle_struct *handle,
1755 const struct smb_filename *smb_fname,
1756 char *list,
1757 size_t size)
1759 ssize_t ret;
1760 struct smb_filename *client_fname = NULL;
1761 int status;
1763 DEBUG(10, ("Entering um_listxattr\n"));
1765 if (!is_in_media_files(smb_fname->base_name)) {
1766 return SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
1769 status = alloc_get_client_smb_fname(handle,
1770 talloc_tos(),
1771 smb_fname,
1772 &client_fname);
1773 if (status != 0) {
1774 ret = -1;
1775 goto err;
1778 ret = SMB_VFS_NEXT_LISTXATTR(handle, client_fname, list, size);
1780 err:
1781 TALLOC_FREE(client_fname);
1782 return ret;
1785 static int um_removexattr(struct vfs_handle_struct *handle,
1786 const struct smb_filename *smb_fname,
1787 const char *name)
1789 int status;
1790 struct smb_filename *client_fname = NULL;
1792 DEBUG(10, ("Entering um_removexattr\n"));
1794 if (!is_in_media_files(smb_fname->base_name)) {
1795 return SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
1798 status = alloc_get_client_smb_fname(handle,
1799 talloc_tos(),
1800 smb_fname,
1801 &client_fname);
1802 if (status != 0) {
1803 goto err;
1806 status = SMB_VFS_NEXT_REMOVEXATTR(handle, client_fname, name);
1808 err:
1809 TALLOC_FREE(client_fname);
1810 return status;
1813 static int um_setxattr(struct vfs_handle_struct *handle,
1814 const struct smb_filename *smb_fname,
1815 const char *name,
1816 const void *value,
1817 size_t size,
1818 int flags)
1820 int status;
1821 struct smb_filename *client_fname = NULL;
1823 DEBUG(10, ("Entering um_setxattr\n"));
1825 if (!is_in_media_files(smb_fname->base_name)) {
1826 return SMB_VFS_NEXT_SETXATTR(handle, smb_fname, name, value,
1827 size, flags);
1830 status = alloc_get_client_smb_fname(handle,
1831 talloc_tos(),
1832 smb_fname,
1833 &client_fname);
1834 if (status != 0) {
1835 goto err;
1838 status = SMB_VFS_NEXT_SETXATTR(handle, client_fname, name, value,
1839 size, flags);
1841 err:
1842 TALLOC_FREE(client_fname);
1843 return status;
1846 static int um_connect(vfs_handle_struct *handle,
1847 const char *service,
1848 const char *user)
1850 int rc;
1851 struct um_config_data *config;
1852 int enumval;
1854 rc = SMB_VFS_NEXT_CONNECT(handle, service, user);
1855 if (rc != 0) {
1856 return rc;
1859 config = talloc_zero(handle->conn, struct um_config_data);
1860 if (!config) {
1861 DEBUG(1, ("talloc_zero() failed\n"));
1862 errno = ENOMEM;
1863 return -1;
1866 enumval = lp_parm_enum(SNUM(handle->conn), UM_PARAM_TYPE_NAME,
1867 "clientid", um_clientid, UM_CLIENTID_NAME);
1868 if (enumval == -1) {
1869 DEBUG(1, ("value for %s: type unknown\n",
1870 UM_PARAM_TYPE_NAME));
1871 return -1;
1873 config->clientid = (enum um_clientid)enumval;
1875 SMB_VFS_HANDLE_SET_DATA(handle, config,
1876 NULL, struct um_config_data,
1877 return -1);
1879 return 0;
1882 /* VFS operations structure */
1884 static struct vfs_fn_pointers vfs_um_fns = {
1885 .connect_fn = um_connect,
1887 /* Disk operations */
1889 .statvfs_fn = um_statvfs,
1891 /* Directory operations */
1893 .opendir_fn = um_opendir,
1894 .fdopendir_fn = um_fdopendir,
1895 .readdir_fn = um_readdir,
1896 .seekdir_fn = um_seekdir,
1897 .telldir_fn = um_telldir,
1898 .rewind_dir_fn = um_rewinddir,
1899 .mkdir_fn = um_mkdir,
1900 .rmdir_fn = um_rmdir,
1901 .closedir_fn = um_closedir,
1903 /* File operations */
1905 .open_fn = um_open,
1906 .create_file_fn = um_create_file,
1907 .rename_fn = um_rename,
1908 .stat_fn = um_stat,
1909 .lstat_fn = um_lstat,
1910 .fstat_fn = um_fstat,
1911 .unlink_fn = um_unlink,
1912 .chmod_fn = um_chmod,
1913 .chown_fn = um_chown,
1914 .lchown_fn = um_lchown,
1915 .chdir_fn = um_chdir,
1916 .ntimes_fn = um_ntimes,
1917 .symlink_fn = um_symlink,
1918 .readlink_fn = um_readlink,
1919 .link_fn = um_link,
1920 .mknod_fn = um_mknod,
1921 .realpath_fn = um_realpath,
1922 .chflags_fn = um_chflags,
1923 .streaminfo_fn = um_streaminfo,
1925 /* NT ACL operations. */
1927 .get_nt_acl_fn = um_get_nt_acl,
1929 /* POSIX ACL operations. */
1931 .chmod_acl_fn = um_chmod_acl,
1933 .sys_acl_get_file_fn = um_sys_acl_get_file,
1934 .sys_acl_set_file_fn = um_sys_acl_set_file,
1935 .sys_acl_delete_def_file_fn = um_sys_acl_delete_def_file,
1937 /* EA operations. */
1938 .getxattr_fn = um_getxattr,
1939 .listxattr_fn = um_listxattr,
1940 .removexattr_fn = um_removexattr,
1941 .setxattr_fn = um_setxattr,
1944 static_decl_vfs;
1945 NTSTATUS vfs_unityed_media_init(TALLOC_CTX *ctx)
1947 NTSTATUS ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
1948 "unityed_media", &vfs_um_fns);
1949 if (!NT_STATUS_IS_OK(ret)) {
1950 return ret;
1953 vfs_um_debug_level = debug_add_class("unityed_media");
1955 if (vfs_um_debug_level == -1) {
1956 vfs_um_debug_level = DBGC_VFS;
1957 DEBUG(1, ("unityed_media_init: Couldn't register custom "
1958 "debugging class.\n"));
1961 return ret;