2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Almost completely rewritten by (C) Jeremy Allison 2005 - 2010
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 /* this module apparently provides an implementation of DCE/RPC over a
21 * named pipe (IPC$ connection using SMBtrans). details of DCE/RPC
22 * documentation are available (in on-line form) from the X-Open group.
24 * this module should provide a level of abstraction between SMB
25 * and DCE/RPC, while minimising the amount of mallocs, unnecessary
26 * data copies, and network traffic.
31 #include "system/filesys.h"
32 #include "srv_pipe_internal.h"
33 #include "../librpc/gen_ndr/ndr_dcerpc.h"
34 #include "../librpc/rpc/rpc_common.h"
35 #include "dcesrv_auth_generic.h"
36 #include "rpc_server.h"
38 #include "smbd/smbd.h"
41 #include "rpc_server/srv_pipe.h"
42 #include "rpc_server/rpc_contexts.h"
43 #include "lib/param/param.h"
44 #include "librpc/ndr/ndr_table.h"
45 #include "auth/gensec/gensec.h"
46 #include "librpc/ndr/ndr_dcerpc.h"
47 #include "lib/tsocket/tsocket.h"
48 #include "../librpc/gen_ndr/ndr_samr.h"
49 #include "../librpc/gen_ndr/ndr_lsa.h"
50 #include "../librpc/gen_ndr/ndr_netlogon.h"
51 #include "../librpc/gen_ndr/ndr_epmapper.h"
52 #include "../librpc/gen_ndr/ndr_echo.h"
53 #include "../librpc/gen_ndr/ndr_winspool.h"
56 #define DBGC_CLASS DBGC_RPC_SRV
58 static NTSTATUS
pipe_auth_verify_final(struct pipes_struct
*p
);
61 * Dump everything from the start of the end up of the provided data
62 * into a file, but only at debug level >= 50
64 static void dump_pdu_region(const char *name
, int v
,
65 DATA_BLOB
*data
, size_t start
, size_t end
)
71 if (DEBUGLEVEL
< 50) return;
73 if (start
> data
->length
|| end
> data
->length
|| start
> end
) return;
75 for (i
= 1; i
< 100; i
++) {
77 fname
= talloc_asprintf(talloc_tos(),
81 fname
= talloc_asprintf(talloc_tos(),
88 fd
= open(fname
, O_WRONLY
|O_CREAT
|O_EXCL
, 0644);
89 if (fd
!= -1 || errno
!= EEXIST
) break;
92 sz
= write(fd
, data
->data
+ start
, end
- start
);
94 if ((sz
!= end
- start
) || (i
!= 0) ) {
95 DEBUG(0, ("Error writing/closing %s: %ld!=%ld %d\n",
96 fname
, (unsigned long)sz
,
97 (unsigned long)end
- start
, i
));
99 DEBUG(0,("created %s\n", fname
));
105 static DATA_BLOB
generic_session_key(void)
107 return data_blob_const("SystemLibraryDTC", 16);
110 /*******************************************************************
111 Generate the next PDU to be returned from the data.
112 ********************************************************************/
114 static NTSTATUS
create_next_packet(TALLOC_CTX
*mem_ctx
,
115 struct pipe_auth_data
*auth
,
118 size_t data_sent_length
,
122 union dcerpc_payload u
;
131 ZERO_STRUCT(u
.response
);
133 /* Set up rpc packet pfc flags. */
134 if (data_sent_length
== 0) {
135 pfc_flags
= DCERPC_PFC_FLAG_FIRST
;
140 /* Work out how much we can fit in a single PDU. */
141 data_left
= rdata
->length
- data_sent_length
;
143 /* Ensure there really is data left to send. */
145 DEBUG(0, ("No data left to send !\n"));
146 return NT_STATUS_BUFFER_TOO_SMALL
;
149 status
= dcerpc_guess_sizes(auth
,
150 DCERPC_RESPONSE_LENGTH
,
152 RPC_MAX_PDU_FRAG_LEN
,
153 &data_to_send
, &frag_len
,
154 &auth_len
, &pad_len
);
155 if (!NT_STATUS_IS_OK(status
)) {
159 /* Set up the alloc hint. This should be the data left to send. */
160 u
.response
.alloc_hint
= data_left
;
162 /* Work out if this PDU will be the last. */
163 if (data_sent_length
+ data_to_send
>= rdata
->length
) {
164 pfc_flags
|= DCERPC_PFC_FLAG_LAST
;
167 /* Prepare data to be NDR encoded. */
168 u
.response
.stub_and_verifier
=
169 data_blob_const(rdata
->data
+ data_sent_length
, data_to_send
);
171 /* Store the packet in the data stream. */
172 status
= dcerpc_push_ncacn_packet(mem_ctx
, DCERPC_PKT_RESPONSE
,
173 pfc_flags
, auth_len
, call_id
,
175 if (!NT_STATUS_IS_OK(status
)) {
176 DEBUG(0, ("Failed to marshall RPC Packet.\n"));
181 /* Set the proper length on the pdu, including padding.
182 * Only needed if an auth trailer will be appended. */
183 dcerpc_set_frag_length(frag
, frag
->length
185 + DCERPC_AUTH_TRAILER_LENGTH
190 status
= dcerpc_add_auth_footer(auth
, pad_len
, frag
);
191 if (!NT_STATUS_IS_OK(status
)) {
192 data_blob_free(frag
);
197 *pdu_size
= data_to_send
;
201 /*******************************************************************
202 Generate the next PDU to be returned from the data in p->rdata.
203 ********************************************************************/
205 bool create_next_pdu(struct pipes_struct
*p
)
211 * If we're in the fault state, keep returning fault PDU's until
212 * the pipe gets closed. JRA.
214 if (p
->fault_state
) {
215 setup_fault_pdu(p
, NT_STATUS(p
->fault_state
));
219 status
= create_next_packet(p
->mem_ctx
, &p
->auth
,
220 p
->call_id
, &p
->out_data
.rdata
,
221 p
->out_data
.data_sent_length
,
222 &p
->out_data
.frag
, &pdu_size
);
223 if (!NT_STATUS_IS_OK(status
)) {
224 DEBUG(0, ("Failed to create packet with error %s, "
225 "(auth level %u / type %u)\n",
227 (unsigned int)p
->auth
.auth_level
,
228 (unsigned int)p
->auth
.auth_type
));
232 /* Setup the counts for this PDU. */
233 p
->out_data
.data_sent_length
+= pdu_size
;
234 p
->out_data
.current_pdu_sent
= 0;
239 static bool pipe_init_outgoing_data(struct pipes_struct
*p
);
241 /*******************************************************************
242 Marshall a bind_nak pdu.
243 *******************************************************************/
245 static bool setup_bind_nak(struct pipes_struct
*p
, struct ncacn_packet
*pkt
)
248 union dcerpc_payload u
;
250 /* Free any memory in the current return data buffer. */
251 pipe_init_outgoing_data(p
);
254 * Initialize a bind_nak header.
259 u
.bind_nak
.reject_reason
= 0;
262 * Marshall directly into the outgoing PDU space. We
263 * must do this as we need to set to the bind response
264 * header and are never sending more than one PDU here.
267 status
= dcerpc_push_ncacn_packet(p
->mem_ctx
,
269 DCERPC_PFC_FLAG_FIRST
|
270 DCERPC_PFC_FLAG_LAST
,
275 if (!NT_STATUS_IS_OK(status
)) {
279 p
->out_data
.data_sent_length
= 0;
280 p
->out_data
.current_pdu_sent
= 0;
282 set_incoming_fault(p
);
283 TALLOC_FREE(p
->auth
.auth_ctx
);
284 p
->auth
.auth_level
= DCERPC_AUTH_LEVEL_NONE
;
285 p
->auth
.auth_type
= DCERPC_AUTH_TYPE_NONE
;
286 p
->pipe_bound
= False
;
287 p
->allow_bind
= false;
288 p
->allow_alter
= false;
289 p
->allow_auth3
= false;
294 /*******************************************************************
295 Marshall a fault pdu.
296 *******************************************************************/
298 bool setup_fault_pdu(struct pipes_struct
*p
, NTSTATUS fault_status
)
301 union dcerpc_payload u
;
303 /* Free any memory in the current return data buffer. */
304 pipe_init_outgoing_data(p
);
307 * Initialize a fault header.
312 u
.fault
.status
= NT_STATUS_V(fault_status
);
315 * Marshall directly into the outgoing PDU space. We
316 * must do this as we need to set to the bind response
317 * header and are never sending more than one PDU here.
320 status
= dcerpc_push_ncacn_packet(p
->mem_ctx
,
322 DCERPC_PFC_FLAG_FIRST
|
323 DCERPC_PFC_FLAG_LAST
|
324 DCERPC_PFC_FLAG_DID_NOT_EXECUTE
,
329 if (!NT_STATUS_IS_OK(status
)) {
333 p
->out_data
.data_sent_length
= 0;
334 p
->out_data
.current_pdu_sent
= 0;
339 /*******************************************************************
340 Ensure a bind request has the correct abstract & transfer interface.
341 Used to reject unknown binds from Win2k.
342 *******************************************************************/
344 static bool check_bind_req(struct pipes_struct
*p
,
345 struct ndr_syntax_id
* abstract
,
346 struct ndr_syntax_id
* transfer
,
349 struct pipe_rpc_fns
*context_fns
;
351 const char *interface_name
= NULL
;
353 DEBUG(3,("check_bind_req for %s context_id=%u\n",
354 ndr_interface_name(&abstract
->uuid
,
355 abstract
->if_version
),
356 (unsigned)context_id
));
358 ok
= ndr_syntax_id_equal(transfer
, &ndr_transfer_syntax_ndr
);
360 DEBUG(1,("check_bind_req unknown transfer syntax for "
361 "%s context_id=%u\n",
362 ndr_interface_name(&abstract
->uuid
,
363 abstract
->if_version
),
364 (unsigned)context_id
));
368 for (context_fns
= p
->contexts
;
370 context_fns
= context_fns
->next
)
372 if (context_fns
->context_id
!= context_id
) {
376 ok
= ndr_syntax_id_equal(&context_fns
->syntax
,
382 DEBUG(1,("check_bind_req: changing abstract syntax for "
383 "%s context_id=%u into %s not supported\n",
384 ndr_interface_name(&context_fns
->syntax
.uuid
,
385 context_fns
->syntax
.if_version
),
386 (unsigned)context_id
,
387 ndr_interface_name(&abstract
->uuid
,
388 abstract
->if_version
)));
392 /* we have to check all now since win2k introduced a new UUID on the lsaprpc pipe */
393 if (!rpc_srv_pipe_exists_by_id(abstract
)) {
397 DEBUG(3, ("check_bind_req: %s -> %s rpc service\n",
398 rpc_srv_get_pipe_cli_name(abstract
),
399 rpc_srv_get_pipe_srv_name(abstract
)));
401 ok
= init_pipe_handles(p
, abstract
);
403 DEBUG(1, ("Failed to init pipe handles!\n"));
407 context_fns
= talloc_zero(p
, struct pipe_rpc_fns
);
408 if (context_fns
== NULL
) {
409 DEBUG(0,("check_bind_req: talloc() failed!\n"));
413 interface_name
= ndr_interface_name(&abstract
->uuid
,
414 abstract
->if_version
);
415 SMB_ASSERT(interface_name
!= NULL
);
417 context_fns
->next
= context_fns
->prev
= NULL
;
418 context_fns
->n_cmds
= rpc_srv_get_pipe_num_cmds(abstract
);
419 context_fns
->cmds
= rpc_srv_get_pipe_cmds(abstract
);
420 context_fns
->context_id
= context_id
;
421 context_fns
->syntax
= *abstract
;
423 context_fns
->allow_connect
= lp_allow_dcerpc_auth_level_connect();
425 * for the samr, lsarpc and netlogon interfaces we don't allow "connect"
426 * auth_level by default.
428 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_samr
.syntax_id
);
430 context_fns
->allow_connect
= false;
432 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_lsarpc
.syntax_id
);
434 context_fns
->allow_connect
= false;
436 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_netlogon
.syntax_id
);
438 context_fns
->allow_connect
= false;
441 * for the epmapper and echo interfaces we allow "connect"
442 * auth_level by default.
444 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_epmapper
.syntax_id
);
446 context_fns
->allow_connect
= true;
448 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_rpcecho
.syntax_id
);
450 context_fns
->allow_connect
= true;
453 * every interface can be modified to allow "connect" auth_level by
454 * using a parametric option like:
455 * allow dcerpc auth level connect:<interface>
457 * allow dcerpc auth level connect:samr = yes
459 context_fns
->allow_connect
= lp_parm_bool(-1,
460 "allow dcerpc auth level connect",
461 interface_name
, context_fns
->allow_connect
);
463 ok
= ndr_syntax_id_equal(abstract
, &ndr_table_iremotewinspool
.syntax_id
);
465 context_fns
->min_auth_level
= DCERPC_AUTH_LEVEL_PACKET
;
468 /* add to the list of open contexts */
470 DLIST_ADD( p
->contexts
, context_fns
);
476 * Is a named pipe known?
477 * @param[in] pipename Just the filename
478 * @result NT error code
480 NTSTATUS
is_known_pipename(const char *pipename
, struct ndr_syntax_id
*syntax
)
484 if (strchr(pipename
, '/')) {
485 DBG_WARNING("Refusing open on pipe %s\n", pipename
);
486 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
489 if (lp_disable_spoolss() && strequal(pipename
, "spoolss")) {
490 DBG_DEBUG("refusing spoolss access\n");
491 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
494 if (rpc_srv_get_pipe_interface_by_cli_name(pipename
, syntax
)) {
498 status
= smb_probe_module("rpc", pipename
);
499 if (!NT_STATUS_IS_OK(status
)) {
500 DBG_DEBUG("Unknown pipe '%s'\n", pipename
);
501 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
503 DBG_DEBUG("'%s' loaded dynamically\n", pipename
);
506 * Scan the list again for the interface id
508 if (rpc_srv_get_pipe_interface_by_cli_name(pipename
, syntax
)) {
512 DBG_DEBUG("pipe %s did not register itself!\n", pipename
);
514 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
517 /*******************************************************************
518 Handle an NTLMSSP bind auth.
519 *******************************************************************/
521 static bool pipe_auth_generic_bind(struct pipes_struct
*p
,
522 struct ncacn_packet
*pkt
,
523 struct dcerpc_auth
*auth_info
,
524 const char *service_description
,
527 TALLOC_CTX
*mem_ctx
= pkt
;
528 struct gensec_security
*gensec_security
= NULL
;
531 status
= auth_generic_server_authtype_start(p
,
532 auth_info
->auth_type
,
533 auth_info
->auth_level
,
538 if (!NT_STATUS_IS_OK(status
)) {
539 DEBUG(0, (__location__
": auth_generic_server_authtype_start[%u/%u] failed: %s\n",
540 auth_info
->auth_type
, auth_info
->auth_level
, nt_errstr(status
)));
544 p
->auth
.auth_ctx
= gensec_security
;
545 p
->auth
.auth_type
= auth_info
->auth_type
;
546 p
->auth
.auth_level
= auth_info
->auth_level
;
547 p
->auth
.auth_context_id
= auth_info
->auth_context_id
;
549 if (pkt
->pfc_flags
& DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN
) {
550 p
->auth
.client_hdr_signing
= true;
551 p
->auth
.hdr_signing
= gensec_have_feature(gensec_security
,
552 GENSEC_FEATURE_SIGN_PKT_HEADER
);
555 if (p
->auth
.hdr_signing
) {
556 gensec_want_feature(gensec_security
,
557 GENSEC_FEATURE_SIGN_PKT_HEADER
);
560 status
= auth_generic_server_step(gensec_security
, mem_ctx
,
561 &auth_info
->credentials
,
563 if (!NT_STATUS_IS_OK(status
) &&
564 !NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
))
566 DEBUG(2, (__location__
": "
567 "auth_generic_server_step[%u/%u] failed: %s\n",
568 auth_info
->auth_type
, auth_info
->auth_level
,
573 if (NT_STATUS_EQUAL(status
, NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
577 status
= pipe_auth_verify_final(p
);
578 if (!NT_STATUS_IS_OK(status
)) {
579 DEBUG(0, ("pipe_auth_verify_final failed: %s\n",
587 /*******************************************************************
588 Process an NTLMSSP authentication response.
589 If this function succeeds, the user has been authenticated
590 and their domain, name and calling workstation stored in
592 *******************************************************************/
594 static bool pipe_auth_generic_verify_final(TALLOC_CTX
*mem_ctx
,
595 struct gensec_security
*gensec_security
,
596 enum dcerpc_AuthLevel auth_level
,
597 struct auth_session_info
**session_info
)
602 DEBUG(5, (__location__
": checking user details\n"));
604 /* Finally - if the pipe negotiated integrity (sign) or privacy (seal)
605 ensure the underlying NTLMSSP flags are also set. If not we should
608 status
= auth_generic_server_check_flags(gensec_security
,
610 DCERPC_AUTH_LEVEL_PACKET
),
612 DCERPC_AUTH_LEVEL_PRIVACY
));
613 if (!NT_STATUS_IS_OK(status
)) {
614 DEBUG(0, (__location__
": Client failed to negotiate proper "
615 "security for rpc connection\n"));
619 TALLOC_FREE(*session_info
);
621 status
= auth_generic_server_get_user_info(gensec_security
,
622 mem_ctx
, session_info
);
623 if (!NT_STATUS_IS_OK(status
)) {
624 DEBUG(0, (__location__
": failed to obtain the server info "
625 "for authenticated user: %s\n", nt_errstr(status
)));
629 if ((*session_info
)->security_token
== NULL
) {
630 DEBUG(1, ("Auth module failed to provide nt_user_token\n"));
634 if ((*session_info
)->unix_token
== NULL
) {
635 DEBUG(1, ("Auth module failed to provide unix_token\n"));
640 * We're an authenticated bind over smb, so the session key needs to
641 * be set to "SystemLibraryDTC". Weird, but this is what Windows
642 * does. See the RPC-SAMBA3SESSIONKEY.
645 ret
= session_info_set_session_key((*session_info
), generic_session_key());
647 DEBUG(0, ("Failed to set session key!\n"));
654 static NTSTATUS
pipe_auth_verify_final(struct pipes_struct
*p
)
656 struct gensec_security
*gensec_security
;
659 if (p
->auth
.auth_type
== DCERPC_AUTH_TYPE_NONE
) {
660 p
->pipe_bound
= true;
664 gensec_security
= p
->auth
.auth_ctx
;
666 ok
= pipe_auth_generic_verify_final(p
, gensec_security
,
670 return NT_STATUS_ACCESS_DENIED
;
673 p
->pipe_bound
= true;
678 /*******************************************************************
679 Respond to a pipe bind request.
680 *******************************************************************/
682 static bool api_pipe_bind_req(struct pipes_struct
*p
,
683 struct ncacn_packet
*pkt
)
685 struct dcerpc_auth auth_info
= {0};
688 struct ndr_syntax_id id
;
689 uint8_t pfc_flags
= 0;
690 union dcerpc_payload u
;
691 struct dcerpc_ack_ctx bind_ack_ctx
;
692 DATA_BLOB auth_resp
= data_blob_null
;
693 DATA_BLOB auth_blob
= data_blob_null
;
694 const struct ndr_interface_table
*table
;
695 const char *secondary_address
= NULL
;
697 if (!p
->allow_bind
) {
698 DEBUG(2,("Pipe not in allow bind state\n"));
699 return setup_bind_nak(p
, pkt
);
701 p
->allow_bind
= false;
703 status
= dcerpc_verify_ncacn_packet_header(pkt
,
705 pkt
->u
.bind
.auth_info
.length
,
706 0, /* required flags */
707 DCERPC_PFC_FLAG_FIRST
|
708 DCERPC_PFC_FLAG_LAST
|
709 DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN
|
710 0x08 | /* this is not defined, but should be ignored */
711 DCERPC_PFC_FLAG_CONC_MPX
|
712 DCERPC_PFC_FLAG_DID_NOT_EXECUTE
|
713 DCERPC_PFC_FLAG_MAYBE
|
714 DCERPC_PFC_FLAG_OBJECT_UUID
);
715 if (!NT_STATUS_IS_OK(status
)) {
716 DEBUG(1, ("api_pipe_bind_req: invalid pdu: %s\n",
718 NDR_PRINT_DEBUG(ncacn_packet
, pkt
);
722 if (pkt
->u
.bind
.num_contexts
== 0) {
723 DEBUG(1, ("api_pipe_bind_req: no rpc contexts around\n"));
727 if (pkt
->u
.bind
.ctx_list
[0].num_transfer_syntaxes
== 0) {
728 DEBUG(1, ("api_pipe_bind_req: no transfer syntaxes around\n"));
733 * Try and find the correct pipe name to ensure
734 * that this is a pipe name we support.
736 id
= pkt
->u
.bind
.ctx_list
[0].abstract_syntax
;
738 table
= ndr_table_by_uuid(&id
.uuid
);
740 char *iface
= ndr_syntax_id_to_string(talloc_tos(), &id
);
741 DBG_NOTICE("unknown interface %s\n",
742 iface
? iface
: "<null>");
747 if (rpc_srv_pipe_exists_by_id(&id
)) {
748 DEBUG(3, ("api_pipe_bind_req: %s -> %s rpc service\n",
749 rpc_srv_get_pipe_cli_name(&id
),
750 rpc_srv_get_pipe_srv_name(&id
)));
752 status
= smb_probe_module(
753 "rpc", dcerpc_default_transport_endpoint(pkt
,
756 if (NT_STATUS_IS_ERR(status
)) {
757 DEBUG(3,("api_pipe_bind_req: Unknown rpc service name "
758 "%s in bind request.\n",
759 ndr_interface_name(&id
.uuid
,
762 return setup_bind_nak(p
, pkt
);
765 if (rpc_srv_get_pipe_interface_by_cli_name(
766 dcerpc_default_transport_endpoint(pkt
,
769 DEBUG(3, ("api_pipe_bind_req: %s -> %s rpc service\n",
770 rpc_srv_get_pipe_cli_name(&id
),
771 rpc_srv_get_pipe_srv_name(&id
)));
773 DEBUG(0, ("module %s doesn't provide functions for "
775 ndr_interface_name(&id
.uuid
,
777 ndr_interface_name(&id
.uuid
,
779 return setup_bind_nak(p
, pkt
);
783 DEBUG(5,("api_pipe_bind_req: make response. %d\n", __LINE__
));
785 if (pkt
->u
.bind
.assoc_group_id
!= 0) {
786 assoc_gid
= pkt
->u
.bind
.assoc_group_id
;
792 * Create the bind response struct.
795 /* If the requested abstract synt uuid doesn't match our client pipe,
796 reject the bind_ack & set the transfer interface synt to all 0's,
797 ver 0 (observed when NT5 attempts to bind to abstract interfaces
799 Needed when adding entries to a DACL from NT5 - SK */
801 if (check_bind_req(p
,
802 &pkt
->u
.bind
.ctx_list
[0].abstract_syntax
,
803 &pkt
->u
.bind
.ctx_list
[0].transfer_syntaxes
[0],
804 pkt
->u
.bind
.ctx_list
[0].context_id
)) {
806 bind_ack_ctx
.result
= 0;
807 bind_ack_ctx
.reason
.value
= 0;
808 bind_ack_ctx
.syntax
= pkt
->u
.bind
.ctx_list
[0].transfer_syntaxes
[0];
810 /* Rejection reason: abstract syntax not supported */
811 bind_ack_ctx
.result
= DCERPC_BIND_PROVIDER_REJECT
;
812 bind_ack_ctx
.reason
.value
= DCERPC_BIND_REASON_ASYNTAX
;
813 bind_ack_ctx
.syntax
= ndr_syntax_id_null
;
817 * Check if this is an authenticated bind request.
819 if (pkt
->auth_length
) {
821 * Decode the authentication verifier.
823 status
= dcerpc_pull_auth_trailer(pkt
, pkt
,
824 &pkt
->u
.bind
.auth_info
,
825 &auth_info
, NULL
, true);
826 if (!NT_STATUS_IS_OK(status
)) {
827 DEBUG(0, ("Unable to unmarshall dcerpc_auth.\n"));
831 if (!pipe_auth_generic_bind(p
, pkt
,
838 TALLOC_CTX
*frame
= talloc_stackframe();
839 struct auth4_context
*auth4_context
;
840 const char *transport_protection
= AUTHZ_TRANSPORT_PROTECTION_NONE
;
841 if (p
->transport
== NCACN_NP
) {
842 transport_protection
= AUTHZ_TRANSPORT_PROTECTION_SMB
;
845 p
->auth
.auth_type
= DCERPC_AUTH_TYPE_NONE
;
846 p
->auth
.auth_level
= DCERPC_AUTH_LEVEL_NONE
;
847 p
->auth
.auth_context_id
= 0;
850 status
= make_auth4_context(frame
, &auth4_context
);
852 if (!NT_STATUS_IS_OK(status
)) {
853 DEBUG(0, ("Unable to make auth context for authz log.\n"));
859 * Log the authorization to this RPC interface. This
860 * covered ncacn_np pass-through auth, and anonymous
861 * DCE/RPC (eg epmapper, netlogon etc)
863 log_successful_authz_event(auth4_context
->msg_ctx
,
864 auth4_context
->lp_ctx
,
868 derpc_transport_string_by_transport(p
->transport
),
869 transport_protection
,
874 ZERO_STRUCT(u
.bind_ack
);
875 u
.bind_ack
.max_xmit_frag
= RPC_MAX_PDU_FRAG_LEN
;
876 u
.bind_ack
.max_recv_frag
= RPC_MAX_PDU_FRAG_LEN
;
877 u
.bind_ack
.assoc_group_id
= assoc_gid
;
879 switch (p
->transport
) {
881 secondary_address
= talloc_asprintf(pkt
, "%d",
882 tsocket_address_inet_port(p
->local_address
));
886 /* name has to be \PIPE\xxxxx */
888 talloc_asprintf(pkt
, "\\PIPE\\%s",
889 rpc_srv_get_pipe_srv_name(&id
));
893 if (secondary_address
== NULL
) {
894 DEBUG(0, ("Out of memory!\n"));
898 u
.bind_ack
.secondary_address
= secondary_address
;
899 u
.bind_ack
.secondary_address_size
=
900 strlen(u
.bind_ack
.secondary_address
) + 1;
902 u
.bind_ack
.num_results
= 1;
903 u
.bind_ack
.ctx_list
= &bind_ack_ctx
;
905 /* NOTE: We leave the auth_info empty so we can calculate the padding
906 * later and then append the auth_info --simo */
909 * Marshall directly into the outgoing PDU space. We
910 * must do this as we need to set to the bind response
911 * header and are never sending more than one PDU here.
914 pfc_flags
= DCERPC_PFC_FLAG_FIRST
| DCERPC_PFC_FLAG_LAST
;
916 if (p
->auth
.hdr_signing
) {
917 pfc_flags
|= DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN
;
920 status
= dcerpc_push_ncacn_packet(p
->mem_ctx
,
927 if (!NT_STATUS_IS_OK(status
)) {
928 DEBUG(0, ("Failed to marshall bind_ack packet. (%s)\n",
933 if (auth_resp
.length
) {
934 status
= dcerpc_push_dcerpc_auth(pkt
,
938 p
->auth
.auth_context_id
,
941 if (!NT_STATUS_IS_OK(status
)) {
942 DEBUG(0, ("Marshalling of dcerpc_auth failed.\n"));
947 /* Now that we have the auth len store it into the right place in
948 * the dcerpc header */
949 dcerpc_set_frag_length(&p
->out_data
.frag
,
950 p
->out_data
.frag
.length
+ auth_blob
.length
);
952 if (auth_blob
.length
) {
954 if (!data_blob_append(p
->mem_ctx
, &p
->out_data
.frag
,
955 auth_blob
.data
, auth_blob
.length
)) {
956 DEBUG(0, ("Append of auth info failed.\n"));
962 * Setup the lengths for the initial reply.
965 p
->out_data
.data_sent_length
= 0;
966 p
->out_data
.current_pdu_sent
= 0;
968 TALLOC_FREE(auth_blob
.data
);
970 if (bind_ack_ctx
.result
== 0) {
971 p
->allow_alter
= true;
972 p
->allow_auth3
= true;
973 if (p
->auth
.auth_type
== DCERPC_AUTH_TYPE_NONE
) {
974 status
= pipe_auth_verify_final(p
);
975 if (!NT_STATUS_IS_OK(status
)) {
976 DEBUG(0, ("pipe_auth_verify_final failed: %s\n",
989 data_blob_free(&p
->out_data
.frag
);
990 TALLOC_FREE(auth_blob
.data
);
991 return setup_bind_nak(p
, pkt
);
994 /*******************************************************************
995 This is the "stage3" response after a bind request and reply.
996 *******************************************************************/
998 bool api_pipe_bind_auth3(struct pipes_struct
*p
, struct ncacn_packet
*pkt
)
1000 struct dcerpc_auth auth_info
;
1001 DATA_BLOB response
= data_blob_null
;
1002 struct gensec_security
*gensec_security
;
1005 DEBUG(5, ("api_pipe_bind_auth3: decode request. %d\n", __LINE__
));
1007 if (!p
->allow_auth3
) {
1008 DEBUG(1, ("Pipe not in allow auth3 state.\n"));
1012 status
= dcerpc_verify_ncacn_packet_header(pkt
,
1014 pkt
->u
.auth3
.auth_info
.length
,
1015 0, /* required flags */
1016 DCERPC_PFC_FLAG_FIRST
|
1017 DCERPC_PFC_FLAG_LAST
|
1018 DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN
|
1019 0x08 | /* this is not defined, but should be ignored */
1020 DCERPC_PFC_FLAG_CONC_MPX
|
1021 DCERPC_PFC_FLAG_DID_NOT_EXECUTE
|
1022 DCERPC_PFC_FLAG_MAYBE
|
1023 DCERPC_PFC_FLAG_OBJECT_UUID
);
1024 if (!NT_STATUS_IS_OK(status
)) {
1025 DEBUG(1, ("api_pipe_bind_auth3: invalid pdu: %s\n",
1026 nt_errstr(status
)));
1027 NDR_PRINT_DEBUG(ncacn_packet
, pkt
);
1031 /* We can only finish if the pipe is unbound for now */
1032 if (p
->pipe_bound
) {
1033 DEBUG(0, (__location__
": Pipe already bound, "
1034 "AUTH3 not supported!\n"));
1038 if (pkt
->auth_length
== 0) {
1039 DEBUG(1, ("No auth field sent for auth3 request!\n"));
1044 * Decode the authentication verifier response.
1047 status
= dcerpc_pull_auth_trailer(pkt
, pkt
,
1048 &pkt
->u
.auth3
.auth_info
,
1049 &auth_info
, NULL
, true);
1050 if (!NT_STATUS_IS_OK(status
)) {
1051 DEBUG(1, ("Failed to unmarshall dcerpc_auth.\n"));
1055 /* We must NEVER look at auth_info->auth_pad_len here,
1056 * as old Samba client code gets it wrong and sends it
1060 if (auth_info
.auth_type
!= p
->auth
.auth_type
) {
1061 DEBUG(1, ("Auth type mismatch! Client sent %d, "
1062 "but auth was started as type %d!\n",
1063 auth_info
.auth_type
, p
->auth
.auth_type
));
1067 if (auth_info
.auth_level
!= p
->auth
.auth_level
) {
1068 DEBUG(1, ("Auth level mismatch! Client sent %d, "
1069 "but auth was started as level %d!\n",
1070 auth_info
.auth_level
, p
->auth
.auth_level
));
1074 if (auth_info
.auth_context_id
!= p
->auth
.auth_context_id
) {
1075 DEBUG(0, ("Auth context id mismatch! Client sent %u, "
1076 "but auth was started as level %u!\n",
1077 (unsigned)auth_info
.auth_context_id
,
1078 (unsigned)p
->auth
.auth_context_id
));
1082 gensec_security
= p
->auth
.auth_ctx
;
1084 status
= auth_generic_server_step(gensec_security
,
1085 pkt
, &auth_info
.credentials
,
1088 if (NT_STATUS_EQUAL(status
,
1089 NT_STATUS_MORE_PROCESSING_REQUIRED
) ||
1091 DEBUG(1, (__location__
": This was supposed to be the final "
1092 "leg, but crypto machinery claims a response is "
1093 "needed, aborting auth!\n"));
1094 data_blob_free(&response
);
1097 if (!NT_STATUS_IS_OK(status
)) {
1098 DEBUG(2, ("Auth failed (%s)\n", nt_errstr(status
)));
1102 /* Now verify auth was indeed successful and extract server info */
1103 status
= pipe_auth_verify_final(p
);
1104 if (!NT_STATUS_IS_OK(status
)) {
1105 DEBUG(2, ("Auth Verify failed (%s)\n", nt_errstr(status
)));
1112 p
->pipe_bound
= false;
1113 p
->allow_bind
= false;
1114 p
->allow_alter
= false;
1115 p
->allow_auth3
= false;
1117 TALLOC_FREE(p
->auth
.auth_ctx
);
1121 /****************************************************************************
1122 Deal with an alter context call. Can be third part of 3 leg auth request for
1124 ****************************************************************************/
1126 static bool api_pipe_alter_context(struct pipes_struct
*p
,
1127 struct ncacn_packet
*pkt
)
1129 struct dcerpc_auth auth_info
= {0};
1132 union dcerpc_payload u
;
1133 struct dcerpc_ack_ctx alter_ack_ctx
;
1134 DATA_BLOB auth_resp
= data_blob_null
;
1135 DATA_BLOB auth_blob
= data_blob_null
;
1136 struct gensec_security
*gensec_security
;
1138 DEBUG(5,("api_pipe_alter_context: make response. %d\n", __LINE__
));
1140 if (!p
->allow_alter
) {
1141 DEBUG(1, ("Pipe not in allow alter state.\n"));
1145 status
= dcerpc_verify_ncacn_packet_header(pkt
,
1147 pkt
->u
.alter
.auth_info
.length
,
1148 0, /* required flags */
1149 DCERPC_PFC_FLAG_FIRST
|
1150 DCERPC_PFC_FLAG_LAST
|
1151 DCERPC_PFC_FLAG_SUPPORT_HEADER_SIGN
|
1152 0x08 | /* this is not defined, but should be ignored */
1153 DCERPC_PFC_FLAG_CONC_MPX
|
1154 DCERPC_PFC_FLAG_DID_NOT_EXECUTE
|
1155 DCERPC_PFC_FLAG_MAYBE
|
1156 DCERPC_PFC_FLAG_OBJECT_UUID
);
1157 if (!NT_STATUS_IS_OK(status
)) {
1158 DEBUG(1, ("api_pipe_alter_context: invalid pdu: %s\n",
1159 nt_errstr(status
)));
1160 NDR_PRINT_DEBUG(ncacn_packet
, pkt
);
1164 if (pkt
->u
.alter
.num_contexts
== 0) {
1165 DEBUG(1, ("api_pipe_alter_context: no rpc contexts around\n"));
1169 if (pkt
->u
.alter
.ctx_list
[0].num_transfer_syntaxes
== 0) {
1170 DEBUG(1, ("api_pipe_alter_context: no transfer syntaxes around\n"));
1174 if (pkt
->u
.alter
.assoc_group_id
!= 0) {
1175 assoc_gid
= pkt
->u
.alter
.assoc_group_id
;
1181 * Create the bind response struct.
1184 /* If the requested abstract synt uuid doesn't match our client pipe,
1185 reject the alter_ack & set the transfer interface synt to all 0's,
1186 ver 0 (observed when NT5 attempts to bind to abstract interfaces
1188 Needed when adding entries to a DACL from NT5 - SK */
1190 if (check_bind_req(p
,
1191 &pkt
->u
.alter
.ctx_list
[0].abstract_syntax
,
1192 &pkt
->u
.alter
.ctx_list
[0].transfer_syntaxes
[0],
1193 pkt
->u
.alter
.ctx_list
[0].context_id
)) {
1195 alter_ack_ctx
.result
= 0;
1196 alter_ack_ctx
.reason
.value
= 0;
1197 alter_ack_ctx
.syntax
= pkt
->u
.alter
.ctx_list
[0].transfer_syntaxes
[0];
1199 /* Rejection reason: abstract syntax not supported */
1200 alter_ack_ctx
.result
= DCERPC_BIND_PROVIDER_REJECT
;
1201 alter_ack_ctx
.reason
.value
= DCERPC_BIND_REASON_ASYNTAX
;
1202 alter_ack_ctx
.syntax
= ndr_syntax_id_null
;
1206 * Check if this is an authenticated alter context request.
1208 if (pkt
->auth_length
) {
1209 /* We can only finish if the pipe is unbound for now */
1210 if (p
->pipe_bound
) {
1211 DEBUG(0, (__location__
": Pipe already bound, "
1212 "Altering Context not yet supported!\n"));
1216 status
= dcerpc_pull_auth_trailer(pkt
, pkt
,
1217 &pkt
->u
.alter
.auth_info
,
1218 &auth_info
, NULL
, true);
1219 if (!NT_STATUS_IS_OK(status
)) {
1220 DEBUG(0, ("Unable to unmarshall dcerpc_auth.\n"));
1224 if (auth_info
.auth_type
!= p
->auth
.auth_type
) {
1225 DEBUG(0, ("Auth type mismatch! Client sent %d, "
1226 "but auth was started as type %d!\n",
1227 auth_info
.auth_type
, p
->auth
.auth_type
));
1231 if (auth_info
.auth_level
!= p
->auth
.auth_level
) {
1232 DEBUG(0, ("Auth level mismatch! Client sent %d, "
1233 "but auth was started as level %d!\n",
1234 auth_info
.auth_level
, p
->auth
.auth_level
));
1238 if (auth_info
.auth_context_id
!= p
->auth
.auth_context_id
) {
1239 DEBUG(0, ("Auth context id mismatch! Client sent %u, "
1240 "but auth was started as level %u!\n",
1241 (unsigned)auth_info
.auth_context_id
,
1242 (unsigned)p
->auth
.auth_context_id
));
1246 gensec_security
= p
->auth
.auth_ctx
;
1247 status
= auth_generic_server_step(gensec_security
,
1249 &auth_info
.credentials
,
1251 if (NT_STATUS_IS_OK(status
)) {
1252 /* third leg of auth, verify auth info */
1253 status
= pipe_auth_verify_final(p
);
1254 if (!NT_STATUS_IS_OK(status
)) {
1255 DEBUG(0, ("Auth Verify failed (%s)\n",
1256 nt_errstr(status
)));
1259 } else if (NT_STATUS_EQUAL(status
,
1260 NT_STATUS_MORE_PROCESSING_REQUIRED
)) {
1261 DEBUG(10, ("More auth legs required.\n"));
1263 DEBUG(0, ("Auth step returned an error (%s)\n",
1264 nt_errstr(status
)));
1269 ZERO_STRUCT(u
.alter_resp
);
1270 u
.alter_resp
.max_xmit_frag
= RPC_MAX_PDU_FRAG_LEN
;
1271 u
.alter_resp
.max_recv_frag
= RPC_MAX_PDU_FRAG_LEN
;
1272 u
.alter_resp
.assoc_group_id
= assoc_gid
;
1274 /* secondary address CAN be NULL
1275 * as the specs say it's ignored.
1276 * It MUST be NULL to have the spoolss working.
1278 u
.alter_resp
.secondary_address
= "";
1279 u
.alter_resp
.secondary_address_size
= 1;
1281 u
.alter_resp
.num_results
= 1;
1282 u
.alter_resp
.ctx_list
= &alter_ack_ctx
;
1284 /* NOTE: We leave the auth_info empty so we can calculate the padding
1285 * later and then append the auth_info --simo */
1288 * Marshall directly into the outgoing PDU space. We
1289 * must do this as we need to set to the bind response
1290 * header and are never sending more than one PDU here.
1293 status
= dcerpc_push_ncacn_packet(p
->mem_ctx
,
1294 DCERPC_PKT_ALTER_RESP
,
1295 DCERPC_PFC_FLAG_FIRST
|
1296 DCERPC_PFC_FLAG_LAST
,
1301 if (!NT_STATUS_IS_OK(status
)) {
1302 DEBUG(0, ("Failed to marshall alter_resp packet. (%s)\n",
1303 nt_errstr(status
)));
1307 if (auth_resp
.length
) {
1308 status
= dcerpc_push_dcerpc_auth(pkt
,
1312 p
->auth
.auth_context_id
,
1315 if (!NT_STATUS_IS_OK(status
)) {
1316 DEBUG(0, ("Marshalling of dcerpc_auth failed.\n"));
1321 /* Now that we have the auth len store it into the right place in
1322 * the dcerpc header */
1323 dcerpc_set_frag_length(&p
->out_data
.frag
,
1324 p
->out_data
.frag
.length
+
1327 if (auth_resp
.length
) {
1328 if (!data_blob_append(p
->mem_ctx
, &p
->out_data
.frag
,
1329 auth_blob
.data
, auth_blob
.length
)) {
1330 DEBUG(0, ("Append of auth info failed.\n"));
1336 * Setup the lengths for the initial reply.
1339 p
->out_data
.data_sent_length
= 0;
1340 p
->out_data
.current_pdu_sent
= 0;
1342 TALLOC_FREE(auth_blob
.data
);
1347 data_blob_free(&p
->out_data
.frag
);
1348 TALLOC_FREE(auth_blob
.data
);
1349 return setup_bind_nak(p
, pkt
);
1352 static bool api_rpcTNP(struct pipes_struct
*p
, struct ncacn_packet
*pkt
,
1353 const struct api_struct
*api_rpc_cmds
, int n_cmds
,
1354 const struct ndr_syntax_id
*syntax
);
1356 static bool srv_pipe_check_verification_trailer(struct pipes_struct
*p
,
1357 struct ncacn_packet
*pkt
,
1358 struct pipe_rpc_fns
*pipe_fns
)
1360 TALLOC_CTX
*frame
= talloc_stackframe();
1361 struct dcerpc_sec_verification_trailer
*vt
= NULL
;
1362 const uint32_t bitmask1
=
1363 p
->auth
.client_hdr_signing
? DCERPC_SEC_VT_CLIENT_SUPPORTS_HEADER_SIGNING
: 0;
1364 const struct dcerpc_sec_vt_pcontext pcontext
= {
1365 .abstract_syntax
= pipe_fns
->syntax
,
1366 .transfer_syntax
= ndr_transfer_syntax_ndr
,
1368 const struct dcerpc_sec_vt_header2 header2
=
1369 dcerpc_sec_vt_header2_from_ncacn_packet(pkt
);
1370 struct ndr_pull
*ndr
;
1371 enum ndr_err_code ndr_err
;
1374 ndr
= ndr_pull_init_blob(&p
->in_data
.data
, frame
);
1379 ndr_err
= ndr_pop_dcerpc_sec_verification_trailer(ndr
, frame
, &vt
);
1380 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1384 ret
= dcerpc_sec_verification_trailer_check(vt
, &bitmask1
,
1385 &pcontext
, &header2
);
1391 /****************************************************************************
1392 Find the correct RPC function to call for this request.
1393 If the pipe is authenticated then become the correct UNIX user
1394 before doing the call.
1395 ****************************************************************************/
1397 static bool api_pipe_request(struct pipes_struct
*p
,
1398 struct ncacn_packet
*pkt
)
1400 TALLOC_CTX
*frame
= talloc_stackframe();
1402 struct pipe_rpc_fns
*pipe_fns
;
1403 const char *interface_name
= NULL
;
1404 const char *dump_dir
= NULL
;
1406 if (!p
->pipe_bound
) {
1407 DEBUG(1, ("Pipe not bound!\n"));
1408 data_blob_free(&p
->out_data
.rdata
);
1413 /* get the set of RPC functions for this context */
1414 pipe_fns
= find_pipe_fns_by_context(p
->contexts
,
1415 pkt
->u
.request
.context_id
);
1416 if (pipe_fns
== NULL
) {
1417 DEBUG(0, ("No rpc function table associated with context "
1419 pkt
->u
.request
.context_id
));
1420 data_blob_free(&p
->out_data
.rdata
);
1425 interface_name
= ndr_interface_name(&pipe_fns
->syntax
.uuid
,
1426 pipe_fns
->syntax
.if_version
);
1427 SMB_ASSERT(interface_name
!= NULL
);
1429 if (p
->auth
.auth_level
< pipe_fns
->min_auth_level
) {
1431 DEBUG(1, ("%s: auth level required for %s: 0x%x, got: 0x%0x\n",
1432 __func__
, interface_name
,
1433 pipe_fns
->min_auth_level
,
1434 p
->auth
.auth_level
));
1436 setup_fault_pdu(p
, NT_STATUS(DCERPC_FAULT_ACCESS_DENIED
));
1441 switch (p
->auth
.auth_level
) {
1442 case DCERPC_AUTH_LEVEL_NONE
:
1443 case DCERPC_AUTH_LEVEL_PACKET
:
1444 case DCERPC_AUTH_LEVEL_INTEGRITY
:
1445 case DCERPC_AUTH_LEVEL_PRIVACY
:
1448 if (!pipe_fns
->allow_connect
) {
1451 addr
= tsocket_address_string(p
->remote_address
, frame
);
1453 DEBUG(1, ("%s: restrict auth_level_connect access "
1454 "to [%s] with auth[type=0x%x,level=0x%x] "
1455 "on [%s] from [%s]\n",
1456 __func__
, interface_name
,
1459 derpc_transport_string_by_transport(p
->transport
),
1462 setup_fault_pdu(p
, NT_STATUS(DCERPC_FAULT_ACCESS_DENIED
));
1469 dump_dir
= lp_parm_const_string(0, "dcesrv", "fuzz directory", NULL
);
1471 dcerpc_save_ndr_fuzz_seed(p
,
1476 pkt
->u
.request
.opnum
,
1479 if (!srv_pipe_check_verification_trailer(p
, pkt
, pipe_fns
)) {
1480 DEBUG(1, ("srv_pipe_check_verification_trailer: failed\n"));
1481 set_incoming_fault(p
);
1482 setup_fault_pdu(p
, NT_STATUS(DCERPC_FAULT_ACCESS_DENIED
));
1483 data_blob_free(&p
->out_data
.rdata
);
1488 if (!become_authenticated_pipe_user(p
->session_info
)) {
1489 DEBUG(1, ("Failed to become pipe user!\n"));
1490 data_blob_free(&p
->out_data
.rdata
);
1495 DEBUG(5, ("Requested %s rpc service\n", interface_name
));
1497 ret
= api_rpcTNP(p
, pkt
, pipe_fns
->cmds
, pipe_fns
->n_cmds
,
1499 unbecome_authenticated_pipe_user();
1501 dcerpc_save_ndr_fuzz_seed(p
,
1506 pkt
->u
.request
.opnum
,
1513 /*******************************************************************
1514 Calls the underlying RPC function for a named pipe.
1515 ********************************************************************/
1517 static bool api_rpcTNP(struct pipes_struct
*p
, struct ncacn_packet
*pkt
,
1518 const struct api_struct
*api_rpc_cmds
, int n_cmds
,
1519 const struct ndr_syntax_id
*syntax
)
1523 const struct ndr_interface_table
*table
;
1525 /* interpret the command */
1526 DEBUG(4,("api_rpcTNP: %s op 0x%x - ",
1527 ndr_interface_name(&syntax
->uuid
, syntax
->if_version
),
1528 pkt
->u
.request
.opnum
));
1530 table
= ndr_table_by_uuid(&syntax
->uuid
);
1531 if (table
== NULL
) {
1532 DEBUG(0,("unknown interface\n"));
1536 if (DEBUGLEVEL
>= 50) {
1538 slprintf(name
, sizeof(name
)-1, "in_%s",
1539 dcerpc_default_transport_endpoint(pkt
, NCACN_NP
, table
));
1540 dump_pdu_region(name
, pkt
->u
.request
.opnum
,
1541 &p
->in_data
.data
, 0,
1542 p
->in_data
.data
.length
);
1545 for (fn_num
= 0; fn_num
< n_cmds
; fn_num
++) {
1546 if (api_rpc_cmds
[fn_num
].opnum
== pkt
->u
.request
.opnum
&&
1547 api_rpc_cmds
[fn_num
].fn
!= NULL
) {
1548 DEBUG(3, ("api_rpcTNP: rpc command: %s\n",
1549 api_rpc_cmds
[fn_num
].name
));
1554 if (fn_num
== n_cmds
) {
1556 * For an unknown RPC just return a fault PDU but
1557 * return True to allow RPC's on the pipe to continue
1558 * and not put the pipe into fault state. JRA.
1560 DEBUG(4, ("unknown\n"));
1561 setup_fault_pdu(p
, NT_STATUS(DCERPC_FAULT_OP_RNG_ERROR
));
1565 offset1
= p
->out_data
.rdata
.length
;
1567 DEBUG(6, ("api_rpc_cmds[%d].fn == %p\n",
1568 fn_num
, api_rpc_cmds
[fn_num
].fn
));
1569 /* do the actual command */
1570 if(!api_rpc_cmds
[fn_num
].fn(p
)) {
1571 DEBUG(0,("api_rpcTNP: %s: %s failed.\n",
1572 ndr_interface_name(&syntax
->uuid
, syntax
->if_version
),
1573 api_rpc_cmds
[fn_num
].name
));
1574 data_blob_free(&p
->out_data
.rdata
);
1578 if (p
->fault_state
) {
1579 DEBUG(4,("api_rpcTNP: fault(%d) return.\n", p
->fault_state
));
1580 setup_fault_pdu(p
, NT_STATUS(p
->fault_state
));
1585 if (DEBUGLEVEL
>= 50) {
1587 slprintf(name
, sizeof(name
)-1, "out_%s",
1588 dcerpc_default_transport_endpoint(pkt
, NCACN_NP
, table
));
1589 dump_pdu_region(name
, pkt
->u
.request
.opnum
,
1590 &p
->out_data
.rdata
, offset1
,
1591 p
->out_data
.rdata
.length
);
1594 DEBUG(5,("api_rpcTNP: called %s successfully\n",
1595 ndr_interface_name(&syntax
->uuid
, syntax
->if_version
)));
1597 /* Check for buffer underflow in rpc parsing */
1598 if ((DEBUGLEVEL
>= 10) &&
1599 (pkt
->frag_length
< p
->in_data
.data
.length
)) {
1600 DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
1601 dump_data(10, p
->in_data
.data
.data
+ pkt
->frag_length
,
1602 p
->in_data
.data
.length
- pkt
->frag_length
);
1608 /****************************************************************************
1609 Initialise an outgoing packet.
1610 ****************************************************************************/
1612 static bool pipe_init_outgoing_data(struct pipes_struct
*p
)
1614 output_data
*o_data
= &p
->out_data
;
1616 /* Reset the offset counters. */
1617 o_data
->data_sent_length
= 0;
1618 o_data
->current_pdu_sent
= 0;
1620 data_blob_free(&o_data
->frag
);
1622 /* Free any memory in the current return data buffer. */
1623 data_blob_free(&o_data
->rdata
);
1628 /****************************************************************************
1629 Sets the fault state on incoming packets.
1630 ****************************************************************************/
1632 void set_incoming_fault(struct pipes_struct
*p
)
1634 data_blob_free(&p
->in_data
.data
);
1635 p
->in_data
.pdu_needed_len
= 0;
1636 p
->in_data
.pdu
.length
= 0;
1637 p
->fault_state
= DCERPC_NCA_S_PROTO_ERROR
;
1639 p
->allow_alter
= false;
1640 p
->allow_auth3
= false;
1641 p
->pipe_bound
= false;
1643 DEBUG(10, ("Setting fault state\n"));
1646 static NTSTATUS
dcesrv_auth_request(struct pipe_auth_data
*auth
,
1647 struct ncacn_packet
*pkt
,
1651 size_t hdr_size
= DCERPC_REQUEST_LENGTH
;
1653 DEBUG(10, ("Checking request auth.\n"));
1655 if (pkt
->pfc_flags
& DCERPC_PFC_FLAG_OBJECT_UUID
) {
1659 /* in case of sealing this function will unseal the data in place */
1660 status
= dcerpc_check_auth(auth
, pkt
,
1661 &pkt
->u
.request
.stub_and_verifier
,
1663 if (!NT_STATUS_IS_OK(status
)) {
1667 return NT_STATUS_OK
;
1670 /****************************************************************************
1671 Processes a request pdu. This will do auth processing if needed, and
1672 appends the data into the complete stream if the LAST flag is not set.
1673 ****************************************************************************/
1675 static bool process_request_pdu(struct pipes_struct
*p
, struct ncacn_packet
*pkt
)
1679 struct dcerpc_sec_vt_header2 hdr2
;
1681 if (!p
->pipe_bound
) {
1682 DEBUG(0,("process_request_pdu: rpc request with no bind.\n"));
1683 set_incoming_fault(p
);
1688 * We don't ignore DCERPC_PFC_FLAG_PENDING_CANCEL.
1689 * TODO: we can reject it with DCERPC_FAULT_NO_CALL_ACTIVE later.
1691 status
= dcerpc_verify_ncacn_packet_header(pkt
,
1693 pkt
->u
.request
.stub_and_verifier
.length
,
1694 0, /* required_flags */
1695 DCERPC_PFC_FLAG_FIRST
|
1696 DCERPC_PFC_FLAG_LAST
|
1697 0x08 | /* this is not defined, but should be ignored */
1698 DCERPC_PFC_FLAG_CONC_MPX
|
1699 DCERPC_PFC_FLAG_DID_NOT_EXECUTE
|
1700 DCERPC_PFC_FLAG_MAYBE
|
1701 DCERPC_PFC_FLAG_OBJECT_UUID
);
1702 if (!NT_STATUS_IS_OK(status
)) {
1703 DEBUG(1, ("process_request_pdu: invalid pdu: %s\n",
1704 nt_errstr(status
)));
1705 NDR_PRINT_DEBUG(ncacn_packet
, pkt
);
1706 set_incoming_fault(p
);
1710 hdr2
= dcerpc_sec_vt_header2_from_ncacn_packet(pkt
);
1711 if (pkt
->pfc_flags
& DCERPC_PFC_FLAG_FIRST
) {
1714 if (!dcerpc_sec_vt_header2_equal(&hdr2
, &p
->header2
)) {
1715 set_incoming_fault(p
);
1720 /* Store the opnum */
1721 p
->opnum
= pkt
->u
.request
.opnum
;
1723 status
= dcesrv_auth_request(&p
->auth
, pkt
, &p
->in_data
.pdu
);
1724 if (!NT_STATUS_IS_OK(status
)) {
1725 DEBUG(0, ("Failed to check packet auth. (%s)\n",
1726 nt_errstr(status
)));
1727 set_incoming_fault(p
);
1731 data
= pkt
->u
.request
.stub_and_verifier
;
1734 * Check the data length doesn't go over the 15Mb limit.
1735 * increased after observing a bug in the Windows NT 4.0 SP6a
1736 * spoolsv.exe when the response to a GETPRINTERDRIVER2 RPC
1737 * will not fit in the initial buffer of size 0x1068 --jerry 22/01/2002
1740 if (p
->in_data
.data
.length
+ data
.length
> MAX_RPC_DATA_SIZE
) {
1741 DEBUG(0, ("process_request_pdu: "
1742 "rpc data buffer too large (%u) + (%u)\n",
1743 (unsigned int)p
->in_data
.data
.length
,
1744 (unsigned int)data
.length
));
1745 set_incoming_fault(p
);
1750 * Append the data portion into the buffer and return.
1754 if (!data_blob_append(p
->mem_ctx
, &p
->in_data
.data
,
1755 data
.data
, data
.length
)) {
1756 DEBUG(0, ("Unable to append data size %u "
1757 "to parse buffer of size %u.\n",
1758 (unsigned int)data
.length
,
1759 (unsigned int)p
->in_data
.data
.length
));
1760 set_incoming_fault(p
);
1765 if (!(pkt
->pfc_flags
& DCERPC_PFC_FLAG_LAST
)) {
1770 * Ok - we finally have a complete RPC stream.
1771 * Call the rpc command to process it.
1774 return api_pipe_request(p
, pkt
);
1777 void process_complete_pdu(struct pipes_struct
*p
, struct ncacn_packet
*pkt
)
1781 /* Store the call_id */
1782 p
->call_id
= pkt
->call_id
;
1784 DEBUG(10, ("Processing packet type %u\n", (unsigned int)pkt
->ptype
));
1786 if (!pipe_init_outgoing_data(p
)) {
1790 switch (pkt
->ptype
) {
1791 case DCERPC_PKT_REQUEST
:
1792 reply
= process_request_pdu(p
, pkt
);
1795 case DCERPC_PKT_PING
: /* CL request - ignore... */
1796 DEBUG(0, ("Error - Connectionless packet type %u received\n",
1797 (unsigned int)pkt
->ptype
));
1800 case DCERPC_PKT_RESPONSE
: /* No responses here. */
1801 DEBUG(0, ("Error - DCERPC_PKT_RESPONSE received from client"));
1804 case DCERPC_PKT_FAULT
:
1805 case DCERPC_PKT_WORKING
:
1806 /* CL request - reply to a ping when a call in process. */
1807 case DCERPC_PKT_NOCALL
:
1808 /* CL - server reply to a ping call. */
1809 case DCERPC_PKT_REJECT
:
1810 case DCERPC_PKT_ACK
:
1811 case DCERPC_PKT_CL_CANCEL
:
1812 case DCERPC_PKT_FACK
:
1813 case DCERPC_PKT_CANCEL_ACK
:
1814 DEBUG(0, ("Error - Connectionless packet type %u received\n",
1815 (unsigned int)pkt
->ptype
));
1818 case DCERPC_PKT_BIND
:
1820 * We assume that a pipe bind is only in one pdu.
1822 reply
= api_pipe_bind_req(p
, pkt
);
1825 case DCERPC_PKT_BIND_ACK
:
1826 case DCERPC_PKT_BIND_NAK
:
1827 DEBUG(0, ("Error - DCERPC_PKT_BINDACK/DCERPC_PKT_BINDNACK "
1828 "packet type %u received.\n",
1829 (unsigned int)pkt
->ptype
));
1833 case DCERPC_PKT_ALTER
:
1835 * We assume that a pipe bind is only in one pdu.
1837 reply
= api_pipe_alter_context(p
, pkt
);
1840 case DCERPC_PKT_ALTER_RESP
:
1841 DEBUG(0, ("Error - DCERPC_PKT_ALTER_RESP received: "
1842 "Should only be server -> client.\n"));
1845 case DCERPC_PKT_AUTH3
:
1847 * The third packet in an auth exchange.
1849 reply
= api_pipe_bind_auth3(p
, pkt
);
1852 case DCERPC_PKT_SHUTDOWN
:
1853 DEBUG(0, ("Error - DCERPC_PKT_SHUTDOWN received: "
1854 "Should only be server -> client.\n"));
1857 case DCERPC_PKT_CO_CANCEL
:
1858 /* For now just free all client data and continue
1860 DEBUG(3,("process_complete_pdu: DCERPC_PKT_CO_CANCEL."
1861 " Abandoning rpc call.\n"));
1862 /* As we never do asynchronous RPC serving, we can
1863 * never cancel a call (as far as I know).
1864 * If we ever did we'd have to send a cancel_ack reply.
1865 * For now, just free all client data and continue
1871 /* Enable this if we're doing async rpc. */
1872 /* We must check the outstanding callid matches. */
1873 if (pipe_init_outgoing_data(p
)) {
1874 /* Send a cancel_ack PDU reply. */
1875 /* We should probably check the auth-verifier here. */
1876 reply
= setup_cancel_ack_reply(p
, pkt
);
1881 case DCERPC_PKT_ORPHANED
:
1882 /* We should probably check the auth-verifier here.
1883 * For now just free all client data and continue
1885 DEBUG(3, ("process_complete_pdu: DCERPC_PKT_ORPHANED."
1886 " Abandoning rpc call.\n"));
1891 DEBUG(0, ("process_complete_pdu: "
1892 "Unknown rpc type = %u received.\n",
1893 (unsigned int)pkt
->ptype
));
1899 DBG_NOTICE("DCE/RPC fault sent!\n");
1900 set_incoming_fault(p
);
1901 setup_fault_pdu(p
, NT_STATUS(DCERPC_NCA_S_PROTO_ERROR
));
1903 /* pkt and p->in_data.pdu.data freed by caller */