4 * Copyright 2001-2002 Ove Kåven, TransGaming Technologies
5 * Copyright 2004 Filip Navara
6 * Copyright 2006 CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library 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 GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 //#include "winerror.h"
36 //#include "rpcdcep.h"
38 #include <wine/debug.h>
40 #include "rpc_binding.h"
41 //#include "rpc_defs.h"
42 #include "rpc_message.h"
43 #include "ncastatus.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(rpc
);
47 /* note: the DCE/RPC spec says the alignment amount should be 4, but
48 * MS/RPC servers seem to always use 16 */
49 #define AUTH_ALIGNMENT 16
51 /* gets the amount needed to round a value up to the specified alignment */
52 #define ROUND_UP_AMOUNT(value, alignment) \
53 (((alignment) - (((value) % (alignment)))) % (alignment))
54 #define ROUND_UP(value, alignment) (((value) + ((alignment) - 1)) & ~((alignment)-1))
56 static RPC_STATUS
I_RpcReAllocateBuffer(PRPC_MESSAGE pMsg
);
58 DWORD
RPCRT4_GetHeaderSize(const RpcPktHdr
*Header
)
60 static const DWORD header_sizes
[] = {
61 sizeof(Header
->request
), 0, sizeof(Header
->response
),
62 sizeof(Header
->fault
), 0, 0, 0, 0, 0, 0, 0, sizeof(Header
->bind
),
63 sizeof(Header
->bind_ack
), sizeof(Header
->bind_nack
),
64 0, 0, sizeof(Header
->auth3
), 0, 0, 0, sizeof(Header
->http
)
68 if (Header
->common
.ptype
< sizeof(header_sizes
) / sizeof(header_sizes
[0])) {
69 ret
= header_sizes
[Header
->common
.ptype
];
71 FIXME("unhandled packet type %u\n", Header
->common
.ptype
);
72 if (Header
->common
.flags
& RPC_FLG_OBJECT_UUID
)
75 WARN("invalid packet type %u\n", Header
->common
.ptype
);
81 static int packet_has_body(const RpcPktHdr
*Header
)
83 return (Header
->common
.ptype
== PKT_FAULT
) ||
84 (Header
->common
.ptype
== PKT_REQUEST
) ||
85 (Header
->common
.ptype
== PKT_RESPONSE
);
88 static int packet_has_auth_verifier(const RpcPktHdr
*Header
)
90 return !(Header
->common
.ptype
== PKT_BIND_NACK
) &&
91 !(Header
->common
.ptype
== PKT_SHUTDOWN
);
94 static int packet_does_auth_negotiation(const RpcPktHdr
*Header
)
96 switch (Header
->common
.ptype
)
101 case PKT_ALTER_CONTEXT
:
102 case PKT_ALTER_CONTEXT_RESP
:
109 static VOID
RPCRT4_BuildCommonHeader(RpcPktHdr
*Header
, unsigned char PacketType
,
110 ULONG DataRepresentation
)
112 Header
->common
.rpc_ver
= RPC_VER_MAJOR
;
113 Header
->common
.rpc_ver_minor
= RPC_VER_MINOR
;
114 Header
->common
.ptype
= PacketType
;
115 Header
->common
.drep
[0] = LOBYTE(LOWORD(DataRepresentation
));
116 Header
->common
.drep
[1] = HIBYTE(LOWORD(DataRepresentation
));
117 Header
->common
.drep
[2] = LOBYTE(HIWORD(DataRepresentation
));
118 Header
->common
.drep
[3] = HIBYTE(HIWORD(DataRepresentation
));
119 Header
->common
.auth_len
= 0;
120 Header
->common
.call_id
= 1;
121 Header
->common
.flags
= 0;
122 /* Flags and fragment length are computed in RPCRT4_Send. */
125 static RpcPktHdr
*RPCRT4_BuildRequestHeader(ULONG DataRepresentation
,
127 unsigned short ProcNum
,
134 has_object
= (ObjectUuid
!= NULL
&& !UuidIsNil(ObjectUuid
, &status
));
135 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
136 sizeof(header
->request
) + (has_object
? sizeof(UUID
) : 0));
137 if (header
== NULL
) {
141 RPCRT4_BuildCommonHeader(header
, PKT_REQUEST
, DataRepresentation
);
142 header
->common
.frag_len
= sizeof(header
->request
);
143 header
->request
.alloc_hint
= BufferLength
;
144 header
->request
.context_id
= 0;
145 header
->request
.opnum
= ProcNum
;
147 header
->common
.flags
|= RPC_FLG_OBJECT_UUID
;
148 header
->common
.frag_len
+= sizeof(UUID
);
149 memcpy(&header
->request
+ 1, ObjectUuid
, sizeof(UUID
));
155 RpcPktHdr
*RPCRT4_BuildResponseHeader(ULONG DataRepresentation
, ULONG BufferLength
)
159 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(header
->response
));
160 if (header
== NULL
) {
164 RPCRT4_BuildCommonHeader(header
, PKT_RESPONSE
, DataRepresentation
);
165 header
->common
.frag_len
= sizeof(header
->response
);
166 header
->response
.alloc_hint
= BufferLength
;
171 RpcPktHdr
*RPCRT4_BuildFaultHeader(ULONG DataRepresentation
, RPC_STATUS Status
)
175 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(header
->fault
));
176 if (header
== NULL
) {
180 RPCRT4_BuildCommonHeader(header
, PKT_FAULT
, DataRepresentation
);
181 header
->common
.frag_len
= sizeof(header
->fault
);
182 header
->fault
.status
= Status
;
187 RpcPktHdr
*RPCRT4_BuildBindHeader(ULONG DataRepresentation
,
188 unsigned short MaxTransmissionSize
,
189 unsigned short MaxReceiveSize
,
191 const RPC_SYNTAX_IDENTIFIER
*AbstractId
,
192 const RPC_SYNTAX_IDENTIFIER
*TransferId
)
195 RpcContextElement
*ctxt_elem
;
197 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
198 sizeof(header
->bind
) + FIELD_OFFSET(RpcContextElement
, transfer_syntaxes
[1]));
199 if (header
== NULL
) {
202 ctxt_elem
= (RpcContextElement
*)(&header
->bind
+ 1);
204 RPCRT4_BuildCommonHeader(header
, PKT_BIND
, DataRepresentation
);
205 header
->common
.frag_len
= sizeof(header
->bind
) + FIELD_OFFSET(RpcContextElement
, transfer_syntaxes
[1]);
206 header
->bind
.max_tsize
= MaxTransmissionSize
;
207 header
->bind
.max_rsize
= MaxReceiveSize
;
208 header
->bind
.assoc_gid
= AssocGroupId
;
209 header
->bind
.num_elements
= 1;
210 ctxt_elem
->num_syntaxes
= 1;
211 ctxt_elem
->abstract_syntax
= *AbstractId
;
212 ctxt_elem
->transfer_syntaxes
[0] = *TransferId
;
217 static RpcPktHdr
*RPCRT4_BuildAuthHeader(ULONG DataRepresentation
)
221 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
222 sizeof(header
->auth3
));
226 RPCRT4_BuildCommonHeader(header
, PKT_AUTH3
, DataRepresentation
);
227 header
->common
.frag_len
= sizeof(header
->auth3
);
232 RpcPktHdr
*RPCRT4_BuildBindNackHeader(ULONG DataRepresentation
,
233 unsigned char RpcVersion
,
234 unsigned char RpcVersionMinor
,
235 unsigned short RejectReason
)
239 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, FIELD_OFFSET(RpcPktHdr
, bind_nack
.protocols
[1]));
240 if (header
== NULL
) {
244 RPCRT4_BuildCommonHeader(header
, PKT_BIND_NACK
, DataRepresentation
);
245 header
->common
.frag_len
= FIELD_OFFSET(RpcPktHdr
, bind_nack
.protocols
[1]);
246 header
->bind_nack
.reject_reason
= RejectReason
;
247 header
->bind_nack
.protocols_count
= 1;
248 header
->bind_nack
.protocols
[0].rpc_ver
= RpcVersion
;
249 header
->bind_nack
.protocols
[0].rpc_ver_minor
= RpcVersionMinor
;
254 RpcPktHdr
*RPCRT4_BuildBindAckHeader(ULONG DataRepresentation
,
255 unsigned short MaxTransmissionSize
,
256 unsigned short MaxReceiveSize
,
258 LPCSTR ServerAddress
,
259 unsigned char ResultCount
,
260 const RpcResult
*Results
)
264 RpcAddressString
*server_address
;
265 RpcResultList
*results
;
267 header_size
= sizeof(header
->bind_ack
) +
268 ROUND_UP(FIELD_OFFSET(RpcAddressString
, string
[strlen(ServerAddress
) + 1]), 4) +
269 FIELD_OFFSET(RpcResultList
, results
[ResultCount
]);
271 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, header_size
);
272 if (header
== NULL
) {
276 RPCRT4_BuildCommonHeader(header
, PKT_BIND_ACK
, DataRepresentation
);
277 header
->common
.frag_len
= header_size
;
278 header
->bind_ack
.max_tsize
= MaxTransmissionSize
;
279 header
->bind_ack
.max_rsize
= MaxReceiveSize
;
280 header
->bind_ack
.assoc_gid
= AssocGroupId
;
281 server_address
= (RpcAddressString
*)(&header
->bind_ack
+ 1);
282 server_address
->length
= strlen(ServerAddress
) + 1;
283 strcpy(server_address
->string
, ServerAddress
);
284 /* results is 4-byte aligned */
285 results
= (RpcResultList
*)((ULONG_PTR
)server_address
+ ROUND_UP(FIELD_OFFSET(RpcAddressString
, string
[server_address
->length
]), 4));
286 results
->num_results
= ResultCount
;
287 memcpy(&results
->results
[0], Results
, ResultCount
* sizeof(*Results
));
292 RpcPktHdr
*RPCRT4_BuildHttpHeader(ULONG DataRepresentation
,
293 unsigned short flags
,
294 unsigned short num_data_items
,
295 unsigned int payload_size
)
299 header
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(header
->http
) + payload_size
);
300 if (header
== NULL
) {
301 ERR("failed to allocate memory\n");
305 RPCRT4_BuildCommonHeader(header
, PKT_HTTP
, DataRepresentation
);
306 /* since the packet isn't current sent using RPCRT4_Send, set the flags
308 header
->common
.flags
= RPC_FLG_FIRST
|RPC_FLG_LAST
;
309 header
->common
.call_id
= 0;
310 header
->common
.frag_len
= sizeof(header
->http
) + payload_size
;
311 header
->http
.flags
= flags
;
312 header
->http
.num_data_items
= num_data_items
;
317 #define WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, type, value) \
319 *(unsigned int *)(payload) = (type); \
321 *(unsigned int *)(payload) = (value); \
325 #define WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, type, uuid) \
327 *(unsigned int *)(payload) = (type); \
329 *(UUID *)(payload) = (uuid); \
330 (payload) += sizeof(UUID); \
333 #define WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload, bytes_transmitted, flow_control_increment, uuid) \
335 *(unsigned int *)(payload) = 0x00000001; \
337 *(unsigned int *)(payload) = (bytes_transmitted); \
339 *(unsigned int *)(payload) = (flow_control_increment); \
341 *(UUID *)(payload) = (uuid); \
342 (payload) += sizeof(UUID); \
345 RpcPktHdr
*RPCRT4_BuildHttpConnectHeader(unsigned short flags
, int out_pipe
,
346 const UUID
*connection_uuid
,
347 const UUID
*pipe_uuid
,
348 const UUID
*association_uuid
)
354 size
= 8 + 4 + sizeof(UUID
) + 4 + sizeof(UUID
) + 8;
356 size
+= 8 + 4 + sizeof(UUID
);
358 header
= RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION
, flags
,
359 out_pipe
? 4 : 6, size
);
360 if (!header
) return NULL
;
361 payload
= (char *)(&header
->http
+1);
363 /* FIXME: what does this part of the payload do? */
364 WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload
, 0x00000006, 0x00000001);
366 WRITE_HTTP_PAYLOAD_FIELD_UUID(payload
, 0x00000003, *connection_uuid
);
367 WRITE_HTTP_PAYLOAD_FIELD_UUID(payload
, 0x00000003, *pipe_uuid
);
370 /* FIXME: what does this part of the payload do? */
371 WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload
, 0x00000000, 0x00010000);
374 /* FIXME: what does this part of the payload do? */
375 WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload
, 0x00000004, 0x40000000);
376 /* FIXME: what does this part of the payload do? */
377 WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload
, 0x00000005, 0x000493e0);
379 WRITE_HTTP_PAYLOAD_FIELD_UUID(payload
, 0x0000000c, *association_uuid
);
385 RpcPktHdr
*RPCRT4_BuildHttpFlowControlHeader(BOOL server
, ULONG bytes_transmitted
,
386 ULONG flow_control_increment
,
387 const UUID
*pipe_uuid
)
392 header
= RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION
, 0x2, 2,
393 5 * sizeof(ULONG
) + sizeof(UUID
));
394 if (!header
) return NULL
;
395 payload
= (char *)(&header
->http
+1);
397 WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload
, 0x0000000d, (server
? 0x0 : 0x3));
399 WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload
, bytes_transmitted
,
400 flow_control_increment
, *pipe_uuid
);
404 VOID
RPCRT4_FreeHeader(RpcPktHdr
*Header
)
406 HeapFree(GetProcessHeap(), 0, Header
);
409 NCA_STATUS
RPC2NCA_STATUS(RPC_STATUS status
)
413 case ERROR_INVALID_HANDLE
: return NCA_S_FAULT_CONTEXT_MISMATCH
;
414 case ERROR_OUTOFMEMORY
: return NCA_S_FAULT_REMOTE_NO_MEMORY
;
415 case RPC_S_NOT_LISTENING
: return NCA_S_SERVER_TOO_BUSY
;
416 case RPC_S_UNKNOWN_IF
: return NCA_S_UNK_IF
;
417 case RPC_S_SERVER_TOO_BUSY
: return NCA_S_SERVER_TOO_BUSY
;
418 case RPC_S_CALL_FAILED
: return NCA_S_FAULT_UNSPEC
;
419 case RPC_S_CALL_FAILED_DNE
: return NCA_S_MANAGER_NOT_ENTERED
;
420 case RPC_S_PROTOCOL_ERROR
: return NCA_S_PROTO_ERROR
;
421 case RPC_S_UNSUPPORTED_TYPE
: return NCA_S_UNSUPPORTED_TYPE
;
422 case RPC_S_INVALID_TAG
: return NCA_S_FAULT_INVALID_TAG
;
423 case RPC_S_INVALID_BOUND
: return NCA_S_FAULT_INVALID_BOUND
;
424 case RPC_S_PROCNUM_OUT_OF_RANGE
: return NCA_S_OP_RNG_ERROR
;
425 case RPC_X_SS_HANDLES_MISMATCH
: return NCA_S_FAULT_CONTEXT_MISMATCH
;
426 case RPC_S_CALL_CANCELLED
: return NCA_S_FAULT_CANCEL
;
427 case RPC_S_COMM_FAILURE
: return NCA_S_COMM_FAILURE
;
428 case RPC_X_WRONG_PIPE_ORDER
: return NCA_S_FAULT_PIPE_ORDER
;
429 case RPC_X_PIPE_CLOSED
: return NCA_S_FAULT_PIPE_CLOSED
;
430 case RPC_X_PIPE_DISCIPLINE_ERROR
: return NCA_S_FAULT_PIPE_DISCIPLINE
;
431 case RPC_X_PIPE_EMPTY
: return NCA_S_FAULT_PIPE_EMPTY
;
432 case STATUS_FLOAT_DIVIDE_BY_ZERO
: return NCA_S_FAULT_FP_DIV_ZERO
;
433 case STATUS_FLOAT_INVALID_OPERATION
: return NCA_S_FAULT_FP_ERROR
;
434 case STATUS_FLOAT_OVERFLOW
: return NCA_S_FAULT_FP_OVERFLOW
;
435 case STATUS_FLOAT_UNDERFLOW
: return NCA_S_FAULT_FP_UNDERFLOW
;
436 case STATUS_INTEGER_DIVIDE_BY_ZERO
: return NCA_S_FAULT_INT_DIV_BY_ZERO
;
437 case STATUS_INTEGER_OVERFLOW
: return NCA_S_FAULT_INT_OVERFLOW
;
438 default: return status
;
442 static RPC_STATUS
NCA2RPC_STATUS(NCA_STATUS status
)
446 case NCA_S_COMM_FAILURE
: return RPC_S_COMM_FAILURE
;
447 case NCA_S_OP_RNG_ERROR
: return RPC_S_PROCNUM_OUT_OF_RANGE
;
448 case NCA_S_UNK_IF
: return RPC_S_UNKNOWN_IF
;
449 case NCA_S_YOU_CRASHED
: return RPC_S_CALL_FAILED
;
450 case NCA_S_PROTO_ERROR
: return RPC_S_PROTOCOL_ERROR
;
451 case NCA_S_OUT_ARGS_TOO_BIG
: return ERROR_NOT_ENOUGH_SERVER_MEMORY
;
452 case NCA_S_SERVER_TOO_BUSY
: return RPC_S_SERVER_TOO_BUSY
;
453 case NCA_S_UNSUPPORTED_TYPE
: return RPC_S_UNSUPPORTED_TYPE
;
454 case NCA_S_FAULT_INT_DIV_BY_ZERO
: return RPC_S_ZERO_DIVIDE
;
455 case NCA_S_FAULT_ADDR_ERROR
: return RPC_S_ADDRESS_ERROR
;
456 case NCA_S_FAULT_FP_DIV_ZERO
: return RPC_S_FP_DIV_ZERO
;
457 case NCA_S_FAULT_FP_UNDERFLOW
: return RPC_S_FP_UNDERFLOW
;
458 case NCA_S_FAULT_FP_OVERFLOW
: return RPC_S_FP_OVERFLOW
;
459 case NCA_S_FAULT_INVALID_TAG
: return RPC_S_INVALID_TAG
;
460 case NCA_S_FAULT_INVALID_BOUND
: return RPC_S_INVALID_BOUND
;
461 case NCA_S_RPC_VERSION_MISMATCH
: return RPC_S_PROTOCOL_ERROR
;
462 case NCA_S_UNSPEC_REJECT
: return RPC_S_CALL_FAILED_DNE
;
463 case NCA_S_BAD_ACTID
: return RPC_S_CALL_FAILED_DNE
;
464 case NCA_S_WHO_ARE_YOU_FAILED
: return RPC_S_CALL_FAILED
;
465 case NCA_S_MANAGER_NOT_ENTERED
: return RPC_S_CALL_FAILED_DNE
;
466 case NCA_S_FAULT_CANCEL
: return RPC_S_CALL_CANCELLED
;
467 case NCA_S_FAULT_ILL_INST
: return RPC_S_ADDRESS_ERROR
;
468 case NCA_S_FAULT_FP_ERROR
: return RPC_S_FP_OVERFLOW
;
469 case NCA_S_FAULT_INT_OVERFLOW
: return RPC_S_ADDRESS_ERROR
;
470 case NCA_S_FAULT_UNSPEC
: return RPC_S_CALL_FAILED
;
471 case NCA_S_FAULT_PIPE_EMPTY
: return RPC_X_PIPE_EMPTY
;
472 case NCA_S_FAULT_PIPE_CLOSED
: return RPC_X_PIPE_CLOSED
;
473 case NCA_S_FAULT_PIPE_ORDER
: return RPC_X_WRONG_PIPE_ORDER
;
474 case NCA_S_FAULT_PIPE_DISCIPLINE
: return RPC_X_PIPE_DISCIPLINE_ERROR
;
475 case NCA_S_FAULT_PIPE_COMM_ERROR
: return RPC_S_COMM_FAILURE
;
476 case NCA_S_FAULT_PIPE_MEMORY
: return ERROR_OUTOFMEMORY
;
477 case NCA_S_FAULT_CONTEXT_MISMATCH
: return ERROR_INVALID_HANDLE
;
478 case NCA_S_FAULT_REMOTE_NO_MEMORY
: return ERROR_NOT_ENOUGH_SERVER_MEMORY
;
479 default: return status
;
483 /* assumes the common header fields have already been validated */
484 BOOL
RPCRT4_IsValidHttpPacket(RpcPktHdr
*hdr
, unsigned char *data
,
485 unsigned short data_len
)
490 for (i
= 0; i
< hdr
->http
.num_data_items
; i
++)
494 if (data_len
< sizeof(ULONG
))
499 data_len
-= sizeof(ULONG
);
505 if (data_len
< sizeof(GUID
))
508 data_len
-= sizeof(GUID
);
516 if (data_len
< sizeof(ULONG
))
519 data_len
-= sizeof(ULONG
);
528 FIXME("unimplemented type 0x%x\n", type
);
535 /* assumes the HTTP packet has been validated */
536 static unsigned char *RPCRT4_NextHttpHeaderField(unsigned char *data
)
540 type
= *(ULONG
*)data
;
541 data
+= sizeof(ULONG
);
547 return data
+ sizeof(GUID
);
554 return data
+ sizeof(ULONG
);
558 FIXME("unimplemented type 0x%x\n", type
);
563 #define READ_HTTP_PAYLOAD_FIELD_TYPE(data) *(ULONG *)(data)
564 #define GET_HTTP_PAYLOAD_FIELD_DATA(data) ((data) + sizeof(ULONG))
566 /* assumes the HTTP packet has been validated */
567 RPC_STATUS
RPCRT4_ParseHttpPrepareHeader1(RpcPktHdr
*header
,
568 unsigned char *data
, ULONG
*field1
)
571 if (header
->http
.flags
!= 0x0)
573 ERR("invalid flags 0x%x\n", header
->http
.flags
);
574 return RPC_S_PROTOCOL_ERROR
;
576 if (header
->http
.num_data_items
!= 1)
578 ERR("invalid number of data items %d\n", header
->http
.num_data_items
);
579 return RPC_S_PROTOCOL_ERROR
;
581 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
582 if (type
!= 0x00000002)
584 ERR("invalid type 0x%08x\n", type
);
585 return RPC_S_PROTOCOL_ERROR
;
587 *field1
= *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
);
591 /* assumes the HTTP packet has been validated */
592 RPC_STATUS
RPCRT4_ParseHttpPrepareHeader2(RpcPktHdr
*header
,
593 unsigned char *data
, ULONG
*field1
,
594 ULONG
*bytes_until_next_packet
,
598 if (header
->http
.flags
!= 0x0)
600 ERR("invalid flags 0x%x\n", header
->http
.flags
);
601 return RPC_S_PROTOCOL_ERROR
;
603 if (header
->http
.num_data_items
!= 3)
605 ERR("invalid number of data items %d\n", header
->http
.num_data_items
);
606 return RPC_S_PROTOCOL_ERROR
;
609 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
610 if (type
!= 0x00000006)
612 ERR("invalid type for field 1: 0x%08x\n", type
);
613 return RPC_S_PROTOCOL_ERROR
;
615 *field1
= *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
);
616 data
= RPCRT4_NextHttpHeaderField(data
);
618 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
619 if (type
!= 0x00000000)
621 ERR("invalid type for field 2: 0x%08x\n", type
);
622 return RPC_S_PROTOCOL_ERROR
;
624 *bytes_until_next_packet
= *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
);
625 data
= RPCRT4_NextHttpHeaderField(data
);
627 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
628 if (type
!= 0x00000002)
630 ERR("invalid type for field 3: 0x%08x\n", type
);
631 return RPC_S_PROTOCOL_ERROR
;
633 *field3
= *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
);
638 RPC_STATUS
RPCRT4_ParseHttpFlowControlHeader(RpcPktHdr
*header
,
639 unsigned char *data
, BOOL server
,
640 ULONG
*bytes_transmitted
,
641 ULONG
*flow_control_increment
,
645 if (header
->http
.flags
!= 0x2)
647 ERR("invalid flags 0x%x\n", header
->http
.flags
);
648 return RPC_S_PROTOCOL_ERROR
;
650 if (header
->http
.num_data_items
!= 2)
652 ERR("invalid number of data items %d\n", header
->http
.num_data_items
);
653 return RPC_S_PROTOCOL_ERROR
;
656 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
657 if (type
!= 0x0000000d)
659 ERR("invalid type for field 1: 0x%08x\n", type
);
660 return RPC_S_PROTOCOL_ERROR
;
662 if (*(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
) != (server
? 0x3 : 0x0))
664 ERR("invalid type for 0xd field data: 0x%08x\n", *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
));
665 return RPC_S_PROTOCOL_ERROR
;
667 data
= RPCRT4_NextHttpHeaderField(data
);
669 type
= READ_HTTP_PAYLOAD_FIELD_TYPE(data
);
670 if (type
!= 0x00000001)
672 ERR("invalid type for field 2: 0x%08x\n", type
);
673 return RPC_S_PROTOCOL_ERROR
;
675 *bytes_transmitted
= *(ULONG
*)GET_HTTP_PAYLOAD_FIELD_DATA(data
);
676 *flow_control_increment
= *(ULONG
*)(GET_HTTP_PAYLOAD_FIELD_DATA(data
) + 4);
677 *pipe_uuid
= *(UUID
*)(GET_HTTP_PAYLOAD_FIELD_DATA(data
) + 8);
683 RPC_STATUS
RPCRT4_default_secure_packet(RpcConnection
*Connection
,
684 enum secure_packet_direction dir
,
685 RpcPktHdr
*hdr
, unsigned int hdr_size
,
686 unsigned char *stub_data
, unsigned int stub_data_size
,
687 RpcAuthVerifier
*auth_hdr
,
688 unsigned char *auth_value
, unsigned int auth_value_size
)
690 SecBufferDesc message
;
691 SecBuffer buffers
[4];
692 SECURITY_STATUS sec_status
;
694 message
.ulVersion
= SECBUFFER_VERSION
;
695 message
.cBuffers
= sizeof(buffers
)/sizeof(buffers
[0]);
696 message
.pBuffers
= buffers
;
698 buffers
[0].cbBuffer
= hdr_size
;
699 buffers
[0].BufferType
= SECBUFFER_DATA
|SECBUFFER_READONLY_WITH_CHECKSUM
;
700 buffers
[0].pvBuffer
= hdr
;
701 buffers
[1].cbBuffer
= stub_data_size
;
702 buffers
[1].BufferType
= SECBUFFER_DATA
;
703 buffers
[1].pvBuffer
= stub_data
;
704 buffers
[2].cbBuffer
= sizeof(*auth_hdr
);
705 buffers
[2].BufferType
= SECBUFFER_DATA
|SECBUFFER_READONLY_WITH_CHECKSUM
;
706 buffers
[2].pvBuffer
= auth_hdr
;
707 buffers
[3].cbBuffer
= auth_value_size
;
708 buffers
[3].BufferType
= SECBUFFER_TOKEN
;
709 buffers
[3].pvBuffer
= auth_value
;
711 if (dir
== SECURE_PACKET_SEND
)
713 if ((auth_hdr
->auth_level
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
) && packet_has_body(hdr
))
715 sec_status
= EncryptMessage(&Connection
->ctx
, 0, &message
, 0 /* FIXME */);
716 if (sec_status
!= SEC_E_OK
)
718 ERR("EncryptMessage failed with 0x%08x\n", sec_status
);
719 return RPC_S_SEC_PKG_ERROR
;
722 else if (auth_hdr
->auth_level
!= RPC_C_AUTHN_LEVEL_NONE
)
724 sec_status
= MakeSignature(&Connection
->ctx
, 0, &message
, 0 /* FIXME */);
725 if (sec_status
!= SEC_E_OK
)
727 ERR("MakeSignature failed with 0x%08x\n", sec_status
);
728 return RPC_S_SEC_PKG_ERROR
;
732 else if (dir
== SECURE_PACKET_RECEIVE
)
734 if ((auth_hdr
->auth_level
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
) && packet_has_body(hdr
))
736 sec_status
= DecryptMessage(&Connection
->ctx
, &message
, 0 /* FIXME */, 0);
737 if (sec_status
!= SEC_E_OK
)
739 ERR("DecryptMessage failed with 0x%08x\n", sec_status
);
740 return RPC_S_SEC_PKG_ERROR
;
743 else if (auth_hdr
->auth_level
!= RPC_C_AUTHN_LEVEL_NONE
)
745 sec_status
= VerifySignature(&Connection
->ctx
, &message
, 0 /* FIXME */, NULL
);
746 if (sec_status
!= SEC_E_OK
)
748 ERR("VerifySignature failed with 0x%08x\n", sec_status
);
749 return RPC_S_SEC_PKG_ERROR
;
757 /***********************************************************************
758 * RPCRT4_SendWithAuth (internal)
760 * Transmit a packet with authorization data over connection in acceptable fragments.
762 RPC_STATUS
RPCRT4_SendWithAuth(RpcConnection
*Connection
, RpcPktHdr
*Header
,
763 void *Buffer
, unsigned int BufferLength
,
764 const void *Auth
, unsigned int AuthLength
)
773 RPCRT4_SetThreadCurrentConnection(Connection
);
776 /* The packet building functions save the packet header size, so we can use it. */
777 hdr_size
= Header
->common
.frag_len
;
779 Header
->common
.auth_len
= AuthLength
;
780 else if (Connection
->AuthInfo
&& packet_has_auth_verifier(Header
))
782 if ((Connection
->AuthInfo
->AuthnLevel
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
) && packet_has_body(Header
))
783 Header
->common
.auth_len
= Connection
->encryption_auth_len
;
785 Header
->common
.auth_len
= Connection
->signature_auth_len
;
788 Header
->common
.auth_len
= 0;
789 Header
->common
.flags
|= RPC_FLG_FIRST
;
790 Header
->common
.flags
&= ~RPC_FLG_LAST
;
792 alen
= RPC_AUTH_VERIFIER_LEN(&Header
->common
);
794 while (!(Header
->common
.flags
& RPC_FLG_LAST
)) {
795 unsigned char auth_pad_len
= Header
->common
.auth_len
? ROUND_UP_AMOUNT(BufferLength
, AUTH_ALIGNMENT
) : 0;
796 unsigned int pkt_size
= BufferLength
+ hdr_size
+ alen
+ auth_pad_len
;
798 /* decide if we need to split the packet into fragments */
799 if (pkt_size
<= Connection
->MaxTransmissionSize
) {
800 Header
->common
.flags
|= RPC_FLG_LAST
;
801 Header
->common
.frag_len
= pkt_size
;
804 /* make sure packet payload will be a multiple of 16 */
805 Header
->common
.frag_len
=
806 ((Connection
->MaxTransmissionSize
- hdr_size
- alen
) & ~(AUTH_ALIGNMENT
-1)) +
810 pkt
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, Header
->common
.frag_len
);
812 memcpy(pkt
, Header
, hdr_size
);
814 /* fragment consisted of header only and is the last one */
815 if (hdr_size
== Header
->common
.frag_len
)
818 memcpy(pkt
+ hdr_size
, buffer_pos
, Header
->common
.frag_len
- hdr_size
- auth_pad_len
- alen
);
820 /* add the authorization info */
821 if (Header
->common
.auth_len
)
823 RpcAuthVerifier
*auth_hdr
= (RpcAuthVerifier
*)&pkt
[Header
->common
.frag_len
- alen
];
825 auth_hdr
->auth_type
= Connection
->AuthInfo
->AuthnSvc
;
826 auth_hdr
->auth_level
= Connection
->AuthInfo
->AuthnLevel
;
827 auth_hdr
->auth_pad_length
= auth_pad_len
;
828 auth_hdr
->auth_reserved
= 0;
829 /* a unique number... */
830 auth_hdr
->auth_context_id
= Connection
->auth_context_id
;
833 memcpy(auth_hdr
+ 1, Auth
, AuthLength
);
836 status
= rpcrt4_conn_secure_packet(Connection
, SECURE_PACKET_SEND
,
837 (RpcPktHdr
*)pkt
, hdr_size
,
838 pkt
+ hdr_size
, Header
->common
.frag_len
- hdr_size
- alen
,
840 (unsigned char *)(auth_hdr
+ 1), Header
->common
.auth_len
);
841 if (status
!= RPC_S_OK
)
843 HeapFree(GetProcessHeap(), 0, pkt
);
844 RPCRT4_SetThreadCurrentConnection(NULL
);
851 count
= rpcrt4_conn_write(Connection
, pkt
, Header
->common
.frag_len
);
852 HeapFree(GetProcessHeap(), 0, pkt
);
854 WARN("rpcrt4_conn_write failed (auth)\n");
855 RPCRT4_SetThreadCurrentConnection(NULL
);
856 return RPC_S_CALL_FAILED
;
859 buffer_pos
+= Header
->common
.frag_len
- hdr_size
- alen
- auth_pad_len
;
860 BufferLength
-= Header
->common
.frag_len
- hdr_size
- alen
- auth_pad_len
;
861 Header
->common
.flags
&= ~RPC_FLG_FIRST
;
864 RPCRT4_SetThreadCurrentConnection(NULL
);
868 /***********************************************************************
869 * RPCRT4_default_authorize (internal)
871 * Authorize a client connection.
873 RPC_STATUS
RPCRT4_default_authorize(RpcConnection
*conn
, BOOL first_time
,
874 unsigned char *in_buffer
,
875 unsigned int in_size
,
876 unsigned char *out_buffer
,
877 unsigned int *out_size
)
880 SecBufferDesc out_desc
;
881 SecBufferDesc inp_desc
;
882 SecPkgContext_Sizes secctx_sizes
;
883 BOOL continue_needed
;
889 *out_size
= conn
->AuthInfo
->cbMaxToken
;
893 in
.BufferType
= SECBUFFER_TOKEN
;
894 in
.pvBuffer
= in_buffer
;
895 in
.cbBuffer
= in_size
;
897 out
.BufferType
= SECBUFFER_TOKEN
;
898 out
.pvBuffer
= out_buffer
;
899 out
.cbBuffer
= *out_size
;
901 out_desc
.ulVersion
= 0;
902 out_desc
.cBuffers
= 1;
903 out_desc
.pBuffers
= &out
;
905 inp_desc
.ulVersion
= 0;
906 inp_desc
.cBuffers
= 1;
907 inp_desc
.pBuffers
= &in
;
911 context_req
= ASC_REQ_CONNECTION
| ASC_REQ_USE_DCE_STYLE
|
914 if (conn
->AuthInfo
->AuthnLevel
== RPC_C_AUTHN_LEVEL_PKT_INTEGRITY
)
915 context_req
|= ASC_REQ_INTEGRITY
;
916 else if (conn
->AuthInfo
->AuthnLevel
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
917 context_req
|= ASC_REQ_CONFIDENTIALITY
| ASC_REQ_INTEGRITY
;
919 r
= AcceptSecurityContext(&conn
->AuthInfo
->cred
,
920 first_time
? NULL
: &conn
->ctx
,
921 &inp_desc
, context_req
, SECURITY_NETWORK_DREP
,
923 &out_desc
, &conn
->attr
, &conn
->exp
);
924 if (r
== SEC_E_OK
|| r
== SEC_I_COMPLETE_NEEDED
)
926 /* authorisation done, so nothing more to send */
932 context_req
= ISC_REQ_CONNECTION
| ISC_REQ_USE_DCE_STYLE
|
933 ISC_REQ_MUTUAL_AUTH
| ISC_REQ_DELEGATE
;
935 if (conn
->AuthInfo
->AuthnLevel
== RPC_C_AUTHN_LEVEL_PKT_INTEGRITY
)
936 context_req
|= ISC_REQ_INTEGRITY
;
937 else if (conn
->AuthInfo
->AuthnLevel
== RPC_C_AUTHN_LEVEL_PKT_PRIVACY
)
938 context_req
|= ISC_REQ_CONFIDENTIALITY
| ISC_REQ_INTEGRITY
;
940 r
= InitializeSecurityContextW(&conn
->AuthInfo
->cred
,
941 first_time
? NULL
: &conn
->ctx
,
942 first_time
? conn
->AuthInfo
->server_principal_name
: NULL
,
943 context_req
, 0, SECURITY_NETWORK_DREP
,
944 first_time
? NULL
: &inp_desc
, 0, &conn
->ctx
,
945 &out_desc
, &conn
->attr
, &conn
->exp
);
949 WARN("InitializeSecurityContext failed with error 0x%08x\n", r
);
953 TRACE("r = 0x%08x, attr = 0x%08x\n", r
, conn
->attr
);
954 continue_needed
= ((r
== SEC_I_CONTINUE_NEEDED
) ||
955 (r
== SEC_I_COMPLETE_AND_CONTINUE
));
957 if ((r
== SEC_I_COMPLETE_NEEDED
) || (r
== SEC_I_COMPLETE_AND_CONTINUE
))
959 TRACE("complete needed\n");
960 r
= CompleteAuthToken(&conn
->ctx
, &out_desc
);
963 WARN("CompleteAuthToken failed with error 0x%08x\n", r
);
968 TRACE("cbBuffer = %d\n", out
.cbBuffer
);
970 if (!continue_needed
)
972 r
= QueryContextAttributesA(&conn
->ctx
, SECPKG_ATTR_SIZES
, &secctx_sizes
);
975 WARN("QueryContextAttributes failed with error 0x%08x\n", r
);
978 conn
->signature_auth_len
= secctx_sizes
.cbMaxSignature
;
979 conn
->encryption_auth_len
= secctx_sizes
.cbSecurityTrailer
;
982 *out_size
= out
.cbBuffer
;
987 return ERROR_ACCESS_DENIED
; /* FIXME: is this correct? */
990 /***********************************************************************
991 * RPCRT4_ClientConnectionAuth (internal)
993 RPC_STATUS
RPCRT4_ClientConnectionAuth(RpcConnection
* conn
, BYTE
*challenge
,
998 unsigned char *out_buffer
;
999 unsigned int out_len
= 0;
1001 TRACE("challenge %s, %d bytes\n", challenge
, count
);
1003 status
= rpcrt4_conn_authorize(conn
, FALSE
, challenge
, count
, NULL
, &out_len
);
1004 if (status
) return status
;
1005 out_buffer
= HeapAlloc(GetProcessHeap(), 0, out_len
);
1006 if (!out_buffer
) return RPC_S_OUT_OF_RESOURCES
;
1007 status
= rpcrt4_conn_authorize(conn
, FALSE
, challenge
, count
, out_buffer
, &out_len
);
1008 if (status
) return status
;
1010 resp_hdr
= RPCRT4_BuildAuthHeader(NDR_LOCAL_DATA_REPRESENTATION
);
1013 status
= RPCRT4_SendWithAuth(conn
, resp_hdr
, NULL
, 0, out_buffer
, out_len
);
1015 status
= RPC_S_OUT_OF_RESOURCES
;
1017 HeapFree(GetProcessHeap(), 0, out_buffer
);
1018 RPCRT4_FreeHeader(resp_hdr
);
1023 /***********************************************************************
1024 * RPCRT4_ServerConnectionAuth (internal)
1026 RPC_STATUS
RPCRT4_ServerConnectionAuth(RpcConnection
* conn
,
1028 RpcAuthVerifier
*auth_data_in
,
1029 ULONG auth_length_in
,
1030 unsigned char **auth_data_out
,
1031 ULONG
*auth_length_out
)
1033 unsigned char *out_buffer
;
1034 unsigned int out_size
;
1039 /* remove any existing authentication information */
1042 RpcAuthInfo_Release(conn
->AuthInfo
);
1043 conn
->AuthInfo
= NULL
;
1045 if (SecIsValidHandle(&conn
->ctx
))
1047 DeleteSecurityContext(&conn
->ctx
);
1048 SecInvalidateHandle(&conn
->ctx
);
1050 if (auth_length_in
>= sizeof(RpcAuthVerifier
))
1056 status
= RPCRT4_ServerGetRegisteredAuthInfo(
1057 auth_data_in
->auth_type
, &cred
, &exp
, &max_token
);
1058 if (status
!= RPC_S_OK
)
1060 ERR("unknown authentication service %u\n", auth_data_in
->auth_type
);
1064 status
= RpcAuthInfo_Create(auth_data_in
->auth_level
,
1065 auth_data_in
->auth_type
, cred
, exp
,
1066 max_token
, NULL
, &conn
->AuthInfo
);
1067 if (status
!= RPC_S_OK
)
1070 /* FIXME: should auth_data_in->auth_context_id be checked in the !start case? */
1071 conn
->auth_context_id
= auth_data_in
->auth_context_id
;
1075 if (auth_length_in
< sizeof(RpcAuthVerifier
))
1078 if (!conn
->AuthInfo
)
1079 /* should have filled in authentication info by now */
1080 return RPC_S_PROTOCOL_ERROR
;
1082 status
= rpcrt4_conn_authorize(
1083 conn
, start
, (unsigned char *)(auth_data_in
+ 1),
1084 auth_length_in
- sizeof(RpcAuthVerifier
), NULL
, &out_size
);
1085 if (status
) return status
;
1087 out_buffer
= HeapAlloc(GetProcessHeap(), 0, out_size
);
1088 if (!out_buffer
) return RPC_S_OUT_OF_RESOURCES
;
1090 status
= rpcrt4_conn_authorize(
1091 conn
, start
, (unsigned char *)(auth_data_in
+ 1),
1092 auth_length_in
- sizeof(RpcAuthVerifier
), out_buffer
, &out_size
);
1093 if (status
!= RPC_S_OK
)
1095 HeapFree(GetProcessHeap(), 0, out_buffer
);
1099 if (out_size
&& !auth_length_out
)
1101 ERR("expected authentication to be complete but SSP returned data of "
1102 "%u bytes to be sent back to client\n", out_size
);
1103 HeapFree(GetProcessHeap(), 0, out_buffer
);
1104 return RPC_S_SEC_PKG_ERROR
;
1108 *auth_data_out
= out_buffer
;
1109 *auth_length_out
= out_size
;
1115 /***********************************************************************
1116 * RPCRT4_default_is_authorized (internal)
1118 * Has a connection started the process of authorizing with the server?
1120 BOOL
RPCRT4_default_is_authorized(RpcConnection
*Connection
)
1122 return Connection
->AuthInfo
&& SecIsValidHandle(&Connection
->ctx
);
1125 /***********************************************************************
1126 * RPCRT4_default_impersonate_client (internal)
1129 RPC_STATUS
RPCRT4_default_impersonate_client(RpcConnection
*conn
)
1131 SECURITY_STATUS sec_status
;
1133 TRACE("(%p)\n", conn
);
1135 if (!conn
->AuthInfo
|| !SecIsValidHandle(&conn
->ctx
))
1136 return RPC_S_NO_CONTEXT_AVAILABLE
;
1137 sec_status
= ImpersonateSecurityContext(&conn
->ctx
);
1138 if (sec_status
!= SEC_E_OK
)
1139 WARN("ImpersonateSecurityContext returned 0x%08x\n", sec_status
);
1142 case SEC_E_UNSUPPORTED_FUNCTION
:
1143 return RPC_S_CANNOT_SUPPORT
;
1144 case SEC_E_NO_IMPERSONATION
:
1145 return RPC_S_NO_CONTEXT_AVAILABLE
;
1149 return RPC_S_SEC_PKG_ERROR
;
1153 /***********************************************************************
1154 * RPCRT4_default_revert_to_self (internal)
1157 RPC_STATUS
RPCRT4_default_revert_to_self(RpcConnection
*conn
)
1159 SECURITY_STATUS sec_status
;
1161 TRACE("(%p)\n", conn
);
1163 if (!conn
->AuthInfo
|| !SecIsValidHandle(&conn
->ctx
))
1164 return RPC_S_NO_CONTEXT_AVAILABLE
;
1165 sec_status
= RevertSecurityContext(&conn
->ctx
);
1166 if (sec_status
!= SEC_E_OK
)
1167 WARN("RevertSecurityContext returned 0x%08x\n", sec_status
);
1170 case SEC_E_UNSUPPORTED_FUNCTION
:
1171 return RPC_S_CANNOT_SUPPORT
;
1172 case SEC_E_NO_IMPERSONATION
:
1173 return RPC_S_NO_CONTEXT_AVAILABLE
;
1177 return RPC_S_SEC_PKG_ERROR
;
1181 /***********************************************************************
1182 * RPCRT4_default_inquire_auth_client (internal)
1184 * Default function to retrieve the authentication details that the client
1185 * is using to call the server.
1187 RPC_STATUS
RPCRT4_default_inquire_auth_client(
1188 RpcConnection
*conn
, RPC_AUTHZ_HANDLE
*privs
, RPC_WSTR
*server_princ_name
,
1189 ULONG
*authn_level
, ULONG
*authn_svc
, ULONG
*authz_svc
, ULONG flags
)
1191 if (!conn
->AuthInfo
) return RPC_S_BINDING_HAS_NO_AUTH
;
1195 FIXME("privs not implemented\n");
1198 if (server_princ_name
)
1200 *server_princ_name
= RPCRT4_strdupW(conn
->AuthInfo
->server_principal_name
);
1201 if (!*server_princ_name
) return ERROR_OUTOFMEMORY
;
1203 if (authn_level
) *authn_level
= conn
->AuthInfo
->AuthnLevel
;
1204 if (authn_svc
) *authn_svc
= conn
->AuthInfo
->AuthnSvc
;
1207 FIXME("authorization service not implemented\n");
1208 *authz_svc
= RPC_C_AUTHZ_NONE
;
1211 FIXME("flags 0x%x not implemented\n", flags
);
1216 /***********************************************************************
1217 * RPCRT4_Send (internal)
1219 * Transmit a packet over connection in acceptable fragments.
1221 RPC_STATUS
RPCRT4_Send(RpcConnection
*Connection
, RpcPktHdr
*Header
,
1222 void *Buffer
, unsigned int BufferLength
)
1226 if (packet_does_auth_negotiation(Header
) &&
1227 Connection
->AuthInfo
&&
1228 !rpcrt4_conn_is_authorized(Connection
))
1230 unsigned int out_size
= 0;
1231 unsigned char *out_buffer
;
1233 r
= rpcrt4_conn_authorize(Connection
, TRUE
, NULL
, 0, NULL
, &out_size
);
1234 if (r
!= RPC_S_OK
) return r
;
1236 out_buffer
= HeapAlloc(GetProcessHeap(), 0, out_size
);
1237 if (!out_buffer
) return RPC_S_OUT_OF_RESOURCES
;
1239 /* tack on a negotiate packet */
1240 r
= rpcrt4_conn_authorize(Connection
, TRUE
, NULL
, 0, out_buffer
, &out_size
);
1242 r
= RPCRT4_SendWithAuth(Connection
, Header
, Buffer
, BufferLength
, out_buffer
, out_size
);
1244 HeapFree(GetProcessHeap(), 0, out_buffer
);
1247 r
= RPCRT4_SendWithAuth(Connection
, Header
, Buffer
, BufferLength
, NULL
, 0);
1252 /* validates version and frag_len fields */
1253 RPC_STATUS
RPCRT4_ValidateCommonHeader(const RpcPktCommonHdr
*hdr
)
1257 /* verify if the header really makes sense */
1258 if (hdr
->rpc_ver
!= RPC_VER_MAJOR
||
1259 hdr
->rpc_ver_minor
!= RPC_VER_MINOR
)
1261 WARN("unhandled packet version\n");
1262 return RPC_S_PROTOCOL_ERROR
;
1265 hdr_length
= RPCRT4_GetHeaderSize((const RpcPktHdr
*)hdr
);
1266 if (hdr_length
== 0)
1268 WARN("header length == 0\n");
1269 return RPC_S_PROTOCOL_ERROR
;
1272 if (hdr
->frag_len
< hdr_length
)
1274 WARN("bad frag length %d\n", hdr
->frag_len
);
1275 return RPC_S_PROTOCOL_ERROR
;
1281 /***********************************************************************
1282 * RPCRT4_default_receive_fragment (internal)
1284 * Receive a fragment from a connection.
1286 static RPC_STATUS
RPCRT4_default_receive_fragment(RpcConnection
*Connection
, RpcPktHdr
**Header
, void **Payload
)
1291 RpcPktCommonHdr common_hdr
;
1296 TRACE("(%p, %p, %p)\n", Connection
, Header
, Payload
);
1298 /* read packet common header */
1299 dwRead
= rpcrt4_conn_read(Connection
, &common_hdr
, sizeof(common_hdr
));
1300 if (dwRead
!= sizeof(common_hdr
)) {
1301 WARN("Short read of header, %d bytes\n", dwRead
);
1302 status
= RPC_S_CALL_FAILED
;
1306 status
= RPCRT4_ValidateCommonHeader(&common_hdr
);
1307 if (status
!= RPC_S_OK
) goto fail
;
1309 hdr_length
= RPCRT4_GetHeaderSize((RpcPktHdr
*)&common_hdr
);
1310 if (hdr_length
== 0) {
1311 WARN("header length == 0\n");
1312 status
= RPC_S_PROTOCOL_ERROR
;
1316 *Header
= HeapAlloc(GetProcessHeap(), 0, hdr_length
);
1317 memcpy(*Header
, &common_hdr
, sizeof(common_hdr
));
1319 /* read the rest of packet header */
1320 dwRead
= rpcrt4_conn_read(Connection
, &(*Header
)->common
+ 1, hdr_length
- sizeof(common_hdr
));
1321 if (dwRead
!= hdr_length
- sizeof(common_hdr
)) {
1322 WARN("bad header length, %d bytes, hdr_length %d\n", dwRead
, hdr_length
);
1323 status
= RPC_S_CALL_FAILED
;
1327 if (common_hdr
.frag_len
- hdr_length
)
1329 *Payload
= HeapAlloc(GetProcessHeap(), 0, common_hdr
.frag_len
- hdr_length
);
1332 status
= RPC_S_OUT_OF_RESOURCES
;
1336 dwRead
= rpcrt4_conn_read(Connection
, *Payload
, common_hdr
.frag_len
- hdr_length
);
1337 if (dwRead
!= common_hdr
.frag_len
- hdr_length
)
1339 WARN("bad data length, %d/%d\n", dwRead
, common_hdr
.frag_len
- hdr_length
);
1340 status
= RPC_S_CALL_FAILED
;
1351 if (status
!= RPC_S_OK
) {
1352 RPCRT4_FreeHeader(*Header
);
1354 HeapFree(GetProcessHeap(), 0, *Payload
);
1360 static RPC_STATUS
RPCRT4_receive_fragment(RpcConnection
*Connection
, RpcPktHdr
**Header
, void **Payload
)
1362 if (Connection
->ops
->receive_fragment
)
1363 return Connection
->ops
->receive_fragment(Connection
, Header
, Payload
);
1365 return RPCRT4_default_receive_fragment(Connection
, Header
, Payload
);
1368 /***********************************************************************
1369 * RPCRT4_ReceiveWithAuth (internal)
1371 * Receive a packet from connection, merge the fragments and return the auth
1374 RPC_STATUS
RPCRT4_ReceiveWithAuth(RpcConnection
*Connection
, RpcPktHdr
**Header
,
1376 unsigned char **auth_data_out
,
1377 ULONG
*auth_length_out
)
1381 unsigned short first_flag
;
1383 ULONG buffer_length
;
1384 ULONG auth_length
= 0;
1385 unsigned char *auth_data
= NULL
;
1386 RpcPktHdr
*CurrentHeader
= NULL
;
1387 void *payload
= NULL
;
1390 pMsg
->Buffer
= NULL
;
1391 if (auth_data_out
) *auth_data_out
= NULL
;
1392 if (auth_length_out
) *auth_length_out
= 0;
1394 TRACE("(%p, %p, %p, %p)\n", Connection
, Header
, pMsg
, auth_data_out
);
1396 RPCRT4_SetThreadCurrentConnection(Connection
);
1398 status
= RPCRT4_receive_fragment(Connection
, Header
, &payload
);
1399 if (status
!= RPC_S_OK
) goto fail
;
1401 hdr_length
= RPCRT4_GetHeaderSize(*Header
);
1403 /* read packet body */
1404 switch ((*Header
)->common
.ptype
) {
1406 pMsg
->BufferLength
= (*Header
)->response
.alloc_hint
;
1409 pMsg
->BufferLength
= (*Header
)->request
.alloc_hint
;
1412 pMsg
->BufferLength
= (*Header
)->common
.frag_len
- hdr_length
- RPC_AUTH_VERIFIER_LEN(&(*Header
)->common
);
1415 TRACE("buffer length = %u\n", pMsg
->BufferLength
);
1417 pMsg
->Buffer
= I_RpcAllocate(pMsg
->BufferLength
);
1420 status
= ERROR_OUTOFMEMORY
;
1424 first_flag
= RPC_FLG_FIRST
;
1425 auth_length
= (*Header
)->common
.auth_len
;
1427 auth_data
= HeapAlloc(GetProcessHeap(), 0, RPC_AUTH_VERIFIER_LEN(&(*Header
)->common
));
1429 status
= RPC_S_OUT_OF_RESOURCES
;
1433 CurrentHeader
= *Header
;
1437 unsigned int header_auth_len
= RPC_AUTH_VERIFIER_LEN(&CurrentHeader
->common
);
1439 /* verify header fields */
1441 if ((CurrentHeader
->common
.frag_len
< hdr_length
) ||
1442 (CurrentHeader
->common
.frag_len
- hdr_length
< header_auth_len
)) {
1443 WARN("frag_len %d too small for hdr_length %d and auth_len %d\n",
1444 CurrentHeader
->common
.frag_len
, hdr_length
, CurrentHeader
->common
.auth_len
);
1445 status
= RPC_S_PROTOCOL_ERROR
;
1449 if (CurrentHeader
->common
.auth_len
!= auth_length
) {
1450 WARN("auth_len header field changed from %d to %d\n",
1451 auth_length
, CurrentHeader
->common
.auth_len
);
1452 status
= RPC_S_PROTOCOL_ERROR
;
1456 if ((CurrentHeader
->common
.flags
& RPC_FLG_FIRST
) != first_flag
) {
1457 TRACE("invalid packet flags\n");
1458 status
= RPC_S_PROTOCOL_ERROR
;
1462 data_length
= CurrentHeader
->common
.frag_len
- hdr_length
- header_auth_len
;
1463 if (data_length
+ buffer_length
> pMsg
->BufferLength
) {
1464 TRACE("allocation hint exceeded, new buffer length = %d\n",
1465 data_length
+ buffer_length
);
1466 pMsg
->BufferLength
= data_length
+ buffer_length
;
1467 status
= I_RpcReAllocateBuffer(pMsg
);
1468 if (status
!= RPC_S_OK
) goto fail
;
1471 memcpy((unsigned char *)pMsg
->Buffer
+ buffer_length
, payload
, data_length
);
1473 if (header_auth_len
) {
1474 if (header_auth_len
< sizeof(RpcAuthVerifier
) ||
1475 header_auth_len
> RPC_AUTH_VERIFIER_LEN(&(*Header
)->common
)) {
1476 WARN("bad auth verifier length %d\n", header_auth_len
);
1477 status
= RPC_S_PROTOCOL_ERROR
;
1481 /* FIXME: we should accumulate authentication data for the bind,
1482 * bind_ack, alter_context and alter_context_response if necessary.
1483 * however, the details of how this is done is very sketchy in the
1484 * DCE/RPC spec. for all other packet types that have authentication
1485 * verifier data then it is just duplicated in all the fragments */
1486 memcpy(auth_data
, (unsigned char *)payload
+ data_length
, header_auth_len
);
1488 /* these packets are handled specially, not by the generic SecurePacket
1490 if (!packet_does_auth_negotiation(*Header
) && rpcrt4_conn_is_authorized(Connection
))
1492 status
= rpcrt4_conn_secure_packet(Connection
, SECURE_PACKET_RECEIVE
,
1493 CurrentHeader
, hdr_length
,
1494 (unsigned char *)pMsg
->Buffer
+ buffer_length
, data_length
,
1495 (RpcAuthVerifier
*)auth_data
,
1496 auth_data
+ sizeof(RpcAuthVerifier
),
1497 header_auth_len
- sizeof(RpcAuthVerifier
));
1498 if (status
!= RPC_S_OK
) goto fail
;
1502 buffer_length
+= data_length
;
1503 if (!(CurrentHeader
->common
.flags
& RPC_FLG_LAST
)) {
1504 TRACE("next header\n");
1506 if (*Header
!= CurrentHeader
)
1508 RPCRT4_FreeHeader(CurrentHeader
);
1509 CurrentHeader
= NULL
;
1511 HeapFree(GetProcessHeap(), 0, payload
);
1514 status
= RPCRT4_receive_fragment(Connection
, &CurrentHeader
, &payload
);
1515 if (status
!= RPC_S_OK
) goto fail
;
1522 pMsg
->BufferLength
= buffer_length
;
1528 RPCRT4_SetThreadCurrentConnection(NULL
);
1529 if (CurrentHeader
!= *Header
)
1530 RPCRT4_FreeHeader(CurrentHeader
);
1531 if (status
!= RPC_S_OK
) {
1532 I_RpcFree(pMsg
->Buffer
);
1533 pMsg
->Buffer
= NULL
;
1534 RPCRT4_FreeHeader(*Header
);
1537 if (auth_data_out
&& status
== RPC_S_OK
) {
1538 *auth_length_out
= auth_length
;
1539 *auth_data_out
= auth_data
;
1542 HeapFree(GetProcessHeap(), 0, auth_data
);
1543 HeapFree(GetProcessHeap(), 0, payload
);
1547 /***********************************************************************
1548 * RPCRT4_Receive (internal)
1550 * Receive a packet from connection and merge the fragments.
1552 static RPC_STATUS
RPCRT4_Receive(RpcConnection
*Connection
, RpcPktHdr
**Header
,
1555 return RPCRT4_ReceiveWithAuth(Connection
, Header
, pMsg
, NULL
, NULL
);
1558 /***********************************************************************
1559 * I_RpcNegotiateTransferSyntax [RPCRT4.@]
1561 * Negotiates the transfer syntax used by a client connection by connecting
1565 * pMsg [I] RPC Message structure.
1566 * pAsync [I] Asynchronous state to set.
1569 * Success: RPC_S_OK.
1570 * Failure: Any error code.
1572 RPC_STATUS WINAPI
I_RpcNegotiateTransferSyntax(PRPC_MESSAGE pMsg
)
1574 RpcBinding
* bind
= pMsg
->Handle
;
1575 RpcConnection
* conn
;
1576 RPC_STATUS status
= RPC_S_OK
;
1578 TRACE("(%p)\n", pMsg
);
1580 if (!bind
|| bind
->server
)
1582 ERR("no binding\n");
1583 return RPC_S_INVALID_BINDING
;
1586 /* if we already have a connection, we don't need to negotiate again */
1587 if (!pMsg
->ReservedForRuntime
)
1589 RPC_CLIENT_INTERFACE
*cif
= pMsg
->RpcInterfaceInformation
;
1590 if (!cif
) return RPC_S_INTERFACE_NOT_FOUND
;
1592 if (!bind
->Endpoint
|| !bind
->Endpoint
[0])
1594 TRACE("automatically resolving partially bound binding\n");
1595 status
= RpcEpResolveBinding(bind
, cif
);
1596 if (status
!= RPC_S_OK
) return status
;
1599 status
= RPCRT4_OpenBinding(bind
, &conn
, &cif
->TransferSyntax
,
1602 if (status
== RPC_S_OK
)
1604 pMsg
->ReservedForRuntime
= conn
;
1605 RPCRT4_AddRefBinding(bind
);
1612 /***********************************************************************
1613 * I_RpcGetBuffer [RPCRT4.@]
1615 * Allocates a buffer for use by I_RpcSend or I_RpcSendReceive and binds to the
1619 * pMsg [I/O] RPC message information.
1622 * Success: RPC_S_OK.
1623 * Failure: RPC_S_INVALID_BINDING if pMsg->Handle is invalid.
1624 * RPC_S_SERVER_UNAVAILABLE if unable to connect to server.
1625 * ERROR_OUTOFMEMORY if buffer allocation failed.
1628 * The pMsg->BufferLength field determines the size of the buffer to allocate,
1631 * Use I_RpcFreeBuffer() to unbind from the server and free the message buffer.
1634 * I_RpcFreeBuffer(), I_RpcSend(), I_RpcReceive(), I_RpcSendReceive().
1636 RPC_STATUS WINAPI
I_RpcGetBuffer(PRPC_MESSAGE pMsg
)
1639 RpcBinding
* bind
= pMsg
->Handle
;
1641 TRACE("(%p): BufferLength=%d\n", pMsg
, pMsg
->BufferLength
);
1645 ERR("no binding\n");
1646 return RPC_S_INVALID_BINDING
;
1649 pMsg
->Buffer
= I_RpcAllocate(pMsg
->BufferLength
);
1650 TRACE("Buffer=%p\n", pMsg
->Buffer
);
1653 return ERROR_OUTOFMEMORY
;
1657 status
= I_RpcNegotiateTransferSyntax(pMsg
);
1658 if (status
!= RPC_S_OK
)
1659 I_RpcFree(pMsg
->Buffer
);
1667 /***********************************************************************
1668 * I_RpcReAllocateBuffer (internal)
1670 static RPC_STATUS
I_RpcReAllocateBuffer(PRPC_MESSAGE pMsg
)
1672 TRACE("(%p): BufferLength=%d\n", pMsg
, pMsg
->BufferLength
);
1673 pMsg
->Buffer
= HeapReAlloc(GetProcessHeap(), 0, pMsg
->Buffer
, pMsg
->BufferLength
);
1675 TRACE("Buffer=%p\n", pMsg
->Buffer
);
1676 return pMsg
->Buffer
? RPC_S_OK
: ERROR_OUTOFMEMORY
;
1679 /***********************************************************************
1680 * I_RpcFreeBuffer [RPCRT4.@]
1682 * Frees a buffer allocated by I_RpcGetBuffer or I_RpcReceive and unbinds from
1683 * the server interface.
1686 * pMsg [I/O] RPC message information.
1692 * I_RpcGetBuffer(), I_RpcReceive().
1694 RPC_STATUS WINAPI
I_RpcFreeBuffer(PRPC_MESSAGE pMsg
)
1696 RpcBinding
* bind
= pMsg
->Handle
;
1698 TRACE("(%p) Buffer=%p\n", pMsg
, pMsg
->Buffer
);
1702 ERR("no binding\n");
1703 return RPC_S_INVALID_BINDING
;
1706 if (pMsg
->ReservedForRuntime
)
1708 RpcConnection
*conn
= pMsg
->ReservedForRuntime
;
1709 RPCRT4_CloseBinding(bind
, conn
);
1710 RPCRT4_ReleaseBinding(bind
);
1711 pMsg
->ReservedForRuntime
= NULL
;
1713 I_RpcFree(pMsg
->Buffer
);
1717 static void CALLBACK
async_apc_notifier_proc(ULONG_PTR ulParam
)
1719 RPC_ASYNC_STATE
*state
= (RPC_ASYNC_STATE
*)ulParam
;
1720 state
->u
.APC
.NotificationRoutine(state
, NULL
, state
->Event
);
1723 static DWORD WINAPI
async_notifier_proc(LPVOID p
)
1725 RpcConnection
*conn
= p
;
1726 RPC_ASYNC_STATE
*state
= conn
->async_state
;
1728 if (state
&& conn
->ops
->wait_for_incoming_data(conn
) != -1)
1730 state
->Event
= RpcCallComplete
;
1731 switch (state
->NotificationType
)
1733 case RpcNotificationTypeEvent
:
1734 TRACE("RpcNotificationTypeEvent %p\n", state
->u
.hEvent
);
1735 SetEvent(state
->u
.hEvent
);
1737 case RpcNotificationTypeApc
:
1738 TRACE("RpcNotificationTypeApc %p\n", state
->u
.APC
.hThread
);
1739 QueueUserAPC(async_apc_notifier_proc
, state
->u
.APC
.hThread
, (ULONG_PTR
)state
);
1741 case RpcNotificationTypeIoc
:
1742 TRACE("RpcNotificationTypeIoc %p, 0x%x, 0x%lx, %p\n",
1743 state
->u
.IOC
.hIOPort
, state
->u
.IOC
.dwNumberOfBytesTransferred
,
1744 state
->u
.IOC
.dwCompletionKey
, state
->u
.IOC
.lpOverlapped
);
1745 PostQueuedCompletionStatus(state
->u
.IOC
.hIOPort
,
1746 state
->u
.IOC
.dwNumberOfBytesTransferred
,
1747 state
->u
.IOC
.dwCompletionKey
,
1748 state
->u
.IOC
.lpOverlapped
);
1750 case RpcNotificationTypeHwnd
:
1751 TRACE("RpcNotificationTypeHwnd %p 0x%x\n", state
->u
.HWND
.hWnd
,
1753 PostMessageW(state
->u
.HWND
.hWnd
, state
->u
.HWND
.Msg
, 0, 0);
1755 case RpcNotificationTypeCallback
:
1756 TRACE("RpcNotificationTypeCallback %p\n", state
->u
.NotificationRoutine
);
1757 state
->u
.NotificationRoutine(state
, NULL
, state
->Event
);
1759 case RpcNotificationTypeNone
:
1760 TRACE("RpcNotificationTypeNone\n");
1763 FIXME("unknown NotificationType: %d/0x%x\n", state
->NotificationType
, state
->NotificationType
);
1771 /***********************************************************************
1772 * I_RpcSend [RPCRT4.@]
1774 * Sends a message to the server.
1777 * pMsg [I/O] RPC message information.
1783 * The buffer must have been allocated with I_RpcGetBuffer().
1786 * I_RpcGetBuffer(), I_RpcReceive(), I_RpcSendReceive().
1788 RPC_STATUS WINAPI
I_RpcSend(PRPC_MESSAGE pMsg
)
1790 RpcBinding
* bind
= pMsg
->Handle
;
1791 RpcConnection
* conn
;
1795 TRACE("(%p)\n", pMsg
);
1796 if (!bind
|| bind
->server
|| !pMsg
->ReservedForRuntime
) return RPC_S_INVALID_BINDING
;
1798 conn
= pMsg
->ReservedForRuntime
;
1800 hdr
= RPCRT4_BuildRequestHeader(pMsg
->DataRepresentation
,
1802 pMsg
->ProcNum
& ~RPC_FLAGS_VALID_BIT
,
1805 return ERROR_OUTOFMEMORY
;
1806 hdr
->common
.call_id
= conn
->NextCallId
++;
1808 status
= RPCRT4_Send(conn
, hdr
, pMsg
->Buffer
, pMsg
->BufferLength
);
1810 RPCRT4_FreeHeader(hdr
);
1812 if (status
== RPC_S_OK
&& pMsg
->RpcFlags
& RPC_BUFFER_ASYNC
)
1814 if (!QueueUserWorkItem(async_notifier_proc
, conn
, WT_EXECUTEDEFAULT
| WT_EXECUTELONGFUNCTION
))
1815 status
= RPC_S_OUT_OF_RESOURCES
;
1821 /* is this status something that the server can't recover from? */
1822 static inline BOOL
is_hard_error(RPC_STATUS status
)
1826 case 0: /* user-defined fault */
1827 case ERROR_ACCESS_DENIED
:
1828 case ERROR_INVALID_PARAMETER
:
1829 case RPC_S_PROTOCOL_ERROR
:
1830 case RPC_S_CALL_FAILED
:
1831 case RPC_S_CALL_FAILED_DNE
:
1832 case RPC_S_SEC_PKG_ERROR
:
1839 /***********************************************************************
1840 * I_RpcReceive [RPCRT4.@]
1842 RPC_STATUS WINAPI
I_RpcReceive(PRPC_MESSAGE pMsg
)
1844 RpcBinding
* bind
= pMsg
->Handle
;
1846 RpcPktHdr
*hdr
= NULL
;
1847 RpcConnection
*conn
;
1849 TRACE("(%p)\n", pMsg
);
1850 if (!bind
|| bind
->server
|| !pMsg
->ReservedForRuntime
) return RPC_S_INVALID_BINDING
;
1852 conn
= pMsg
->ReservedForRuntime
;
1853 status
= RPCRT4_Receive(conn
, &hdr
, pMsg
);
1854 if (status
!= RPC_S_OK
) {
1855 WARN("receive failed with error %x\n", status
);
1859 switch (hdr
->common
.ptype
) {
1863 ERR ("we got fault packet with status 0x%x\n", hdr
->fault
.status
);
1864 status
= NCA2RPC_STATUS(hdr
->fault
.status
);
1865 if (is_hard_error(status
))
1869 WARN("bad packet type %d\n", hdr
->common
.ptype
);
1870 status
= RPC_S_PROTOCOL_ERROR
;
1875 RPCRT4_FreeHeader(hdr
);
1879 RPCRT4_FreeHeader(hdr
);
1880 RPCRT4_DestroyConnection(conn
);
1881 pMsg
->ReservedForRuntime
= NULL
;
1885 /***********************************************************************
1886 * I_RpcSendReceive [RPCRT4.@]
1888 * Sends a message to the server and receives the response.
1891 * pMsg [I/O] RPC message information.
1894 * Success: RPC_S_OK.
1895 * Failure: Any error code.
1898 * The buffer must have been allocated with I_RpcGetBuffer().
1901 * I_RpcGetBuffer(), I_RpcSend(), I_RpcReceive().
1903 RPC_STATUS WINAPI
I_RpcSendReceive(PRPC_MESSAGE pMsg
)
1906 void *original_buffer
;
1908 TRACE("(%p)\n", pMsg
);
1910 original_buffer
= pMsg
->Buffer
;
1911 status
= I_RpcSend(pMsg
);
1912 if (status
== RPC_S_OK
)
1913 status
= I_RpcReceive(pMsg
);
1914 /* free the buffer replaced by a new buffer in I_RpcReceive */
1915 if (status
== RPC_S_OK
)
1916 I_RpcFree(original_buffer
);
1920 /***********************************************************************
1921 * I_RpcAsyncSetHandle [RPCRT4.@]
1923 * Sets the asynchronous state of the handle contained in the RPC message
1927 * pMsg [I] RPC Message structure.
1928 * pAsync [I] Asynchronous state to set.
1931 * Success: RPC_S_OK.
1932 * Failure: Any error code.
1934 RPC_STATUS WINAPI
I_RpcAsyncSetHandle(PRPC_MESSAGE pMsg
, PRPC_ASYNC_STATE pAsync
)
1936 RpcBinding
* bind
= pMsg
->Handle
;
1937 RpcConnection
*conn
;
1939 TRACE("(%p, %p)\n", pMsg
, pAsync
);
1941 if (!bind
|| bind
->server
|| !pMsg
->ReservedForRuntime
) return RPC_S_INVALID_BINDING
;
1943 conn
= pMsg
->ReservedForRuntime
;
1944 conn
->async_state
= pAsync
;
1949 /***********************************************************************
1950 * I_RpcAsyncAbortCall [RPCRT4.@]
1952 * Aborts an asynchronous call.
1955 * pAsync [I] Asynchronous state.
1956 * ExceptionCode [I] Exception code.
1959 * Success: RPC_S_OK.
1960 * Failure: Any error code.
1962 RPC_STATUS WINAPI
I_RpcAsyncAbortCall(PRPC_ASYNC_STATE pAsync
, ULONG ExceptionCode
)
1964 FIXME("(%p, %d): stub\n", pAsync
, ExceptionCode
);
1965 return RPC_S_INVALID_ASYNC_HANDLE
;