2 Unix SMB/CIFS implementation.
4 CIFS-on-CIFS NTVFS filesystem backend
6 Copyright (C) Andrew Tridgell 2003
7 Copyright (C) James J Myers 2003 <myersjj@samba.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 this implements a CIFS->CIFS NTVFS filesystem backend.
28 #include "libcli/raw/libcliraw.h"
29 #include "libcli/smb_composite/smb_composite.h"
30 #include "auth/auth.h"
31 #include "auth/credentials/credentials.h"
32 #include "ntvfs/ntvfs.h"
33 #include "lib/util/dlinklist.h"
34 #include "param/param.h"
35 #include "libcli/resolve/resolve.h"
38 struct cvfs_file *prev, *next;
40 struct ntvfs_handle *h;
43 /* this is stored in ntvfs_private */
45 struct smbcli_tree *tree;
46 struct smbcli_transport *transport;
47 struct ntvfs_module_context *ntvfs;
48 struct async_info *pending;
49 struct cvfs_file *files;
55 /* a structure used to pass information to an async handler */
57 struct async_info *next, *prev;
58 struct cvfs_private *cvfs;
59 struct ntvfs_request *req;
60 struct smbcli_request *c_req;
65 #define SETUP_PID private->tree->session->pid = req->smbpid
67 #define SETUP_FILE do { \
68 struct cvfs_file *f; \
69 f = ntvfs_handle_get_backend_data(io->generic.in.file.ntvfs, ntvfs); \
70 if (!f) return NT_STATUS_INVALID_HANDLE; \
71 io->generic.in.file.fnum = f->fnum; \
74 #define SETUP_PID_AND_FILE do { \
79 #define CIFS_SERVER "cifs:server"
80 #define CIFS_USER "cifs:user"
81 #define CIFS_PASSWORD "cifs:password"
82 #define CIFS_DOMAIN "cifs:domain"
83 #define CIFS_SHARE "cifs:share"
84 #define CIFS_USE_MACHINE_ACCT "cifs:use-machine-account"
85 #define CIFS_MAP_GENERIC "cifs:map-generic"
86 #define CIFS_MAP_TRANS2 "cifs:map-trans2"
88 #define CIFS_USE_MACHINE_ACCT_DEFAULT false
89 #define CIFS_MAP_GENERIC_DEFAULT false
90 #define CIFS_MAP_TRANS2_DEFAULT true
93 a handler for oplock break events from the server - these need to be passed
96 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *p_private)
98 struct cvfs_private *private = p_private;
100 struct ntvfs_handle *h = NULL;
103 for (f=private->files; f; f=f->next) {
104 if (f->fnum != fnum) continue;
110 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level, fnum));
114 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level, fnum));
115 status = ntvfs_send_oplock_break(private->ntvfs, h, level);
116 if (!NT_STATUS_IS_OK(status)) return false;
121 connect to a share - used when a tree_connect operation comes in.
123 static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
124 struct ntvfs_request *req, const char *sharename)
127 struct cvfs_private *private;
128 const char *host, *user, *pass, *domain, *remote_share;
129 struct smb_composite_connect io;
130 struct composite_context *creq;
131 struct share_config *scfg = ntvfs->ctx->config;
133 struct cli_credentials *credentials;
134 bool machine_account;
136 /* Here we need to determine which server to connect to.
137 * For now we use parametric options, type cifs.
138 * Later we will use security=server and auth_server.c.
140 host = share_string_option(scfg, CIFS_SERVER, NULL);
141 user = share_string_option(scfg, CIFS_USER, NULL);
142 pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
143 domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
144 remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
146 remote_share = sharename;
149 machine_account = share_bool_option(scfg, CIFS_USE_MACHINE_ACCT, CIFS_USE_MACHINE_ACCT_DEFAULT);
151 private = talloc_zero(ntvfs, struct cvfs_private);
153 return NT_STATUS_NO_MEMORY;
156 ntvfs->private_data = private;
159 DEBUG(1,("CIFS backend: You must supply server\n"));
160 return NT_STATUS_INVALID_PARAMETER;
164 DEBUG(5, ("CIFS backend: Using specified password\n"));
165 credentials = cli_credentials_init(private);
167 return NT_STATUS_NO_MEMORY;
169 cli_credentials_set_event_context(credentials, ntvfs->ctx->event_ctx);
170 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
171 cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
173 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
175 cli_credentials_set_password(credentials, pass, CRED_SPECIFIED);
176 } else if (machine_account) {
177 DEBUG(5, ("CIFS backend: Using machine account\n"));
178 credentials = cli_credentials_init(private);
179 cli_credentials_set_event_context(credentials, ntvfs->ctx->event_ctx);
180 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
182 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
184 status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
185 if (!NT_STATUS_IS_OK(status)) {
188 } else if (req->session_info->credentials) {
189 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
190 credentials = req->session_info->credentials;
192 DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
193 return NT_STATUS_INVALID_PARAMETER;
196 /* connect to the server, using the smbd event context */
197 io.in.dest_host = host;
198 io.in.dest_ports = lp_smb_ports(ntvfs->ctx->lp_ctx);
199 io.in.called_name = host;
200 io.in.credentials = credentials;
201 io.in.fallback_to_anonymous = false;
202 io.in.workgroup = lp_workgroup(ntvfs->ctx->lp_ctx);
203 io.in.service = remote_share;
204 io.in.service_type = "?????";
206 creq = smb_composite_connect_send(&io, private,
207 lp_resolve_context(ntvfs->ctx->lp_ctx),
208 ntvfs->ctx->event_ctx);
209 status = smb_composite_connect_recv(creq, private);
210 NT_STATUS_NOT_OK_RETURN(status);
212 private->tree = io.out.tree;
214 private->transport = private->tree->session->transport;
216 private->ntvfs = ntvfs;
218 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
219 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
220 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
221 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
223 /* we need to receive oplock break requests from the server */
224 smbcli_oplock_handler(private->transport, oplock_handler, private);
226 private->map_generic = share_bool_option(scfg, CIFS_MAP_GENERIC, CIFS_MAP_GENERIC_DEFAULT);
228 private->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
234 disconnect from a share
236 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
238 struct cvfs_private *private = ntvfs->private_data;
239 struct async_info *a, *an;
241 /* first cleanup pending requests */
242 for (a=private->pending; a; a = an) {
244 smbcli_request_destroy(a->c_req);
248 talloc_free(private);
249 ntvfs->private_data = NULL;
255 destroy an async info structure
257 static int async_info_destructor(struct async_info *async)
259 DLIST_REMOVE(async->cvfs->pending, async);
264 a handler for simple async replies
265 this handler can only be used for functions that don't return any
266 parameters (those that just return a status code)
268 static void async_simple(struct smbcli_request *c_req)
270 struct async_info *async = c_req->async.private;
271 struct ntvfs_request *req = async->req;
272 req->async_states->status = smbcli_request_simple_recv(c_req);
274 req->async_states->send_fn(req);
278 /* save some typing for the simple functions */
279 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
280 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
282 struct async_info *async; \
283 async = talloc(req, struct async_info); \
284 if (!async) return NT_STATUS_NO_MEMORY; \
288 async->cvfs = private; \
289 async->c_req = c_req; \
290 DLIST_ADD(private->pending, async); \
291 c_req->async.private = async; \
292 talloc_set_destructor(async, async_info_destructor); \
294 c_req->async.fn = async_fn; \
295 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
296 return NT_STATUS_OK; \
299 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
301 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
304 delete a file - the dirtype specifies the file types to include in the search.
305 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
307 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
308 struct ntvfs_request *req, union smb_unlink *unl)
310 struct cvfs_private *private = ntvfs->private_data;
311 struct smbcli_request *c_req;
315 /* see if the front end will allow us to perform this
316 function asynchronously. */
317 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
318 return smb_raw_unlink(private->tree, unl);
321 c_req = smb_raw_unlink_send(private->tree, unl);
327 a handler for async ioctl replies
329 static void async_ioctl(struct smbcli_request *c_req)
331 struct async_info *async = c_req->async.private;
332 struct ntvfs_request *req = async->req;
333 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
335 req->async_states->send_fn(req);
341 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
342 struct ntvfs_request *req, union smb_ioctl *io)
344 struct cvfs_private *private = ntvfs->private_data;
345 struct smbcli_request *c_req;
349 /* see if the front end will allow us to perform this
350 function asynchronously. */
351 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
352 return smb_raw_ioctl(private->tree, req, io);
355 c_req = smb_raw_ioctl_send(private->tree, io);
357 ASYNC_RECV_TAIL(io, async_ioctl);
361 check if a directory exists
363 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
364 struct ntvfs_request *req, union smb_chkpath *cp)
366 struct cvfs_private *private = ntvfs->private_data;
367 struct smbcli_request *c_req;
371 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
372 return smb_raw_chkpath(private->tree, cp);
375 c_req = smb_raw_chkpath_send(private->tree, cp);
381 a handler for async qpathinfo replies
383 static void async_qpathinfo(struct smbcli_request *c_req)
385 struct async_info *async = c_req->async.private;
386 struct ntvfs_request *req = async->req;
387 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
389 req->async_states->send_fn(req);
393 return info on a pathname
395 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
396 struct ntvfs_request *req, union smb_fileinfo *info)
398 struct cvfs_private *private = ntvfs->private_data;
399 struct smbcli_request *c_req;
403 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
404 return smb_raw_pathinfo(private->tree, req, info);
407 c_req = smb_raw_pathinfo_send(private->tree, info);
409 ASYNC_RECV_TAIL(info, async_qpathinfo);
413 a handler for async qfileinfo replies
415 static void async_qfileinfo(struct smbcli_request *c_req)
417 struct async_info *async = c_req->async.private;
418 struct ntvfs_request *req = async->req;
419 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
421 req->async_states->send_fn(req);
425 query info on a open file
427 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
428 struct ntvfs_request *req, union smb_fileinfo *io)
430 struct cvfs_private *private = ntvfs->private_data;
431 struct smbcli_request *c_req;
435 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
436 return smb_raw_fileinfo(private->tree, req, io);
439 c_req = smb_raw_fileinfo_send(private->tree, io);
441 ASYNC_RECV_TAIL(io, async_qfileinfo);
446 set info on a pathname
448 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
449 struct ntvfs_request *req, union smb_setfileinfo *st)
451 struct cvfs_private *private = ntvfs->private_data;
452 struct smbcli_request *c_req;
456 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
457 return smb_raw_setpathinfo(private->tree, st);
460 c_req = smb_raw_setpathinfo_send(private->tree, st);
467 a handler for async open replies
469 static void async_open(struct smbcli_request *c_req)
471 struct async_info *async = c_req->async.private;
472 struct cvfs_private *cvfs = async->cvfs;
473 struct ntvfs_request *req = async->req;
474 struct cvfs_file *f = async->f;
475 union smb_open *io = async->parms;
476 union smb_handle *file;
478 req->async_states->status = smb_raw_open_recv(c_req, req, io);
479 SMB_OPEN_OUT_FILE(io, file);
480 f->fnum = file->fnum;
482 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
483 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
484 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
487 req->async_states->send_fn(req);
493 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
494 struct ntvfs_request *req, union smb_open *io)
496 struct cvfs_private *private = ntvfs->private_data;
497 struct smbcli_request *c_req;
498 struct ntvfs_handle *h;
504 if (io->generic.level != RAW_OPEN_GENERIC &&
505 private->map_generic) {
506 return ntvfs_map_open(ntvfs, req, io);
509 status = ntvfs_handle_new(ntvfs, req, &h);
510 NT_STATUS_NOT_OK_RETURN(status);
512 f = talloc_zero(h, struct cvfs_file);
513 NT_STATUS_HAVE_NO_MEMORY(f);
516 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
517 union smb_handle *file;
519 status = smb_raw_open(private->tree, req, io);
520 NT_STATUS_NOT_OK_RETURN(status);
522 SMB_OPEN_OUT_FILE(io, file);
523 f->fnum = file->fnum;
525 status = ntvfs_handle_set_backend_data(f->h, private->ntvfs, f);
526 NT_STATUS_NOT_OK_RETURN(status);
532 c_req = smb_raw_open_send(private->tree, io);
534 ASYNC_RECV_TAIL_F(io, async_open, f);
540 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
541 struct ntvfs_request *req, union smb_mkdir *md)
543 struct cvfs_private *private = ntvfs->private_data;
544 struct smbcli_request *c_req;
548 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
549 return smb_raw_mkdir(private->tree, md);
552 c_req = smb_raw_mkdir_send(private->tree, md);
560 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
561 struct ntvfs_request *req, struct smb_rmdir *rd)
563 struct cvfs_private *private = ntvfs->private_data;
564 struct smbcli_request *c_req;
568 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
569 return smb_raw_rmdir(private->tree, rd);
571 c_req = smb_raw_rmdir_send(private->tree, rd);
577 rename a set of files
579 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
580 struct ntvfs_request *req, union smb_rename *ren)
582 struct cvfs_private *private = ntvfs->private_data;
583 struct smbcli_request *c_req;
587 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
588 return smb_raw_rename(private->tree, ren);
591 c_req = smb_raw_rename_send(private->tree, ren);
599 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
600 struct ntvfs_request *req, struct smb_copy *cp)
602 return NT_STATUS_NOT_SUPPORTED;
606 a handler for async read replies
608 static void async_read(struct smbcli_request *c_req)
610 struct async_info *async = c_req->async.private;
611 struct ntvfs_request *req = async->req;
612 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
614 req->async_states->send_fn(req);
620 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
621 struct ntvfs_request *req, union smb_read *io)
623 struct cvfs_private *private = ntvfs->private_data;
624 struct smbcli_request *c_req;
628 if (io->generic.level != RAW_READ_GENERIC &&
629 private->map_generic) {
630 return ntvfs_map_read(ntvfs, req, io);
635 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
636 return smb_raw_read(private->tree, io);
639 c_req = smb_raw_read_send(private->tree, io);
641 ASYNC_RECV_TAIL(io, async_read);
645 a handler for async write replies
647 static void async_write(struct smbcli_request *c_req)
649 struct async_info *async = c_req->async.private;
650 struct ntvfs_request *req = async->req;
651 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
653 req->async_states->send_fn(req);
659 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
660 struct ntvfs_request *req, union smb_write *io)
662 struct cvfs_private *private = ntvfs->private_data;
663 struct smbcli_request *c_req;
667 if (io->generic.level != RAW_WRITE_GENERIC &&
668 private->map_generic) {
669 return ntvfs_map_write(ntvfs, req, io);
673 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
674 return smb_raw_write(private->tree, io);
677 c_req = smb_raw_write_send(private->tree, io);
679 ASYNC_RECV_TAIL(io, async_write);
683 a handler for async seek replies
685 static void async_seek(struct smbcli_request *c_req)
687 struct async_info *async = c_req->async.private;
688 struct ntvfs_request *req = async->req;
689 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
691 req->async_states->send_fn(req);
697 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
698 struct ntvfs_request *req,
701 struct cvfs_private *private = ntvfs->private_data;
702 struct smbcli_request *c_req;
706 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
707 return smb_raw_seek(private->tree, io);
710 c_req = smb_raw_seek_send(private->tree, io);
712 ASYNC_RECV_TAIL(io, async_seek);
718 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
719 struct ntvfs_request *req,
722 struct cvfs_private *private = ntvfs->private_data;
723 struct smbcli_request *c_req;
726 switch (io->generic.level) {
727 case RAW_FLUSH_FLUSH:
731 io->generic.in.file.fnum = 0xFFFF;
734 return NT_STATUS_INVALID_LEVEL;
737 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
738 return smb_raw_flush(private->tree, io);
741 c_req = smb_raw_flush_send(private->tree, io);
749 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
750 struct ntvfs_request *req, union smb_close *io)
752 struct cvfs_private *private = ntvfs->private_data;
753 struct smbcli_request *c_req;
757 if (io->generic.level != RAW_CLOSE_GENERIC &&
758 private->map_generic) {
759 return ntvfs_map_close(ntvfs, req, io);
763 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
764 return smb_raw_close(private->tree, io);
767 c_req = smb_raw_close_send(private->tree, io);
773 exit - closing files open by the pid
775 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
776 struct ntvfs_request *req)
778 struct cvfs_private *private = ntvfs->private_data;
779 struct smbcli_request *c_req;
783 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
784 return smb_raw_exit(private->tree->session);
787 c_req = smb_raw_exit_send(private->tree->session);
793 logoff - closing files open by the user
795 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
796 struct ntvfs_request *req)
798 /* we can't do this right in the cifs backend .... */
803 setup for an async call - nothing to do yet
805 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
806 struct ntvfs_request *req,
815 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
816 struct ntvfs_request *req)
818 struct cvfs_private *private = ntvfs->private_data;
819 struct async_info *a;
821 /* find the matching request */
822 for (a=private->pending;a;a=a->next) {
829 return NT_STATUS_INVALID_PARAMETER;
832 return smb_raw_ntcancel(a->c_req);
838 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
839 struct ntvfs_request *req, union smb_lock *io)
841 struct cvfs_private *private = ntvfs->private_data;
842 struct smbcli_request *c_req;
846 if (io->generic.level != RAW_LOCK_GENERIC &&
847 private->map_generic) {
848 return ntvfs_map_lock(ntvfs, req, io);
852 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
853 return smb_raw_lock(private->tree, io);
856 c_req = smb_raw_lock_send(private->tree, io);
861 set info on a open file
863 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
864 struct ntvfs_request *req,
865 union smb_setfileinfo *io)
867 struct cvfs_private *private = ntvfs->private_data;
868 struct smbcli_request *c_req;
872 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
873 return smb_raw_setfileinfo(private->tree, io);
875 c_req = smb_raw_setfileinfo_send(private->tree, io);
882 a handler for async fsinfo replies
884 static void async_fsinfo(struct smbcli_request *c_req)
886 struct async_info *async = c_req->async.private;
887 struct ntvfs_request *req = async->req;
888 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
890 req->async_states->send_fn(req);
894 return filesystem space info
896 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
897 struct ntvfs_request *req, union smb_fsinfo *fs)
899 struct cvfs_private *private = ntvfs->private_data;
900 struct smbcli_request *c_req;
904 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
905 return smb_raw_fsinfo(private->tree, req, fs);
908 c_req = smb_raw_fsinfo_send(private->tree, req, fs);
910 ASYNC_RECV_TAIL(fs, async_fsinfo);
914 return print queue info
916 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
917 struct ntvfs_request *req, union smb_lpq *lpq)
919 return NT_STATUS_NOT_SUPPORTED;
923 list files in a directory matching a wildcard pattern
925 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
926 struct ntvfs_request *req, union smb_search_first *io,
927 void *search_private,
928 bool (*callback)(void *, const union smb_search_data *))
930 struct cvfs_private *private = ntvfs->private_data;
934 return smb_raw_search_first(private->tree, req, io, search_private, callback);
937 /* continue a search */
938 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
939 struct ntvfs_request *req, union smb_search_next *io,
940 void *search_private,
941 bool (*callback)(void *, const union smb_search_data *))
943 struct cvfs_private *private = ntvfs->private_data;
947 return smb_raw_search_next(private->tree, req, io, search_private, callback);
951 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
952 struct ntvfs_request *req, union smb_search_close *io)
954 struct cvfs_private *private = ntvfs->private_data;
958 return smb_raw_search_close(private->tree, io);
962 a handler for async trans2 replies
964 static void async_trans2(struct smbcli_request *c_req)
966 struct async_info *async = c_req->async.private;
967 struct ntvfs_request *req = async->req;
968 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
970 req->async_states->send_fn(req);
974 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
975 struct ntvfs_request *req,
976 struct smb_trans2 *trans2)
978 struct cvfs_private *private = ntvfs->private_data;
979 struct smbcli_request *c_req;
981 if (private->map_trans2) {
982 return NT_STATUS_NOT_IMPLEMENTED;
987 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
988 return smb_raw_trans2(private->tree, req, trans2);
991 c_req = smb_raw_trans2_send(private->tree, trans2);
993 ASYNC_RECV_TAIL(trans2, async_trans2);
997 /* SMBtrans - not used on file shares */
998 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
999 struct ntvfs_request *req,
1000 struct smb_trans2 *trans2)
1002 return NT_STATUS_ACCESS_DENIED;
1006 a handler for async change notify replies
1008 static void async_changenotify(struct smbcli_request *c_req)
1010 struct async_info *async = c_req->async.private;
1011 struct ntvfs_request *req = async->req;
1012 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
1014 req->async_states->send_fn(req);
1017 /* change notify request - always async */
1018 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1019 struct ntvfs_request *req,
1020 union smb_notify *io)
1022 struct cvfs_private *private = ntvfs->private_data;
1023 struct smbcli_request *c_req;
1024 int saved_timeout = private->transport->options.request_timeout;
1025 struct cvfs_file *f;
1027 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1028 return NT_STATUS_NOT_IMPLEMENTED;
1033 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1034 if (!f) return NT_STATUS_INVALID_HANDLE;
1035 io->nttrans.in.file.fnum = f->fnum;
1037 /* this request doesn't make sense unless its async */
1038 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1039 return NT_STATUS_INVALID_PARAMETER;
1042 /* we must not timeout on notify requests - they wait
1044 private->transport->options.request_timeout = 0;
1046 c_req = smb_raw_changenotify_send(private->tree, io);
1048 private->transport->options.request_timeout = saved_timeout;
1050 ASYNC_RECV_TAIL(io, async_changenotify);
1054 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1056 NTSTATUS ntvfs_cifs_init(void)
1059 struct ntvfs_ops ops;
1060 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1064 /* fill in the name and type */
1066 ops.type = NTVFS_DISK;
1068 /* fill in all the operations */
1069 ops.connect = cvfs_connect;
1070 ops.disconnect = cvfs_disconnect;
1071 ops.unlink = cvfs_unlink;
1072 ops.chkpath = cvfs_chkpath;
1073 ops.qpathinfo = cvfs_qpathinfo;
1074 ops.setpathinfo = cvfs_setpathinfo;
1075 ops.open = cvfs_open;
1076 ops.mkdir = cvfs_mkdir;
1077 ops.rmdir = cvfs_rmdir;
1078 ops.rename = cvfs_rename;
1079 ops.copy = cvfs_copy;
1080 ops.ioctl = cvfs_ioctl;
1081 ops.read = cvfs_read;
1082 ops.write = cvfs_write;
1083 ops.seek = cvfs_seek;
1084 ops.flush = cvfs_flush;
1085 ops.close = cvfs_close;
1086 ops.exit = cvfs_exit;
1087 ops.lock = cvfs_lock;
1088 ops.setfileinfo = cvfs_setfileinfo;
1089 ops.qfileinfo = cvfs_qfileinfo;
1090 ops.fsinfo = cvfs_fsinfo;
1092 ops.search_first = cvfs_search_first;
1093 ops.search_next = cvfs_search_next;
1094 ops.search_close = cvfs_search_close;
1095 ops.trans = cvfs_trans;
1096 ops.logoff = cvfs_logoff;
1097 ops.async_setup = cvfs_async_setup;
1098 ops.cancel = cvfs_cancel;
1099 ops.notify = cvfs_notify;
1100 ops.trans2 = cvfs_trans2;
1102 /* register ourselves with the NTVFS subsystem. We register
1103 under the name 'cifs'. */
1104 ret = ntvfs_register(&ops, &vers);
1106 if (!NT_STATUS_IS_OK(ret)) {
1107 DEBUG(0,("Failed to register CIFS backend!\n"));