2 Unix SMB/Netbios implementation.
4 VFS initialisation and support functions
5 Copyright (C) Tim Potter 1999
6 Copyright (C) Alexander Bokovoy 2002
7 Copyright (C) James Peach 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (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, see <http://www.gnu.org/licenses/>.
22 This work was sponsored by Optifacio Software Services, Inc.
26 #include "smbd/globals.h"
29 #define DBGC_CLASS DBGC_VFS
33 struct vfs_init_function_entry {
35 const vfs_op_tuple *vfs_op_tuples;
36 struct vfs_init_function_entry *prev, *next;
39 /****************************************************************************
40 maintain the list of available backends
41 ****************************************************************************/
43 static struct vfs_init_function_entry *vfs_find_backend_entry(const char *name)
45 struct vfs_init_function_entry *entry = backends;
47 DEBUG(10, ("vfs_find_backend_entry called for %s\n", name));
50 if (strcmp(entry->name, name)==0) return entry;
57 NTSTATUS smb_register_vfs(int version, const char *name, const vfs_op_tuple *vfs_op_tuples)
59 struct vfs_init_function_entry *entry = backends;
61 if ((version != SMB_VFS_INTERFACE_VERSION)) {
62 DEBUG(0, ("Failed to register vfs module.\n"
63 "The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
64 "current SMB_VFS_INTERFACE_VERSION is %d.\n"
65 "Please recompile against the current Samba Version!\n",
66 version, SMB_VFS_INTERFACE_VERSION));
67 return NT_STATUS_OBJECT_TYPE_MISMATCH;
70 if (!name || !name[0] || !vfs_op_tuples) {
71 DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
72 return NT_STATUS_INVALID_PARAMETER;
75 if (vfs_find_backend_entry(name)) {
76 DEBUG(0,("VFS module %s already loaded!\n", name));
77 return NT_STATUS_OBJECT_NAME_COLLISION;
80 entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
81 entry->name = smb_xstrdup(name);
82 entry->vfs_op_tuples = vfs_op_tuples;
84 DLIST_ADD(backends, entry);
85 DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
89 /****************************************************************************
90 initialise default vfs hooks
91 ****************************************************************************/
93 static void vfs_init_default(connection_struct *conn)
95 DEBUG(3, ("Initialising default vfs hooks\n"));
96 vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
99 /****************************************************************************
100 initialise custom vfs hooks
101 ****************************************************************************/
103 static inline void vfs_set_operation(struct vfs_ops * vfs, vfs_op_type which,
104 struct vfs_handle_struct * handle, void * op)
106 ((struct vfs_handle_struct **)&vfs->handles)[which] = handle;
107 ((void **)(void *)&vfs->ops)[which] = op;
110 bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
112 const vfs_op_tuple *ops;
113 char *module_path = NULL;
114 char *module_name = NULL;
115 char *module_param = NULL, *p;
117 vfs_handle_struct *handle;
118 const struct vfs_init_function_entry *entry;
120 if (!conn||!vfs_object||!vfs_object[0]) {
121 DEBUG(0,("vfs_init_custon() called with NULL pointer or emtpy vfs_object!\n"));
129 DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
131 module_path = smb_xstrdup(vfs_object);
133 p = strchr_m(module_path, ':');
138 trim_char(module_param, ' ', ' ');
141 trim_char(module_path, ' ', ' ');
143 module_name = smb_xstrdup(module_path);
145 if ((module_name[0] == '/') &&
146 (strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
149 * Extract the module name from the path. Just use the base
150 * name of the last path component.
153 SAFE_FREE(module_name);
154 module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
156 p = strchr_m(module_name, '.');
163 /* First, try to load the module with the new module system */
164 entry = vfs_find_backend_entry(module_name);
168 DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
171 status = smb_probe_module("vfs", module_path);
172 if (!NT_STATUS_IS_OK(status)) {
173 DEBUG(0, ("error probing vfs module '%s': %s\n",
174 module_path, nt_errstr(status)));
178 entry = vfs_find_backend_entry(module_name);
180 DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
185 DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
186 if ((ops = entry->vfs_op_tuples) == NULL) {
187 DEBUG(0, ("entry->vfs_op_tuples==NULL for [%s] failed\n", vfs_object));
191 handle = TALLOC_ZERO_P(conn, vfs_handle_struct);
193 DEBUG(0,("TALLOC_ZERO() failed!\n"));
196 memcpy(&handle->vfs_next, &conn->vfs, sizeof(struct vfs_ops));
199 handle->param = talloc_strdup(conn, module_param);
201 DLIST_ADD(conn->vfs_handles, handle);
203 for(i=0; ops[i].op != NULL; i++) {
204 DEBUG(5, ("Checking operation #%d (type %d, layer %d)\n", i, ops[i].type, ops[i].layer));
205 if(ops[i].layer == SMB_VFS_LAYER_OPAQUE) {
206 /* If this operation was already made opaque by different module, it
207 * will be overridden here.
209 DEBUGADD(5, ("Making operation type %d opaque [module %s]\n", ops[i].type, vfs_object));
210 vfs_set_operation(&conn->vfs_opaque, ops[i].type, handle, ops[i].op);
212 /* Change current VFS disposition*/
213 DEBUGADD(5, ("Accepting operation type %d from module %s\n", ops[i].type, vfs_object));
214 vfs_set_operation(&conn->vfs, ops[i].type, handle, ops[i].op);
217 SAFE_FREE(module_path);
218 SAFE_FREE(module_name);
222 SAFE_FREE(module_path);
223 SAFE_FREE(module_name);
227 /*****************************************************************
228 Allow VFS modules to extend files_struct with VFS-specific state.
229 This will be ok for small numbers of extensions, but might need to
230 be refactored if it becomes more widely used.
231 ******************************************************************/
233 #define EXT_DATA_AREA(e) ((uint8 *)(e) + sizeof(struct vfs_fsp_data))
235 void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
236 files_struct *fsp, size_t ext_size,
237 void (*destroy_fn)(void *p_data))
239 struct vfs_fsp_data *ext;
242 /* Prevent VFS modules adding multiple extensions. */
243 if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
247 ext = (struct vfs_fsp_data *)TALLOC_ZERO(
248 handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
254 ext->next = fsp->vfs_extension;
255 ext->destroy = destroy_fn;
256 fsp->vfs_extension = ext;
257 return EXT_DATA_AREA(ext);
260 void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
262 struct vfs_fsp_data *curr;
263 struct vfs_fsp_data *prev;
265 for (curr = fsp->vfs_extension, prev = NULL;
267 prev = curr, curr = curr->next) {
268 if (curr->owner == handle) {
270 prev->next = curr->next;
272 fsp->vfs_extension = curr->next;
275 curr->destroy(EXT_DATA_AREA(curr));
283 void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
285 struct vfs_fsp_data *head;
287 for (head = fsp->vfs_extension; head; head = head->next) {
288 if (head->owner == handle) {
296 void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
298 struct vfs_fsp_data *head;
300 head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
302 return EXT_DATA_AREA(head);
310 /*****************************************************************
312 ******************************************************************/
314 bool smbd_vfs_init(connection_struct *conn)
316 const char **vfs_objects;
320 /* Normal share - initialise with disk access functions */
321 vfs_init_default(conn);
322 vfs_objects = lp_vfs_objects(SNUM(conn));
324 /* Override VFS functions if 'vfs object' was not specified*/
325 if (!vfs_objects || !vfs_objects[0])
328 for (i=0; vfs_objects[i] ;) {
332 for (j=i-1; j >= 0; j--) {
333 if (!vfs_init_custom(conn, vfs_objects[j])) {
334 DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
341 /*******************************************************************
342 Check if a file exists in the vfs.
343 ********************************************************************/
345 NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
347 /* Only return OK if stat was successful and S_ISREG */
348 if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
349 S_ISREG(smb_fname->st.st_ex_mode)) {
353 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
356 /****************************************************************************
357 Read data from fsp on the vfs. (note: EINTR re-read differs from vfs_write_data)
358 ****************************************************************************/
360 ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
364 while (total < byte_count)
366 ssize_t ret = SMB_VFS_READ(fsp, buf + total,
369 if (ret == 0) return total;
378 return (ssize_t)total;
381 ssize_t vfs_pread_data(files_struct *fsp, char *buf,
382 size_t byte_count, SMB_OFF_T offset)
386 while (total < byte_count)
388 ssize_t ret = SMB_VFS_PREAD(fsp, buf + total,
389 byte_count - total, offset + total);
391 if (ret == 0) return total;
400 return (ssize_t)total;
403 /****************************************************************************
404 Write data to a fd on the vfs.
405 ****************************************************************************/
407 ssize_t vfs_write_data(struct smb_request *req,
415 if (req && req->unread_bytes) {
416 SMB_ASSERT(req->unread_bytes == N);
417 /* VFS_RECVFILE must drain the socket
418 * before returning. */
419 req->unread_bytes = 0;
420 return SMB_VFS_RECVFILE(smbd_server_fd(),
427 ret = SMB_VFS_WRITE(fsp, buffer + total, N - total);
436 return (ssize_t)total;
439 ssize_t vfs_pwrite_data(struct smb_request *req,
448 if (req && req->unread_bytes) {
449 SMB_ASSERT(req->unread_bytes == N);
450 /* VFS_RECVFILE must drain the socket
451 * before returning. */
452 req->unread_bytes = 0;
453 return SMB_VFS_RECVFILE(smbd_server_fd(),
460 ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total,
470 return (ssize_t)total;
472 /****************************************************************************
473 An allocate file space call using the vfs interface.
474 Allocates space for a file from a filedescriptor.
475 Returns 0 on success, -1 on failure.
476 ****************************************************************************/
478 int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
482 connection_struct *conn = fsp->conn;
483 uint64_t space_avail;
484 uint64_t bsize,dfree,dsize;
487 * Actually try and commit the space on disk....
490 DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n", fsp->fsp_name, (double)len ));
492 if (((SMB_OFF_T)len) < 0) {
493 DEBUG(0,("vfs_allocate_file_space: %s negative len requested.\n", fsp->fsp_name ));
498 ret = SMB_VFS_FSTAT(fsp, &st);
502 if (len == (uint64_t)st.st_ex_size)
505 if (len < (uint64_t)st.st_ex_size) {
506 /* Shrink - use ftruncate. */
508 DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current size %.0f\n",
509 fsp->fsp_name, (double)st.st_ex_size ));
511 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
513 flush_write_cache(fsp, SIZECHANGE_FLUSH);
514 if ((ret = SMB_VFS_FTRUNCATE(fsp, (SMB_OFF_T)len)) != -1) {
515 set_filelen_write_cache(fsp, len);
518 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
523 /* Grow - we need to test if we have enough space. */
525 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
526 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
528 if (!lp_strict_allocate(SNUM(fsp->conn)))
531 len -= st.st_ex_size;
532 len /= 1024; /* Len is now number of 1k blocks needed. */
533 space_avail = get_dfree_info(conn,fsp->fsp_name,False,&bsize,&dfree,&dsize);
534 if (space_avail == (uint64_t)-1) {
538 DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, needed blocks = %.0f, space avail = %.0f\n",
539 fsp->fsp_name, (double)st.st_ex_size, (double)len, (double)space_avail ));
541 if (len > space_avail) {
549 /****************************************************************************
550 A vfs set_filelen call.
551 set the length of a file from a filedescriptor.
552 Returns 0 on success, -1 on failure.
553 ****************************************************************************/
555 int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len)
559 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
561 DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n", fsp->fsp_name, (double)len));
562 flush_write_cache(fsp, SIZECHANGE_FLUSH);
563 if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
564 set_filelen_write_cache(fsp, len);
565 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
566 FILE_NOTIFY_CHANGE_SIZE
567 | FILE_NOTIFY_CHANGE_ATTRIBUTES,
571 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
576 /****************************************************************************
577 A vfs fill sparse call.
578 Writes zeros from the end of file to len, if len is greater than EOF.
579 Used only by strict_sync.
580 Returns 0 on success, -1 on failure.
581 ****************************************************************************/
583 #define SPARSE_BUF_WRITE_SIZE (32*1024)
585 int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len)
594 ret = SMB_VFS_FSTAT(fsp, &st);
599 if (len <= st.st_ex_size) {
603 DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to len %.0f (%.0f bytes)\n",
604 fsp->fsp_name, (double)st.st_ex_size, (double)len, (double)(len - st.st_ex_size)));
606 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
608 flush_write_cache(fsp, SIZECHANGE_FLUSH);
611 sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
619 offset = st.st_ex_size;
620 num_to_write = len - st.st_ex_size;
623 while (total < num_to_write) {
624 size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (num_to_write - total));
626 pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
627 if (pwrite_ret == -1) {
628 DEBUG(10,("vfs_fill_sparse: SMB_VFS_PWRITE for file %s failed with error %s\n",
629 fsp->fsp_name, strerror(errno) ));
633 if (pwrite_ret == 0) {
641 set_filelen_write_cache(fsp, len);
645 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
649 /****************************************************************************
650 Transfer some data (n bytes) between two file_struct's.
651 ****************************************************************************/
653 static ssize_t vfs_read_fn(void *file, void *buf, size_t len)
655 struct files_struct *fsp = (struct files_struct *)file;
657 return SMB_VFS_READ(fsp, buf, len);
660 static ssize_t vfs_write_fn(void *file, const void *buf, size_t len)
662 struct files_struct *fsp = (struct files_struct *)file;
664 return SMB_VFS_WRITE(fsp, buf, len);
667 SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n)
669 return transfer_file_internal((void *)in, (void *)out, n,
670 vfs_read_fn, vfs_write_fn);
673 /*******************************************************************
674 A vfs_readdir wrapper which just returns the file name.
675 ********************************************************************/
677 char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf)
679 SMB_STRUCT_DIRENT *ptr= NULL;
685 ptr = SMB_VFS_READDIR(conn, (DIR *)p, sbuf);
696 #ifdef HAVE_BROKEN_READDIR_NAME
697 /* using /usr/ucb/cc is BAD */
704 /*******************************************************************
705 A wrapper for vfs_chdir().
706 ********************************************************************/
708 int vfs_ChDir(connection_struct *conn, const char *path)
713 LastDir = SMB_STRDUP("");
716 if (strcsequal(path,"."))
719 if (*path == '/' && strcsequal(LastDir,path))
722 DEBUG(4,("vfs_ChDir to %s\n",path));
724 res = SMB_VFS_CHDIR(conn,path);
727 LastDir = SMB_STRDUP(path);
732 /*******************************************************************
733 Return the absolute current directory path - given a UNIX pathname.
734 Note that this path is returned in DOS format, not UNIX
735 format. Note this can be called with conn == NULL.
736 ********************************************************************/
738 char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
742 DATA_BLOB cache_value;
744 struct smb_filename *smb_fname_dot = NULL;
745 struct smb_filename *smb_fname_full = NULL;
750 if (!lp_getwd_cache()) {
754 status = create_synthetic_smb_fname(ctx, ".", NULL, NULL,
756 if (!NT_STATUS_IS_OK(status)) {
757 errno = map_errno_from_nt_status(status);
761 if (SMB_VFS_STAT(conn, smb_fname_dot) == -1) {
763 * Known to fail for root: the directory may be NFS-mounted
764 * and exported with root_squash (so has no root access).
766 DEBUG(1,("vfs_GetWd: couldn't stat \".\" error %s "
767 "(NFS problem ?)\n", strerror(errno) ));
771 key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
773 if (!memcache_lookup(smbd_memcache(), GETWD_CACHE,
774 data_blob_const(&key, sizeof(key)),
779 SMB_ASSERT((cache_value.length > 0)
780 && (cache_value.data[cache_value.length-1] == '\0'));
782 status = create_synthetic_smb_fname(ctx, (char *)cache_value.data,
783 NULL, NULL, &smb_fname_full);
784 if (!NT_STATUS_IS_OK(status)) {
785 errno = map_errno_from_nt_status(status);
789 if ((SMB_VFS_STAT(conn, smb_fname_full) == 0) &&
790 (smb_fname_dot->st.st_ex_dev == smb_fname_full->st.st_ex_dev) &&
791 (smb_fname_dot->st.st_ex_ino == smb_fname_full->st.st_ex_ino) &&
792 (S_ISDIR(smb_fname_dot->st.st_ex_mode))) {
796 result = talloc_strdup(ctx, smb_fname_full->base_name);
797 if (result == NULL) {
806 * We don't have the information to hand so rely on traditional
807 * methods. The very slow getcwd, which spawns a process on some
808 * systems, or the not quite so bad getwd.
811 if (!SMB_VFS_GETWD(conn,s)) {
812 DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
817 if (lp_getwd_cache() && VALID_STAT(smb_fname_dot->st)) {
818 key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
820 memcache_add(smbd_memcache(), GETWD_CACHE,
821 data_blob_const(&key, sizeof(key)),
822 data_blob_const(s, strlen(s)+1));
825 result = talloc_strdup(ctx, s);
826 if (result == NULL) {
831 TALLOC_FREE(smb_fname_dot);
832 TALLOC_FREE(smb_fname_full);
836 /*******************************************************************
837 Reduce a file name, removing .. elements and checking that
838 it is below dir in the heirachy. This uses realpath.
839 ********************************************************************/
841 NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
843 #ifdef REALPATH_TAKES_NULL
844 bool free_resolved_name = True;
846 char resolved_name_buf[PATH_MAX+1];
847 bool free_resolved_name = False;
849 char *resolved_name = NULL;
852 DEBUG(3,("reduce_name [%s] [%s]\n", fname, conn->connectpath));
854 #ifdef REALPATH_TAKES_NULL
855 resolved_name = SMB_VFS_REALPATH(conn,fname,NULL);
857 resolved_name = SMB_VFS_REALPATH(conn,fname,resolved_name_buf);
860 if (!resolved_name) {
863 DEBUG(3,("reduce_name: Component not a directory in getting realpath for %s\n", fname));
864 return map_nt_error_from_unix(errno);
867 TALLOC_CTX *ctx = talloc_tos();
868 char *tmp_fname = NULL;
869 char *last_component = NULL;
870 /* Last component didn't exist. Remove it and try and canonicalise the directory. */
872 tmp_fname = talloc_strdup(ctx, fname);
874 return NT_STATUS_NO_MEMORY;
876 p = strrchr_m(tmp_fname, '/');
881 last_component = tmp_fname;
882 tmp_fname = talloc_strdup(ctx,
885 return NT_STATUS_NO_MEMORY;
889 #ifdef REALPATH_TAKES_NULL
890 resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,NULL);
892 resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,resolved_name_buf);
894 if (!resolved_name) {
895 DEBUG(3,("reduce_name: couldn't get realpath for %s\n", fname));
896 return map_nt_error_from_unix(errno);
898 tmp_fname = talloc_asprintf(ctx,
903 return NT_STATUS_NO_MEMORY;
905 #ifdef REALPATH_TAKES_NULL
906 SAFE_FREE(resolved_name);
907 resolved_name = SMB_STRDUP(tmp_fname);
908 if (!resolved_name) {
909 DEBUG(0,("reduce_name: malloc fail for %s\n", tmp_fname));
910 return NT_STATUS_NO_MEMORY;
913 safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
914 resolved_name = resolved_name_buf;
919 DEBUG(1,("reduce_name: couldn't get realpath for %s\n", fname));
920 return map_nt_error_from_unix(errno);
924 DEBUG(10,("reduce_name realpath [%s] -> [%s]\n", fname, resolved_name));
926 if (*resolved_name != '/') {
927 DEBUG(0,("reduce_name: realpath doesn't return absolute paths !\n"));
928 if (free_resolved_name) {
929 SAFE_FREE(resolved_name);
931 return NT_STATUS_OBJECT_NAME_INVALID;
934 /* Check for widelinks allowed. */
935 if (!lp_widelinks(SNUM(conn))) {
936 const char *conn_rootdir;
938 conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
939 if (conn_rootdir == NULL) {
940 DEBUG(2, ("check_reduced_name: Could not get conn_rootdir\n"));
941 if (free_resolved_name) {
942 SAFE_FREE(resolved_name);
944 return NT_STATUS_ACCESS_DENIED;
947 if (strncmp(conn_rootdir, resolved_name,
948 strlen(conn_rootdir)) != 0) {
949 DEBUG(2, ("reduce_name: Bad access attempt: %s is "
950 "a symlink outside the share path",
952 if (free_resolved_name) {
953 SAFE_FREE(resolved_name);
955 return NT_STATUS_ACCESS_DENIED;
959 /* Check if we are allowing users to follow symlinks */
960 /* Patch from David Clerc <David.Clerc@cui.unige.ch>
961 University of Geneva */
964 if (!lp_symlinks(SNUM(conn))) {
965 SMB_STRUCT_STAT statbuf;
966 if ( (vfs_lstat_smb_fname(conn,fname,&statbuf) != -1) &&
967 (S_ISLNK(statbuf.st_ex_mode)) ) {
968 if (free_resolved_name) {
969 SAFE_FREE(resolved_name);
971 DEBUG(3,("reduce_name: denied: file path name %s is a symlink\n",resolved_name));
972 return NT_STATUS_ACCESS_DENIED;
977 DEBUG(3,("reduce_name: %s reduced to %s\n", fname, resolved_name));
978 if (free_resolved_name) {
979 SAFE_FREE(resolved_name);