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/raw/raw_proto.h"
30 #include "libcli/smb_composite/smb_composite.h"
31 #include "auth/auth.h"
32 #include "auth/credentials/credentials.h"
33 #include "ntvfs/ntvfs.h"
34 #include "../lib/util/dlinklist.h"
35 #include "param/param.h"
36 #include "libcli/resolve/resolve.h"
39 struct cvfs_file *prev, *next;
41 struct ntvfs_handle *h;
44 /* this is stored in ntvfs_private */
46 struct smbcli_tree *tree;
47 struct smbcli_transport *transport;
48 struct ntvfs_module_context *ntvfs;
49 struct async_info *pending;
50 struct cvfs_file *files;
56 /* a structure used to pass information to an async handler */
58 struct async_info *next, *prev;
59 struct cvfs_private *cvfs;
60 struct ntvfs_request *req;
61 struct smbcli_request *c_req;
66 NTSTATUS ntvfs_cifs_init(void);
68 #define CHECK_UPSTREAM_OPEN do { \
69 if (! p->transport->socket->sock) { \
70 req->async_states->state|=NTVFS_ASYNC_STATE_CLOSE; \
71 return NT_STATUS_CONNECTION_DISCONNECTED; \
75 #define SETUP_PID do { \
76 p->tree->session->pid = req->smbpid; \
77 CHECK_UPSTREAM_OPEN; \
80 #define SETUP_FILE_HERE(f) do { \
81 f = ntvfs_handle_get_backend_data(io->generic.in.file.ntvfs, ntvfs); \
82 if (!f) return NT_STATUS_INVALID_HANDLE; \
83 io->generic.in.file.fnum = f->fnum; \
86 #define SETUP_FILE do { \
87 struct cvfs_file *f; \
91 #define SETUP_PID_AND_FILE do { \
96 #define CIFS_SERVER "cifs:server"
97 #define CIFS_USER "cifs:user"
98 #define CIFS_PASSWORD "cifs:password"
99 #define CIFS_DOMAIN "cifs:domain"
100 #define CIFS_SHARE "cifs:share"
101 #define CIFS_USE_MACHINE_ACCT "cifs:use-machine-account"
102 #define CIFS_MAP_GENERIC "cifs:map-generic"
103 #define CIFS_MAP_TRANS2 "cifs:map-trans2"
105 #define CIFS_USE_MACHINE_ACCT_DEFAULT false
106 #define CIFS_MAP_GENERIC_DEFAULT false
107 #define CIFS_MAP_TRANS2_DEFAULT true
110 a handler for oplock break events from the server - these need to be passed
113 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *p_private)
115 struct cvfs_private *p = p_private;
117 struct ntvfs_handle *h = NULL;
120 for (f=p->files; f; f=f->next) {
121 if (f->fnum != fnum) continue;
127 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level, fnum));
131 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level, fnum));
132 status = ntvfs_send_oplock_break(p->ntvfs, h, level);
133 if (!NT_STATUS_IS_OK(status)) return false;
138 connect to a share - used when a tree_connect operation comes in.
140 static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
141 struct ntvfs_request *req,
142 union smb_tcon *tcon)
145 struct cvfs_private *p;
146 const char *host, *user, *pass, *domain, *remote_share;
147 struct smb_composite_connect io;
148 struct composite_context *creq;
149 struct share_config *scfg = ntvfs->ctx->config;
151 struct cli_credentials *credentials;
152 bool machine_account;
153 const char* sharename;
155 switch (tcon->generic.level) {
157 sharename = tcon->tcon.in.service;
160 sharename = tcon->tconx.in.path;
163 sharename = tcon->smb2.in.path;
166 return NT_STATUS_INVALID_LEVEL;
169 if (strncmp(sharename, "\\\\", 2) == 0) {
170 char *str = strchr(sharename+2, '\\');
176 /* Here we need to determine which server to connect to.
177 * For now we use parametric options, type cifs.
178 * Later we will use security=server and auth_server.c.
180 host = share_string_option(scfg, CIFS_SERVER, NULL);
181 user = share_string_option(scfg, CIFS_USER, NULL);
182 pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
183 domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
184 remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
186 remote_share = sharename;
189 machine_account = share_bool_option(scfg, CIFS_USE_MACHINE_ACCT, CIFS_USE_MACHINE_ACCT_DEFAULT);
191 p = talloc_zero(ntvfs, struct cvfs_private);
193 return NT_STATUS_NO_MEMORY;
196 ntvfs->private_data = p;
199 DEBUG(1,("CIFS backend: You must supply server\n"));
200 return NT_STATUS_INVALID_PARAMETER;
204 DEBUG(5, ("CIFS backend: Using specified password\n"));
205 credentials = cli_credentials_init(p);
207 return NT_STATUS_NO_MEMORY;
209 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
210 cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
212 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
214 cli_credentials_set_password(credentials, pass, CRED_SPECIFIED);
215 } else if (machine_account) {
216 DEBUG(5, ("CIFS backend: Using machine account\n"));
217 credentials = cli_credentials_init(p);
218 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
220 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
222 status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
223 if (!NT_STATUS_IS_OK(status)) {
226 } else if (req->session_info->credentials) {
227 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
228 credentials = req->session_info->credentials;
230 DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
231 return NT_STATUS_INTERNAL_ERROR;
234 /* connect to the server, using the smbd event context */
235 io.in.dest_host = host;
236 io.in.dest_ports = lpcfg_smb_ports(ntvfs->ctx->lp_ctx);
237 io.in.socket_options = lpcfg_socket_options(ntvfs->ctx->lp_ctx);
238 io.in.called_name = host;
239 io.in.credentials = credentials;
240 io.in.fallback_to_anonymous = false;
241 io.in.workgroup = lpcfg_workgroup(ntvfs->ctx->lp_ctx);
242 io.in.service = remote_share;
243 io.in.service_type = "?????";
244 io.in.gensec_settings = lpcfg_gensec_settings(p, ntvfs->ctx->lp_ctx);
245 lpcfg_smbcli_options(ntvfs->ctx->lp_ctx, &io.in.options);
246 lpcfg_smbcli_session_options(ntvfs->ctx->lp_ctx, &io.in.session_options);
248 if (!(ntvfs->ctx->client_caps & NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS)) {
249 io.in.options.use_level2_oplocks = false;
252 creq = smb_composite_connect_send(&io, p,
253 lpcfg_resolve_context(ntvfs->ctx->lp_ctx),
254 ntvfs->ctx->event_ctx);
255 status = smb_composite_connect_recv(creq, p);
256 NT_STATUS_NOT_OK_RETURN(status);
258 p->tree = io.out.tree;
260 p->transport = p->tree->session->transport;
264 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
265 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
266 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
267 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
269 if (tcon->generic.level == RAW_TCON_TCONX) {
270 tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
271 tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
274 /* we need to receive oplock break requests from the server */
275 smbcli_oplock_handler(p->transport, oplock_handler, p);
277 p->map_generic = share_bool_option(scfg, CIFS_MAP_GENERIC, CIFS_MAP_GENERIC_DEFAULT);
279 p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
285 disconnect from a share
287 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
289 struct cvfs_private *p = ntvfs->private_data;
290 struct async_info *a, *an;
292 /* first cleanup pending requests */
293 for (a=p->pending; a; a = an) {
295 smbcli_request_destroy(a->c_req);
300 ntvfs->private_data = NULL;
306 destroy an async info structure
308 static int async_info_destructor(struct async_info *async)
310 DLIST_REMOVE(async->cvfs->pending, async);
315 a handler for simple async replies
316 this handler can only be used for functions that don't return any
317 parameters (those that just return a status code)
319 static void async_simple(struct smbcli_request *c_req)
321 struct async_info *async = c_req->async.private_data;
322 struct ntvfs_request *req = async->req;
323 req->async_states->status = smbcli_request_simple_recv(c_req);
325 req->async_states->send_fn(req);
329 /* save some typing for the simple functions */
330 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
331 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
333 struct async_info *async; \
334 async = talloc(req, struct async_info); \
335 if (!async) return NT_STATUS_NO_MEMORY; \
340 async->c_req = c_req; \
341 DLIST_ADD(p->pending, async); \
342 c_req->async.private_data = async; \
343 talloc_set_destructor(async, async_info_destructor); \
345 c_req->async.fn = async_fn; \
346 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
347 return NT_STATUS_OK; \
350 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
352 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
355 delete a file - the dirtype specifies the file types to include in the search.
356 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
358 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
359 struct ntvfs_request *req, union smb_unlink *unl)
361 struct cvfs_private *p = ntvfs->private_data;
362 struct smbcli_request *c_req;
366 /* see if the front end will allow us to perform this
367 function asynchronously. */
368 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
369 return smb_raw_unlink(p->tree, unl);
372 c_req = smb_raw_unlink_send(p->tree, unl);
378 a handler for async ioctl replies
380 static void async_ioctl(struct smbcli_request *c_req)
382 struct async_info *async = c_req->async.private_data;
383 struct ntvfs_request *req = async->req;
384 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
386 req->async_states->send_fn(req);
392 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
393 struct ntvfs_request *req, union smb_ioctl *io)
395 struct cvfs_private *p = ntvfs->private_data;
396 struct smbcli_request *c_req;
400 /* see if the front end will allow us to perform this
401 function asynchronously. */
402 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
403 return smb_raw_ioctl(p->tree, req, io);
406 c_req = smb_raw_ioctl_send(p->tree, io);
408 ASYNC_RECV_TAIL(io, async_ioctl);
412 check if a directory exists
414 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
415 struct ntvfs_request *req, union smb_chkpath *cp)
417 struct cvfs_private *p = ntvfs->private_data;
418 struct smbcli_request *c_req;
422 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
423 return smb_raw_chkpath(p->tree, cp);
426 c_req = smb_raw_chkpath_send(p->tree, cp);
432 a handler for async qpathinfo replies
434 static void async_qpathinfo(struct smbcli_request *c_req)
436 struct async_info *async = c_req->async.private_data;
437 struct ntvfs_request *req = async->req;
438 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
440 req->async_states->send_fn(req);
444 return info on a pathname
446 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
447 struct ntvfs_request *req, union smb_fileinfo *info)
449 struct cvfs_private *p = ntvfs->private_data;
450 struct smbcli_request *c_req;
454 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
455 return smb_raw_pathinfo(p->tree, req, info);
458 c_req = smb_raw_pathinfo_send(p->tree, info);
460 ASYNC_RECV_TAIL(info, async_qpathinfo);
464 a handler for async qfileinfo replies
466 static void async_qfileinfo(struct smbcli_request *c_req)
468 struct async_info *async = c_req->async.private_data;
469 struct ntvfs_request *req = async->req;
470 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
472 req->async_states->send_fn(req);
476 query info on a open file
478 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
479 struct ntvfs_request *req, union smb_fileinfo *io)
481 struct cvfs_private *p = ntvfs->private_data;
482 struct smbcli_request *c_req;
486 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
487 return smb_raw_fileinfo(p->tree, req, io);
490 c_req = smb_raw_fileinfo_send(p->tree, io);
492 ASYNC_RECV_TAIL(io, async_qfileinfo);
497 set info on a pathname
499 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
500 struct ntvfs_request *req, union smb_setfileinfo *st)
502 struct cvfs_private *p = ntvfs->private_data;
503 struct smbcli_request *c_req;
507 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
508 return smb_raw_setpathinfo(p->tree, st);
511 c_req = smb_raw_setpathinfo_send(p->tree, st);
518 a handler for async open replies
520 static void async_open(struct smbcli_request *c_req)
522 struct async_info *async = c_req->async.private_data;
523 struct cvfs_private *cvfs = async->cvfs;
524 struct ntvfs_request *req = async->req;
525 struct cvfs_file *f = async->f;
526 union smb_open *io = async->parms;
527 union smb_handle *file;
529 req->async_states->status = smb_raw_open_recv(c_req, req, io);
530 SMB_OPEN_OUT_FILE(io, file);
531 f->fnum = file->fnum;
533 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
534 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
535 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
537 DLIST_ADD(cvfs->files, f);
539 req->async_states->send_fn(req);
545 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
546 struct ntvfs_request *req, union smb_open *io)
548 struct cvfs_private *p = ntvfs->private_data;
549 struct smbcli_request *c_req;
550 struct ntvfs_handle *h;
556 if (io->generic.level != RAW_OPEN_GENERIC &&
558 return ntvfs_map_open(ntvfs, req, io);
561 status = ntvfs_handle_new(ntvfs, req, &h);
562 NT_STATUS_NOT_OK_RETURN(status);
564 f = talloc_zero(h, struct cvfs_file);
565 NT_STATUS_HAVE_NO_MEMORY(f);
568 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
569 union smb_handle *file;
571 status = smb_raw_open(p->tree, req, io);
572 NT_STATUS_NOT_OK_RETURN(status);
574 SMB_OPEN_OUT_FILE(io, file);
575 f->fnum = file->fnum;
577 status = ntvfs_handle_set_backend_data(f->h, p->ntvfs, f);
578 NT_STATUS_NOT_OK_RETURN(status);
580 DLIST_ADD(p->files, f);
585 c_req = smb_raw_open_send(p->tree, io);
587 ASYNC_RECV_TAIL_F(io, async_open, f);
593 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
594 struct ntvfs_request *req, union smb_mkdir *md)
596 struct cvfs_private *p = ntvfs->private_data;
597 struct smbcli_request *c_req;
601 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
602 return smb_raw_mkdir(p->tree, md);
605 c_req = smb_raw_mkdir_send(p->tree, md);
613 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
614 struct ntvfs_request *req, struct smb_rmdir *rd)
616 struct cvfs_private *p = ntvfs->private_data;
617 struct smbcli_request *c_req;
621 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
622 return smb_raw_rmdir(p->tree, rd);
624 c_req = smb_raw_rmdir_send(p->tree, rd);
630 rename a set of files
632 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
633 struct ntvfs_request *req, union smb_rename *ren)
635 struct cvfs_private *p = ntvfs->private_data;
636 struct smbcli_request *c_req;
640 if (ren->nttrans.level == RAW_RENAME_NTTRANS) {
642 f = ntvfs_handle_get_backend_data(ren->nttrans.in.file.ntvfs, ntvfs);
643 if (!f) return NT_STATUS_INVALID_HANDLE;
644 ren->nttrans.in.file.fnum = f->fnum;
647 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
648 return smb_raw_rename(p->tree, ren);
651 c_req = smb_raw_rename_send(p->tree, ren);
659 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
660 struct ntvfs_request *req, struct smb_copy *cp)
662 return NT_STATUS_NOT_SUPPORTED;
666 a handler for async read replies
668 static void async_read(struct smbcli_request *c_req)
670 struct async_info *async = c_req->async.private_data;
671 struct ntvfs_request *req = async->req;
672 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
674 req->async_states->send_fn(req);
680 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
681 struct ntvfs_request *req, union smb_read *io)
683 struct cvfs_private *p = ntvfs->private_data;
684 struct smbcli_request *c_req;
688 if (io->generic.level != RAW_READ_GENERIC &&
690 return ntvfs_map_read(ntvfs, req, io);
695 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
696 return smb_raw_read(p->tree, io);
699 c_req = smb_raw_read_send(p->tree, io);
701 ASYNC_RECV_TAIL(io, async_read);
705 a handler for async write replies
707 static void async_write(struct smbcli_request *c_req)
709 struct async_info *async = c_req->async.private_data;
710 struct ntvfs_request *req = async->req;
711 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
713 req->async_states->send_fn(req);
719 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
720 struct ntvfs_request *req, union smb_write *io)
722 struct cvfs_private *p = ntvfs->private_data;
723 struct smbcli_request *c_req;
727 if (io->generic.level != RAW_WRITE_GENERIC &&
729 return ntvfs_map_write(ntvfs, req, io);
733 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
734 return smb_raw_write(p->tree, io);
737 c_req = smb_raw_write_send(p->tree, io);
739 ASYNC_RECV_TAIL(io, async_write);
743 a handler for async seek replies
745 static void async_seek(struct smbcli_request *c_req)
747 struct async_info *async = c_req->async.private_data;
748 struct ntvfs_request *req = async->req;
749 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
751 req->async_states->send_fn(req);
757 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
758 struct ntvfs_request *req,
761 struct cvfs_private *p = ntvfs->private_data;
762 struct smbcli_request *c_req;
766 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
767 return smb_raw_seek(p->tree, io);
770 c_req = smb_raw_seek_send(p->tree, io);
772 ASYNC_RECV_TAIL(io, async_seek);
778 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
779 struct ntvfs_request *req,
782 struct cvfs_private *p = ntvfs->private_data;
783 struct smbcli_request *c_req;
786 switch (io->generic.level) {
787 case RAW_FLUSH_FLUSH:
791 io->generic.in.file.fnum = 0xFFFF;
794 return NT_STATUS_INVALID_LEVEL;
797 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
798 return smb_raw_flush(p->tree, io);
801 c_req = smb_raw_flush_send(p->tree, io);
809 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
810 struct ntvfs_request *req, union smb_close *io)
812 struct cvfs_private *p = ntvfs->private_data;
813 struct smbcli_request *c_req;
819 if (io->generic.level != RAW_CLOSE_GENERIC &&
821 return ntvfs_map_close(ntvfs, req, io);
824 if (io->generic.level == RAW_CLOSE_GENERIC) {
826 io2.close.level = RAW_CLOSE_CLOSE;
827 io2.close.in.file = io->generic.in.file;
828 io2.close.in.write_time = io->generic.in.write_time;
833 /* Note, we aren't free-ing f, or it's h here. Should we?
834 even if file-close fails, we'll remove it from the list,
835 what else would we do? Maybe we should not remove until
836 after the proxied call completes? */
837 DLIST_REMOVE(p->files, f);
839 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
840 return smb_raw_close(p->tree, io);
843 c_req = smb_raw_close_send(p->tree, io);
849 exit - closing files open by the pid
851 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
852 struct ntvfs_request *req)
854 struct cvfs_private *p = ntvfs->private_data;
855 struct smbcli_request *c_req;
859 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
860 return smb_raw_exit(p->tree->session);
863 c_req = smb_raw_exit_send(p->tree->session);
869 logoff - closing files open by the user
871 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
872 struct ntvfs_request *req)
874 /* we can't do this right in the cifs backend .... */
879 setup for an async call - nothing to do yet
881 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
882 struct ntvfs_request *req,
891 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
892 struct ntvfs_request *req)
894 struct cvfs_private *p = ntvfs->private_data;
895 struct async_info *a;
897 /* find the matching request */
898 for (a=p->pending;a;a=a->next) {
905 return NT_STATUS_INVALID_PARAMETER;
908 return smb_raw_ntcancel(a->c_req);
914 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
915 struct ntvfs_request *req, union smb_lock *io)
917 struct cvfs_private *p = ntvfs->private_data;
918 struct smbcli_request *c_req;
922 if (io->generic.level != RAW_LOCK_GENERIC &&
924 return ntvfs_map_lock(ntvfs, req, io);
928 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
929 return smb_raw_lock(p->tree, io);
932 c_req = smb_raw_lock_send(p->tree, io);
937 set info on a open file
939 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
940 struct ntvfs_request *req,
941 union smb_setfileinfo *io)
943 struct cvfs_private *p = ntvfs->private_data;
944 struct smbcli_request *c_req;
948 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
949 return smb_raw_setfileinfo(p->tree, io);
951 c_req = smb_raw_setfileinfo_send(p->tree, io);
958 a handler for async fsinfo replies
960 static void async_fsinfo(struct smbcli_request *c_req)
962 struct async_info *async = c_req->async.private_data;
963 struct ntvfs_request *req = async->req;
964 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
966 req->async_states->send_fn(req);
970 return filesystem space info
972 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
973 struct ntvfs_request *req, union smb_fsinfo *fs)
975 struct cvfs_private *p = ntvfs->private_data;
976 struct smbcli_request *c_req;
980 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
981 return smb_raw_fsinfo(p->tree, req, fs);
984 c_req = smb_raw_fsinfo_send(p->tree, req, fs);
986 ASYNC_RECV_TAIL(fs, async_fsinfo);
990 return print queue info
992 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
993 struct ntvfs_request *req, union smb_lpq *lpq)
995 return NT_STATUS_NOT_SUPPORTED;
999 list files in a directory matching a wildcard pattern
1001 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
1002 struct ntvfs_request *req, union smb_search_first *io,
1003 void *search_private,
1004 bool (*callback)(void *, const union smb_search_data *))
1006 struct cvfs_private *p = ntvfs->private_data;
1010 return smb_raw_search_first(p->tree, req, io, search_private, callback);
1013 /* continue a search */
1014 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
1015 struct ntvfs_request *req, union smb_search_next *io,
1016 void *search_private,
1017 bool (*callback)(void *, const union smb_search_data *))
1019 struct cvfs_private *p = ntvfs->private_data;
1023 return smb_raw_search_next(p->tree, req, io, search_private, callback);
1026 /* close a search */
1027 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
1028 struct ntvfs_request *req, union smb_search_close *io)
1030 struct cvfs_private *p = ntvfs->private_data;
1034 return smb_raw_search_close(p->tree, io);
1038 a handler for async trans2 replies
1040 static void async_trans2(struct smbcli_request *c_req)
1042 struct async_info *async = c_req->async.private_data;
1043 struct ntvfs_request *req = async->req;
1044 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
1046 req->async_states->send_fn(req);
1050 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
1051 struct ntvfs_request *req,
1052 struct smb_trans2 *trans2)
1054 struct cvfs_private *p = ntvfs->private_data;
1055 struct smbcli_request *c_req;
1057 if (p->map_trans2) {
1058 return NT_STATUS_NOT_IMPLEMENTED;
1063 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1064 return smb_raw_trans2(p->tree, req, trans2);
1067 c_req = smb_raw_trans2_send(p->tree, trans2);
1069 ASYNC_RECV_TAIL(trans2, async_trans2);
1073 /* SMBtrans - not used on file shares */
1074 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
1075 struct ntvfs_request *req,
1076 struct smb_trans2 *trans2)
1078 return NT_STATUS_ACCESS_DENIED;
1082 a handler for async change notify replies
1084 static void async_changenotify(struct smbcli_request *c_req)
1086 struct async_info *async = c_req->async.private_data;
1087 struct ntvfs_request *req = async->req;
1088 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
1090 req->async_states->send_fn(req);
1093 /* change notify request - always async */
1094 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1095 struct ntvfs_request *req,
1096 union smb_notify *io)
1098 struct cvfs_private *p = ntvfs->private_data;
1099 struct smbcli_request *c_req;
1100 int saved_timeout = p->transport->options.request_timeout;
1101 struct cvfs_file *f;
1103 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1104 return NT_STATUS_NOT_IMPLEMENTED;
1109 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1110 if (!f) return NT_STATUS_INVALID_HANDLE;
1111 io->nttrans.in.file.fnum = f->fnum;
1113 /* this request doesn't make sense unless its async */
1114 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1115 return NT_STATUS_INVALID_PARAMETER;
1118 /* we must not timeout on notify requests - they wait
1120 p->transport->options.request_timeout = 0;
1122 c_req = smb_raw_changenotify_send(p->tree, io);
1124 p->transport->options.request_timeout = saved_timeout;
1126 ASYNC_RECV_TAIL(io, async_changenotify);
1130 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1132 NTSTATUS ntvfs_cifs_init(void)
1135 struct ntvfs_ops ops;
1136 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1140 /* fill in the name and type */
1142 ops.type = NTVFS_DISK;
1144 /* fill in all the operations */
1145 ops.connect = cvfs_connect;
1146 ops.disconnect = cvfs_disconnect;
1147 ops.unlink = cvfs_unlink;
1148 ops.chkpath = cvfs_chkpath;
1149 ops.qpathinfo = cvfs_qpathinfo;
1150 ops.setpathinfo = cvfs_setpathinfo;
1151 ops.open = cvfs_open;
1152 ops.mkdir = cvfs_mkdir;
1153 ops.rmdir = cvfs_rmdir;
1154 ops.rename = cvfs_rename;
1155 ops.copy = cvfs_copy;
1156 ops.ioctl = cvfs_ioctl;
1157 ops.read = cvfs_read;
1158 ops.write = cvfs_write;
1159 ops.seek = cvfs_seek;
1160 ops.flush = cvfs_flush;
1161 ops.close = cvfs_close;
1162 ops.exit = cvfs_exit;
1163 ops.lock = cvfs_lock;
1164 ops.setfileinfo = cvfs_setfileinfo;
1165 ops.qfileinfo = cvfs_qfileinfo;
1166 ops.fsinfo = cvfs_fsinfo;
1168 ops.search_first = cvfs_search_first;
1169 ops.search_next = cvfs_search_next;
1170 ops.search_close = cvfs_search_close;
1171 ops.trans = cvfs_trans;
1172 ops.logoff = cvfs_logoff;
1173 ops.async_setup = cvfs_async_setup;
1174 ops.cancel = cvfs_cancel;
1175 ops.notify = cvfs_notify;
1176 ops.trans2 = cvfs_trans2;
1178 /* register ourselves with the NTVFS subsystem. We register
1179 under the name 'cifs'. */
1180 ret = ntvfs_register(&ops, &vers);
1182 if (!NT_STATUS_IS_OK(ret)) {
1183 DEBUG(0,("Failed to register CIFS backend!\n"));