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 "lib/util/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 { \
77 #define CIFS_SERVER "cifs:server"
78 #define CIFS_USER "cifs:user"
79 #define CIFS_PASSWORD "cifs:password"
80 #define CIFS_DOMAIN "cifs:domain"
81 #define CIFS_SHARE "cifs:share"
82 #define CIFS_USE_MACHINE_ACCT "cifs:use-machine-account"
83 #define CIFS_MAP_GENERIC "cifs:map-generic"
84 #define CIFS_MAP_TRANS2 "cifs:map-trans2"
86 #define CIFS_USE_MACHINE_ACCT_DEFAULT False
87 #define CIFS_MAP_GENERIC_DEFAULT False
88 #define CIFS_MAP_TRANS2_DEFAULT True
91 a handler for oplock break events from the server - these need to be passed
94 static BOOL oplock_handler(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *p_private)
96 struct cvfs_private *private = p_private;
98 struct ntvfs_handle *h = NULL;
101 for (f=private->files; f; f=f->next) {
102 if (f->fnum != fnum) continue;
108 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level, fnum));
112 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level, fnum));
113 status = ntvfs_send_oplock_break(private->ntvfs, h, level);
114 if (!NT_STATUS_IS_OK(status)) return False;
119 connect to a share - used when a tree_connect operation comes in.
121 static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs,
122 struct ntvfs_request *req, const char *sharename)
125 struct cvfs_private *private;
126 const char *host, *user, *pass, *domain, *remote_share;
127 struct smb_composite_connect io;
128 struct composite_context *creq;
129 struct share_config *scfg = ntvfs->ctx->config;
131 struct cli_credentials *credentials;
132 BOOL machine_account;
134 /* Here we need to determine which server to connect to.
135 * For now we use parametric options, type cifs.
136 * Later we will use security=server and auth_server.c.
138 host = share_string_option(scfg, CIFS_SERVER, NULL);
139 user = share_string_option(scfg, CIFS_USER, NULL);
140 pass = share_string_option(scfg, CIFS_PASSWORD, NULL);
141 domain = share_string_option(scfg, CIFS_DOMAIN, NULL);
142 remote_share = share_string_option(scfg, CIFS_SHARE, NULL);
144 remote_share = sharename;
147 machine_account = share_bool_option(scfg, CIFS_USE_MACHINE_ACCT, CIFS_USE_MACHINE_ACCT_DEFAULT);
149 private = talloc_zero(ntvfs, struct cvfs_private);
151 return NT_STATUS_NO_MEMORY;
154 ntvfs->private_data = private;
157 DEBUG(1,("CIFS backend: You must supply server\n"));
158 return NT_STATUS_INVALID_PARAMETER;
162 DEBUG(5, ("CIFS backend: Using specified password\n"));
163 credentials = cli_credentials_init(private);
165 return NT_STATUS_NO_MEMORY;
167 cli_credentials_set_conf(credentials);
168 cli_credentials_set_username(credentials, user, CRED_SPECIFIED);
170 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
172 cli_credentials_set_password(credentials, pass, CRED_SPECIFIED);
173 } else if (machine_account) {
174 DEBUG(5, ("CIFS backend: Using machine account\n"));
175 credentials = cli_credentials_init(private);
176 cli_credentials_set_conf(credentials);
178 cli_credentials_set_domain(credentials, domain, CRED_SPECIFIED);
180 status = cli_credentials_set_machine_account(credentials);
181 if (!NT_STATUS_IS_OK(status)) {
184 } else if (req->session_info->credentials) {
185 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
186 credentials = req->session_info->credentials;
188 DEBUG(1,("CIFS backend: You must supply server, user and password and or have delegated credentials\n"));
189 return NT_STATUS_INVALID_PARAMETER;
192 /* connect to the server, using the smbd event context */
193 io.in.dest_host = host;
195 io.in.called_name = host;
196 io.in.credentials = credentials;
197 io.in.fallback_to_anonymous = False;
198 io.in.workgroup = lp_workgroup();
199 io.in.service = remote_share;
200 io.in.service_type = "?????";
202 creq = smb_composite_connect_send(&io, private, ntvfs->ctx->event_ctx);
203 status = smb_composite_connect_recv(creq, private);
204 NT_STATUS_NOT_OK_RETURN(status);
206 private->tree = io.out.tree;
208 private->transport = private->tree->session->transport;
210 private->ntvfs = ntvfs;
212 ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
213 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
214 ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
215 NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
217 /* we need to receive oplock break requests from the server */
218 smbcli_oplock_handler(private->transport, oplock_handler, private);
220 private->map_generic = share_bool_option(scfg, CIFS_MAP_GENERIC, CIFS_MAP_GENERIC_DEFAULT);
222 private->map_trans2 = share_bool_option(scfg, CIFS_MAP_TRANS2, CIFS_MAP_TRANS2_DEFAULT);
228 disconnect from a share
230 static NTSTATUS cvfs_disconnect(struct ntvfs_module_context *ntvfs)
232 struct cvfs_private *private = ntvfs->private_data;
233 struct async_info *a, *an;
235 /* first cleanup pending requests */
236 for (a=private->pending; a; a = an) {
238 smbcli_request_destroy(a->c_req);
242 talloc_free(private);
243 ntvfs->private_data = NULL;
249 destroy an async info structure
251 static int async_info_destructor(struct async_info *async)
253 DLIST_REMOVE(async->cvfs->pending, async);
258 a handler for simple async replies
259 this handler can only be used for functions that don't return any
260 parameters (those that just return a status code)
262 static void async_simple(struct smbcli_request *c_req)
264 struct async_info *async = c_req->async.private;
265 struct ntvfs_request *req = async->req;
266 req->async_states->status = smbcli_request_simple_recv(c_req);
268 req->async_states->send_fn(req);
272 /* save some typing for the simple functions */
273 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
274 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
276 struct async_info *async; \
277 async = talloc(req, struct async_info); \
278 if (!async) return NT_STATUS_NO_MEMORY; \
282 async->cvfs = private; \
283 async->c_req = c_req; \
284 DLIST_ADD(private->pending, async); \
285 c_req->async.private = async; \
286 talloc_set_destructor(async, async_info_destructor); \
288 c_req->async.fn = async_fn; \
289 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
290 return NT_STATUS_OK; \
293 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
295 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
298 delete a file - the dirtype specifies the file types to include in the search.
299 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
301 static NTSTATUS cvfs_unlink(struct ntvfs_module_context *ntvfs,
302 struct ntvfs_request *req, union smb_unlink *unl)
304 struct cvfs_private *private = ntvfs->private_data;
305 struct smbcli_request *c_req;
309 /* see if the front end will allow us to perform this
310 function asynchronously. */
311 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
312 return smb_raw_unlink(private->tree, unl);
315 c_req = smb_raw_unlink_send(private->tree, unl);
321 a handler for async ioctl replies
323 static void async_ioctl(struct smbcli_request *c_req)
325 struct async_info *async = c_req->async.private;
326 struct ntvfs_request *req = async->req;
327 req->async_states->status = smb_raw_ioctl_recv(c_req, req, async->parms);
329 req->async_states->send_fn(req);
335 static NTSTATUS cvfs_ioctl(struct ntvfs_module_context *ntvfs,
336 struct ntvfs_request *req, union smb_ioctl *io)
338 struct cvfs_private *private = ntvfs->private_data;
339 struct smbcli_request *c_req;
343 /* see if the front end will allow us to perform this
344 function asynchronously. */
345 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
346 return smb_raw_ioctl(private->tree, req, io);
349 c_req = smb_raw_ioctl_send(private->tree, io);
351 ASYNC_RECV_TAIL(io, async_ioctl);
355 check if a directory exists
357 static NTSTATUS cvfs_chkpath(struct ntvfs_module_context *ntvfs,
358 struct ntvfs_request *req, union smb_chkpath *cp)
360 struct cvfs_private *private = ntvfs->private_data;
361 struct smbcli_request *c_req;
365 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
366 return smb_raw_chkpath(private->tree, cp);
369 c_req = smb_raw_chkpath_send(private->tree, cp);
375 a handler for async qpathinfo replies
377 static void async_qpathinfo(struct smbcli_request *c_req)
379 struct async_info *async = c_req->async.private;
380 struct ntvfs_request *req = async->req;
381 req->async_states->status = smb_raw_pathinfo_recv(c_req, req, async->parms);
383 req->async_states->send_fn(req);
387 return info on a pathname
389 static NTSTATUS cvfs_qpathinfo(struct ntvfs_module_context *ntvfs,
390 struct ntvfs_request *req, union smb_fileinfo *info)
392 struct cvfs_private *private = ntvfs->private_data;
393 struct smbcli_request *c_req;
397 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
398 return smb_raw_pathinfo(private->tree, req, info);
401 c_req = smb_raw_pathinfo_send(private->tree, info);
403 ASYNC_RECV_TAIL(info, async_qpathinfo);
407 a handler for async qfileinfo replies
409 static void async_qfileinfo(struct smbcli_request *c_req)
411 struct async_info *async = c_req->async.private;
412 struct ntvfs_request *req = async->req;
413 req->async_states->status = smb_raw_fileinfo_recv(c_req, req, async->parms);
415 req->async_states->send_fn(req);
419 query info on a open file
421 static NTSTATUS cvfs_qfileinfo(struct ntvfs_module_context *ntvfs,
422 struct ntvfs_request *req, union smb_fileinfo *io)
424 struct cvfs_private *private = ntvfs->private_data;
425 struct smbcli_request *c_req;
429 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
430 return smb_raw_fileinfo(private->tree, req, io);
433 c_req = smb_raw_fileinfo_send(private->tree, io);
435 ASYNC_RECV_TAIL(io, async_qfileinfo);
440 set info on a pathname
442 static NTSTATUS cvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
443 struct ntvfs_request *req, union smb_setfileinfo *st)
445 struct cvfs_private *private = ntvfs->private_data;
446 struct smbcli_request *c_req;
450 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
451 return smb_raw_setpathinfo(private->tree, st);
454 c_req = smb_raw_setpathinfo_send(private->tree, st);
461 a handler for async open replies
463 static void async_open(struct smbcli_request *c_req)
465 struct async_info *async = c_req->async.private;
466 struct cvfs_private *cvfs = async->cvfs;
467 struct ntvfs_request *req = async->req;
468 struct cvfs_file *f = async->f;
469 union smb_open *io = async->parms;
470 union smb_handle *file;
472 req->async_states->status = smb_raw_open_recv(c_req, req, io);
473 SMB_OPEN_OUT_FILE(io, file);
474 f->fnum = file->fnum;
476 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
477 req->async_states->status = ntvfs_handle_set_backend_data(f->h, cvfs->ntvfs, f);
478 if (!NT_STATUS_IS_OK(req->async_states->status)) goto failed;
481 req->async_states->send_fn(req);
487 static NTSTATUS cvfs_open(struct ntvfs_module_context *ntvfs,
488 struct ntvfs_request *req, union smb_open *io)
490 struct cvfs_private *private = ntvfs->private_data;
491 struct smbcli_request *c_req;
492 struct ntvfs_handle *h;
498 if (io->generic.level != RAW_OPEN_GENERIC &&
499 private->map_generic) {
500 return ntvfs_map_open(ntvfs, req, io);
503 status = ntvfs_handle_new(ntvfs, req, &h);
504 NT_STATUS_NOT_OK_RETURN(status);
506 f = talloc_zero(h, struct cvfs_file);
507 NT_STATUS_HAVE_NO_MEMORY(f);
510 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
511 union smb_handle *file;
513 status = smb_raw_open(private->tree, req, io);
514 NT_STATUS_NOT_OK_RETURN(status);
516 SMB_OPEN_OUT_FILE(io, file);
517 f->fnum = file->fnum;
519 status = ntvfs_handle_set_backend_data(f->h, private->ntvfs, f);
520 NT_STATUS_NOT_OK_RETURN(status);
526 c_req = smb_raw_open_send(private->tree, io);
528 ASYNC_RECV_TAIL_F(io, async_open, f);
534 static NTSTATUS cvfs_mkdir(struct ntvfs_module_context *ntvfs,
535 struct ntvfs_request *req, union smb_mkdir *md)
537 struct cvfs_private *private = ntvfs->private_data;
538 struct smbcli_request *c_req;
542 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
543 return smb_raw_mkdir(private->tree, md);
546 c_req = smb_raw_mkdir_send(private->tree, md);
554 static NTSTATUS cvfs_rmdir(struct ntvfs_module_context *ntvfs,
555 struct ntvfs_request *req, struct smb_rmdir *rd)
557 struct cvfs_private *private = ntvfs->private_data;
558 struct smbcli_request *c_req;
562 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
563 return smb_raw_rmdir(private->tree, rd);
565 c_req = smb_raw_rmdir_send(private->tree, rd);
571 rename a set of files
573 static NTSTATUS cvfs_rename(struct ntvfs_module_context *ntvfs,
574 struct ntvfs_request *req, union smb_rename *ren)
576 struct cvfs_private *private = ntvfs->private_data;
577 struct smbcli_request *c_req;
581 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
582 return smb_raw_rename(private->tree, ren);
585 c_req = smb_raw_rename_send(private->tree, ren);
593 static NTSTATUS cvfs_copy(struct ntvfs_module_context *ntvfs,
594 struct ntvfs_request *req, struct smb_copy *cp)
596 return NT_STATUS_NOT_SUPPORTED;
600 a handler for async read replies
602 static void async_read(struct smbcli_request *c_req)
604 struct async_info *async = c_req->async.private;
605 struct ntvfs_request *req = async->req;
606 req->async_states->status = smb_raw_read_recv(c_req, async->parms);
608 req->async_states->send_fn(req);
614 static NTSTATUS cvfs_read(struct ntvfs_module_context *ntvfs,
615 struct ntvfs_request *req, union smb_read *io)
617 struct cvfs_private *private = ntvfs->private_data;
618 struct smbcli_request *c_req;
622 if (io->generic.level != RAW_READ_GENERIC &&
623 private->map_generic) {
624 return ntvfs_map_read(ntvfs, req, io);
629 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
630 return smb_raw_read(private->tree, io);
633 c_req = smb_raw_read_send(private->tree, io);
635 ASYNC_RECV_TAIL(io, async_read);
639 a handler for async write replies
641 static void async_write(struct smbcli_request *c_req)
643 struct async_info *async = c_req->async.private;
644 struct ntvfs_request *req = async->req;
645 req->async_states->status = smb_raw_write_recv(c_req, async->parms);
647 req->async_states->send_fn(req);
653 static NTSTATUS cvfs_write(struct ntvfs_module_context *ntvfs,
654 struct ntvfs_request *req, union smb_write *io)
656 struct cvfs_private *private = ntvfs->private_data;
657 struct smbcli_request *c_req;
661 if (io->generic.level != RAW_WRITE_GENERIC &&
662 private->map_generic) {
663 return ntvfs_map_write(ntvfs, req, io);
667 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
668 return smb_raw_write(private->tree, io);
671 c_req = smb_raw_write_send(private->tree, io);
673 ASYNC_RECV_TAIL(io, async_write);
677 a handler for async seek replies
679 static void async_seek(struct smbcli_request *c_req)
681 struct async_info *async = c_req->async.private;
682 struct ntvfs_request *req = async->req;
683 req->async_states->status = smb_raw_seek_recv(c_req, async->parms);
685 req->async_states->send_fn(req);
691 static NTSTATUS cvfs_seek(struct ntvfs_module_context *ntvfs,
692 struct ntvfs_request *req,
695 struct cvfs_private *private = ntvfs->private_data;
696 struct smbcli_request *c_req;
700 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
701 return smb_raw_seek(private->tree, io);
704 c_req = smb_raw_seek_send(private->tree, io);
706 ASYNC_RECV_TAIL(io, async_seek);
712 static NTSTATUS cvfs_flush(struct ntvfs_module_context *ntvfs,
713 struct ntvfs_request *req,
716 struct cvfs_private *private = ntvfs->private_data;
717 struct smbcli_request *c_req;
720 switch (io->generic.level) {
721 case RAW_FLUSH_FLUSH:
725 io->generic.in.file.fnum = 0xFFFF;
728 return NT_STATUS_INVALID_LEVEL;
731 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
732 return smb_raw_flush(private->tree, io);
735 c_req = smb_raw_flush_send(private->tree, io);
743 static NTSTATUS cvfs_close(struct ntvfs_module_context *ntvfs,
744 struct ntvfs_request *req, union smb_close *io)
746 struct cvfs_private *private = ntvfs->private_data;
747 struct smbcli_request *c_req;
751 if (io->generic.level != RAW_CLOSE_GENERIC &&
752 private->map_generic) {
753 return ntvfs_map_close(ntvfs, req, io);
757 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
758 return smb_raw_close(private->tree, io);
761 c_req = smb_raw_close_send(private->tree, io);
767 exit - closing files open by the pid
769 static NTSTATUS cvfs_exit(struct ntvfs_module_context *ntvfs,
770 struct ntvfs_request *req)
772 struct cvfs_private *private = ntvfs->private_data;
773 struct smbcli_request *c_req;
777 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
778 return smb_raw_exit(private->tree->session);
781 c_req = smb_raw_exit_send(private->tree->session);
787 logoff - closing files open by the user
789 static NTSTATUS cvfs_logoff(struct ntvfs_module_context *ntvfs,
790 struct ntvfs_request *req)
792 /* we can't do this right in the cifs backend .... */
797 setup for an async call - nothing to do yet
799 static NTSTATUS cvfs_async_setup(struct ntvfs_module_context *ntvfs,
800 struct ntvfs_request *req,
809 static NTSTATUS cvfs_cancel(struct ntvfs_module_context *ntvfs,
810 struct ntvfs_request *req)
812 struct cvfs_private *private = ntvfs->private_data;
813 struct async_info *a;
815 /* find the matching request */
816 for (a=private->pending;a;a=a->next) {
823 return NT_STATUS_INVALID_PARAMETER;
826 return smb_raw_ntcancel(a->c_req);
832 static NTSTATUS cvfs_lock(struct ntvfs_module_context *ntvfs,
833 struct ntvfs_request *req, union smb_lock *io)
835 struct cvfs_private *private = ntvfs->private_data;
836 struct smbcli_request *c_req;
840 if (io->generic.level != RAW_LOCK_GENERIC &&
841 private->map_generic) {
842 return ntvfs_map_lock(ntvfs, req, io);
846 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
847 return smb_raw_lock(private->tree, io);
850 c_req = smb_raw_lock_send(private->tree, io);
855 set info on a open file
857 static NTSTATUS cvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
858 struct ntvfs_request *req,
859 union smb_setfileinfo *io)
861 struct cvfs_private *private = ntvfs->private_data;
862 struct smbcli_request *c_req;
866 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
867 return smb_raw_setfileinfo(private->tree, io);
869 c_req = smb_raw_setfileinfo_send(private->tree, io);
876 a handler for async fsinfo replies
878 static void async_fsinfo(struct smbcli_request *c_req)
880 struct async_info *async = c_req->async.private;
881 struct ntvfs_request *req = async->req;
882 req->async_states->status = smb_raw_fsinfo_recv(c_req, req, async->parms);
884 req->async_states->send_fn(req);
888 return filesystem space info
890 static NTSTATUS cvfs_fsinfo(struct ntvfs_module_context *ntvfs,
891 struct ntvfs_request *req, union smb_fsinfo *fs)
893 struct cvfs_private *private = ntvfs->private_data;
894 struct smbcli_request *c_req;
898 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
899 return smb_raw_fsinfo(private->tree, req, fs);
902 c_req = smb_raw_fsinfo_send(private->tree, req, fs);
904 ASYNC_RECV_TAIL(fs, async_fsinfo);
908 return print queue info
910 static NTSTATUS cvfs_lpq(struct ntvfs_module_context *ntvfs,
911 struct ntvfs_request *req, union smb_lpq *lpq)
913 return NT_STATUS_NOT_SUPPORTED;
917 list files in a directory matching a wildcard pattern
919 static NTSTATUS cvfs_search_first(struct ntvfs_module_context *ntvfs,
920 struct ntvfs_request *req, union smb_search_first *io,
921 void *search_private,
922 BOOL (*callback)(void *, union smb_search_data *))
924 struct cvfs_private *private = ntvfs->private_data;
928 return smb_raw_search_first(private->tree, req, io, search_private, callback);
931 /* continue a search */
932 static NTSTATUS cvfs_search_next(struct ntvfs_module_context *ntvfs,
933 struct ntvfs_request *req, union smb_search_next *io,
934 void *search_private,
935 BOOL (*callback)(void *, union smb_search_data *))
937 struct cvfs_private *private = ntvfs->private_data;
941 return smb_raw_search_next(private->tree, req, io, search_private, callback);
945 static NTSTATUS cvfs_search_close(struct ntvfs_module_context *ntvfs,
946 struct ntvfs_request *req, union smb_search_close *io)
948 struct cvfs_private *private = ntvfs->private_data;
952 return smb_raw_search_close(private->tree, io);
956 a handler for async trans2 replies
958 static void async_trans2(struct smbcli_request *c_req)
960 struct async_info *async = c_req->async.private;
961 struct ntvfs_request *req = async->req;
962 req->async_states->status = smb_raw_trans2_recv(c_req, req, async->parms);
964 req->async_states->send_fn(req);
968 static NTSTATUS cvfs_trans2(struct ntvfs_module_context *ntvfs,
969 struct ntvfs_request *req,
970 struct smb_trans2 *trans2)
972 struct cvfs_private *private = ntvfs->private_data;
973 struct smbcli_request *c_req;
975 if (private->map_trans2) {
976 return NT_STATUS_NOT_IMPLEMENTED;
981 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
982 return smb_raw_trans2(private->tree, req, trans2);
985 c_req = smb_raw_trans2_send(private->tree, trans2);
987 ASYNC_RECV_TAIL(trans2, async_trans2);
991 /* SMBtrans - not used on file shares */
992 static NTSTATUS cvfs_trans(struct ntvfs_module_context *ntvfs,
993 struct ntvfs_request *req,
994 struct smb_trans2 *trans2)
996 return NT_STATUS_ACCESS_DENIED;
1000 a handler for async change notify replies
1002 static void async_changenotify(struct smbcli_request *c_req)
1004 struct async_info *async = c_req->async.private;
1005 struct ntvfs_request *req = async->req;
1006 req->async_states->status = smb_raw_changenotify_recv(c_req, req, async->parms);
1008 req->async_states->send_fn(req);
1011 /* change notify request - always async */
1012 static NTSTATUS cvfs_notify(struct ntvfs_module_context *ntvfs,
1013 struct ntvfs_request *req,
1014 union smb_notify *io)
1016 struct cvfs_private *private = ntvfs->private_data;
1017 struct smbcli_request *c_req;
1018 int saved_timeout = private->transport->options.request_timeout;
1019 struct cvfs_file *f;
1021 if (io->nttrans.level != RAW_NOTIFY_NTTRANS) {
1022 return NT_STATUS_NOT_IMPLEMENTED;
1027 f = ntvfs_handle_get_backend_data(io->nttrans.in.file.ntvfs, ntvfs);
1028 if (!f) return NT_STATUS_INVALID_HANDLE;
1029 io->nttrans.in.file.fnum = f->fnum;
1031 /* this request doesn't make sense unless its async */
1032 if (!(req->async_states->state & NTVFS_ASYNC_STATE_MAY_ASYNC)) {
1033 return NT_STATUS_INVALID_PARAMETER;
1036 /* we must not timeout on notify requests - they wait
1038 private->transport->options.request_timeout = 0;
1040 c_req = smb_raw_changenotify_send(private->tree, io);
1042 private->transport->options.request_timeout = saved_timeout;
1044 ASYNC_RECV_TAIL(io, async_changenotify);
1048 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1050 NTSTATUS ntvfs_cifs_init(void)
1053 struct ntvfs_ops ops;
1054 NTVFS_CURRENT_CRITICAL_SIZES(vers);
1058 /* fill in the name and type */
1060 ops.type = NTVFS_DISK;
1062 /* fill in all the operations */
1063 ops.connect = cvfs_connect;
1064 ops.disconnect = cvfs_disconnect;
1065 ops.unlink = cvfs_unlink;
1066 ops.chkpath = cvfs_chkpath;
1067 ops.qpathinfo = cvfs_qpathinfo;
1068 ops.setpathinfo = cvfs_setpathinfo;
1069 ops.open = cvfs_open;
1070 ops.mkdir = cvfs_mkdir;
1071 ops.rmdir = cvfs_rmdir;
1072 ops.rename = cvfs_rename;
1073 ops.copy = cvfs_copy;
1074 ops.ioctl = cvfs_ioctl;
1075 ops.read = cvfs_read;
1076 ops.write = cvfs_write;
1077 ops.seek = cvfs_seek;
1078 ops.flush = cvfs_flush;
1079 ops.close = cvfs_close;
1080 ops.exit = cvfs_exit;
1081 ops.lock = cvfs_lock;
1082 ops.setfileinfo = cvfs_setfileinfo;
1083 ops.qfileinfo = cvfs_qfileinfo;
1084 ops.fsinfo = cvfs_fsinfo;
1086 ops.search_first = cvfs_search_first;
1087 ops.search_next = cvfs_search_next;
1088 ops.search_close = cvfs_search_close;
1089 ops.trans = cvfs_trans;
1090 ops.logoff = cvfs_logoff;
1091 ops.async_setup = cvfs_async_setup;
1092 ops.cancel = cvfs_cancel;
1093 ops.notify = cvfs_notify;
1094 ops.trans2 = cvfs_trans2;
1096 /* register ourselves with the NTVFS subsystem. We register
1097 under the name 'cifs'. */
1098 ret = ntvfs_register(&ops, &vers);
1100 if (!NT_STATUS_IS_OK(ret)) {
1101 DEBUG(0,("Failed to register CIFS backend!\n"));