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.iconv_convenience = lp_iconv_convenience(ntvfs->ctx->lp_ctx);
243 io.in.gensec_settings = lp_gensec_settings(p, ntvfs->ctx->lp_ctx);
244 lp_smbcli_options(ntvfs->ctx->lp_ctx, &io.in.options);
245 lp_smbcli_session_options(ntvfs->ctx->lp_ctx, &io.in.session_options);
247 if (!(ntvfs->ctx->client_caps & NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS)) {
248 io.in.options.use_level2_oplocks = false;
251 creq = smb_composite_connect_send(&io, p,
252 lp_resolve_context(ntvfs->ctx->lp_ctx),
253 ntvfs->ctx->event_ctx);
254 status = smb_composite_connect_recv(creq, p);
255 NT_STATUS_NOT_OK_RETURN(status);
257 p->tree = io.out.tree;
259 p->transport = p->tree->session->transport;
263 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
264 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
265 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
266 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
268 if (tcon->generic.level == RAW_TCON_TCONX) {
269 tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
270 tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
273 /* we need to receive oplock break requests from the server */
274 smbcli_oplock_handler(p->transport, oplock_handler, p);
276 p->map_generic = share_bool_option(scfg, CIFS_MAP_GENERIC, CIFS_MAP_GENERIC_DEFAULT);
278 p->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
284 disconnect from a share
286 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
288 struct cvfs_private *p = ntvfs->private_data;
289 struct async_info *a, *an;
291 /* first cleanup pending requests */
292 for (a=p->pending; a; a = an) {
294 smbcli_request_destroy(a->c_req);
299 ntvfs->private_data = NULL;
305 destroy an async info structure
307 static int async_info_destructor(struct async_info *async)
309 DLIST_REMOVE(async->cvfs->pending, async);
314 a handler for simple async replies
315 this handler can only be used for functions that don't return any
316 parameters (those that just return a status code)
318 static void async_simple(struct smbcli_request *c_req)
320 struct async_info *async = c_req->async.private_data;
321 struct ntvfs_request *req = async->req;
322 req->async_states->status = smbcli_request_simple_recv(c_req);
324 req->async_states->send_fn(req);
328 /* save some typing for the simple functions */
329 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
330 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
332 struct async_info *async; \
333 async = talloc(req, struct async_info); \
334 if (!async) return NT_STATUS_NO_MEMORY; \
339 async->c_req = c_req; \
340 DLIST_ADD(p->pending, async); \
341 c_req->async.private_data = async; \
342 talloc_set_destructor(async, async_info_destructor); \
344 c_req->async.fn = async_fn; \
345 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
346 return NT_STATUS_OK; \
349 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
351 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
354 delete a file - the dirtype specifies the file types to include in the search.
355 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
357 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
358 struct ntvfs_request *req, union smb_unlink *unl)
360 struct cvfs_private *p = ntvfs->private_data;
361 struct smbcli_request *c_req;
365 /* see if the front end will allow us to perform this
366 function asynchronously. */
367 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
368 return smb_raw_unlink(p->tree, unl);
371 c_req = smb_raw_unlink_send(p->tree, unl);
377 a handler for async ioctl replies
379 static void async_ioctl(struct smbcli_request *c_req)
381 struct async_info *async = c_req->async.private_data;
382 struct ntvfs_request *req = async->req;
383 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
385 req->async_states->send_fn(req);
391 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
392 struct ntvfs_request *req, union smb_ioctl *io)
394 struct cvfs_private *p = ntvfs->private_data;
395 struct smbcli_request *c_req;
399 /* see if the front end will allow us to perform this
400 function asynchronously. */
401 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
402 return smb_raw_ioctl(p->tree, req, io);
405 c_req = smb_raw_ioctl_send(p->tree, io);
407 ASYNC_RECV_TAIL(io, async_ioctl);
411 check if a directory exists
413 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
414 struct ntvfs_request *req, union smb_chkpath *cp)
416 struct cvfs_private *p = ntvfs->private_data;
417 struct smbcli_request *c_req;
421 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
422 return smb_raw_chkpath(p->tree, cp);
425 c_req = smb_raw_chkpath_send(p->tree, cp);
431 a handler for async qpathinfo replies
433 static void async_qpathinfo(struct smbcli_request *c_req)
435 struct async_info *async = c_req->async.private_data;
436 struct ntvfs_request *req = async->req;
437 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
439 req->async_states->send_fn(req);
443 return info on a pathname
445 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
446 struct ntvfs_request *req, union smb_fileinfo *info)
448 struct cvfs_private *p = ntvfs->private_data;
449 struct smbcli_request *c_req;
453 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
454 return smb_raw_pathinfo(p->tree, req, info);
457 c_req = smb_raw_pathinfo_send(p->tree, info);
459 ASYNC_RECV_TAIL(info, async_qpathinfo);
463 a handler for async qfileinfo replies
465 static void async_qfileinfo(struct smbcli_request *c_req)
467 struct async_info *async = c_req->async.private_data;
468 struct ntvfs_request *req = async->req;
469 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
471 req->async_states->send_fn(req);
475 query info on a open file
477 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
478 struct ntvfs_request *req, union smb_fileinfo *io)
480 struct cvfs_private *p = ntvfs->private_data;
481 struct smbcli_request *c_req;
485 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
486 return smb_raw_fileinfo(p->tree, req, io);
489 c_req = smb_raw_fileinfo_send(p->tree, io);
491 ASYNC_RECV_TAIL(io, async_qfileinfo);
496 set info on a pathname
498 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
499 struct ntvfs_request *req, union smb_setfileinfo *st)
501 struct cvfs_private *p = ntvfs->private_data;
502 struct smbcli_request *c_req;
506 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
507 return smb_raw_setpathinfo(p->tree, st);
510 c_req = smb_raw_setpathinfo_send(p->tree, st);
517 a handler for async open replies
519 static void async_open(struct smbcli_request *c_req)
521 struct async_info *async = c_req->async.private_data;
522 struct cvfs_private *cvfs = async->cvfs;
523 struct ntvfs_request *req = async->req;
524 struct cvfs_file *f = async->f;
525 union smb_open *io = async->parms;
526 union smb_handle *file;
528 req->async_states->status = smb_raw_open_recv(c_req, req, io);
529 SMB_OPEN_OUT_FILE(io, file);
530 f->fnum = file->fnum;
532 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
533 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
534 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
536 DLIST_ADD(cvfs->files, f);
538 req->async_states->send_fn(req);
544 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
545 struct ntvfs_request *req, union smb_open *io)
547 struct cvfs_private *p = ntvfs->private_data;
548 struct smbcli_request *c_req;
549 struct ntvfs_handle *h;
555 if (io->generic.level != RAW_OPEN_GENERIC &&
557 return ntvfs_map_open(ntvfs, req, io);
560 status = ntvfs_handle_new(ntvfs, req, &h);
561 NT_STATUS_NOT_OK_RETURN(status);
563 f = talloc_zero(h, struct cvfs_file);
564 NT_STATUS_HAVE_NO_MEMORY(f);
567 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
568 union smb_handle *file;
570 status = smb_raw_open(p->tree, req, io);
571 NT_STATUS_NOT_OK_RETURN(status);
573 SMB_OPEN_OUT_FILE(io, file);
574 f->fnum = file->fnum;
576 status = ntvfs_handle_set_backend_data(f->h, p->ntvfs, f);
577 NT_STATUS_NOT_OK_RETURN(status);
579 DLIST_ADD(p->files, f);
584 c_req = smb_raw_open_send(p->tree, io);
586 ASYNC_RECV_TAIL_F(io, async_open, f);
592 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
593 struct ntvfs_request *req, union smb_mkdir *md)
595 struct cvfs_private *p = ntvfs->private_data;
596 struct smbcli_request *c_req;
600 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
601 return smb_raw_mkdir(p->tree, md);
604 c_req = smb_raw_mkdir_send(p->tree, md);
612 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
613 struct ntvfs_request *req, struct smb_rmdir *rd)
615 struct cvfs_private *p = ntvfs->private_data;
616 struct smbcli_request *c_req;
620 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
621 return smb_raw_rmdir(p->tree, rd);
623 c_req = smb_raw_rmdir_send(p->tree, rd);
629 rename a set of files
631 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
632 struct ntvfs_request *req, union smb_rename *ren)
634 struct cvfs_private *p = ntvfs->private_data;
635 struct smbcli_request *c_req;
639 if (ren->nttrans.level == RAW_RENAME_NTTRANS) {
641 f = ntvfs_handle_get_backend_data(ren->nttrans.in.file.ntvfs, ntvfs);
642 if (!f) return NT_STATUS_INVALID_HANDLE;
643 ren->nttrans.in.file.fnum = f->fnum;
646 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
647 return smb_raw_rename(p->tree, ren);
650 c_req = smb_raw_rename_send(p->tree, ren);
658 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
659 struct ntvfs_request *req, struct smb_copy *cp)
661 return NT_STATUS_NOT_SUPPORTED;
665 a handler for async read replies
667 static void async_read(struct smbcli_request *c_req)
669 struct async_info *async = c_req->async.private_data;
670 struct ntvfs_request *req = async->req;
671 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
673 req->async_states->send_fn(req);
679 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
680 struct ntvfs_request *req, union smb_read *io)
682 struct cvfs_private *p = ntvfs->private_data;
683 struct smbcli_request *c_req;
687 if (io->generic.level != RAW_READ_GENERIC &&
689 return ntvfs_map_read(ntvfs, req, io);
694 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
695 return smb_raw_read(p->tree, io);
698 c_req = smb_raw_read_send(p->tree, io);
700 ASYNC_RECV_TAIL(io, async_read);
704 a handler for async write replies
706 static void async_write(struct smbcli_request *c_req)
708 struct async_info *async = c_req->async.private_data;
709 struct ntvfs_request *req = async->req;
710 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
712 req->async_states->send_fn(req);
718 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
719 struct ntvfs_request *req, union smb_write *io)
721 struct cvfs_private *p = ntvfs->private_data;
722 struct smbcli_request *c_req;
726 if (io->generic.level != RAW_WRITE_GENERIC &&
728 return ntvfs_map_write(ntvfs, req, io);
732 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
733 return smb_raw_write(p->tree, io);
736 c_req = smb_raw_write_send(p->tree, io);
738 ASYNC_RECV_TAIL(io, async_write);
742 a handler for async seek replies
744 static void async_seek(struct smbcli_request *c_req)
746 struct async_info *async = c_req->async.private_data;
747 struct ntvfs_request *req = async->req;
748 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
750 req->async_states->send_fn(req);
756 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
757 struct ntvfs_request *req,
760 struct cvfs_private *p = ntvfs->private_data;
761 struct smbcli_request *c_req;
765 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
766 return smb_raw_seek(p->tree, io);
769 c_req = smb_raw_seek_send(p->tree, io);
771 ASYNC_RECV_TAIL(io, async_seek);
777 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
778 struct ntvfs_request *req,
781 struct cvfs_private *p = ntvfs->private_data;
782 struct smbcli_request *c_req;
785 switch (io->generic.level) {
786 case RAW_FLUSH_FLUSH:
790 io->generic.in.file.fnum = 0xFFFF;
793 return NT_STATUS_INVALID_LEVEL;
796 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
797 return smb_raw_flush(p->tree, io);
800 c_req = smb_raw_flush_send(p->tree, io);
808 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
809 struct ntvfs_request *req, union smb_close *io)
811 struct cvfs_private *p = ntvfs->private_data;
812 struct smbcli_request *c_req;
818 if (io->generic.level != RAW_CLOSE_GENERIC &&
820 return ntvfs_map_close(ntvfs, req, io);
823 if (io->generic.level == RAW_CLOSE_GENERIC) {
825 io2.close.level = RAW_CLOSE_CLOSE;
826 io2.close.in.file = io->generic.in.file;
827 io2.close.in.write_time = io->generic.in.write_time;
832 /* Note, we aren't free-ing f, or it's h here. Should we?
833 even if file-close fails, we'll remove it from the list,
834 what else would we do? Maybe we should not remove until
835 after the proxied call completes? */
836 DLIST_REMOVE(p->files, f);
838 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
839 return smb_raw_close(p->tree, io);
842 c_req = smb_raw_close_send(p->tree, io);
848 exit - closing files open by the pid
850 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
851 struct ntvfs_request *req)
853 struct cvfs_private *p = ntvfs->private_data;
854 struct smbcli_request *c_req;
858 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
859 return smb_raw_exit(p->tree->session);
862 c_req = smb_raw_exit_send(p->tree->session);
868 logoff - closing files open by the user
870 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
871 struct ntvfs_request *req)
873 /* we can't do this right in the cifs backend .... */
878 setup for an async call - nothing to do yet
880 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
881 struct ntvfs_request *req,
890 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
891 struct ntvfs_request *req)
893 struct cvfs_private *p = ntvfs->private_data;
894 struct async_info *a;
896 /* find the matching request */
897 for (a=p->pending;a;a=a->next) {
904 return NT_STATUS_INVALID_PARAMETER;
907 return smb_raw_ntcancel(a->c_req);
913 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
914 struct ntvfs_request *req, union smb_lock *io)
916 struct cvfs_private *p = ntvfs->private_data;
917 struct smbcli_request *c_req;
921 if (io->generic.level != RAW_LOCK_GENERIC &&
923 return ntvfs_map_lock(ntvfs, req, io);
927 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
928 return smb_raw_lock(p->tree, io);
931 c_req = smb_raw_lock_send(p->tree, io);
936 set info on a open file
938 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
939 struct ntvfs_request *req,
940 union smb_setfileinfo *io)
942 struct cvfs_private *p = ntvfs->private_data;
943 struct smbcli_request *c_req;
947 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
948 return smb_raw_setfileinfo(p->tree, io);
950 c_req = smb_raw_setfileinfo_send(p->tree, io);
957 a handler for async fsinfo replies
959 static void async_fsinfo(struct smbcli_request *c_req)
961 struct async_info *async = c_req->async.private_data;
962 struct ntvfs_request *req = async->req;
963 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
965 req->async_states->send_fn(req);
969 return filesystem space info
971 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
972 struct ntvfs_request *req, union smb_fsinfo *fs)
974 struct cvfs_private *p = ntvfs->private_data;
975 struct smbcli_request *c_req;
979 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
980 return smb_raw_fsinfo(p->tree, req, fs);
983 c_req = smb_raw_fsinfo_send(p->tree, req, fs);
985 ASYNC_RECV_TAIL(fs, async_fsinfo);
989 return print queue info
991 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
992 struct ntvfs_request *req, union smb_lpq *lpq)
994 return NT_STATUS_NOT_SUPPORTED;
998 list files in a directory matching a wildcard pattern
1000 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
1001 struct ntvfs_request *req, union smb_search_first *io,
1002 void *search_private,
1003 bool (*callback)(void *, const union smb_search_data *))
1005 struct cvfs_private *p = ntvfs->private_data;
1009 return smb_raw_search_first(p->tree, req, io, search_private, callback);
1012 /* continue a search */
1013 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
1014 struct ntvfs_request *req, union smb_search_next *io,
1015 void *search_private,
1016 bool (*callback)(void *, const union smb_search_data *))
1018 struct cvfs_private *p = ntvfs->private_data;
1022 return smb_raw_search_next(p->tree, req, io, search_private, callback);
1025 /* close a search */
1026 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
1027 struct ntvfs_request *req, union smb_search_close *io)
1029 struct cvfs_private *p = ntvfs->private_data;
1033 return smb_raw_search_close(p->tree, io);
1037 a handler for async trans2 replies
1039 static void async_trans2(struct smbcli_request *c_req)
1041 struct async_info *async = c_req->async.private_data;
1042 struct ntvfs_request *req = async->req;
1043 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
1045 req->async_states->send_fn(req);
1049 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
1050 struct ntvfs_request *req,
1051 struct smb_trans2 *trans2)
1053 struct cvfs_private *p = ntvfs->private_data;
1054 struct smbcli_request *c_req;
1056 if (p->map_trans2) {
1057 return NT_STATUS_NOT_IMPLEMENTED;
1062 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1063 return smb_raw_trans2(p->tree, req, trans2);
1066 c_req = smb_raw_trans2_send(p->tree, trans2);
1068 ASYNC_RECV_TAIL(trans2, async_trans2);
1072 /* SMBtrans - not used on file shares */
1073 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
1074 struct ntvfs_request *req,
1075 struct smb_trans2 *trans2)
1077 return NT_STATUS_ACCESS_DENIED;
1081 a handler for async change notify replies
1083 static void async_changenotify(struct smbcli_request *c_req)
1085 struct async_info *async = c_req->async.private_data;
1086 struct ntvfs_request *req = async->req;
1087 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
1089 req->async_states->send_fn(req);
1092 /* change notify request - always async */
1093 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1094 struct ntvfs_request *req,
1095 union smb_notify *io)
1097 struct cvfs_private *p = ntvfs->private_data;
1098 struct smbcli_request *c_req;
1099 int saved_timeout = p->transport->options.request_timeout;
1100 struct cvfs_file *f;
1102 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1103 return NT_STATUS_NOT_IMPLEMENTED;
1108 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1109 if (!f) return NT_STATUS_INVALID_HANDLE;
1110 io->nttrans.in.file.fnum = f->fnum;
1112 /* this request doesn't make sense unless its async */
1113 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1114 return NT_STATUS_INVALID_PARAMETER;
1117 /* we must not timeout on notify requests - they wait
1119 p->transport->options.request_timeout = 0;
1121 c_req = smb_raw_changenotify_send(p->tree, io);
1123 p->transport->options.request_timeout = saved_timeout;
1125 ASYNC_RECV_TAIL(io, async_changenotify);
1129 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1131 NTSTATUS ntvfs_cifs_init(void)
1134 struct ntvfs_ops ops;
1135 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1139 /* fill in the name and type */
1141 ops.type = NTVFS_DISK;
1143 /* fill in all the operations */
1144 ops.connect = cvfs_connect;
1145 ops.disconnect = cvfs_disconnect;
1146 ops.unlink = cvfs_unlink;
1147 ops.chkpath = cvfs_chkpath;
1148 ops.qpathinfo = cvfs_qpathinfo;
1149 ops.setpathinfo = cvfs_setpathinfo;
1150 ops.open = cvfs_open;
1151 ops.mkdir = cvfs_mkdir;
1152 ops.rmdir = cvfs_rmdir;
1153 ops.rename = cvfs_rename;
1154 ops.copy = cvfs_copy;
1155 ops.ioctl = cvfs_ioctl;
1156 ops.read = cvfs_read;
1157 ops.write = cvfs_write;
1158 ops.seek = cvfs_seek;
1159 ops.flush = cvfs_flush;
1160 ops.close = cvfs_close;
1161 ops.exit = cvfs_exit;
1162 ops.lock = cvfs_lock;
1163 ops.setfileinfo = cvfs_setfileinfo;
1164 ops.qfileinfo = cvfs_qfileinfo;
1165 ops.fsinfo = cvfs_fsinfo;
1167 ops.search_first = cvfs_search_first;
1168 ops.search_next = cvfs_search_next;
1169 ops.search_close = cvfs_search_close;
1170 ops.trans = cvfs_trans;
1171 ops.logoff = cvfs_logoff;
1172 ops.async_setup = cvfs_async_setup;
1173 ops.cancel = cvfs_cancel;
1174 ops.notify = cvfs_notify;
1175 ops.trans2 = cvfs_trans2;
1177 /* register ourselves with the NTVFS subsystem. We register
1178 under the name 'cifs'. */
1179 ret = ntvfs_register(&ops, &vers);
1181 if (!NT_STATUS_IS_OK(ret)) {
1182 DEBUG(0,("Failed to register CIFS backend!\n"));