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 #define CHECK_UPSTREAM_OPEN do { \
67 if (! p->transport->socket->sock) { \
68 req->async_states->state|=NTVFS_ASYNC_STATE_CLOSE; \
69 return NT_STATUS_CONNECTION_DISCONNECTED; \
73 #define SETUP_PID do { \
74 p->tree->session->pid = req->smbpid; \
75 CHECK_UPSTREAM_OPEN; \
78 #define SETUP_FILE_HERE(f) do { \
79 f = ntvfs_handle_get_backend_data(io->generic.in.file.ntvfs, ntvfs); \
80 if (!f) return NT_STATUS_INVALID_HANDLE; \
81 io->generic.in.file.fnum = f->fnum; \
84 #define SETUP_FILE do { \
85 struct cvfs_file *f; \
89 #define SETUP_PID_AND_FILE do { \
94 #define CIFS_SERVER "cifs:server"
95 #define CIFS_USER "cifs:user"
96 #define CIFS_PASSWORD "cifs:password"
97 #define CIFS_DOMAIN "cifs:domain"
98 #define CIFS_SHARE "cifs:share"
99 #define CIFS_USE_MACHINE_ACCT "cifs:use-machine-account"
100 #define CIFS_MAP_GENERIC "cifs:map-generic"
101 #define CIFS_MAP_TRANS2 "cifs:map-trans2"
103 #define CIFS_USE_MACHINE_ACCT_DEFAULT false
104 #define CIFS_MAP_GENERIC_DEFAULT false
105 #define CIFS_MAP_TRANS2_DEFAULT true
108 a handler for oplock break events from the server - these need to be passed
111 static bool oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *p_private)
113 struct cvfs_private *p = p_private;
115 struct ntvfs_handle *h = NULL;
118 for (f=p->files; f; f=f->next) {
119 if (f->fnum != fnum) continue;
125 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level, fnum));
129 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level, fnum));
130 status = ntvfs_send_oplock_break(p->ntvfs, h, level);
131 if (!NT_STATUS_IS_OK(status)) return false;
136 connect to a share - used when a tree_connect operation comes in.
138 static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
139 struct ntvfs_request *req,
140 union smb_tcon *tcon)
143 struct cvfs_private *p;
144 const char *host, *user, *pass, *domain, *remote_share;
145 struct smb_composite_connect io;
146 struct composite_context *creq;
147 struct share_config *scfg = ntvfs->ctx->config;
149 struct cli_credentials *credentials;
150 bool machine_account;
151 const char* sharename;
153 switch (tcon->generic.level) {
155 sharename = tcon->tcon.in.service;
158 sharename = tcon->tconx.in.path;
161 sharename = tcon->smb2.in.path;
164 return NT_STATUS_INVALID_LEVEL;
167 if (strncmp(sharename, "\\\\", 2) == 0) {
168 char *str = strchr(sharename+2, '\\');
174 /* Here we need to determine which server to connect to.
175 * For now we use parametric options, type cifs.
176 * Later we will use security=server and auth_server.c.
178 host = share_string_option(scfg, CIFS_SERVER, NULL);
179 user = share_string_option(scfg, CIFS_USER, NULL);
180 pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
181 domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
182 remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
184 remote_share = sharename;
187 machine_account = share_bool_option(scfg, CIFS_USE_MACHINE_ACCT, CIFS_USE_MACHINE_ACCT_DEFAULT);
189 p = talloc_zero(ntvfs, struct cvfs_private);
191 return NT_STATUS_NO_MEMORY;
194 ntvfs->private_data = p;
197 DEBUG(1,("CIFS backend: You must supply server\n"));
198 return NT_STATUS_INVALID_PARAMETER;
202 DEBUG(5, ("CIFS backend: Using specified password\n"));
203 credentials = cli_credentials_init(p);
205 return NT_STATUS_NO_MEMORY;
207 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
208 cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
210 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
212 cli_credentials_set_password(credentials, pass, CRED_SPECIFIED);
213 } else if (machine_account) {
214 DEBUG(5, ("CIFS backend: Using machine account\n"));
215 credentials = cli_credentials_init(p);
216 cli_credentials_set_conf(credentials, ntvfs->ctx->lp_ctx);
218 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
220 status = cli_credentials_set_machine_account(credentials, ntvfs->ctx->lp_ctx);
221 if (!NT_STATUS_IS_OK(status)) {
224 } else if (req->session_info->credentials) {
225 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
226 credentials = req->session_info->credentials;
228 DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
229 return NT_STATUS_INVALID_PARAMETER;
232 /* connect to the server, using the smbd event context */
233 io.in.dest_host = host;
234 io.in.dest_ports = lp_smb_ports(ntvfs->ctx->lp_ctx);
235 io.in.socket_options = lp_socket_options(ntvfs->ctx->lp_ctx);
236 io.in.called_name = host;
237 io.in.credentials = credentials;
238 io.in.fallback_to_anonymous = false;
239 io.in.workgroup = lp_workgroup(ntvfs->ctx->lp_ctx);
240 io.in.service = remote_share;
241 io.in.service_type = "?????";
242 io.in.gensec_settings = lp_gensec_settings(p, ntvfs->ctx->lp_ctx);
243 lp_smbcli_options(ntvfs->ctx->lp_ctx, &io.in.options);
244 lp_smbcli_session_options(ntvfs->ctx->lp_ctx, &io.in.session_options);
246 if (!(ntvfs->ctx->client_caps & NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS)) {
247 io.in.options.use_level2_oplocks = false;
250 creq = smb_composite_connect_send(&io, p,
251 lp_resolve_context(ntvfs->ctx->lp_ctx),
252 ntvfs->ctx->event_ctx);
253 status = smb_composite_connect_recv(creq, p);
254 NT_STATUS_NOT_OK_RETURN(status);
256 p->tree = io.out.tree;
258 p->transport = p->tree->session->transport;
262 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
263 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
264 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
265 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
267 if (tcon->generic.level == RAW_TCON_TCONX) {
268 tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
269 tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
272 /* we need to receive oplock break requests from the server */
273 smbcli_oplock_handler(p->transport, oplock_handler, p);
275 p->map_generic = share_bool_option(scfg, CIFS_MAP_GENERIC, CIFS_MAP_GENERIC_DEFAULT);
277 p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
283 disconnect from a share
285 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
287 struct cvfs_private *p = ntvfs->private_data;
288 struct async_info *a, *an;
290 /* first cleanup pending requests */
291 for (a=p->pending; a; a = an) {
293 smbcli_request_destroy(a->c_req);
298 ntvfs->private_data = NULL;
304 destroy an async info structure
306 static int async_info_destructor(struct async_info *async)
308 DLIST_REMOVE(async->cvfs->pending, async);
313 a handler for simple async replies
314 this handler can only be used for functions that don't return any
315 parameters (those that just return a status code)
317 static void async_simple(struct smbcli_request *c_req)
319 struct async_info *async = c_req->async.private_data;
320 struct ntvfs_request *req = async->req;
321 req->async_states->status = smbcli_request_simple_recv(c_req);
323 req->async_states->send_fn(req);
327 /* save some typing for the simple functions */
328 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
329 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
331 struct async_info *async; \
332 async = talloc(req, struct async_info); \
333 if (!async) return NT_STATUS_NO_MEMORY; \
338 async->c_req = c_req; \
339 DLIST_ADD(p->pending, async); \
340 c_req->async.private_data = async; \
341 talloc_set_destructor(async, async_info_destructor); \
343 c_req->async.fn = async_fn; \
344 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
345 return NT_STATUS_OK; \
348 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
350 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
353 delete a file - the dirtype specifies the file types to include in the search.
354 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
356 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
357 struct ntvfs_request *req, union smb_unlink *unl)
359 struct cvfs_private *p = ntvfs->private_data;
360 struct smbcli_request *c_req;
364 /* see if the front end will allow us to perform this
365 function asynchronously. */
366 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
367 return smb_raw_unlink(p->tree, unl);
370 c_req = smb_raw_unlink_send(p->tree, unl);
376 a handler for async ioctl replies
378 static void async_ioctl(struct smbcli_request *c_req)
380 struct async_info *async = c_req->async.private_data;
381 struct ntvfs_request *req = async->req;
382 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
384 req->async_states->send_fn(req);
390 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
391 struct ntvfs_request *req, union smb_ioctl *io)
393 struct cvfs_private *p = ntvfs->private_data;
394 struct smbcli_request *c_req;
398 /* see if the front end will allow us to perform this
399 function asynchronously. */
400 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
401 return smb_raw_ioctl(p->tree, req, io);
404 c_req = smb_raw_ioctl_send(p->tree, io);
406 ASYNC_RECV_TAIL(io, async_ioctl);
410 check if a directory exists
412 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
413 struct ntvfs_request *req, union smb_chkpath *cp)
415 struct cvfs_private *p = ntvfs->private_data;
416 struct smbcli_request *c_req;
420 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
421 return smb_raw_chkpath(p->tree, cp);
424 c_req = smb_raw_chkpath_send(p->tree, cp);
430 a handler for async qpathinfo replies
432 static void async_qpathinfo(struct smbcli_request *c_req)
434 struct async_info *async = c_req->async.private_data;
435 struct ntvfs_request *req = async->req;
436 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
438 req->async_states->send_fn(req);
442 return info on a pathname
444 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
445 struct ntvfs_request *req, union smb_fileinfo *info)
447 struct cvfs_private *p = ntvfs->private_data;
448 struct smbcli_request *c_req;
452 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
453 return smb_raw_pathinfo(p->tree, req, info);
456 c_req = smb_raw_pathinfo_send(p->tree, info);
458 ASYNC_RECV_TAIL(info, async_qpathinfo);
462 a handler for async qfileinfo replies
464 static void async_qfileinfo(struct smbcli_request *c_req)
466 struct async_info *async = c_req->async.private_data;
467 struct ntvfs_request *req = async->req;
468 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
470 req->async_states->send_fn(req);
474 query info on a open file
476 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
477 struct ntvfs_request *req, union smb_fileinfo *io)
479 struct cvfs_private *p = ntvfs->private_data;
480 struct smbcli_request *c_req;
484 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
485 return smb_raw_fileinfo(p->tree, req, io);
488 c_req = smb_raw_fileinfo_send(p->tree, io);
490 ASYNC_RECV_TAIL(io, async_qfileinfo);
495 set info on a pathname
497 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
498 struct ntvfs_request *req, union smb_setfileinfo *st)
500 struct cvfs_private *p = ntvfs->private_data;
501 struct smbcli_request *c_req;
505 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
506 return smb_raw_setpathinfo(p->tree, st);
509 c_req = smb_raw_setpathinfo_send(p->tree, st);
516 a handler for async open replies
518 static void async_open(struct smbcli_request *c_req)
520 struct async_info *async = c_req->async.private_data;
521 struct cvfs_private *cvfs = async->cvfs;
522 struct ntvfs_request *req = async->req;
523 struct cvfs_file *f = async->f;
524 union smb_open *io = async->parms;
525 union smb_handle *file;
527 req->async_states->status = smb_raw_open_recv(c_req, req, io);
528 SMB_OPEN_OUT_FILE(io, file);
529 f->fnum = file->fnum;
531 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
532 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
533 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
535 DLIST_ADD(cvfs->files, f);
537 req->async_states->send_fn(req);
543 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
544 struct ntvfs_request *req, union smb_open *io)
546 struct cvfs_private *p = ntvfs->private_data;
547 struct smbcli_request *c_req;
548 struct ntvfs_handle *h;
554 if (io->generic.level != RAW_OPEN_GENERIC &&
556 return ntvfs_map_open(ntvfs, req, io);
559 status = ntvfs_handle_new(ntvfs, req, &h);
560 NT_STATUS_NOT_OK_RETURN(status);
562 f = talloc_zero(h, struct cvfs_file);
563 NT_STATUS_HAVE_NO_MEMORY(f);
566 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
567 union smb_handle *file;
569 status = smb_raw_open(p->tree, req, io);
570 NT_STATUS_NOT_OK_RETURN(status);
572 SMB_OPEN_OUT_FILE(io, file);
573 f->fnum = file->fnum;
575 status = ntvfs_handle_set_backend_data(f->h, p->ntvfs, f);
576 NT_STATUS_NOT_OK_RETURN(status);
578 DLIST_ADD(p->files, f);
583 c_req = smb_raw_open_send(p->tree, io);
585 ASYNC_RECV_TAIL_F(io, async_open, f);
591 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
592 struct ntvfs_request *req, union smb_mkdir *md)
594 struct cvfs_private *p = ntvfs->private_data;
595 struct smbcli_request *c_req;
599 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
600 return smb_raw_mkdir(p->tree, md);
603 c_req = smb_raw_mkdir_send(p->tree, md);
611 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
612 struct ntvfs_request *req, struct smb_rmdir *rd)
614 struct cvfs_private *p = ntvfs->private_data;
615 struct smbcli_request *c_req;
619 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
620 return smb_raw_rmdir(p->tree, rd);
622 c_req = smb_raw_rmdir_send(p->tree, rd);
628 rename a set of files
630 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
631 struct ntvfs_request *req, union smb_rename *ren)
633 struct cvfs_private *p = ntvfs->private_data;
634 struct smbcli_request *c_req;
638 if (ren->nttrans.level == RAW_RENAME_NTTRANS) {
640 f = ntvfs_handle_get_backend_data(ren->nttrans.in.file.ntvfs, ntvfs);
641 if (!f) return NT_STATUS_INVALID_HANDLE;
642 ren->nttrans.in.file.fnum = f->fnum;
645 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
646 return smb_raw_rename(p->tree, ren);
649 c_req = smb_raw_rename_send(p->tree, ren);
657 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
658 struct ntvfs_request *req, struct smb_copy *cp)
660 return NT_STATUS_NOT_SUPPORTED;
664 a handler for async read replies
666 static void async_read(struct smbcli_request *c_req)
668 struct async_info *async = c_req->async.private_data;
669 struct ntvfs_request *req = async->req;
670 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
672 req->async_states->send_fn(req);
678 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
679 struct ntvfs_request *req, union smb_read *io)
681 struct cvfs_private *p = ntvfs->private_data;
682 struct smbcli_request *c_req;
686 if (io->generic.level != RAW_READ_GENERIC &&
688 return ntvfs_map_read(ntvfs, req, io);
693 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
694 return smb_raw_read(p->tree, io);
697 c_req = smb_raw_read_send(p->tree, io);
699 ASYNC_RECV_TAIL(io, async_read);
703 a handler for async write replies
705 static void async_write(struct smbcli_request *c_req)
707 struct async_info *async = c_req->async.private_data;
708 struct ntvfs_request *req = async->req;
709 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
711 req->async_states->send_fn(req);
717 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
718 struct ntvfs_request *req, union smb_write *io)
720 struct cvfs_private *p = ntvfs->private_data;
721 struct smbcli_request *c_req;
725 if (io->generic.level != RAW_WRITE_GENERIC &&
727 return ntvfs_map_write(ntvfs, req, io);
731 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
732 return smb_raw_write(p->tree, io);
735 c_req = smb_raw_write_send(p->tree, io);
737 ASYNC_RECV_TAIL(io, async_write);
741 a handler for async seek replies
743 static void async_seek(struct smbcli_request *c_req)
745 struct async_info *async = c_req->async.private_data;
746 struct ntvfs_request *req = async->req;
747 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
749 req->async_states->send_fn(req);
755 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
756 struct ntvfs_request *req,
759 struct cvfs_private *p = ntvfs->private_data;
760 struct smbcli_request *c_req;
764 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
765 return smb_raw_seek(p->tree, io);
768 c_req = smb_raw_seek_send(p->tree, io);
770 ASYNC_RECV_TAIL(io, async_seek);
776 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
777 struct ntvfs_request *req,
780 struct cvfs_private *p = ntvfs->private_data;
781 struct smbcli_request *c_req;
784 switch (io->generic.level) {
785 case RAW_FLUSH_FLUSH:
789 io->generic.in.file.fnum = 0xFFFF;
792 return NT_STATUS_INVALID_LEVEL;
795 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
796 return smb_raw_flush(p->tree, io);
799 c_req = smb_raw_flush_send(p->tree, io);
807 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
808 struct ntvfs_request *req, union smb_close *io)
810 struct cvfs_private *p = ntvfs->private_data;
811 struct smbcli_request *c_req;
817 if (io->generic.level != RAW_CLOSE_GENERIC &&
819 return ntvfs_map_close(ntvfs, req, io);
822 if (io->generic.level == RAW_CLOSE_GENERIC) {
824 io2.close.level = RAW_CLOSE_CLOSE;
825 io2.close.in.file = io->generic.in.file;
826 io2.close.in.write_time = io->generic.in.write_time;
831 /* Note, we aren't free-ing f, or it's h here. Should we?
832 even if file-close fails, we'll remove it from the list,
833 what else would we do? Maybe we should not remove until
834 after the proxied call completes? */
835 DLIST_REMOVE(p->files, f);
837 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
838 return smb_raw_close(p->tree, io);
841 c_req = smb_raw_close_send(p->tree, io);
847 exit - closing files open by the pid
849 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
850 struct ntvfs_request *req)
852 struct cvfs_private *p = ntvfs->private_data;
853 struct smbcli_request *c_req;
857 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
858 return smb_raw_exit(p->tree->session);
861 c_req = smb_raw_exit_send(p->tree->session);
867 logoff - closing files open by the user
869 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
870 struct ntvfs_request *req)
872 /* we can't do this right in the cifs backend .... */
877 setup for an async call - nothing to do yet
879 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
880 struct ntvfs_request *req,
889 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
890 struct ntvfs_request *req)
892 struct cvfs_private *p = ntvfs->private_data;
893 struct async_info *a;
895 /* find the matching request */
896 for (a=p->pending;a;a=a->next) {
903 return NT_STATUS_INVALID_PARAMETER;
906 return smb_raw_ntcancel(a->c_req);
912 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
913 struct ntvfs_request *req, union smb_lock *io)
915 struct cvfs_private *p = ntvfs->private_data;
916 struct smbcli_request *c_req;
920 if (io->generic.level != RAW_LOCK_GENERIC &&
922 return ntvfs_map_lock(ntvfs, req, io);
926 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
927 return smb_raw_lock(p->tree, io);
930 c_req = smb_raw_lock_send(p->tree, io);
935 set info on a open file
937 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
938 struct ntvfs_request *req,
939 union smb_setfileinfo *io)
941 struct cvfs_private *p = ntvfs->private_data;
942 struct smbcli_request *c_req;
946 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
947 return smb_raw_setfileinfo(p->tree, io);
949 c_req = smb_raw_setfileinfo_send(p->tree, io);
956 a handler for async fsinfo replies
958 static void async_fsinfo(struct smbcli_request *c_req)
960 struct async_info *async = c_req->async.private_data;
961 struct ntvfs_request *req = async->req;
962 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
964 req->async_states->send_fn(req);
968 return filesystem space info
970 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
971 struct ntvfs_request *req, union smb_fsinfo *fs)
973 struct cvfs_private *p = ntvfs->private_data;
974 struct smbcli_request *c_req;
978 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
979 return smb_raw_fsinfo(p->tree, req, fs);
982 c_req = smb_raw_fsinfo_send(p->tree, req, fs);
984 ASYNC_RECV_TAIL(fs, async_fsinfo);
988 return print queue info
990 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
991 struct ntvfs_request *req, union smb_lpq *lpq)
993 return NT_STATUS_NOT_SUPPORTED;
997 list files in a directory matching a wildcard pattern
999 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
1000 struct ntvfs_request *req, union smb_search_first *io,
1001 void *search_private,
1002 bool (*callback)(void *, const union smb_search_data *))
1004 struct cvfs_private *p = ntvfs->private_data;
1008 return smb_raw_search_first(p->tree, req, io, search_private, callback);
1011 /* continue a search */
1012 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
1013 struct ntvfs_request *req, union smb_search_next *io,
1014 void *search_private,
1015 bool (*callback)(void *, const union smb_search_data *))
1017 struct cvfs_private *p = ntvfs->private_data;
1021 return smb_raw_search_next(p->tree, req, io, search_private, callback);
1024 /* close a search */
1025 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
1026 struct ntvfs_request *req, union smb_search_close *io)
1028 struct cvfs_private *p = ntvfs->private_data;
1032 return smb_raw_search_close(p->tree, io);
1036 a handler for async trans2 replies
1038 static void async_trans2(struct smbcli_request *c_req)
1040 struct async_info *async = c_req->async.private_data;
1041 struct ntvfs_request *req = async->req;
1042 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
1044 req->async_states->send_fn(req);
1048 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
1049 struct ntvfs_request *req,
1050 struct smb_trans2 *trans2)
1052 struct cvfs_private *p = ntvfs->private_data;
1053 struct smbcli_request *c_req;
1055 if (p->map_trans2) {
1056 return NT_STATUS_NOT_IMPLEMENTED;
1061 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1062 return smb_raw_trans2(p->tree, req, trans2);
1065 c_req = smb_raw_trans2_send(p->tree, trans2);
1067 ASYNC_RECV_TAIL(trans2, async_trans2);
1071 /* SMBtrans - not used on file shares */
1072 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
1073 struct ntvfs_request *req,
1074 struct smb_trans2 *trans2)
1076 return NT_STATUS_ACCESS_DENIED;
1080 a handler for async change notify replies
1082 static void async_changenotify(struct smbcli_request *c_req)
1084 struct async_info *async = c_req->async.private_data;
1085 struct ntvfs_request *req = async->req;
1086 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
1088 req->async_states->send_fn(req);
1091 /* change notify request - always async */
1092 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1093 struct ntvfs_request *req,
1094 union smb_notify *io)
1096 struct cvfs_private *p = ntvfs->private_data;
1097 struct smbcli_request *c_req;
1098 int saved_timeout = p->transport->options.request_timeout;
1099 struct cvfs_file *f;
1101 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1102 return NT_STATUS_NOT_IMPLEMENTED;
1107 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1108 if (!f) return NT_STATUS_INVALID_HANDLE;
1109 io->nttrans.in.file.fnum = f->fnum;
1111 /* this request doesn't make sense unless its async */
1112 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1113 return NT_STATUS_INVALID_PARAMETER;
1116 /* we must not timeout on notify requests - they wait
1118 p->transport->options.request_timeout = 0;
1120 c_req = smb_raw_changenotify_send(p->tree, io);
1122 p->transport->options.request_timeout = saved_timeout;
1124 ASYNC_RECV_TAIL(io, async_changenotify);
1128 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1130 NTSTATUS ntvfs_cifs_init(void)
1133 struct ntvfs_ops ops;
1134 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1138 /* fill in the name and type */
1140 ops.type = NTVFS_DISK;
1142 /* fill in all the operations */
1143 ops.connect = cvfs_connect;
1144 ops.disconnect = cvfs_disconnect;
1145 ops.unlink = cvfs_unlink;
1146 ops.chkpath = cvfs_chkpath;
1147 ops.qpathinfo = cvfs_qpathinfo;
1148 ops.setpathinfo = cvfs_setpathinfo;
1149 ops.open = cvfs_open;
1150 ops.mkdir = cvfs_mkdir;
1151 ops.rmdir = cvfs_rmdir;
1152 ops.rename = cvfs_rename;
1153 ops.copy = cvfs_copy;
1154 ops.ioctl = cvfs_ioctl;
1155 ops.read = cvfs_read;
1156 ops.write = cvfs_write;
1157 ops.seek = cvfs_seek;
1158 ops.flush = cvfs_flush;
1159 ops.close = cvfs_close;
1160 ops.exit = cvfs_exit;
1161 ops.lock = cvfs_lock;
1162 ops.setfileinfo = cvfs_setfileinfo;
1163 ops.qfileinfo = cvfs_qfileinfo;
1164 ops.fsinfo = cvfs_fsinfo;
1166 ops.search_first = cvfs_search_first;
1167 ops.search_next = cvfs_search_next;
1168 ops.search_close = cvfs_search_close;
1169 ops.trans = cvfs_trans;
1170 ops.logoff = cvfs_logoff;
1171 ops.async_setup = cvfs_async_setup;
1172 ops.cancel = cvfs_cancel;
1173 ops.notify = cvfs_notify;
1174 ops.trans2 = cvfs_trans2;
1176 /* register ourselves with the NTVFS subsystem. We register
1177 under the name 'cifs'. */
1178 ret = ntvfs_register(&ops, &vers);
1180 if (!NT_STATUS_IS_OK(ret)) {
1181 DEBUG(0,("Failed to register CIFS backend!\n"));