2 Unix SMB/CIFS implementation.
3 default IPC$ NTVFS backend
5 Copyright (C) Andrew Tridgell 2003
6 Copyright (C) Stefan (metze) Metzmacher 2004-2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 this implements the IPC$ backend, called by the NTVFS subsystem to
23 handle requests on IPC$ shares
28 #include "../lib/util/dlinklist.h"
29 #include "ntvfs/ntvfs.h"
30 #include "libcli/rap/rap.h"
31 #include "ntvfs/ipc/proto.h"
32 #include "libcli/raw/ioctl.h"
33 #include "param/param.h"
34 #include "../lib/tsocket/tsocket.h"
35 #include "../libcli/named_pipe_auth/npa_tstream.h"
36 #include "auth/auth.h"
37 #include "auth/auth_sam_reply.h"
38 #include "lib/socket/socket.h"
39 #include "auth/credentials/credentials.h"
40 #include "auth/credentials/credentials_krb5.h"
41 #include <gssapi/gssapi.h>
42 #include "system/locale.h"
44 /* this is the private structure used to keep the state of an open
45 ipc$ connection. It needs to keep information about all open
48 struct ntvfs_module_context
*ntvfs
;
50 /* a list of open pipes */
52 struct pipe_state
*next
, *prev
;
53 struct ipc_private
*ipriv
;
54 const char *pipe_name
;
55 struct ntvfs_handle
*handle
;
56 struct tstream_context
*npipe
;
58 uint16_t device_state
;
59 uint64_t allocation_size
;
60 struct tevent_queue
*write_queue
;
61 struct tevent_queue
*read_queue
;
67 find a open pipe give a file handle
69 static struct pipe_state
*pipe_state_find(struct ipc_private
*ipriv
, struct ntvfs_handle
*handle
)
74 p
= ntvfs_handle_get_backend_data(handle
, ipriv
->ntvfs
);
77 s
= talloc_get_type(p
, struct pipe_state
);
84 find a open pipe give a wire fnum
86 static struct pipe_state
*pipe_state_find_key(struct ipc_private
*ipriv
, struct ntvfs_request
*req
, const DATA_BLOB
*key
)
88 struct ntvfs_handle
*h
;
90 h
= ntvfs_handle_search_by_wire_key(ipriv
->ntvfs
, req
, key
);
93 return pipe_state_find(ipriv
, h
);
98 connect to a share - always works
100 static NTSTATUS
ipc_connect(struct ntvfs_module_context
*ntvfs
,
101 struct ntvfs_request
*req
,
102 union smb_tcon
* tcon
)
104 struct ipc_private
*ipriv
;
105 const char *sharename
;
107 switch (tcon
->generic
.level
) {
109 sharename
= tcon
->tcon
.in
.service
;
112 sharename
= tcon
->tconx
.in
.path
;
115 sharename
= tcon
->smb2
.in
.path
;
118 return NT_STATUS_INVALID_LEVEL
;
121 if (strncmp(sharename
, "\\\\", 2) == 0) {
122 char *p
= strchr(sharename
+2, '\\');
128 ntvfs
->ctx
->fs_type
= talloc_strdup(ntvfs
->ctx
, "IPC");
129 NT_STATUS_HAVE_NO_MEMORY(ntvfs
->ctx
->fs_type
);
131 ntvfs
->ctx
->dev_type
= talloc_strdup(ntvfs
->ctx
, "IPC");
132 NT_STATUS_HAVE_NO_MEMORY(ntvfs
->ctx
->dev_type
);
134 if (tcon
->generic
.level
== RAW_TCON_TCONX
) {
135 tcon
->tconx
.out
.fs_type
= ntvfs
->ctx
->fs_type
;
136 tcon
->tconx
.out
.dev_type
= ntvfs
->ctx
->dev_type
;
139 /* prepare the private state for this connection */
140 ipriv
= talloc(ntvfs
, struct ipc_private
);
141 NT_STATUS_HAVE_NO_MEMORY(ipriv
);
143 ntvfs
->private_data
= ipriv
;
145 ipriv
->ntvfs
= ntvfs
;
146 ipriv
->pipe_list
= NULL
;
152 disconnect from a share
154 static NTSTATUS
ipc_disconnect(struct ntvfs_module_context
*ntvfs
)
162 static NTSTATUS
ipc_unlink(struct ntvfs_module_context
*ntvfs
,
163 struct ntvfs_request
*req
,
164 union smb_unlink
*unl
)
166 return NT_STATUS_ACCESS_DENIED
;
170 check if a directory exists
172 static NTSTATUS
ipc_chkpath(struct ntvfs_module_context
*ntvfs
,
173 struct ntvfs_request
*req
,
174 union smb_chkpath
*cp
)
176 return NT_STATUS_ACCESS_DENIED
;
180 return info on a pathname
182 static NTSTATUS
ipc_qpathinfo(struct ntvfs_module_context
*ntvfs
,
183 struct ntvfs_request
*req
, union smb_fileinfo
*info
)
185 switch (info
->generic
.level
) {
186 case RAW_FILEINFO_GENERIC
:
187 return NT_STATUS_INVALID_DEVICE_REQUEST
;
188 case RAW_FILEINFO_GETATTR
:
189 return NT_STATUS_ACCESS_DENIED
;
191 return ntvfs_map_qpathinfo(ntvfs
, req
, info
);
196 set info on a pathname
198 static NTSTATUS
ipc_setpathinfo(struct ntvfs_module_context
*ntvfs
,
199 struct ntvfs_request
*req
, union smb_setfileinfo
*st
)
201 return NT_STATUS_ACCESS_DENIED
;
206 destroy a open pipe structure
208 static int ipc_fd_destructor(struct pipe_state
*p
)
210 DLIST_REMOVE(p
->ipriv
->pipe_list
, p
);
211 ntvfs_handle_remove_backend_data(p
->handle
, p
->ipriv
->ntvfs
);
215 struct ipc_open_state
{
216 struct ipc_private
*ipriv
;
217 struct pipe_state
*p
;
218 struct ntvfs_request
*req
;
220 struct netr_SamInfo3
*info3
;
223 static void ipc_open_done(struct tevent_req
*subreq
);
226 check the pipename is valid
228 static NTSTATUS
validate_pipename(const char *name
)
231 if (!isalnum(*name
)) return NT_STATUS_INVALID_PARAMETER
;
238 open a file - used for MSRPC pipes
240 static NTSTATUS
ipc_open(struct ntvfs_module_context
*ntvfs
,
241 struct ntvfs_request
*req
, union smb_open
*oi
)
244 struct pipe_state
*p
;
245 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
247 struct smb_iconv_convenience
*smb_ic
248 = lp_iconv_convenience(ipriv
->ntvfs
->ctx
->lp_ctx
);
249 struct ntvfs_handle
*h
;
250 struct ipc_open_state
*state
;
251 struct tevent_req
*subreq
;
253 const char *directory
;
254 struct socket_address
*client_sa
;
255 struct tsocket_address
*client_addr
;
256 struct socket_address
*server_sa
;
257 struct tsocket_address
*server_addr
;
259 DATA_BLOB delegated_creds
= data_blob_null
;
261 switch (oi
->generic
.level
) {
262 case RAW_OPEN_NTCREATEX
:
263 fname
= oi
->ntcreatex
.in
.fname
;
266 fname
= oi
->openx
.in
.fname
;
269 fname
= oi
->smb2
.in
.fname
;
272 status
= NT_STATUS_NOT_SUPPORTED
;
276 directory
= talloc_asprintf(req
, "%s/np",
277 lp_ncalrpc_dir(ipriv
->ntvfs
->ctx
->lp_ctx
));
278 NT_STATUS_HAVE_NO_MEMORY(directory
);
280 state
= talloc(req
, struct ipc_open_state
);
281 NT_STATUS_HAVE_NO_MEMORY(state
);
283 status
= ntvfs_handle_new(ntvfs
, req
, &h
);
284 NT_STATUS_NOT_OK_RETURN(status
);
286 p
= talloc(h
, struct pipe_state
);
287 NT_STATUS_HAVE_NO_MEMORY(p
);
289 while (fname
[0] == '\\') fname
++;
291 /* check for valid characters in name */
292 fname
= strlower_talloc(p
, fname
);
294 status
= validate_pipename(fname
);
295 NT_STATUS_NOT_OK_RETURN(status
);
297 p
->pipe_name
= talloc_asprintf(p
, "\\pipe\\%s", fname
);
298 NT_STATUS_HAVE_NO_MEMORY(p
->pipe_name
);
303 p
->write_queue
= tevent_queue_create(p
, "ipc_write_queue");
304 NT_STATUS_HAVE_NO_MEMORY(p
->write_queue
);
306 p
->read_queue
= tevent_queue_create(p
, "ipc_read_queue");
307 NT_STATUS_HAVE_NO_MEMORY(p
->read_queue
);
309 state
->ipriv
= ipriv
;
314 status
= auth_convert_server_info_saminfo3(state
,
315 req
->session_info
->server_info
,
317 NT_STATUS_NOT_OK_RETURN(status
);
319 client_sa
= ntvfs_get_peer_addr(ntvfs
, state
);
321 return NT_STATUS_INTERNAL_ERROR
;
324 server_sa
= ntvfs_get_my_addr(ntvfs
, state
);
326 return NT_STATUS_INTERNAL_ERROR
;
329 ret
= tsocket_address_inet_from_strings(state
, "ip",
334 status
= map_nt_error_from_unix(errno
);
338 ret
= tsocket_address_inet_from_strings(state
, "ip",
343 status
= map_nt_error_from_unix(errno
);
347 if (req
->session_info
->credentials
) {
348 struct gssapi_creds_container
*gcc
;
350 OM_uint32 minor_status
;
351 gss_buffer_desc cred_token
;
353 ret
= cli_credentials_get_client_gss_creds(req
->session_info
->credentials
,
354 ipriv
->ntvfs
->ctx
->event_ctx
,
355 ipriv
->ntvfs
->ctx
->lp_ctx
,
361 gret
= gss_export_cred(&minor_status
,
364 if (gret
!= GSS_S_COMPLETE
) {
365 return NT_STATUS_INTERNAL_ERROR
;
368 if (cred_token
.length
) {
369 delegated_creds
= data_blob_talloc(req
,
372 gss_release_buffer(&minor_status
, &cred_token
);
373 NT_STATUS_HAVE_NO_MEMORY(delegated_creds
.data
);
379 subreq
= tstream_npa_connect_send(p
,
380 ipriv
->ntvfs
->ctx
->event_ctx
,
389 req
->session_info
->session_key
,
391 NT_STATUS_HAVE_NO_MEMORY(subreq
);
392 tevent_req_set_callback(subreq
, ipc_open_done
, state
);
394 req
->async_states
->state
|= NTVFS_ASYNC_STATE_ASYNC
;
398 static void ipc_open_done(struct tevent_req
*subreq
)
400 struct ipc_open_state
*state
= tevent_req_callback_data(subreq
,
401 struct ipc_open_state
);
402 struct ipc_private
*ipriv
= state
->ipriv
;
403 struct pipe_state
*p
= state
->p
;
404 struct ntvfs_request
*req
= state
->req
;
405 union smb_open
*oi
= state
->oi
;
410 ret
= tstream_npa_connect_recv(subreq
, &sys_errno
,
414 &p
->allocation_size
);
417 status
= map_nt_error_from_unix(sys_errno
);
421 DLIST_ADD(ipriv
->pipe_list
, p
);
422 talloc_set_destructor(p
, ipc_fd_destructor
);
424 status
= ntvfs_handle_set_backend_data(p
->handle
, ipriv
->ntvfs
, p
);
425 if (!NT_STATUS_IS_OK(status
)) {
429 switch (oi
->generic
.level
) {
430 case RAW_OPEN_NTCREATEX
:
431 ZERO_STRUCT(oi
->ntcreatex
.out
);
432 oi
->ntcreatex
.out
.file
.ntvfs
= p
->handle
;
433 oi
->ntcreatex
.out
.oplock_level
= 0;
434 oi
->ntcreatex
.out
.create_action
= NTCREATEX_ACTION_EXISTED
;
435 oi
->ntcreatex
.out
.create_time
= 0;
436 oi
->ntcreatex
.out
.access_time
= 0;
437 oi
->ntcreatex
.out
.write_time
= 0;
438 oi
->ntcreatex
.out
.change_time
= 0;
439 oi
->ntcreatex
.out
.attrib
= FILE_ATTRIBUTE_NORMAL
;
440 oi
->ntcreatex
.out
.alloc_size
= p
->allocation_size
;
441 oi
->ntcreatex
.out
.size
= 0;
442 oi
->ntcreatex
.out
.file_type
= p
->file_type
;
443 oi
->ntcreatex
.out
.ipc_state
= p
->device_state
;
444 oi
->ntcreatex
.out
.is_directory
= 0;
447 ZERO_STRUCT(oi
->openx
.out
);
448 oi
->openx
.out
.file
.ntvfs
= p
->handle
;
449 oi
->openx
.out
.attrib
= FILE_ATTRIBUTE_NORMAL
;
450 oi
->openx
.out
.write_time
= 0;
451 oi
->openx
.out
.size
= 0;
452 oi
->openx
.out
.access
= 0;
453 oi
->openx
.out
.ftype
= p
->file_type
;
454 oi
->openx
.out
.devstate
= p
->device_state
;
455 oi
->openx
.out
.action
= 0;
456 oi
->openx
.out
.unique_fid
= 0;
457 oi
->openx
.out
.access_mask
= 0;
458 oi
->openx
.out
.unknown
= 0;
461 ZERO_STRUCT(oi
->smb2
.out
);
462 oi
->smb2
.out
.file
.ntvfs
= p
->handle
;
463 oi
->smb2
.out
.oplock_level
= oi
->smb2
.in
.oplock_level
;
464 oi
->smb2
.out
.create_action
= NTCREATEX_ACTION_EXISTED
;
465 oi
->smb2
.out
.create_time
= 0;
466 oi
->smb2
.out
.access_time
= 0;
467 oi
->smb2
.out
.write_time
= 0;
468 oi
->smb2
.out
.change_time
= 0;
469 oi
->smb2
.out
.alloc_size
= p
->allocation_size
;
470 oi
->smb2
.out
.size
= 0;
471 oi
->smb2
.out
.file_attr
= FILE_ATTRIBUTE_NORMAL
;
472 oi
->smb2
.out
.reserved2
= 0;
479 req
->async_states
->status
= status
;
480 req
->async_states
->send_fn(req
);
486 static NTSTATUS
ipc_mkdir(struct ntvfs_module_context
*ntvfs
,
487 struct ntvfs_request
*req
, union smb_mkdir
*md
)
489 return NT_STATUS_ACCESS_DENIED
;
495 static NTSTATUS
ipc_rmdir(struct ntvfs_module_context
*ntvfs
,
496 struct ntvfs_request
*req
, struct smb_rmdir
*rd
)
498 return NT_STATUS_ACCESS_DENIED
;
502 rename a set of files
504 static NTSTATUS
ipc_rename(struct ntvfs_module_context
*ntvfs
,
505 struct ntvfs_request
*req
, union smb_rename
*ren
)
507 return NT_STATUS_ACCESS_DENIED
;
513 static NTSTATUS
ipc_copy(struct ntvfs_module_context
*ntvfs
,
514 struct ntvfs_request
*req
, struct smb_copy
*cp
)
516 return NT_STATUS_ACCESS_DENIED
;
519 struct ipc_readv_next_vector_state
{
526 static void ipc_readv_next_vector_init(struct ipc_readv_next_vector_state
*s
,
527 uint8_t *buf
, size_t len
)
532 s
->len
= MIN(len
, UINT16_MAX
);
533 //DEBUG(0,("readv_next_vector_init[%u 0x%04X]\n", s->len, s->len));
536 static int ipc_readv_next_vector(struct tstream_context
*stream
,
539 struct iovec
**_vector
,
542 struct ipc_readv_next_vector_state
*state
=
543 (struct ipc_readv_next_vector_state
*)private_data
;
544 struct iovec
*vector
;
548 if (state
->ofs
== state
->len
) {
551 // DEBUG(0,("readv_next_vector done ofs[%u 0x%04X]\n",
552 // state->ofs, state->ofs));
556 pending
= tstream_pending_bytes(stream
);
561 if (pending
== 0 && state
->ofs
!= 0) {
562 /* return a short read */
565 // DEBUG(0,("readv_next_vector short read ofs[%u 0x%04X]\n",
566 // state->ofs, state->ofs));
571 /* we want at least one byte and recheck again */
574 size_t missing
= state
->len
- state
->ofs
;
575 if (pending
> missing
) {
576 /* there's more available */
577 state
->remaining
= pending
- missing
;
580 /* read what we can get and recheck in the next cycle */
585 vector
= talloc_array(mem_ctx
, struct iovec
, 1);
590 vector
[0].iov_base
= state
->buf
+ state
->ofs
;
591 vector
[0].iov_len
= wanted
;
593 state
->ofs
+= wanted
;
600 struct ipc_read_state
{
601 struct ipc_private
*ipriv
;
602 struct pipe_state
*p
;
603 struct ntvfs_request
*req
;
605 struct ipc_readv_next_vector_state next_vector
;
608 static void ipc_read_done(struct tevent_req
*subreq
);
613 static NTSTATUS
ipc_read(struct ntvfs_module_context
*ntvfs
,
614 struct ntvfs_request
*req
, union smb_read
*rd
)
616 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
618 struct pipe_state
*p
;
619 struct ipc_read_state
*state
;
620 struct tevent_req
*subreq
;
622 if (rd
->generic
.level
!= RAW_READ_GENERIC
) {
623 return ntvfs_map_read(ntvfs
, req
, rd
);
626 p
= pipe_state_find(ipriv
, rd
->readx
.in
.file
.ntvfs
);
628 return NT_STATUS_INVALID_HANDLE
;
631 state
= talloc(req
, struct ipc_read_state
);
632 NT_STATUS_HAVE_NO_MEMORY(state
);
634 state
->ipriv
= ipriv
;
639 /* rd->readx.out.data is already allocated */
640 ipc_readv_next_vector_init(&state
->next_vector
,
642 rd
->readx
.in
.maxcnt
);
644 subreq
= tstream_readv_pdu_queue_send(req
,
645 ipriv
->ntvfs
->ctx
->event_ctx
,
648 ipc_readv_next_vector
,
649 &state
->next_vector
);
650 NT_STATUS_HAVE_NO_MEMORY(subreq
);
651 tevent_req_set_callback(subreq
, ipc_read_done
, state
);
653 req
->async_states
->state
|= NTVFS_ASYNC_STATE_ASYNC
;
657 static void ipc_read_done(struct tevent_req
*subreq
)
659 struct ipc_read_state
*state
=
660 tevent_req_callback_data(subreq
,
661 struct ipc_read_state
);
662 struct ntvfs_request
*req
= state
->req
;
663 union smb_read
*rd
= state
->rd
;
668 ret
= tstream_readv_pdu_queue_recv(subreq
, &sys_errno
);
671 status
= map_nt_error_from_unix(sys_errno
);
675 status
= NT_STATUS_OK
;
676 if (state
->next_vector
.remaining
> 0) {
677 status
= STATUS_BUFFER_OVERFLOW
;
680 rd
->readx
.out
.remaining
= state
->next_vector
.remaining
;
681 rd
->readx
.out
.compaction_mode
= 0;
682 rd
->readx
.out
.nread
= ret
;
685 req
->async_states
->status
= status
;
686 req
->async_states
->send_fn(req
);
689 struct ipc_write_state
{
690 struct ipc_private
*ipriv
;
691 struct pipe_state
*p
;
692 struct ntvfs_request
*req
;
697 static void ipc_write_done(struct tevent_req
*subreq
);
702 static NTSTATUS
ipc_write(struct ntvfs_module_context
*ntvfs
,
703 struct ntvfs_request
*req
, union smb_write
*wr
)
705 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
707 struct pipe_state
*p
;
708 struct tevent_req
*subreq
;
709 struct ipc_write_state
*state
;
711 if (wr
->generic
.level
!= RAW_WRITE_GENERIC
) {
712 return ntvfs_map_write(ntvfs
, req
, wr
);
715 p
= pipe_state_find(ipriv
, wr
->writex
.in
.file
.ntvfs
);
717 return NT_STATUS_INVALID_HANDLE
;
720 state
= talloc(req
, struct ipc_write_state
);
721 NT_STATUS_HAVE_NO_MEMORY(state
);
723 state
->ipriv
= ipriv
;
727 state
->iov
.iov_base
= discard_const_p(void, wr
->writex
.in
.data
);
728 state
->iov
.iov_len
= wr
->writex
.in
.count
;
730 subreq
= tstream_writev_queue_send(state
,
731 ipriv
->ntvfs
->ctx
->event_ctx
,
735 NT_STATUS_HAVE_NO_MEMORY(subreq
);
736 tevent_req_set_callback(subreq
, ipc_write_done
, state
);
738 req
->async_states
->state
|= NTVFS_ASYNC_STATE_ASYNC
;
742 static void ipc_write_done(struct tevent_req
*subreq
)
744 struct ipc_write_state
*state
=
745 tevent_req_callback_data(subreq
,
746 struct ipc_write_state
);
747 struct ntvfs_request
*req
= state
->req
;
748 union smb_write
*wr
= state
->wr
;
753 ret
= tstream_writev_queue_recv(subreq
, &sys_errno
);
756 status
= map_nt_error_from_unix(sys_errno
);
760 status
= NT_STATUS_OK
;
762 wr
->writex
.out
.nwritten
= ret
;
763 wr
->writex
.out
.remaining
= 0;
766 req
->async_states
->status
= status
;
767 req
->async_states
->send_fn(req
);
773 static NTSTATUS
ipc_seek(struct ntvfs_module_context
*ntvfs
,
774 struct ntvfs_request
*req
,
777 return NT_STATUS_ACCESS_DENIED
;
783 static NTSTATUS
ipc_flush(struct ntvfs_module_context
*ntvfs
,
784 struct ntvfs_request
*req
,
787 return NT_STATUS_ACCESS_DENIED
;
793 static NTSTATUS
ipc_close(struct ntvfs_module_context
*ntvfs
,
794 struct ntvfs_request
*req
, union smb_close
*io
)
796 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
798 struct pipe_state
*p
;
800 if (io
->generic
.level
!= RAW_CLOSE_CLOSE
) {
801 return ntvfs_map_close(ntvfs
, req
, io
);
804 p
= pipe_state_find(ipriv
, io
->close
.in
.file
.ntvfs
);
806 return NT_STATUS_INVALID_HANDLE
;
817 static NTSTATUS
ipc_exit(struct ntvfs_module_context
*ntvfs
,
818 struct ntvfs_request
*req
)
820 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
822 struct pipe_state
*p
, *next
;
824 for (p
=ipriv
->pipe_list
; p
; p
=next
) {
826 if (p
->handle
->session_info
== req
->session_info
&&
827 p
->handle
->smbpid
== req
->smbpid
) {
836 logoff - closing files open by the user
838 static NTSTATUS
ipc_logoff(struct ntvfs_module_context
*ntvfs
,
839 struct ntvfs_request
*req
)
841 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
843 struct pipe_state
*p
, *next
;
845 for (p
=ipriv
->pipe_list
; p
; p
=next
) {
847 if (p
->handle
->session_info
== req
->session_info
) {
856 setup for an async call
858 static NTSTATUS
ipc_async_setup(struct ntvfs_module_context
*ntvfs
,
859 struct ntvfs_request
*req
,
868 static NTSTATUS
ipc_cancel(struct ntvfs_module_context
*ntvfs
,
869 struct ntvfs_request
*req
)
871 return NT_STATUS_UNSUCCESSFUL
;
877 static NTSTATUS
ipc_lock(struct ntvfs_module_context
*ntvfs
,
878 struct ntvfs_request
*req
, union smb_lock
*lck
)
880 return NT_STATUS_ACCESS_DENIED
;
884 set info on a open file
886 static NTSTATUS
ipc_setfileinfo(struct ntvfs_module_context
*ntvfs
,
887 struct ntvfs_request
*req
, union smb_setfileinfo
*info
)
889 return NT_STATUS_ACCESS_DENIED
;
893 query info on a open file
895 static NTSTATUS
ipc_qfileinfo(struct ntvfs_module_context
*ntvfs
,
896 struct ntvfs_request
*req
, union smb_fileinfo
*info
)
898 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
900 struct pipe_state
*p
= pipe_state_find(ipriv
, info
->generic
.in
.file
.ntvfs
);
902 return NT_STATUS_INVALID_HANDLE
;
904 switch (info
->generic
.level
) {
905 case RAW_FILEINFO_GENERIC
:
907 ZERO_STRUCT(info
->generic
.out
);
908 info
->generic
.out
.attrib
= FILE_ATTRIBUTE_NORMAL
;
909 info
->generic
.out
.fname
.s
= strrchr(p
->pipe_name
, '\\');
910 info
->generic
.out
.alloc_size
= 4096;
911 info
->generic
.out
.nlink
= 1;
912 /* What the heck? Match Win2k3: IPC$ pipes are delete pending */
913 info
->generic
.out
.delete_pending
= 1;
916 case RAW_FILEINFO_ALT_NAME_INFO
:
917 case RAW_FILEINFO_ALT_NAME_INFORMATION
:
918 case RAW_FILEINFO_STREAM_INFO
:
919 case RAW_FILEINFO_STREAM_INFORMATION
:
920 case RAW_FILEINFO_COMPRESSION_INFO
:
921 case RAW_FILEINFO_COMPRESSION_INFORMATION
:
922 case RAW_FILEINFO_NETWORK_OPEN_INFORMATION
:
923 case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION
:
924 return NT_STATUS_INVALID_PARAMETER
;
925 case RAW_FILEINFO_ALL_EAS
:
926 return NT_STATUS_ACCESS_DENIED
;
928 return ntvfs_map_qfileinfo(ntvfs
, req
, info
);
931 return NT_STATUS_ACCESS_DENIED
;
936 return filesystem info
938 static NTSTATUS
ipc_fsinfo(struct ntvfs_module_context
*ntvfs
,
939 struct ntvfs_request
*req
, union smb_fsinfo
*fs
)
941 return NT_STATUS_ACCESS_DENIED
;
945 return print queue info
947 static NTSTATUS
ipc_lpq(struct ntvfs_module_context
*ntvfs
,
948 struct ntvfs_request
*req
, union smb_lpq
*lpq
)
950 return NT_STATUS_ACCESS_DENIED
;
954 list files in a directory matching a wildcard pattern
956 static NTSTATUS
ipc_search_first(struct ntvfs_module_context
*ntvfs
,
957 struct ntvfs_request
*req
, union smb_search_first
*io
,
958 void *search_private
,
959 bool (*callback
)(void *, const union smb_search_data
*))
961 return NT_STATUS_ACCESS_DENIED
;
965 continue listing files in a directory
967 static NTSTATUS
ipc_search_next(struct ntvfs_module_context
*ntvfs
,
968 struct ntvfs_request
*req
, union smb_search_next
*io
,
969 void *search_private
,
970 bool (*callback
)(void *, const union smb_search_data
*))
972 return NT_STATUS_ACCESS_DENIED
;
976 end listing files in a directory
978 static NTSTATUS
ipc_search_close(struct ntvfs_module_context
*ntvfs
,
979 struct ntvfs_request
*req
, union smb_search_close
*io
)
981 return NT_STATUS_ACCESS_DENIED
;
984 struct ipc_trans_state
{
985 struct ipc_private
*ipriv
;
986 struct pipe_state
*p
;
987 struct ntvfs_request
*req
;
988 struct smb_trans2
*trans
;
989 struct iovec writev_iov
;
990 struct ipc_readv_next_vector_state next_vector
;
993 static void ipc_trans_writev_done(struct tevent_req
*subreq
);
994 static void ipc_trans_readv_done(struct tevent_req
*subreq
);
996 /* SMBtrans - handle a DCERPC command */
997 static NTSTATUS
ipc_dcerpc_cmd(struct ntvfs_module_context
*ntvfs
,
998 struct ntvfs_request
*req
, struct smb_trans2
*trans
)
1000 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
1001 struct ipc_private
);
1002 struct pipe_state
*p
;
1005 struct ipc_trans_state
*state
;
1006 struct tevent_req
*subreq
;
1009 * the fnum is in setup[1], a 16 bit value
1010 * the setup[*] values are already in host byteorder
1011 * but ntvfs_handle_search_by_wire_key() expects
1014 SSVAL(&fnum
, 0, trans
->in
.setup
[1]);
1015 fnum_key
= data_blob_const(&fnum
, 2);
1017 p
= pipe_state_find_key(ipriv
, req
, &fnum_key
);
1019 return NT_STATUS_INVALID_HANDLE
;
1023 * Trans requests are only allowed
1024 * if no other Trans or Read is active
1026 if (tevent_queue_length(p
->read_queue
) > 0) {
1027 return NT_STATUS_PIPE_BUSY
;
1030 state
= talloc(req
, struct ipc_trans_state
);
1031 NT_STATUS_HAVE_NO_MEMORY(state
);
1033 trans
->out
.setup_count
= 0;
1034 trans
->out
.setup
= NULL
;
1035 trans
->out
.params
= data_blob(NULL
, 0);
1036 trans
->out
.data
= data_blob_talloc(req
, NULL
, trans
->in
.max_data
);
1037 NT_STATUS_HAVE_NO_MEMORY(trans
->out
.data
.data
);
1039 state
->ipriv
= ipriv
;
1042 state
->trans
= trans
;
1043 state
->writev_iov
.iov_base
= trans
->in
.data
.data
;
1044 state
->writev_iov
.iov_len
= trans
->in
.data
.length
;
1046 ipc_readv_next_vector_init(&state
->next_vector
,
1047 trans
->out
.data
.data
,
1048 trans
->out
.data
.length
);
1050 subreq
= tstream_writev_queue_send(state
,
1051 ipriv
->ntvfs
->ctx
->event_ctx
,
1054 &state
->writev_iov
, 1);
1055 NT_STATUS_HAVE_NO_MEMORY(subreq
);
1056 tevent_req_set_callback(subreq
, ipc_trans_writev_done
, state
);
1058 req
->async_states
->state
|= NTVFS_ASYNC_STATE_ASYNC
;
1059 return NT_STATUS_OK
;
1062 static void ipc_trans_writev_done(struct tevent_req
*subreq
)
1064 struct ipc_trans_state
*state
=
1065 tevent_req_callback_data(subreq
,
1066 struct ipc_trans_state
);
1067 struct ipc_private
*ipriv
= state
->ipriv
;
1068 struct pipe_state
*p
= state
->p
;
1069 struct ntvfs_request
*req
= state
->req
;
1074 ret
= tstream_writev_queue_recv(subreq
, &sys_errno
);
1075 TALLOC_FREE(subreq
);
1077 status
= NT_STATUS_PIPE_DISCONNECTED
;
1079 } else if (ret
== -1) {
1080 status
= map_nt_error_from_unix(sys_errno
);
1084 subreq
= tstream_readv_pdu_queue_send(state
,
1085 ipriv
->ntvfs
->ctx
->event_ctx
,
1088 ipc_readv_next_vector
,
1089 &state
->next_vector
);
1091 status
= NT_STATUS_NO_MEMORY
;
1094 tevent_req_set_callback(subreq
, ipc_trans_readv_done
, state
);
1098 req
->async_states
->status
= status
;
1099 req
->async_states
->send_fn(req
);
1102 static void ipc_trans_readv_done(struct tevent_req
*subreq
)
1104 struct ipc_trans_state
*state
=
1105 tevent_req_callback_data(subreq
,
1106 struct ipc_trans_state
);
1107 struct ntvfs_request
*req
= state
->req
;
1108 struct smb_trans2
*trans
= state
->trans
;
1113 ret
= tstream_readv_pdu_queue_recv(subreq
, &sys_errno
);
1114 TALLOC_FREE(subreq
);
1116 status
= map_nt_error_from_unix(sys_errno
);
1120 status
= NT_STATUS_OK
;
1121 if (state
->next_vector
.remaining
> 0) {
1122 status
= STATUS_BUFFER_OVERFLOW
;
1125 trans
->out
.data
.length
= ret
;
1128 req
->async_states
->status
= status
;
1129 req
->async_states
->send_fn(req
);
1132 /* SMBtrans - set named pipe state */
1133 static NTSTATUS
ipc_set_nm_pipe_state(struct ntvfs_module_context
*ntvfs
,
1134 struct ntvfs_request
*req
, struct smb_trans2
*trans
)
1136 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
1137 struct ipc_private
);
1138 struct pipe_state
*p
;
1141 /* the fnum is in setup[1] */
1142 fnum_key
= data_blob_const(&trans
->in
.setup
[1], sizeof(trans
->in
.setup
[1]));
1144 p
= pipe_state_find_key(ipriv
, req
, &fnum_key
);
1146 return NT_STATUS_INVALID_HANDLE
;
1149 if (trans
->in
.params
.length
!= 2) {
1150 return NT_STATUS_INVALID_PARAMETER
;
1154 * TODO: pass this to the tstream_npa logic
1156 p
->device_state
= SVAL(trans
->in
.params
.data
, 0);
1158 trans
->out
.setup_count
= 0;
1159 trans
->out
.setup
= NULL
;
1160 trans
->out
.params
= data_blob(NULL
, 0);
1161 trans
->out
.data
= data_blob(NULL
, 0);
1163 return NT_STATUS_OK
;
1167 /* SMBtrans - used to provide access to SMB pipes */
1168 static NTSTATUS
ipc_trans(struct ntvfs_module_context
*ntvfs
,
1169 struct ntvfs_request
*req
, struct smb_trans2
*trans
)
1173 if (strequal(trans
->in
.trans_name
, "\\PIPE\\LANMAN"))
1174 return ipc_rap_call(req
, ntvfs
->ctx
->event_ctx
, ntvfs
->ctx
->lp_ctx
, trans
);
1176 if (trans
->in
.setup_count
!= 2) {
1177 return NT_STATUS_INVALID_PARAMETER
;
1180 switch (trans
->in
.setup
[0]) {
1181 case TRANSACT_SETNAMEDPIPEHANDLESTATE
:
1182 status
= ipc_set_nm_pipe_state(ntvfs
, req
, trans
);
1184 case TRANSACT_DCERPCCMD
:
1185 status
= ipc_dcerpc_cmd(ntvfs
, req
, trans
);
1188 status
= NT_STATUS_INVALID_PARAMETER
;
1195 struct ipc_ioctl_state
{
1196 struct ipc_private
*ipriv
;
1197 struct pipe_state
*p
;
1198 struct ntvfs_request
*req
;
1199 union smb_ioctl
*io
;
1200 struct iovec writev_iov
;
1201 struct ipc_readv_next_vector_state next_vector
;
1204 static void ipc_ioctl_writev_done(struct tevent_req
*subreq
);
1205 static void ipc_ioctl_readv_done(struct tevent_req
*subreq
);
1207 static NTSTATUS
ipc_ioctl_smb2(struct ntvfs_module_context
*ntvfs
,
1208 struct ntvfs_request
*req
, union smb_ioctl
*io
)
1210 struct ipc_private
*ipriv
= talloc_get_type_abort(ntvfs
->private_data
,
1211 struct ipc_private
);
1212 struct pipe_state
*p
;
1213 struct ipc_ioctl_state
*state
;
1214 struct tevent_req
*subreq
;
1216 switch (io
->smb2
.in
.function
) {
1217 case FSCTL_NAMED_PIPE_READ_WRITE
:
1221 return NT_STATUS_FS_DRIVER_REQUIRED
;
1224 p
= pipe_state_find(ipriv
, io
->smb2
.in
.file
.ntvfs
);
1226 return NT_STATUS_INVALID_HANDLE
;
1230 * Trans requests are only allowed
1231 * if no other Trans or Read is active
1233 if (tevent_queue_length(p
->read_queue
) > 0) {
1234 return NT_STATUS_PIPE_BUSY
;
1237 state
= talloc(req
, struct ipc_ioctl_state
);
1238 NT_STATUS_HAVE_NO_MEMORY(state
);
1240 io
->smb2
.out
._pad
= 0;
1241 io
->smb2
.out
.function
= io
->smb2
.in
.function
;
1242 io
->smb2
.out
.unknown2
= 0;
1243 io
->smb2
.out
.unknown3
= 0;
1244 io
->smb2
.out
.in
= io
->smb2
.in
.out
;
1245 io
->smb2
.out
.out
= data_blob_talloc(req
, NULL
, io
->smb2
.in
.max_response_size
);
1246 NT_STATUS_HAVE_NO_MEMORY(io
->smb2
.out
.out
.data
);
1248 state
->ipriv
= ipriv
;
1252 state
->writev_iov
.iov_base
= io
->smb2
.in
.out
.data
;
1253 state
->writev_iov
.iov_len
= io
->smb2
.in
.out
.length
;
1255 ipc_readv_next_vector_init(&state
->next_vector
,
1256 io
->smb2
.out
.out
.data
,
1257 io
->smb2
.out
.out
.length
);
1259 subreq
= tstream_writev_queue_send(state
,
1260 ipriv
->ntvfs
->ctx
->event_ctx
,
1263 &state
->writev_iov
, 1);
1264 NT_STATUS_HAVE_NO_MEMORY(subreq
);
1265 tevent_req_set_callback(subreq
, ipc_ioctl_writev_done
, state
);
1267 req
->async_states
->state
|= NTVFS_ASYNC_STATE_ASYNC
;
1268 return NT_STATUS_OK
;
1271 static void ipc_ioctl_writev_done(struct tevent_req
*subreq
)
1273 struct ipc_ioctl_state
*state
=
1274 tevent_req_callback_data(subreq
,
1275 struct ipc_ioctl_state
);
1276 struct ipc_private
*ipriv
= state
->ipriv
;
1277 struct pipe_state
*p
= state
->p
;
1278 struct ntvfs_request
*req
= state
->req
;
1283 ret
= tstream_writev_queue_recv(subreq
, &sys_errno
);
1284 TALLOC_FREE(subreq
);
1286 status
= map_nt_error_from_unix(sys_errno
);
1290 subreq
= tstream_readv_pdu_queue_send(state
,
1291 ipriv
->ntvfs
->ctx
->event_ctx
,
1294 ipc_readv_next_vector
,
1295 &state
->next_vector
);
1297 status
= NT_STATUS_NO_MEMORY
;
1300 tevent_req_set_callback(subreq
, ipc_ioctl_readv_done
, state
);
1304 req
->async_states
->status
= status
;
1305 req
->async_states
->send_fn(req
);
1308 static void ipc_ioctl_readv_done(struct tevent_req
*subreq
)
1310 struct ipc_ioctl_state
*state
=
1311 tevent_req_callback_data(subreq
,
1312 struct ipc_ioctl_state
);
1313 struct ntvfs_request
*req
= state
->req
;
1314 union smb_ioctl
*io
= state
->io
;
1319 ret
= tstream_readv_pdu_queue_recv(subreq
, &sys_errno
);
1320 TALLOC_FREE(subreq
);
1322 status
= map_nt_error_from_unix(sys_errno
);
1326 status
= NT_STATUS_OK
;
1327 if (state
->next_vector
.remaining
> 0) {
1328 status
= STATUS_BUFFER_OVERFLOW
;
1331 io
->smb2
.out
.out
.length
= ret
;
1334 req
->async_states
->status
= status
;
1335 req
->async_states
->send_fn(req
);
1341 static NTSTATUS
ipc_ioctl(struct ntvfs_module_context
*ntvfs
,
1342 struct ntvfs_request
*req
, union smb_ioctl
*io
)
1344 switch (io
->generic
.level
) {
1345 case RAW_IOCTL_SMB2
:
1346 return ipc_ioctl_smb2(ntvfs
, req
, io
);
1348 case RAW_IOCTL_SMB2_NO_HANDLE
:
1349 return NT_STATUS_FS_DRIVER_REQUIRED
;
1352 return NT_STATUS_ACCESS_DENIED
;
1355 return NT_STATUS_ACCESS_DENIED
;
1360 initialialise the IPC backend, registering ourselves with the ntvfs subsystem
1362 NTSTATUS
ntvfs_ipc_init(void)
1365 struct ntvfs_ops ops
;
1366 NTVFS_CURRENT_CRITICAL_SIZES(vers
);
1370 /* fill in the name and type */
1371 ops
.name
= "default";
1372 ops
.type
= NTVFS_IPC
;
1374 /* fill in all the operations */
1375 ops
.connect
= ipc_connect
;
1376 ops
.disconnect
= ipc_disconnect
;
1377 ops
.unlink
= ipc_unlink
;
1378 ops
.chkpath
= ipc_chkpath
;
1379 ops
.qpathinfo
= ipc_qpathinfo
;
1380 ops
.setpathinfo
= ipc_setpathinfo
;
1381 ops
.open
= ipc_open
;
1382 ops
.mkdir
= ipc_mkdir
;
1383 ops
.rmdir
= ipc_rmdir
;
1384 ops
.rename
= ipc_rename
;
1385 ops
.copy
= ipc_copy
;
1386 ops
.ioctl
= ipc_ioctl
;
1387 ops
.read
= ipc_read
;
1388 ops
.write
= ipc_write
;
1389 ops
.seek
= ipc_seek
;
1390 ops
.flush
= ipc_flush
;
1391 ops
.close
= ipc_close
;
1392 ops
.exit
= ipc_exit
;
1393 ops
.lock
= ipc_lock
;
1394 ops
.setfileinfo
= ipc_setfileinfo
;
1395 ops
.qfileinfo
= ipc_qfileinfo
;
1396 ops
.fsinfo
= ipc_fsinfo
;
1398 ops
.search_first
= ipc_search_first
;
1399 ops
.search_next
= ipc_search_next
;
1400 ops
.search_close
= ipc_search_close
;
1401 ops
.trans
= ipc_trans
;
1402 ops
.logoff
= ipc_logoff
;
1403 ops
.async_setup
= ipc_async_setup
;
1404 ops
.cancel
= ipc_cancel
;
1406 /* register ourselves with the NTVFS subsystem. */
1407 ret
= ntvfs_register(&ops
, &vers
);
1409 if (!NT_STATUS_IS_OK(ret
)) {
1410 DEBUG(0,("Failed to register IPC backend!\n"));