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 2 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, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 this implements a CIFS->CIFS NTVFS filesystem backend.
29 #include "libcli/raw/libcliraw.h"
30 #include "libcli/smb_composite/smb_composite.h"
31 #include "auth/auth.h"
32 #include "ntvfs/ntvfs.h"
33 #include "include/dlinklist.h"
36 struct cvfs_file *prev, *next;
38 struct ntvfs_handle *h;
41 /* this is stored in ntvfs_private */
43 struct smbcli_tree *tree;
44 struct smbcli_transport *transport;
45 struct ntvfs_module_context *ntvfs;
46 struct async_info *pending;
47 struct cvfs_file *files;
53 /* a structure used to pass information to an async handler */
55 struct async_info *next, *prev;
56 struct cvfs_private *cvfs;
57 struct ntvfs_request *req;
58 struct smbcli_request *c_req;
63 #define SETUP_PID private->tree->session->pid = req->smbpid
65 #define SETUP_FILE do { \
66 struct cvfs_file *f; \
67 f = ntvfs_handle_get_backend_data(io->generic.in.file.ntvfs, ntvfs); \
68 if (!f) return NT_STATUS_INVALID_HANDLE; \
69 io->generic.in.file.fnum = f->fnum; \
72 #define SETUP_PID_AND_FILE do { \
78 a handler for oplock break events from the server - these need to be passed
81 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *p_private)
83 struct cvfs_private *private = p_private;
85 struct ntvfs_handle *h = NULL;
88 for (f=private->files; f; f=f->next) {
89 if (f->fnum != fnum) continue;
95 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level, fnum));
99 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level, fnum));
100 status = ntvfs_send_oplock_break(private->ntvfs, h, level);
101 if (!NT_STATUS_IS_OK(status)) return False;
106 connect to a share - used when a tree_connect operation comes in.
108 static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
109 struct ntvfs_request *req, const char *sharename)
112 struct cvfs_private *private;
113 const char *host, *user, *pass, *domain, *remote_share;
114 struct smb_composite_connect io;
115 struct composite_context *creq;
116 int snum = ntvfs->ctx->config.snum;
118 struct cli_credentials *credentials;
119 BOOL machine_account;
121 /* Here we need to determine which server to connect to.
122 * For now we use parametric options, type cifs.
123 * Later we will use security=server and auth_server.c.
125 host = lp_parm_string(snum, "cifs", "server");
126 user = lp_parm_string(snum, "cifs", "user");
127 pass = lp_parm_string(snum, "cifs", "password");
128 domain = lp_parm_string(snum, "cifs", "domain");
129 remote_share = lp_parm_string(snum, "cifs", "share");
131 remote_share = sharename;
134 machine_account = lp_parm_bool(snum, "cifs", "use_machine_account", False);
136 private = talloc_zero(ntvfs, struct cvfs_private);
138 return NT_STATUS_NO_MEMORY;
141 ntvfs->private_data = private;
144 DEBUG(1,("CIFS backend: You must supply server\n"));
145 return NT_STATUS_INVALID_PARAMETER;
149 DEBUG(5, ("CIFS backend: Using specified password\n"));
150 credentials = cli_credentials_init(private);
152 return NT_STATUS_NO_MEMORY;
154 cli_credentials_set_conf(credentials);
155 cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
157 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
159 cli_credentials_set_password(credentials, pass, CRED_SPECIFIED);
160 } else if (machine_account) {
161 DEBUG(5, ("CIFS backend: Using machine account\n"));
162 credentials = cli_credentials_init(private);
163 cli_credentials_set_conf(credentials);
165 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
167 status = cli_credentials_set_machine_account(credentials);
168 if (!NT_STATUS_IS_OK(status)) {
171 } else if (req->session_info->credentials) {
172 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
173 credentials = req->session_info->credentials;
175 DEBUG(1,("CIFS backend: You must supply server, user and password and or have delegated credentials\n"));
176 return NT_STATUS_INVALID_PARAMETER;
179 /* connect to the server, using the smbd event context */
180 io.in.dest_host = host;
182 io.in.called_name = host;
183 io.in.credentials = credentials;
184 io.in.fallback_to_anonymous = False;
185 io.in.workgroup = lp_workgroup();
186 io.in.service = remote_share;
187 io.in.service_type = "?????";
189 creq = smb_composite_connect_send(&io, private, ntvfs->ctx->event_ctx);
190 status = smb_composite_connect_recv(creq, private);
191 NT_STATUS_NOT_OK_RETURN(status);
193 private->tree = io.out.tree;
195 private->transport = private->tree->session->transport;
197 private->ntvfs = ntvfs;
199 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
200 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
201 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
202 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
204 /* we need to receive oplock break requests from the server */
205 smbcli_oplock_handler(private->transport, oplock_handler, private);
207 private->map_generic = lp_parm_bool(ntvfs->ctx->config.snum,
208 "cifs", "mapgeneric", False);
210 private->map_trans2 = lp_parm_bool(ntvfs->ctx->config.snum,
211 "cifs", "maptrans2", True);
217 disconnect from a share
219 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
221 struct cvfs_private *private = ntvfs->private_data;
222 struct async_info *a, *an;
224 /* first cleanup pending requests */
225 for (a=private->pending; a; a = an) {
227 smbcli_request_destroy(a->c_req);
231 talloc_free(private);
232 ntvfs->private_data = NULL;
238 destroy an async info structure
240 static int async_info_destructor(struct async_info *async)
242 DLIST_REMOVE(async->cvfs->pending, async);
247 a handler for simple async replies
248 this handler can only be used for functions that don't return any
249 parameters (those that just return a status code)
251 static void async_simple(struct smbcli_request *c_req)
253 struct async_info *async = c_req->async.private;
254 struct ntvfs_request *req = async->req;
255 req->async_states->status = smbcli_request_simple_recv(c_req);
257 req->async_states->send_fn(req);
261 /* save some typing for the simple functions */
262 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
263 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
265 struct async_info *async; \
266 async = talloc(req, struct async_info); \
267 if (!async) return NT_STATUS_NO_MEMORY; \
271 async->cvfs = private; \
272 async->c_req = c_req; \
273 DLIST_ADD(private->pending, async); \
274 c_req->async.private = async; \
275 talloc_set_destructor(async, async_info_destructor); \
277 c_req->async.fn = async_fn; \
278 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
279 return NT_STATUS_OK; \
282 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
284 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
287 delete a file - the dirtype specifies the file types to include in the search.
288 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
290 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
291 struct ntvfs_request *req, union smb_unlink *unl)
293 struct cvfs_private *private = ntvfs->private_data;
294 struct smbcli_request *c_req;
298 /* see if the front end will allow us to perform this
299 function asynchronously. */
300 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
301 return smb_raw_unlink(private->tree, unl);
304 c_req = smb_raw_unlink_send(private->tree, unl);
310 a handler for async ioctl replies
312 static void async_ioctl(struct smbcli_request *c_req)
314 struct async_info *async = c_req->async.private;
315 struct ntvfs_request *req = async->req;
316 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
318 req->async_states->send_fn(req);
324 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
325 struct ntvfs_request *req, union smb_ioctl *io)
327 struct cvfs_private *private = ntvfs->private_data;
328 struct smbcli_request *c_req;
332 /* see if the front end will allow us to perform this
333 function asynchronously. */
334 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
335 return smb_raw_ioctl(private->tree, req, io);
338 c_req = smb_raw_ioctl_send(private->tree, io);
340 ASYNC_RECV_TAIL(io, async_ioctl);
344 check if a directory exists
346 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
347 struct ntvfs_request *req, union smb_chkpath *cp)
349 struct cvfs_private *private = ntvfs->private_data;
350 struct smbcli_request *c_req;
354 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
355 return smb_raw_chkpath(private->tree, cp);
358 c_req = smb_raw_chkpath_send(private->tree, cp);
364 a handler for async qpathinfo replies
366 static void async_qpathinfo(struct smbcli_request *c_req)
368 struct async_info *async = c_req->async.private;
369 struct ntvfs_request *req = async->req;
370 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
372 req->async_states->send_fn(req);
376 return info on a pathname
378 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
379 struct ntvfs_request *req, union smb_fileinfo *info)
381 struct cvfs_private *private = ntvfs->private_data;
382 struct smbcli_request *c_req;
386 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
387 return smb_raw_pathinfo(private->tree, req, info);
390 c_req = smb_raw_pathinfo_send(private->tree, info);
392 ASYNC_RECV_TAIL(info, async_qpathinfo);
396 a handler for async qfileinfo replies
398 static void async_qfileinfo(struct smbcli_request *c_req)
400 struct async_info *async = c_req->async.private;
401 struct ntvfs_request *req = async->req;
402 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
404 req->async_states->send_fn(req);
408 query info on a open file
410 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
411 struct ntvfs_request *req, union smb_fileinfo *io)
413 struct cvfs_private *private = ntvfs->private_data;
414 struct smbcli_request *c_req;
418 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
419 return smb_raw_fileinfo(private->tree, req, io);
422 c_req = smb_raw_fileinfo_send(private->tree, io);
424 ASYNC_RECV_TAIL(io, async_qfileinfo);
429 set info on a pathname
431 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
432 struct ntvfs_request *req, union smb_setfileinfo *st)
434 struct cvfs_private *private = ntvfs->private_data;
435 struct smbcli_request *c_req;
439 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
440 return smb_raw_setpathinfo(private->tree, st);
443 c_req = smb_raw_setpathinfo_send(private->tree, st);
450 a handler for async open replies
452 static void async_open(struct smbcli_request *c_req)
454 struct async_info *async = c_req->async.private;
455 struct cvfs_private *cvfs = async->cvfs;
456 struct ntvfs_request *req = async->req;
457 struct cvfs_file *f = async->f;
458 union smb_open *io = async->parms;
459 union smb_handle *file;
461 req->async_states->status = smb_raw_open_recv(c_req, req, io);
462 SMB_OPEN_OUT_FILE(io, file);
463 f->fnum = file->fnum;
465 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
466 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
467 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
470 req->async_states->send_fn(req);
476 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
477 struct ntvfs_request *req, union smb_open *io)
479 struct cvfs_private *private = ntvfs->private_data;
480 struct smbcli_request *c_req;
481 struct ntvfs_handle *h;
487 if (io->generic.level != RAW_OPEN_GENERIC &&
488 private->map_generic) {
489 return ntvfs_map_open(ntvfs, req, io);
492 status = ntvfs_handle_new(ntvfs, req, &h);
493 NT_STATUS_NOT_OK_RETURN(status);
495 f = talloc_zero(h, struct cvfs_file);
496 NT_STATUS_HAVE_NO_MEMORY(f);
499 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
500 union smb_handle *file;
502 status = smb_raw_open(private->tree, req, io);
503 NT_STATUS_NOT_OK_RETURN(status);
505 SMB_OPEN_OUT_FILE(io, file);
506 f->fnum = file->fnum;
508 status = ntvfs_handle_set_backend_data(f->h, private->ntvfs, f);
509 NT_STATUS_NOT_OK_RETURN(status);
515 c_req = smb_raw_open_send(private->tree, io);
517 ASYNC_RECV_TAIL_F(io, async_open, f);
523 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
524 struct ntvfs_request *req, union smb_mkdir *md)
526 struct cvfs_private *private = ntvfs->private_data;
527 struct smbcli_request *c_req;
531 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
532 return smb_raw_mkdir(private->tree, md);
535 c_req = smb_raw_mkdir_send(private->tree, md);
543 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
544 struct ntvfs_request *req, struct smb_rmdir *rd)
546 struct cvfs_private *private = ntvfs->private_data;
547 struct smbcli_request *c_req;
551 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
552 return smb_raw_rmdir(private->tree, rd);
554 c_req = smb_raw_rmdir_send(private->tree, rd);
560 rename a set of files
562 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
563 struct ntvfs_request *req, union smb_rename *ren)
565 struct cvfs_private *private = ntvfs->private_data;
566 struct smbcli_request *c_req;
570 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
571 return smb_raw_rename(private->tree, ren);
574 c_req = smb_raw_rename_send(private->tree, ren);
582 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
583 struct ntvfs_request *req, struct smb_copy *cp)
585 return NT_STATUS_NOT_SUPPORTED;
589 a handler for async read replies
591 static void async_read(struct smbcli_request *c_req)
593 struct async_info *async = c_req->async.private;
594 struct ntvfs_request *req = async->req;
595 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
597 req->async_states->send_fn(req);
603 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
604 struct ntvfs_request *req, union smb_read *io)
606 struct cvfs_private *private = ntvfs->private_data;
607 struct smbcli_request *c_req;
611 if (io->generic.level != RAW_READ_GENERIC &&
612 private->map_generic) {
613 return ntvfs_map_read(ntvfs, req, io);
618 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
619 return smb_raw_read(private->tree, io);
622 c_req = smb_raw_read_send(private->tree, io);
624 ASYNC_RECV_TAIL(io, async_read);
628 a handler for async write replies
630 static void async_write(struct smbcli_request *c_req)
632 struct async_info *async = c_req->async.private;
633 struct ntvfs_request *req = async->req;
634 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
636 req->async_states->send_fn(req);
642 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
643 struct ntvfs_request *req, union smb_write *io)
645 struct cvfs_private *private = ntvfs->private_data;
646 struct smbcli_request *c_req;
650 if (io->generic.level != RAW_WRITE_GENERIC &&
651 private->map_generic) {
652 return ntvfs_map_write(ntvfs, req, io);
656 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
657 return smb_raw_write(private->tree, io);
660 c_req = smb_raw_write_send(private->tree, io);
662 ASYNC_RECV_TAIL(io, async_write);
666 a handler for async seek replies
668 static void async_seek(struct smbcli_request *c_req)
670 struct async_info *async = c_req->async.private;
671 struct ntvfs_request *req = async->req;
672 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
674 req->async_states->send_fn(req);
680 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
681 struct ntvfs_request *req,
684 struct cvfs_private *private = ntvfs->private_data;
685 struct smbcli_request *c_req;
689 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
690 return smb_raw_seek(private->tree, io);
693 c_req = smb_raw_seek_send(private->tree, io);
695 ASYNC_RECV_TAIL(io, async_seek);
701 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
702 struct ntvfs_request *req,
705 struct cvfs_private *private = ntvfs->private_data;
706 struct smbcli_request *c_req;
709 switch (io->generic.level) {
710 case RAW_FLUSH_FLUSH:
714 io->generic.in.file.fnum = 0xFFFF;
717 return NT_STATUS_INVALID_LEVEL;
720 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
721 return smb_raw_flush(private->tree, io);
724 c_req = smb_raw_flush_send(private->tree, io);
732 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
733 struct ntvfs_request *req, union smb_close *io)
735 struct cvfs_private *private = ntvfs->private_data;
736 struct smbcli_request *c_req;
740 if (io->generic.level != RAW_CLOSE_GENERIC &&
741 private->map_generic) {
742 return ntvfs_map_close(ntvfs, req, io);
746 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
747 return smb_raw_close(private->tree, io);
750 c_req = smb_raw_close_send(private->tree, io);
756 exit - closing files open by the pid
758 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
759 struct ntvfs_request *req)
761 struct cvfs_private *private = ntvfs->private_data;
762 struct smbcli_request *c_req;
766 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
767 return smb_raw_exit(private->tree->session);
770 c_req = smb_raw_exit_send(private->tree->session);
776 logoff - closing files open by the user
778 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
779 struct ntvfs_request *req)
781 /* we can't do this right in the cifs backend .... */
786 setup for an async call - nothing to do yet
788 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
789 struct ntvfs_request *req,
798 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
799 struct ntvfs_request *req)
801 struct cvfs_private *private = ntvfs->private_data;
802 struct async_info *a;
804 /* find the matching request */
805 for (a=private->pending;a;a=a->next) {
812 return NT_STATUS_INVALID_PARAMETER;
815 return smb_raw_ntcancel(a->c_req);
821 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
822 struct ntvfs_request *req, union smb_lock *io)
824 struct cvfs_private *private = ntvfs->private_data;
825 struct smbcli_request *c_req;
829 if (io->generic.level != RAW_LOCK_GENERIC &&
830 private->map_generic) {
831 return ntvfs_map_lock(ntvfs, req, io);
835 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
836 return smb_raw_lock(private->tree, io);
839 c_req = smb_raw_lock_send(private->tree, io);
844 set info on a open file
846 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
847 struct ntvfs_request *req,
848 union smb_setfileinfo *io)
850 struct cvfs_private *private = ntvfs->private_data;
851 struct smbcli_request *c_req;
855 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
856 return smb_raw_setfileinfo(private->tree, io);
858 c_req = smb_raw_setfileinfo_send(private->tree, io);
865 a handler for async fsinfo replies
867 static void async_fsinfo(struct smbcli_request *c_req)
869 struct async_info *async = c_req->async.private;
870 struct ntvfs_request *req = async->req;
871 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
873 req->async_states->send_fn(req);
877 return filesystem space info
879 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
880 struct ntvfs_request *req, union smb_fsinfo *fs)
882 struct cvfs_private *private = ntvfs->private_data;
883 struct smbcli_request *c_req;
887 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
888 return smb_raw_fsinfo(private->tree, req, fs);
891 c_req = smb_raw_fsinfo_send(private->tree, req, fs);
893 ASYNC_RECV_TAIL(fs, async_fsinfo);
897 return print queue info
899 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
900 struct ntvfs_request *req, union smb_lpq *lpq)
902 return NT_STATUS_NOT_SUPPORTED;
906 list files in a directory matching a wildcard pattern
908 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
909 struct ntvfs_request *req, union smb_search_first *io,
910 void *search_private,
911 BOOL (*callback)(void *, union smb_search_data *))
913 struct cvfs_private *private = ntvfs->private_data;
917 return smb_raw_search_first(private->tree, req, io, search_private, callback);
920 /* continue a search */
921 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
922 struct ntvfs_request *req, union smb_search_next *io,
923 void *search_private,
924 BOOL (*callback)(void *, union smb_search_data *))
926 struct cvfs_private *private = ntvfs->private_data;
930 return smb_raw_search_next(private->tree, req, io, search_private, callback);
934 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
935 struct ntvfs_request *req, union smb_search_close *io)
937 struct cvfs_private *private = ntvfs->private_data;
941 return smb_raw_search_close(private->tree, io);
945 a handler for async trans2 replies
947 static void async_trans2(struct smbcli_request *c_req)
949 struct async_info *async = c_req->async.private;
950 struct ntvfs_request *req = async->req;
951 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
953 req->async_states->send_fn(req);
957 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
958 struct ntvfs_request *req,
959 struct smb_trans2 *trans2)
961 struct cvfs_private *private = ntvfs->private_data;
962 struct smbcli_request *c_req;
964 if (private->map_trans2) {
965 return NT_STATUS_NOT_IMPLEMENTED;
970 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
971 return smb_raw_trans2(private->tree, req, trans2);
974 c_req = smb_raw_trans2_send(private->tree, trans2);
976 ASYNC_RECV_TAIL(trans2, async_trans2);
980 /* SMBtrans - not used on file shares */
981 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
982 struct ntvfs_request *req,
983 struct smb_trans2 *trans2)
985 return NT_STATUS_ACCESS_DENIED;
989 a handler for async change notify replies
991 static void async_changenotify(struct smbcli_request *c_req)
993 struct async_info *async = c_req->async.private;
994 struct ntvfs_request *req = async->req;
995 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
997 req->async_states->send_fn(req);
1000 /* change notify request - always async */
1001 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1002 struct ntvfs_request *req,
1003 union smb_notify *io)
1005 struct cvfs_private *private = ntvfs->private_data;
1006 struct smbcli_request *c_req;
1007 int saved_timeout = private->transport->options.request_timeout;
1008 struct cvfs_file *f;
1010 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1011 return NT_STATUS_NOT_IMPLEMENTED;
1016 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1017 if (!f) return NT_STATUS_INVALID_HANDLE;
1018 io->nttrans.in.file.fnum = f->fnum;
1020 /* this request doesn't make sense unless its async */
1021 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1022 return NT_STATUS_INVALID_PARAMETER;
1025 /* we must not timeout on notify requests - they wait
1027 private->transport->options.request_timeout = 0;
1029 c_req = smb_raw_changenotify_send(private->tree, io);
1031 private->transport->options.request_timeout = saved_timeout;
1033 ASYNC_RECV_TAIL(io, async_changenotify);
1037 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1039 NTSTATUS ntvfs_cifs_init(void)
1042 struct ntvfs_ops ops;
1043 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1047 /* fill in the name and type */
1049 ops.type = NTVFS_DISK;
1051 /* fill in all the operations */
1052 ops.connect = cvfs_connect;
1053 ops.disconnect = cvfs_disconnect;
1054 ops.unlink = cvfs_unlink;
1055 ops.chkpath = cvfs_chkpath;
1056 ops.qpathinfo = cvfs_qpathinfo;
1057 ops.setpathinfo = cvfs_setpathinfo;
1058 ops.open = cvfs_open;
1059 ops.mkdir = cvfs_mkdir;
1060 ops.rmdir = cvfs_rmdir;
1061 ops.rename = cvfs_rename;
1062 ops.copy = cvfs_copy;
1063 ops.ioctl = cvfs_ioctl;
1064 ops.read = cvfs_read;
1065 ops.write = cvfs_write;
1066 ops.seek = cvfs_seek;
1067 ops.flush = cvfs_flush;
1068 ops.close = cvfs_close;
1069 ops.exit = cvfs_exit;
1070 ops.lock = cvfs_lock;
1071 ops.setfileinfo = cvfs_setfileinfo;
1072 ops.qfileinfo = cvfs_qfileinfo;
1073 ops.fsinfo = cvfs_fsinfo;
1075 ops.search_first = cvfs_search_first;
1076 ops.search_next = cvfs_search_next;
1077 ops.search_close = cvfs_search_close;
1078 ops.trans = cvfs_trans;
1079 ops.logoff = cvfs_logoff;
1080 ops.async_setup = cvfs_async_setup;
1081 ops.cancel = cvfs_cancel;
1082 ops.notify = cvfs_notify;
1083 ops.trans2 = cvfs_trans2;
1085 /* register ourselves with the NTVFS subsystem. We register
1086 under the name 'cifs'. */
1087 ret = ntvfs_register(&ops, &vers);
1089 if (!NT_STATUS_IS_OK(ret)) {
1090 DEBUG(0,("Failed to register CIFS backend!\n"));