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 781445 : static struct vfs_init_function_entry *vfs_find_backend_entry(const char *name)
63 : {
64 781445 : struct vfs_init_function_entry *entry = backends;
65 :
66 781445 : DEBUG(10, ("vfs_find_backend_entry called for %s\n", name));
67 :
68 3449588 : while(entry) {
69 3036387 : if (strcmp(entry->name, name)==0) return entry;
70 2668143 : entry = entry->next;
71 : }
72 :
73 404245 : return NULL;
74 : }
75 :
76 256353 : NTSTATUS smb_register_vfs(int version, const char *name,
77 : const struct vfs_fn_pointers *fns)
78 : {
79 256353 : struct vfs_init_function_entry *entry = backends;
80 :
81 256353 : 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 256353 : 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 256353 : 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 256353 : entry = SMB_XMALLOC_P(struct vfs_init_function_entry);
101 256353 : entry->name = smb_xstrdup(name);
102 256353 : entry->fns = fns;
103 :
104 256353 : DLIST_ADD(backends, entry);
105 256353 : DEBUG(5, ("Successfully added vfs backend '%s'\n", name));
106 256353 : return NT_STATUS_OK;
107 : }
108 :
109 : /****************************************************************************
110 : initialise default vfs hooks
111 : ****************************************************************************/
112 :
113 57263 : static void vfs_init_default(connection_struct *conn)
114 : {
115 57263 : DEBUG(3, ("Initialising default vfs hooks\n"));
116 57263 : vfs_init_custom(conn, DEFAULT_VFS_MODULE_NAME);
117 57263 : }
118 :
119 : /****************************************************************************
120 : initialise custom vfs hooks
121 : ****************************************************************************/
122 :
123 368244 : bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
124 : {
125 368244 : char *module_path = NULL;
126 368244 : char *module_name = NULL;
127 368244 : char *module_param = NULL, *p;
128 5129 : vfs_handle_struct *handle;
129 5129 : const struct vfs_init_function_entry *entry;
130 :
131 368244 : 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 368244 : if(!backends) {
138 29268 : static_init_vfs(NULL);
139 : }
140 :
141 368244 : DEBUG(3, ("Initialising custom vfs hooks from [%s]\n", vfs_object));
142 :
143 368244 : module_path = smb_xstrdup(vfs_object);
144 :
145 368244 : p = strchr_m(module_path, ':');
146 :
147 368244 : if (p) {
148 0 : *p = 0;
149 0 : module_param = p+1;
150 0 : trim_char(module_param, ' ', ' ');
151 : }
152 :
153 368244 : trim_char(module_path, ' ', ' ');
154 :
155 368244 : module_name = smb_xstrdup(module_path);
156 :
157 368244 : if ((module_name[0] == '/') &&
158 57263 : (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 368244 : entry = vfs_find_backend_entry(module_name);
177 368244 : if (!entry) {
178 2984 : NTSTATUS status;
179 :
180 156848 : DEBUG(5, ("vfs module [%s] not loaded - trying to load...\n",
181 : vfs_object));
182 :
183 156848 : status = smb_load_module("vfs", module_path);
184 156848 : 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 156848 : entry = vfs_find_backend_entry(module_name);
191 156848 : if (!entry) {
192 0 : DEBUG(0,("Can't find a vfs module [%s]\n",vfs_object));
193 0 : goto fail;
194 : }
195 : }
196 :
197 368244 : DEBUGADD(5,("Successfully loaded vfs module [%s] with the new modules system\n", vfs_object));
198 :
199 368244 : handle = talloc_zero(conn, vfs_handle_struct);
200 368244 : if (!handle) {
201 0 : DEBUG(0,("TALLOC_ZERO() failed!\n"));
202 0 : goto fail;
203 : }
204 368244 : handle->conn = conn;
205 368244 : handle->fns = entry->fns;
206 368244 : if (module_param) {
207 0 : handle->param = talloc_strdup(conn, module_param);
208 : }
209 368244 : DLIST_ADD(conn->vfs_handles, handle);
210 :
211 368244 : SAFE_FREE(module_path);
212 368244 : SAFE_FREE(module_name);
213 363115 : 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 232139 : 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 431 : struct vfs_fsp_data *ext;
234 431 : void * ext_data;
235 :
236 : /* Prevent VFS modules adding multiple extensions. */
237 232139 : if ((ext_data = vfs_fetch_fsp_extension(handle, fsp))) {
238 1489 : return ext_data;
239 : }
240 :
241 230650 : ext = talloc_zero_size(
242 : handle->conn, sizeof(struct vfs_fsp_data) + ext_size);
243 230650 : if (ext == NULL) {
244 0 : return NULL;
245 : }
246 :
247 230650 : ext->owner = handle;
248 230650 : ext->next = fsp->vfs_extension;
249 230650 : ext->destroy = destroy_fn;
250 230650 : fsp->vfs_extension = ext;
251 230650 : return EXT_DATA_AREA(ext);
252 : }
253 :
254 167601 : void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
255 : {
256 431 : struct vfs_fsp_data *curr;
257 431 : struct vfs_fsp_data *prev;
258 :
259 167601 : for (curr = fsp->vfs_extension, prev = NULL;
260 168015 : curr;
261 414 : prev = curr, curr = curr->next) {
262 168015 : if (curr->owner == handle) {
263 167601 : if (prev) {
264 414 : prev->next = curr->next;
265 : } else {
266 167187 : fsp->vfs_extension = curr->next;
267 : }
268 167601 : if (curr->destroy) {
269 1464 : curr->destroy(EXT_DATA_AREA(curr));
270 : }
271 167601 : TALLOC_FREE(curr);
272 167601 : return;
273 : }
274 : }
275 : }
276 :
277 6284180 : void vfs_remove_all_fsp_extensions(files_struct *fsp)
278 : {
279 32286 : struct vfs_fsp_data *curr;
280 32286 : struct vfs_fsp_data *next;
281 :
282 6347177 : for (curr = fsp->vfs_extension; curr; curr = next) {
283 :
284 62997 : next = curr->next;
285 62997 : fsp->vfs_extension = next;
286 :
287 62997 : if (curr->destroy) {
288 4676 : curr->destroy(EXT_DATA_AREA(curr));
289 : }
290 62997 : TALLOC_FREE(curr);
291 : }
292 6284180 : }
293 :
294 906251 : void *vfs_memctx_fsp_extension(vfs_handle_struct *handle,
295 : const struct files_struct *fsp)
296 : {
297 946 : struct vfs_fsp_data *head;
298 :
299 1102979 : for (head = fsp->vfs_extension; head; head = head->next) {
300 544395 : if (head->owner == handle) {
301 347667 : return head;
302 : }
303 : }
304 :
305 558149 : return NULL;
306 : }
307 :
308 836423 : void *vfs_fetch_fsp_extension(vfs_handle_struct *handle,
309 : const struct files_struct *fsp)
310 : {
311 946 : struct vfs_fsp_data *head;
312 :
313 836423 : head = (struct vfs_fsp_data *)vfs_memctx_fsp_extension(handle, fsp);
314 836423 : if (head != NULL) {
315 277839 : return EXT_DATA_AREA(head);
316 : }
317 :
318 558149 : return NULL;
319 : }
320 :
321 : #undef EXT_DATA_AREA
322 :
323 : /*
324 : * Ensure this module catches all VFS functions.
325 : */
326 : #ifdef DEVELOPER
327 97168 : void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
328 : const char *module)
329 : {
330 97168 : bool missing_fn = false;
331 1494 : unsigned int idx;
332 97168 : const uintptr_t *end = (const uintptr_t *)(fns + 1);
333 :
334 9619632 : for (idx = 0; ((const uintptr_t *)fns + idx) < end; idx++) {
335 9522464 : 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 97168 : if (missing_fn) {
343 0 : smb_panic("Required VFS function not implemented in module.\n");
344 : }
345 97168 : }
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 57263 : bool smbd_vfs_init(connection_struct *conn)
358 : {
359 874 : const char **vfs_objects;
360 57263 : unsigned int i = 0;
361 57263 : int j = 0;
362 :
363 : /* Normal share - initialise with disk access functions */
364 57263 : vfs_init_default(conn);
365 :
366 : /* No need to load vfs modules for printer connections */
367 57263 : if (conn->printer) {
368 28 : return True;
369 : }
370 :
371 57235 : 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 258 : bool ok = vfs_init_custom(conn, "widelinks");
380 258 : 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 57235 : vfs_objects = lp_vfs_objects(SNUM(conn));
388 :
389 : /* Override VFS functions if 'vfs object' was not specified*/
390 57235 : if (!vfs_objects || !vfs_objects[0])
391 39 : return True;
392 :
393 367917 : for (i=0; vfs_objects[i] ;) {
394 310721 : i++;
395 : }
396 :
397 367917 : for (j=i-1; j >= 0; j--) {
398 310721 : 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 56322 : 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 16 : 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 17222 : bool vfs_valid_pread_range(off_t offset, size_t length)
422 : {
423 17222 : return sys_valid_io_range(offset, length);
424 : }
425 :
426 193086 : 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 113 : static const uint64_t maxfilesize = 0xfffffff0000;
432 113 : uint64_t last_byte_ofs;
433 113 : bool ok;
434 :
435 193086 : ok = sys_valid_io_range(offset, length);
436 193086 : if (!ok) {
437 36 : return false;
438 : }
439 :
440 193050 : if (length == 0) {
441 658 : return true;
442 : }
443 :
444 192355 : last_byte_ofs = offset + length;
445 192355 : if (last_byte_ofs > maxfilesize) {
446 6 : return false;
447 : }
448 :
449 192273 : return true;
450 : }
451 :
452 3334 : 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 3334 : size_t total=0;
459 12 : ssize_t ret;
460 12 : bool ok;
461 :
462 3334 : ok = vfs_valid_pwrite_range(offset, N);
463 3334 : if (!ok) {
464 0 : errno = EINVAL;
465 0 : return -1;
466 : }
467 :
468 3334 : 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 0 : 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 4466 : while (total < N) {
518 3334 : ret = SMB_VFS_PWRITE(fsp, buffer + total, N - total,
519 : offset + total);
520 :
521 3334 : if (ret == -1)
522 2202 : return -1;
523 1132 : if (ret == 0)
524 0 : return total;
525 :
526 1132 : total += ret;
527 : }
528 1132 : 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 281 : int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
537 : {
538 25 : int ret;
539 281 : connection_struct *conn = fsp->conn;
540 25 : uint64_t space_avail;
541 25 : uint64_t bsize,dfree,dsize;
542 25 : NTSTATUS status;
543 25 : bool ok;
544 :
545 : /*
546 : * Actually try and commit the space on disk....
547 : */
548 :
549 281 : DEBUG(10,("vfs_allocate_file_space: file %s, len %.0f\n",
550 : fsp_str_dbg(fsp), (double)len));
551 :
552 281 : ok = vfs_valid_pwrite_range((off_t)len, 0);
553 281 : 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 281 : status = vfs_stat_fsp(fsp);
561 281 : if (!NT_STATUS_IS_OK(status)) {
562 0 : return -1;
563 : }
564 :
565 281 : if (len == (uint64_t)fsp->fsp_name->st.st_ex_size)
566 44 : return 0;
567 :
568 236 : 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 230 : contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
587 :
588 230 : 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 206 : ret = 0;
595 : }
596 :
597 230 : contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
598 :
599 230 : if (ret == 0) {
600 : /* We changed the allocation size on disk, but not
601 : EOF - exactly as required. We're done ! */
602 206 : 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 392 : int vfs_set_filelen(files_struct *fsp, off_t len)
637 : {
638 10 : int ret;
639 10 : bool ok;
640 :
641 392 : ok = vfs_valid_pwrite_range(len, 0);
642 392 : if (!ok) {
643 0 : errno = EINVAL;
644 0 : return -1;
645 : }
646 :
647 392 : contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
648 :
649 392 : DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
650 : fsp_str_dbg(fsp), (double)len));
651 392 : if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
652 384 : notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
653 : FILE_NOTIFY_CHANGE_SIZE
654 : | FILE_NOTIFY_CHANGE_ATTRIBUTES,
655 384 : fsp->fsp_name->base_name);
656 : }
657 :
658 392 : contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_SET_FILE_LEN);
659 :
660 392 : 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 0 : ssize_t pwrite_ret;
676 0 : size_t total = 0;
677 0 : 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 0 : int ret;
721 0 : NTSTATUS status;
722 0 : off_t offset;
723 0 : size_t num_to_write;
724 0 : 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_is_alternate_stream(fsp)) {
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 190941 : int vfs_set_blocking(files_struct *fsp, bool set)
788 : {
789 449 : 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 190941 : if (fsp->fsp_flags.is_pathref) {
801 0 : return 0;
802 : }
803 :
804 190941 : val = SMB_VFS_FCNTL(fsp, F_GETFL, 0);
805 190941 : if (val == -1) {
806 0 : return -1;
807 : }
808 :
809 190941 : if (set) {
810 190941 : val &= ~FLAG_TO_SET;
811 : } else {
812 0 : val |= FLAG_TO_SET;
813 : }
814 :
815 190941 : 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 161003948 : const char *vfs_readdirname(connection_struct *conn,
848 : struct files_struct *dirfsp,
849 : DIR *d,
850 : char **talloced)
851 : {
852 161003948 : struct dirent *ptr= NULL;
853 7202 : const char *dname;
854 7202 : char *translated;
855 7202 : NTSTATUS status;
856 :
857 161003948 : if (d == NULL) {
858 0 : return(NULL);
859 : }
860 :
861 161003948 : ptr = SMB_VFS_READDIR(conn, dirfsp, d);
862 161003948 : if (!ptr)
863 305848 : return(NULL);
864 :
865 160697064 : dname = ptr->d_name;
866 :
867 160697064 : status = SMB_VFS_TRANSLATE_NAME(conn, dname, vfs_translate_to_windows,
868 : talloc_tos(), &translated);
869 160697064 : if (NT_STATUS_EQUAL(status, NT_STATUS_NONE_MAPPED)) {
870 160656938 : *talloced = NULL;
871 160656938 : return dname;
872 : }
873 40126 : *talloced = translated;
874 40126 : if (!NT_STATUS_IS_OK(status)) {
875 0 : return NULL;
876 : }
877 40126 : return translated;
878 : }
879 :
880 : /*******************************************************************
881 : A wrapper for vfs_chdir().
882 : ********************************************************************/
883 :
884 3186528 : int vfs_ChDir(connection_struct *conn, const struct smb_filename *smb_fname)
885 : {
886 18422 : int ret;
887 3186528 : struct smb_filename *cwd = NULL;
888 :
889 3186528 : if (!LastDir) {
890 978102 : LastDir = SMB_STRDUP("");
891 : }
892 :
893 3186528 : 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 6051806 : if (smb_fname->base_name[0] == '/' &&
923 2865278 : 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 1384358 : fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
935 1384358 : return 0;
936 : }
937 :
938 1802170 : DEBUG(4,("vfs_ChDir to %s\n", smb_fname->base_name));
939 :
940 1802170 : ret = SMB_VFS_CHDIR(conn, smb_fname);
941 1802170 : if (ret != 0) {
942 16847 : 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 1785306 : fsp_set_fd(conn->cwd_fsp, AT_FDCWD);
951 :
952 : /* conn cache. */
953 1785306 : cwd = vfs_GetWd(conn, conn);
954 1785306 : 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 1785306 : SAFE_FREE(LastDir);
989 1785306 : 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 1785306 : talloc_move(talloc_tos(), &conn->cwd_fsp->fsp_name);
997 :
998 1785306 : conn->cwd_fsp->fsp_name = talloc_move(conn->cwd_fsp, &cwd);
999 :
1000 1785306 : DBG_INFO("vfs_ChDir got %s\n", fsp_str_dbg(conn->cwd_fsp));
1001 :
1002 1780977 : 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 2413702 : struct smb_filename *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
1012 : {
1013 2413702 : struct smb_filename *current_dir_fname = NULL;
1014 4592 : struct file_id key;
1015 2413702 : struct smb_filename *smb_fname_dot = NULL;
1016 2413702 : struct smb_filename *smb_fname_full = NULL;
1017 2413702 : struct smb_filename *result = NULL;
1018 :
1019 2413702 : if (!lp_getwd_cache()) {
1020 0 : goto nocache;
1021 : }
1022 :
1023 2413702 : smb_fname_dot = synthetic_smb_fname(ctx,
1024 : ".",
1025 : NULL,
1026 : NULL,
1027 : 0,
1028 : 0);
1029 2413702 : if (smb_fname_dot == NULL) {
1030 0 : errno = ENOMEM;
1031 0 : goto out;
1032 : }
1033 :
1034 2413702 : 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 2413702 : key = vfs_file_id_from_sbuf(conn, &smb_fname_dot->st);
1045 :
1046 2413702 : smb_fname_full = (struct smb_filename *)memcache_lookup_talloc(
1047 : smbd_memcache(),
1048 : GETWD_CACHE,
1049 : data_blob_const(&key, sizeof(key)));
1050 :
1051 2413702 : if (smb_fname_full == NULL) {
1052 77364 : goto nocache;
1053 : }
1054 :
1055 2336338 : if ((SMB_VFS_STAT(conn, smb_fname_full) == 0) &&
1056 2336154 : (smb_fname_dot->st.st_ex_dev == smb_fname_full->st.st_ex_dev) &&
1057 2336154 : (smb_fname_dot->st.st_ex_ino == smb_fname_full->st.st_ex_ino) &&
1058 2336154 : (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 2336154 : result = cp_smb_filename(ctx, smb_fname_full);
1065 2336154 : if (result == NULL) {
1066 0 : errno = ENOMEM;
1067 : }
1068 2336154 : goto out;
1069 : }
1070 :
1071 184 : 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 77548 : current_dir_fname = SMB_VFS_GETWD(conn, ctx);
1080 77548 : 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 77548 : if (lp_getwd_cache() && VALID_STAT(smb_fname_dot->st)) {
1087 77548 : 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 77548 : result = cp_smb_filename(ctx, current_dir_fname);
1095 77548 : 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 77548 : talloc_set_destructor(current_dir_fname, NULL);
1105 :
1106 77548 : memcache_add_talloc(smbd_memcache(),
1107 : GETWD_CACHE,
1108 : data_blob_const(&key, sizeof(key)),
1109 : ¤t_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 2413702 : out:
1117 2413702 : 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 2413702 : return result;
1123 : }
1124 :
1125 : /*
1126 : * Ensure LSTAT is called for POSIX paths.
1127 : */
1128 36495 : int vfs_stat(struct connection_struct *conn,
1129 : struct smb_filename *smb_fname)
1130 : {
1131 36495 : if (smb_fname->flags & SMB_FILENAME_POSIX_PATH) {
1132 92 : return SMB_VFS_LSTAT(conn, smb_fname);
1133 : }
1134 36403 : return SMB_VFS_STAT(conn, smb_fname);
1135 : }
1136 :
1137 : /**
1138 : * XXX: This is temporary and there should be no callers of this once
1139 : * smb_filename is plumbed through all path based operations.
1140 : *
1141 : * Called when we know stream name parsing has already been done.
1142 : */
1143 0 : int vfs_stat_smb_basename(struct connection_struct *conn,
1144 : const struct smb_filename *smb_fname_in,
1145 : SMB_STRUCT_STAT *psbuf)
1146 : {
1147 0 : struct smb_filename smb_fname = {
1148 0 : .base_name = discard_const_p(char, smb_fname_in->base_name),
1149 0 : .flags = smb_fname_in->flags,
1150 0 : .twrp = smb_fname_in->twrp,
1151 : };
1152 0 : int ret;
1153 :
1154 0 : ret = vfs_stat(conn, &smb_fname);
1155 0 : if (ret != -1) {
1156 0 : *psbuf = smb_fname.st;
1157 : }
1158 0 : return ret;
1159 : }
1160 :
1161 : /**
1162 : * Ensure LSTAT is called for POSIX paths.
1163 : */
1164 :
1165 3460374 : NTSTATUS vfs_stat_fsp(files_struct *fsp)
1166 : {
1167 14121 : int ret;
1168 3460374 : struct stat_ex saved_stat = fsp->fsp_name->st;
1169 :
1170 3460374 : if (fsp->fake_file_handle != NULL) {
1171 0 : return NT_STATUS_OK;
1172 : }
1173 :
1174 3460374 : if (fsp_get_pathref_fd(fsp) == -1) {
1175 67 : if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
1176 67 : ret = SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
1177 : } else {
1178 0 : ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name);
1179 : }
1180 : } else {
1181 3460307 : ret = SMB_VFS_FSTAT(fsp, &fsp->fsp_name->st);
1182 : }
1183 3460374 : if (ret == -1) {
1184 0 : return map_nt_error_from_unix(errno);
1185 : }
1186 3460374 : update_stat_ex_from_saved_stat(&fsp->fsp_name->st, &saved_stat);
1187 3460374 : fsp->fsp_flags.is_directory = S_ISDIR(fsp->fsp_name->st.st_ex_mode);
1188 3460374 : return NT_STATUS_OK;
1189 : }
1190 :
1191 370032 : void init_smb_file_time(struct smb_file_time *ft)
1192 : {
1193 370848 : *ft = (struct smb_file_time) {
1194 370032 : .atime = make_omit_timespec(),
1195 370032 : .ctime = make_omit_timespec(),
1196 370032 : .mtime = make_omit_timespec(),
1197 370032 : .create_time = make_omit_timespec()
1198 : };
1199 370032 : }
1200 :
1201 : /**
1202 : * Initialize num_streams and streams, then call VFS op streaminfo
1203 : */
1204 :
1205 316938 : NTSTATUS vfs_fstreaminfo(struct files_struct *fsp,
1206 : TALLOC_CTX *mem_ctx,
1207 : unsigned int *num_streams,
1208 : struct stream_struct **streams)
1209 : {
1210 316938 : *num_streams = 0;
1211 316938 : *streams = NULL;
1212 :
1213 316938 : if (fsp == NULL) {
1214 : /*
1215 : * Callers may pass fsp == NULL when passing smb_fname->fsp of a
1216 : * symlink. This is ok, handle it here, by just return no
1217 : * streams on a symlink.
1218 : */
1219 0 : return NT_STATUS_OK;
1220 : }
1221 :
1222 316938 : if (fsp_get_pathref_fd(fsp) == -1) {
1223 : /*
1224 : * No streams on non-real files/directories.
1225 : */
1226 128 : return NT_STATUS_OK;
1227 : }
1228 :
1229 316810 : return SMB_VFS_FSTREAMINFO(fsp,
1230 : mem_ctx,
1231 : num_streams,
1232 : streams);
1233 : }
1234 :
1235 5414 : int vfs_fake_fd(void)
1236 : {
1237 0 : int pipe_fds[2];
1238 0 : int ret;
1239 :
1240 : /*
1241 : * Return a valid fd, but ensure any attempt to use
1242 : * it returns an error (EPIPE).
1243 : */
1244 5414 : ret = pipe(pipe_fds);
1245 5414 : if (ret != 0) {
1246 0 : return -1;
1247 : }
1248 :
1249 5414 : close(pipe_fds[1]);
1250 5414 : return pipe_fds[0];
1251 : }
1252 :
1253 : /*
1254 : * This is just a helper to make
1255 : * users of vfs_fake_fd() more symmetric
1256 : */
1257 5396 : int vfs_fake_fd_close(int fd)
1258 : {
1259 5396 : return close(fd);
1260 : }
1261 :
1262 : /*
1263 : generate a file_id from a stat structure
1264 : */
1265 9066686 : struct file_id vfs_file_id_from_sbuf(connection_struct *conn, const SMB_STRUCT_STAT *sbuf)
1266 : {
1267 9066686 : return SMB_VFS_FILE_ID_CREATE(conn, sbuf);
1268 : }
1269 :
1270 10142 : NTSTATUS vfs_at_fspcwd(TALLOC_CTX *mem_ctx,
1271 : struct connection_struct *conn,
1272 : struct files_struct **_fsp)
1273 : {
1274 10142 : struct files_struct *fsp = NULL;
1275 :
1276 10142 : fsp = talloc_zero(mem_ctx, struct files_struct);
1277 10142 : if (fsp == NULL) {
1278 0 : return NT_STATUS_NO_MEMORY;
1279 : }
1280 :
1281 10142 : fsp->fsp_name = synthetic_smb_fname(fsp, ".", NULL, NULL, 0, 0);
1282 10142 : if (fsp->fsp_name == NULL) {
1283 0 : TALLOC_FREE(fsp);
1284 0 : return NT_STATUS_NO_MEMORY;
1285 : }
1286 :
1287 10142 : fsp->fh = fd_handle_create(fsp);
1288 10142 : if (fsp->fh == NULL) {
1289 0 : TALLOC_FREE(fsp);
1290 0 : return NT_STATUS_NO_MEMORY;
1291 : }
1292 :
1293 10142 : fsp_set_fd(fsp, AT_FDCWD);
1294 10142 : fsp->fnum = FNUM_FIELD_INVALID;
1295 10142 : fsp->conn = conn;
1296 :
1297 10142 : *_fsp = fsp;
1298 10142 : return NT_STATUS_OK;
1299 : }
1300 :
1301 : static struct smb_vfs_deny_state *smb_vfs_deny_global;
1302 :
1303 14524 : void smb_vfs_assert_allowed(void)
1304 : {
1305 14524 : if (unlikely(smb_vfs_deny_global != NULL)) {
1306 0 : DBG_ERR("Called with VFS denied by %s\n",
1307 : smb_vfs_deny_global->location);
1308 0 : smb_panic("Called with VFS denied!");
1309 : }
1310 14524 : }
1311 :
1312 1111844 : void _smb_vfs_deny_push(struct smb_vfs_deny_state *state, const char *location)
1313 : {
1314 1111844 : SMB_ASSERT(smb_vfs_deny_global != state);
1315 :
1316 1111844 : *state = (struct smb_vfs_deny_state) {
1317 : .parent = smb_vfs_deny_global,
1318 : .location = location,
1319 : };
1320 :
1321 1111844 : smb_vfs_deny_global = state;
1322 1111844 : }
1323 :
1324 1111844 : void _smb_vfs_deny_pop(struct smb_vfs_deny_state *state, const char *location)
1325 : {
1326 1111844 : SMB_ASSERT(smb_vfs_deny_global == state);
1327 :
1328 1111844 : smb_vfs_deny_global = state->parent;
1329 :
1330 1111844 : *state = (struct smb_vfs_deny_state) { .parent = NULL, };
1331 1111844 : }
1332 :
1333 : #define VFS_FIND(__fn__) do { \
1334 : if (unlikely(smb_vfs_deny_global != NULL)) { \
1335 : DBG_ERR("Called with VFS denied by %s\n", \
1336 : smb_vfs_deny_global->location); \
1337 : smb_panic("Called with VFS denied!"); \
1338 : } \
1339 : while (handle->fns->__fn__##_fn==NULL) { \
1340 : handle = handle->next; \
1341 : } \
1342 : } while(0)
1343 :
1344 315264 : int smb_vfs_call_connect(struct vfs_handle_struct *handle,
1345 : const char *service, const char *user)
1346 : {
1347 368308 : VFS_FIND(connect);
1348 315264 : return handle->fns->connect_fn(handle, service, user);
1349 : }
1350 :
1351 150148 : void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
1352 : {
1353 367984 : VFS_FIND(disconnect);
1354 150148 : handle->fns->disconnect_fn(handle);
1355 150148 : }
1356 :
1357 3708 : uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
1358 : const struct smb_filename *smb_fname,
1359 : uint64_t *bsize,
1360 : uint64_t *dfree,
1361 : uint64_t *dsize)
1362 : {
1363 10004 : VFS_FIND(disk_free);
1364 3708 : return handle->fns->disk_free_fn(handle, smb_fname,
1365 : bsize, dfree, dsize);
1366 : }
1367 :
1368 7690 : int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
1369 : const struct smb_filename *smb_fname,
1370 : enum SMB_QUOTA_TYPE qtype,
1371 : unid_t id,
1372 : SMB_DISK_QUOTA *qt)
1373 : {
1374 20732 : VFS_FIND(get_quota);
1375 7690 : return handle->fns->get_quota_fn(handle, smb_fname, qtype, id, qt);
1376 : }
1377 :
1378 12 : int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
1379 : enum SMB_QUOTA_TYPE qtype, unid_t id,
1380 : SMB_DISK_QUOTA *qt)
1381 : {
1382 28 : VFS_FIND(set_quota);
1383 12 : return handle->fns->set_quota_fn(handle, qtype, id, qt);
1384 : }
1385 :
1386 3612 : int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
1387 : struct files_struct *fsp,
1388 : struct shadow_copy_data *shadow_copy_data,
1389 : bool labels)
1390 : {
1391 4680 : VFS_FIND(get_shadow_copy_data);
1392 3612 : return handle->fns->get_shadow_copy_data_fn(handle, fsp,
1393 : shadow_copy_data,
1394 : labels);
1395 : }
1396 68848 : int smb_vfs_call_statvfs(struct vfs_handle_struct *handle,
1397 : const struct smb_filename *smb_fname,
1398 : struct vfs_statvfs_struct *statbuf)
1399 : {
1400 188375 : VFS_FIND(statvfs);
1401 68848 : return handle->fns->statvfs_fn(handle, smb_fname, statbuf);
1402 : }
1403 :
1404 95244 : uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
1405 : enum timestamp_set_resolution *p_ts_res)
1406 : {
1407 188375 : VFS_FIND(fs_capabilities);
1408 95244 : return handle->fns->fs_capabilities_fn(handle, p_ts_res);
1409 : }
1410 :
1411 45620 : NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
1412 : struct dfs_GetDFSReferral *r)
1413 : {
1414 106920 : VFS_FIND(get_dfs_referrals);
1415 45620 : return handle->fns->get_dfs_referrals_fn(handle, r);
1416 : }
1417 :
1418 0 : NTSTATUS smb_vfs_call_create_dfs_pathat(struct vfs_handle_struct *handle,
1419 : struct files_struct *dirfsp,
1420 : const struct smb_filename *smb_fname,
1421 : const struct referral *reflist,
1422 : size_t referral_count)
1423 : {
1424 0 : VFS_FIND(create_dfs_pathat);
1425 0 : return handle->fns->create_dfs_pathat_fn(handle,
1426 : dirfsp,
1427 : smb_fname,
1428 : reflist,
1429 : referral_count);
1430 : }
1431 :
1432 14826 : NTSTATUS smb_vfs_call_read_dfs_pathat(struct vfs_handle_struct *handle,
1433 : TALLOC_CTX *mem_ctx,
1434 : struct files_struct *dirfsp,
1435 : struct smb_filename *smb_fname,
1436 : struct referral **ppreflist,
1437 : size_t *preferral_count)
1438 : {
1439 34596 : VFS_FIND(read_dfs_pathat);
1440 14826 : return handle->fns->read_dfs_pathat_fn(handle,
1441 : mem_ctx,
1442 : dirfsp,
1443 : smb_fname,
1444 : ppreflist,
1445 : preferral_count);
1446 : }
1447 :
1448 623394 : DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
1449 : struct files_struct *fsp,
1450 : const char *mask,
1451 : uint32_t attributes)
1452 : {
1453 1889305 : VFS_FIND(fdopendir);
1454 623394 : return handle->fns->fdopendir_fn(handle, fsp, mask, attributes);
1455 : }
1456 :
1457 322365088 : struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
1458 : struct files_struct *dirfsp,
1459 : DIR *dirp)
1460 : {
1461 870110013 : VFS_FIND(readdir);
1462 322365088 : return handle->fns->readdir_fn(handle, dirfsp, dirp);
1463 : }
1464 :
1465 5088 : void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
1466 : DIR *dirp)
1467 : {
1468 15454 : VFS_FIND(rewind_dir);
1469 5088 : handle->fns->rewind_dir_fn(handle, dirp);
1470 5088 : }
1471 :
1472 37488 : int smb_vfs_call_mkdirat(struct vfs_handle_struct *handle,
1473 : struct files_struct *dirfsp,
1474 : const struct smb_filename *smb_fname,
1475 : mode_t mode)
1476 : {
1477 75527 : VFS_FIND(mkdirat);
1478 37488 : return handle->fns->mkdirat_fn(handle,
1479 : dirfsp,
1480 : smb_fname,
1481 : mode);
1482 : }
1483 :
1484 623394 : int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
1485 : DIR *dir)
1486 : {
1487 1889305 : VFS_FIND(closedir);
1488 623394 : return handle->fns->closedir_fn(handle, dir);
1489 : }
1490 :
1491 25106823 : int smb_vfs_call_openat(struct vfs_handle_struct *handle,
1492 : const struct files_struct *dirfsp,
1493 : const struct smb_filename *smb_fname,
1494 : struct files_struct *fsp,
1495 : const struct vfs_open_how *how)
1496 : {
1497 39123282 : VFS_FIND(openat);
1498 25106823 : return handle->fns->openat_fn(handle,
1499 : dirfsp,
1500 : smb_fname,
1501 : fsp,
1502 : how);
1503 : }
1504 :
1505 1126703 : NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
1506 : struct smb_request *req,
1507 : struct files_struct *dirfsp,
1508 : struct smb_filename *smb_fname,
1509 : uint32_t access_mask,
1510 : uint32_t share_access,
1511 : uint32_t create_disposition,
1512 : uint32_t create_options,
1513 : uint32_t file_attributes,
1514 : uint32_t oplock_request,
1515 : const struct smb2_lease *lease,
1516 : uint64_t allocation_size,
1517 : uint32_t private_flags,
1518 : struct security_descriptor *sd,
1519 : struct ea_list *ea_list,
1520 : files_struct **result,
1521 : int *pinfo,
1522 : const struct smb2_create_blobs *in_context_blobs,
1523 : struct smb2_create_blobs *out_context_blobs)
1524 : {
1525 3387905 : VFS_FIND(create_file);
1526 1126703 : return handle->fns->create_file_fn(
1527 : handle, req, dirfsp, smb_fname,
1528 : access_mask, share_access, create_disposition, create_options,
1529 : file_attributes, oplock_request, lease, allocation_size,
1530 : private_flags, sd, ea_list,
1531 : result, pinfo, in_context_blobs, out_context_blobs);
1532 : }
1533 :
1534 8657537 : int smb_vfs_call_close(struct vfs_handle_struct *handle,
1535 : struct files_struct *fsp)
1536 : {
1537 25961310 : VFS_FIND(close);
1538 8657537 : return handle->fns->close_fn(handle, fsp);
1539 : }
1540 :
1541 11825 : ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
1542 : struct files_struct *fsp, void *data, size_t n,
1543 : off_t offset)
1544 : {
1545 24956 : VFS_FIND(pread);
1546 11825 : return handle->fns->pread_fn(handle, fsp, data, n, offset);
1547 : }
1548 :
1549 : struct smb_vfs_call_pread_state {
1550 : ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
1551 : ssize_t retval;
1552 : struct vfs_aio_state vfs_aio_state;
1553 : };
1554 :
1555 : static void smb_vfs_call_pread_done(struct tevent_req *subreq);
1556 :
1557 32760 : struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
1558 : TALLOC_CTX *mem_ctx,
1559 : struct tevent_context *ev,
1560 : struct files_struct *fsp,
1561 : void *data,
1562 : size_t n, off_t offset)
1563 : {
1564 42 : struct tevent_req *req, *subreq;
1565 42 : struct smb_vfs_call_pread_state *state;
1566 :
1567 32760 : req = tevent_req_create(mem_ctx, &state,
1568 : struct smb_vfs_call_pread_state);
1569 32760 : if (req == NULL) {
1570 0 : return NULL;
1571 : }
1572 83785 : VFS_FIND(pread_send);
1573 32760 : state->recv_fn = handle->fns->pread_recv_fn;
1574 :
1575 32760 : subreq = handle->fns->pread_send_fn(handle, state, ev, fsp, data, n,
1576 : offset);
1577 32760 : if (tevent_req_nomem(subreq, req)) {
1578 0 : return tevent_req_post(req, ev);
1579 : }
1580 32760 : tevent_req_set_callback(subreq, smb_vfs_call_pread_done, req);
1581 32760 : return req;
1582 : }
1583 :
1584 32760 : static void smb_vfs_call_pread_done(struct tevent_req *subreq)
1585 : {
1586 32760 : struct tevent_req *req = tevent_req_callback_data(
1587 : subreq, struct tevent_req);
1588 32760 : struct smb_vfs_call_pread_state *state = tevent_req_data(
1589 : req, struct smb_vfs_call_pread_state);
1590 :
1591 32760 : state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
1592 32760 : TALLOC_FREE(subreq);
1593 32760 : if (state->retval == -1) {
1594 0 : tevent_req_error(req, state->vfs_aio_state.error);
1595 0 : return;
1596 : }
1597 32760 : tevent_req_done(req);
1598 : }
1599 :
1600 32760 : ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req,
1601 : struct vfs_aio_state *vfs_aio_state)
1602 : {
1603 32760 : struct smb_vfs_call_pread_state *state = tevent_req_data(
1604 : req, struct smb_vfs_call_pread_state);
1605 42 : ssize_t retval;
1606 :
1607 32760 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1608 0 : tevent_req_received(req);
1609 0 : return -1;
1610 : }
1611 32760 : *vfs_aio_state = state->vfs_aio_state;
1612 32760 : retval = state->retval;
1613 32760 : tevent_req_received(req);
1614 32760 : return retval;
1615 : }
1616 :
1617 6398 : ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
1618 : struct files_struct *fsp, const void *data,
1619 : size_t n, off_t offset)
1620 : {
1621 9406 : VFS_FIND(pwrite);
1622 6398 : return handle->fns->pwrite_fn(handle, fsp, data, n, offset);
1623 : }
1624 :
1625 : struct smb_vfs_call_pwrite_state {
1626 : ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
1627 : ssize_t retval;
1628 : struct vfs_aio_state vfs_aio_state;
1629 : };
1630 :
1631 : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq);
1632 :
1633 418477 : struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle,
1634 : TALLOC_CTX *mem_ctx,
1635 : struct tevent_context *ev,
1636 : struct files_struct *fsp,
1637 : const void *data,
1638 : size_t n, off_t offset)
1639 : {
1640 52 : struct tevent_req *req, *subreq;
1641 52 : struct smb_vfs_call_pwrite_state *state;
1642 :
1643 418477 : req = tevent_req_create(mem_ctx, &state,
1644 : struct smb_vfs_call_pwrite_state);
1645 418477 : if (req == NULL) {
1646 0 : return NULL;
1647 : }
1648 999918 : VFS_FIND(pwrite_send);
1649 418477 : state->recv_fn = handle->fns->pwrite_recv_fn;
1650 :
1651 418477 : subreq = handle->fns->pwrite_send_fn(handle, state, ev, fsp, data, n,
1652 : offset);
1653 418477 : if (tevent_req_nomem(subreq, req)) {
1654 0 : return tevent_req_post(req, ev);
1655 : }
1656 418477 : tevent_req_set_callback(subreq, smb_vfs_call_pwrite_done, req);
1657 418477 : return req;
1658 : }
1659 :
1660 418473 : static void smb_vfs_call_pwrite_done(struct tevent_req *subreq)
1661 : {
1662 418473 : struct tevent_req *req = tevent_req_callback_data(
1663 : subreq, struct tevent_req);
1664 418473 : struct smb_vfs_call_pwrite_state *state = tevent_req_data(
1665 : req, struct smb_vfs_call_pwrite_state);
1666 :
1667 418473 : state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
1668 418473 : TALLOC_FREE(subreq);
1669 418473 : if (state->retval == -1) {
1670 0 : tevent_req_error(req, state->vfs_aio_state.error);
1671 0 : return;
1672 : }
1673 418473 : tevent_req_done(req);
1674 : }
1675 :
1676 418473 : ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req,
1677 : struct vfs_aio_state *vfs_aio_state)
1678 : {
1679 418473 : struct smb_vfs_call_pwrite_state *state = tevent_req_data(
1680 : req, struct smb_vfs_call_pwrite_state);
1681 52 : ssize_t retval;
1682 :
1683 418473 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1684 0 : tevent_req_received(req);
1685 0 : return -1;
1686 : }
1687 418473 : *vfs_aio_state = state->vfs_aio_state;
1688 418473 : retval = state->retval;
1689 418473 : tevent_req_received(req);
1690 418473 : return retval;
1691 : }
1692 :
1693 1109 : off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle,
1694 : struct files_struct *fsp, off_t offset,
1695 : int whence)
1696 : {
1697 3112 : VFS_FIND(lseek);
1698 1109 : return handle->fns->lseek_fn(handle, fsp, offset, whence);
1699 : }
1700 :
1701 0 : ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
1702 : files_struct *fromfsp, const DATA_BLOB *header,
1703 : off_t offset, size_t count)
1704 : {
1705 0 : VFS_FIND(sendfile);
1706 0 : return handle->fns->sendfile_fn(handle, tofd, fromfsp, header, offset,
1707 : count);
1708 : }
1709 :
1710 0 : ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
1711 : files_struct *tofsp, off_t offset,
1712 : size_t count)
1713 : {
1714 0 : VFS_FIND(recvfile);
1715 0 : return handle->fns->recvfile_fn(handle, fromfd, tofsp, offset, count);
1716 : }
1717 :
1718 3262 : int smb_vfs_call_renameat(struct vfs_handle_struct *handle,
1719 : files_struct *srcfsp,
1720 : const struct smb_filename *smb_fname_src,
1721 : files_struct *dstfsp,
1722 : const struct smb_filename *smb_fname_dst)
1723 : {
1724 6412 : VFS_FIND(renameat);
1725 3262 : return handle->fns->renameat_fn(handle,
1726 : srcfsp,
1727 : smb_fname_src,
1728 : dstfsp,
1729 : smb_fname_dst);
1730 : }
1731 :
1732 : struct smb_vfs_call_fsync_state {
1733 : int (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
1734 : int retval;
1735 : struct vfs_aio_state vfs_aio_state;
1736 : };
1737 :
1738 : static void smb_vfs_call_fsync_done(struct tevent_req *subreq);
1739 :
1740 404 : struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle,
1741 : TALLOC_CTX *mem_ctx,
1742 : struct tevent_context *ev,
1743 : struct files_struct *fsp)
1744 : {
1745 2 : struct tevent_req *req, *subreq;
1746 2 : struct smb_vfs_call_fsync_state *state;
1747 :
1748 404 : req = tevent_req_create(mem_ctx, &state,
1749 : struct smb_vfs_call_fsync_state);
1750 404 : if (req == NULL) {
1751 0 : return NULL;
1752 : }
1753 968 : VFS_FIND(fsync_send);
1754 404 : state->recv_fn = handle->fns->fsync_recv_fn;
1755 :
1756 404 : subreq = handle->fns->fsync_send_fn(handle, state, ev, fsp);
1757 404 : if (tevent_req_nomem(subreq, req)) {
1758 0 : return tevent_req_post(req, ev);
1759 : }
1760 404 : tevent_req_set_callback(subreq, smb_vfs_call_fsync_done, req);
1761 404 : return req;
1762 : }
1763 :
1764 404 : static void smb_vfs_call_fsync_done(struct tevent_req *subreq)
1765 : {
1766 404 : struct tevent_req *req = tevent_req_callback_data(
1767 : subreq, struct tevent_req);
1768 404 : struct smb_vfs_call_fsync_state *state = tevent_req_data(
1769 : req, struct smb_vfs_call_fsync_state);
1770 :
1771 404 : state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
1772 404 : TALLOC_FREE(subreq);
1773 404 : if (state->retval == -1) {
1774 0 : tevent_req_error(req, state->vfs_aio_state.error);
1775 0 : return;
1776 : }
1777 404 : tevent_req_done(req);
1778 : }
1779 :
1780 404 : int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state)
1781 : {
1782 404 : struct smb_vfs_call_fsync_state *state = tevent_req_data(
1783 : req, struct smb_vfs_call_fsync_state);
1784 2 : ssize_t retval;
1785 :
1786 404 : if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
1787 0 : tevent_req_received(req);
1788 0 : return -1;
1789 : }
1790 404 : *vfs_aio_state = state->vfs_aio_state;
1791 404 : retval = state->retval;
1792 404 : tevent_req_received(req);
1793 404 : return retval;
1794 : }
1795 :
1796 : /*
1797 : * Synchronous version of fsync, built from backend
1798 : * async VFS primitives. Uses a temporary sub-event
1799 : * context (NOT NESTED).
1800 : */
1801 :
1802 7 : int smb_vfs_fsync_sync(files_struct *fsp)
1803 : {
1804 7 : TALLOC_CTX *frame = talloc_stackframe();
1805 7 : struct tevent_req *req = NULL;
1806 7 : struct vfs_aio_state aio_state = { 0 };
1807 7 : int ret = -1;
1808 1 : bool ok;
1809 7 : struct tevent_context *ev = samba_tevent_context_init(frame);
1810 :
1811 7 : if (ev == NULL) {
1812 0 : goto out;
1813 : }
1814 :
1815 7 : req = SMB_VFS_FSYNC_SEND(talloc_tos(), ev, fsp);
1816 7 : if (req == NULL) {
1817 0 : goto out;
1818 : }
1819 :
1820 7 : ok = tevent_req_poll(req, ev);
1821 7 : if (!ok) {
1822 0 : goto out;
1823 : }
1824 :
1825 7 : ret = SMB_VFS_FSYNC_RECV(req, &aio_state);
1826 :
1827 7 : out:
1828 :
1829 7 : TALLOC_FREE(frame);
1830 7 : if (aio_state.error != 0) {
1831 0 : errno = aio_state.error;
1832 : }
1833 7 : return ret;
1834 : }
1835 :
1836 21580473 : int smb_vfs_call_stat(struct vfs_handle_struct *handle,
1837 : struct smb_filename *smb_fname)
1838 : {
1839 33009682 : VFS_FIND(stat);
1840 21580473 : return handle->fns->stat_fn(handle, smb_fname);
1841 : }
1842 :
1843 75179896 : int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
1844 : struct files_struct *fsp, SMB_STRUCT_STAT *sbuf)
1845 : {
1846 128558920 : VFS_FIND(fstat);
1847 75179896 : return handle->fns->fstat_fn(handle, fsp, sbuf);
1848 : }
1849 :
1850 130422 : int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
1851 : struct smb_filename *smb_filename)
1852 : {
1853 167135 : VFS_FIND(lstat);
1854 130422 : return handle->fns->lstat_fn(handle, smb_filename);
1855 : }
1856 :
1857 119675 : int smb_vfs_call_fstatat(
1858 : struct vfs_handle_struct *handle,
1859 : const struct files_struct *dirfsp,
1860 : const struct smb_filename *smb_fname,
1861 : SMB_STRUCT_STAT *sbuf,
1862 : int flags)
1863 : {
1864 257251 : VFS_FIND(fstatat);
1865 119675 : return handle->fns->fstatat_fn(handle, dirfsp, smb_fname, sbuf, flags);
1866 : }
1867 :
1868 3401602 : uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
1869 : struct files_struct *fsp,
1870 : const SMB_STRUCT_STAT *sbuf)
1871 : {
1872 10644856 : VFS_FIND(get_alloc_size);
1873 3401602 : return handle->fns->get_alloc_size_fn(handle, fsp, sbuf);
1874 : }
1875 :
1876 803094 : int smb_vfs_call_unlinkat(struct vfs_handle_struct *handle,
1877 : struct files_struct *dirfsp,
1878 : const struct smb_filename *smb_fname,
1879 : int flags)
1880 : {
1881 1035075 : VFS_FIND(unlinkat);
1882 803094 : return handle->fns->unlinkat_fn(handle,
1883 : dirfsp,
1884 : smb_fname,
1885 : flags);
1886 : }
1887 :
1888 21025 : int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
1889 : struct files_struct *fsp, mode_t mode)
1890 : {
1891 52022 : VFS_FIND(fchmod);
1892 21025 : return handle->fns->fchmod_fn(handle, fsp, mode);
1893 : }
1894 :
1895 213934 : int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
1896 : struct files_struct *fsp, uid_t uid, gid_t gid)
1897 : {
1898 554051 : VFS_FIND(fchown);
1899 213934 : return handle->fns->fchown_fn(handle, fsp, uid, gid);
1900 : }
1901 :
1902 0 : int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
1903 : const struct smb_filename *smb_fname,
1904 : uid_t uid,
1905 : gid_t gid)
1906 : {
1907 0 : VFS_FIND(lchown);
1908 0 : return handle->fns->lchown_fn(handle, smb_fname, uid, gid);
1909 : }
1910 :
1911 3902023 : int smb_vfs_call_chdir(struct vfs_handle_struct *handle,
1912 : const struct smb_filename *smb_fname)
1913 : {
1914 11562968 : VFS_FIND(chdir);
1915 3902023 : return handle->fns->chdir_fn(handle, smb_fname);
1916 : }
1917 :
1918 209026 : struct smb_filename *smb_vfs_call_getwd(struct vfs_handle_struct *handle,
1919 : TALLOC_CTX *ctx)
1920 : {
1921 548107 : VFS_FIND(getwd);
1922 209026 : return handle->fns->getwd_fn(handle, ctx);
1923 : }
1924 :
1925 27123 : int smb_vfs_call_fntimes(struct vfs_handle_struct *handle,
1926 : struct files_struct *fsp,
1927 : struct smb_file_time *ft)
1928 : {
1929 71024 : VFS_FIND(fntimes);
1930 27123 : return handle->fns->fntimes_fn(handle, fsp, ft);
1931 : }
1932 :
1933 2440 : int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
1934 : struct files_struct *fsp, off_t offset)
1935 : {
1936 7269 : VFS_FIND(ftruncate);
1937 2440 : return handle->fns->ftruncate_fn(handle, fsp, offset);
1938 : }
1939 :
1940 466 : int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
1941 : struct files_struct *fsp,
1942 : uint32_t mode,
1943 : off_t offset,
1944 : off_t len)
1945 : {
1946 1302 : VFS_FIND(fallocate);
1947 466 : return handle->fns->fallocate_fn(handle, fsp, mode, offset, len);
1948 : }
1949 :
1950 0 : int smb_vfs_call_filesystem_sharemode(struct vfs_handle_struct *handle,
1951 : struct files_struct *fsp,
1952 : uint32_t share_mode,
1953 : uint32_t access_mask)
1954 : {
1955 0 : VFS_FIND(filesystem_sharemode);
1956 0 : return handle->fns->filesystem_sharemode_fn(handle,
1957 : fsp,
1958 : share_mode,
1959 : access_mask);
1960 : }
1961 :
1962 771208 : int smb_vfs_call_fcntl(struct vfs_handle_struct *handle,
1963 : struct files_struct *fsp, int cmd, ...)
1964 : {
1965 898 : int result;
1966 898 : va_list cmd_arg;
1967 :
1968 2308100 : VFS_FIND(fcntl);
1969 :
1970 771208 : va_start(cmd_arg, cmd);
1971 771208 : result = handle->fns->fcntl_fn(handle, fsp, cmd, cmd_arg);
1972 771208 : va_end(cmd_arg);
1973 :
1974 771208 : return result;
1975 : }
1976 :
1977 26 : int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
1978 : struct files_struct *fsp, int leasetype)
1979 : {
1980 38 : VFS_FIND(linux_setlease);
1981 26 : return handle->fns->linux_setlease_fn(handle, fsp, leasetype);
1982 : }
1983 :
1984 160 : int smb_vfs_call_symlinkat(struct vfs_handle_struct *handle,
1985 : const struct smb_filename *link_target,
1986 : struct files_struct *dirfsp,
1987 : const struct smb_filename *new_smb_fname)
1988 : {
1989 448 : VFS_FIND(symlinkat);
1990 160 : return handle->fns->symlinkat_fn(handle,
1991 : link_target,
1992 : dirfsp,
1993 : new_smb_fname);
1994 : }
1995 :
1996 217921 : int smb_vfs_call_readlinkat(struct vfs_handle_struct *handle,
1997 : const struct files_struct *dirfsp,
1998 : const struct smb_filename *smb_fname,
1999 : char *buf,
2000 : size_t bufsiz)
2001 : {
2002 501825 : VFS_FIND(readlinkat);
2003 217921 : return handle->fns->readlinkat_fn(handle,
2004 : dirfsp,
2005 : smb_fname,
2006 : buf,
2007 : bufsiz);
2008 : }
2009 :
2010 107 : int smb_vfs_call_linkat(struct vfs_handle_struct *handle,
2011 : struct files_struct *srcfsp,
2012 : const struct smb_filename *old_smb_fname,
2013 : struct files_struct *dstfsp,
2014 : const struct smb_filename *new_smb_fname,
2015 : int flags)
2016 : {
2017 266 : VFS_FIND(linkat);
2018 107 : return handle->fns->linkat_fn(handle,
2019 : srcfsp,
2020 : old_smb_fname,
2021 : dstfsp,
2022 : new_smb_fname,
2023 : flags);
2024 : }
2025 :
2026 2 : int smb_vfs_call_mknodat(struct vfs_handle_struct *handle,
2027 : struct files_struct *dirfsp,
2028 : const struct smb_filename *smb_fname,
2029 : mode_t mode,
2030 : SMB_DEV_T dev)
2031 : {
2032 6 : VFS_FIND(mknodat);
2033 2 : return handle->fns->mknodat_fn(handle,
2034 : dirfsp,
2035 : smb_fname,
2036 : mode,
2037 : dev);
2038 : }
2039 :
2040 7707864 : struct smb_filename *smb_vfs_call_realpath(struct vfs_handle_struct *handle,
2041 : TALLOC_CTX *ctx,
2042 : const struct smb_filename *smb_fname)
2043 : {
2044 23019401 : VFS_FIND(realpath);
2045 7707864 : return handle->fns->realpath_fn(handle, ctx, smb_fname);
2046 : }
2047 :
2048 0 : int smb_vfs_call_fchflags(struct vfs_handle_struct *handle,
2049 : struct files_struct *fsp,
2050 : unsigned int flags)
2051 : {
2052 0 : VFS_FIND(fchflags);
2053 0 : return handle->fns->fchflags_fn(handle, fsp, flags);
2054 : }
2055 :
2056 70351666 : struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
2057 : const SMB_STRUCT_STAT *sbuf)
2058 : {
2059 137043716 : VFS_FIND(file_id_create);
2060 70351666 : return handle->fns->file_id_create_fn(handle, sbuf);
2061 : }
2062 :
2063 1789959 : uint64_t smb_vfs_call_fs_file_id(struct vfs_handle_struct *handle,
2064 : const SMB_STRUCT_STAT *sbuf)
2065 : {
2066 5766952 : VFS_FIND(fs_file_id);
2067 1789959 : return handle->fns->fs_file_id_fn(handle, sbuf);
2068 : }
2069 :
2070 994924 : NTSTATUS smb_vfs_call_fstreaminfo(struct vfs_handle_struct *handle,
2071 : struct files_struct *fsp,
2072 : TALLOC_CTX *mem_ctx,
2073 : unsigned int *num_streams,
2074 : struct stream_struct **streams)
2075 : {
2076 2060369 : VFS_FIND(fstreaminfo);
2077 994924 : return handle->fns->fstreaminfo_fn(handle, fsp, mem_ctx,
2078 : num_streams, streams);
2079 : }
2080 :
2081 550003 : NTSTATUS smb_vfs_call_get_real_filename_at(struct vfs_handle_struct *handle,
2082 : struct files_struct *dirfsp,
2083 : const char *name,
2084 : TALLOC_CTX *mem_ctx,
2085 : char **found_name)
2086 : {
2087 1684327 : VFS_FIND(get_real_filename_at);
2088 550003 : return handle->fns->get_real_filename_at_fn(
2089 : handle, dirfsp, name, mem_ctx, found_name);
2090 : }
2091 :
2092 8382128 : const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
2093 : const struct files_struct *dirfsp,
2094 : const struct smb_filename *smb_fname)
2095 : {
2096 25272705 : VFS_FIND(connectpath);
2097 8382128 : return handle->fns->connectpath_fn(handle, dirfsp, smb_fname);
2098 : }
2099 :
2100 461559 : bool smb_vfs_call_strict_lock_check(struct vfs_handle_struct *handle,
2101 : struct files_struct *fsp,
2102 : struct lock_struct *plock)
2103 : {
2104 1154011 : VFS_FIND(strict_lock_check);
2105 461559 : return handle->fns->strict_lock_check_fn(handle, fsp, plock);
2106 : }
2107 :
2108 320119314 : NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
2109 : const char *name,
2110 : enum vfs_translate_direction direction,
2111 : TALLOC_CTX *mem_ctx,
2112 : char **mapped_name)
2113 : {
2114 868339750 : VFS_FIND(translate_name);
2115 320119314 : return handle->fns->translate_name_fn(handle, name, direction, mem_ctx,
2116 : mapped_name);
2117 : }
2118 :
2119 8926052 : NTSTATUS smb_vfs_call_parent_pathname(struct vfs_handle_struct *handle,
2120 : TALLOC_CTX *mem_ctx,
2121 : const struct smb_filename *smb_fname_in,
2122 : struct smb_filename **parent_dir_out,
2123 : struct smb_filename **atname_out)
2124 : {
2125 26934269 : VFS_FIND(parent_pathname);
2126 8926052 : return handle->fns->parent_pathname_fn(handle,
2127 : mem_ctx,
2128 : smb_fname_in,
2129 : parent_dir_out,
2130 : atname_out);
2131 : }
2132 :
2133 4472 : NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
2134 : struct files_struct *fsp,
2135 : TALLOC_CTX *ctx,
2136 : uint32_t function,
2137 : uint16_t req_flags,
2138 : const uint8_t *in_data,
2139 : uint32_t in_len,
2140 : uint8_t **out_data,
2141 : uint32_t max_out_len,
2142 : uint32_t *out_len)
2143 : {
2144 10158 : VFS_FIND(fsctl);
2145 4472 : return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags,
2146 : in_data, in_len, out_data, max_out_len,
2147 : out_len);
2148 : }
2149 :
2150 2877325 : NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle,
2151 : struct files_struct *fsp,
2152 : uint32_t *dosmode)
2153 : {
2154 9057322 : VFS_FIND(fget_dos_attributes);
2155 2877325 : return handle->fns->fget_dos_attributes_fn(handle, fsp, dosmode);
2156 : }
2157 :
2158 350452 : NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle,
2159 : struct files_struct *fsp,
2160 : uint32_t dosmode)
2161 : {
2162 1061857 : VFS_FIND(fset_dos_attributes);
2163 350452 : return handle->fns->fset_dos_attributes_fn(handle, fsp, dosmode);
2164 : }
2165 :
2166 680 : struct tevent_req *smb_vfs_call_offload_read_send(TALLOC_CTX *mem_ctx,
2167 : struct tevent_context *ev,
2168 : struct vfs_handle_struct *handle,
2169 : struct files_struct *fsp,
2170 : uint32_t fsctl,
2171 : uint32_t ttl,
2172 : off_t offset,
2173 : size_t to_copy)
2174 : {
2175 1890 : VFS_FIND(offload_read_send);
2176 680 : return handle->fns->offload_read_send_fn(mem_ctx, ev, handle,
2177 : fsp, fsctl,
2178 : ttl, offset, to_copy);
2179 : }
2180 :
2181 680 : NTSTATUS smb_vfs_call_offload_read_recv(struct tevent_req *req,
2182 : struct vfs_handle_struct *handle,
2183 : TALLOC_CTX *mem_ctx,
2184 : uint32_t *flags,
2185 : uint64_t *xferlen,
2186 : DATA_BLOB *token_blob)
2187 : {
2188 1890 : VFS_FIND(offload_read_recv);
2189 680 : return handle->fns->offload_read_recv_fn(req, handle, mem_ctx, flags, xferlen, token_blob);
2190 : }
2191 :
2192 760 : struct tevent_req *smb_vfs_call_offload_write_send(struct vfs_handle_struct *handle,
2193 : TALLOC_CTX *mem_ctx,
2194 : struct tevent_context *ev,
2195 : uint32_t fsctl,
2196 : DATA_BLOB *token,
2197 : off_t transfer_offset,
2198 : struct files_struct *dest_fsp,
2199 : off_t dest_off,
2200 : off_t num)
2201 : {
2202 2114 : VFS_FIND(offload_write_send);
2203 760 : return handle->fns->offload_write_send_fn(handle, mem_ctx, ev, fsctl,
2204 : token, transfer_offset,
2205 : dest_fsp, dest_off, num);
2206 : }
2207 :
2208 760 : NTSTATUS smb_vfs_call_offload_write_recv(struct vfs_handle_struct *handle,
2209 : struct tevent_req *req,
2210 : off_t *copied)
2211 : {
2212 2114 : VFS_FIND(offload_write_recv);
2213 760 : return handle->fns->offload_write_recv_fn(handle, req, copied);
2214 : }
2215 :
2216 : struct smb_vfs_call_get_dos_attributes_state {
2217 : files_struct *dir_fsp;
2218 : NTSTATUS (*recv_fn)(struct tevent_req *req,
2219 : struct vfs_aio_state *aio_state,
2220 : uint32_t *dosmode);
2221 : struct vfs_aio_state aio_state;
2222 : uint32_t dos_attributes;
2223 : };
2224 :
2225 : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq);
2226 :
2227 20143 : struct tevent_req *smb_vfs_call_get_dos_attributes_send(
2228 : TALLOC_CTX *mem_ctx,
2229 : struct tevent_context *ev,
2230 : struct vfs_handle_struct *handle,
2231 : files_struct *dir_fsp,
2232 : struct smb_filename *smb_fname)
2233 : {
2234 20143 : struct tevent_req *req = NULL;
2235 20143 : struct smb_vfs_call_get_dos_attributes_state *state = NULL;
2236 20143 : struct tevent_req *subreq = NULL;
2237 :
2238 20143 : req = tevent_req_create(mem_ctx, &state,
2239 : struct smb_vfs_call_get_dos_attributes_state);
2240 20143 : if (req == NULL) {
2241 0 : return NULL;
2242 : }
2243 :
2244 50361 : VFS_FIND(get_dos_attributes_send);
2245 :
2246 20143 : *state = (struct smb_vfs_call_get_dos_attributes_state) {
2247 : .dir_fsp = dir_fsp,
2248 20143 : .recv_fn = handle->fns->get_dos_attributes_recv_fn,
2249 : };
2250 :
2251 20143 : subreq = handle->fns->get_dos_attributes_send_fn(mem_ctx,
2252 : ev,
2253 : handle,
2254 : dir_fsp,
2255 : smb_fname);
2256 20143 : if (tevent_req_nomem(subreq, req)) {
2257 0 : return tevent_req_post(req, ev);
2258 : }
2259 20143 : tevent_req_defer_callback(req, ev);
2260 :
2261 20143 : tevent_req_set_callback(subreq,
2262 : smb_vfs_call_get_dos_attributes_done,
2263 : req);
2264 :
2265 20143 : return req;
2266 : }
2267 :
2268 20143 : static void smb_vfs_call_get_dos_attributes_done(struct tevent_req *subreq)
2269 : {
2270 0 : struct tevent_req *req =
2271 20143 : tevent_req_callback_data(subreq,
2272 : struct tevent_req);
2273 0 : struct smb_vfs_call_get_dos_attributes_state *state =
2274 20143 : tevent_req_data(req,
2275 : struct smb_vfs_call_get_dos_attributes_state);
2276 0 : NTSTATUS status;
2277 0 : bool ok;
2278 :
2279 : /*
2280 : * Make sure we run as the user again
2281 : */
2282 20143 : ok = change_to_user_and_service_by_fsp(state->dir_fsp);
2283 20143 : SMB_ASSERT(ok);
2284 :
2285 20143 : status = state->recv_fn(subreq,
2286 : &state->aio_state,
2287 : &state->dos_attributes);
2288 20143 : TALLOC_FREE(subreq);
2289 20143 : if (tevent_req_nterror(req, status)) {
2290 126 : return;
2291 : }
2292 :
2293 20017 : tevent_req_done(req);
2294 : }
2295 :
2296 20143 : NTSTATUS smb_vfs_call_get_dos_attributes_recv(
2297 : struct tevent_req *req,
2298 : struct vfs_aio_state *aio_state,
2299 : uint32_t *dos_attributes)
2300 : {
2301 0 : struct smb_vfs_call_get_dos_attributes_state *state =
2302 20143 : tevent_req_data(req,
2303 : struct smb_vfs_call_get_dos_attributes_state);
2304 0 : NTSTATUS status;
2305 :
2306 20143 : if (tevent_req_is_nterror(req, &status)) {
2307 126 : tevent_req_received(req);
2308 126 : return status;
2309 : }
2310 :
2311 20017 : *aio_state = state->aio_state;
2312 20017 : *dos_attributes = state->dos_attributes;
2313 20017 : tevent_req_received(req);
2314 20017 : return NT_STATUS_OK;
2315 : }
2316 :
2317 0 : NTSTATUS smb_vfs_call_fget_compression(vfs_handle_struct *handle,
2318 : TALLOC_CTX *mem_ctx,
2319 : struct files_struct *fsp,
2320 : uint16_t *_compression_fmt)
2321 : {
2322 0 : VFS_FIND(fget_compression);
2323 0 : return handle->fns->fget_compression_fn(handle, mem_ctx, fsp,
2324 : _compression_fmt);
2325 : }
2326 :
2327 0 : NTSTATUS smb_vfs_call_set_compression(vfs_handle_struct *handle,
2328 : TALLOC_CTX *mem_ctx,
2329 : struct files_struct *fsp,
2330 : uint16_t compression_fmt)
2331 : {
2332 0 : VFS_FIND(set_compression);
2333 0 : return handle->fns->set_compression_fn(handle, mem_ctx, fsp,
2334 : compression_fmt);
2335 : }
2336 :
2337 68 : NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle,
2338 : TALLOC_CTX *mem_ctx,
2339 : const char *service_path,
2340 : char **base_volume)
2341 : {
2342 68 : VFS_FIND(snap_check_path);
2343 68 : return handle->fns->snap_check_path_fn(handle, mem_ctx, service_path,
2344 : base_volume);
2345 : }
2346 :
2347 16 : NTSTATUS smb_vfs_call_snap_create(struct vfs_handle_struct *handle,
2348 : TALLOC_CTX *mem_ctx,
2349 : const char *base_volume,
2350 : time_t *tstamp,
2351 : bool rw,
2352 : char **base_path,
2353 : char **snap_path)
2354 : {
2355 16 : VFS_FIND(snap_create);
2356 16 : return handle->fns->snap_create_fn(handle, mem_ctx, base_volume, tstamp,
2357 : rw, base_path, snap_path);
2358 : }
2359 :
2360 10 : NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle,
2361 : TALLOC_CTX *mem_ctx,
2362 : char *base_path,
2363 : char *snap_path)
2364 : {
2365 10 : VFS_FIND(snap_delete);
2366 10 : return handle->fns->snap_delete_fn(handle, mem_ctx, base_path,
2367 : snap_path);
2368 : }
2369 :
2370 1650232 : NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
2371 : struct files_struct *fsp,
2372 : uint32_t security_info,
2373 : TALLOC_CTX *mem_ctx,
2374 : struct security_descriptor **ppdesc)
2375 : {
2376 3129881 : VFS_FIND(fget_nt_acl);
2377 1650232 : return handle->fns->fget_nt_acl_fn(handle, fsp, security_info,
2378 : mem_ctx, ppdesc);
2379 : }
2380 :
2381 499045 : NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
2382 : struct files_struct *fsp,
2383 : uint32_t security_info_sent,
2384 : const struct security_descriptor *psd)
2385 : {
2386 1038349 : VFS_FIND(fset_nt_acl);
2387 499045 : return handle->fns->fset_nt_acl_fn(handle, fsp, security_info_sent,
2388 : psd);
2389 : }
2390 :
2391 0 : NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
2392 : struct smb_filename *file,
2393 : struct security_acl *sacl,
2394 : uint32_t access_requested,
2395 : uint32_t access_denied)
2396 : {
2397 0 : VFS_FIND(audit_file);
2398 0 : return handle->fns->audit_file_fn(handle,
2399 : file,
2400 : sacl,
2401 : access_requested,
2402 : access_denied);
2403 : }
2404 :
2405 2074291 : SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
2406 : struct files_struct *fsp,
2407 : SMB_ACL_TYPE_T type,
2408 : TALLOC_CTX *mem_ctx)
2409 : {
2410 3085895 : VFS_FIND(sys_acl_get_fd);
2411 2074291 : return handle->fns->sys_acl_get_fd_fn(handle, fsp, type, mem_ctx);
2412 : }
2413 :
2414 913158 : int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
2415 : struct files_struct *fsp,
2416 : TALLOC_CTX *mem_ctx,
2417 : char **blob_description,
2418 : DATA_BLOB *blob)
2419 : {
2420 924066 : VFS_FIND(sys_acl_blob_get_fd);
2421 913158 : return handle->fns->sys_acl_blob_get_fd_fn(handle, fsp, mem_ctx, blob_description, blob);
2422 : }
2423 :
2424 329411 : int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
2425 : struct files_struct *fsp,
2426 : SMB_ACL_TYPE_T type,
2427 : SMB_ACL_T theacl)
2428 : {
2429 402670 : VFS_FIND(sys_acl_set_fd);
2430 329411 : return handle->fns->sys_acl_set_fd_fn(handle, fsp, type, theacl);
2431 : }
2432 :
2433 321 : int smb_vfs_call_sys_acl_delete_def_fd(struct vfs_handle_struct *handle,
2434 : struct files_struct *fsp)
2435 : {
2436 788 : VFS_FIND(sys_acl_delete_def_fd);
2437 321 : return handle->fns->sys_acl_delete_def_fd_fn(handle, fsp);
2438 : }
2439 :
2440 : struct smb_vfs_call_getxattrat_state {
2441 : files_struct *dir_fsp;
2442 : ssize_t (*recv_fn)(struct tevent_req *req,
2443 : struct vfs_aio_state *aio_state,
2444 : TALLOC_CTX *mem_ctx,
2445 : uint8_t **xattr_value);
2446 : ssize_t retval;
2447 : uint8_t *xattr_value;
2448 : struct vfs_aio_state aio_state;
2449 : };
2450 :
2451 : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq);
2452 :
2453 20145 : struct tevent_req *smb_vfs_call_getxattrat_send(
2454 : TALLOC_CTX *mem_ctx,
2455 : struct tevent_context *ev,
2456 : struct vfs_handle_struct *handle,
2457 : files_struct *dir_fsp,
2458 : const struct smb_filename *smb_fname,
2459 : const char *xattr_name,
2460 : size_t alloc_hint)
2461 : {
2462 20145 : struct tevent_req *req = NULL;
2463 20145 : struct smb_vfs_call_getxattrat_state *state = NULL;
2464 20145 : struct tevent_req *subreq = NULL;
2465 :
2466 20145 : req = tevent_req_create(mem_ctx, &state,
2467 : struct smb_vfs_call_getxattrat_state);
2468 20145 : if (req == NULL) {
2469 0 : return NULL;
2470 : }
2471 :
2472 40297 : VFS_FIND(getxattrat_send);
2473 :
2474 20145 : *state = (struct smb_vfs_call_getxattrat_state) {
2475 : .dir_fsp = dir_fsp,
2476 20145 : .recv_fn = handle->fns->getxattrat_recv_fn,
2477 : };
2478 :
2479 20145 : subreq = handle->fns->getxattrat_send_fn(mem_ctx,
2480 : ev,
2481 : handle,
2482 : dir_fsp,
2483 : smb_fname,
2484 : xattr_name,
2485 : alloc_hint);
2486 20145 : if (tevent_req_nomem(subreq, req)) {
2487 0 : return tevent_req_post(req, ev);
2488 : }
2489 20145 : tevent_req_defer_callback(req, ev);
2490 :
2491 20145 : tevent_req_set_callback(subreq, smb_vfs_call_getxattrat_done, req);
2492 20145 : return req;
2493 : }
2494 :
2495 20145 : static void smb_vfs_call_getxattrat_done(struct tevent_req *subreq)
2496 : {
2497 20145 : struct tevent_req *req = tevent_req_callback_data(
2498 : subreq, struct tevent_req);
2499 20145 : struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
2500 : req, struct smb_vfs_call_getxattrat_state);
2501 0 : bool ok;
2502 :
2503 : /*
2504 : * Make sure we run as the user again
2505 : */
2506 20145 : ok = change_to_user_and_service_by_fsp(state->dir_fsp);
2507 20145 : SMB_ASSERT(ok);
2508 :
2509 20145 : state->retval = state->recv_fn(subreq,
2510 : &state->aio_state,
2511 : state,
2512 : &state->xattr_value);
2513 20145 : TALLOC_FREE(subreq);
2514 20145 : if (state->retval == -1) {
2515 128 : tevent_req_error(req, state->aio_state.error);
2516 128 : return;
2517 : }
2518 :
2519 20017 : tevent_req_done(req);
2520 : }
2521 :
2522 20145 : ssize_t smb_vfs_call_getxattrat_recv(struct tevent_req *req,
2523 : struct vfs_aio_state *aio_state,
2524 : TALLOC_CTX *mem_ctx,
2525 : uint8_t **xattr_value)
2526 : {
2527 20145 : struct smb_vfs_call_getxattrat_state *state = tevent_req_data(
2528 : req, struct smb_vfs_call_getxattrat_state);
2529 0 : size_t xattr_size;
2530 :
2531 20145 : if (tevent_req_is_unix_error(req, &aio_state->error)) {
2532 128 : tevent_req_received(req);
2533 128 : return -1;
2534 : }
2535 :
2536 20017 : *aio_state = state->aio_state;
2537 20017 : xattr_size = state->retval;
2538 20017 : if (xattr_value != NULL) {
2539 20017 : *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
2540 : }
2541 :
2542 20017 : tevent_req_received(req);
2543 20017 : return xattr_size;
2544 : }
2545 :
2546 26291647 : ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
2547 : struct files_struct *fsp, const char *name,
2548 : void *value, size_t size)
2549 : {
2550 29760452 : VFS_FIND(fgetxattr);
2551 26291647 : return handle->fns->fgetxattr_fn(handle, fsp, name, value, size);
2552 : }
2553 :
2554 1487303 : ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
2555 : struct files_struct *fsp, char *list,
2556 : size_t size)
2557 : {
2558 2608993 : VFS_FIND(flistxattr);
2559 1487303 : return handle->fns->flistxattr_fn(handle, fsp, list, size);
2560 : }
2561 :
2562 4485 : int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
2563 : struct files_struct *fsp, const char *name)
2564 : {
2565 7007 : VFS_FIND(fremovexattr);
2566 4485 : return handle->fns->fremovexattr_fn(handle, fsp, name);
2567 : }
2568 :
2569 1123303 : int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
2570 : struct files_struct *fsp, const char *name,
2571 : const void *value, size_t size, int flags)
2572 : {
2573 1593962 : VFS_FIND(fsetxattr);
2574 1123303 : return handle->fns->fsetxattr_fn(handle, fsp, name, value, size, flags);
2575 : }
2576 :
2577 193 : bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
2578 : struct files_struct *fsp)
2579 : {
2580 532 : VFS_FIND(aio_force);
2581 193 : return handle->fns->aio_force_fn(handle, fsp);
2582 : }
2583 :
2584 1318 : NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
2585 : struct files_struct *fsp,
2586 : TALLOC_CTX *mem_ctx,
2587 : DATA_BLOB *cookie)
2588 : {
2589 3670 : VFS_FIND(durable_cookie);
2590 1318 : return handle->fns->durable_cookie_fn(handle, fsp, mem_ctx, cookie);
2591 : }
2592 :
2593 392 : NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle,
2594 : struct files_struct *fsp,
2595 : const DATA_BLOB old_cookie,
2596 : TALLOC_CTX *mem_ctx,
2597 : DATA_BLOB *new_cookie)
2598 : {
2599 1106 : VFS_FIND(durable_disconnect);
2600 392 : return handle->fns->durable_disconnect_fn(handle, fsp, old_cookie,
2601 : mem_ctx, new_cookie);
2602 : }
2603 :
2604 378 : NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle,
2605 : struct smb_request *smb1req,
2606 : struct smbXsrv_open *op,
2607 : const DATA_BLOB old_cookie,
2608 : TALLOC_CTX *mem_ctx,
2609 : struct files_struct **fsp,
2610 : DATA_BLOB *new_cookie)
2611 : {
2612 1050 : VFS_FIND(durable_reconnect);
2613 378 : return handle->fns->durable_reconnect_fn(handle, smb1req, op,
2614 : old_cookie, mem_ctx, fsp,
2615 : new_cookie);
2616 : }
2617 :
2618 1743058 : NTSTATUS smb_vfs_call_freaddir_attr(struct vfs_handle_struct *handle,
2619 : struct files_struct *fsp,
2620 : TALLOC_CTX *mem_ctx,
2621 : struct readdir_attr_data **attr_data)
2622 : {
2623 5640555 : VFS_FIND(freaddir_attr);
2624 1743058 : return handle->fns->freaddir_attr_fn(handle,
2625 : fsp,
2626 : mem_ctx,
2627 : attr_data);
2628 : }
2629 :
2630 16496 : bool smb_vfs_call_lock(struct vfs_handle_struct *handle,
2631 : struct files_struct *fsp, int op, off_t offset,
2632 : off_t count, int type)
2633 : {
2634 37806 : VFS_FIND(lock);
2635 16496 : return handle->fns->lock_fn(handle, fsp, op, offset, count, type);
2636 : }
2637 :
2638 466522 : bool smb_vfs_call_getlock(struct vfs_handle_struct *handle,
2639 : struct files_struct *fsp, off_t *poffset,
2640 : off_t *pcount, int *ptype, pid_t *ppid)
2641 : {
2642 1161975 : VFS_FIND(getlock);
2643 466522 : return handle->fns->getlock_fn(handle, fsp, poffset, pcount, ptype,
2644 : ppid);
2645 : }
2646 :
2647 17121 : NTSTATUS smb_vfs_call_brl_lock_windows(struct vfs_handle_struct *handle,
2648 : struct byte_range_lock *br_lck,
2649 : struct lock_struct *plock)
2650 : {
2651 40381 : VFS_FIND(brl_lock_windows);
2652 17121 : return handle->fns->brl_lock_windows_fn(handle, br_lck, plock);
2653 : }
2654 :
2655 8447 : bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct *handle,
2656 : struct byte_range_lock *br_lck,
2657 : const struct lock_struct *plock)
2658 : {
2659 20079 : VFS_FIND(brl_unlock_windows);
2660 8447 : return handle->fns->brl_unlock_windows_fn(handle, br_lck, plock);
2661 : }
|