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 SETUP_PID private->tree->session->pid = req->smbpid
68 #define SETUP_FILE_HERE(f) do { \
69 f = ntvfs_handle_get_backend_data(io->generic.in.file.ntvfs, ntvfs); \
70 if (!f) return NT_STATUS_INVALID_HANDLE; \
71 io->generic.in.file.fnum = f->fnum; \
74 #define SETUP_FILE do { \
75 struct cvfs_file *f; \
79 #define SETUP_PID_AND_FILE do { \
84 #define CIFS_SERVER "cifs:server"
85 #define CIFS_USER "cifs:user"
86 #define CIFS_PASSWORD "cifs:password"
87 #define CIFS_DOMAIN "cifs:domain"
88 #define CIFS_SHARE "cifs:share"
89 #define CIFS_USE_MACHINE_ACCT "cifs:use-machine-account"
90 #define CIFS_MAP_GENERIC "cifs:map-generic"
91 #define CIFS_MAP_TRANS2 "cifs:map-trans2"
93 #define CIFS_USE_MACHINE_ACCT_DEFAULT false
94 #define CIFS_MAP_GENERIC_DEFAULT false
95 #define CIFS_MAP_TRANS2_DEFAULT true
98 a handler for oplock break events from the server - these need to be passed
101 static bool oplock_handler(struct smbcli_transport
*transport
, uint16_t tid
, uint16_t fnum
, uint8_t level
, void *p_private
)
103 struct cvfs_private
*private = p_private
;
105 struct ntvfs_handle
*h
= NULL
;
108 for (f
=private->files
; f
; f
=f
->next
) {
109 if (f
->fnum
!= fnum
) continue;
115 DEBUG(5,("vfs_cifs: ignoring oplock break level %d for fnum %d\n", level
, fnum
));
119 DEBUG(5,("vfs_cifs: sending oplock break level %d for fnum %d\n", level
, fnum
));
120 status
= ntvfs_send_oplock_break(private->ntvfs
, h
, level
);
121 if (!NT_STATUS_IS_OK(status
)) return false;
126 connect to a share - used when a tree_connect operation comes in.
128 static NTSTATUS
cvfs_connect(struct ntvfs_module_context
*ntvfs
,
129 struct ntvfs_request
*req
, const char *sharename
)
132 struct cvfs_private
*private;
133 const char *host
, *user
, *pass
, *domain
, *remote_share
;
134 struct smb_composite_connect io
;
135 struct composite_context
*creq
;
136 struct share_config
*scfg
= ntvfs
->ctx
->config
;
138 struct cli_credentials
*credentials
;
139 bool machine_account
;
141 /* Here we need to determine which server to connect to.
142 * For now we use parametric options, type cifs.
143 * Later we will use security=server and auth_server.c.
145 host
= share_string_option(scfg
, CIFS_SERVER
, NULL
);
146 user
= share_string_option(scfg
, CIFS_USER
, NULL
);
147 pass
= share_string_option(scfg
, CIFS_PASSWORD
, NULL
);
148 domain
= share_string_option(scfg
, CIFS_DOMAIN
, NULL
);
149 remote_share
= share_string_option(scfg
, CIFS_SHARE
, NULL
);
151 remote_share
= sharename
;
154 machine_account
= share_bool_option(scfg
, CIFS_USE_MACHINE_ACCT
, CIFS_USE_MACHINE_ACCT_DEFAULT
);
156 private = talloc_zero(ntvfs
, struct cvfs_private
);
158 return NT_STATUS_NO_MEMORY
;
161 ntvfs
->private_data
= private;
164 DEBUG(1,("CIFS backend: You must supply server\n"));
165 return NT_STATUS_INVALID_PARAMETER
;
169 DEBUG(5, ("CIFS backend: Using specified password\n"));
170 credentials
= cli_credentials_init(private);
172 return NT_STATUS_NO_MEMORY
;
174 cli_credentials_set_conf(credentials
, ntvfs
->ctx
->lp_ctx
);
175 cli_credentials_set_username(credentials
, user
, CRED_SPECIFIED
);
177 cli_credentials_set_domain(credentials
, domain
, CRED_SPECIFIED
);
179 cli_credentials_set_password(credentials
, pass
, CRED_SPECIFIED
);
180 } else if (machine_account
) {
181 DEBUG(5, ("CIFS backend: Using machine account\n"));
182 credentials
= cli_credentials_init(private);
183 cli_credentials_set_conf(credentials
, ntvfs
->ctx
->lp_ctx
);
185 cli_credentials_set_domain(credentials
, domain
, CRED_SPECIFIED
);
187 status
= cli_credentials_set_machine_account(credentials
, ntvfs
->ctx
->lp_ctx
);
188 if (!NT_STATUS_IS_OK(status
)) {
191 } else if (req
->session_info
->credentials
) {
192 DEBUG(5, ("CIFS backend: Using delegated credentials\n"));
193 credentials
= req
->session_info
->credentials
;
195 DEBUG(1,("CIFS backend: NO delegated credentials found: You must supply server, user and password or the client must supply delegated credentials\n"));
196 return NT_STATUS_INVALID_PARAMETER
;
199 /* connect to the server, using the smbd event context */
200 io
.in
.dest_host
= host
;
201 io
.in
.dest_ports
= lp_smb_ports(ntvfs
->ctx
->lp_ctx
);
202 io
.in
.socket_options
= lp_socket_options(ntvfs
->ctx
->lp_ctx
);
203 io
.in
.called_name
= host
;
204 io
.in
.credentials
= credentials
;
205 io
.in
.fallback_to_anonymous
= false;
206 io
.in
.workgroup
= lp_workgroup(ntvfs
->ctx
->lp_ctx
);
207 io
.in
.service
= remote_share
;
208 io
.in
.service_type
= "?????";
209 io
.in
.iconv_convenience
= lp_iconv_convenience(ntvfs
->ctx
->lp_ctx
);
210 io
.in
.gensec_settings
= lp_gensec_settings(private, ntvfs
->ctx
->lp_ctx
);
211 lp_smbcli_options(ntvfs
->ctx
->lp_ctx
, &io
.in
.options
);
212 lp_smbcli_session_options(ntvfs
->ctx
->lp_ctx
, &io
.in
.session_options
);
214 if (!(ntvfs
->ctx
->client_caps
& NTVFS_CLIENT_CAP_LEVEL_II_OPLOCKS
)) {
215 io
.in
.options
.use_level2_oplocks
= false;
218 creq
= smb_composite_connect_send(&io
, private,
219 lp_resolve_context(ntvfs
->ctx
->lp_ctx
),
220 ntvfs
->ctx
->event_ctx
);
221 status
= smb_composite_connect_recv(creq
, private);
222 NT_STATUS_NOT_OK_RETURN(status
);
224 private->tree
= io
.out
.tree
;
226 private->transport
= private->tree
->session
->transport
;
228 private->ntvfs
= ntvfs
;
230 ntvfs
->ctx
->fs_type
= talloc_strdup(ntvfs
->ctx
, "NTFS");
231 NT_STATUS_HAVE_NO_MEMORY(ntvfs
->ctx
->fs_type
);
232 ntvfs
->ctx
->dev_type
= talloc_strdup(ntvfs
->ctx
, "A:");
233 NT_STATUS_HAVE_NO_MEMORY(ntvfs
->ctx
->dev_type
);
235 /* we need to receive oplock break requests from the server */
236 smbcli_oplock_handler(private->transport
, oplock_handler
, private);
238 private->map_generic
= share_bool_option(scfg
, CIFS_MAP_GENERIC
, CIFS_MAP_GENERIC_DEFAULT
);
240 private->map_trans2
= share_bool_option(scfg
, CIFS_MAP_TRANS2
, CIFS_MAP_TRANS2_DEFAULT
);
246 disconnect from a share
248 static NTSTATUS
cvfs_disconnect(struct ntvfs_module_context
*ntvfs
)
250 struct cvfs_private
*private = ntvfs
->private_data
;
251 struct async_info
*a
, *an
;
253 /* first cleanup pending requests */
254 for (a
=private->pending
; a
; a
= an
) {
256 smbcli_request_destroy(a
->c_req
);
260 talloc_free(private);
261 ntvfs
->private_data
= NULL
;
267 destroy an async info structure
269 static int async_info_destructor(struct async_info
*async
)
271 DLIST_REMOVE(async
->cvfs
->pending
, async
);
276 a handler for simple async replies
277 this handler can only be used for functions that don't return any
278 parameters (those that just return a status code)
280 static void async_simple(struct smbcli_request
*c_req
)
282 struct async_info
*async
= c_req
->async
.private;
283 struct ntvfs_request
*req
= async
->req
;
284 req
->async_states
->status
= smbcli_request_simple_recv(c_req
);
286 req
->async_states
->send_fn(req
);
290 /* save some typing for the simple functions */
291 #define ASYNC_RECV_TAIL_F(io, async_fn, file) do { \
292 if (!c_req) return NT_STATUS_UNSUCCESSFUL; \
294 struct async_info *async; \
295 async = talloc(req, struct async_info); \
296 if (!async) return NT_STATUS_NO_MEMORY; \
300 async->cvfs = private; \
301 async->c_req = c_req; \
302 DLIST_ADD(private->pending, async); \
303 c_req->async.private = async; \
304 talloc_set_destructor(async, async_info_destructor); \
306 c_req->async.fn = async_fn; \
307 req->async_states->state |= NTVFS_ASYNC_STATE_ASYNC; \
308 return NT_STATUS_OK; \
311 #define ASYNC_RECV_TAIL(io, async_fn) ASYNC_RECV_TAIL_F(io, async_fn, NULL)
313 #define SIMPLE_ASYNC_TAIL ASYNC_RECV_TAIL(NULL, async_simple)
316 delete a file - the dirtype specifies the file types to include in the search.
317 The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
319 static NTSTATUS
cvfs_unlink(struct ntvfs_module_context
*ntvfs
,
320 struct ntvfs_request
*req
, union smb_unlink
*unl
)
322 struct cvfs_private
*private = ntvfs
->private_data
;
323 struct smbcli_request
*c_req
;
327 /* see if the front end will allow us to perform this
328 function asynchronously. */
329 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
330 return smb_raw_unlink(private->tree
, unl
);
333 c_req
= smb_raw_unlink_send(private->tree
, unl
);
339 a handler for async ioctl replies
341 static void async_ioctl(struct smbcli_request
*c_req
)
343 struct async_info
*async
= c_req
->async
.private;
344 struct ntvfs_request
*req
= async
->req
;
345 req
->async_states
->status
= smb_raw_ioctl_recv(c_req
, req
, async
->parms
);
347 req
->async_states
->send_fn(req
);
353 static NTSTATUS
cvfs_ioctl(struct ntvfs_module_context
*ntvfs
,
354 struct ntvfs_request
*req
, union smb_ioctl
*io
)
356 struct cvfs_private
*private = ntvfs
->private_data
;
357 struct smbcli_request
*c_req
;
361 /* see if the front end will allow us to perform this
362 function asynchronously. */
363 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
364 return smb_raw_ioctl(private->tree
, req
, io
);
367 c_req
= smb_raw_ioctl_send(private->tree
, io
);
369 ASYNC_RECV_TAIL(io
, async_ioctl
);
373 check if a directory exists
375 static NTSTATUS
cvfs_chkpath(struct ntvfs_module_context
*ntvfs
,
376 struct ntvfs_request
*req
, union smb_chkpath
*cp
)
378 struct cvfs_private
*private = ntvfs
->private_data
;
379 struct smbcli_request
*c_req
;
383 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
384 return smb_raw_chkpath(private->tree
, cp
);
387 c_req
= smb_raw_chkpath_send(private->tree
, cp
);
393 a handler for async qpathinfo replies
395 static void async_qpathinfo(struct smbcli_request
*c_req
)
397 struct async_info
*async
= c_req
->async
.private;
398 struct ntvfs_request
*req
= async
->req
;
399 req
->async_states
->status
= smb_raw_pathinfo_recv(c_req
, req
, async
->parms
);
401 req
->async_states
->send_fn(req
);
405 return info on a pathname
407 static NTSTATUS
cvfs_qpathinfo(struct ntvfs_module_context
*ntvfs
,
408 struct ntvfs_request
*req
, union smb_fileinfo
*info
)
410 struct cvfs_private
*private = ntvfs
->private_data
;
411 struct smbcli_request
*c_req
;
415 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
416 return smb_raw_pathinfo(private->tree
, req
, info
);
419 c_req
= smb_raw_pathinfo_send(private->tree
, info
);
421 ASYNC_RECV_TAIL(info
, async_qpathinfo
);
425 a handler for async qfileinfo replies
427 static void async_qfileinfo(struct smbcli_request
*c_req
)
429 struct async_info
*async
= c_req
->async
.private;
430 struct ntvfs_request
*req
= async
->req
;
431 req
->async_states
->status
= smb_raw_fileinfo_recv(c_req
, req
, async
->parms
);
433 req
->async_states
->send_fn(req
);
437 query info on a open file
439 static NTSTATUS
cvfs_qfileinfo(struct ntvfs_module_context
*ntvfs
,
440 struct ntvfs_request
*req
, union smb_fileinfo
*io
)
442 struct cvfs_private
*private = ntvfs
->private_data
;
443 struct smbcli_request
*c_req
;
447 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
448 return smb_raw_fileinfo(private->tree
, req
, io
);
451 c_req
= smb_raw_fileinfo_send(private->tree
, io
);
453 ASYNC_RECV_TAIL(io
, async_qfileinfo
);
458 set info on a pathname
460 static NTSTATUS
cvfs_setpathinfo(struct ntvfs_module_context
*ntvfs
,
461 struct ntvfs_request
*req
, union smb_setfileinfo
*st
)
463 struct cvfs_private
*private = ntvfs
->private_data
;
464 struct smbcli_request
*c_req
;
468 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
469 return smb_raw_setpathinfo(private->tree
, st
);
472 c_req
= smb_raw_setpathinfo_send(private->tree
, st
);
479 a handler for async open replies
481 static void async_open(struct smbcli_request
*c_req
)
483 struct async_info
*async
= c_req
->async
.private;
484 struct cvfs_private
*cvfs
= async
->cvfs
;
485 struct ntvfs_request
*req
= async
->req
;
486 struct cvfs_file
*f
= async
->f
;
487 union smb_open
*io
= async
->parms
;
488 union smb_handle
*file
;
490 req
->async_states
->status
= smb_raw_open_recv(c_req
, req
, io
);
491 SMB_OPEN_OUT_FILE(io
, file
);
492 f
->fnum
= file
->fnum
;
494 if (!NT_STATUS_IS_OK(req
->async_states
->status
)) goto failed
;
495 req
->async_states
->status
= ntvfs_handle_set_backend_data(f
->h
, cvfs
->ntvfs
, f
);
496 if (!NT_STATUS_IS_OK(req
->async_states
->status
)) goto failed
;
498 DLIST_ADD(cvfs
->files
, f
);
500 req
->async_states
->send_fn(req
);
506 static NTSTATUS
cvfs_open(struct ntvfs_module_context
*ntvfs
,
507 struct ntvfs_request
*req
, union smb_open
*io
)
509 struct cvfs_private
*private = ntvfs
->private_data
;
510 struct smbcli_request
*c_req
;
511 struct ntvfs_handle
*h
;
517 if (io
->generic
.level
!= RAW_OPEN_GENERIC
&&
518 private->map_generic
) {
519 return ntvfs_map_open(ntvfs
, req
, io
);
522 status
= ntvfs_handle_new(ntvfs
, req
, &h
);
523 NT_STATUS_NOT_OK_RETURN(status
);
525 f
= talloc_zero(h
, struct cvfs_file
);
526 NT_STATUS_HAVE_NO_MEMORY(f
);
529 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
530 union smb_handle
*file
;
532 status
= smb_raw_open(private->tree
, req
, io
);
533 NT_STATUS_NOT_OK_RETURN(status
);
535 SMB_OPEN_OUT_FILE(io
, file
);
536 f
->fnum
= file
->fnum
;
538 status
= ntvfs_handle_set_backend_data(f
->h
, private->ntvfs
, f
);
539 NT_STATUS_NOT_OK_RETURN(status
);
541 DLIST_ADD(private->files
, f
);
546 c_req
= smb_raw_open_send(private->tree
, io
);
548 ASYNC_RECV_TAIL_F(io
, async_open
, f
);
554 static NTSTATUS
cvfs_mkdir(struct ntvfs_module_context
*ntvfs
,
555 struct ntvfs_request
*req
, union smb_mkdir
*md
)
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_mkdir(private->tree
, md
);
566 c_req
= smb_raw_mkdir_send(private->tree
, md
);
574 static NTSTATUS
cvfs_rmdir(struct ntvfs_module_context
*ntvfs
,
575 struct ntvfs_request
*req
, struct smb_rmdir
*rd
)
577 struct cvfs_private
*private = ntvfs
->private_data
;
578 struct smbcli_request
*c_req
;
582 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
583 return smb_raw_rmdir(private->tree
, rd
);
585 c_req
= smb_raw_rmdir_send(private->tree
, rd
);
591 rename a set of files
593 static NTSTATUS
cvfs_rename(struct ntvfs_module_context
*ntvfs
,
594 struct ntvfs_request
*req
, union smb_rename
*ren
)
596 struct cvfs_private
*private = ntvfs
->private_data
;
597 struct smbcli_request
*c_req
;
601 if (ren
->nttrans
.level
== RAW_RENAME_NTTRANS
) {
603 f
= ntvfs_handle_get_backend_data(ren
->nttrans
.in
.file
.ntvfs
, ntvfs
);
604 if (!f
) return NT_STATUS_INVALID_HANDLE
;
605 ren
->nttrans
.in
.file
.fnum
= f
->fnum
;
608 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
609 return smb_raw_rename(private->tree
, ren
);
612 c_req
= smb_raw_rename_send(private->tree
, ren
);
620 static NTSTATUS
cvfs_copy(struct ntvfs_module_context
*ntvfs
,
621 struct ntvfs_request
*req
, struct smb_copy
*cp
)
623 return NT_STATUS_NOT_SUPPORTED
;
627 a handler for async read replies
629 static void async_read(struct smbcli_request
*c_req
)
631 struct async_info
*async
= c_req
->async
.private;
632 struct ntvfs_request
*req
= async
->req
;
633 req
->async_states
->status
= smb_raw_read_recv(c_req
, async
->parms
);
635 req
->async_states
->send_fn(req
);
641 static NTSTATUS
cvfs_read(struct ntvfs_module_context
*ntvfs
,
642 struct ntvfs_request
*req
, union smb_read
*io
)
644 struct cvfs_private
*private = ntvfs
->private_data
;
645 struct smbcli_request
*c_req
;
649 if (io
->generic
.level
!= RAW_READ_GENERIC
&&
650 private->map_generic
) {
651 return ntvfs_map_read(ntvfs
, req
, io
);
656 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
657 return smb_raw_read(private->tree
, io
);
660 c_req
= smb_raw_read_send(private->tree
, io
);
662 ASYNC_RECV_TAIL(io
, async_read
);
666 a handler for async write replies
668 static void async_write(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_write_recv(c_req
, async
->parms
);
674 req
->async_states
->send_fn(req
);
680 static NTSTATUS
cvfs_write(struct ntvfs_module_context
*ntvfs
,
681 struct ntvfs_request
*req
, union smb_write
*io
)
683 struct cvfs_private
*private = ntvfs
->private_data
;
684 struct smbcli_request
*c_req
;
688 if (io
->generic
.level
!= RAW_WRITE_GENERIC
&&
689 private->map_generic
) {
690 return ntvfs_map_write(ntvfs
, req
, io
);
694 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
695 return smb_raw_write(private->tree
, io
);
698 c_req
= smb_raw_write_send(private->tree
, io
);
700 ASYNC_RECV_TAIL(io
, async_write
);
704 a handler for async seek replies
706 static void async_seek(struct smbcli_request
*c_req
)
708 struct async_info
*async
= c_req
->async
.private;
709 struct ntvfs_request
*req
= async
->req
;
710 req
->async_states
->status
= smb_raw_seek_recv(c_req
, async
->parms
);
712 req
->async_states
->send_fn(req
);
718 static NTSTATUS
cvfs_seek(struct ntvfs_module_context
*ntvfs
,
719 struct ntvfs_request
*req
,
722 struct cvfs_private
*private = ntvfs
->private_data
;
723 struct smbcli_request
*c_req
;
727 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
728 return smb_raw_seek(private->tree
, io
);
731 c_req
= smb_raw_seek_send(private->tree
, io
);
733 ASYNC_RECV_TAIL(io
, async_seek
);
739 static NTSTATUS
cvfs_flush(struct ntvfs_module_context
*ntvfs
,
740 struct ntvfs_request
*req
,
743 struct cvfs_private
*private = ntvfs
->private_data
;
744 struct smbcli_request
*c_req
;
747 switch (io
->generic
.level
) {
748 case RAW_FLUSH_FLUSH
:
752 io
->generic
.in
.file
.fnum
= 0xFFFF;
755 return NT_STATUS_INVALID_LEVEL
;
758 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
759 return smb_raw_flush(private->tree
, io
);
762 c_req
= smb_raw_flush_send(private->tree
, io
);
770 static NTSTATUS
cvfs_close(struct ntvfs_module_context
*ntvfs
,
771 struct ntvfs_request
*req
, union smb_close
*io
)
773 struct cvfs_private
*private = ntvfs
->private_data
;
774 struct smbcli_request
*c_req
;
780 if (io
->generic
.level
!= RAW_CLOSE_GENERIC
&&
781 private->map_generic
) {
782 return ntvfs_map_close(ntvfs
, req
, io
);
785 if (io
->generic
.level
== RAW_CLOSE_GENERIC
) {
787 io2
.close
.level
= RAW_CLOSE_CLOSE
;
788 io2
.close
.in
.file
= io
->generic
.in
.file
;
789 io2
.close
.in
.write_time
= io
->generic
.in
.write_time
;
794 /* Note, we aren't free-ing f, or it's h here. Should we?
795 even if file-close fails, we'll remove it from the list,
796 what else would we do? Maybe we should not remove until
797 after the proxied call completes? */
798 DLIST_REMOVE(private->files
, f
);
800 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
801 return smb_raw_close(private->tree
, io
);
804 c_req
= smb_raw_close_send(private->tree
, io
);
810 exit - closing files open by the pid
812 static NTSTATUS
cvfs_exit(struct ntvfs_module_context
*ntvfs
,
813 struct ntvfs_request
*req
)
815 struct cvfs_private
*private = ntvfs
->private_data
;
816 struct smbcli_request
*c_req
;
820 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
821 return smb_raw_exit(private->tree
->session
);
824 c_req
= smb_raw_exit_send(private->tree
->session
);
830 logoff - closing files open by the user
832 static NTSTATUS
cvfs_logoff(struct ntvfs_module_context
*ntvfs
,
833 struct ntvfs_request
*req
)
835 /* we can't do this right in the cifs backend .... */
840 setup for an async call - nothing to do yet
842 static NTSTATUS
cvfs_async_setup(struct ntvfs_module_context
*ntvfs
,
843 struct ntvfs_request
*req
,
852 static NTSTATUS
cvfs_cancel(struct ntvfs_module_context
*ntvfs
,
853 struct ntvfs_request
*req
)
855 struct cvfs_private
*private = ntvfs
->private_data
;
856 struct async_info
*a
;
858 /* find the matching request */
859 for (a
=private->pending
;a
;a
=a
->next
) {
866 return NT_STATUS_INVALID_PARAMETER
;
869 return smb_raw_ntcancel(a
->c_req
);
875 static NTSTATUS
cvfs_lock(struct ntvfs_module_context
*ntvfs
,
876 struct ntvfs_request
*req
, union smb_lock
*io
)
878 struct cvfs_private
*private = ntvfs
->private_data
;
879 struct smbcli_request
*c_req
;
883 if (io
->generic
.level
!= RAW_LOCK_GENERIC
&&
884 private->map_generic
) {
885 return ntvfs_map_lock(ntvfs
, req
, io
);
889 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
890 return smb_raw_lock(private->tree
, io
);
893 c_req
= smb_raw_lock_send(private->tree
, io
);
898 set info on a open file
900 static NTSTATUS
cvfs_setfileinfo(struct ntvfs_module_context
*ntvfs
,
901 struct ntvfs_request
*req
,
902 union smb_setfileinfo
*io
)
904 struct cvfs_private
*private = ntvfs
->private_data
;
905 struct smbcli_request
*c_req
;
909 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
910 return smb_raw_setfileinfo(private->tree
, io
);
912 c_req
= smb_raw_setfileinfo_send(private->tree
, io
);
919 a handler for async fsinfo replies
921 static void async_fsinfo(struct smbcli_request
*c_req
)
923 struct async_info
*async
= c_req
->async
.private;
924 struct ntvfs_request
*req
= async
->req
;
925 req
->async_states
->status
= smb_raw_fsinfo_recv(c_req
, req
, async
->parms
);
927 req
->async_states
->send_fn(req
);
931 return filesystem space info
933 static NTSTATUS
cvfs_fsinfo(struct ntvfs_module_context
*ntvfs
,
934 struct ntvfs_request
*req
, union smb_fsinfo
*fs
)
936 struct cvfs_private
*private = ntvfs
->private_data
;
937 struct smbcli_request
*c_req
;
941 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
942 return smb_raw_fsinfo(private->tree
, req
, fs
);
945 c_req
= smb_raw_fsinfo_send(private->tree
, req
, fs
);
947 ASYNC_RECV_TAIL(fs
, async_fsinfo
);
951 return print queue info
953 static NTSTATUS
cvfs_lpq(struct ntvfs_module_context
*ntvfs
,
954 struct ntvfs_request
*req
, union smb_lpq
*lpq
)
956 return NT_STATUS_NOT_SUPPORTED
;
960 list files in a directory matching a wildcard pattern
962 static NTSTATUS
cvfs_search_first(struct ntvfs_module_context
*ntvfs
,
963 struct ntvfs_request
*req
, union smb_search_first
*io
,
964 void *search_private
,
965 bool (*callback
)(void *, const union smb_search_data
*))
967 struct cvfs_private
*private = ntvfs
->private_data
;
971 return smb_raw_search_first(private->tree
, req
, io
, search_private
, callback
);
974 /* continue a search */
975 static NTSTATUS
cvfs_search_next(struct ntvfs_module_context
*ntvfs
,
976 struct ntvfs_request
*req
, union smb_search_next
*io
,
977 void *search_private
,
978 bool (*callback
)(void *, const union smb_search_data
*))
980 struct cvfs_private
*private = ntvfs
->private_data
;
984 return smb_raw_search_next(private->tree
, req
, io
, search_private
, callback
);
988 static NTSTATUS
cvfs_search_close(struct ntvfs_module_context
*ntvfs
,
989 struct ntvfs_request
*req
, union smb_search_close
*io
)
991 struct cvfs_private
*private = ntvfs
->private_data
;
995 return smb_raw_search_close(private->tree
, io
);
999 a handler for async trans2 replies
1001 static void async_trans2(struct smbcli_request
*c_req
)
1003 struct async_info
*async
= c_req
->async
.private;
1004 struct ntvfs_request
*req
= async
->req
;
1005 req
->async_states
->status
= smb_raw_trans2_recv(c_req
, req
, async
->parms
);
1007 req
->async_states
->send_fn(req
);
1011 static NTSTATUS
cvfs_trans2(struct ntvfs_module_context
*ntvfs
,
1012 struct ntvfs_request
*req
,
1013 struct smb_trans2
*trans2
)
1015 struct cvfs_private
*private = ntvfs
->private_data
;
1016 struct smbcli_request
*c_req
;
1018 if (private->map_trans2
) {
1019 return NT_STATUS_NOT_IMPLEMENTED
;
1024 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
1025 return smb_raw_trans2(private->tree
, req
, trans2
);
1028 c_req
= smb_raw_trans2_send(private->tree
, trans2
);
1030 ASYNC_RECV_TAIL(trans2
, async_trans2
);
1034 /* SMBtrans - not used on file shares */
1035 static NTSTATUS
cvfs_trans(struct ntvfs_module_context
*ntvfs
,
1036 struct ntvfs_request
*req
,
1037 struct smb_trans2
*trans2
)
1039 return NT_STATUS_ACCESS_DENIED
;
1043 a handler for async change notify replies
1045 static void async_changenotify(struct smbcli_request
*c_req
)
1047 struct async_info
*async
= c_req
->async
.private;
1048 struct ntvfs_request
*req
= async
->req
;
1049 req
->async_states
->status
= smb_raw_changenotify_recv(c_req
, req
, async
->parms
);
1051 req
->async_states
->send_fn(req
);
1054 /* change notify request - always async */
1055 static NTSTATUS
cvfs_notify(struct ntvfs_module_context
*ntvfs
,
1056 struct ntvfs_request
*req
,
1057 union smb_notify
*io
)
1059 struct cvfs_private
*private = ntvfs
->private_data
;
1060 struct smbcli_request
*c_req
;
1061 int saved_timeout
= private->transport
->options
.request_timeout
;
1062 struct cvfs_file
*f
;
1064 if (io
->nttrans
.level
!= RAW_NOTIFY_NTTRANS
) {
1065 return NT_STATUS_NOT_IMPLEMENTED
;
1070 f
= ntvfs_handle_get_backend_data(io
->nttrans
.in
.file
.ntvfs
, ntvfs
);
1071 if (!f
) return NT_STATUS_INVALID_HANDLE
;
1072 io
->nttrans
.in
.file
.fnum
= f
->fnum
;
1074 /* this request doesn't make sense unless its async */
1075 if (!(req
->async_states
->state
& NTVFS_ASYNC_STATE_MAY_ASYNC
)) {
1076 return NT_STATUS_INVALID_PARAMETER
;
1079 /* we must not timeout on notify requests - they wait
1081 private->transport
->options
.request_timeout
= 0;
1083 c_req
= smb_raw_changenotify_send(private->tree
, io
);
1085 private->transport
->options
.request_timeout
= saved_timeout
;
1087 ASYNC_RECV_TAIL(io
, async_changenotify
);
1091 initialise the CIFS->CIFS backend, registering ourselves with the ntvfs subsystem
1093 NTSTATUS
ntvfs_cifs_init(void)
1096 struct ntvfs_ops ops
;
1097 NTVFS_CURRENT_CRITICAL_SIZES(vers
);
1101 /* fill in the name and type */
1103 ops
.type
= NTVFS_DISK
;
1105 /* fill in all the operations */
1106 ops
.connect
= cvfs_connect
;
1107 ops
.disconnect
= cvfs_disconnect
;
1108 ops
.unlink
= cvfs_unlink
;
1109 ops
.chkpath
= cvfs_chkpath
;
1110 ops
.qpathinfo
= cvfs_qpathinfo
;
1111 ops
.setpathinfo
= cvfs_setpathinfo
;
1112 ops
.open
= cvfs_open
;
1113 ops
.mkdir
= cvfs_mkdir
;
1114 ops
.rmdir
= cvfs_rmdir
;
1115 ops
.rename
= cvfs_rename
;
1116 ops
.copy
= cvfs_copy
;
1117 ops
.ioctl
= cvfs_ioctl
;
1118 ops
.read
= cvfs_read
;
1119 ops
.write
= cvfs_write
;
1120 ops
.seek
= cvfs_seek
;
1121 ops
.flush
= cvfs_flush
;
1122 ops
.close
= cvfs_close
;
1123 ops
.exit
= cvfs_exit
;
1124 ops
.lock
= cvfs_lock
;
1125 ops
.setfileinfo
= cvfs_setfileinfo
;
1126 ops
.qfileinfo
= cvfs_qfileinfo
;
1127 ops
.fsinfo
= cvfs_fsinfo
;
1129 ops
.search_first
= cvfs_search_first
;
1130 ops
.search_next
= cvfs_search_next
;
1131 ops
.search_close
= cvfs_search_close
;
1132 ops
.trans
= cvfs_trans
;
1133 ops
.logoff
= cvfs_logoff
;
1134 ops
.async_setup
= cvfs_async_setup
;
1135 ops
.cancel
= cvfs_cancel
;
1136 ops
.notify
= cvfs_notify
;
1137 ops
.trans2
= cvfs_trans2
;
1139 /* register ourselves with the NTVFS subsystem. We register
1140 under the name 'cifs'. */
1141 ret
= ntvfs_register(&ops
, &vers
);
1143 if (!NT_STATUS_IS_OK(ret
)) {
1144 DEBUG(0,("Failed to register CIFS backend!\n"));