LCOV - code coverage report
Current view: top level - source3/smbd - vfs.c (source / functions) Hit Total Coverage
Test: coverage report for master 6248eab5 Lines: 763 1085 70.3 %
Date: 2021-08-25 13:27:56 Functions: 125 138 90.6 %

          Line data    Source code
       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             :    Copyright (C) Volker Lendecke 2009
       9             : 
      10             :    This program is free software; you can redistribute it and/or modify
      11             :    it under the terms of the GNU General Public License as published by
      12             :    the Free Software Foundation; either version 3 of the License, or
      13             :    (at your option) any later version.
      14             : 
      15             :    This program is distributed in the hope that it will be useful,
      16             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      17             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      18             :    GNU General Public License for more details.
      19             : 
      20             :    You should have received a copy of the GNU General Public License
      21             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      22             : 
      23             :    This work was sponsored by Optifacio Software Services, Inc.
      24             : */
      25             : 
      26             : #include "includes.h"
      27             : #include "system/filesys.h"
      28             : #include "smbd/smbd.h"
      29             : #include "smbd/globals.h"
      30             : #include "../lib/util/memcache.h"
      31             : #include "transfer_file.h"
      32             : #include "ntioctl.h"
      33             : #include "lib/util/tevent_unix.h"
      34             : #include "lib/util/tevent_ntstatus.h"
      35             : #include "lib/util/sys_rw.h"
      36             : 
      37             : #undef DBGC_CLASS
      38             : #define DBGC_CLASS DBGC_VFS
      39             : 
      40             : static_decl_vfs;
      41             : 
      42             : struct vfs_fsp_data {
      43             :     struct vfs_fsp_data *next;
      44             :     struct vfs_handle_struct *owner;
      45             :     void (*destroy)(void *p_data);
      46             :     void *_dummy_;
      47             :     /* NOTE: This structure contains four pointers so that we can guarantee
      48             :      * that the end of the structure is always both 4-byte and 8-byte aligned.
      49             :      */
      50             : };
      51             : 
      52             : struct vfs_init_function_entry {
      53             :         char *name;
      54             :         struct vfs_init_function_entry *prev, *next;
      55             :         const struct vfs_fn_pointers *fns;
      56             : };
      57             : 
      58             : /****************************************************************************
      59             :     maintain the list of available backends
      60             : ****************************************************************************/
      61             : 
      62      655402 : static struct vfs_init_function_entry *vfs_find_backend_entry(const char *name)
      63             : {
      64      655402 :         struct vfs_init_function_entry *entry = backends;
      65             : 
      66      655402 :         DEBUG(10, ("vfs_find_backend_entry called for %s\n", name));
      67             : 
      68     3523887 :         while(entry) {
      69     2521088 :                 if (strcmp(entry->name, name)==0) return entry;
      70     2223136 :                 entry = entry->next;
      71             :         }
      72             : 
      73      351134 :         return NULL;
      74             : }
      75             : 
      76      222080 : NTSTATUS smb_register_vfs(int version, const char *name,
      77             :                           const struct vfs_fn_pointers *fns)
      78             : {
      79      222080 :         struct vfs_init_function_entry *entry = backends;
      80             : 
      81      222080 :         if ((version != SMB_VFS_INTERFACE_VERSION)) {
      82           0 :                 DEBUG(0, ("Failed to register vfs module.\n"
      83             :                           "The module was compiled against SMB_VFS_INTERFACE_VERSION %d,\n"
      84             :                           "current SMB_VFS_INTERFACE_VERSION is %d.\n"
      85             :                           "Please recompile against the current Samba Version!\n",  
      86             :                           version, SMB_VFS_INTERFACE_VERSION));
      87           0 :                 return NT_STATUS_OBJECT_TYPE_MISMATCH;
      88             :         }
      89             : 
      90      222080 :         if (!name || !name[0]) {
      91           0 :                 DEBUG(0,("smb_register_vfs() called with NULL pointer or empty name!\n"));
      92           0 :                 return NT_STATUS_INVALID_PARAMETER;
      93             :         }
      94             : 
      95      222080 :         if (vfs_find_backend_entry(name)) {
      96           0 :                 DEBUG(0,("VFS module %s already loaded!\n", name));
      97           0 :                 return NT_STATUS_OBJECT_NAME_COLLISION;
      98             :         }
      99             : 
     100      222080 :         entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
     101      222080 :         entry->name = smb_xstrdup(name);
     102      222080 :         entry->fns = fns;
     103             : 
     104      222080 :         DLIST_ADD(backends, entry);
     105      222080 :         DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
     106      222080 :         return NT_STATUS_OK;
     107             : }
     108             : 
     109             : /****************************************************************************
     110             :   initialise default vfs hooks
     111             : ****************************************************************************/
     112             : 
     113       46843 : static void vfs_init_default(connection_struct *conn)
     114             : {
     115       46843 :         DEBUG(3, ("Initialising default vfs hooks\n"));
     116       46843 :         vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
     117       46843 : }
     118             : 
     119             : /****************************************************************************
     120             :   initialise custom vfs hooks
     121             :  ****************************************************************************/
     122             : 
     123      297952 : bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
     124             : {
     125      297952 :         char *module_path = NULL;
     126      297952 :         char *module_name = NULL;
     127      297952 :         char *module_param = NULL, *p;
     128             :         vfs_handle_struct *handle;
     129             :         const struct vfs_init_function_entry *entry;
     130             : 
     131      297952 :         if (!conn||!vfs_object||!vfs_object[0]) {
     132           0 :                 DEBUG(0, ("vfs_init_custom() called with NULL pointer or "
     133             :                           "empty vfs_object!\n"));
     134           0 :                 return False;
     135             :         }
     136             : 
     137      297952 :         if(!backends) {
     138       25512 :                 static_init_vfs(NULL);
     139             :         }
     140             : 
     141      297952 :         DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
     142             : 
     143      297952 :         module_path = smb_xstrdup(vfs_object);
     144             : 
     145      297952 :         p = strchr_m(module_path, ':');
     146             : 
     147      297952 :         if (p) {
     148           0 :                 *p = 0;
     149           0 :                 module_param = p+1;
     150           0 :                 trim_char(module_param, ' ', ' ');
     151             :         }
     152             : 
     153      297952 :         trim_char(module_path, ' ', ' ');
     154             : 
     155      297952 :         module_name = smb_xstrdup(module_path);
     156             : 
     157      344795 :         if ((module_name[0] == '/') &&
     158       46843 :             (strcmp(module_path, DEFAULT_VFS_MODULE_NAME) != 0)) {
     159             : 
     160             :                 /*
     161             :                  * Extract the module name from the path. Just use the base
     162             :                  * name of the last path component.
     163             :                  */
     164             : 
     165           0 :                 SAFE_FREE(module_name);
     166           0 :                 module_name = smb_xstrdup(strrchr_m(module_path, '/')+1);
     167             : 
     168           0 :                 p = strchr_m(module_name, '.');
     169             : 
     170           0 :                 if (p != NULL) {
     171           0 :                         *p = '\0';
     172             :                 }
     173             :         }
     174             : 
     175             :         /* First, try to load the module with the new module system */
     176      297952 :         entry = vfs_find_backend_entry(module_name);
     177      297952 :         if (!entry) {
     178             :                 NTSTATUS status;
     179             : 
     180      135370 :                 DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
     181             :                           vfs_object));
     182             : 
     183      135370 :                 status = smb_load_module("vfs", module_path);
     184      135370 :                 if (!NT_STATUS_IS_OK(status)) {
     185           0 :                         DEBUG(0, ("error probing vfs module '%s': %s\n",
     186             :                                   module_path, nt_errstr(status)));
     187           0 :                         goto fail;
     188             :                 }
     189             : 
     190      135370 :                 entry = vfs_find_backend_entry(module_name);
     191      135370 :                 if (!entry) {
     192           0 :                         DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
     193           0 :                         goto fail;
     194             :                 }
     195             :         }
     196             : 
     197      297952 :         DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
     198             : 
     199      297952 :         handle = talloc_zero(conn, vfs_handle_struct);
     200      297952 :         if (!handle) {
     201           0 :                 DEBUG(0,("TALLOC_ZERO() failed!\n"));
     202           0 :                 goto fail;
     203             :         }
     204      297952 :         handle->conn = conn;
     205      297952 :         handle->fns = entry->fns;
     206      297952 :         if (module_param) {
     207           0 :                 handle->param = talloc_strdup(conn, module_param);
     208             :         }
     209      297952 :         DLIST_ADD(conn->vfs_handles, handle);
     210             : 
     211      297952 :         SAFE_FREE(module_path);
     212      297952 :         SAFE_FREE(module_name);
     213      294215 :         return True;
     214             : 
     215           0 :  fail:
     216           0 :         SAFE_FREE(module_path);
     217           0 :         SAFE_FREE(module_name);
     218           0 :         return False;
     219             : }
     220             : 
     221             : /*****************************************************************
     222             :  Allow VFS modules to extend files_struct with VFS-specific state.
     223             :  This will be ok for small numbers of extensions, but might need to
     224             :  be refactored if it becomes more widely used.
     225             : ******************************************************************/
     226             : 
     227             : #define EXT_DATA_AREA(e) ((uint8_t *)(e) + sizeof(struct vfs_fsp_data))
     228             : 
     229      222883 : void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
     230             :                                    files_struct *fsp, size_t ext_size,
     231             :                                    void (*destroy_fn)(void *p_data))
     232             : {
     233             :         struct vfs_fsp_data *ext;
     234             :         void * ext_data;
     235             : 
     236             :         /* Prevent VFS modules adding multiple extensions. */
     237      222883 :         if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
     238        1420 :                 return ext_data;
     239             :         }
     240             : 
     241      221463 :         ext = talloc_zero_size(
     242             :                 handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
     243      221463 :         if (ext == NULL) {
     244           0 :                 return NULL;
     245             :         }
     246             : 
     247      221463 :         ext->owner = handle;
     248      221463 :         ext->next = fsp->vfs_extension;
     249      221463 :         ext->destroy = destroy_fn;
     250      221463 :         fsp->vfs_extension = ext;
     251      221463 :         return EXT_DATA_AREA(ext);
     252             : }
     253             : 
     254      158775 : void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
     255             : {
     256             :         struct vfs_fsp_data *curr;
     257             :         struct vfs_fsp_data *prev;
     258             : 
     259      318548 :         for (curr = fsp->vfs_extension, prev = NULL;
     260             :              curr;
     261         998 :              prev = curr, curr = curr->next) {
     262      159773 :                 if (curr->owner == handle) {
     263      158775 :                     if (prev) {
     264         998 :                             prev->next = curr->next;
     265             :                     } else {
     266      157777 :                             fsp->vfs_extension = curr->next;
     267             :                     }
     268      158775 :                     if (curr->destroy) {
     269           4 :                             curr->destroy(EXT_DATA_AREA(curr));
     270             :                     }
     271      158775 :                     TALLOC_FREE(curr);
     272      158474 :                     return;
     273             :                 }
     274             :         }
     275             : }
     276             : 
     277    10580380 : void vfs_remove_all_fsp_extensions(files_struct *fsp)
     278             : {
     279             :         struct vfs_fsp_data *curr;
     280             :         struct vfs_fsp_data *next;
     281             : 
     282    10643022 :         for (curr = fsp->vfs_extension; curr; curr = next) {
     283             : 
     284       62642 :                 next = curr->next;
     285       62642 :                 fsp->vfs_extension = next;
     286             : 
     287       62642 :                 if (curr->destroy) {
     288        4318 :                         curr->destroy(EXT_DATA_AREA(curr));
     289             :                 }
     290       62642 :                 TALLOC_FREE(curr);
     291             :         }
     292    10580380 : }
     293             : 
     294      961737 : void *vfs_memctx_fsp_extension(vfs_handle_struct *handle,
     295             :                                const struct files_struct *fsp)
     296             : {
     297             :         struct vfs_fsp_data *head;
     298             : 
     299     1193769 :         for (head = fsp->vfs_extension; head; head = head->next) {
     300      587665 :                 if (head->owner == handle) {
     301      355199 :                         return head;
     302             :                 }
     303             :         }
     304             : 
     305      605799 :         return NULL;
     306             : }
     307             : 
     308      891640 : void *vfs_fetch_fsp_extension(vfs_handle_struct *handle,
     309             :                               const struct files_struct *fsp)
     310             : {
     311             :         struct vfs_fsp_data *head;
     312             : 
     313      891640 :         head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
     314      891640 :         if (head != NULL) {
     315      285536 :                 return EXT_DATA_AREA(head);
     316             :         }
     317             : 
     318      605799 :         return NULL;
     319             : }
     320             : 
     321             : #undef EXT_DATA_AREA
     322             : 
     323             : /*
     324             :  * Ensure this module catches all VFS functions.
     325             :  */
     326             : #ifdef DEVELOPER
     327       83670 : void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
     328             :                             const char *module)
     329             : {
     330       83670 :         bool missing_fn = false;
     331             :         unsigned int idx;
     332       83670 :         const uintptr_t *end = (const uintptr_t *)(fns + 1);
     333             : 
     334     8367000 :         for (idx = 0; ((const uintptr_t *)fns + idx) < end; idx++) {
     335     8283330 :                 if (*((const uintptr_t *)fns + idx) == 0) {
     336           0 :                         DBG_ERR("VFS function at index %d not implemented "
     337             :                                 "in module %s\n", idx, module);
     338           0 :                         missing_fn = true;
     339             :                 }
     340             :         }
     341             : 
     342       83670 :         if (missing_fn) {
     343           0 :                 smb_panic("Required VFS function not implemented in module.\n");
     344             :         }
     345       83670 : }
     346             : #else
     347             : void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
     348             :                             const char *module)
     349             : {
     350             : }
     351             : #endif
     352             : 
     353             : /*****************************************************************
     354             :  Generic VFS init.
     355             : ******************************************************************/
     356             : 
     357       46843 : bool smbd_vfs_init(connection_struct *conn)
     358             : {
     359             :         const char **vfs_objects;
     360       46843 :         unsigned int i = 0;
     361       46843 :         int j = 0;
     362             : 
     363             :         /* Normal share - initialise with disk access functions */
     364       46843 :         vfs_init_default(conn);
     365             : 
     366             :         /* No need to load vfs modules for printer connections */
     367       46843 :         if (conn->printer) {
     368          28 :                 return True;
     369             :         }
     370             : 
     371       46815 :         if (lp_widelinks(SNUM(conn))) {
     372             :                 /*
     373             :                  * As the widelinks logic is now moving into a
     374             :                  * vfs_widelinks module, we need to custom load
     375             :                  * it after the default module is initialized.
     376             :                  * That way no changes to smb.conf files are
     377             :                  * needed.
     378             :                  */
     379         208 :                 bool ok = vfs_init_custom(conn, "widelinks");
     380         208 :                 if (!ok) {
     381           0 :                         DBG_ERR("widelinks enabled and vfs_init_custom "
     382             :                                 "failed for vfs_widelinks module\n");
     383           0 :                         return false;
     384             :                 }
     385             :         }
     386             : 
     387       46815 :         vfs_objects = lp_vfs_objects(SNUM(conn));
     388             : 
     389             :         /* Override VFS functions if 'vfs object' was not specified*/
     390       46815 :         if (!vfs_objects || !vfs_objects[0])
     391          39 :                 return True;
     392             : 
     393      343811 :         for (i=0; vfs_objects[i] ;) {
     394      250901 :                 i++;
     395             :         }
     396             : 
     397      297677 :         for (j=i-1; j >= 0; j--) {
     398      250901 :                 if (!vfs_init_custom(conn, vfs_objects[j])) {
     399           0 :                         DEBUG(0, ("smbd_vfs_init: vfs_init_custom failed for %s\n", vfs_objects[j]));
     400           0 :                         return False;
     401             :                 }
     402             :         }
     403       46134 :         return True;
     404             : }
     405             : 
     406             : /*******************************************************************
     407             :  Check if a file exists in the vfs.
     408             : ********************************************************************/
     409             : 
     410          16 : NTSTATUS vfs_file_exist(connection_struct *conn, struct smb_filename *smb_fname)
     411             : {
     412             :         /* Only return OK if stat was successful and S_ISREG */
     413          32 :         if ((SMB_VFS_STAT(conn, smb_fname) != -1) &&
     414          16 :             S_ISREG(smb_fname->st.st_ex_mode)) {
     415          16 :                 return NT_STATUS_OK;
     416             :         }
     417             : 
     418           0 :         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
     419             : }
     420             : 
     421       15989 : bool vfs_valid_pread_range(off_t offset, size_t length)
     422             : {
     423       15989 :         return sys_valid_io_range(offset, length);
     424             : }
     425             : 
     426      175609 : bool vfs_valid_pwrite_range(off_t offset, size_t length)
     427             : {
     428             :         /*
     429             :          * See MAXFILESIZE in [MS-FSA] 2.1.5.3 Server Requests a Write
     430             :          */
     431             :         static const uint64_t maxfilesize = 0xfffffff0000;
     432             :         uint64_t last_byte_ofs;
     433             :         bool ok;
     434             : 
     435      175609 :         ok = sys_valid_io_range(offset, length);
     436      175609 :         if (!ok) {
     437          24 :                 return false;
     438             :         }
     439             : 
     440      175585 :         if (length == 0) {
     441         657 :                 return true;
     442             :         }
     443             : 
     444      174891 :         last_byte_ofs = offset + length;
     445      174891 :         if (last_byte_ofs > maxfilesize) {
     446           4 :                 return false;
     447             :         }
     448             : 
     449      174887 :         return true;
     450             : }
     451             : 
     452        3290 : ssize_t vfs_pwrite_data(struct smb_request *req,
     453             :                         files_struct *fsp,
     454             :                         const char *buffer,
     455             :                         size_t N,
     456             :                         off_t offset)
     457             : {
     458        3290 :         size_t total=0;
     459             :         ssize_t ret;
     460             :         bool ok;
     461             : 
     462        3290 :         ok = vfs_valid_pwrite_range(offset, N);
     463        3290 :         if (!ok) {
     464           0 :                 errno = EINVAL;
     465           0 :                 return -1;
     466             :         }
     467             : 
     468        3290 :         if (req && req->unread_bytes) {
     469           0 :                 int sockfd = req->xconn->transport.sock;
     470           0 :                 SMB_ASSERT(req->unread_bytes == N);
     471             :                 /* VFS_RECVFILE must drain the socket
     472             :                  * before returning. */
     473           0 :                 req->unread_bytes = 0;
     474             :                 /*
     475             :                  * Leave the socket non-blocking and
     476             :                  * use SMB_VFS_RECVFILE. If it returns
     477             :                  * EAGAIN || EWOULDBLOCK temporarily set
     478             :                  * the socket blocking and retry
     479             :                  * the RECVFILE.
     480             :                  */
     481           0 :                 while (total < N) {
     482           0 :                         ret = SMB_VFS_RECVFILE(sockfd,
     483             :                                                 fsp,
     484             :                                                 offset + total,
     485             :                                                 N - total);
     486           0 :                         if (ret == 0 || (ret == -1 &&
     487           0 :                                          (errno == EAGAIN ||
     488           0 :                                           errno == EWOULDBLOCK))) {
     489             :                                 int old_flags;
     490             :                                 /* Ensure the socket is blocking. */
     491           0 :                                 old_flags = fcntl(sockfd, F_GETFL, 0);
     492           0 :                                 if (set_blocking(sockfd, true) == -1) {
     493           0 :                                         return (ssize_t)-1;
     494             :                                 }
     495           0 :                                 ret = SMB_VFS_RECVFILE(sockfd,
     496             :                                                         fsp,
     497             :                                                         offset + total,
     498             :                                                         N - total);
     499           0 :                                 if (fcntl(sockfd, F_SETFL, old_flags) == -1) {
     500           0 :                                         return (ssize_t)-1;
     501             :                                 }
     502           0 :                                 if (ret == -1) {
     503           0 :                                         return (ssize_t)-1;
     504             :                                 }
     505           0 :                                 total += ret;
     506           0 :                                 return (ssize_t)total;
     507             :                         }
     508             :                         /* Any other error case. */
     509           0 :                         if (ret == -1) {
     510           0 :                                 return ret;
     511             :                         }
     512           0 :                         total += ret;
     513             :                 }
     514           0 :                 return (ssize_t)total;
     515             :         }
     516             : 
     517        7656 :         while (total < N) {
     518        3290 :                 ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total,
     519             :                                      offset + total);
     520             : 
     521        3290 :                 if (ret == -1)
     522        2202 :                         return -1;
     523        1088 :                 if (ret == 0)
     524           0 :                         return total;
     525             : 
     526        1088 :                 total += ret;
     527             :         }
     528        1088 :         return (ssize_t)total;
     529             : }
     530             : /****************************************************************************
     531             :  An allocate file space call using the vfs interface.
     532             :  Allocates space for a file from a filedescriptor.
     533             :  Returns 0 on success, -1 on failure.
     534             : ****************************************************************************/
     535             : 
     536         286 : int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
     537             : {
     538             :         int ret;
     539         286 :         connection_struct *conn = fsp->conn;
     540             :         uint64_t space_avail;
     541             :         uint64_t bsize,dfree,dsize;
     542             :         NTSTATUS status;
     543             :         bool ok;
     544             : 
     545             :         /*
     546             :          * Actually try and commit the space on disk....
     547             :          */
     548             : 
     549         286 :         DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
     550             :                   fsp_str_dbg(fsp), (double)len));
     551             : 
     552         286 :         ok = vfs_valid_pwrite_range((off_t)len, 0);
     553         286 :         if (!ok) {
     554           0 :                 DEBUG(0,("vfs_allocate_file_space: %s negative/invalid len "
     555             :                          "requested.\n", fsp_str_dbg(fsp)));
     556           0 :                 errno = EINVAL;
     557           0 :                 return -1;
     558             :         }
     559             : 
     560         286 :         status = vfs_stat_fsp(fsp);
     561         286 :         if (!NT_STATUS_IS_OK(status)) {
     562           0 :                 return -1;
     563             :         }
     564             : 
     565         286 :         if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
     566          44 :                 return 0;
     567             : 
     568         241 :         if (len < (uint64_t)fsp->fsp_name->st.st_ex_size) {
     569             :                 /* Shrink - use ftruncate. */
     570             : 
     571           6 :                 DEBUG(10,("vfs_allocate_file_space: file %s, shrink. Current "
     572             :                           "size %.0f\n", fsp_str_dbg(fsp),
     573             :                           (double)fsp->fsp_name->st.st_ex_size));
     574             : 
     575           6 :                 contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
     576             : 
     577           6 :                 ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len);
     578             : 
     579           6 :                 contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
     580             : 
     581           6 :                 return ret;
     582             :         }
     583             : 
     584             :         /* Grow - we need to test if we have enough space. */
     585             : 
     586         235 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
     587             : 
     588         235 :         if (lp_strict_allocate(SNUM(fsp->conn))) {
     589             :                 /* See if we have a syscall that will allocate beyond
     590             :                    end-of-file without changing EOF. */
     591           0 :                 ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
     592             :                                         0, len);
     593             :         } else {
     594         211 :                 ret = 0;
     595             :         }
     596             : 
     597         235 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
     598             : 
     599         235 :         if (ret == 0) {
     600             :                 /* We changed the allocation size on disk, but not
     601             :                    EOF - exactly as required. We're done ! */
     602         211 :                 return 0;
     603             :         }
     604             : 
     605           0 :         if (ret == -1 && errno == ENOSPC) {
     606           0 :                 return -1;
     607             :         }
     608             : 
     609           0 :         len -= fsp->fsp_name->st.st_ex_size;
     610           0 :         len /= 1024; /* Len is now number of 1k blocks needed. */
     611           0 :         space_avail =
     612           0 :             get_dfree_info(conn, fsp->fsp_name, &bsize, &dfree, &dsize);
     613           0 :         if (space_avail == (uint64_t)-1) {
     614           0 :                 return -1;
     615             :         }
     616             : 
     617           0 :         DEBUG(10,("vfs_allocate_file_space: file %s, grow. Current size %.0f, "
     618             :                   "needed blocks = %.0f, space avail = %.0f\n",
     619             :                   fsp_str_dbg(fsp), (double)fsp->fsp_name->st.st_ex_size, (double)len,
     620             :                   (double)space_avail));
     621             : 
     622           0 :         if (len > space_avail) {
     623           0 :                 errno = ENOSPC;
     624           0 :                 return -1;
     625             :         }
     626             : 
     627           0 :         return 0;
     628             : }
     629             : 
     630             : /****************************************************************************
     631             :  A vfs set_filelen call.
     632             :  set the length of a file from a filedescriptor.
     633             :  Returns 0 on success, -1 on failure.
     634             : ****************************************************************************/
     635             : 
     636         390 : int vfs_set_filelen(files_struct *fsp, off_t len)
     637             : {
     638             :         int ret;
     639             :         bool ok;
     640             : 
     641         390 :         ok = vfs_valid_pwrite_range(len, 0);
     642         390 :         if (!ok) {
     643           0 :                 errno = EINVAL;
     644           0 :                 return -1;
     645             :         }
     646             : 
     647         390 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
     648             : 
     649         390 :         DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
     650             :                   fsp_str_dbg(fsp), (double)len));
     651         390 :         if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
     652         382 :                 notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
     653             :                              FILE_NOTIFY_CHANGE_SIZE
     654             :                              | FILE_NOTIFY_CHANGE_ATTRIBUTES,
     655         382 :                              fsp->fsp_name->base_name);
     656             :         }
     657             : 
     658         390 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
     659             : 
     660         390 :         return ret;
     661             : }
     662             : 
     663             : /****************************************************************************
     664             :  A slow version of fallocate. Fallback code if SMB_VFS_FALLOCATE
     665             :  fails. Needs to be outside of the default version of SMB_VFS_FALLOCATE
     666             :  as this is also called from the default SMB_VFS_FTRUNCATE code.
     667             :  Always extends the file size.
     668             :  Returns 0 on success, -1 on failure.
     669             : ****************************************************************************/
     670             : 
     671             : #define SPARSE_BUF_WRITE_SIZE (32*1024)
     672             : 
     673           0 : int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
     674             : {
     675             :         ssize_t pwrite_ret;
     676           0 :         size_t total = 0;
     677             :         bool ok;
     678             : 
     679           0 :         ok = vfs_valid_pwrite_range(offset, len);
     680           0 :         if (!ok) {
     681           0 :                 errno = EINVAL;
     682           0 :                 return -1;
     683             :         }
     684             : 
     685           0 :         if (!sparse_buf) {
     686           0 :                 sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
     687           0 :                 if (!sparse_buf) {
     688           0 :                         errno = ENOMEM;
     689           0 :                         return -1;
     690             :                 }
     691             :         }
     692             : 
     693           0 :         while (total < len) {
     694           0 :                 size_t curr_write_size = MIN(SPARSE_BUF_WRITE_SIZE, (len - total));
     695             : 
     696           0 :                 pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
     697           0 :                 if (pwrite_ret == -1) {
     698           0 :                         int saved_errno = errno;
     699           0 :                         DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
     700             :                                   "%s failed with error %s\n",
     701             :                                   fsp_str_dbg(fsp), strerror(saved_errno)));
     702           0 :                         errno = saved_errno;
     703           0 :                         return -1;
     704             :                 }
     705           0 :                 total += pwrite_ret;
     706             :         }
     707             : 
     708           0 :         return 0;
     709             : }
     710             : 
     711             : /****************************************************************************
     712             :  A vfs fill sparse call.
     713             :  Writes zeros from the end of file to len, if len is greater than EOF.
     714             :  Used only by strict_sync.
     715             :  Returns 0 on success, -1 on failure.
     716             : ****************************************************************************/
     717             : 
     718           0 : int vfs_fill_sparse(files_struct *fsp, off_t len)
     719             : {
     720             :         int ret;
     721             :         NTSTATUS status;
     722             :         off_t offset;
     723             :         size_t num_to_write;
     724             :         bool ok;
     725             : 
     726           0 :         ok = vfs_valid_pwrite_range(len, 0);
     727           0 :         if (!ok) {
     728           0 :                 errno = EINVAL;
     729           0 :                 return -1;
     730             :         }
     731             : 
     732           0 :         status = vfs_stat_fsp(fsp);
     733           0 :         if (!NT_STATUS_IS_OK(status)) {
     734           0 :                 return -1;
     735             :         }
     736             : 
     737           0 :         if (len <= fsp->fsp_name->st.st_ex_size) {
     738           0 :                 return 0;
     739             :         }
     740             : 
     741             : #ifdef S_ISFIFO
     742           0 :         if (S_ISFIFO(fsp->fsp_name->st.st_ex_mode)) {
     743           0 :                 return 0;
     744             :         }
     745             : #endif
     746             : 
     747           0 :         DEBUG(10,("vfs_fill_sparse: write zeros in file %s from len %.0f to "
     748             :                   "len %.0f (%.0f bytes)\n", fsp_str_dbg(fsp),
     749             :                   (double)fsp->fsp_name->st.st_ex_size, (double)len,
     750             :                   (double)(len - fsp->fsp_name->st.st_ex_size)));
     751             : 
     752           0 :         contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
     753             : 
     754           0 :         offset = fsp->fsp_name->st.st_ex_size;
     755           0 :         num_to_write = len - fsp->fsp_name->st.st_ex_size;
     756             : 
     757             :         /* Only do this on non-stream file handles. */
     758           0 :         if (fsp->base_fsp == NULL) {
     759             :                 /* for allocation try fallocate first. This can fail on some
     760             :                  * platforms e.g. when the filesystem doesn't support it and no
     761             :                  * emulation is being done by the libc (like on AIX with JFS1). In that
     762             :                  * case we do our own emulation. fallocate implementations can
     763             :                  * return ENOTSUP or EINVAL in cases like that. */
     764           0 :                 ret = SMB_VFS_FALLOCATE(fsp, 0, offset, num_to_write);
     765           0 :                 if (ret == -1 && errno == ENOSPC) {
     766           0 :                         goto out;
     767             :                 }
     768           0 :                 if (ret == 0) {
     769           0 :                         goto out;
     770             :                 }
     771           0 :                 DEBUG(10,("vfs_fill_sparse: SMB_VFS_FALLOCATE failed with "
     772             :                         "error %d. Falling back to slow manual allocation\n", ret));
     773             :         }
     774             : 
     775           0 :         ret = vfs_slow_fallocate(fsp, offset, num_to_write);
     776             : 
     777           0 :  out:
     778             : 
     779           0 :         contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_FILL_SPARSE);
     780           0 :         return ret;
     781             : }
     782             : 
     783             : /*******************************************************************************
     784             :  Set a fd into blocking/nonblocking mode through VFS
     785             : *******************************************************************************/
     786             : 
     787      203686 : int vfs_set_blocking(files_struct *fsp, bool set)
     788             : {
     789             :         int val;
     790             : #ifdef O_NONBLOCK
     791             : #define FLAG_TO_SET O_NONBLOCK
     792             : #else
     793             : #ifdef SYSV
     794             : #define FLAG_TO_SET O_NDELAY
     795             : #else /* BSD */
     796             : #define FLAG_TO_SET FNDELAY
     797             : #endif
     798             : #endif
     799             : 
     800      203686 :         if (fsp->fsp_flags.is_pathref) {
     801           0 :                 return 0;
     802             :         }
     803             : 
     804      203686 :         val = SMB_VFS_FCNTL(fsp, F_GETFL, 0);
     805      203686 :         if (val == -1) {
     806           0 :                 return -1;
     807             :         }
     808             : 
     809      203686 :         if (set) {
     810      203686 :                 val &= ~FLAG_TO_SET;
     811             :         } else {
     812           0 :                 val |= FLAG_TO_SET;
     813             :         }
     814             : 
     815      203686 :         return SMB_VFS_FCNTL(fsp, F_SETFL, val);
     816             : #undef FLAG_TO_SET
     817             : }
     818             : 
     819             : /****************************************************************************
     820             :  Transfer some data (n bytes) between two file_struct's.
     821             : ****************************************************************************/
     822             : 
     823          26 : static ssize_t vfs_pread_fn(void *file, void *buf, size_t len, off_t offset)
     824             : {
     825          26 :         struct files_struct *fsp = (struct files_struct *)file;
     826             : 
     827          26 :         return SMB_VFS_PREAD(fsp, buf, len, offset);
     828             : }
     829             : 
     830          26 : static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset)
     831             : {
     832          26 :         struct files_struct *fsp = (struct files_struct *)file;
     833             : 
     834          26 :         return SMB_VFS_PWRITE(fsp, buf, len, offset);
     835             : }
     836             : 
     837          26 : off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n)
     838             : {
     839          26 :         return transfer_file_internal((void *)in, (void *)out, n,
     840             :                                       vfs_pread_fn, vfs_pwrite_fn);
     841             : }
     842             : 
     843             : /*******************************************************************
     844             :  A vfs_readdir wrapper which just returns the file name.
     845             : ********************************************************************/
     846             : 
     847   207760450 : const char *vfs_readdirname(connection_struct *conn,
     848             :                             struct files_struct *dirfsp,
     849             :                             void *p,
     850             :                             SMB_STRUCT_STAT *sbuf,
     851             :                             char **talloced)
     852             : {
     853   207760450 :         struct dirent *ptr= NULL;
     854             :         const char *dname;
     855             :         char *translated;
     856             :         NTSTATUS status;
     857             : 
     858   207760450 :         if (!p)
     859           0 :                 return(NULL);
     860             : 
     861   207760450 :         ptr = SMB_VFS_READDIR(conn, dirfsp, (DIR *)p, sbuf);
     862   207760450 :         if (!ptr)
     863      310115 :                 return(NULL);
     864             : 
     865   207449575 :         dname = ptr->d_name;
     866             : 
     867   207449575 :         status = SMB_VFS_TRANSLATE_NAME(conn, dname, vfs_translate_to_windows,
     868             :                                         talloc_tos(), &translated);
     869   207449575 :         if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
     870   207434027 :                 *talloced = NULL;
     871   207434027 :                 return dname;
     872             :         }
     873       15548 :         *talloced = translated;
     874       15548 :         if (!NT_STATUS_IS_OK(status)) {
     875           0 :                 return NULL;
     876             :         }
     877       15548 :         return translated;
     878             : }
     879             : 
     880             : /*******************************************************************
     881             :  A wrapper for vfs_chdir().
     882             : ********************************************************************/
     883             : 
     884    14305290 : int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
     885             : {
     886             :         int ret;
     887    14305290 :         struct smb_filename *cwd = NULL;
     888             : 
     889    14305290 :         if (!LastDir) {
     890       25510 :                 LastDir = SMB_STRDUP("");
     891             :         }
     892             : 
     893    14305290 :         if (ISDOT(smb_fname->base_name)) {
     894             :                 /*
     895             :                  * passing a '.' is a noop,
     896             :                  * and we only expect this after
     897             :                  * everything is initialized.
     898             :                  *
     899             :                  * So the first vfs_ChDir() on a given
     900             :                  * connection_struct must not be '.'.
     901             :                  *
     902             :                  * Note: conn_new() sets
     903             :                  * conn->cwd_fsp->fh->fd = -1
     904             :                  * and vfs_ChDir() leaves with
     905             :                  * conn->cwd_fsp->fh->fd = AT_FDCWD
     906             :                  * on success!
     907             :                  */
     908           0 :                 if (fsp_get_pathref_fd(conn->cwd_fsp) != AT_FDCWD) {
     909             :                         /*
     910             :                          * This should never happen and
     911             :                          * we might change this to
     912             :                          * SMB_ASSERT() in future.
     913             :                          */
     914           0 :                         DBG_ERR("Called with '.' as first operation!\n");
     915           0 :                         log_stack_trace();
     916           0 :                         errno = EINVAL;
     917           0 :                         return -1;
     918             :                 }
     919           0 :                 return 0;
     920             :         }
     921             : 
     922    25958433 :         if (smb_fname->base_name[0] == '/' &&
     923    11653143 :             strcsequal(LastDir,smb_fname->base_name))
     924             :         {
     925             :                 /*
     926             :                  * conn->cwd_fsp->fsp_name and the kernel
     927             :                  * are already correct, but conn->cwd_fsp->fh->fd
     928             :                  * might still be -1 as initialized in conn_new().
     929             :                  *
     930             :                  * This can happen when a client made a 2nd
     931             :                  * tree connect to a share with the same underlying
     932             :                  * path (may or may not the same share).
     933             :                  */
     934     6416964 :                 fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
     935     6416964 :                 return 0;
     936             :         }
     937             : 
     938     7888326 :         DEBUG(4,("vfs_ChDir to %s\n", smb_fname->base_name));
     939             : 
     940     7888326 :         ret = SMB_VFS_CHDIR(conn, smb_fname);
     941     7888326 :         if (ret != 0) {
     942         614 :                 return -1;
     943             :         }
     944             : 
     945             :         /*
     946             :          * Always replace conn->cwd_fsp. We
     947             :          * don't know if it's been modified by
     948             :          * VFS modules in the stack.
     949             :          */
     950     7887712 :         fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
     951             : 
     952             :         /* conn cache. */
     953     7887712 :         cwd = vfs_GetWd(conn, conn);
     954     7887712 :         if (cwd == NULL) {
     955             :                 /*
     956             :                  * vfs_GetWd() failed.
     957             :                  * We must be able to read cwd.
     958             :                  * Return to original directory
     959             :                  * and return -1.
     960             :                  */
     961           0 :                 int saved_errno = errno;
     962             : 
     963           0 :                 if (conn->cwd_fsp->fsp_name == NULL) {
     964             :                         /*
     965             :                          * Failed on the very first chdir()+getwd()
     966             :                          * for this connection. We can't
     967             :                          * continue.
     968             :                          */
     969           0 :                         smb_panic("conn->cwd getwd failed\n");
     970             :                         /* NOTREACHED */
     971             :                         return -1;
     972             :                 }
     973             : 
     974             :                 /* Return to the previous $cwd. */
     975           0 :                 ret = SMB_VFS_CHDIR(conn, conn->cwd_fsp->fsp_name);
     976           0 :                 if (ret != 0) {
     977           0 :                         smb_panic("conn->cwd getwd failed\n");
     978             :                         /* NOTREACHED */
     979             :                         return -1;
     980             :                 }
     981           0 :                 errno = saved_errno;
     982             :                 /* And fail the chdir(). */
     983           0 :                 return -1;
     984             :         }
     985             : 
     986             :         /* vfs_GetWd() succeeded. */
     987             :         /* Replace global cache. */
     988     7887712 :         SAFE_FREE(LastDir);
     989     7887712 :         LastDir = SMB_STRDUP(smb_fname->base_name);
     990             : 
     991             :         /*
     992             :          * (Indirect) Callers of vfs_ChDir() may still hold references to the
     993             :          * old conn->cwd_fsp->fsp_name. Move it to talloc_tos(), that way
     994             :          * callers can use it for the lifetime of the SMB request.
     995             :          */
     996     7887712 :         talloc_move(talloc_tos(), &conn->cwd_fsp->fsp_name);
     997             : 
     998     7887712 :         conn->cwd_fsp->fsp_name = talloc_move(conn->cwd_fsp, &cwd);
     999             : 
    1000     7887712 :         DBG_INFO("vfs_ChDir got %s\n", fsp_str_dbg(conn->cwd_fsp));
    1001             : 
    1002     7823843 :         return ret;
    1003             : }
    1004             : 
    1005             : /*******************************************************************
    1006             :  Return the absolute current directory path - given a UNIX pathname.
    1007             :  Note that this path is returned in DOS format, not UNIX
    1008             :  format. Note this can be called with conn == NULL.
    1009             : ********************************************************************/
    1010             : 
    1011    14079621 : struct smb_filename *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
    1012             : {
    1013    14079621 :         struct smb_filename *current_dir_fname = NULL;
    1014             :         struct file_id key;
    1015    14079621 :         struct smb_filename *smb_fname_dot = NULL;
    1016    14079621 :         struct smb_filename *smb_fname_full = NULL;
    1017    14079621 :         struct smb_filename *result = NULL;
    1018             : 
    1019    14079621 :         if (!lp_getwd_cache()) {
    1020           0 :                 goto nocache;
    1021             :         }
    1022             : 
    1023    14079621 :         smb_fname_dot = synthetic_smb_fname(ctx,
    1024             :                                             ".",
    1025             :                                             NULL,
    1026             :                                             NULL,
    1027             :                                             0,
    1028             :                                             0);
    1029    14079621 :         if (smb_fname_dot == NULL) {
    1030           0 :                 errno = ENOMEM;
    1031           0 :                 goto out;
    1032             :         }
    1033             : 
    1034    14079621 :         if (SMB_VFS_STAT(conn, smb_fname_dot) == -1) {
    1035             :                 /*
    1036             :                  * Known to fail for root: the directory may be NFS-mounted
    1037             :                  * and exported with root_squash (so has no root access).
    1038             :                  */
    1039           0 :                 DEBUG(1,("vfs_GetWd: couldn't stat \".\" error %s "
    1040             :                          "(NFS problem ?)\n", strerror(errno) ));
    1041           0 :                 goto nocache;
    1042             :         }
    1043             : 
    1044    14079621 :         key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
    1045             : 
    1046    14079621 :         smb_fname_full = (struct smb_filename *)memcache_lookup_talloc(
    1047             :                                         smbd_memcache(),
    1048             :                                         GETWD_CACHE,
    1049             :                                         data_blob_const(&key, sizeof(key)));
    1050             : 
    1051    14079621 :         if (smb_fname_full == NULL) {
    1052      118626 :                 goto nocache;
    1053             :         }
    1054             : 
    1055    27918523 :         if ((SMB_VFS_STAT(conn, smb_fname_full) == 0) &&
    1056    27918334 :             (smb_fname_dot->st.st_ex_dev == smb_fname_full->st.st_ex_dev) &&
    1057    27918334 :             (smb_fname_dot->st.st_ex_ino == smb_fname_full->st.st_ex_ino) &&
    1058    13959167 :             (S_ISDIR(smb_fname_dot->st.st_ex_mode))) {
    1059             :                 /*
    1060             :                  * Ok, we're done
    1061             :                  * Note: smb_fname_full is owned by smbd_memcache()
    1062             :                  * so we must make a copy to return.
    1063             :                  */
    1064    13959167 :                 result = cp_smb_filename(ctx, smb_fname_full);
    1065    13959167 :                 if (result == NULL) {
    1066           0 :                         errno = ENOMEM;
    1067             :                 }
    1068    13845435 :                 goto out;
    1069             :         }
    1070             : 
    1071        1828 :  nocache:
    1072             : 
    1073             :         /*
    1074             :          * We don't have the information to hand so rely on traditional
    1075             :          * methods. The very slow getcwd, which spawns a process on some
    1076             :          * systems, or the not quite so bad getwd.
    1077             :          */
    1078             : 
    1079      120454 :         current_dir_fname = SMB_VFS_GETWD(conn, ctx);
    1080      120454 :         if (current_dir_fname == NULL) {
    1081           0 :                 DEBUG(0, ("vfs_GetWd: SMB_VFS_GETWD call failed: %s\n",
    1082             :                           strerror(errno)));
    1083           0 :                 goto out;
    1084             :         }
    1085             : 
    1086      120454 :         if (lp_getwd_cache() && VALID_STAT(smb_fname_dot->st)) {
    1087      120454 :                 key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
    1088             : 
    1089             :                 /*
    1090             :                  * smbd_memcache() will own current_dir_fname after the
    1091             :                  * memcache_add_talloc call, so we must make
    1092             :                  * a copy on ctx to return.
    1093             :                  */
    1094      120454 :                 result = cp_smb_filename(ctx, current_dir_fname);
    1095      120454 :                 if (result == NULL) {
    1096           0 :                         errno = ENOMEM;
    1097             :                 }
    1098             : 
    1099             :                 /*
    1100             :                  * Ensure the memory going into the cache
    1101             :                  * doesn't have a destructor so it can be
    1102             :                  * cleanly freed.
    1103             :                  */
    1104      120454 :                 talloc_set_destructor(current_dir_fname, NULL);
    1105             : 
    1106      120454 :                 memcache_add_talloc(smbd_memcache(),
    1107             :                                 GETWD_CACHE,
    1108             :                                 data_blob_const(&key, sizeof(key)),
    1109             :                                 &current_dir_fname);
    1110             :                 /* current_dir_fname is now == NULL here. */
    1111             :         } else {
    1112             :                 /* current_dir_fname is already allocated on ctx. */
    1113           0 :                 result = current_dir_fname;
    1114             :         }
    1115             : 
    1116    14079621 :  out:
    1117    14079621 :         TALLOC_FREE(smb_fname_dot);
    1118             :         /*
    1119             :          * Don't free current_dir_fname here. It's either been moved
    1120             :          * to the memcache or is being returned in result.
    1121             :          */
    1122    14079621 :         return result;
    1123             : }
    1124             : 
    1125             : /*******************************************************************
    1126             :  Reduce a file name, removing .. elements and checking that
    1127             :  it is below dir in the hierarchy. This uses realpath.
    1128             :  This function must run as root, and will return names
    1129             :  and valid stat structs that can be checked on open.
    1130             : ********************************************************************/
    1131             : 
    1132           0 : NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
    1133             :                         const struct smb_filename *smb_fname,
    1134             :                         struct smb_request *smbreq)
    1135             : {
    1136             :         NTSTATUS status;
    1137           0 :         TALLOC_CTX *ctx = talloc_tos();
    1138             :         const char *conn_rootdir;
    1139             :         size_t rootdir_len;
    1140           0 :         char *resolved_name = NULL;
    1141           0 :         struct smb_filename *resolved_fname = NULL;
    1142           0 :         struct smb_filename *saved_dir_fname = NULL;
    1143           0 :         struct smb_filename *smb_fname_cwd = NULL;
    1144             :         int ret;
    1145           0 :         struct smb_filename *parent_name = NULL;
    1146           0 :         struct smb_filename *file_name = NULL;
    1147             : 
    1148           0 :         DEBUG(3,("check_reduced_name_with_privilege [%s] [%s]\n",
    1149             :                         smb_fname->base_name,
    1150             :                         conn->connectpath));
    1151             : 
    1152           0 :         status = SMB_VFS_PARENT_PATHNAME(conn,
    1153             :                                          ctx,
    1154             :                                          smb_fname,
    1155             :                                          &parent_name,
    1156             :                                          &file_name);
    1157           0 :         if (!NT_STATUS_IS_OK(status)) {
    1158           0 :                 goto err;
    1159             :         }
    1160             : 
    1161           0 :         if (SMB_VFS_STAT(conn, parent_name) != 0) {
    1162           0 :                 status = map_nt_error_from_unix(errno);
    1163           0 :                 goto err;
    1164             :         }
    1165             :         /* Remember where we were. */
    1166           0 :         saved_dir_fname = vfs_GetWd(ctx, conn);
    1167           0 :         if (!saved_dir_fname) {
    1168           0 :                 status = map_nt_error_from_unix(errno);
    1169           0 :                 goto err;
    1170             :         }
    1171             : 
    1172           0 :         if (vfs_ChDir(conn, parent_name) == -1) {
    1173           0 :                 status = map_nt_error_from_unix(errno);
    1174           0 :                 goto err;
    1175             :         }
    1176             : 
    1177           0 :         smb_fname_cwd = synthetic_smb_fname(talloc_tos(),
    1178             :                                             ".",
    1179             :                                             NULL,
    1180             :                                             NULL,
    1181           0 :                                             parent_name->twrp,
    1182             :                                             0);
    1183           0 :         if (smb_fname_cwd == NULL) {
    1184           0 :                 status = NT_STATUS_NO_MEMORY;
    1185           0 :                 goto err;
    1186             :         }
    1187             : 
    1188             :         /* Get the absolute path of the parent directory. */
    1189           0 :         resolved_fname = SMB_VFS_REALPATH(conn, ctx, smb_fname_cwd);
    1190           0 :         if (resolved_fname == NULL) {
    1191           0 :                 status = map_nt_error_from_unix(errno);
    1192           0 :                 goto err;
    1193             :         }
    1194           0 :         resolved_name = resolved_fname->base_name;
    1195             : 
    1196           0 :         if (*resolved_name != '/') {
    1197           0 :                 DEBUG(0,("check_reduced_name_with_privilege: realpath "
    1198             :                         "doesn't return absolute paths !\n"));
    1199           0 :                 status = NT_STATUS_OBJECT_NAME_INVALID;
    1200           0 :                 goto err;
    1201             :         }
    1202             : 
    1203           0 :         DBG_DEBUG("realpath [%s] -> [%s]\n",
    1204             :                   smb_fname_str_dbg(parent_name),
    1205             :                   resolved_name);
    1206             : 
    1207             :         /* Now check the stat value is the same. */
    1208           0 :         if (SMB_VFS_LSTAT(conn, smb_fname_cwd) != 0) {
    1209           0 :                 status = map_nt_error_from_unix(errno);
    1210           0 :                 goto err;
    1211             :         }
    1212             : 
    1213             :         /* Ensure we're pointing at the same place. */
    1214           0 :         if (!check_same_stat(&smb_fname_cwd->st, &parent_name->st)) {
    1215           0 :                 DBG_ERR("device/inode/uid/gid on directory %s changed. "
    1216             :                         "Denying access !\n",
    1217             :                         smb_fname_str_dbg(parent_name));
    1218           0 :                 status = NT_STATUS_ACCESS_DENIED;
    1219           0 :                 goto err;
    1220             :         }
    1221             : 
    1222             :         /* Ensure we're below the connect path. */
    1223             : 
    1224           0 :         conn_rootdir = SMB_VFS_CONNECTPATH(conn, smb_fname);
    1225           0 :         if (conn_rootdir == NULL) {
    1226           0 :                 DEBUG(2, ("check_reduced_name_with_privilege: Could not get "
    1227             :                         "conn_rootdir\n"));
    1228           0 :                 status = NT_STATUS_ACCESS_DENIED;
    1229           0 :                 goto err;
    1230             :         }
    1231             : 
    1232           0 :         rootdir_len = strlen(conn_rootdir);
    1233             : 
    1234             :         /*
    1235             :          * In the case of rootdir_len == 1, we know that conn_rootdir is
    1236             :          * "/", and we also know that resolved_name starts with a slash.
    1237             :          * So, in this corner case, resolved_name is automatically a
    1238             :          * sub-directory of the conn_rootdir. Thus we can skip the string
    1239             :          * comparison and the next character checks (which are even
    1240             :          * wrong in this case).
    1241             :          */
    1242           0 :         if (rootdir_len != 1) {
    1243             :                 bool matched;
    1244             : 
    1245           0 :                 matched = (strncmp(conn_rootdir, resolved_name,
    1246             :                                 rootdir_len) == 0);
    1247             : 
    1248           0 :                 if (!matched || (resolved_name[rootdir_len] != '/' &&
    1249           0 :                                  resolved_name[rootdir_len] != '\0')) {
    1250           0 :                         DBG_WARNING("%s is a symlink outside the "
    1251             :                                     "share path\n",
    1252             :                                     smb_fname_str_dbg(parent_name));
    1253           0 :                         DEBUGADD(1, ("conn_rootdir =%s\n", conn_rootdir));
    1254           0 :                         DEBUGADD(1, ("resolved_name=%s\n", resolved_name));
    1255           0 :                         status = NT_STATUS_ACCESS_DENIED;
    1256           0 :                         goto err;
    1257             :                 }
    1258             :         }
    1259             : 
    1260             :         /* Now ensure that the last component either doesn't
    1261             :            exist, or is *NOT* a symlink. */
    1262             : 
    1263           0 :         ret = SMB_VFS_LSTAT(conn, file_name);
    1264           0 :         if (ret == -1) {
    1265             :                 /* Errno must be ENOENT for this be ok. */
    1266           0 :                 if (errno != ENOENT) {
    1267           0 :                         status = map_nt_error_from_unix(errno);
    1268           0 :                         DBG_WARNING("LSTAT on %s failed with %s\n",
    1269             :                                     smb_fname_str_dbg(file_name),
    1270             :                                     nt_errstr(status));
    1271           0 :                         goto err;
    1272             :                 }
    1273             :         }
    1274             : 
    1275           0 :         if (VALID_STAT(file_name->st) &&
    1276           0 :             S_ISLNK(file_name->st.st_ex_mode))
    1277             :         {
    1278           0 :                 DBG_WARNING("Last component %s is a symlink. Denying"
    1279             :                             "access.\n",
    1280             :                             smb_fname_str_dbg(file_name));
    1281           0 :                 status = NT_STATUS_ACCESS_DENIED;
    1282           0 :                 goto err;
    1283             :         }
    1284             : 
    1285           0 :         status = NT_STATUS_OK;
    1286             : 
    1287           0 :   err:
    1288             : 
    1289           0 :         if (saved_dir_fname != NULL) {
    1290           0 :                 vfs_ChDir(conn, saved_dir_fname);
    1291           0 :                 TALLOC_FREE(saved_dir_fname);
    1292             :         }
    1293           0 :         TALLOC_FREE(resolved_fname);
    1294           0 :         TALLOC_FREE(parent_name);
    1295           0 :         return status;
    1296             : }
    1297             : 
    1298             : /*******************************************************************
    1299             :  Reduce a file name, removing .. elements and checking that
    1300             :  it is below dir in the hierarchy. This uses realpath.
    1301             : 
    1302             :  If cwd_name == NULL then fname is a client given path relative
    1303             :  to the root path of the share.
    1304             : 
    1305             :  If cwd_name != NULL then fname is a client given path relative
    1306             :  to cwd_name. cwd_name is relative to the root path of the share.
    1307             : ********************************************************************/
    1308             : 
    1309    10568519 : NTSTATUS check_reduced_name(connection_struct *conn,
    1310             :                                 const struct smb_filename *cwd_fname,
    1311             :                                 const struct smb_filename *smb_fname)
    1312             : {
    1313    10568519 :         TALLOC_CTX *ctx = talloc_tos();
    1314    10568519 :         const char *cwd_name = cwd_fname ? cwd_fname->base_name : NULL;
    1315    10568519 :         const char *fname = smb_fname->base_name;
    1316             :         struct smb_filename *resolved_fname;
    1317    10568519 :         char *resolved_name = NULL;
    1318    10568519 :         char *new_fname = NULL;
    1319    10568519 :         bool allow_symlinks = true;
    1320             :         const char *conn_rootdir;
    1321             :         size_t rootdir_len;
    1322             : 
    1323    10568519 :         DBG_DEBUG("check_reduced_name [%s] [%s]\n", fname, conn->connectpath);
    1324             : 
    1325    10568519 :         resolved_fname = SMB_VFS_REALPATH(conn, ctx, smb_fname);
    1326             : 
    1327    10568519 :         if (resolved_fname == NULL) {
    1328             :                 NTSTATUS status;
    1329      475858 :                 struct smb_filename *dir_fname = NULL;
    1330      475858 :                 struct smb_filename *last_component = NULL;
    1331             : 
    1332      475858 :                 if (errno == ENOTDIR) {
    1333           0 :                         DBG_NOTICE("Component not a directory in getting "
    1334             :                                    "realpath for %s\n",
    1335             :                                    fname);
    1336         106 :                         return NT_STATUS_OBJECT_PATH_NOT_FOUND;
    1337             :                 }
    1338      475858 :                 if (errno != ENOENT) {
    1339           4 :                         status = map_nt_error_from_unix(errno);
    1340           4 :                         DBG_NOTICE("couldn't get realpath for %s: %s\n",
    1341             :                                    fname,
    1342             :                                    strerror(errno));
    1343           4 :                         return status;
    1344             :                 }
    1345             : 
    1346             :                 /* errno == ENOENT */
    1347             : 
    1348             :                 /*
    1349             :                  * Last component didn't exist. Remove it and try and
    1350             :                  * canonicalise the directory name.
    1351             :                  */
    1352             : 
    1353      475854 :                 status = SMB_VFS_PARENT_PATHNAME(conn,
    1354             :                                                  ctx,
    1355             :                                                  smb_fname,
    1356             :                                                  &dir_fname,
    1357             :                                                  &last_component);
    1358      475854 :                 if (!NT_STATUS_IS_OK(status)) {
    1359           0 :                         return status;
    1360             :                 }
    1361             : 
    1362      475854 :                 resolved_fname = SMB_VFS_REALPATH(conn, ctx, dir_fname);
    1363      475854 :                 if (resolved_fname == NULL) {
    1364         102 :                         status = map_nt_error_from_unix(errno);
    1365             : 
    1366         102 :                         if (errno == ENOENT || errno == ENOTDIR) {
    1367         102 :                                 status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
    1368             :                         }
    1369             : 
    1370         102 :                         DBG_NOTICE("couldn't get realpath for "
    1371             :                                    "%s (%s)\n",
    1372             :                                    smb_fname_str_dbg(dir_fname),
    1373             :                                    nt_errstr(status));
    1374         102 :                         return status;
    1375             :                 }
    1376      475752 :                 resolved_name = talloc_asprintf(ctx,
    1377             :                                                 "%s/%s",
    1378             :                                                 resolved_fname->base_name,
    1379      475752 :                                                 last_component->base_name);
    1380      475752 :                 if (resolved_name == NULL) {
    1381           0 :                         return NT_STATUS_NO_MEMORY;
    1382             :                 }
    1383             :         } else {
    1384    10092661 :                 resolved_name = resolved_fname->base_name;
    1385             :         }
    1386             : 
    1387    10568413 :         DEBUG(10,("check_reduced_name realpath [%s] -> [%s]\n", fname,
    1388             :                   resolved_name));
    1389             : 
    1390    10568413 :         if (*resolved_name != '/') {
    1391           0 :                 DEBUG(0,("check_reduced_name: realpath doesn't return "
    1392             :                          "absolute paths !\n"));
    1393           0 :                 TALLOC_FREE(resolved_fname);
    1394           0 :                 return NT_STATUS_OBJECT_NAME_INVALID;
    1395             :         }
    1396             : 
    1397             :         /* Common widelinks and symlinks checks. */
    1398    10568413 :         conn_rootdir = SMB_VFS_CONNECTPATH(conn, smb_fname);
    1399    10568413 :         if (conn_rootdir == NULL) {
    1400           0 :                 DBG_NOTICE("Could not get conn_rootdir\n");
    1401           0 :                 TALLOC_FREE(resolved_fname);
    1402           0 :                 return NT_STATUS_ACCESS_DENIED;
    1403             :         }
    1404             : 
    1405    10568413 :         rootdir_len = strlen(conn_rootdir);
    1406             : 
    1407             :         /*
    1408             :          * In the case of rootdir_len == 1, we know that
    1409             :          * conn_rootdir is "/", and we also know that
    1410             :          * resolved_name starts with a slash.  So, in this
    1411             :          * corner case, resolved_name is automatically a
    1412             :          * sub-directory of the conn_rootdir. Thus we can skip
    1413             :          * the string comparison and the next character checks
    1414             :          * (which are even wrong in this case).
    1415             :          */
    1416    10568413 :         if (rootdir_len != 1) {
    1417             :                 bool matched;
    1418             : 
    1419    10551376 :                 matched = (strncmp(conn_rootdir, resolved_name,
    1420             :                                 rootdir_len) == 0);
    1421    15371289 :                 if (!matched || (resolved_name[rootdir_len] != '/' &&
    1422     4819913 :                                  resolved_name[rootdir_len] != '\0')) {
    1423       61490 :                         DBG_NOTICE("Bad access attempt: %s is a symlink "
    1424             :                                 "outside the "
    1425             :                                 "share path\n"
    1426             :                                 "conn_rootdir =%s\n"
    1427             :                                 "resolved_name=%s\n",
    1428             :                                 fname,
    1429             :                                 conn_rootdir,
    1430             :                                 resolved_name);
    1431       61490 :                         TALLOC_FREE(resolved_fname);
    1432       61490 :                         return NT_STATUS_ACCESS_DENIED;
    1433             :                 }
    1434             :         }
    1435             : 
    1436             :         /* Extra checks if all symlinks are disallowed. */
    1437    10506923 :         allow_symlinks = lp_follow_symlinks(SNUM(conn));
    1438    10506923 :         if (!allow_symlinks) {
    1439             :                 /* fname can't have changed in resolved_path. */
    1440       12976 :                 const char *p = &resolved_name[rootdir_len];
    1441             : 
    1442             :                 /*
    1443             :                  * UNIX filesystem semantics, names consisting
    1444             :                  * only of "." or ".." CANNOT be symlinks.
    1445             :                  */
    1446       13890 :                 if (ISDOT(fname) || ISDOTDOT(fname)) {
    1447             :                         goto out;
    1448             :                 }
    1449             : 
    1450         914 :                 if (*p != '/') {
    1451           0 :                         DBG_NOTICE("logic error (%c) "
    1452             :                                 "in resolved_name: %s\n",
    1453             :                                 *p,
    1454             :                                 fname);
    1455           0 :                         TALLOC_FREE(resolved_fname);
    1456           0 :                         return NT_STATUS_ACCESS_DENIED;
    1457             :                 }
    1458             : 
    1459         914 :                 p++;
    1460             : 
    1461             :                 /*
    1462             :                  * If cwd_name is present and not ".",
    1463             :                  * then fname is relative to that, not
    1464             :                  * the root of the share. Make sure the
    1465             :                  * path we check is the one the client
    1466             :                  * sent (cwd_name+fname).
    1467             :                  */
    1468         914 :                 if (cwd_name != NULL && !ISDOT(cwd_name)) {
    1469         292 :                         new_fname = talloc_asprintf(ctx,
    1470             :                                                 "%s/%s",
    1471             :                                                 cwd_name,
    1472             :                                                 fname);
    1473         292 :                         if (new_fname == NULL) {
    1474           0 :                                 TALLOC_FREE(resolved_fname);
    1475           0 :                                 return NT_STATUS_NO_MEMORY;
    1476             :                         }
    1477         292 :                         fname = new_fname;
    1478             :                 }
    1479             : 
    1480         914 :                 if (strcmp(fname, p)!=0) {
    1481          40 :                         DBG_NOTICE("Bad access "
    1482             :                                 "attempt: %s is a symlink to %s\n",
    1483             :                                 fname,
    1484             :                                 p);
    1485          40 :                         TALLOC_FREE(resolved_fname);
    1486          40 :                         TALLOC_FREE(new_fname);
    1487          40 :                         return NT_STATUS_ACCESS_DENIED;
    1488             :                 }
    1489             :         }
    1490             : 
    1491    10506883 :   out:
    1492             : 
    1493    10506883 :         DBG_INFO("%s reduced to %s\n", fname, resolved_name);
    1494    10506883 :         TALLOC_FREE(resolved_fname);
    1495    10506883 :         TALLOC_FREE(new_fname);
    1496    10506883 :         return NT_STATUS_OK;
    1497             : }
    1498             : 
    1499             : /*
    1500             :  * Ensure LSTAT is called for POSIX paths.
    1501             :  */
    1502     1889202 : int vfs_stat(struct connection_struct *conn,
    1503             :              struct smb_filename *smb_fname)
    1504             : {
    1505     1889202 :         if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) {
    1506        1910 :                 return SMB_VFS_LSTAT(conn, smb_fname);
    1507             :         }
    1508     1887292 :         return SMB_VFS_STAT(conn, smb_fname);
    1509             : }
    1510             : 
    1511             : /**
    1512             :  * XXX: This is temporary and there should be no callers of this once
    1513             :  * smb_filename is plumbed through all path based operations.
    1514             :  *
    1515             :  * Called when we know stream name parsing has already been done.
    1516             :  */
    1517           0 : int vfs_stat_smb_basename(struct connection_struct *conn,
    1518             :                         const struct smb_filename *smb_fname_in,
    1519             :                         SMB_STRUCT_STAT *psbuf)
    1520             : {
    1521           0 :         struct smb_filename smb_fname = {
    1522           0 :                 .base_name = discard_const_p(char, smb_fname_in->base_name),
    1523           0 :                 .flags = smb_fname_in->flags,
    1524           0 :                 .twrp = smb_fname_in->twrp,
    1525             :         };
    1526             :         int ret;
    1527             : 
    1528           0 :         if (smb_fname.flags & SMB_FILENAME_POSIX_PATH) {
    1529           0 :                 ret = SMB_VFS_LSTAT(conn, &smb_fname);
    1530             :         } else {
    1531           0 :                 ret = SMB_VFS_STAT(conn, &smb_fname);
    1532             :         }
    1533             : 
    1534           0 :         if (ret != -1) {
    1535           0 :                 *psbuf = smb_fname.st;
    1536             :         }
    1537           0 :         return ret;
    1538             : }
    1539             : 
    1540             : /**
    1541             :  * Ensure LSTAT is called for POSIX paths.
    1542             :  */
    1543             : 
    1544     2713522 : NTSTATUS vfs_stat_fsp(files_struct *fsp)
    1545             : {
    1546             :         int ret;
    1547     2713522 :         struct stat_ex saved_stat = fsp->fsp_name->st;
    1548             : 
    1549     2713522 :         if (fsp_get_pathref_fd(fsp) == -1) {
    1550         118 :                 if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
    1551         118 :                         ret = SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
    1552             :                 } else {
    1553           0 :                         ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name);
    1554             :                 }
    1555             :         } else {
    1556     2713404 :                 ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
    1557             :         }
    1558     2713522 :         if (ret == -1) {
    1559           0 :                 return map_nt_error_from_unix(errno);
    1560             :         }
    1561     2713522 :         update_stat_ex_from_saved_stat(&fsp->fsp_name->st, &saved_stat);
    1562     2713522 :         return NT_STATUS_OK;
    1563             : }
    1564             : 
    1565      394949 : void init_smb_file_time(struct smb_file_time *ft)
    1566             : {
    1567      394949 :         *ft = (struct smb_file_time) {
    1568      394949 :                 .atime = make_omit_timespec(),
    1569      394949 :                 .ctime = make_omit_timespec(),
    1570      394949 :                 .mtime = make_omit_timespec(),
    1571      394949 :                 .create_time = make_omit_timespec()
    1572             :         };
    1573      394949 : }
    1574             : 
    1575             : /**
    1576             :  * Initialize num_streams and streams, then call VFS op streaminfo
    1577             :  */
    1578             : 
    1579      302873 : NTSTATUS vfs_fstreaminfo(struct files_struct *fsp,
    1580             :                         TALLOC_CTX *mem_ctx,
    1581             :                         unsigned int *num_streams,
    1582             :                         struct stream_struct **streams)
    1583             : {
    1584      302873 :         *num_streams = 0;
    1585      302873 :         *streams = NULL;
    1586             : 
    1587      302873 :         if (fsp == NULL) {
    1588             :                 /*
    1589             :                  * Callers may pass fsp == NULL when passing smb_fname->fsp of a
    1590             :                  * symlink. This is ok, handle it here, by just return no
    1591             :                  * streams on a symlink.
    1592             :                  */
    1593           8 :                 return NT_STATUS_OK;
    1594             :         }
    1595             : 
    1596      302865 :         if (fsp_get_pathref_fd(fsp) == -1) {
    1597             :                 /*
    1598             :                  * No streams on non-real files/directories.
    1599             :                  */
    1600         112 :                 return NT_STATUS_OK;
    1601             :         }
    1602             : 
    1603      302753 :         return SMB_VFS_FSTREAMINFO(fsp,
    1604             :                         mem_ctx,
    1605             :                         num_streams,
    1606             :                         streams);
    1607             : }
    1608             : 
    1609        4944 : int vfs_fake_fd(void)
    1610             : {
    1611             :         int pipe_fds[2];
    1612             :         int ret;
    1613             : 
    1614             :         /*
    1615             :          * Return a valid fd, but ensure any attempt to use
    1616             :          * it returns an error (EPIPE).
    1617             :          */
    1618        4944 :         ret = pipe(pipe_fds);
    1619        4944 :         if (ret != 0) {
    1620           0 :                 return -1;
    1621             :         }
    1622             : 
    1623        4944 :         close(pipe_fds[1]);
    1624        4944 :         return pipe_fds[0];
    1625             : }
    1626             : 
    1627             : /*
    1628             :  * This is just a helper to make
    1629             :  * users of vfs_fake_fd() more symetric
    1630             :  */
    1631        4944 : int vfs_fake_fd_close(int fd)
    1632             : {
    1633        4944 :         return close(fd);
    1634             : }
    1635             : 
    1636             : /*
    1637             :   generate a file_id from a stat structure
    1638             :  */
    1639    25927490 : struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf)
    1640             : {
    1641    25927490 :         return SMB_VFS_FILE_ID_CREATE(conn, sbuf);
    1642             : }
    1643             : 
    1644        9885 : NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
    1645             :                        struct connection_struct *conn,
    1646             :                        struct files_struct **_fsp)
    1647             : {
    1648        9885 :         struct files_struct *fsp = NULL;
    1649             : 
    1650        9885 :         fsp = talloc_zero(mem_ctx, struct files_struct);
    1651        9885 :         if (fsp == NULL) {
    1652           0 :                 return NT_STATUS_NO_MEMORY;
    1653             :         }
    1654             : 
    1655        9885 :         fsp->fsp_name = synthetic_smb_fname(fsp, ".", NULL, NULL, 0, 0);
    1656        9885 :         if (fsp->fsp_name == NULL) {
    1657           0 :                 TALLOC_FREE(fsp);
    1658           0 :                 return NT_STATUS_NO_MEMORY;
    1659             :         }
    1660             : 
    1661        9885 :         fsp->fh = fd_handle_create(fsp);
    1662        9885 :         if (fsp->fh == NULL) {
    1663           0 :                 TALLOC_FREE(fsp);
    1664           0 :                 return NT_STATUS_NO_MEMORY;
    1665             :         }
    1666             : 
    1667        9885 :         fsp_set_fd(fsp, AT_FDCWD);
    1668        9885 :         fsp->fnum = FNUM_FIELD_INVALID;
    1669        9885 :         fsp->conn = conn;
    1670             : 
    1671        9885 :         *_fsp = fsp;
    1672        9885 :         return NT_STATUS_OK;
    1673             : }
    1674             : 
    1675      254952 : int smb_vfs_call_connect(struct vfs_handle_struct *handle,
    1676             :                          const char *service, const char *user)
    1677             : {
    1678      254952 :         VFS_FIND(connect);
    1679      254952 :         return handle->fns->connect_fn(handle, service, user);
    1680             : }
    1681             : 
    1682      120490 : void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
    1683             : {
    1684      120490 :         VFS_FIND(disconnect);
    1685      120490 :         handle->fns->disconnect_fn(handle);
    1686      120490 : }
    1687             : 
    1688        3269 : uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
    1689             :                                 const struct smb_filename *smb_fname,
    1690             :                                 uint64_t *bsize,
    1691             :                                 uint64_t *dfree,
    1692             :                                 uint64_t *dsize)
    1693             : {
    1694        3269 :         VFS_FIND(disk_free);
    1695        3269 :         return handle->fns->disk_free_fn(handle, smb_fname,
    1696             :                         bsize, dfree, dsize);
    1697             : }
    1698             : 
    1699        6764 : int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
    1700             :                                 const struct smb_filename *smb_fname,
    1701             :                                 enum SMB_QUOTA_TYPE qtype,
    1702             :                                 unid_t id,
    1703             :                                 SMB_DISK_QUOTA *qt)
    1704             : {
    1705        6764 :         VFS_FIND(get_quota);
    1706        6764 :         return handle->fns->get_quota_fn(handle, smb_fname, qtype, id, qt);
    1707             : }
    1708             : 
    1709          12 : int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
    1710             :                            enum SMB_QUOTA_TYPE qtype, unid_t id,
    1711             :                            SMB_DISK_QUOTA *qt)
    1712             : {
    1713          12 :         VFS_FIND(set_quota);
    1714          12 :         return handle->fns->set_quota_fn(handle, qtype, id, qt);
    1715             : }
    1716             : 
    1717        3166 : int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
    1718             :                                       struct files_struct *fsp,
    1719             :                                       struct shadow_copy_data *shadow_copy_data,
    1720             :                                       bool labels)
    1721             : {
    1722        3166 :         VFS_FIND(get_shadow_copy_data);
    1723        3166 :         return handle->fns->get_shadow_copy_data_fn(handle, fsp, 
    1724             :                                                     shadow_copy_data,
    1725             :                                                     labels);
    1726             : }
    1727      108661 : int smb_vfs_call_statvfs(struct vfs_handle_struct *handle,
    1728             :                         const struct smb_filename *smb_fname,
    1729             :                         struct vfs_statvfs_struct *statbuf)
    1730             : {
    1731      108661 :         VFS_FIND(statvfs);
    1732      108661 :         return handle->fns->statvfs_fn(handle, smb_fname, statbuf);
    1733             : }
    1734             : 
    1735      151506 : uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
    1736             :                         enum timestamp_set_resolution *p_ts_res)
    1737             : {
    1738      151506 :         VFS_FIND(fs_capabilities);
    1739      151506 :         return handle->fns->fs_capabilities_fn(handle, p_ts_res);
    1740             : }
    1741             : 
    1742       26868 : NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
    1743             :                                         struct dfs_GetDFSReferral *r)
    1744             : {
    1745       26868 :         VFS_FIND(get_dfs_referrals);
    1746       26868 :         return handle->fns->get_dfs_referrals_fn(handle, r);
    1747             : }
    1748             : 
    1749           0 : NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle,
    1750             :                                 struct files_struct *dirfsp,
    1751             :                                 const struct smb_filename *smb_fname,
    1752             :                                 const struct referral *reflist,
    1753             :                                 size_t referral_count)
    1754             : {
    1755           0 :         VFS_FIND(create_dfs_pathat);
    1756           0 :         return handle->fns->create_dfs_pathat_fn(handle,
    1757             :                                                 dirfsp,
    1758             :                                                 smb_fname,
    1759             :                                                 reflist,
    1760             :                                                 referral_count);
    1761             : }
    1762             : 
    1763       50022 : NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle,
    1764             :                                 TALLOC_CTX *mem_ctx,
    1765             :                                 struct files_struct *dirfsp,
    1766             :                                 struct smb_filename *smb_fname,
    1767             :                                 struct referral **ppreflist,
    1768             :                                 size_t *preferral_count)
    1769             : {
    1770       50022 :         VFS_FIND(read_dfs_pathat);
    1771       50022 :         return handle->fns->read_dfs_pathat_fn(handle,
    1772             :                                                 mem_ctx,
    1773             :                                                 dirfsp,
    1774             :                                                 smb_fname,
    1775             :                                                 ppreflist,
    1776             :                                                 preferral_count);
    1777             : }
    1778             : 
    1779      613716 : DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
    1780             :                                         struct files_struct *fsp,
    1781             :                                         const char *mask,
    1782             :                                         uint32_t attributes)
    1783             : {
    1784      613716 :         VFS_FIND(fdopendir);
    1785      613716 :         return handle->fns->fdopendir_fn(handle, fsp, mask, attributes);
    1786             : }
    1787             : 
    1788   366574141 : struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
    1789             :                                     struct files_struct *dirfsp,
    1790             :                                     DIR *dirp,
    1791             :                                     SMB_STRUCT_STAT *sbuf)
    1792             : {
    1793   366574141 :         VFS_FIND(readdir);
    1794   366574141 :         return handle->fns->readdir_fn(handle, dirfsp, dirp, sbuf);
    1795             : }
    1796             : 
    1797        5654 : void smb_vfs_call_seekdir(struct vfs_handle_struct *handle,
    1798             :                           DIR *dirp, long offset)
    1799             : {
    1800        5654 :         VFS_FIND(seekdir);
    1801        5654 :         handle->fns->seekdir_fn(handle, dirp, offset);
    1802        5654 : }
    1803             : 
    1804   362359798 : long smb_vfs_call_telldir(struct vfs_handle_struct *handle,
    1805             :                           DIR *dirp)
    1806             : {
    1807   362359798 :         VFS_FIND(telldir);
    1808   362359798 :         return handle->fns->telldir_fn(handle, dirp);
    1809             : }
    1810             : 
    1811        2074 : void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
    1812             :                              DIR *dirp)
    1813             : {
    1814        2074 :         VFS_FIND(rewind_dir);
    1815        2074 :         handle->fns->rewind_dir_fn(handle, dirp);
    1816        2074 : }
    1817             : 
    1818       34268 : int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle,
    1819             :                         struct files_struct *dirfsp,
    1820             :                         const struct smb_filename *smb_fname,
    1821             :                         mode_t mode)
    1822             : {
    1823       34268 :         VFS_FIND(mkdirat);
    1824       34268 :         return handle->fns->mkdirat_fn(handle,
    1825             :                         dirfsp,
    1826             :                         smb_fname,
    1827             :                         mode);
    1828             : }
    1829             : 
    1830      613716 : int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
    1831             :                           DIR *dir)
    1832             : {
    1833      613716 :         VFS_FIND(closedir);
    1834      613716 :         return handle->fns->closedir_fn(handle, dir);
    1835             : }
    1836             : 
    1837    42120414 : int smb_vfs_call_openat(struct vfs_handle_struct *handle,
    1838             :                         const struct files_struct *dirfsp,
    1839             :                         const struct smb_filename *smb_fname,
    1840             :                         struct files_struct *fsp,
    1841             :                         int flags,
    1842             :                         mode_t mode)
    1843             : {
    1844    42120414 :         VFS_FIND(openat);
    1845    42120414 :         return handle->fns->openat_fn(handle,
    1846             :                                       dirfsp,
    1847             :                                       smb_fname,
    1848             :                                       fsp,
    1849             :                                       flags,
    1850             :                                       mode);
    1851             : }
    1852             : 
    1853     1050238 : NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
    1854             :                                   struct smb_request *req,
    1855             :                                   struct smb_filename *smb_fname,
    1856             :                                   uint32_t access_mask,
    1857             :                                   uint32_t share_access,
    1858             :                                   uint32_t create_disposition,
    1859             :                                   uint32_t create_options,
    1860             :                                   uint32_t file_attributes,
    1861             :                                   uint32_t oplock_request,
    1862             :                                   const struct smb2_lease *lease,
    1863             :                                   uint64_t allocation_size,
    1864             :                                   uint32_t private_flags,
    1865             :                                   struct security_descriptor *sd,
    1866             :                                   struct ea_list *ea_list,
    1867             :                                   files_struct **result,
    1868             :                                   int *pinfo,
    1869             :                                   const struct smb2_create_blobs *in_context_blobs,
    1870             :                                   struct smb2_create_blobs *out_context_blobs)
    1871             : {
    1872     1050238 :         VFS_FIND(create_file);
    1873     1050238 :         return handle->fns->create_file_fn(
    1874             :                 handle, req, smb_fname,
    1875             :                 access_mask, share_access, create_disposition, create_options,
    1876             :                 file_attributes, oplock_request, lease, allocation_size,
    1877             :                 private_flags, sd, ea_list,
    1878             :                 result, pinfo, in_context_blobs, out_context_blobs);
    1879             : }
    1880             : 
    1881    21312304 : int smb_vfs_call_close(struct vfs_handle_struct *handle,
    1882             :                        struct files_struct *fsp)
    1883             : {
    1884    21312304 :         VFS_FIND(close);
    1885    21312304 :         return handle->fns->close_fn(handle, fsp);
    1886             : }
    1887             : 
    1888       13294 : ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
    1889             :                            struct files_struct *fsp, void *data, size_t n,
    1890             :                            off_t offset)
    1891             : {
    1892       13294 :         VFS_FIND(pread);
    1893       13294 :         return handle->fns->pread_fn(handle, fsp, data, n, offset);
    1894             : }
    1895             : 
    1896             : struct smb_vfs_call_pread_state {
    1897             :         ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    1898             :         ssize_t retval;
    1899             :         struct vfs_aio_state vfs_aio_state;
    1900             : };
    1901             : 
    1902             : static void smb_vfs_call_pread_done(struct tevent_req *subreq);
    1903             : 
    1904       30489 : struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
    1905             :                                            TALLOC_CTX *mem_ctx,
    1906             :                                            struct tevent_context *ev,
    1907             :                                            struct files_struct *fsp,
    1908             :                                            void *data,
    1909             :                                            size_t n, off_t offset)
    1910             : {
    1911             :         struct tevent_req *req, *subreq;
    1912             :         struct smb_vfs_call_pread_state *state;
    1913             : 
    1914       30489 :         req = tevent_req_create(mem_ctx, &state,
    1915             :                                 struct smb_vfs_call_pread_state);
    1916       30489 :         if (req == NULL) {
    1917           0 :                 return NULL;
    1918             :         }
    1919       30657 :         VFS_FIND(pread_send);
    1920       30489 :         state->recv_fn = handle->fns->pread_recv_fn;
    1921             : 
    1922       30489 :         subreq = handle->fns->pread_send_fn(handle, state, ev, fsp, data, n,
    1923             :                                             offset);
    1924       30489 :         if (tevent_req_nomem(subreq, req)) {
    1925           0 :                 return tevent_req_post(req, ev);
    1926             :         }
    1927       30489 :         tevent_req_set_callback(subreq, smb_vfs_call_pread_done, req);
    1928       30489 :         return req;
    1929             : }
    1930             : 
    1931       30489 : static void smb_vfs_call_pread_done(struct tevent_req *subreq)
    1932             : {
    1933       30489 :         struct tevent_req *req = tevent_req_callback_data(
    1934             :                 subreq, struct tevent_req);
    1935       30489 :         struct smb_vfs_call_pread_state *state = tevent_req_data(
    1936             :                 req, struct smb_vfs_call_pread_state);
    1937             : 
    1938       30489 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    1939       30489 :         TALLOC_FREE(subreq);
    1940       30489 :         if (state->retval == -1) {
    1941           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    1942           0 :                 return;
    1943             :         }
    1944       30489 :         tevent_req_done(req);
    1945             : }
    1946             : 
    1947       30489 : ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req,
    1948             :                            struct vfs_aio_state *vfs_aio_state)
    1949             : {
    1950       30489 :         struct smb_vfs_call_pread_state *state = tevent_req_data(
    1951             :                 req, struct smb_vfs_call_pread_state);
    1952             :         ssize_t retval;
    1953             : 
    1954       30489 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    1955           0 :                 tevent_req_received(req);
    1956           0 :                 return -1;
    1957             :         }
    1958       30489 :         *vfs_aio_state = state->vfs_aio_state;
    1959       30489 :         retval = state->retval;
    1960       30489 :         tevent_req_received(req);
    1961       30489 :         return retval;
    1962             : }
    1963             : 
    1964        6124 : ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
    1965             :                             struct files_struct *fsp, const void *data,
    1966             :                             size_t n, off_t offset)
    1967             : {
    1968        6124 :         VFS_FIND(pwrite);
    1969        6124 :         return handle->fns->pwrite_fn(handle, fsp, data, n, offset);
    1970             : }
    1971             : 
    1972             : struct smb_vfs_call_pwrite_state {
    1973             :         ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    1974             :         ssize_t retval;
    1975             :         struct vfs_aio_state vfs_aio_state;
    1976             : };
    1977             : 
    1978             : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq);
    1979             : 
    1980      366737 : struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle,
    1981             :                                             TALLOC_CTX *mem_ctx,
    1982             :                                             struct tevent_context *ev,
    1983             :                                             struct files_struct *fsp,
    1984             :                                             const void *data,
    1985             :                                             size_t n, off_t offset)
    1986             : {
    1987             :         struct tevent_req *req, *subreq;
    1988             :         struct smb_vfs_call_pwrite_state *state;
    1989             : 
    1990      366737 :         req = tevent_req_create(mem_ctx, &state,
    1991             :                                 struct smb_vfs_call_pwrite_state);
    1992      366737 :         if (req == NULL) {
    1993           0 :                 return NULL;
    1994             :         }
    1995      366945 :         VFS_FIND(pwrite_send);
    1996      366737 :         state->recv_fn = handle->fns->pwrite_recv_fn;
    1997             : 
    1998      366737 :         subreq = handle->fns->pwrite_send_fn(handle, state, ev, fsp, data, n,
    1999             :                                              offset);
    2000      366737 :         if (tevent_req_nomem(subreq, req)) {
    2001           0 :                 return tevent_req_post(req, ev);
    2002             :         }
    2003      366737 :         tevent_req_set_callback(subreq, smb_vfs_call_pwrite_done, req);
    2004      366737 :         return req;
    2005             : }
    2006             : 
    2007      366733 : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq)
    2008             : {
    2009      366733 :         struct tevent_req *req = tevent_req_callback_data(
    2010             :                 subreq, struct tevent_req);
    2011      366733 :         struct smb_vfs_call_pwrite_state *state = tevent_req_data(
    2012             :                 req, struct smb_vfs_call_pwrite_state);
    2013             : 
    2014      366733 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    2015      366733 :         TALLOC_FREE(subreq);
    2016      366733 :         if (state->retval == -1) {
    2017           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    2018           0 :                 return;
    2019             :         }
    2020      366733 :         tevent_req_done(req);
    2021             : }
    2022             : 
    2023      366733 : ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req,
    2024             :                             struct vfs_aio_state *vfs_aio_state)
    2025             : {
    2026      366733 :         struct smb_vfs_call_pwrite_state *state = tevent_req_data(
    2027             :                 req, struct smb_vfs_call_pwrite_state);
    2028             :         ssize_t retval;
    2029             : 
    2030      366733 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    2031           0 :                 tevent_req_received(req);
    2032           0 :                 return -1;
    2033             :         }
    2034      366733 :         *vfs_aio_state = state->vfs_aio_state;
    2035      366733 :         retval = state->retval;
    2036      366733 :         tevent_req_received(req);
    2037      366733 :         return retval;
    2038             : }
    2039             : 
    2040         779 : off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle,
    2041             :                              struct files_struct *fsp, off_t offset,
    2042             :                              int whence)
    2043             : {
    2044         779 :         VFS_FIND(lseek);
    2045         779 :         return handle->fns->lseek_fn(handle, fsp, offset, whence);
    2046             : }
    2047             : 
    2048           0 : ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
    2049             :                               files_struct *fromfsp, const DATA_BLOB *header,
    2050             :                               off_t offset, size_t count)
    2051             : {
    2052           0 :         VFS_FIND(sendfile);
    2053           0 :         return handle->fns->sendfile_fn(handle, tofd, fromfsp, header, offset,
    2054             :                                         count);
    2055             : }
    2056             : 
    2057           0 : ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
    2058             :                               files_struct *tofsp, off_t offset,
    2059             :                               size_t count)
    2060             : {
    2061           0 :         VFS_FIND(recvfile);
    2062           0 :         return handle->fns->recvfile_fn(handle, fromfd, tofsp, offset, count);
    2063             : }
    2064             : 
    2065        1968 : int smb_vfs_call_renameat(struct vfs_handle_struct *handle,
    2066             :                         files_struct *srcfsp,
    2067             :                         const struct smb_filename *smb_fname_src,
    2068             :                         files_struct *dstfsp,
    2069             :                         const struct smb_filename *smb_fname_dst)
    2070             : {
    2071        1968 :         VFS_FIND(renameat);
    2072        1968 :         return handle->fns->renameat_fn(handle,
    2073             :                                 srcfsp,
    2074             :                                 smb_fname_src,
    2075             :                                 dstfsp,
    2076             :                                 smb_fname_dst);
    2077             : }
    2078             : 
    2079             : struct smb_vfs_call_fsync_state {
    2080             :         int (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
    2081             :         int retval;
    2082             :         struct vfs_aio_state vfs_aio_state;
    2083             : };
    2084             : 
    2085             : static void smb_vfs_call_fsync_done(struct tevent_req *subreq);
    2086             : 
    2087         372 : struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle,
    2088             :                                            TALLOC_CTX *mem_ctx,
    2089             :                                            struct tevent_context *ev,
    2090             :                                            struct files_struct *fsp)
    2091             : {
    2092             :         struct tevent_req *req, *subreq;
    2093             :         struct smb_vfs_call_fsync_state *state;
    2094             : 
    2095         372 :         req = tevent_req_create(mem_ctx, &state,
    2096             :                                 struct smb_vfs_call_fsync_state);
    2097         372 :         if (req == NULL) {
    2098           0 :                 return NULL;
    2099             :         }
    2100         380 :         VFS_FIND(fsync_send);
    2101         372 :         state->recv_fn = handle->fns->fsync_recv_fn;
    2102             : 
    2103         372 :         subreq = handle->fns->fsync_send_fn(handle, state, ev, fsp);
    2104         372 :         if (tevent_req_nomem(subreq, req)) {
    2105           0 :                 return tevent_req_post(req, ev);
    2106             :         }
    2107         372 :         tevent_req_set_callback(subreq, smb_vfs_call_fsync_done, req);
    2108         372 :         return req;
    2109             : }
    2110             : 
    2111         372 : static void smb_vfs_call_fsync_done(struct tevent_req *subreq)
    2112             : {
    2113         372 :         struct tevent_req *req = tevent_req_callback_data(
    2114             :                 subreq, struct tevent_req);
    2115         372 :         struct smb_vfs_call_fsync_state *state = tevent_req_data(
    2116             :                 req, struct smb_vfs_call_fsync_state);
    2117             : 
    2118         372 :         state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
    2119         372 :         TALLOC_FREE(subreq);
    2120         372 :         if (state->retval == -1) {
    2121           0 :                 tevent_req_error(req, state->vfs_aio_state.error);
    2122           0 :                 return;
    2123             :         }
    2124         372 :         tevent_req_done(req);
    2125             : }
    2126             : 
    2127         372 : int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state)
    2128             : {
    2129         372 :         struct smb_vfs_call_fsync_state *state = tevent_req_data(
    2130             :                 req, struct smb_vfs_call_fsync_state);
    2131             :         ssize_t retval;
    2132             : 
    2133         372 :         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
    2134           0 :                 tevent_req_received(req);
    2135           0 :                 return -1;
    2136             :         }
    2137         372 :         *vfs_aio_state = state->vfs_aio_state;
    2138         372 :         retval = state->retval;
    2139         372 :         tevent_req_received(req);
    2140         372 :         return retval;
    2141             : }
    2142             : 
    2143             : /*
    2144             :  * Synchronous version of fsync, built from backend
    2145             :  * async VFS primitives. Uses a temporary sub-event
    2146             :  * context (NOT NESTED).
    2147             :  */
    2148             : 
    2149           7 : int smb_vfs_fsync_sync(files_struct *fsp)
    2150             : {
    2151           7 :         TALLOC_CTX *frame = talloc_stackframe();
    2152           7 :         struct tevent_req *req = NULL;
    2153           7 :         struct vfs_aio_state aio_state = { 0 };
    2154           7 :         int ret = -1;
    2155             :         bool ok;
    2156           7 :         struct tevent_context *ev = samba_tevent_context_init(frame);
    2157             : 
    2158           7 :         if (ev == NULL) {
    2159           0 :                 goto out;
    2160             :         }
    2161             : 
    2162           7 :         req = SMB_VFS_FSYNC_SEND(talloc_tos(), ev, fsp);
    2163           7 :         if (req == NULL) {
    2164           0 :                 goto out;
    2165             :         }
    2166             : 
    2167           7 :         ok = tevent_req_poll(req, ev);
    2168           7 :         if (!ok) {
    2169           0 :                 goto out;
    2170             :         }
    2171             : 
    2172           7 :         ret = SMB_VFS_FSYNC_RECV(req, &aio_state);
    2173             : 
    2174           7 :   out:
    2175             : 
    2176           7 :         TALLOC_FREE(frame);
    2177           7 :         if (aio_state.error != 0) {
    2178           0 :                 errno = aio_state.error;
    2179             :         }
    2180           7 :         return ret;
    2181             : }
    2182             : 
    2183   121953691 : int smb_vfs_call_stat(struct vfs_handle_struct *handle,
    2184             :                       struct smb_filename *smb_fname)
    2185             : {
    2186   121953691 :         VFS_FIND(stat);
    2187   121953691 :         return handle->fns->stat_fn(handle, smb_fname);
    2188             : }
    2189             : 
    2190   146211892 : int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
    2191             :                        struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
    2192             : {
    2193   146211892 :         VFS_FIND(fstat);
    2194   146211892 :         return handle->fns->fstat_fn(handle, fsp, sbuf);
    2195             : }
    2196             : 
    2197      190696 : int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
    2198             :                        struct smb_filename *smb_filename)
    2199             : {
    2200      190696 :         VFS_FIND(lstat);
    2201      190696 :         return handle->fns->lstat_fn(handle, smb_filename);
    2202             : }
    2203             : 
    2204     2454376 : uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
    2205             :                                      struct files_struct *fsp,
    2206             :                                      const SMB_STRUCT_STAT *sbuf)
    2207             : {
    2208     2454376 :         VFS_FIND(get_alloc_size);
    2209     2454376 :         return handle->fns->get_alloc_size_fn(handle, fsp, sbuf);
    2210             : }
    2211             : 
    2212      799562 : int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle,
    2213             :                         struct files_struct *dirfsp,
    2214             :                         const struct smb_filename *smb_fname,
    2215             :                         int flags)
    2216             : {
    2217      799562 :         VFS_FIND(unlinkat);
    2218      799562 :         return handle->fns->unlinkat_fn(handle,
    2219             :                         dirfsp,
    2220             :                         smb_fname,
    2221             :                         flags);
    2222             : }
    2223             : 
    2224         358 : int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
    2225             :                         struct files_struct *fsp, mode_t mode)
    2226             : {
    2227         358 :         VFS_FIND(fchmod);
    2228         358 :         return handle->fns->fchmod_fn(handle, fsp, mode);
    2229             : }
    2230             : 
    2231      204140 : int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
    2232             :                         struct files_struct *fsp, uid_t uid, gid_t gid)
    2233             : {
    2234      204140 :         VFS_FIND(fchown);
    2235      204140 :         return handle->fns->fchown_fn(handle, fsp, uid, gid);
    2236             : }
    2237             : 
    2238           0 : int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
    2239             :                         const struct smb_filename *smb_fname,
    2240             :                         uid_t uid,
    2241             :                         gid_t gid)
    2242             : {
    2243           0 :         VFS_FIND(lchown);
    2244           0 :         return handle->fns->lchown_fn(handle, smb_fname, uid, gid);
    2245             : }
    2246             : 
    2247    16203774 : int smb_vfs_call_chdir(struct vfs_handle_struct *handle,
    2248             :                         const struct smb_filename *smb_fname)
    2249             : {
    2250    16203774 :         VFS_FIND(chdir);
    2251    16203774 :         return handle->fns->chdir_fn(handle, smb_fname);
    2252             : }
    2253             : 
    2254      319436 : struct smb_filename *smb_vfs_call_getwd(struct vfs_handle_struct *handle,
    2255             :                                 TALLOC_CTX *ctx)
    2256             : {
    2257      319436 :         VFS_FIND(getwd);
    2258      319436 :         return handle->fns->getwd_fn(handle, ctx);
    2259             : }
    2260             : 
    2261       26300 : int smb_vfs_call_fntimes(struct vfs_handle_struct *handle,
    2262             :                          struct files_struct *fsp,
    2263             :                          struct smb_file_time *ft)
    2264             : {
    2265       26300 :         VFS_FIND(fntimes);
    2266       26300 :         return handle->fns->fntimes_fn(handle, fsp, ft);
    2267             : }
    2268             : 
    2269        2243 : int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
    2270             :                            struct files_struct *fsp, off_t offset)
    2271             : {
    2272        2243 :         VFS_FIND(ftruncate);
    2273        2243 :         return handle->fns->ftruncate_fn(handle, fsp, offset);
    2274             : }
    2275             : 
    2276         328 : int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
    2277             :                            struct files_struct *fsp,
    2278             :                            uint32_t mode,
    2279             :                            off_t offset,
    2280             :                            off_t len)
    2281             : {
    2282         328 :         VFS_FIND(fallocate);
    2283         328 :         return handle->fns->fallocate_fn(handle, fsp, mode, offset, len);
    2284             : }
    2285             : 
    2286      726818 : int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
    2287             :                               struct files_struct *fsp, uint32_t share_mode,
    2288             :                               uint32_t access_mask)
    2289             : {
    2290      726818 :         VFS_FIND(kernel_flock);
    2291      726818 :         return handle->fns->kernel_flock_fn(handle, fsp, share_mode,
    2292             :                                          access_mask);
    2293             : }
    2294             : 
    2295      775580 : int smb_vfs_call_fcntl(struct vfs_handle_struct *handle,
    2296             :                        struct files_struct *fsp, int cmd, ...)
    2297             : {
    2298             :         int result;
    2299             :         va_list cmd_arg;
    2300             : 
    2301      775580 :         VFS_FIND(fcntl);
    2302             : 
    2303      775580 :         va_start(cmd_arg, cmd);
    2304      775580 :         result = handle->fns->fcntl_fn(handle, fsp, cmd, cmd_arg);
    2305      775580 :         va_end(cmd_arg);
    2306             : 
    2307      775580 :         return result;
    2308             : }
    2309             : 
    2310          26 : int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
    2311             :                                 struct files_struct *fsp, int leasetype)
    2312             : {
    2313          26 :         VFS_FIND(linux_setlease);
    2314          26 :         return handle->fns->linux_setlease_fn(handle, fsp, leasetype);
    2315             : }
    2316             : 
    2317         130 : int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle,
    2318             :                         const struct smb_filename *link_target,
    2319             :                         struct files_struct *dirfsp,
    2320             :                         const struct smb_filename *new_smb_fname)
    2321             : {
    2322         130 :         VFS_FIND(symlinkat);
    2323         130 :         return handle->fns->symlinkat_fn(handle,
    2324             :                                 link_target,
    2325             :                                 dirfsp,
    2326             :                                 new_smb_fname);
    2327             : }
    2328             : 
    2329        2860 : int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle,
    2330             :                         const struct files_struct *dirfsp,
    2331             :                         const struct smb_filename *smb_fname,
    2332             :                         char *buf,
    2333             :                         size_t bufsiz)
    2334             : {
    2335        2860 :         VFS_FIND(readlinkat);
    2336        2860 :         return handle->fns->readlinkat_fn(handle,
    2337             :                                 dirfsp,
    2338             :                                 smb_fname,
    2339             :                                 buf,
    2340             :                                 bufsiz);
    2341             : }
    2342             : 
    2343          41 : int smb_vfs_call_linkat(struct vfs_handle_struct *handle,
    2344             :                         struct files_struct *srcfsp,
    2345             :                         const struct smb_filename *old_smb_fname,
    2346             :                         struct files_struct *dstfsp,
    2347             :                         const struct smb_filename *new_smb_fname,
    2348             :                         int flags)
    2349             : {
    2350          41 :         VFS_FIND(linkat);
    2351          41 :         return handle->fns->linkat_fn(handle,
    2352             :                                 srcfsp,
    2353             :                                 old_smb_fname,
    2354             :                                 dstfsp,
    2355             :                                 new_smb_fname,
    2356             :                                 flags);
    2357             : }
    2358             : 
    2359           0 : int smb_vfs_call_mknodat(struct vfs_handle_struct *handle,
    2360             :                         struct files_struct *dirfsp,
    2361             :                         const struct smb_filename *smb_fname,
    2362             :                         mode_t mode,
    2363             :                         SMB_DEV_T dev)
    2364             : {
    2365           0 :         VFS_FIND(mknodat);
    2366           0 :         return handle->fns->mknodat_fn(handle,
    2367             :                                 dirfsp,
    2368             :                                 smb_fname,
    2369             :                                 mode,
    2370             :                                 dev);
    2371             : }
    2372             : 
    2373    23280552 : struct smb_filename *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
    2374             :                         TALLOC_CTX *ctx,
    2375             :                         const struct smb_filename *smb_fname)
    2376             : {
    2377    23280552 :         VFS_FIND(realpath);
    2378    23280552 :         return handle->fns->realpath_fn(handle, ctx, smb_fname);
    2379             : }
    2380             : 
    2381           0 : int smb_vfs_call_fchflags(struct vfs_handle_struct *handle,
    2382             :                         struct files_struct *fsp,
    2383             :                         unsigned int flags)
    2384             : {
    2385           0 :         VFS_FIND(fchflags);
    2386           0 :         return handle->fns->fchflags_fn(handle, fsp, flags);
    2387             : }
    2388             : 
    2389   157095851 : struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
    2390             :                                            const SMB_STRUCT_STAT *sbuf)
    2391             : {
    2392   157095851 :         VFS_FIND(file_id_create);
    2393   157095851 :         return handle->fns->file_id_create_fn(handle, sbuf);
    2394             : }
    2395             : 
    2396      945679 : uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle,
    2397             :                                  const SMB_STRUCT_STAT *sbuf)
    2398             : {
    2399      945679 :         VFS_FIND(fs_file_id);
    2400      945679 :         return handle->fns->fs_file_id_fn(handle, sbuf);
    2401             : }
    2402             : 
    2403      949002 : NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle,
    2404             :                                  struct files_struct *fsp,
    2405             :                                  TALLOC_CTX *mem_ctx,
    2406             :                                  unsigned int *num_streams,
    2407             :                                  struct stream_struct **streams)
    2408             : {
    2409      949002 :         VFS_FIND(fstreaminfo);
    2410      949002 :         return handle->fns->fstreaminfo_fn(handle, fsp, mem_ctx,
    2411             :                                           num_streams, streams);
    2412             : }
    2413             : 
    2414      544118 : int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle,
    2415             :                                    const struct smb_filename *path,
    2416             :                                    const char *name,
    2417             :                                    TALLOC_CTX *mem_ctx,
    2418             :                                    char **found_name)
    2419             : {
    2420      544118 :         VFS_FIND(get_real_filename);
    2421      544118 :         return handle->fns->get_real_filename_fn(handle, path, name, mem_ctx,
    2422             :                                                  found_name);
    2423             : }
    2424             : 
    2425    22079961 : const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
    2426             :                                  const struct smb_filename *smb_fname)
    2427             : {
    2428    22079961 :         VFS_FIND(connectpath);
    2429    22079961 :         return handle->fns->connectpath_fn(handle, smb_fname);
    2430             : }
    2431             : 
    2432      406963 : bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct *handle,
    2433             :                                     struct files_struct *fsp,
    2434             :                                     struct lock_struct *plock)
    2435             : {
    2436      406963 :         VFS_FIND(strict_lock_check);
    2437      406963 :         return handle->fns->strict_lock_check_fn(handle, fsp, plock);
    2438             : }
    2439             : 
    2440   363580707 : NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
    2441             :                                      const char *name,
    2442             :                                      enum vfs_translate_direction direction,
    2443             :                                      TALLOC_CTX *mem_ctx,
    2444             :                                      char **mapped_name)
    2445             : {
    2446   363580707 :         VFS_FIND(translate_name);
    2447   363580707 :         return handle->fns->translate_name_fn(handle, name, direction, mem_ctx,
    2448             :                                               mapped_name);
    2449             : }
    2450             : 
    2451     3829386 : NTSTATUS smb_vfs_call_parent_pathname(struct vfs_handle_struct *handle,
    2452             :                                       TALLOC_CTX *mem_ctx,
    2453             :                                       const struct smb_filename *smb_fname_in,
    2454             :                                       struct smb_filename **parent_dir_out,
    2455             :                                       struct smb_filename **atname_out)
    2456             : {
    2457     3829386 :         VFS_FIND(parent_pathname);
    2458     3829386 :         return handle->fns->parent_pathname_fn(handle,
    2459             :                                                mem_ctx,
    2460             :                                                smb_fname_in,
    2461             :                                                parent_dir_out,
    2462             :                                                atname_out);
    2463             : }
    2464             : 
    2465        3858 : NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
    2466             :                             struct files_struct *fsp,
    2467             :                             TALLOC_CTX *ctx,
    2468             :                             uint32_t function,
    2469             :                             uint16_t req_flags,
    2470             :                             const uint8_t *in_data,
    2471             :                             uint32_t in_len,
    2472             :                             uint8_t **out_data,
    2473             :                             uint32_t max_out_len,
    2474             :                             uint32_t *out_len)
    2475             : {
    2476        3858 :         VFS_FIND(fsctl);
    2477        3858 :         return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags,
    2478             :                                      in_data, in_len, out_data, max_out_len,
    2479             :                                      out_len);
    2480             : }
    2481             : 
    2482     2537340 : NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle,
    2483             :                                           struct files_struct *fsp,
    2484             :                                           uint32_t *dosmode)
    2485             : {
    2486     2537340 :         VFS_FIND(fget_dos_attributes);
    2487     2537340 :         return handle->fns->fget_dos_attributes_fn(handle, fsp, dosmode);
    2488             : }
    2489             : 
    2490      356152 : NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle,
    2491             :                                           struct files_struct *fsp,
    2492             :                                           uint32_t dosmode)
    2493             : {
    2494      356152 :         VFS_FIND(fset_dos_attributes);
    2495      356152 :         return handle->fns->fset_dos_attributes_fn(handle, fsp, dosmode);
    2496             : }
    2497             : 
    2498         500 : struct tevent_req *smb_vfs_call_offload_read_send(TALLOC_CTX *mem_ctx,
    2499             :                                                   struct tevent_context *ev,
    2500             :                                                   struct vfs_handle_struct *handle,
    2501             :                                                   struct files_struct *fsp,
    2502             :                                                   uint32_t fsctl,
    2503             :                                                   uint32_t ttl,
    2504             :                                                   off_t offset,
    2505             :                                                   size_t to_copy)
    2506             : {
    2507         500 :         VFS_FIND(offload_read_send);
    2508         500 :         return handle->fns->offload_read_send_fn(mem_ctx, ev, handle,
    2509             :                                                  fsp, fsctl,
    2510             :                                                  ttl, offset, to_copy);
    2511             : }
    2512             : 
    2513         500 : NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req,
    2514             :                                         struct vfs_handle_struct *handle,
    2515             :                                         TALLOC_CTX *mem_ctx,
    2516             :                                         DATA_BLOB *token_blob)
    2517             : {
    2518         500 :         VFS_FIND(offload_read_recv);
    2519         500 :         return handle->fns->offload_read_recv_fn(req, handle, mem_ctx, token_blob);
    2520             : }
    2521             : 
    2522         556 : struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle,
    2523             :                                                    TALLOC_CTX *mem_ctx,
    2524             :                                                    struct tevent_context *ev,
    2525             :                                                    uint32_t fsctl,
    2526             :                                                    DATA_BLOB *token,
    2527             :                                                    off_t transfer_offset,
    2528             :                                                    struct files_struct *dest_fsp,
    2529             :                                                    off_t dest_off,
    2530             :                                                    off_t num)
    2531             : {
    2532         556 :         VFS_FIND(offload_write_send);
    2533         556 :         return handle->fns->offload_write_send_fn(handle, mem_ctx, ev, fsctl,
    2534             :                                                token, transfer_offset,
    2535             :                                                dest_fsp, dest_off, num);
    2536             : }
    2537             : 
    2538         556 : NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle,
    2539             :                                          struct tevent_req *req,
    2540             :                                          off_t *copied)
    2541             : {
    2542         556 :         VFS_FIND(offload_write_recv);
    2543         556 :         return handle->fns->offload_write_recv_fn(handle, req, copied);
    2544             : }
    2545             : 
    2546             : struct smb_vfs_call_get_dos_attributes_state {
    2547             :         files_struct *dir_fsp;
    2548             :         NTSTATUS (*recv_fn)(struct tevent_req *req,
    2549             :                             struct vfs_aio_state *aio_state,
    2550             :                             uint32_t *dosmode);
    2551             :         struct vfs_aio_state aio_state;
    2552             :         uint32_t dos_attributes;
    2553             : };
    2554             : 
    2555             : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq);
    2556             : 
    2557       40234 : struct tevent_req *smb_vfs_call_get_dos_attributes_send(
    2558             :                         TALLOC_CTX *mem_ctx,
    2559             :                         struct tevent_context *ev,
    2560             :                         struct vfs_handle_struct *handle,
    2561             :                         files_struct *dir_fsp,
    2562             :                         struct smb_filename *smb_fname)
    2563             : {
    2564       40234 :         struct tevent_req *req = NULL;
    2565       40234 :         struct smb_vfs_call_get_dos_attributes_state *state = NULL;
    2566       40234 :         struct tevent_req *subreq = NULL;
    2567             : 
    2568       40234 :         req = tevent_req_create(mem_ctx, &state,
    2569             :                                 struct smb_vfs_call_get_dos_attributes_state);
    2570       40234 :         if (req == NULL) {
    2571           0 :                 return NULL;
    2572             :         }
    2573             : 
    2574       40234 :         VFS_FIND(get_dos_attributes_send);
    2575             : 
    2576       80468 :         *state = (struct smb_vfs_call_get_dos_attributes_state) {
    2577             :                 .dir_fsp = dir_fsp,
    2578       40234 :                 .recv_fn = handle->fns->get_dos_attributes_recv_fn,
    2579             :         };
    2580             : 
    2581       40234 :         subreq = handle->fns->get_dos_attributes_send_fn(mem_ctx,
    2582             :                                                          ev,
    2583             :                                                          handle,
    2584             :                                                          dir_fsp,
    2585             :                                                          smb_fname);
    2586       40234 :         if (tevent_req_nomem(subreq, req)) {
    2587           0 :                 return tevent_req_post(req, ev);
    2588             :         }
    2589       40234 :         tevent_req_defer_callback(req, ev);
    2590             : 
    2591       40234 :         tevent_req_set_callback(subreq,
    2592             :                                 smb_vfs_call_get_dos_attributes_done,
    2593             :                                 req);
    2594             : 
    2595       40234 :         return req;
    2596             : }
    2597             : 
    2598       40234 : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq)
    2599             : {
    2600       40234 :         struct tevent_req *req =
    2601       40234 :                 tevent_req_callback_data(subreq,
    2602             :                 struct tevent_req);
    2603       40234 :         struct smb_vfs_call_get_dos_attributes_state *state =
    2604       40234 :                 tevent_req_data(req,
    2605             :                 struct smb_vfs_call_get_dos_attributes_state);
    2606             :         NTSTATUS status;
    2607             :         bool ok;
    2608             : 
    2609             :         /*
    2610             :          * Make sure we run as the user again
    2611             :          */
    2612       40234 :         ok = change_to_user_and_service_by_fsp(state->dir_fsp);
    2613       40234 :         SMB_ASSERT(ok);
    2614             : 
    2615       40234 :         status = state->recv_fn(subreq,
    2616             :                                 &state->aio_state,
    2617             :                                 &state->dos_attributes);
    2618       40234 :         TALLOC_FREE(subreq);
    2619       40234 :         if (tevent_req_nterror(req, status)) {
    2620         208 :                 return;
    2621             :         }
    2622             : 
    2623       40026 :         tevent_req_done(req);
    2624             : }
    2625             : 
    2626       40234 : NTSTATUS smb_vfs_call_get_dos_attributes_recv(
    2627             :                 struct tevent_req *req,
    2628             :                 struct vfs_aio_state *aio_state,
    2629             :                 uint32_t *dos_attributes)
    2630             : {
    2631       40234 :         struct smb_vfs_call_get_dos_attributes_state *state =
    2632       40234 :                 tevent_req_data(req,
    2633             :                 struct smb_vfs_call_get_dos_attributes_state);
    2634             :         NTSTATUS status;
    2635             : 
    2636       40234 :         if (tevent_req_is_nterror(req, &status)) {
    2637         208 :                 tevent_req_received(req);
    2638         208 :                 return status;
    2639             :         }
    2640             : 
    2641       40026 :         *aio_state = state->aio_state;
    2642       40026 :         *dos_attributes = state->dos_attributes;
    2643       40026 :         tevent_req_received(req);
    2644       40026 :         return NT_STATUS_OK;
    2645             : }
    2646             : 
    2647           0 : NTSTATUS smb_vfs_call_fget_compression(vfs_handle_struct *handle,
    2648             :                                       TALLOC_CTX *mem_ctx,
    2649             :                                       struct files_struct *fsp,
    2650             :                                       uint16_t *_compression_fmt)
    2651             : {
    2652           0 :         VFS_FIND(fget_compression);
    2653           0 :         return handle->fns->fget_compression_fn(handle, mem_ctx, fsp,
    2654             :                                                _compression_fmt);
    2655             : }
    2656             : 
    2657           0 : NTSTATUS smb_vfs_call_set_compression(vfs_handle_struct *handle,
    2658             :                                       TALLOC_CTX *mem_ctx,
    2659             :                                       struct files_struct *fsp,
    2660             :                                       uint16_t compression_fmt)
    2661             : {
    2662           0 :         VFS_FIND(set_compression);
    2663           0 :         return handle->fns->set_compression_fn(handle, mem_ctx, fsp,
    2664             :                                                compression_fmt);
    2665             : }
    2666             : 
    2667          68 : NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle,
    2668             :                                       TALLOC_CTX *mem_ctx,
    2669             :                                       const char *service_path,
    2670             :                                       char **base_volume)
    2671             : {
    2672          68 :         VFS_FIND(snap_check_path);
    2673          68 :         return handle->fns->snap_check_path_fn(handle, mem_ctx, service_path,
    2674             :                                                base_volume);
    2675             : }
    2676             : 
    2677          16 : NTSTATUS smb_vfs_call_snap_create(struct vfs_handle_struct *handle,
    2678             :                                   TALLOC_CTX *mem_ctx,
    2679             :                                   const char *base_volume,
    2680             :                                   time_t *tstamp,
    2681             :                                   bool rw,
    2682             :                                   char **base_path,
    2683             :                                   char **snap_path)
    2684             : {
    2685          16 :         VFS_FIND(snap_create);
    2686          16 :         return handle->fns->snap_create_fn(handle, mem_ctx, base_volume, tstamp,
    2687             :                                            rw, base_path, snap_path);
    2688             : }
    2689             : 
    2690          10 : NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle,
    2691             :                                   TALLOC_CTX *mem_ctx,
    2692             :                                   char *base_path,
    2693             :                                   char *snap_path)
    2694             : {
    2695          10 :         VFS_FIND(snap_delete);
    2696          10 :         return handle->fns->snap_delete_fn(handle, mem_ctx, base_path,
    2697             :                                            snap_path);
    2698             : }
    2699             : 
    2700     1519443 : NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
    2701             :                                   struct files_struct *fsp,
    2702             :                                   uint32_t security_info,
    2703             :                                   TALLOC_CTX *mem_ctx,
    2704             :                                   struct security_descriptor **ppdesc)
    2705             : {
    2706     1519443 :         VFS_FIND(fget_nt_acl);
    2707     1519443 :         return handle->fns->fget_nt_acl_fn(handle, fsp, security_info,
    2708             :                                            mem_ctx, ppdesc);
    2709             : }
    2710             : 
    2711      480911 : NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
    2712             :                                   struct files_struct *fsp,
    2713             :                                   uint32_t security_info_sent,
    2714             :                                   const struct security_descriptor *psd)
    2715             : {
    2716      480911 :         VFS_FIND(fset_nt_acl);
    2717      480911 :         return handle->fns->fset_nt_acl_fn(handle, fsp, security_info_sent, 
    2718             :                                            psd);
    2719             : }
    2720             : 
    2721           0 : NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
    2722             :                                  struct smb_filename *file,
    2723             :                                  struct security_acl *sacl,
    2724             :                                  uint32_t access_requested,
    2725             :                                  uint32_t access_denied)
    2726             : {
    2727           0 :         VFS_FIND(audit_file);
    2728           0 :         return handle->fns->audit_file_fn(handle, 
    2729             :                                           file, 
    2730             :                                           sacl, 
    2731             :                                           access_requested, 
    2732             :                                           access_denied);
    2733             : }
    2734             : 
    2735     1963209 : SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
    2736             :                                       struct files_struct *fsp,
    2737             :                                       SMB_ACL_TYPE_T type,
    2738             :                                       TALLOC_CTX *mem_ctx)
    2739             : {
    2740     1963209 :         VFS_FIND(sys_acl_get_fd);
    2741     1963209 :         return handle->fns->sys_acl_get_fd_fn(handle, fsp, type, mem_ctx);
    2742             : }
    2743             : 
    2744      778553 : int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
    2745             :                                      struct files_struct *fsp,
    2746             :                                      TALLOC_CTX *mem_ctx, 
    2747             :                                      char **blob_description,
    2748             :                                      DATA_BLOB *blob)
    2749             : {
    2750      778553 :         VFS_FIND(sys_acl_blob_get_fd);
    2751      778553 :         return handle->fns->sys_acl_blob_get_fd_fn(handle, fsp, mem_ctx, blob_description, blob);
    2752             : }
    2753             : 
    2754      324501 : int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
    2755             :                                 struct files_struct *fsp,
    2756             :                                 SMB_ACL_TYPE_T type,
    2757             :                                 SMB_ACL_T theacl)
    2758             : {
    2759      324501 :         VFS_FIND(sys_acl_set_fd);
    2760      324501 :         return handle->fns->sys_acl_set_fd_fn(handle, fsp, type, theacl);
    2761             : }
    2762             : 
    2763         321 : int smb_vfs_call_sys_acl_delete_def_fd(struct vfs_handle_struct *handle,
    2764             :                                 struct files_struct *fsp)
    2765             : {
    2766         321 :         VFS_FIND(sys_acl_delete_def_fd);
    2767         321 :         return handle->fns->sys_acl_delete_def_fd_fn(handle, fsp);
    2768             : }
    2769             : 
    2770             : struct smb_vfs_call_getxattrat_state {
    2771             :         files_struct *dir_fsp;
    2772             :         ssize_t (*recv_fn)(struct tevent_req *req,
    2773             :                            struct vfs_aio_state *aio_state,
    2774             :                            TALLOC_CTX *mem_ctx,
    2775             :                            uint8_t **xattr_value);
    2776             :         ssize_t retval;
    2777             :         uint8_t *xattr_value;
    2778             :         struct vfs_aio_state aio_state;
    2779             : };
    2780             : 
    2781             : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq);
    2782             : 
    2783       40234 : struct tevent_req *smb_vfs_call_getxattrat_send(
    2784             :                         TALLOC_CTX *mem_ctx,
    2785             :                         struct tevent_context *ev,
    2786             :                         struct vfs_handle_struct *handle,
    2787             :                         files_struct *dir_fsp,
    2788             :                         const struct smb_filename *smb_fname,
    2789             :                         const char *xattr_name,
    2790             :                         size_t alloc_hint)
    2791             : {
    2792       40234 :         struct tevent_req *req = NULL;
    2793       40234 :         struct smb_vfs_call_getxattrat_state *state = NULL;
    2794       40234 :         struct tevent_req *subreq = NULL;
    2795             : 
    2796       40234 :         req = tevent_req_create(mem_ctx, &state,
    2797             :                                 struct smb_vfs_call_getxattrat_state);
    2798       40234 :         if (req == NULL) {
    2799           0 :                 return NULL;
    2800             :         }
    2801             : 
    2802       40234 :         VFS_FIND(getxattrat_send);
    2803             : 
    2804       80468 :         *state = (struct smb_vfs_call_getxattrat_state) {
    2805             :                 .dir_fsp = dir_fsp,
    2806       40234 :                 .recv_fn = handle->fns->getxattrat_recv_fn,
    2807             :         };
    2808             : 
    2809       40234 :         subreq = handle->fns->getxattrat_send_fn(mem_ctx,
    2810             :                                                  ev,
    2811             :                                                  handle,
    2812             :                                                  dir_fsp,
    2813             :                                                  smb_fname,
    2814             :                                                  xattr_name,
    2815             :                                                  alloc_hint);
    2816       40234 :         if (tevent_req_nomem(subreq, req)) {
    2817           0 :                 return tevent_req_post(req, ev);
    2818             :         }
    2819       40234 :         tevent_req_defer_callback(req, ev);
    2820             : 
    2821       40234 :         tevent_req_set_callback(subreq, smb_vfs_call_getxattrat_done, req);
    2822       40234 :         return req;
    2823             : }
    2824             : 
    2825       40234 : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq)
    2826             : {
    2827       40234 :         struct tevent_req *req = tevent_req_callback_data(
    2828             :                 subreq, struct tevent_req);
    2829       40234 :         struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
    2830             :                 req, struct smb_vfs_call_getxattrat_state);
    2831             :         bool ok;
    2832             : 
    2833             :         /*
    2834             :          * Make sure we run as the user again
    2835             :          */
    2836       40234 :         ok = change_to_user_and_service_by_fsp(state->dir_fsp);
    2837       40234 :         SMB_ASSERT(ok);
    2838             : 
    2839       40234 :         state->retval = state->recv_fn(subreq,
    2840             :                                        &state->aio_state,
    2841             :                                        state,
    2842             :                                        &state->xattr_value);
    2843       40234 :         TALLOC_FREE(subreq);
    2844       40234 :         if (state->retval == -1) {
    2845         208 :                 tevent_req_error(req, state->aio_state.error);
    2846         208 :                 return;
    2847             :         }
    2848             : 
    2849       40026 :         tevent_req_done(req);
    2850             : }
    2851             : 
    2852       40234 : ssize_t smb_vfs_call_getxattrat_recv(struct tevent_req *req,
    2853             :                                      struct vfs_aio_state *aio_state,
    2854             :                                      TALLOC_CTX *mem_ctx,
    2855             :                                      uint8_t **xattr_value)
    2856             : {
    2857       40234 :         struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
    2858             :                 req, struct smb_vfs_call_getxattrat_state);
    2859             :         size_t xattr_size;
    2860             : 
    2861       40234 :         if (tevent_req_is_unix_error(req, &aio_state->error)) {
    2862         208 :                 tevent_req_received(req);
    2863         208 :                 return -1;
    2864             :         }
    2865             : 
    2866       40026 :         *aio_state = state->aio_state;
    2867       40026 :         xattr_size = state->retval;
    2868       40026 :         if (xattr_value != NULL) {
    2869       40026 :                 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
    2870             :         }
    2871             : 
    2872       40026 :         tevent_req_received(req);
    2873       40026 :         return xattr_size;
    2874             : }
    2875             : 
    2876    48842186 : ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
    2877             :                                struct files_struct *fsp, const char *name,
    2878             :                                void *value, size_t size)
    2879             : {
    2880    48842186 :         VFS_FIND(fgetxattr);
    2881    48842186 :         return handle->fns->fgetxattr_fn(handle, fsp, name, value, size);
    2882             : }
    2883             : 
    2884      340582 : ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
    2885             :                                 struct files_struct *fsp, char *list,
    2886             :                                 size_t size)
    2887             : {
    2888      340582 :         VFS_FIND(flistxattr);
    2889      340582 :         return handle->fns->flistxattr_fn(handle, fsp, list, size);
    2890             : }
    2891             : 
    2892        2713 : int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
    2893             :                               struct files_struct *fsp, const char *name)
    2894             : {
    2895        2713 :         VFS_FIND(fremovexattr);
    2896        2713 :         return handle->fns->fremovexattr_fn(handle, fsp, name);
    2897             : }
    2898             : 
    2899      801920 : int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
    2900             :                            struct files_struct *fsp, const char *name,
    2901             :                            const void *value, size_t size, int flags)
    2902             : {
    2903      801920 :         VFS_FIND(fsetxattr);
    2904      801920 :         return handle->fns->fsetxattr_fn(handle, fsp, name, value, size, flags);
    2905             : }
    2906             : 
    2907         159 : bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
    2908             :                             struct files_struct *fsp)
    2909             : {
    2910         159 :         VFS_FIND(aio_force);
    2911         159 :         return handle->fns->aio_force_fn(handle, fsp);
    2912             : }
    2913             : 
    2914        1306 : NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
    2915             :                                      struct files_struct *fsp,
    2916             :                                      TALLOC_CTX *mem_ctx,
    2917             :                                      DATA_BLOB *cookie)
    2918             : {
    2919        1306 :         VFS_FIND(durable_cookie);
    2920        1306 :         return handle->fns->durable_cookie_fn(handle, fsp, mem_ctx, cookie);
    2921             : }
    2922             : 
    2923         380 : NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle,
    2924             :                                          struct files_struct *fsp,
    2925             :                                          const DATA_BLOB old_cookie,
    2926             :                                          TALLOC_CTX *mem_ctx,
    2927             :                                          DATA_BLOB *new_cookie)
    2928             : {
    2929         380 :         VFS_FIND(durable_disconnect);
    2930         380 :         return handle->fns->durable_disconnect_fn(handle, fsp, old_cookie,
    2931             :                                                   mem_ctx, new_cookie);
    2932             : }
    2933             : 
    2934         372 : NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle,
    2935             :                                         struct smb_request *smb1req,
    2936             :                                         struct smbXsrv_open *op,
    2937             :                                         const DATA_BLOB old_cookie,
    2938             :                                         TALLOC_CTX *mem_ctx,
    2939             :                                         struct files_struct **fsp,
    2940             :                                         DATA_BLOB *new_cookie)
    2941             : {
    2942         372 :         VFS_FIND(durable_reconnect);
    2943         372 :         return handle->fns->durable_reconnect_fn(handle, smb1req, op,
    2944             :                                                  old_cookie, mem_ctx, fsp,
    2945             :                                                  new_cookie);
    2946             : }
    2947             : 
    2948      898462 : NTSTATUS smb_vfs_call_freaddir_attr(struct vfs_handle_struct *handle,
    2949             :                                     struct files_struct *fsp,
    2950             :                                     TALLOC_CTX *mem_ctx,
    2951             :                                     struct readdir_attr_data **attr_data)
    2952             : {
    2953      898462 :         VFS_FIND(freaddir_attr);
    2954      898462 :         return handle->fns->freaddir_attr_fn(handle,
    2955             :                                              fsp,
    2956             :                                              mem_ctx,
    2957             :                                              attr_data);
    2958             : }

Generated by: LCOV version 1.13