Make the smbd VFS typesafe
[nivanova/samba-autobuild/.git] / source3 / smbd / vfs.c
1 /*
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    VFS initialisation and support functions
5    Copyright (C) Tim Potter 1999
6    Copyright (C) Alexander Bokovoy 2002
7    Copyright (C) James Peach 2006
8
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.
13
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.
18
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/>.
21
22    This work was sponsored by Optifacio Software Services, Inc.
23 */
24
25 #include "includes.h"
26 #include "smbd/globals.h"
27
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_VFS
30
31 static_decl_vfs;
32
33 struct vfs_init_function_entry {
34         char *name;
35         struct vfs_init_function_entry *prev, *next;
36         const struct vfs_fn_pointers *fns;
37 };
38
39 /****************************************************************************
40     maintain the list of available backends
41 ****************************************************************************/
42
43 static struct vfs_init_function_entry *vfs_find_backend_entry(const char *name)
44 {
45         struct vfs_init_function_entry *entry = backends;
46
47         DEBUG(10, ("vfs_find_backend_entry called for %s\n", name));
48
49         while(entry) {
50                 if (strcmp(entry->name, name)==0) return entry;
51                 entry = entry->next;
52         }
53
54         return NULL;
55 }
56
57 NTSTATUS smb_register_vfs(int version, const char *name,
58                           const struct vfs_fn_pointers *fns)
59 {
60         struct vfs_init_function_entry *entry = backends;
61
62         if ((version != SMB_VFS_INTERFACE_VERSION)) {
63                 DEBUG(0, ("Failed to register vfs module.\n"
64                           "The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
65                           "current SMB_VFS_INTERFACE_VERSION is %d.\n"
66                           "Please recompile against the current Samba Version!\n",  
67                           version, SMB_VFS_INTERFACE_VERSION));
68                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
69         }
70
71         if (!name || !name[0]) {
72                 DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
73                 return NT_STATUS_INVALID_PARAMETER;
74         }
75
76         if (vfs_find_backend_entry(name)) {
77                 DEBUG(0,("VFS module %s already loaded!\n", name));
78                 return NT_STATUS_OBJECT_NAME_COLLISION;
79         }
80
81         entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
82         entry->name = smb_xstrdup(name);
83         entry->fns = fns;
84
85         DLIST_ADD(backends, entry);
86         DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
87         return NT_STATUS_OK;
88 }
89
90 /****************************************************************************
91   initialise default vfs hooks
92 ****************************************************************************/
93
94 static void vfs_init_default(connection_struct *conn)
95 {
96         DEBUG(3, ("Initialising default vfs hooks\n"));
97         vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
98 }
99
100 /****************************************************************************
101   initialise custom vfs hooks
102  ****************************************************************************/
103
104 bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
105 {
106         char *module_path = NULL;
107         char *module_name = NULL;
108         char *module_param = NULL, *p;
109         vfs_handle_struct *handle;
110         const struct vfs_init_function_entry *entry;
111
112         if (!conn||!vfs_object||!vfs_object[0]) {
113                 DEBUG(0,("vfs_init_custon() called with NULL pointer or emtpy vfs_object!\n"));
114                 return False;
115         }
116
117         if(!backends) {
118                 static_init_vfs;
119         }
120
121         DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
122
123         module_path = smb_xstrdup(vfs_object);
124
125         p = strchr_m(module_path, ':');
126
127         if (p) {
128                 *p = 0;
129                 module_param = p+1;
130                 trim_char(module_param, ' ', ' ');
131         }
132
133         trim_char(module_path, ' ', ' ');
134
135         module_name = smb_xstrdup(module_path);
136
137         if ((module_name[0] == '/') &&
138             (strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
139
140                 /*
141                  * Extract the module name from the path. Just use the base
142                  * name of the last path component.
143                  */
144
145                 SAFE_FREE(module_name);
146                 module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
147
148                 p = strchr_m(module_name, '.');
149
150                 if (p != NULL) {
151                         *p = '\0';
152                 }
153         }
154
155         /* First, try to load the module with the new module system */
156         entry = vfs_find_backend_entry(module_name);
157         if (!entry) {
158                 NTSTATUS status;
159
160                 DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
161                           vfs_object));
162
163                 status = smb_probe_module("vfs", module_path);
164                 if (!NT_STATUS_IS_OK(status)) {
165                         DEBUG(0, ("error probing vfs module '%s': %s\n",
166                                   module_path, nt_errstr(status)));
167                         goto fail;
168                 }
169
170                 entry = vfs_find_backend_entry(module_name);
171                 if (!entry) {
172                         DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
173                         goto fail;
174                 }
175         }
176
177         DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
178
179         handle = TALLOC_ZERO_P(conn, vfs_handle_struct);
180         if (!handle) {
181                 DEBUG(0,("TALLOC_ZERO() failed!\n"));
182                 goto fail;
183         }
184         handle->conn = conn;
185         handle->fns = entry->fns;
186         if (module_param) {
187                 handle->param = talloc_strdup(conn, module_param);
188         }
189         DLIST_ADD(conn->vfs_handles, handle);
190
191         SAFE_FREE(module_path);
192         SAFE_FREE(module_name);
193         return True;
194
195  fail:
196         SAFE_FREE(module_path);
197         SAFE_FREE(module_name);
198         return False;
199 }
200
201 /*****************************************************************
202  Allow VFS modules to extend files_struct with VFS-specific state.
203  This will be ok for small numbers of extensions, but might need to
204  be refactored if it becomes more widely used.
205 ******************************************************************/
206
207 #define EXT_DATA_AREA(e) ((uint8 *)(e) + sizeof(struct vfs_fsp_data))
208
209 void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
210                                    files_struct *fsp, size_t ext_size,
211                                    void (*destroy_fn)(void *p_data))
212 {
213         struct vfs_fsp_data *ext;
214         void * ext_data;
215
216         /* Prevent VFS modules adding multiple extensions. */
217         if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
218                 return ext_data;
219         }
220
221         ext = (struct vfs_fsp_data *)TALLOC_ZERO(
222                 handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
223         if (ext == NULL) {
224                 return NULL;
225         }
226
227         ext->owner = handle;
228         ext->next = fsp->vfs_extension;
229         ext->destroy = destroy_fn;
230         fsp->vfs_extension = ext;
231         return EXT_DATA_AREA(ext);
232 }
233
234 void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
235 {
236         struct vfs_fsp_data *curr;
237         struct vfs_fsp_data *prev;
238
239         for (curr = fsp->vfs_extension, prev = NULL;
240              curr;
241              prev = curr, curr = curr->next) {
242                 if (curr->owner == handle) {
243                     if (prev) {
244                             prev->next = curr->next;
245                     } else {
246                             fsp->vfs_extension = curr->next;
247                     }
248                     if (curr->destroy) {
249                             curr->destroy(EXT_DATA_AREA(curr));
250                     }
251                     TALLOC_FREE(curr);
252                     return;
253                 }
254         }
255 }
256
257 void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
258 {
259         struct vfs_fsp_data *head;
260
261         for (head = fsp->vfs_extension; head; head = head->next) {
262                 if (head->owner == handle) {
263                         return head;
264                 }
265         }
266
267         return NULL;
268 }
269
270 void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
271 {
272         struct vfs_fsp_data *head;
273
274         head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
275         if (head != NULL) {
276                 return EXT_DATA_AREA(head);
277         }
278
279         return NULL;
280 }
281
282 #undef EXT_DATA_AREA
283
284 /*****************************************************************
285  Generic VFS init.
286 ******************************************************************/
287
288 bool smbd_vfs_init(connection_struct *conn)
289 {
290         const char **vfs_objects;
291         unsigned int i = 0;
292         int j = 0;
293
294         /* Normal share - initialise with disk access functions */
295         vfs_init_default(conn);
296         vfs_objects = lp_vfs_objects(SNUM(conn));
297
298         /* Override VFS functions if 'vfs object' was not specified*/
299         if (!vfs_objects || !vfs_objects[0])
300                 return True;
301
302         for (i=0; vfs_objects[i] ;) {
303                 i++;
304         }
305
306         for (j=i-1; j >= 0; j--) {
307                 if (!vfs_init_custom(conn, vfs_objects[j])) {
308                         DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
309                         return False;
310                 }
311         }
312         return True;
313 }
314
315 /*******************************************************************
316  Check if a file exists in the vfs.
317 ********************************************************************/
318
319 NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
320 {
321         /* Only return OK if stat was successful and S_ISREG */
322         if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
323             S_ISREG(smb_fname->st.st_ex_mode)) {
324                 return NT_STATUS_OK;
325         }
326
327         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
328 }
329
330 /****************************************************************************
331  Read data from fsp on the vfs. (note: EINTR re-read differs from vfs_write_data)
332 ****************************************************************************/
333
334 ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
335 {
336         size_t total=0;
337
338         while (total < byte_count)
339         {
340                 ssize_t ret = SMB_VFS_READ(fsp, buf + total,
341                                            byte_count - total);
342
343                 if (ret == 0) return total;
344                 if (ret == -1) {
345                         if (errno == EINTR)
346                                 continue;
347                         else
348                                 return -1;
349                 }
350                 total += ret;
351         }
352         return (ssize_t)total;
353 }
354
355 ssize_t vfs_pread_data(files_struct *fsp, char *buf,
356                 size_t byte_count, SMB_OFF_T offset)
357 {
358         size_t total=0;
359
360         while (total < byte_count)
361         {
362                 ssize_t ret = SMB_VFS_PREAD(fsp, buf + total,
363                                         byte_count - total, offset + total);
364
365                 if (ret == 0) return total;
366                 if (ret == -1) {
367                         if (errno == EINTR)
368                                 continue;
369                         else
370                                 return -1;
371                 }
372                 total += ret;
373         }
374         return (ssize_t)total;
375 }
376
377 /****************************************************************************
378  Write data to a fd on the vfs.
379 ****************************************************************************/
380
381 ssize_t vfs_write_data(struct smb_request *req,
382                         files_struct *fsp,
383                         const char *buffer,
384                         size_t N)
385 {
386         size_t total=0;
387         ssize_t ret;
388
389         if (req && req->unread_bytes) {
390                 SMB_ASSERT(req->unread_bytes == N);
391                 /* VFS_RECVFILE must drain the socket
392                  * before returning. */
393                 req->unread_bytes = 0;
394                 return SMB_VFS_RECVFILE(smbd_server_fd(),
395                                         fsp,
396                                         (SMB_OFF_T)-1,
397                                         N);
398         }
399
400         while (total < N) {
401                 ret = SMB_VFS_WRITE(fsp, buffer + total, N - total);
402
403                 if (ret == -1)
404                         return -1;
405                 if (ret == 0)
406                         return total;
407
408                 total += ret;
409         }
410         return (ssize_t)total;
411 }
412
413 ssize_t vfs_pwrite_data(struct smb_request *req,
414                         files_struct *fsp,
415                         const char *buffer,
416                         size_t N,
417                         SMB_OFF_T offset)
418 {
419         size_t total=0;
420         ssize_t ret;
421
422         if (req && req->unread_bytes) {
423                 SMB_ASSERT(req->unread_bytes == N);
424                 /* VFS_RECVFILE must drain the socket
425                  * before returning. */
426                 req->unread_bytes = 0;
427                 return SMB_VFS_RECVFILE(smbd_server_fd(),
428                                         fsp,
429                                         offset,
430                                         N);
431         }
432
433         while (total < N) {
434                 ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total,
435                                      offset + total);
436
437                 if (ret == -1)
438                         return -1;
439                 if (ret == 0)
440                         return total;
441
442                 total += ret;
443         }
444         return (ssize_t)total;
445 }
446 /****************************************************************************
447  An allocate file space call using the vfs interface.
448  Allocates space for a file from a filedescriptor.
449  Returns 0 on success, -1 on failure.
450 ****************************************************************************/
451
452 int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
453 {
454         int ret;
455         SMB_STRUCT_STAT st;
456         connection_struct *conn = fsp->conn;
457         uint64_t space_avail;
458         uint64_t bsize,dfree,dsize;
459
460         /*
461          * Actually try and commit the space on disk....
462          */
463
464         DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
465                   fsp_str_dbg(fsp), (double)len));
466
467         if (((SMB_OFF_T)len) < 0) {
468                 DEBUG(0,("vfs_allocate_file_space: %s negative len "
469                          "requested.\n", fsp_str_dbg(fsp)));
470                 errno = EINVAL;
471                 return -1;
472         }
473
474         ret = SMB_VFS_FSTAT(fsp, &st);
475         if (ret == -1)
476                 return ret;
477
478         if (len == (uint64_t)st.st_ex_size)
479                 return 0;
480
481         if (len < (uint64_t)st.st_ex_size) {
482                 /* Shrink - use ftruncate. */
483
484                 DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
485                           "size %.0f\n", fsp_str_dbg(fsp),
486                           (double)st.st_ex_size));
487
488                 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
489
490                 flush_write_cache(fsp, SIZECHANGE_FLUSH);
491                 if ((ret = SMB_VFS_FTRUNCATE(fsp, (SMB_OFF_T)len)) != -1) {
492                         set_filelen_write_cache(fsp, len);
493                 }
494
495                 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
496
497                 return ret;
498         }
499
500         /* Grow - we need to test if we have enough space. */
501
502         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
503         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
504
505         if (!lp_strict_allocate(SNUM(fsp->conn)))
506                 return 0;
507
508         len -= st.st_ex_size;
509         len /= 1024; /* Len is now number of 1k blocks needed. */
510         space_avail = get_dfree_info(conn, fsp->fsp_name->base_name, false,
511                                      &bsize, &dfree, &dsize);
512         if (space_avail == (uint64_t)-1) {
513                 return -1;
514         }
515
516         DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
517                   "needed blocks = %.0f, space avail = %.0f\n",
518                   fsp_str_dbg(fsp), (double)st.st_ex_size, (double)len,
519                   (double)space_avail));
520
521         if (len > space_avail) {
522                 errno = ENOSPC;
523                 return -1;
524         }
525
526         return 0;
527 }
528
529 /****************************************************************************
530  A vfs set_filelen call.
531  set the length of a file from a filedescriptor.
532  Returns 0 on success, -1 on failure.
533 ****************************************************************************/
534
535 int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len)
536 {
537         int ret;
538
539         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
540
541         DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
542                   fsp_str_dbg(fsp), (double)len));
543         flush_write_cache(fsp, SIZECHANGE_FLUSH);
544         if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
545                 set_filelen_write_cache(fsp, len);
546                 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
547                              FILE_NOTIFY_CHANGE_SIZE
548                              | FILE_NOTIFY_CHANGE_ATTRIBUTES,
549                              fsp->fsp_name->base_name);
550         }
551
552         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
553
554         return ret;
555 }
556
557 /****************************************************************************
558  A vfs fill sparse call.
559  Writes zeros from the end of file to len, if len is greater than EOF.
560  Used only by strict_sync.
561  Returns 0 on success, -1 on failure.
562 ****************************************************************************/
563
564 #define SPARSE_BUF_WRITE_SIZE (32*1024)
565
566 int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len)
567 {
568         int ret;
569         SMB_STRUCT_STAT st;
570         SMB_OFF_T offset;
571         size_t total;
572         size_t num_to_write;
573         ssize_t pwrite_ret;
574
575         ret = SMB_VFS_FSTAT(fsp, &st);
576         if (ret == -1) {
577                 return ret;
578         }
579
580         if (len <= st.st_ex_size) {
581                 return 0;
582         }
583
584         DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
585                   "len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp),
586                   (double)st.st_ex_size, (double)len,
587                   (double)(len - st.st_ex_size)));
588
589         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
590
591         flush_write_cache(fsp, SIZECHANGE_FLUSH);
592
593         if (!sparse_buf) {
594                 sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
595                 if (!sparse_buf) {
596                         errno = ENOMEM;
597                         ret = -1;
598                         goto out;
599                 }
600         }
601
602         offset = st.st_ex_size;
603         num_to_write = len - st.st_ex_size;
604         total = 0;
605
606         while (total < num_to_write) {
607                 size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (num_to_write - total));
608
609                 pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
610                 if (pwrite_ret == -1) {
611                         DEBUG(10,("vfs_fill_sparse: SMB_VFS_PWRITE for file "
612                                   "%s failed with error %s\n",
613                                   fsp_str_dbg(fsp), strerror(errno)));
614                         ret = -1;
615                         goto out;
616                 }
617                 if (pwrite_ret == 0) {
618                         ret = 0;
619                         goto out;
620                 }
621
622                 total += pwrite_ret;
623         }
624
625         set_filelen_write_cache(fsp, len);
626
627         ret = 0;
628  out:
629         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
630         return ret;
631 }
632
633 /****************************************************************************
634  Transfer some data (n bytes) between two file_struct's.
635 ****************************************************************************/
636
637 static ssize_t vfs_read_fn(void *file, void *buf, size_t len)
638 {
639         struct files_struct *fsp = (struct files_struct *)file;
640
641         return SMB_VFS_READ(fsp, buf, len);
642 }
643
644 static ssize_t vfs_write_fn(void *file, const void *buf, size_t len)
645 {
646         struct files_struct *fsp = (struct files_struct *)file;
647
648         return SMB_VFS_WRITE(fsp, buf, len);
649 }
650
651 SMB_OFF_T vfs_transfer_file(files_struct *in, files_struct *out, SMB_OFF_T n)
652 {
653         return transfer_file_internal((void *)in, (void *)out, n,
654                                       vfs_read_fn, vfs_write_fn);
655 }
656
657 /*******************************************************************
658  A vfs_readdir wrapper which just returns the file name.
659 ********************************************************************/
660
661 char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf)
662 {
663         SMB_STRUCT_DIRENT *ptr= NULL;
664         char *dname;
665
666         if (!p)
667                 return(NULL);
668
669         ptr = SMB_VFS_READDIR(conn, (DIR *)p, sbuf);
670         if (!ptr)
671                 return(NULL);
672
673         dname = ptr->d_name;
674
675 #ifdef NEXT2
676         if (telldir(p) < 0)
677                 return(NULL);
678 #endif
679
680 #ifdef HAVE_BROKEN_READDIR_NAME
681         /* using /usr/ucb/cc is BAD */
682         dname = dname - 2;
683 #endif
684
685         return(dname);
686 }
687
688 /*******************************************************************
689  A wrapper for vfs_chdir().
690 ********************************************************************/
691
692 int vfs_ChDir(connection_struct *conn, const char *path)
693 {
694         int res;
695
696         if (!LastDir) {
697                 LastDir = SMB_STRDUP("");
698         }
699
700         if (strcsequal(path,"."))
701                 return(0);
702
703         if (*path == '/' && strcsequal(LastDir,path))
704                 return(0);
705
706         DEBUG(4,("vfs_ChDir to %s\n",path));
707
708         res = SMB_VFS_CHDIR(conn,path);
709         if (!res) {
710                 SAFE_FREE(LastDir);
711                 LastDir = SMB_STRDUP(path);
712         }
713         return(res);
714 }
715
716 /*******************************************************************
717  Return the absolute current directory path - given a UNIX pathname.
718  Note that this path is returned in DOS format, not UNIX
719  format. Note this can be called with conn == NULL.
720 ********************************************************************/
721
722 char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
723 {
724         char s[PATH_MAX+1];
725         char *result = NULL;
726         DATA_BLOB cache_value;
727         struct file_id key;
728         struct smb_filename *smb_fname_dot = NULL;
729         struct smb_filename *smb_fname_full = NULL;
730         NTSTATUS status;
731
732         *s = 0;
733
734         if (!lp_getwd_cache()) {
735                 goto nocache;
736         }
737
738         status = create_synthetic_smb_fname(ctx, ".", NULL, NULL,
739                                             &smb_fname_dot);
740         if (!NT_STATUS_IS_OK(status)) {
741                 errno = map_errno_from_nt_status(status);
742                 goto out;
743         }
744
745         if (SMB_VFS_STAT(conn, smb_fname_dot) == -1) {
746                 /*
747                  * Known to fail for root: the directory may be NFS-mounted
748                  * and exported with root_squash (so has no root access).
749                  */
750                 DEBUG(1,("vfs_GetWd: couldn't stat \".\" error %s "
751                          "(NFS problem ?)\n", strerror(errno) ));
752                 goto nocache;
753         }
754
755         key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
756
757         if (!memcache_lookup(smbd_memcache(), GETWD_CACHE,
758                              data_blob_const(&key, sizeof(key)),
759                              &cache_value)) {
760                 goto nocache;
761         }
762
763         SMB_ASSERT((cache_value.length > 0)
764                    && (cache_value.data[cache_value.length-1] == '\0'));
765
766         status = create_synthetic_smb_fname(ctx, (char *)cache_value.data,
767                                             NULL, NULL, &smb_fname_full);
768         if (!NT_STATUS_IS_OK(status)) {
769                 errno = map_errno_from_nt_status(status);
770                 goto out;
771         }
772
773         if ((SMB_VFS_STAT(conn, smb_fname_full) == 0) &&
774             (smb_fname_dot->st.st_ex_dev == smb_fname_full->st.st_ex_dev) &&
775             (smb_fname_dot->st.st_ex_ino == smb_fname_full->st.st_ex_ino) &&
776             (S_ISDIR(smb_fname_dot->st.st_ex_mode))) {
777                 /*
778                  * Ok, we're done
779                  */
780                 result = talloc_strdup(ctx, smb_fname_full->base_name);
781                 if (result == NULL) {
782                         errno = ENOMEM;
783                 }
784                 goto out;
785         }
786
787  nocache:
788
789         /*
790          * We don't have the information to hand so rely on traditional
791          * methods. The very slow getcwd, which spawns a process on some
792          * systems, or the not quite so bad getwd.
793          */
794
795         if (!SMB_VFS_GETWD(conn,s)) {
796                 DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
797                           strerror(errno)));
798                 goto out;
799         }
800
801         if (lp_getwd_cache() && VALID_STAT(smb_fname_dot->st)) {
802                 key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
803
804                 memcache_add(smbd_memcache(), GETWD_CACHE,
805                              data_blob_const(&key, sizeof(key)),
806                              data_blob_const(s, strlen(s)+1));
807         }
808
809         result = talloc_strdup(ctx, s);
810         if (result == NULL) {
811                 errno = ENOMEM;
812         }
813
814  out:
815         TALLOC_FREE(smb_fname_dot);
816         TALLOC_FREE(smb_fname_full);
817         return result;
818 }
819
820 /*******************************************************************
821  Reduce a file name, removing .. elements and checking that
822  it is below dir in the heirachy. This uses realpath.
823 ********************************************************************/
824
825 NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
826 {
827 #ifdef REALPATH_TAKES_NULL
828         bool free_resolved_name = True;
829 #else
830         char resolved_name_buf[PATH_MAX+1];
831         bool free_resolved_name = False;
832 #endif
833         char *resolved_name = NULL;
834         char *p = NULL;
835
836         DEBUG(3,("reduce_name [%s] [%s]\n", fname, conn->connectpath));
837
838 #ifdef REALPATH_TAKES_NULL
839         resolved_name = SMB_VFS_REALPATH(conn,fname,NULL);
840 #else
841         resolved_name = SMB_VFS_REALPATH(conn,fname,resolved_name_buf);
842 #endif
843
844         if (!resolved_name) {
845                 switch (errno) {
846                         case ENOTDIR:
847                                 DEBUG(3,("reduce_name: Component not a directory in getting realpath for %s\n", fname));
848                                 return map_nt_error_from_unix(errno);
849                         case ENOENT:
850                         {
851                                 TALLOC_CTX *ctx = talloc_tos();
852                                 char *tmp_fname = NULL;
853                                 char *last_component = NULL;
854                                 /* Last component didn't exist. Remove it and try and canonicalise the directory. */
855
856                                 tmp_fname = talloc_strdup(ctx, fname);
857                                 if (!tmp_fname) {
858                                         return NT_STATUS_NO_MEMORY;
859                                 }
860                                 p = strrchr_m(tmp_fname, '/');
861                                 if (p) {
862                                         *p++ = '\0';
863                                         last_component = p;
864                                 } else {
865                                         last_component = tmp_fname;
866                                         tmp_fname = talloc_strdup(ctx,
867                                                         ".");
868                                         if (!tmp_fname) {
869                                                 return NT_STATUS_NO_MEMORY;
870                                         }
871                                 }
872
873 #ifdef REALPATH_TAKES_NULL
874                                 resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,NULL);
875 #else
876                                 resolved_name = SMB_VFS_REALPATH(conn,tmp_fname,resolved_name_buf);
877 #endif
878                                 if (!resolved_name) {
879                                         DEBUG(3,("reduce_name: couldn't get realpath for %s\n", fname));
880                                         return map_nt_error_from_unix(errno);
881                                 }
882                                 tmp_fname = talloc_asprintf(ctx,
883                                                 "%s/%s",
884                                                 resolved_name,
885                                                 last_component);
886                                 if (!tmp_fname) {
887                                         return NT_STATUS_NO_MEMORY;
888                                 }
889 #ifdef REALPATH_TAKES_NULL
890                                 SAFE_FREE(resolved_name);
891                                 resolved_name = SMB_STRDUP(tmp_fname);
892                                 if (!resolved_name) {
893                                         DEBUG(0,("reduce_name: malloc fail for %s\n", tmp_fname));
894                                         return NT_STATUS_NO_MEMORY;
895                                 }
896 #else
897                                 safe_strcpy(resolved_name_buf, tmp_fname, PATH_MAX);
898                                 resolved_name = resolved_name_buf;
899 #endif
900                                 break;
901                         }
902                         default:
903                                 DEBUG(1,("reduce_name: couldn't get realpath for %s\n", fname));
904                                 return map_nt_error_from_unix(errno);
905                 }
906         }
907
908         DEBUG(10,("reduce_name realpath [%s] -> [%s]\n", fname, resolved_name));
909
910         if (*resolved_name != '/') {
911                 DEBUG(0,("reduce_name: realpath doesn't return absolute paths !\n"));
912                 if (free_resolved_name) {
913                         SAFE_FREE(resolved_name);
914                 }
915                 return NT_STATUS_OBJECT_NAME_INVALID;
916         }
917
918         /* Check for widelinks allowed. */
919         if (!lp_widelinks(SNUM(conn))) {
920                     const char *conn_rootdir;
921
922                     conn_rootdir = SMB_VFS_CONNECTPATH(conn, fname);
923                     if (conn_rootdir == NULL) {
924                             DEBUG(2, ("check_reduced_name: Could not get conn_rootdir\n"));
925                             if (free_resolved_name) {
926                                     SAFE_FREE(resolved_name);
927                             }
928                             return NT_STATUS_ACCESS_DENIED;
929                     }
930
931                     if (strncmp(conn_rootdir, resolved_name,
932                                 strlen(conn_rootdir)) != 0) {
933                             DEBUG(2, ("reduce_name: Bad access attempt: %s is "
934                                       "a symlink outside the share path",
935                                       fname));
936                             if (free_resolved_name) {
937                                     SAFE_FREE(resolved_name);
938                             }
939                             return NT_STATUS_ACCESS_DENIED;
940                     }
941         }
942
943         /* Check if we are allowing users to follow symlinks */
944         /* Patch from David Clerc <David.Clerc@cui.unige.ch>
945                 University of Geneva */
946
947 #ifdef S_ISLNK
948         if (!lp_symlinks(SNUM(conn))) {
949                 struct smb_filename *smb_fname = NULL;
950                 NTSTATUS status;
951
952                 status = create_synthetic_smb_fname(talloc_tos(), fname, NULL,
953                                                     NULL, &smb_fname);
954                 if (!NT_STATUS_IS_OK(status)) {
955                         if (free_resolved_name) {
956                                 SAFE_FREE(resolved_name);
957                         }
958                         return status;
959                 }
960
961                 if ( (SMB_VFS_LSTAT(conn, smb_fname) != -1) &&
962                                 (S_ISLNK(smb_fname->st.st_ex_mode)) ) {
963                         if (free_resolved_name) {
964                                 SAFE_FREE(resolved_name);
965                         }
966                         DEBUG(3,("reduce_name: denied: file path name %s is a symlink\n",resolved_name));
967                         TALLOC_FREE(smb_fname);
968                         return NT_STATUS_ACCESS_DENIED;
969                 }
970                 TALLOC_FREE(smb_fname);
971         }
972 #endif
973
974         DEBUG(3,("reduce_name: %s reduced to %s\n", fname, resolved_name));
975         if (free_resolved_name) {
976                 SAFE_FREE(resolved_name);
977         }
978         return NT_STATUS_OK;
979 }
980
981 /**
982  * XXX: This is temporary and there should be no callers of this once
983  * smb_filename is plumbed through all path based operations.
984  */
985 int vfs_stat_smb_fname(struct connection_struct *conn, const char *fname,
986                        SMB_STRUCT_STAT *psbuf)
987 {
988         struct smb_filename *smb_fname = NULL;
989         NTSTATUS status;
990         int ret;
991
992         status = create_synthetic_smb_fname_split(talloc_tos(), fname, NULL,
993                                                   &smb_fname);
994         if (!NT_STATUS_IS_OK(status)) {
995                 errno = map_errno_from_nt_status(status);
996                 return -1;
997         }
998
999         ret = SMB_VFS_STAT(conn, smb_fname);
1000         if (ret != -1) {
1001                 *psbuf = smb_fname->st;
1002         }
1003
1004         TALLOC_FREE(smb_fname);
1005         return ret;
1006 }
1007
1008 /**
1009  * XXX: This is temporary and there should be no callers of this once
1010  * smb_filename is plumbed through all path based operations.
1011  */
1012 int vfs_lstat_smb_fname(struct connection_struct *conn, const char *fname,
1013                         SMB_STRUCT_STAT *psbuf)
1014 {
1015         struct smb_filename *smb_fname = NULL;
1016         NTSTATUS status;
1017         int ret;
1018
1019         status = create_synthetic_smb_fname_split(talloc_tos(), fname, NULL,
1020                                                   &smb_fname);
1021         if (!NT_STATUS_IS_OK(status)) {
1022                 errno = map_errno_from_nt_status(status);
1023                 return -1;
1024         }
1025
1026         ret = SMB_VFS_LSTAT(conn, smb_fname);
1027         if (ret != -1) {
1028                 *psbuf = smb_fname->st;
1029         }
1030
1031         TALLOC_FREE(smb_fname);
1032         return ret;
1033 }
1034
1035 /*
1036   generate a file_id from a stat structure
1037  */
1038 struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf)
1039 {
1040         return SMB_VFS_FILE_ID_CREATE(conn, sbuf);
1041 }
1042
1043 int smb_vfs_call_connect(struct vfs_handle_struct *handle,
1044                          const char *service, const char *user)
1045 {
1046         VFS_FIND(connect_fn);
1047         return handle->fns->connect_fn(handle, service, user);
1048 }
1049
1050 void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
1051 {
1052         VFS_FIND(disconnect);
1053         return handle->fns->disconnect(handle);
1054 }
1055
1056 uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
1057                                 const char *path, bool small_query,
1058                                 uint64_t *bsize, uint64_t *dfree,
1059                                 uint64_t *dsize)
1060 {
1061         VFS_FIND(disk_free);
1062         return handle->fns->disk_free(handle, path, small_query, bsize, dfree,
1063                                       dsize);
1064 }
1065
1066 int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
1067                            enum SMB_QUOTA_TYPE qtype, unid_t id,
1068                            SMB_DISK_QUOTA *qt)
1069 {
1070         VFS_FIND(get_quota);
1071         return handle->fns->get_quota(handle, qtype, id, qt);
1072 }
1073
1074 int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
1075                            enum SMB_QUOTA_TYPE qtype, unid_t id,
1076                            SMB_DISK_QUOTA *qt)
1077 {
1078         VFS_FIND(set_quota);
1079         return handle->fns->set_quota(handle, qtype, id, qt);
1080 }
1081
1082 int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
1083                                       struct files_struct *fsp,
1084                                       SHADOW_COPY_DATA *shadow_copy_data,
1085                                       bool labels)
1086 {
1087         VFS_FIND(get_shadow_copy_data);
1088         return handle->fns->get_shadow_copy_data(handle, fsp, shadow_copy_data,
1089                                                  labels);
1090 }
1091 int smb_vfs_call_statvfs(struct vfs_handle_struct *handle, const char *path,
1092                          struct vfs_statvfs_struct *statbuf)
1093 {
1094         VFS_FIND(statvfs);
1095         return handle->fns->statvfs(handle, path, statbuf);
1096 }
1097
1098 uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle)
1099 {
1100         VFS_FIND(fs_capabilities);
1101         return handle->fns->fs_capabilities(handle);
1102 }
1103
1104 SMB_STRUCT_DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
1105                                      const char *fname, const char *mask,
1106                                      uint32 attributes)
1107 {
1108         VFS_FIND(opendir);
1109         return handle->fns->opendir(handle, fname, mask, attributes);
1110 }
1111
1112 SMB_STRUCT_DIRENT *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
1113                                               SMB_STRUCT_DIR *dirp,
1114                                               SMB_STRUCT_STAT *sbuf)
1115 {
1116         VFS_FIND(readdir);
1117         return handle->fns->readdir(handle, dirp, sbuf);
1118 }
1119
1120 void smb_vfs_call_seekdir(struct vfs_handle_struct *handle,
1121                           SMB_STRUCT_DIR *dirp, long offset)
1122 {
1123         VFS_FIND(seekdir);
1124         return handle->fns->seekdir(handle, dirp, offset);
1125 }
1126
1127 long smb_vfs_call_telldir(struct vfs_handle_struct *handle,
1128                           SMB_STRUCT_DIR *dirp)
1129 {
1130         VFS_FIND(telldir);
1131         return handle->fns->telldir(handle, dirp);
1132 }
1133
1134 void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
1135                              SMB_STRUCT_DIR *dirp)
1136 {
1137         VFS_FIND(rewind_dir);
1138         return handle->fns->rewind_dir(handle, dirp);
1139 }
1140
1141 int smb_vfs_call_mkdir(struct vfs_handle_struct *handle, const char *path,
1142                        mode_t mode)
1143 {
1144         VFS_FIND(mkdir);
1145         return handle->fns->mkdir(handle, path, mode);
1146 }
1147
1148 int smb_vfs_call_rmdir(struct vfs_handle_struct *handle, const char *path)
1149 {
1150         VFS_FIND(rmdir);
1151         return handle->fns->rmdir(handle, path);
1152 }
1153
1154 int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
1155                           SMB_STRUCT_DIR *dir)
1156 {
1157         VFS_FIND(closedir);
1158         return handle->fns->closedir(handle, dir);
1159 }
1160
1161 void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
1162                                  SMB_STRUCT_DIR *dirp)
1163 {
1164         VFS_FIND(init_search_op);
1165         return handle->fns->init_search_op(handle, dirp);
1166 }
1167
1168 int smb_vfs_call_open(struct vfs_handle_struct *handle,
1169                       struct smb_filename *smb_fname, struct files_struct *fsp,
1170                       int flags, mode_t mode)
1171 {
1172         VFS_FIND(open);
1173         return handle->fns->open(handle, smb_fname, fsp, flags, mode);
1174 }
1175
1176 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
1177                                   struct smb_request *req,
1178                                   uint16_t root_dir_fid,
1179                                   struct smb_filename *smb_fname,
1180                                   uint32_t access_mask,
1181                                   uint32_t share_access,
1182                                   uint32_t create_disposition,
1183                                   uint32_t create_options,
1184                                   uint32_t file_attributes,
1185                                   uint32_t oplock_request,
1186                                   uint64_t allocation_size,
1187                                   struct security_descriptor *sd,
1188                                   struct ea_list *ea_list,
1189                                   files_struct **result,
1190                                   int *pinfo)
1191 {
1192         VFS_FIND(create_file);
1193         return handle->fns->create_file(
1194                 handle, req, root_dir_fid, smb_fname, access_mask,
1195                 share_access, create_disposition, create_options,
1196                 file_attributes, oplock_request, allocation_size, sd, ea_list,
1197                 result, pinfo);
1198 }
1199
1200 int smb_vfs_call_close_fn(struct vfs_handle_struct *handle,
1201                           struct files_struct *fsp)
1202 {
1203         VFS_FIND(close_fn);
1204         return handle->fns->close_fn(handle, fsp);
1205 }
1206
1207 ssize_t smb_vfs_call_vfs_read(struct vfs_handle_struct *handle,
1208                               struct files_struct *fsp, void *data, size_t n)
1209 {
1210         VFS_FIND(vfs_read);
1211         return handle->fns->vfs_read(handle, fsp, data, n);
1212 }
1213
1214 ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
1215                            struct files_struct *fsp, void *data, size_t n,
1216                            SMB_OFF_T offset)
1217 {
1218         VFS_FIND(pread);
1219         return handle->fns->pread(handle, fsp, data, n, offset);
1220 }
1221
1222 ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
1223                            struct files_struct *fsp, const void *data,
1224                            size_t n)
1225 {
1226         VFS_FIND(write);
1227         return handle->fns->write(handle, fsp, data, n);
1228 }
1229
1230 ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
1231                             struct files_struct *fsp, const void *data,
1232                             size_t n, SMB_OFF_T offset)
1233 {
1234         VFS_FIND(pwrite);
1235         return handle->fns->pwrite(handle, fsp, data, n, offset);
1236 }
1237
1238 SMB_OFF_T smb_vfs_call_lseek(struct vfs_handle_struct *handle,
1239                              struct files_struct *fsp, SMB_OFF_T offset,
1240                              int whence)
1241 {
1242         VFS_FIND(lseek);
1243         return handle->fns->lseek(handle, fsp, offset, whence);
1244 }
1245
1246 ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
1247                               files_struct *fromfsp, const DATA_BLOB *header,
1248                               SMB_OFF_T offset, size_t count)
1249 {
1250         VFS_FIND(sendfile);
1251         return handle->fns->sendfile(handle, tofd, fromfsp, header, offset,
1252                                      count);
1253 }
1254
1255 ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
1256                               files_struct *tofsp, SMB_OFF_T offset,
1257                               size_t count)
1258 {
1259         VFS_FIND(recvfile);
1260         return handle->fns->recvfile(handle, fromfd, tofsp, offset, count);
1261 }
1262
1263 int smb_vfs_call_rename(struct vfs_handle_struct *handle,
1264                         const struct smb_filename *smb_fname_src,
1265                         const struct smb_filename *smb_fname_dst)
1266 {
1267         VFS_FIND(rename);
1268         return handle->fns->rename(handle, smb_fname_src, smb_fname_dst);
1269 }
1270
1271 int smb_vfs_call_fsync(struct vfs_handle_struct *handle,
1272                        struct files_struct *fsp)
1273 {
1274         VFS_FIND(fsync);
1275         return handle->fns->fsync(handle, fsp);
1276 }
1277
1278 int smb_vfs_call_stat(struct vfs_handle_struct *handle,
1279                       struct smb_filename *smb_fname)
1280 {
1281         VFS_FIND(stat);
1282         return handle->fns->stat(handle, smb_fname);
1283 }
1284
1285 int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
1286                        struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1287 {
1288         VFS_FIND(fstat);
1289         return handle->fns->fstat(handle, fsp, sbuf);
1290 }
1291
1292 int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
1293                        struct smb_filename *smb_filename)
1294 {
1295         VFS_FIND(lstat);
1296         return handle->fns->lstat(handle, smb_filename);
1297 }
1298
1299 uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
1300                                      struct files_struct *fsp,
1301                                      const SMB_STRUCT_STAT *sbuf)
1302 {
1303         VFS_FIND(get_alloc_size);
1304         return handle->fns->get_alloc_size(handle, fsp, sbuf);
1305 }
1306
1307 int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
1308                         const struct smb_filename *smb_fname)
1309 {
1310         VFS_FIND(unlink);
1311         return handle->fns->unlink(handle, smb_fname);
1312 }
1313
1314 int smb_vfs_call_chmod(struct vfs_handle_struct *handle, const char *path,
1315                        mode_t mode)
1316 {
1317         VFS_FIND(chmod);
1318         return handle->fns->chmod(handle, path, mode);
1319 }
1320
1321 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
1322                         struct files_struct *fsp, mode_t mode)
1323 {
1324         VFS_FIND(fchmod);
1325         return handle->fns->fchmod(handle, fsp, mode);
1326 }
1327
1328 int smb_vfs_call_chown(struct vfs_handle_struct *handle, const char *path,
1329                        uid_t uid, gid_t gid)
1330 {
1331         VFS_FIND(chown);
1332         return handle->fns->chown(handle, path, uid, gid);
1333 }
1334
1335 int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
1336                         struct files_struct *fsp, uid_t uid, gid_t gid)
1337 {
1338         VFS_FIND(fchown);
1339         return handle->fns->fchown(handle, fsp, uid, gid);
1340 }
1341
1342 int smb_vfs_call_lchown(struct vfs_handle_struct *handle, const char *path,
1343                         uid_t uid, gid_t gid)
1344 {
1345         VFS_FIND(lchown);
1346         return handle->fns->lchown(handle, path, uid, gid);
1347 }
1348
1349 int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path)
1350 {
1351         VFS_FIND(chdir);
1352         return handle->fns->chdir(handle, path);
1353 }
1354
1355 char *smb_vfs_call_getwd(struct vfs_handle_struct *handle, char *buf)
1356 {
1357         VFS_FIND(getwd);
1358         return handle->fns->getwd(handle, buf);
1359 }
1360
1361 int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
1362                         const struct smb_filename *smb_fname,
1363                         struct smb_file_time *ft)
1364 {
1365         VFS_FIND(ntimes);
1366         return handle->fns->ntimes(handle, smb_fname, ft);
1367 }
1368
1369 int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
1370                            struct files_struct *fsp, SMB_OFF_T offset)
1371 {
1372         VFS_FIND(ftruncate);
1373         return handle->fns->ftruncate(handle, fsp, offset);
1374 }
1375
1376 int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
1377                               struct files_struct *fsp, uint32 share_mode)
1378 {
1379         VFS_FIND(kernel_flock);
1380         return handle->fns->kernel_flock(handle, fsp, share_mode);
1381 }
1382
1383 int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
1384                                 struct files_struct *fsp, int leasetype)
1385 {
1386         VFS_FIND(linux_setlease);
1387         return handle->fns->linux_setlease(handle, fsp, leasetype);
1388 }
1389
1390 int smb_vfs_call_symlink(struct vfs_handle_struct *handle, const char *oldpath,
1391                          const char *newpath)
1392 {
1393         VFS_FIND(symlink);
1394         return handle->fns->symlink(handle, oldpath, newpath);
1395 }
1396
1397 int smb_vfs_call_vfs_readlink(struct vfs_handle_struct *handle,
1398                               const char *path, char *buf, size_t bufsiz)
1399 {
1400         VFS_FIND(vfs_readlink);
1401         return handle->fns->vfs_readlink(handle, path, buf, bufsiz);
1402 }
1403
1404 int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
1405                       const char *newpath)
1406 {
1407         VFS_FIND(link);
1408         return handle->fns->link(handle, oldpath, newpath);
1409 }
1410
1411 int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
1412                        mode_t mode, SMB_DEV_T dev)
1413 {
1414         VFS_FIND(mknod);
1415         return handle->fns->mknod(handle, path, mode, dev);
1416 }
1417
1418 char *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
1419                             const char *path, char *resolved_path)
1420 {
1421         VFS_FIND(realpath);
1422         return handle->fns->realpath(handle, path, resolved_path);
1423 }
1424
1425 NTSTATUS smb_vfs_call_notify_watch(struct vfs_handle_struct *handle,
1426                                    struct sys_notify_context *ctx,
1427                                    struct notify_entry *e,
1428                                    void (*callback)(struct sys_notify_context *ctx,
1429                                                     void *private_data,
1430                                                     struct notify_event *ev),
1431                                    void *private_data, void *handle_p)
1432 {
1433         VFS_FIND(notify_watch);
1434         return handle->fns->notify_watch(handle, ctx, e, callback,
1435                                          private_data, handle_p);
1436 }
1437
1438 int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
1439                          unsigned int flags)
1440 {
1441         VFS_FIND(chflags);
1442         return handle->fns->chflags(handle, path, flags);
1443 }
1444
1445 struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
1446                                            const SMB_STRUCT_STAT *sbuf)
1447 {
1448         VFS_FIND(file_id_create);
1449         return handle->fns->file_id_create(handle, sbuf);
1450 }
1451
1452 NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle,
1453                                  struct files_struct *fsp,
1454                                  const char *fname,
1455                                  TALLOC_CTX *mem_ctx,
1456                                  unsigned int *num_streams,
1457                                  struct stream_struct **streams)
1458 {
1459         VFS_FIND(streaminfo);
1460         return handle->fns->streaminfo(handle, fsp, fname, mem_ctx,
1461                                        num_streams, streams);
1462 }
1463
1464 int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle,
1465                                    const char *path, const char *name,
1466                                    TALLOC_CTX *mem_ctx, char **found_name)
1467 {
1468         VFS_FIND(get_real_filename);
1469         return handle->fns->get_real_filename(handle, path, name, mem_ctx,
1470                                               found_name);
1471 }
1472
1473 const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
1474                                      const char *filename)
1475 {
1476         VFS_FIND(connectpath);
1477         return handle->fns->connectpath(handle, filename);
1478 }
1479
1480 bool smb_vfs_call_strict_lock(struct vfs_handle_struct *handle,
1481                               struct files_struct *fsp,
1482                               struct lock_struct *plock)
1483 {
1484         VFS_FIND(strict_lock);
1485         return handle->fns->strict_lock(handle, fsp, plock);
1486 }
1487
1488 void smb_vfs_call_strict_unlock(struct vfs_handle_struct *handle,
1489                                 struct files_struct *fsp,
1490                                 struct lock_struct *plock)
1491 {
1492         VFS_FIND(strict_unlock);
1493         return handle->fns->strict_unlock(handle, fsp, plock);
1494 }
1495
1496 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
1497                                   struct files_struct *fsp,
1498                                   uint32 security_info,
1499                                   struct security_descriptor **ppdesc)
1500 {
1501         VFS_FIND(fget_nt_acl);
1502         return handle->fns->fget_nt_acl(handle, fsp, security_info,
1503                                         ppdesc);
1504 }
1505
1506 NTSTATUS smb_vfs_call_get_nt_acl(struct vfs_handle_struct *handle,
1507                                  const char *name,
1508                                  uint32 security_info,
1509                                  struct security_descriptor **ppdesc)
1510 {
1511         VFS_FIND(get_nt_acl);
1512         return handle->fns->get_nt_acl(handle, name, security_info, ppdesc);
1513 }
1514
1515 NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
1516                                   struct files_struct *fsp,
1517                                   uint32 security_info_sent,
1518                                   const struct security_descriptor *psd)
1519 {
1520         VFS_FIND(fset_nt_acl);
1521         return handle->fns->fset_nt_acl(handle, fsp, security_info_sent, psd);
1522 }
1523
1524 int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, const char *name,
1525                            mode_t mode)
1526 {
1527         VFS_FIND(chmod_acl);
1528         return handle->fns->chmod_acl(handle, name, mode);
1529 }
1530
1531 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
1532                             struct files_struct *fsp, mode_t mode)
1533 {
1534         VFS_FIND(fchmod_acl);
1535         return handle->fns->fchmod_acl(handle, fsp, mode);
1536 }
1537
1538 int smb_vfs_call_sys_acl_get_entry(struct vfs_handle_struct *handle,
1539                                    SMB_ACL_T theacl, int entry_id,
1540                                    SMB_ACL_ENTRY_T *entry_p)
1541 {
1542         VFS_FIND(sys_acl_get_entry);
1543         return handle->fns->sys_acl_get_entry(handle, theacl, entry_id,
1544                                               entry_p);
1545 }
1546
1547 int smb_vfs_call_sys_acl_get_tag_type(struct vfs_handle_struct *handle,
1548                                       SMB_ACL_ENTRY_T entry_d,
1549                                       SMB_ACL_TAG_T *tag_type_p)
1550 {
1551         VFS_FIND(sys_acl_get_tag_type);
1552         return handle->fns->sys_acl_get_tag_type(handle, entry_d, tag_type_p);
1553 }
1554
1555 int smb_vfs_call_sys_acl_get_permset(struct vfs_handle_struct *handle,
1556                                      SMB_ACL_ENTRY_T entry_d,
1557                                      SMB_ACL_PERMSET_T *permset_p)
1558 {
1559         VFS_FIND(sys_acl_get_permset);
1560         return handle->fns->sys_acl_get_permset(handle, entry_d, permset_p);
1561 }
1562
1563 void * smb_vfs_call_sys_acl_get_qualifier(struct vfs_handle_struct *handle,
1564                                           SMB_ACL_ENTRY_T entry_d)
1565 {
1566         VFS_FIND(sys_acl_get_qualifier);
1567         return handle->fns->sys_acl_get_qualifier(handle, entry_d);
1568 }
1569
1570 SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
1571                                         const char *path_p,
1572                                         SMB_ACL_TYPE_T type)
1573 {
1574         VFS_FIND(sys_acl_get_file);
1575         return handle->fns->sys_acl_get_file(handle, path_p, type);
1576 }
1577
1578 SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
1579                                       struct files_struct *fsp)
1580 {
1581         VFS_FIND(sys_acl_get_fd);
1582         return handle->fns->sys_acl_get_fd(handle, fsp);
1583 }
1584
1585 int smb_vfs_call_sys_acl_clear_perms(struct vfs_handle_struct *handle,
1586                                      SMB_ACL_PERMSET_T permset)
1587 {
1588         VFS_FIND(sys_acl_clear_perms);
1589         return handle->fns->sys_acl_clear_perms(handle, permset);
1590 }
1591
1592 int smb_vfs_call_sys_acl_add_perm(struct vfs_handle_struct *handle,
1593                                   SMB_ACL_PERMSET_T permset,
1594                                   SMB_ACL_PERM_T perm)
1595 {
1596         VFS_FIND(sys_acl_add_perm);
1597         return handle->fns->sys_acl_add_perm(handle, permset, perm);
1598 }
1599
1600 char * smb_vfs_call_sys_acl_to_text(struct vfs_handle_struct *handle,
1601                                     SMB_ACL_T theacl, ssize_t *plen)
1602 {
1603         VFS_FIND(sys_acl_to_text);
1604         return handle->fns->sys_acl_to_text(handle, theacl, plen);
1605 }
1606
1607 SMB_ACL_T smb_vfs_call_sys_acl_init(struct vfs_handle_struct *handle,
1608                                     int count)
1609 {
1610         VFS_FIND(sys_acl_init);
1611         return handle->fns->sys_acl_init(handle, count);
1612 }
1613
1614 int smb_vfs_call_sys_acl_create_entry(struct vfs_handle_struct *handle,
1615                                       SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
1616 {
1617         VFS_FIND(sys_acl_create_entry);
1618         return handle->fns->sys_acl_create_entry(handle, pacl, pentry);
1619 }
1620
1621 int smb_vfs_call_sys_acl_set_tag_type(struct vfs_handle_struct *handle,
1622                                       SMB_ACL_ENTRY_T entry,
1623                                       SMB_ACL_TAG_T tagtype)
1624 {
1625         VFS_FIND(sys_acl_set_tag_type);
1626         return handle->fns->sys_acl_set_tag_type(handle, entry, tagtype);
1627 }
1628
1629 int smb_vfs_call_sys_acl_set_qualifier(struct vfs_handle_struct *handle,
1630                                        SMB_ACL_ENTRY_T entry, void *qual)
1631 {
1632         VFS_FIND(sys_acl_set_qualifier);
1633         return handle->fns->sys_acl_set_qualifier(handle, entry, qual);
1634 }
1635
1636 int smb_vfs_call_sys_acl_set_permset(struct vfs_handle_struct *handle,
1637                                      SMB_ACL_ENTRY_T entry,
1638                                      SMB_ACL_PERMSET_T permset)
1639 {
1640         VFS_FIND(sys_acl_set_permset);
1641         return handle->fns->sys_acl_set_permset(handle, entry, permset);
1642 }
1643
1644 int smb_vfs_call_sys_acl_valid(struct vfs_handle_struct *handle,
1645                                SMB_ACL_T theacl)
1646 {
1647         VFS_FIND(sys_acl_valid);
1648         return handle->fns->sys_acl_valid(handle, theacl);
1649 }
1650
1651 int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
1652                                   const char *name, SMB_ACL_TYPE_T acltype,
1653                                   SMB_ACL_T theacl)
1654 {
1655         VFS_FIND(sys_acl_set_file);
1656         return handle->fns->sys_acl_set_file(handle, name, acltype, theacl);
1657 }
1658
1659 int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
1660                                 struct files_struct *fsp, SMB_ACL_T theacl)
1661 {
1662         VFS_FIND(sys_acl_set_fd);
1663         return handle->fns->sys_acl_set_fd(handle, fsp, theacl);
1664 }
1665
1666 int smb_vfs_call_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
1667                                          const char *path)
1668 {
1669         VFS_FIND(sys_acl_delete_def_file);
1670         return handle->fns->sys_acl_delete_def_file(handle, path);
1671 }
1672
1673 int smb_vfs_call_sys_acl_get_perm(struct vfs_handle_struct *handle,
1674                                   SMB_ACL_PERMSET_T permset,
1675                                   SMB_ACL_PERM_T perm)
1676 {
1677         VFS_FIND(sys_acl_get_perm);
1678         return handle->fns->sys_acl_get_perm(handle, permset, perm);
1679 }
1680
1681 int smb_vfs_call_sys_acl_free_text(struct vfs_handle_struct *handle,
1682                                    char *text)
1683 {
1684         VFS_FIND(sys_acl_free_text);
1685         return handle->fns->sys_acl_free_text(handle, text);
1686 }
1687
1688 int smb_vfs_call_sys_acl_free_acl(struct vfs_handle_struct *handle,
1689                                   SMB_ACL_T posix_acl)
1690 {
1691         VFS_FIND(sys_acl_free_acl);
1692         return handle->fns->sys_acl_free_acl(handle, posix_acl);
1693 }
1694
1695 int smb_vfs_call_sys_acl_free_qualifier(struct vfs_handle_struct *handle,
1696                                         void *qualifier, SMB_ACL_TAG_T tagtype)
1697 {
1698         VFS_FIND(sys_acl_free_qualifier);
1699         return handle->fns->sys_acl_free_qualifier(handle, qualifier, tagtype);
1700 }
1701
1702 ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
1703                               const char *path, const char *name, void *value,
1704                               size_t size)
1705 {
1706         VFS_FIND(getxattr);
1707         return handle->fns->getxattr(handle, path, name, value, size);
1708 }
1709
1710 ssize_t smb_vfs_call_lgetxattr(struct vfs_handle_struct *handle,
1711                                const char *path, const char *name, void *value,
1712                                size_t size)
1713 {
1714         VFS_FIND(lgetxattr);
1715         return handle->fns->lgetxattr(handle, path, name, value, size);
1716 }
1717
1718 ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
1719                                struct files_struct *fsp, const char *name,
1720                                void *value, size_t size)
1721 {
1722         VFS_FIND(fgetxattr);
1723         return handle->fns->fgetxattr(handle, fsp, name, value, size);
1724 }
1725
1726 ssize_t smb_vfs_call_listxattr(struct vfs_handle_struct *handle,
1727                                const char *path, char *list, size_t size)
1728 {
1729         VFS_FIND(listxattr);
1730         return handle->fns->listxattr(handle, path, list, size);
1731 }
1732
1733 ssize_t smb_vfs_call_llistxattr(struct vfs_handle_struct *handle,
1734                                 const char *path, char *list, size_t size)
1735 {
1736         VFS_FIND(llistxattr);
1737         return handle->fns->llistxattr(handle, path, list, size);
1738 }
1739
1740 ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
1741                                 struct files_struct *fsp, char *list,
1742                                 size_t size)
1743 {
1744         VFS_FIND(flistxattr);
1745         return handle->fns->flistxattr(handle, fsp, list, size);
1746 }
1747
1748 int smb_vfs_call_removexattr(struct vfs_handle_struct *handle,
1749                              const char *path, const char *name)
1750 {
1751         VFS_FIND(removexattr);
1752         return handle->fns->removexattr(handle, path, name);
1753 }
1754
1755 int smb_vfs_call_lremovexattr(struct vfs_handle_struct *handle,
1756                               const char *path, const char *name)
1757 {
1758         VFS_FIND(lremovexattr);
1759         return handle->fns->lremovexattr(handle, path, name);
1760 }
1761
1762 int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
1763                               struct files_struct *fsp, const char *name)
1764 {
1765         VFS_FIND(fremovexattr);
1766         return handle->fns->fremovexattr(handle, fsp, name);
1767 }
1768
1769 int smb_vfs_call_setxattr(struct vfs_handle_struct *handle, const char *path,
1770                           const char *name, const void *value, size_t size,
1771                           int flags)
1772 {
1773         VFS_FIND(setxattr);
1774         return handle->fns->setxattr(handle, path, name, value, size, flags);
1775 }
1776
1777 int smb_vfs_call_lsetxattr(struct vfs_handle_struct *handle, const char *path,
1778                            const char *name, const void *value, size_t size,
1779                            int flags)
1780 {
1781         VFS_FIND(lsetxattr);
1782         return handle->fns->lsetxattr(handle, path, name, value, size, flags);
1783 }
1784
1785 int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
1786                            struct files_struct *fsp, const char *name,
1787                            const void *value, size_t size, int flags)
1788 {
1789         VFS_FIND(fsetxattr);
1790         return handle->fns->fsetxattr(handle, fsp, name, value, size, flags);
1791 }
1792
1793 int smb_vfs_call_aio_read(struct vfs_handle_struct *handle,
1794                           struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1795 {
1796         VFS_FIND(aio_read);
1797         return handle->fns->aio_read(handle, fsp, aiocb);
1798 }
1799
1800 int smb_vfs_call_aio_write(struct vfs_handle_struct *handle,
1801                            struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1802 {
1803         VFS_FIND(aio_write);
1804         return handle->fns->aio_write(handle, fsp, aiocb);
1805 }
1806
1807 ssize_t smb_vfs_call_aio_return_fn(struct vfs_handle_struct *handle,
1808                                    struct files_struct *fsp,
1809                                    SMB_STRUCT_AIOCB *aiocb)
1810 {
1811         VFS_FIND(aio_return_fn);
1812         return handle->fns->aio_return_fn(handle, fsp, aiocb);
1813 }
1814
1815 int smb_vfs_call_aio_cancel(struct vfs_handle_struct *handle,
1816                             struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
1817 {
1818         VFS_FIND(aio_cancel);
1819         return handle->fns->aio_cancel(handle, fsp, aiocb);
1820 }
1821
1822 int smb_vfs_call_aio_error_fn(struct vfs_handle_struct *handle,
1823                               struct files_struct *fsp,
1824                               SMB_STRUCT_AIOCB *aiocb)
1825 {
1826         VFS_FIND(aio_error_fn);
1827         return handle->fns->aio_error_fn(handle, fsp, aiocb);
1828 }
1829
1830 int smb_vfs_call_aio_fsync(struct vfs_handle_struct *handle,
1831                            struct files_struct *fsp, int op,
1832                            SMB_STRUCT_AIOCB *aiocb)
1833 {
1834         VFS_FIND(aio_fsync);
1835         return handle->fns->aio_fsync(handle, fsp, op, aiocb);
1836 }
1837
1838 int smb_vfs_call_aio_suspend(struct vfs_handle_struct *handle,
1839                              struct files_struct *fsp,
1840                              const SMB_STRUCT_AIOCB * const aiocb[], int n,
1841                              const struct timespec *timeout)
1842 {
1843         VFS_FIND(aio_suspend);
1844         return handle->fns->aio_suspend(handle, fsp, aiocb, n, timeout);
1845 }
1846
1847 bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
1848                             struct files_struct *fsp)
1849 {
1850         VFS_FIND(aio_force);
1851         return handle->fns->aio_force(handle, fsp);
1852 }
1853
1854 bool smb_vfs_call_is_offline(struct vfs_handle_struct *handle,
1855                              const char *path, SMB_STRUCT_STAT *sbuf)
1856 {
1857         VFS_FIND(is_offline);
1858         return handle->fns->is_offline(handle, path, sbuf);
1859 }
1860
1861 int smb_vfs_call_set_offline(struct vfs_handle_struct *handle,
1862                              const char *path)
1863 {
1864         VFS_FIND(set_offline);
1865         return handle->fns->set_offline(handle, path);
1866 }