s4:ldap_server: Store whether an LDAP connection is over ldapi
[Samba.git] / examples / VFS / skel_transparent.c
blob461228f09afd617cfce94da8ae2d687da0b58bfd
1 /*
2 * Skeleton VFS module. Implements passthrough operation of all VFS
3 * calls to disk functions.
5 * Copyright (C) Tim Potter, 1999-2000
6 * Copyright (C) Alexander Bokovoy, 2002
7 * Copyright (C) Stefan (metze) Metzmacher, 2003
8 * Copyright (C) Jeremy Allison 2009
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.
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.
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/>.
24 #include "../source3/include/includes.h"
25 #include "lib/util/tevent_unix.h"
26 #include "lib/util/tevent_ntstatus.h"
28 /* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE
29 SAMBA DEVELOPERS GUIDE!!!!!!
32 /* If you take this file as template for your module
33 * please make sure that you remove all skel_XXX() functions you don't
34 * want to implement!! The passthrough operations are not
35 * necessary in a real module.
37 * --metze
40 static int skel_connect(vfs_handle_struct *handle, const char *service,
41 const char *user)
43 return SMB_VFS_NEXT_CONNECT(handle, service, user);
46 static void skel_disconnect(vfs_handle_struct *handle)
48 SMB_VFS_NEXT_DISCONNECT(handle);
51 static uint64_t skel_disk_free(vfs_handle_struct *handle,
52 const struct smb_filename *smb_fname,
53 uint64_t *bsize,
54 uint64_t *dfree,
55 uint64_t *dsize)
57 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree, dsize);
60 static int skel_get_quota(vfs_handle_struct *handle,
61 const struct smb_filename *smb_fname,
62 enum SMB_QUOTA_TYPE qtype,
63 unid_t id,
64 SMB_DISK_QUOTA *dq)
66 return SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, dq);
69 static int skel_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype,
70 unid_t id, SMB_DISK_QUOTA *dq)
72 return SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq);
75 static int skel_get_shadow_copy_data(vfs_handle_struct *handle,
76 files_struct *fsp,
77 struct shadow_copy_data *shadow_copy_data,
78 bool labels)
80 return SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data,
81 labels);
84 static int skel_statvfs(struct vfs_handle_struct *handle,
85 const struct smb_filename *smb_fname,
86 struct vfs_statvfs_struct *statbuf)
88 return SMB_VFS_NEXT_STATVFS(handle, smb_fname, statbuf);
91 static uint32_t skel_fs_capabilities(struct vfs_handle_struct *handle,
92 enum timestamp_set_resolution *p_ts_res)
94 return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
97 static NTSTATUS skel_get_dfs_referrals(struct vfs_handle_struct *handle,
98 struct dfs_GetDFSReferral *r)
100 return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
103 static NTSTATUS skel_create_dfs_pathat(struct vfs_handle_struct *handle,
104 struct files_struct *dirfsp,
105 const struct smb_filename *smb_fname,
106 const struct referral *reflist,
107 size_t referral_count)
109 return SMB_VFS_NEXT_CREATE_DFS_PATHAT(handle,
110 dirfsp,
111 smb_fname,
112 reflist,
113 referral_count);
116 static NTSTATUS skel_read_dfs_pathat(struct vfs_handle_struct *handle,
117 TALLOC_CTX *mem_ctx,
118 struct files_struct *dirfsp,
119 struct smb_filename *smb_fname,
120 struct referral **ppreflist,
121 size_t *preferral_count)
123 return SMB_VFS_NEXT_READ_DFS_PATHAT(handle,
124 mem_ctx,
125 dirfsp,
126 smb_fname,
127 ppreflist,
128 preferral_count);
131 static NTSTATUS skel_snap_check_path(struct vfs_handle_struct *handle,
132 TALLOC_CTX *mem_ctx,
133 const char *service_path,
134 char **base_volume)
136 return SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
137 base_volume);
140 static NTSTATUS skel_snap_create(struct vfs_handle_struct *handle,
141 TALLOC_CTX *mem_ctx,
142 const char *base_volume,
143 time_t *tstamp,
144 bool rw,
145 char **base_path,
146 char **snap_path)
148 return SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
149 rw, base_path, snap_path);
152 static NTSTATUS skel_snap_delete(struct vfs_handle_struct *handle,
153 TALLOC_CTX *mem_ctx,
154 char *base_path,
155 char *snap_path)
157 return SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path, snap_path);
160 static DIR *skel_fdopendir(vfs_handle_struct *handle, files_struct *fsp,
161 const char *mask, uint32_t attr)
163 return SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
166 static struct dirent *
167 skel_readdir(vfs_handle_struct *handle, struct files_struct *dirfsp, DIR *dirp)
169 return SMB_VFS_NEXT_READDIR(handle, dirfsp, dirp);
172 static void skel_rewind_dir(vfs_handle_struct *handle, DIR *dirp)
174 SMB_VFS_NEXT_REWINDDIR(handle, dirp);
177 static int skel_mkdirat(vfs_handle_struct *handle,
178 struct files_struct *dirfsp,
179 const struct smb_filename *smb_fname,
180 mode_t mode)
182 return SMB_VFS_NEXT_MKDIRAT(handle,
183 dirfsp,
184 smb_fname,
185 mode);
188 static int skel_closedir(vfs_handle_struct *handle, DIR *dir)
190 return SMB_VFS_NEXT_CLOSEDIR(handle, dir);
193 static int skel_openat(struct vfs_handle_struct *handle,
194 const struct files_struct *dirfsp,
195 const struct smb_filename *smb_fname,
196 struct files_struct *fsp,
197 const struct vfs_open_how *how)
199 return SMB_VFS_NEXT_OPENAT(handle, dirfsp, smb_fname, fsp, how);
202 static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
203 struct smb_request *req,
204 struct files_struct *dirfsp,
205 struct smb_filename *smb_fname,
206 uint32_t access_mask,
207 uint32_t share_access,
208 uint32_t create_disposition,
209 uint32_t create_options,
210 uint32_t file_attributes,
211 uint32_t oplock_request,
212 const struct smb2_lease *lease,
213 uint64_t allocation_size,
214 uint32_t private_flags,
215 struct security_descriptor *sd,
216 struct ea_list *ea_list,
217 files_struct ** result, int *pinfo,
218 const struct smb2_create_blobs *in_context_blobs,
219 struct smb2_create_blobs *out_context_blobs)
221 return SMB_VFS_NEXT_CREATE_FILE(handle,
222 req,
223 dirfsp,
224 smb_fname,
225 access_mask,
226 share_access,
227 create_disposition,
228 create_options,
229 file_attributes,
230 oplock_request,
231 lease,
232 allocation_size,
233 private_flags,
234 sd, ea_list, result, pinfo,
235 in_context_blobs, out_context_blobs);
238 static int skel_close_fn(vfs_handle_struct *handle, files_struct *fsp)
240 return SMB_VFS_NEXT_CLOSE(handle, fsp);
243 static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp,
244 void *data, size_t n, off_t offset)
246 return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
249 struct skel_pread_state {
250 ssize_t ret;
251 struct vfs_aio_state vfs_aio_state;
254 static void skel_pread_done(struct tevent_req *subreq);
256 static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
257 TALLOC_CTX *mem_ctx,
258 struct tevent_context *ev,
259 struct files_struct *fsp,
260 void *data, size_t n, off_t offset)
262 struct tevent_req *req, *subreq;
263 struct skel_pread_state *state;
265 req = tevent_req_create(mem_ctx, &state, struct skel_pread_state);
266 if (req == NULL) {
267 return NULL;
269 subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
270 n, offset);
271 if (tevent_req_nomem(subreq, req)) {
272 return tevent_req_post(req, ev);
274 tevent_req_set_callback(subreq, skel_pread_done, req);
275 return req;
278 static void skel_pread_done(struct tevent_req *subreq)
280 struct tevent_req *req =
281 tevent_req_callback_data(subreq, struct tevent_req);
282 struct skel_pread_state *state =
283 tevent_req_data(req, struct skel_pread_state);
285 state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
286 TALLOC_FREE(subreq);
287 tevent_req_done(req);
290 static ssize_t skel_pread_recv(struct tevent_req *req,
291 struct vfs_aio_state *vfs_aio_state)
293 struct skel_pread_state *state =
294 tevent_req_data(req, struct skel_pread_state);
296 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
297 return -1;
299 *vfs_aio_state = state->vfs_aio_state;
300 return state->ret;
303 static ssize_t skel_pwrite(vfs_handle_struct *handle, files_struct *fsp,
304 const void *data, size_t n, off_t offset)
306 return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
309 struct skel_pwrite_state {
310 ssize_t ret;
311 struct vfs_aio_state vfs_aio_state;
314 static void skel_pwrite_done(struct tevent_req *subreq);
316 static struct tevent_req *skel_pwrite_send(struct vfs_handle_struct *handle,
317 TALLOC_CTX *mem_ctx,
318 struct tevent_context *ev,
319 struct files_struct *fsp,
320 const void *data,
321 size_t n, off_t offset)
323 struct tevent_req *req, *subreq;
324 struct skel_pwrite_state *state;
326 req = tevent_req_create(mem_ctx, &state, struct skel_pwrite_state);
327 if (req == NULL) {
328 return NULL;
330 subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
331 n, offset);
332 if (tevent_req_nomem(subreq, req)) {
333 return tevent_req_post(req, ev);
335 tevent_req_set_callback(subreq, skel_pwrite_done, req);
336 return req;
339 static void skel_pwrite_done(struct tevent_req *subreq)
341 struct tevent_req *req =
342 tevent_req_callback_data(subreq, struct tevent_req);
343 struct skel_pwrite_state *state =
344 tevent_req_data(req, struct skel_pwrite_state);
346 state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
347 TALLOC_FREE(subreq);
348 tevent_req_done(req);
351 static ssize_t skel_pwrite_recv(struct tevent_req *req,
352 struct vfs_aio_state *vfs_aio_state)
354 struct skel_pwrite_state *state =
355 tevent_req_data(req, struct skel_pwrite_state);
357 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
358 return -1;
360 *vfs_aio_state = state->vfs_aio_state;
361 return state->ret;
364 static off_t skel_lseek(vfs_handle_struct *handle, files_struct *fsp,
365 off_t offset, int whence)
367 return SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
370 static ssize_t skel_sendfile(vfs_handle_struct *handle, int tofd,
371 files_struct *fromfsp, const DATA_BLOB *hdr,
372 off_t offset, size_t n)
374 return SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
377 static ssize_t skel_recvfile(vfs_handle_struct *handle, int fromfd,
378 files_struct *tofsp, off_t offset, size_t n)
380 return SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
383 static int skel_renameat(vfs_handle_struct *handle,
384 files_struct *srcfsp,
385 const struct smb_filename *smb_fname_src,
386 files_struct *dstfsp,
387 const struct smb_filename *smb_fname_dst)
389 return SMB_VFS_NEXT_RENAMEAT(handle,
390 srcfsp,
391 smb_fname_src,
392 dstfsp,
393 smb_fname_dst);
396 struct skel_fsync_state {
397 int ret;
398 struct vfs_aio_state vfs_aio_state;
401 static void skel_fsync_done(struct tevent_req *subreq);
403 static struct tevent_req *skel_fsync_send(struct vfs_handle_struct *handle,
404 TALLOC_CTX *mem_ctx,
405 struct tevent_context *ev,
406 struct files_struct *fsp)
408 struct tevent_req *req, *subreq;
409 struct skel_fsync_state *state;
411 req = tevent_req_create(mem_ctx, &state, struct skel_fsync_state);
412 if (req == NULL) {
413 return NULL;
415 subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
416 if (tevent_req_nomem(subreq, req)) {
417 return tevent_req_post(req, ev);
419 tevent_req_set_callback(subreq, skel_fsync_done, req);
420 return req;
423 static void skel_fsync_done(struct tevent_req *subreq)
425 struct tevent_req *req =
426 tevent_req_callback_data(subreq, struct tevent_req);
427 struct skel_fsync_state *state =
428 tevent_req_data(req, struct skel_fsync_state);
430 state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
431 TALLOC_FREE(subreq);
432 tevent_req_done(req);
435 static int skel_fsync_recv(struct tevent_req *req,
436 struct vfs_aio_state *vfs_aio_state)
438 struct skel_fsync_state *state =
439 tevent_req_data(req, struct skel_fsync_state);
441 if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
442 return -1;
444 *vfs_aio_state = state->vfs_aio_state;
445 return state->ret;
448 static int skel_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
450 return SMB_VFS_NEXT_STAT(handle, smb_fname);
453 static int skel_fstat(vfs_handle_struct *handle, files_struct *fsp,
454 SMB_STRUCT_STAT *sbuf)
456 return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
459 static int skel_lstat(vfs_handle_struct *handle,
460 struct smb_filename *smb_fname)
462 return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
465 static int skel_fstatat(
466 struct vfs_handle_struct *handle,
467 const struct files_struct *dirfsp,
468 const struct smb_filename *smb_fname,
469 SMB_STRUCT_STAT *sbuf,
470 int flags)
472 return SMB_VFS_NEXT_FSTATAT(handle, dirfsp, smb_fname, sbuf, flags);
475 static uint64_t skel_get_alloc_size(struct vfs_handle_struct *handle,
476 struct files_struct *fsp,
477 const SMB_STRUCT_STAT *sbuf)
479 return SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
482 static int skel_unlinkat(vfs_handle_struct *handle,
483 struct files_struct *dirfsp,
484 const struct smb_filename *smb_fname,
485 int flags)
487 return SMB_VFS_NEXT_UNLINKAT(handle,
488 dirfsp,
489 smb_fname,
490 flags);
493 static int skel_fchmod(vfs_handle_struct *handle, files_struct *fsp,
494 mode_t mode)
496 return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
499 static int skel_fchown(vfs_handle_struct *handle, files_struct *fsp,
500 uid_t uid, gid_t gid)
502 return SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
505 static int skel_lchown(vfs_handle_struct *handle,
506 const struct smb_filename *smb_fname,
507 uid_t uid,
508 gid_t gid)
510 return SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
513 static int skel_chdir(vfs_handle_struct *handle,
514 const struct smb_filename *smb_fname)
516 return SMB_VFS_NEXT_CHDIR(handle, smb_fname);
519 static struct smb_filename *skel_getwd(vfs_handle_struct *handle,
520 TALLOC_CTX *ctx)
522 return SMB_VFS_NEXT_GETWD(handle, ctx);
525 static int skel_fntimes(vfs_handle_struct *handle,
526 files_struct *fsp,
527 struct smb_file_time *ft)
529 return SMB_VFS_NEXT_FNTIMES(handle, fsp, ft);
532 static int skel_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
533 off_t offset)
535 return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
538 static int skel_fallocate(vfs_handle_struct *handle, files_struct *fsp,
539 uint32_t mode, off_t offset, off_t len)
541 return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
544 static bool skel_lock(vfs_handle_struct *handle, files_struct *fsp, int op,
545 off_t offset, off_t count, int type)
547 return SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
550 static int skel_filesystem_sharemode(struct vfs_handle_struct *handle,
551 struct files_struct *fsp,
552 uint32_t share_mode,
553 uint32_t access_mask)
555 return SMB_VFS_NEXT_FILESYSTEM_SHAREMODE(handle,
556 fsp,
557 share_mode,
558 access_mask);
561 static int skel_fcntl(struct vfs_handle_struct *handle,
562 struct files_struct *fsp, int cmd, va_list cmd_arg)
564 void *arg;
565 va_list dup_cmd_arg;
566 int result;
568 va_copy(dup_cmd_arg, cmd_arg);
569 arg = va_arg(dup_cmd_arg, void *);
570 result = SMB_VFS_NEXT_FCNTL(handle, fsp, cmd, arg);
571 va_end(dup_cmd_arg);
573 return result;
576 static int skel_linux_setlease(struct vfs_handle_struct *handle,
577 struct files_struct *fsp, int leasetype)
579 return SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
582 static bool skel_getlock(vfs_handle_struct *handle, files_struct *fsp,
583 off_t *poffset, off_t *pcount, int *ptype,
584 pid_t *ppid)
586 return SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
589 static int skel_symlinkat(vfs_handle_struct *handle,
590 const struct smb_filename *link_contents,
591 struct files_struct *dirfsp,
592 const struct smb_filename *new_smb_fname)
594 return SMB_VFS_NEXT_SYMLINKAT(handle,
595 link_contents,
596 dirfsp,
597 new_smb_fname);
600 static int skel_vfs_readlinkat(vfs_handle_struct *handle,
601 const struct files_struct *dirfsp,
602 const struct smb_filename *smb_fname,
603 char *buf,
604 size_t bufsiz)
606 return SMB_VFS_NEXT_READLINKAT(handle,
607 dirfsp,
608 smb_fname,
609 buf,
610 bufsiz);
613 static int skel_linkat(vfs_handle_struct *handle,
614 files_struct *srcfsp,
615 const struct smb_filename *old_smb_fname,
616 files_struct *dstfsp,
617 const struct smb_filename *new_smb_fname,
618 int flags)
620 return SMB_VFS_NEXT_LINKAT(handle,
621 srcfsp,
622 old_smb_fname,
623 dstfsp,
624 new_smb_fname,
625 flags);
628 static int skel_mknodat(vfs_handle_struct *handle,
629 files_struct *dirfsp,
630 const struct smb_filename *smb_fname,
631 mode_t mode,
632 SMB_DEV_T dev)
634 return SMB_VFS_NEXT_MKNODAT(handle,
635 dirfsp,
636 smb_fname,
637 mode,
638 dev);
641 static struct smb_filename *skel_realpath(vfs_handle_struct *handle,
642 TALLOC_CTX *ctx,
643 const struct smb_filename *smb_fname)
645 return SMB_VFS_NEXT_REALPATH(handle, ctx, smb_fname);
648 static int skel_fchflags(vfs_handle_struct *handle,
649 struct files_struct *fsp,
650 uint flags)
652 return SMB_VFS_NEXT_FCHFLAGS(handle, fsp, flags);
655 static struct file_id skel_file_id_create(vfs_handle_struct *handle,
656 const SMB_STRUCT_STAT *sbuf)
658 return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
661 static uint64_t skel_fs_file_id(vfs_handle_struct *handle,
662 const SMB_STRUCT_STAT *sbuf)
664 return SMB_VFS_NEXT_FS_FILE_ID(handle, sbuf);
667 struct skel_offload_read_state {
668 struct vfs_handle_struct *handle;
669 uint32_t flags;
670 uint64_t xferlen;
671 DATA_BLOB token;
674 static void skel_offload_read_done(struct tevent_req *subreq);
676 static struct tevent_req *skel_offload_read_send(
677 TALLOC_CTX *mem_ctx,
678 struct tevent_context *ev,
679 struct vfs_handle_struct *handle,
680 struct files_struct *fsp,
681 uint32_t fsctl,
682 uint32_t ttl,
683 off_t offset,
684 size_t to_copy)
686 struct tevent_req *req = NULL;
687 struct skel_offload_read_state *state = NULL;
688 struct tevent_req *subreq = NULL;
690 req = tevent_req_create(mem_ctx, &state, struct skel_offload_read_state);
691 if (req == NULL) {
692 return NULL;
694 *state = (struct skel_offload_read_state) {
695 .handle = handle,
698 subreq = SMB_VFS_NEXT_OFFLOAD_READ_SEND(mem_ctx, ev, handle, fsp,
699 fsctl, ttl, offset, to_copy);
700 if (tevent_req_nomem(subreq, req)) {
701 return tevent_req_post(req, ev);
703 tevent_req_set_callback(subreq, skel_offload_read_done, req);
704 return req;
707 static void skel_offload_read_done(struct tevent_req *subreq)
709 struct tevent_req *req = tevent_req_callback_data(
710 subreq, struct tevent_req);
711 struct skel_offload_read_state *state = tevent_req_data(
712 req, struct skel_offload_read_state);
713 NTSTATUS status;
715 status = SMB_VFS_NEXT_OFFLOAD_READ_RECV(subreq,
716 state->handle,
717 state,
718 &state->flags,
719 &state->xferlen,
720 &state->token);
721 TALLOC_FREE(subreq);
722 if (tevent_req_nterror(req, status)) {
723 return;
726 tevent_req_done(req);
727 return;
730 static NTSTATUS skel_offload_read_recv(struct tevent_req *req,
731 struct vfs_handle_struct *handle,
732 TALLOC_CTX *mem_ctx,
733 uint32_t *flags,
734 uint64_t *xferlen,
735 DATA_BLOB *_token)
737 struct skel_offload_read_state *state = tevent_req_data(
738 req, struct skel_offload_read_state);
739 DATA_BLOB token;
740 NTSTATUS status;
742 if (tevent_req_is_nterror(req, &status)) {
743 tevent_req_received(req);
744 return status;
747 token = data_blob_talloc(mem_ctx,
748 state->token.data,
749 state->token.length);
751 tevent_req_received(req);
753 if (token.data == NULL) {
754 return NT_STATUS_NO_MEMORY;
757 *flags = state->flags;
758 *xferlen = state->xferlen;
759 *_token = token;
760 return NT_STATUS_OK;
763 struct skel_offload_write_state {
764 struct vfs_handle_struct *handle;
765 off_t copied;
767 static void skel_offload_write_done(struct tevent_req *subreq);
769 static struct tevent_req *skel_offload_write_send(struct vfs_handle_struct *handle,
770 TALLOC_CTX *mem_ctx,
771 struct tevent_context *ev,
772 uint32_t fsctl,
773 DATA_BLOB *token,
774 off_t transfer_offset,
775 struct files_struct *dest_fsp,
776 off_t dest_off,
777 off_t num)
779 struct tevent_req *req;
780 struct tevent_req *subreq;
781 struct skel_offload_write_state *state;
783 req = tevent_req_create(mem_ctx, &state, struct skel_offload_write_state);
784 if (req == NULL) {
785 return NULL;
788 state->handle = handle;
789 subreq = SMB_VFS_NEXT_OFFLOAD_WRITE_SEND(handle, state, ev,
790 fsctl, token, transfer_offset,
791 dest_fsp, dest_off, num);
792 if (tevent_req_nomem(subreq, req)) {
793 return tevent_req_post(req, ev);
796 tevent_req_set_callback(subreq, skel_offload_write_done, req);
797 return req;
800 static void skel_offload_write_done(struct tevent_req *subreq)
802 struct tevent_req *req = tevent_req_callback_data(
803 subreq, struct tevent_req);
804 struct skel_offload_write_state *state
805 = tevent_req_data(req, struct skel_offload_write_state);
806 NTSTATUS status;
808 status = SMB_VFS_NEXT_OFFLOAD_WRITE_RECV(state->handle,
809 subreq,
810 &state->copied);
811 TALLOC_FREE(subreq);
812 if (tevent_req_nterror(req, status)) {
813 return;
815 tevent_req_done(req);
818 static NTSTATUS skel_offload_write_recv(struct vfs_handle_struct *handle,
819 struct tevent_req *req,
820 off_t *copied)
822 struct skel_offload_write_state *state
823 = tevent_req_data(req, struct skel_offload_write_state);
824 NTSTATUS status;
826 *copied = state->copied;
827 if (tevent_req_is_nterror(req, &status)) {
828 tevent_req_received(req);
829 return status;
832 tevent_req_received(req);
833 return NT_STATUS_OK;
836 static NTSTATUS skel_fget_compression(struct vfs_handle_struct *handle,
837 TALLOC_CTX *mem_ctx,
838 struct files_struct *fsp,
839 uint16_t *_compression_fmt)
841 return SMB_VFS_NEXT_FGET_COMPRESSION(handle, mem_ctx, fsp,
842 _compression_fmt);
845 static NTSTATUS skel_set_compression(struct vfs_handle_struct *handle,
846 TALLOC_CTX *mem_ctx,
847 struct files_struct *fsp,
848 uint16_t compression_fmt)
850 return SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
851 compression_fmt);
854 static NTSTATUS skel_fstreaminfo(struct vfs_handle_struct *handle,
855 struct files_struct *fsp,
856 TALLOC_CTX *mem_ctx,
857 unsigned int *num_streams,
858 struct stream_struct **streams)
860 return SMB_VFS_NEXT_FSTREAMINFO(handle,
861 fsp,
862 mem_ctx,
863 num_streams,
864 streams);
867 static NTSTATUS skel_get_real_filename_at(struct vfs_handle_struct *handle,
868 struct files_struct *dirfsp,
869 const char *name,
870 TALLOC_CTX *mem_ctx,
871 char **found_name)
873 return SMB_VFS_NEXT_GET_REAL_FILENAME_AT(
874 handle, dirfsp, name, mem_ctx, found_name);
877 static const char *skel_connectpath(
878 struct vfs_handle_struct *handle,
879 const struct files_struct *dirfsp,
880 const struct smb_filename *smb_fname)
882 return SMB_VFS_NEXT_CONNECTPATH(handle, dirfsp, smb_fname);
885 static NTSTATUS skel_brl_lock_windows(struct vfs_handle_struct *handle,
886 struct byte_range_lock *br_lck,
887 struct lock_struct *plock)
889 return SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle, br_lck, plock);
892 static bool skel_brl_unlock_windows(struct vfs_handle_struct *handle,
893 struct byte_range_lock *br_lck,
894 const struct lock_struct *plock)
896 return SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, br_lck, plock);
899 static bool skel_strict_lock_check(struct vfs_handle_struct *handle,
900 struct files_struct *fsp,
901 struct lock_struct *plock)
903 return SMB_VFS_NEXT_STRICT_LOCK_CHECK(handle, fsp, plock);
906 static NTSTATUS skel_translate_name(struct vfs_handle_struct *handle,
907 const char *mapped_name,
908 enum vfs_translate_direction direction,
909 TALLOC_CTX *mem_ctx, char **pmapped_name)
911 return SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
912 mem_ctx, pmapped_name);
915 static NTSTATUS skel_parent_pathname(struct vfs_handle_struct *handle,
916 TALLOC_CTX *mem_ctx,
917 const struct smb_filename *smb_fname_in,
918 struct smb_filename **parent_dir_out,
919 struct smb_filename **atname_out)
921 return SMB_VFS_NEXT_PARENT_PATHNAME(handle,
922 mem_ctx,
923 smb_fname_in,
924 parent_dir_out,
925 atname_out);
928 static NTSTATUS skel_fsctl(struct vfs_handle_struct *handle,
929 struct files_struct *fsp,
930 TALLOC_CTX *ctx,
931 uint32_t function,
932 uint16_t req_flags, /* Needed for UNICODE ... */
933 const uint8_t *_in_data,
934 uint32_t in_len,
935 uint8_t ** _out_data,
936 uint32_t max_out_len, uint32_t *out_len)
938 return SMB_VFS_NEXT_FSCTL(handle,
939 fsp,
940 ctx,
941 function,
942 req_flags,
943 _in_data,
944 in_len, _out_data, max_out_len, out_len);
947 static NTSTATUS skel_freaddir_attr(struct vfs_handle_struct *handle,
948 struct files_struct *fsp,
949 TALLOC_CTX *mem_ctx,
950 struct readdir_attr_data **pattr_data)
952 return SMB_VFS_NEXT_FREADDIR_ATTR(handle, fsp, mem_ctx, pattr_data);
955 struct skel_get_dos_attributes_state {
956 struct vfs_aio_state aio_state;
957 uint32_t dosmode;
960 static void skel_get_dos_attributes_done(struct tevent_req *subreq);
962 static struct tevent_req *skel_get_dos_attributes_send(
963 TALLOC_CTX *mem_ctx,
964 struct tevent_context *ev,
965 struct vfs_handle_struct *handle,
966 files_struct *dir_fsp,
967 struct smb_filename *smb_fname)
969 struct tevent_req *req = NULL;
970 struct skel_get_dos_attributes_state *state = NULL;
971 struct tevent_req *subreq = NULL;
973 req = tevent_req_create(mem_ctx, &state,
974 struct skel_get_dos_attributes_state);
975 if (req == NULL) {
976 return NULL;
979 subreq = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_SEND(mem_ctx,
981 handle,
982 dir_fsp,
983 smb_fname);
984 if (tevent_req_nomem(subreq, req)) {
985 return tevent_req_post(req, ev);
987 tevent_req_set_callback(subreq, skel_get_dos_attributes_done, req);
989 return req;
992 static void skel_get_dos_attributes_done(struct tevent_req *subreq)
994 struct tevent_req *req =
995 tevent_req_callback_data(subreq,
996 struct tevent_req);
997 struct skel_get_dos_attributes_state *state =
998 tevent_req_data(req,
999 struct skel_get_dos_attributes_state);
1000 NTSTATUS status;
1002 status = SMB_VFS_NEXT_GET_DOS_ATTRIBUTES_RECV(subreq,
1003 &state->aio_state,
1004 &state->dosmode);
1005 TALLOC_FREE(subreq);
1006 if (tevent_req_nterror(req, status)) {
1007 return;
1010 tevent_req_done(req);
1011 return;
1014 static NTSTATUS skel_get_dos_attributes_recv(struct tevent_req *req,
1015 struct vfs_aio_state *aio_state,
1016 uint32_t *dosmode)
1018 struct skel_get_dos_attributes_state *state =
1019 tevent_req_data(req,
1020 struct skel_get_dos_attributes_state);
1021 NTSTATUS status;
1023 if (tevent_req_is_nterror(req, &status)) {
1024 tevent_req_received(req);
1025 return status;
1028 *aio_state = state->aio_state;
1029 *dosmode = state->dosmode;
1030 tevent_req_received(req);
1031 return NT_STATUS_OK;
1034 static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle,
1035 struct files_struct *fsp,
1036 uint32_t *dosmode)
1038 return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
1039 fsp,
1040 dosmode);
1043 static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle,
1044 struct files_struct *fsp,
1045 uint32_t dosmode)
1047 return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
1048 fsp,
1049 dosmode);
1052 static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1053 uint32_t security_info,
1054 TALLOC_CTX *mem_ctx,
1055 struct security_descriptor **ppdesc)
1057 return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx,
1058 ppdesc);
1061 static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
1062 uint32_t security_info_sent,
1063 const struct security_descriptor *psd)
1065 return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
1068 static SMB_ACL_T skel_sys_acl_get_fd(vfs_handle_struct *handle,
1069 files_struct *fsp,
1070 SMB_ACL_TYPE_T type,
1071 TALLOC_CTX *mem_ctx)
1073 return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, type, mem_ctx);
1076 static int skel_sys_acl_blob_get_fd(vfs_handle_struct *handle,
1077 files_struct *fsp, TALLOC_CTX *mem_ctx,
1078 char **blob_description, DATA_BLOB *blob)
1080 return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
1081 blob_description, blob);
1084 static int skel_sys_acl_set_fd(vfs_handle_struct *handle,
1085 struct files_struct *fsp,
1086 SMB_ACL_TYPE_T type,
1087 SMB_ACL_T theacl)
1089 return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, type, theacl);
1092 static int skel_sys_acl_delete_def_fd(vfs_handle_struct *handle,
1093 struct files_struct *fsp)
1095 return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FD(handle, fsp);
1098 struct skel_getxattrat_state {
1099 struct vfs_aio_state aio_state;
1100 ssize_t xattr_size;
1101 uint8_t *xattr_value;
1104 static void skel_getxattrat_done(struct tevent_req *subreq);
1106 static struct tevent_req *skel_getxattrat_send(
1107 TALLOC_CTX *mem_ctx,
1108 struct tevent_context *ev,
1109 struct vfs_handle_struct *handle,
1110 files_struct *dir_fsp,
1111 const struct smb_filename *smb_fname,
1112 const char *xattr_name,
1113 size_t alloc_hint)
1115 struct tevent_req *req = NULL;
1116 struct skel_getxattrat_state *state = NULL;
1117 struct tevent_req *subreq = NULL;
1119 req = tevent_req_create(mem_ctx, &state,
1120 struct skel_getxattrat_state);
1121 if (req == NULL) {
1122 return NULL;
1125 subreq = SMB_VFS_NEXT_GETXATTRAT_SEND(state,
1127 handle,
1128 dir_fsp,
1129 smb_fname,
1130 xattr_name,
1131 alloc_hint);
1132 if (tevent_req_nomem(subreq, req)) {
1133 return tevent_req_post(req, ev);
1135 tevent_req_set_callback(subreq, skel_getxattrat_done, req);
1137 return req;
1140 static void skel_getxattrat_done(struct tevent_req *subreq)
1142 struct tevent_req *req = tevent_req_callback_data(
1143 subreq, struct tevent_req);
1144 struct skel_getxattrat_state *state = tevent_req_data(
1145 req, struct skel_getxattrat_state);
1147 state->xattr_size = SMB_VFS_NEXT_GETXATTRAT_RECV(subreq,
1148 &state->aio_state,
1149 state,
1150 &state->xattr_value);
1151 TALLOC_FREE(subreq);
1152 if (state->xattr_size == -1) {
1153 tevent_req_error(req, state->aio_state.error);
1154 return;
1157 tevent_req_done(req);
1160 static ssize_t skel_getxattrat_recv(struct tevent_req *req,
1161 struct vfs_aio_state *aio_state,
1162 TALLOC_CTX *mem_ctx,
1163 uint8_t **xattr_value)
1165 struct skel_getxattrat_state *state = tevent_req_data(
1166 req, struct skel_getxattrat_state);
1167 ssize_t xattr_size;
1169 if (tevent_req_is_unix_error(req, &aio_state->error)) {
1170 tevent_req_received(req);
1171 return -1;
1174 *aio_state = state->aio_state;
1175 xattr_size = state->xattr_size;
1176 if (xattr_value != NULL) {
1177 *xattr_value = talloc_move(mem_ctx, &state->xattr_value);
1180 tevent_req_received(req);
1181 return xattr_size;
1184 static ssize_t skel_fgetxattr(vfs_handle_struct *handle,
1185 struct files_struct *fsp, const char *name,
1186 void *value, size_t size)
1188 return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
1191 static ssize_t skel_flistxattr(vfs_handle_struct *handle,
1192 struct files_struct *fsp, char *list,
1193 size_t size)
1195 return SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
1198 static int skel_fremovexattr(vfs_handle_struct *handle,
1199 struct files_struct *fsp, const char *name)
1201 return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
1204 static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,
1205 const char *name, const void *value, size_t size,
1206 int flags)
1208 return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
1211 static bool skel_aio_force(struct vfs_handle_struct *handle,
1212 struct files_struct *fsp)
1214 return SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
1217 static NTSTATUS skel_audit_file(struct vfs_handle_struct *handle,
1218 struct smb_filename *file,
1219 struct security_acl *sacl,
1220 uint32_t access_requested,
1221 uint32_t access_denied)
1223 return SMB_VFS_NEXT_AUDIT_FILE(handle,
1224 file,
1225 sacl,
1226 access_requested,
1227 access_denied);
1230 static NTSTATUS skel_durable_cookie(struct vfs_handle_struct *handle,
1231 struct files_struct *fsp,
1232 TALLOC_CTX *mem_ctx,
1233 DATA_BLOB *cookie)
1235 return SMB_VFS_NEXT_DURABLE_COOKIE(handle,
1236 fsp,
1237 mem_ctx,
1238 cookie);
1241 static NTSTATUS skel_durable_disconnect(struct vfs_handle_struct *handle,
1242 struct files_struct *fsp,
1243 const DATA_BLOB old_cookie,
1244 TALLOC_CTX *mem_ctx,
1245 DATA_BLOB *new_cookie)
1247 return SMB_VFS_NEXT_DURABLE_DISCONNECT(handle,
1248 fsp,
1249 old_cookie,
1250 mem_ctx,
1251 new_cookie);
1254 static NTSTATUS skel_durable_reconnect(struct vfs_handle_struct *handle,
1255 struct smb_request *smb1req,
1256 struct smbXsrv_open *op,
1257 const DATA_BLOB old_cookie,
1258 TALLOC_CTX *mem_ctx,
1259 struct files_struct **fsp,
1260 DATA_BLOB *new_cookie)
1262 return SMB_VFS_NEXT_DURABLE_RECONNECT(handle,
1263 smb1req,
1265 old_cookie,
1266 mem_ctx,
1267 fsp,
1268 new_cookie);
1271 /* VFS operations structure */
1273 static struct vfs_fn_pointers skel_transparent_fns = {
1274 /* Disk operations */
1276 .connect_fn = skel_connect,
1277 .disconnect_fn = skel_disconnect,
1278 .disk_free_fn = skel_disk_free,
1279 .get_quota_fn = skel_get_quota,
1280 .set_quota_fn = skel_set_quota,
1281 .get_shadow_copy_data_fn = skel_get_shadow_copy_data,
1282 .statvfs_fn = skel_statvfs,
1283 .fs_capabilities_fn = skel_fs_capabilities,
1284 .get_dfs_referrals_fn = skel_get_dfs_referrals,
1285 .create_dfs_pathat_fn = skel_create_dfs_pathat,
1286 .read_dfs_pathat_fn = skel_read_dfs_pathat,
1287 .snap_check_path_fn = skel_snap_check_path,
1288 .snap_create_fn = skel_snap_create,
1289 .snap_delete_fn = skel_snap_delete,
1291 /* Directory operations */
1293 .fdopendir_fn = skel_fdopendir,
1294 .readdir_fn = skel_readdir,
1295 .rewind_dir_fn = skel_rewind_dir,
1296 .mkdirat_fn = skel_mkdirat,
1297 .closedir_fn = skel_closedir,
1299 /* File operations */
1301 .openat_fn = skel_openat,
1302 .create_file_fn = skel_create_file,
1303 .close_fn = skel_close_fn,
1304 .pread_fn = skel_pread,
1305 .pread_send_fn = skel_pread_send,
1306 .pread_recv_fn = skel_pread_recv,
1307 .pwrite_fn = skel_pwrite,
1308 .pwrite_send_fn = skel_pwrite_send,
1309 .pwrite_recv_fn = skel_pwrite_recv,
1310 .lseek_fn = skel_lseek,
1311 .sendfile_fn = skel_sendfile,
1312 .recvfile_fn = skel_recvfile,
1313 .renameat_fn = skel_renameat,
1314 .fsync_send_fn = skel_fsync_send,
1315 .fsync_recv_fn = skel_fsync_recv,
1316 .stat_fn = skel_stat,
1317 .fstat_fn = skel_fstat,
1318 .lstat_fn = skel_lstat,
1319 .fstatat_fn = skel_fstatat,
1320 .get_alloc_size_fn = skel_get_alloc_size,
1321 .unlinkat_fn = skel_unlinkat,
1322 .fchmod_fn = skel_fchmod,
1323 .fchown_fn = skel_fchown,
1324 .lchown_fn = skel_lchown,
1325 .chdir_fn = skel_chdir,
1326 .getwd_fn = skel_getwd,
1327 .fntimes_fn = skel_fntimes,
1328 .ftruncate_fn = skel_ftruncate,
1329 .fallocate_fn = skel_fallocate,
1330 .lock_fn = skel_lock,
1331 .filesystem_sharemode_fn = skel_filesystem_sharemode,
1332 .fcntl_fn = skel_fcntl,
1333 .linux_setlease_fn = skel_linux_setlease,
1334 .getlock_fn = skel_getlock,
1335 .symlinkat_fn = skel_symlinkat,
1336 .readlinkat_fn = skel_vfs_readlinkat,
1337 .linkat_fn = skel_linkat,
1338 .mknodat_fn = skel_mknodat,
1339 .realpath_fn = skel_realpath,
1340 .fchflags_fn = skel_fchflags,
1341 .file_id_create_fn = skel_file_id_create,
1342 .fs_file_id_fn = skel_fs_file_id,
1343 .offload_read_send_fn = skel_offload_read_send,
1344 .offload_read_recv_fn = skel_offload_read_recv,
1345 .offload_write_send_fn = skel_offload_write_send,
1346 .offload_write_recv_fn = skel_offload_write_recv,
1347 .fget_compression_fn = skel_fget_compression,
1348 .set_compression_fn = skel_set_compression,
1350 .fstreaminfo_fn = skel_fstreaminfo,
1351 .get_real_filename_at_fn = skel_get_real_filename_at,
1352 .connectpath_fn = skel_connectpath,
1353 .brl_lock_windows_fn = skel_brl_lock_windows,
1354 .brl_unlock_windows_fn = skel_brl_unlock_windows,
1355 .strict_lock_check_fn = skel_strict_lock_check,
1356 .translate_name_fn = skel_translate_name,
1357 .parent_pathname_fn = skel_parent_pathname,
1358 .fsctl_fn = skel_fsctl,
1359 .freaddir_attr_fn = skel_freaddir_attr,
1360 .audit_file_fn = skel_audit_file,
1362 /* DOS attributes. */
1363 .get_dos_attributes_send_fn = skel_get_dos_attributes_send,
1364 .get_dos_attributes_recv_fn = skel_get_dos_attributes_recv,
1365 .fget_dos_attributes_fn = skel_fget_dos_attributes,
1366 .fset_dos_attributes_fn = skel_fset_dos_attributes,
1368 /* NT ACL operations. */
1370 .fget_nt_acl_fn = skel_fget_nt_acl,
1371 .fset_nt_acl_fn = skel_fset_nt_acl,
1373 /* POSIX ACL operations. */
1375 .sys_acl_get_fd_fn = skel_sys_acl_get_fd,
1376 .sys_acl_blob_get_fd_fn = skel_sys_acl_blob_get_fd,
1377 .sys_acl_set_fd_fn = skel_sys_acl_set_fd,
1378 .sys_acl_delete_def_fd_fn = skel_sys_acl_delete_def_fd,
1380 /* EA operations. */
1381 .getxattrat_send_fn = skel_getxattrat_send,
1382 .getxattrat_recv_fn = skel_getxattrat_recv,
1383 .fgetxattr_fn = skel_fgetxattr,
1384 .flistxattr_fn = skel_flistxattr,
1385 .fremovexattr_fn = skel_fremovexattr,
1386 .fsetxattr_fn = skel_fsetxattr,
1388 /* aio operations */
1389 .aio_force_fn = skel_aio_force,
1391 /* durable handle operations */
1392 .durable_cookie_fn = skel_durable_cookie,
1393 .durable_disconnect_fn = skel_durable_disconnect,
1394 .durable_reconnect_fn = skel_durable_reconnect,
1397 static_decl_vfs;
1398 NTSTATUS vfs_skel_transparent_init(TALLOC_CTX *ctx)
1401 * smb_vfs_assert_all_fns() is only needed in
1402 * order to have a complete example.
1404 * A transparent vfs module typically don't
1405 * need to implement every calls.
1407 smb_vfs_assert_all_fns(&skel_transparent_fns, "skel_transparent");
1408 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_transparent",
1409 &skel_transparent_fns);