2002-10-10 20:55:24 +02:00
|
|
|
/*
|
|
|
|
* RPC messages
|
|
|
|
*
|
2008-10-18 19:20:44 +02:00
|
|
|
* Copyright 2001-2002 Ove Kåven, TransGaming Technologies
|
2004-04-27 01:33:39 +02:00
|
|
|
* Copyright 2004 Filip Navara
|
2006-05-19 12:03:06 +02:00
|
|
|
* Copyright 2006 CodeWeavers
|
2002-10-10 20:55:24 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-10-10 20:55:24 +02:00
|
|
|
*/
|
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-10-10 20:55:24 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winerror.h"
|
2008-01-21 11:31:40 +01:00
|
|
|
#include "winuser.h"
|
2002-10-10 20:55:24 +02:00
|
|
|
|
|
|
|
#include "rpc.h"
|
2004-04-27 01:33:39 +02:00
|
|
|
#include "rpcndr.h"
|
2002-10-10 20:55:24 +02:00
|
|
|
#include "rpcdcep.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "rpc_binding.h"
|
|
|
|
#include "rpc_defs.h"
|
2005-07-24 19:11:59 +02:00
|
|
|
#include "rpc_message.h"
|
2007-07-05 13:46:59 +02:00
|
|
|
#include "ncastatus.h"
|
2002-10-10 20:55:24 +02:00
|
|
|
|
2005-03-14 11:11:04 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
|
2002-10-10 20:55:24 +02:00
|
|
|
|
2006-05-19 12:03:39 +02:00
|
|
|
/* note: the DCE/RPC spec says the alignment amount should be 4, but
|
|
|
|
* MS/RPC servers seem to always use 16 */
|
|
|
|
#define AUTH_ALIGNMENT 16
|
|
|
|
|
|
|
|
/* gets the amount needed to round a value up to the specified alignment */
|
|
|
|
#define ROUND_UP_AMOUNT(value, alignment) \
|
|
|
|
(((alignment) - (((value) % (alignment)))) % (alignment))
|
2006-11-10 12:01:35 +01:00
|
|
|
#define ROUND_UP(value, alignment) (((value) + ((alignment) - 1)) & ~((alignment)-1))
|
2006-05-19 12:03:39 +02:00
|
|
|
|
2006-11-15 02:00:36 +01:00
|
|
|
enum secure_packet_direction
|
|
|
|
{
|
|
|
|
SECURE_PACKET_SEND,
|
|
|
|
SECURE_PACKET_RECEIVE
|
|
|
|
};
|
|
|
|
|
2006-10-27 00:16:25 +02:00
|
|
|
static RPC_STATUS I_RpcReAllocateBuffer(PRPC_MESSAGE pMsg);
|
|
|
|
|
2009-03-18 12:13:19 +01:00
|
|
|
DWORD RPCRT4_GetHeaderSize(const RpcPktHdr *Header)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
static const DWORD header_sizes[] = {
|
|
|
|
sizeof(Header->request), 0, sizeof(Header->response),
|
|
|
|
sizeof(Header->fault), 0, 0, 0, 0, 0, 0, 0, sizeof(Header->bind),
|
|
|
|
sizeof(Header->bind_ack), sizeof(Header->bind_nack),
|
2009-03-18 12:13:19 +01:00
|
|
|
0, 0, 0, 0, 0, 0, sizeof(Header->http)
|
2004-04-27 01:33:39 +02:00
|
|
|
};
|
|
|
|
ULONG ret = 0;
|
|
|
|
|
|
|
|
if (Header->common.ptype < sizeof(header_sizes) / sizeof(header_sizes[0])) {
|
|
|
|
ret = header_sizes[Header->common.ptype];
|
|
|
|
if (ret == 0)
|
|
|
|
FIXME("unhandled packet type\n");
|
|
|
|
if (Header->common.flags & RPC_FLG_OBJECT_UUID)
|
|
|
|
ret += sizeof(UUID);
|
|
|
|
} else {
|
2009-03-18 12:13:19 +01:00
|
|
|
WARN("invalid packet type %u\n", Header->common.ptype);
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-03-26 19:19:33 +02:00
|
|
|
static int packet_has_body(const RpcPktHdr *Header)
|
2006-11-15 02:00:36 +01:00
|
|
|
{
|
|
|
|
return (Header->common.ptype == PKT_FAULT) ||
|
|
|
|
(Header->common.ptype == PKT_REQUEST) ||
|
|
|
|
(Header->common.ptype == PKT_RESPONSE);
|
|
|
|
}
|
|
|
|
|
2007-03-26 19:19:33 +02:00
|
|
|
static int packet_has_auth_verifier(const RpcPktHdr *Header)
|
2006-11-15 02:00:36 +01:00
|
|
|
{
|
|
|
|
return !(Header->common.ptype == PKT_BIND_NACK) &&
|
|
|
|
!(Header->common.ptype == PKT_SHUTDOWN);
|
|
|
|
}
|
|
|
|
|
2005-07-24 19:11:59 +02:00
|
|
|
static VOID RPCRT4_BuildCommonHeader(RpcPktHdr *Header, unsigned char PacketType,
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG DataRepresentation)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
Header->common.rpc_ver = RPC_VER_MAJOR;
|
|
|
|
Header->common.rpc_ver_minor = RPC_VER_MINOR;
|
|
|
|
Header->common.ptype = PacketType;
|
|
|
|
Header->common.drep[0] = LOBYTE(LOWORD(DataRepresentation));
|
|
|
|
Header->common.drep[1] = HIBYTE(LOWORD(DataRepresentation));
|
|
|
|
Header->common.drep[2] = LOBYTE(HIWORD(DataRepresentation));
|
|
|
|
Header->common.drep[3] = HIBYTE(HIWORD(DataRepresentation));
|
|
|
|
Header->common.auth_len = 0;
|
|
|
|
Header->common.call_id = 1;
|
|
|
|
Header->common.flags = 0;
|
|
|
|
/* Flags and fragment length are computed in RPCRT4_Send. */
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
static RpcPktHdr *RPCRT4_BuildRequestHeader(ULONG DataRepresentation,
|
|
|
|
ULONG BufferLength,
|
2004-04-27 01:33:39 +02:00
|
|
|
unsigned short ProcNum,
|
|
|
|
UUID *ObjectUuid)
|
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
BOOL has_object;
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
|
|
|
has_object = (ObjectUuid != NULL && !UuidIsNil(ObjectUuid, &status));
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(header->request) + (has_object ? sizeof(UUID) : 0));
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_REQUEST, DataRepresentation);
|
|
|
|
header->common.frag_len = sizeof(header->request);
|
|
|
|
header->request.alloc_hint = BufferLength;
|
|
|
|
header->request.context_id = 0;
|
|
|
|
header->request.opnum = ProcNum;
|
|
|
|
if (has_object) {
|
|
|
|
header->common.flags |= RPC_FLG_OBJECT_UUID;
|
|
|
|
header->common.frag_len += sizeof(UUID);
|
|
|
|
memcpy(&header->request + 1, ObjectUuid, sizeof(UUID));
|
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildResponseHeader(ULONG DataRepresentation, ULONG BufferLength)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->response));
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_RESPONSE, DataRepresentation);
|
|
|
|
header->common.frag_len = sizeof(header->response);
|
|
|
|
header->response.alloc_hint = BufferLength;
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildFaultHeader(ULONG DataRepresentation, RPC_STATUS Status)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->fault));
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_FAULT, DataRepresentation);
|
|
|
|
header->common.frag_len = sizeof(header->fault);
|
|
|
|
header->fault.status = Status;
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildBindHeader(ULONG DataRepresentation,
|
2004-04-27 01:33:39 +02:00
|
|
|
unsigned short MaxTransmissionSize,
|
|
|
|
unsigned short MaxReceiveSize,
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG AssocGroupId,
|
2007-06-26 23:26:58 +02:00
|
|
|
const RPC_SYNTAX_IDENTIFIER *AbstractId,
|
|
|
|
const RPC_SYNTAX_IDENTIFIER *TransferId)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->bind));
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_BIND, DataRepresentation);
|
|
|
|
header->common.frag_len = sizeof(header->bind);
|
|
|
|
header->bind.max_tsize = MaxTransmissionSize;
|
|
|
|
header->bind.max_rsize = MaxReceiveSize;
|
2007-06-25 15:26:23 +02:00
|
|
|
header->bind.assoc_gid = AssocGroupId;
|
2004-04-27 01:33:39 +02:00
|
|
|
header->bind.num_elements = 1;
|
|
|
|
header->bind.num_syntaxes = 1;
|
2008-03-13 21:52:48 +01:00
|
|
|
header->bind.abstract = *AbstractId;
|
|
|
|
header->bind.transfer = *TransferId;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
static RpcPktHdr *RPCRT4_BuildAuthHeader(ULONG DataRepresentation)
|
2006-05-15 16:04:25 +02:00
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
sizeof(header->common) + 12);
|
|
|
|
if (header == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_AUTH3, DataRepresentation);
|
|
|
|
header->common.frag_len = 0x14;
|
|
|
|
header->common.auth_len = 0;
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildBindNackHeader(ULONG DataRepresentation,
|
2004-04-27 01:33:39 +02:00
|
|
|
unsigned char RpcVersion,
|
|
|
|
unsigned char RpcVersionMinor)
|
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->bind_nack));
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_BIND_NACK, DataRepresentation);
|
|
|
|
header->common.frag_len = sizeof(header->bind_nack);
|
2007-07-20 12:35:34 +02:00
|
|
|
header->bind_nack.reject_reason = REJECT_REASON_NOT_SPECIFIED;
|
2004-04-27 01:33:39 +02:00
|
|
|
header->bind_nack.protocols_count = 1;
|
|
|
|
header->bind_nack.protocols[0].rpc_ver = RpcVersion;
|
|
|
|
header->bind_nack.protocols[0].rpc_ver_minor = RpcVersionMinor;
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildBindAckHeader(ULONG DataRepresentation,
|
2004-04-27 01:33:39 +02:00
|
|
|
unsigned short MaxTransmissionSize,
|
|
|
|
unsigned short MaxReceiveSize,
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG AssocGroupId,
|
2007-06-26 23:26:58 +02:00
|
|
|
LPCSTR ServerAddress,
|
2009-07-03 13:42:57 +02:00
|
|
|
unsigned short Result,
|
|
|
|
unsigned short Reason,
|
2007-06-26 23:26:58 +02:00
|
|
|
const RPC_SYNTAX_IDENTIFIER *TransferId)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG header_size;
|
2004-04-27 01:33:39 +02:00
|
|
|
RpcAddressString *server_address;
|
|
|
|
RpcResults *results;
|
|
|
|
RPC_SYNTAX_IDENTIFIER *transfer_id;
|
|
|
|
|
2006-11-10 12:01:35 +01:00
|
|
|
header_size = sizeof(header->bind_ack) +
|
|
|
|
ROUND_UP(FIELD_OFFSET(RpcAddressString, string[strlen(ServerAddress) + 1]), 4) +
|
|
|
|
sizeof(RpcResults) +
|
|
|
|
sizeof(RPC_SYNTAX_IDENTIFIER);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, header_size);
|
|
|
|
if (header == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_BIND_ACK, DataRepresentation);
|
|
|
|
header->common.frag_len = header_size;
|
|
|
|
header->bind_ack.max_tsize = MaxTransmissionSize;
|
|
|
|
header->bind_ack.max_rsize = MaxReceiveSize;
|
2007-12-16 13:07:30 +01:00
|
|
|
header->bind_ack.assoc_gid = AssocGroupId;
|
2004-04-27 01:33:39 +02:00
|
|
|
server_address = (RpcAddressString*)(&header->bind_ack + 1);
|
|
|
|
server_address->length = strlen(ServerAddress) + 1;
|
|
|
|
strcpy(server_address->string, ServerAddress);
|
2006-11-10 12:01:35 +01:00
|
|
|
/* results is 4-byte aligned */
|
|
|
|
results = (RpcResults*)((ULONG_PTR)server_address + ROUND_UP(FIELD_OFFSET(RpcAddressString, string[server_address->length]), 4));
|
2004-04-27 01:33:39 +02:00
|
|
|
results->num_results = 1;
|
|
|
|
results->results[0].result = Result;
|
|
|
|
results->results[0].reason = Reason;
|
|
|
|
transfer_id = (RPC_SYNTAX_IDENTIFIER*)(results + 1);
|
2008-03-13 21:52:48 +01:00
|
|
|
*transfer_id = *TransferId;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2009-07-03 13:42:57 +02:00
|
|
|
RpcPktHdr *RPCRT4_BuildHttpHeader(ULONG DataRepresentation,
|
2009-03-18 12:13:19 +01:00
|
|
|
unsigned short flags,
|
|
|
|
unsigned short num_data_items,
|
|
|
|
unsigned int payload_size)
|
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
|
|
|
|
header = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(header->http) + payload_size);
|
|
|
|
if (header == NULL) {
|
|
|
|
ERR("failed to allocate memory\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPCRT4_BuildCommonHeader(header, PKT_HTTP, DataRepresentation);
|
|
|
|
/* since the packet isn't current sent using RPCRT4_Send, set the flags
|
|
|
|
* manually here */
|
|
|
|
header->common.flags = RPC_FLG_FIRST|RPC_FLG_LAST;
|
|
|
|
header->common.call_id = 0;
|
|
|
|
header->common.frag_len = sizeof(header->http) + payload_size;
|
|
|
|
header->http.flags = flags;
|
|
|
|
header->http.num_data_items = num_data_items;
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, type, value) \
|
|
|
|
do { \
|
|
|
|
*(unsigned int *)(payload) = (type); \
|
|
|
|
(payload) += 4; \
|
|
|
|
*(unsigned int *)(payload) = (value); \
|
|
|
|
(payload) += 4; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, type, uuid) \
|
|
|
|
do { \
|
|
|
|
*(unsigned int *)(payload) = (type); \
|
|
|
|
(payload) += 4; \
|
|
|
|
*(UUID *)(payload) = (uuid); \
|
|
|
|
(payload) += sizeof(UUID); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload, bytes_transmitted, flow_control_increment, uuid) \
|
|
|
|
do { \
|
|
|
|
*(unsigned int *)(payload) = 0x00000001; \
|
|
|
|
(payload) += 4; \
|
|
|
|
*(unsigned int *)(payload) = (bytes_transmitted); \
|
|
|
|
(payload) += 4; \
|
|
|
|
*(unsigned int *)(payload) = (flow_control_increment); \
|
|
|
|
(payload) += 4; \
|
|
|
|
*(UUID *)(payload) = (uuid); \
|
|
|
|
(payload) += sizeof(UUID); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
RpcPktHdr *RPCRT4_BuildHttpConnectHeader(unsigned short flags, int out_pipe,
|
|
|
|
const UUID *connection_uuid,
|
|
|
|
const UUID *pipe_uuid,
|
|
|
|
const UUID *association_uuid)
|
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
unsigned int size;
|
|
|
|
char *payload;
|
|
|
|
|
|
|
|
size = 8 + 4 + sizeof(UUID) + 4 + sizeof(UUID) + 8;
|
|
|
|
if (!out_pipe)
|
|
|
|
size += 8 + 4 + sizeof(UUID);
|
|
|
|
|
|
|
|
header = RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION, flags,
|
|
|
|
out_pipe ? 4 : 6, size);
|
|
|
|
if (!header) return NULL;
|
|
|
|
payload = (char *)(&header->http+1);
|
|
|
|
|
|
|
|
/* FIXME: what does this part of the payload do? */
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000006, 0x00000001);
|
|
|
|
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x00000003, *connection_uuid);
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x00000003, *pipe_uuid);
|
|
|
|
|
|
|
|
if (out_pipe)
|
|
|
|
/* FIXME: what does this part of the payload do? */
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000000, 0x00010000);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME: what does this part of the payload do? */
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000004, 0x40000000);
|
|
|
|
/* FIXME: what does this part of the payload do? */
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x00000005, 0x000493e0);
|
|
|
|
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UUID(payload, 0x0000000c, *association_uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
|
|
|
RpcPktHdr *RPCRT4_BuildHttpFlowControlHeader(BOOL server, ULONG bytes_transmitted,
|
|
|
|
ULONG flow_control_increment,
|
|
|
|
const UUID *pipe_uuid)
|
|
|
|
{
|
|
|
|
RpcPktHdr *header;
|
|
|
|
char *payload;
|
|
|
|
|
|
|
|
header = RPCRT4_BuildHttpHeader(NDR_LOCAL_DATA_REPRESENTATION, 0x2, 2,
|
|
|
|
5 * sizeof(ULONG) + sizeof(UUID));
|
|
|
|
if (!header) return NULL;
|
|
|
|
payload = (char *)(&header->http+1);
|
|
|
|
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_UINT32(payload, 0x0000000d, (server ? 0x0 : 0x3));
|
|
|
|
|
|
|
|
WRITE_HTTP_PAYLOAD_FIELD_FLOW_CONTROL(payload, bytes_transmitted,
|
|
|
|
flow_control_increment, *pipe_uuid);
|
|
|
|
return header;
|
|
|
|
}
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
VOID RPCRT4_FreeHeader(RpcPktHdr *Header)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, Header);
|
|
|
|
}
|
|
|
|
|
2007-07-05 13:46:59 +02:00
|
|
|
NCA_STATUS RPC2NCA_STATUS(RPC_STATUS status)
|
|
|
|
{
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case ERROR_INVALID_HANDLE: return NCA_S_FAULT_CONTEXT_MISMATCH;
|
|
|
|
case ERROR_OUTOFMEMORY: return NCA_S_FAULT_REMOTE_NO_MEMORY;
|
|
|
|
case RPC_S_NOT_LISTENING: return NCA_S_SERVER_TOO_BUSY;
|
|
|
|
case RPC_S_UNKNOWN_IF: return NCA_S_UNK_IF;
|
|
|
|
case RPC_S_SERVER_TOO_BUSY: return NCA_S_SERVER_TOO_BUSY;
|
|
|
|
case RPC_S_CALL_FAILED: return NCA_S_FAULT_UNSPEC;
|
|
|
|
case RPC_S_CALL_FAILED_DNE: return NCA_S_MANAGER_NOT_ENTERED;
|
|
|
|
case RPC_S_PROTOCOL_ERROR: return NCA_S_PROTO_ERROR;
|
|
|
|
case RPC_S_UNSUPPORTED_TYPE: return NCA_S_UNSUPPORTED_TYPE;
|
|
|
|
case RPC_S_INVALID_TAG: return NCA_S_FAULT_INVALID_TAG;
|
|
|
|
case RPC_S_INVALID_BOUND: return NCA_S_FAULT_INVALID_BOUND;
|
|
|
|
case RPC_S_PROCNUM_OUT_OF_RANGE: return NCA_S_OP_RNG_ERROR;
|
|
|
|
case RPC_X_SS_HANDLES_MISMATCH: return NCA_S_FAULT_CONTEXT_MISMATCH;
|
2007-07-17 15:05:01 +02:00
|
|
|
case RPC_S_CALL_CANCELLED: return NCA_S_FAULT_CANCEL;
|
|
|
|
case RPC_S_COMM_FAILURE: return NCA_S_COMM_FAILURE;
|
|
|
|
case RPC_X_WRONG_PIPE_ORDER: return NCA_S_FAULT_PIPE_ORDER;
|
|
|
|
case RPC_X_PIPE_CLOSED: return NCA_S_FAULT_PIPE_CLOSED;
|
|
|
|
case RPC_X_PIPE_DISCIPLINE_ERROR: return NCA_S_FAULT_PIPE_DISCIPLINE;
|
|
|
|
case RPC_X_PIPE_EMPTY: return NCA_S_FAULT_PIPE_EMPTY;
|
2007-07-05 13:46:59 +02:00
|
|
|
case STATUS_FLOAT_DIVIDE_BY_ZERO: return NCA_S_FAULT_FP_DIV_ZERO;
|
|
|
|
case STATUS_FLOAT_INVALID_OPERATION: return NCA_S_FAULT_FP_ERROR;
|
|
|
|
case STATUS_FLOAT_OVERFLOW: return NCA_S_FAULT_FP_OVERFLOW;
|
|
|
|
case STATUS_FLOAT_UNDERFLOW: return NCA_S_FAULT_FP_UNDERFLOW;
|
|
|
|
case STATUS_INTEGER_DIVIDE_BY_ZERO: return NCA_S_FAULT_INT_DIV_BY_ZERO;
|
|
|
|
case STATUS_INTEGER_OVERFLOW: return NCA_S_FAULT_INT_OVERFLOW;
|
|
|
|
default: return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 18:45:06 +01:00
|
|
|
static RPC_STATUS NCA2RPC_STATUS(NCA_STATUS status)
|
2007-07-05 13:46:59 +02:00
|
|
|
{
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case NCA_S_COMM_FAILURE: return RPC_S_COMM_FAILURE;
|
|
|
|
case NCA_S_OP_RNG_ERROR: return RPC_S_PROCNUM_OUT_OF_RANGE;
|
|
|
|
case NCA_S_UNK_IF: return RPC_S_UNKNOWN_IF;
|
|
|
|
case NCA_S_YOU_CRASHED: return RPC_S_CALL_FAILED;
|
|
|
|
case NCA_S_PROTO_ERROR: return RPC_S_PROTOCOL_ERROR;
|
|
|
|
case NCA_S_OUT_ARGS_TOO_BIG: return ERROR_NOT_ENOUGH_SERVER_MEMORY;
|
|
|
|
case NCA_S_SERVER_TOO_BUSY: return RPC_S_SERVER_TOO_BUSY;
|
|
|
|
case NCA_S_UNSUPPORTED_TYPE: return RPC_S_UNSUPPORTED_TYPE;
|
|
|
|
case NCA_S_FAULT_INT_DIV_BY_ZERO: return RPC_S_ZERO_DIVIDE;
|
|
|
|
case NCA_S_FAULT_ADDR_ERROR: return RPC_S_ADDRESS_ERROR;
|
|
|
|
case NCA_S_FAULT_FP_DIV_ZERO: return RPC_S_FP_DIV_ZERO;
|
|
|
|
case NCA_S_FAULT_FP_UNDERFLOW: return RPC_S_FP_UNDERFLOW;
|
|
|
|
case NCA_S_FAULT_FP_OVERFLOW: return RPC_S_FP_OVERFLOW;
|
|
|
|
case NCA_S_FAULT_INVALID_TAG: return RPC_S_INVALID_TAG;
|
|
|
|
case NCA_S_FAULT_INVALID_BOUND: return RPC_S_INVALID_BOUND;
|
|
|
|
case NCA_S_RPC_VERSION_MISMATCH: return RPC_S_PROTOCOL_ERROR;
|
|
|
|
case NCA_S_UNSPEC_REJECT: return RPC_S_CALL_FAILED_DNE;
|
|
|
|
case NCA_S_BAD_ACTID: return RPC_S_CALL_FAILED_DNE;
|
|
|
|
case NCA_S_WHO_ARE_YOU_FAILED: return RPC_S_CALL_FAILED;
|
|
|
|
case NCA_S_MANAGER_NOT_ENTERED: return RPC_S_CALL_FAILED_DNE;
|
|
|
|
case NCA_S_FAULT_CANCEL: return RPC_S_CALL_CANCELLED;
|
|
|
|
case NCA_S_FAULT_ILL_INST: return RPC_S_ADDRESS_ERROR;
|
|
|
|
case NCA_S_FAULT_FP_ERROR: return RPC_S_FP_OVERFLOW;
|
|
|
|
case NCA_S_FAULT_INT_OVERFLOW: return RPC_S_ADDRESS_ERROR;
|
|
|
|
case NCA_S_FAULT_UNSPEC: return RPC_S_CALL_FAILED;
|
|
|
|
case NCA_S_FAULT_PIPE_EMPTY: return RPC_X_PIPE_EMPTY;
|
|
|
|
case NCA_S_FAULT_PIPE_CLOSED: return RPC_X_PIPE_CLOSED;
|
|
|
|
case NCA_S_FAULT_PIPE_ORDER: return RPC_X_WRONG_PIPE_ORDER;
|
|
|
|
case NCA_S_FAULT_PIPE_DISCIPLINE: return RPC_X_PIPE_DISCIPLINE_ERROR;
|
|
|
|
case NCA_S_FAULT_PIPE_COMM_ERROR: return RPC_S_COMM_FAILURE;
|
|
|
|
case NCA_S_FAULT_PIPE_MEMORY: return ERROR_OUTOFMEMORY;
|
|
|
|
case NCA_S_FAULT_CONTEXT_MISMATCH: return ERROR_INVALID_HANDLE;
|
|
|
|
case NCA_S_FAULT_REMOTE_NO_MEMORY: return ERROR_NOT_ENOUGH_SERVER_MEMORY;
|
|
|
|
default: return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-18 12:13:19 +01:00
|
|
|
/* assumes the common header fields have already been validated */
|
|
|
|
BOOL RPCRT4_IsValidHttpPacket(RpcPktHdr *hdr, unsigned char *data,
|
|
|
|
unsigned short data_len)
|
|
|
|
{
|
|
|
|
unsigned short i;
|
|
|
|
BYTE *p = data;
|
|
|
|
|
|
|
|
for (i = 0; i < hdr->http.num_data_items; i++)
|
|
|
|
{
|
|
|
|
ULONG type;
|
|
|
|
|
|
|
|
if (data_len < sizeof(ULONG))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
type = *(ULONG *)p;
|
|
|
|
p += sizeof(ULONG);
|
|
|
|
data_len -= sizeof(ULONG);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 0x3:
|
|
|
|
case 0xc:
|
|
|
|
if (data_len < sizeof(GUID))
|
|
|
|
return FALSE;
|
|
|
|
p += sizeof(GUID);
|
|
|
|
data_len -= sizeof(GUID);
|
|
|
|
break;
|
|
|
|
case 0x0:
|
|
|
|
case 0x2:
|
|
|
|
case 0x4:
|
|
|
|
case 0x5:
|
|
|
|
case 0x6:
|
|
|
|
case 0xd:
|
|
|
|
if (data_len < sizeof(ULONG))
|
|
|
|
return FALSE;
|
|
|
|
p += sizeof(ULONG);
|
|
|
|
data_len -= sizeof(ULONG);
|
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
if (data_len < 24)
|
|
|
|
return FALSE;
|
|
|
|
p += 24;
|
|
|
|
data_len -= 24;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented type 0x%x\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes the HTTP packet has been validated */
|
2009-05-13 10:39:33 +02:00
|
|
|
static unsigned char *RPCRT4_NextHttpHeaderField(unsigned char *data)
|
2009-03-18 12:13:19 +01:00
|
|
|
{
|
|
|
|
ULONG type;
|
|
|
|
|
|
|
|
type = *(ULONG *)data;
|
|
|
|
data += sizeof(ULONG);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case 0x3:
|
|
|
|
case 0xc:
|
|
|
|
return data + sizeof(GUID);
|
|
|
|
case 0x0:
|
|
|
|
case 0x2:
|
|
|
|
case 0x4:
|
|
|
|
case 0x5:
|
|
|
|
case 0x6:
|
|
|
|
case 0xd:
|
|
|
|
return data + sizeof(ULONG);
|
|
|
|
case 0x1:
|
|
|
|
return data + 24;
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented type 0x%x\n", type);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define READ_HTTP_PAYLOAD_FIELD_TYPE(data) *(ULONG *)(data)
|
|
|
|
#define GET_HTTP_PAYLOAD_FIELD_DATA(data) ((data) + sizeof(ULONG))
|
|
|
|
|
|
|
|
/* assumes the HTTP packet has been validated */
|
|
|
|
RPC_STATUS RPCRT4_ParseHttpPrepareHeader1(RpcPktHdr *header,
|
|
|
|
unsigned char *data, ULONG *field1)
|
|
|
|
{
|
|
|
|
ULONG type;
|
|
|
|
if (header->http.flags != 0x0)
|
|
|
|
{
|
|
|
|
ERR("invalid flags 0x%x\n", header->http.flags);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
if (header->http.num_data_items != 1)
|
|
|
|
{
|
|
|
|
ERR("invalid number of data items %d\n", header->http.num_data_items);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x00000002)
|
|
|
|
{
|
|
|
|
ERR("invalid type 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
*field1 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assumes the HTTP packet has been validated */
|
|
|
|
RPC_STATUS RPCRT4_ParseHttpPrepareHeader2(RpcPktHdr *header,
|
|
|
|
unsigned char *data, ULONG *field1,
|
|
|
|
ULONG *bytes_until_next_packet,
|
|
|
|
ULONG *field3)
|
|
|
|
{
|
|
|
|
ULONG type;
|
|
|
|
if (header->http.flags != 0x0)
|
|
|
|
{
|
|
|
|
ERR("invalid flags 0x%x\n", header->http.flags);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
if (header->http.num_data_items != 3)
|
|
|
|
{
|
|
|
|
ERR("invalid number of data items %d\n", header->http.num_data_items);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x00000006)
|
|
|
|
{
|
|
|
|
ERR("invalid type for field 1: 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
*field1 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
|
|
|
|
data = RPCRT4_NextHttpHeaderField(data);
|
|
|
|
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x00000000)
|
|
|
|
{
|
|
|
|
ERR("invalid type for field 2: 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
*bytes_until_next_packet = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
|
|
|
|
data = RPCRT4_NextHttpHeaderField(data);
|
|
|
|
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x00000002)
|
|
|
|
{
|
|
|
|
ERR("invalid type for field 3: 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
*field3 = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
RPC_STATUS RPCRT4_ParseHttpFlowControlHeader(RpcPktHdr *header,
|
|
|
|
unsigned char *data, BOOL server,
|
|
|
|
ULONG *bytes_transmitted,
|
|
|
|
ULONG *flow_control_increment,
|
|
|
|
UUID *pipe_uuid)
|
|
|
|
{
|
|
|
|
ULONG type;
|
|
|
|
if (header->http.flags != 0x2)
|
|
|
|
{
|
|
|
|
ERR("invalid flags 0x%x\n", header->http.flags);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
if (header->http.num_data_items != 2)
|
|
|
|
{
|
|
|
|
ERR("invalid number of data items %d\n", header->http.num_data_items);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x0000000d)
|
|
|
|
{
|
|
|
|
ERR("invalid type for field 1: 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
if (*(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data) != (server ? 0x3 : 0x0))
|
|
|
|
{
|
|
|
|
ERR("invalid type for 0xd field data: 0x%08x\n", *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data));
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
data = RPCRT4_NextHttpHeaderField(data);
|
|
|
|
|
|
|
|
type = READ_HTTP_PAYLOAD_FIELD_TYPE(data);
|
|
|
|
if (type != 0x00000001)
|
|
|
|
{
|
|
|
|
ERR("invalid type for field 2: 0x%08x\n", type);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
*bytes_transmitted = *(ULONG *)GET_HTTP_PAYLOAD_FIELD_DATA(data);
|
|
|
|
*flow_control_increment = *(ULONG *)(GET_HTTP_PAYLOAD_FIELD_DATA(data) + 4);
|
|
|
|
*pipe_uuid = *(UUID *)(GET_HTTP_PAYLOAD_FIELD_DATA(data) + 8);
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-15 02:00:36 +01:00
|
|
|
static RPC_STATUS RPCRT4_SecurePacket(RpcConnection *Connection,
|
|
|
|
enum secure_packet_direction dir,
|
|
|
|
RpcPktHdr *hdr, unsigned int hdr_size,
|
|
|
|
unsigned char *stub_data, unsigned int stub_data_size,
|
|
|
|
RpcAuthVerifier *auth_hdr,
|
|
|
|
unsigned char *auth_value, unsigned int auth_value_size)
|
|
|
|
{
|
|
|
|
SecBufferDesc message;
|
|
|
|
SecBuffer buffers[4];
|
|
|
|
SECURITY_STATUS sec_status;
|
|
|
|
|
|
|
|
message.ulVersion = SECBUFFER_VERSION;
|
|
|
|
message.cBuffers = sizeof(buffers)/sizeof(buffers[0]);
|
|
|
|
message.pBuffers = buffers;
|
|
|
|
|
|
|
|
buffers[0].cbBuffer = hdr_size;
|
|
|
|
buffers[0].BufferType = SECBUFFER_DATA|SECBUFFER_READONLY_WITH_CHECKSUM;
|
|
|
|
buffers[0].pvBuffer = hdr;
|
|
|
|
buffers[1].cbBuffer = stub_data_size;
|
|
|
|
buffers[1].BufferType = SECBUFFER_DATA;
|
|
|
|
buffers[1].pvBuffer = stub_data;
|
|
|
|
buffers[2].cbBuffer = sizeof(*auth_hdr);
|
|
|
|
buffers[2].BufferType = SECBUFFER_DATA|SECBUFFER_READONLY_WITH_CHECKSUM;
|
|
|
|
buffers[2].pvBuffer = auth_hdr;
|
|
|
|
buffers[3].cbBuffer = auth_value_size;
|
|
|
|
buffers[3].BufferType = SECBUFFER_TOKEN;
|
|
|
|
buffers[3].pvBuffer = auth_value;
|
|
|
|
|
|
|
|
if (dir == SECURE_PACKET_SEND)
|
|
|
|
{
|
|
|
|
if ((auth_hdr->auth_level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY) && packet_has_body(hdr))
|
|
|
|
{
|
|
|
|
sec_status = EncryptMessage(&Connection->ctx, 0, &message, 0 /* FIXME */);
|
|
|
|
if (sec_status != SEC_E_OK)
|
|
|
|
{
|
|
|
|
ERR("EncryptMessage failed with 0x%08x\n", sec_status);
|
|
|
|
return RPC_S_SEC_PKG_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auth_hdr->auth_level != RPC_C_AUTHN_LEVEL_NONE)
|
|
|
|
{
|
|
|
|
sec_status = MakeSignature(&Connection->ctx, 0, &message, 0 /* FIXME */);
|
|
|
|
if (sec_status != SEC_E_OK)
|
|
|
|
{
|
|
|
|
ERR("MakeSignature failed with 0x%08x\n", sec_status);
|
|
|
|
return RPC_S_SEC_PKG_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dir == SECURE_PACKET_RECEIVE)
|
|
|
|
{
|
|
|
|
if ((auth_hdr->auth_level == RPC_C_AUTHN_LEVEL_PKT_PRIVACY) && packet_has_body(hdr))
|
|
|
|
{
|
|
|
|
sec_status = DecryptMessage(&Connection->ctx, &message, 0 /* FIXME */, 0);
|
|
|
|
if (sec_status != SEC_E_OK)
|
|
|
|
{
|
2007-09-11 18:46:34 +02:00
|
|
|
ERR("DecryptMessage failed with 0x%08x\n", sec_status);
|
2006-11-15 02:00:36 +01:00
|
|
|
return RPC_S_SEC_PKG_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (auth_hdr->auth_level != RPC_C_AUTHN_LEVEL_NONE)
|
|
|
|
{
|
|
|
|
sec_status = VerifySignature(&Connection->ctx, &message, 0 /* FIXME */, NULL);
|
|
|
|
if (sec_status != SEC_E_OK)
|
|
|
|
{
|
|
|
|
ERR("VerifySignature failed with 0x%08x\n", sec_status);
|
|
|
|
return RPC_S_SEC_PKG_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
/***********************************************************************
|
2008-06-18 18:32:05 +02:00
|
|
|
* RPCRT4_SendWithAuth (internal)
|
2004-04-27 01:33:39 +02:00
|
|
|
*
|
2006-05-12 12:20:26 +02:00
|
|
|
* Transmit a packet with authorization data over connection in acceptable fragments.
|
2004-04-27 01:33:39 +02:00
|
|
|
*/
|
2008-06-18 18:32:05 +02:00
|
|
|
static RPC_STATUS RPCRT4_SendWithAuth(RpcConnection *Connection, RpcPktHdr *Header,
|
|
|
|
void *Buffer, unsigned int BufferLength,
|
|
|
|
const void *Auth, unsigned int AuthLength)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
PUCHAR buffer_pos;
|
2006-04-19 17:25:37 +02:00
|
|
|
DWORD hdr_size;
|
|
|
|
LONG count;
|
2006-05-19 17:02:23 +02:00
|
|
|
unsigned char *pkt;
|
2006-11-15 02:00:36 +01:00
|
|
|
LONG alen;
|
|
|
|
RPC_STATUS status;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
2007-11-12 21:10:19 +01:00
|
|
|
RPCRT4_SetThreadCurrentConnection(Connection);
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
buffer_pos = Buffer;
|
|
|
|
/* The packet building functions save the packet header size, so we can use it. */
|
|
|
|
hdr_size = Header->common.frag_len;
|
2006-11-15 02:00:36 +01:00
|
|
|
if (AuthLength)
|
|
|
|
Header->common.auth_len = AuthLength;
|
|
|
|
else if (Connection->AuthInfo && packet_has_auth_verifier(Header))
|
2007-03-26 19:19:33 +02:00
|
|
|
{
|
|
|
|
if ((Connection->AuthInfo->AuthnLevel == RPC_C_AUTHN_LEVEL_PKT_PRIVACY) && packet_has_body(Header))
|
|
|
|
Header->common.auth_len = Connection->encryption_auth_len;
|
2007-03-28 09:57:49 +02:00
|
|
|
else
|
|
|
|
Header->common.auth_len = Connection->signature_auth_len;
|
2007-03-26 19:19:33 +02:00
|
|
|
}
|
2006-11-15 02:00:36 +01:00
|
|
|
else
|
|
|
|
Header->common.auth_len = 0;
|
2004-04-27 01:33:39 +02:00
|
|
|
Header->common.flags |= RPC_FLG_FIRST;
|
|
|
|
Header->common.flags &= ~RPC_FLG_LAST;
|
2006-11-15 02:00:36 +01:00
|
|
|
|
|
|
|
alen = RPC_AUTH_VERIFIER_LEN(&Header->common);
|
|
|
|
|
2006-01-18 11:29:38 +01:00
|
|
|
while (!(Header->common.flags & RPC_FLG_LAST)) {
|
2006-11-15 02:00:36 +01:00
|
|
|
unsigned char auth_pad_len = Header->common.auth_len ? ROUND_UP_AMOUNT(BufferLength, AUTH_ALIGNMENT) : 0;
|
2006-06-20 15:27:00 +02:00
|
|
|
unsigned int pkt_size = BufferLength + hdr_size + alen + auth_pad_len;
|
2006-05-19 12:03:39 +02:00
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
/* decide if we need to split the packet into fragments */
|
2006-05-19 12:03:39 +02:00
|
|
|
if (pkt_size <= Connection->MaxTransmissionSize) {
|
|
|
|
Header->common.flags |= RPC_FLG_LAST;
|
|
|
|
Header->common.frag_len = pkt_size;
|
2004-04-27 01:33:39 +02:00
|
|
|
} else {
|
2006-05-19 12:03:39 +02:00
|
|
|
auth_pad_len = 0;
|
|
|
|
/* make sure packet payload will be a multiple of 16 */
|
|
|
|
Header->common.frag_len =
|
|
|
|
((Connection->MaxTransmissionSize - hdr_size - alen) & ~(AUTH_ALIGNMENT-1)) +
|
|
|
|
hdr_size + alen;
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2006-05-12 12:20:26 +02:00
|
|
|
pkt = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, Header->common.frag_len);
|
|
|
|
|
|
|
|
memcpy(pkt, Header, hdr_size);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
/* fragment consisted of header only and is the last one */
|
2006-05-12 12:20:26 +02:00
|
|
|
if (hdr_size == Header->common.frag_len)
|
|
|
|
goto write;
|
|
|
|
|
2006-05-22 13:02:04 +02:00
|
|
|
memcpy(pkt + hdr_size, buffer_pos, Header->common.frag_len - hdr_size - auth_pad_len - alen);
|
2006-05-12 12:20:26 +02:00
|
|
|
|
|
|
|
/* add the authorization info */
|
2006-11-15 02:00:36 +01:00
|
|
|
if (Connection->AuthInfo && packet_has_auth_verifier(Header))
|
2006-05-12 12:20:26 +02:00
|
|
|
{
|
2006-05-19 17:02:23 +02:00
|
|
|
RpcAuthVerifier *auth_hdr = (RpcAuthVerifier *)&pkt[Header->common.frag_len - alen];
|
2006-05-12 12:20:26 +02:00
|
|
|
|
2006-05-19 17:02:23 +02:00
|
|
|
auth_hdr->auth_type = Connection->AuthInfo->AuthnSvc;
|
|
|
|
auth_hdr->auth_level = Connection->AuthInfo->AuthnLevel;
|
|
|
|
auth_hdr->auth_pad_length = auth_pad_len;
|
|
|
|
auth_hdr->auth_reserved = 0;
|
2006-05-12 12:20:26 +02:00
|
|
|
/* a unique number... */
|
2009-08-18 20:15:01 +02:00
|
|
|
auth_hdr->auth_context_id = Connection->auth_context_id;
|
2006-05-19 17:02:23 +02:00
|
|
|
|
2006-11-15 02:00:36 +01:00
|
|
|
if (AuthLength)
|
|
|
|
memcpy(auth_hdr + 1, Auth, AuthLength);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = RPCRT4_SecurePacket(Connection, SECURE_PACKET_SEND,
|
|
|
|
(RpcPktHdr *)pkt, hdr_size,
|
|
|
|
pkt + hdr_size, Header->common.frag_len - hdr_size - alen,
|
|
|
|
auth_hdr,
|
|
|
|
(unsigned char *)(auth_hdr + 1), Header->common.auth_len);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, pkt);
|
2007-11-12 21:10:19 +01:00
|
|
|
RPCRT4_SetThreadCurrentConnection(NULL);
|
2006-11-15 02:00:36 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2006-05-12 12:20:26 +02:00
|
|
|
write:
|
|
|
|
count = rpcrt4_conn_write(Connection, pkt, Header->common.frag_len);
|
|
|
|
HeapFree(GetProcessHeap(), 0, pkt);
|
2006-04-19 17:25:37 +02:00
|
|
|
if (count<0) {
|
2006-05-12 12:20:26 +02:00
|
|
|
WARN("rpcrt4_conn_write failed (auth)\n");
|
2007-11-12 21:10:19 +01:00
|
|
|
RPCRT4_SetThreadCurrentConnection(NULL);
|
2007-11-29 16:42:20 +01:00
|
|
|
return RPC_S_CALL_FAILED;
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
|
|
|
|
2006-05-19 12:03:39 +02:00
|
|
|
buffer_pos += Header->common.frag_len - hdr_size - alen - auth_pad_len;
|
|
|
|
BufferLength -= Header->common.frag_len - hdr_size - alen - auth_pad_len;
|
2004-04-27 01:33:39 +02:00
|
|
|
Header->common.flags &= ~RPC_FLG_FIRST;
|
|
|
|
}
|
|
|
|
|
2007-11-12 21:10:19 +01:00
|
|
|
RPCRT4_SetThreadCurrentConnection(NULL);
|
2004-04-27 01:33:39 +02:00
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-15 16:04:25 +02:00
|
|
|
/***********************************************************************
|
2007-03-26 19:17:15 +02:00
|
|
|
* RPCRT4_ClientAuthorize (internal)
|
|
|
|
*
|
|
|
|
* Authorize a client connection. A NULL in param signifies a new connection.
|
2006-05-15 16:04:25 +02:00
|
|
|
*/
|
2007-03-26 19:17:15 +02:00
|
|
|
static RPC_STATUS RPCRT4_ClientAuthorize(RpcConnection *conn, SecBuffer *in,
|
|
|
|
SecBuffer *out)
|
2006-05-15 16:04:25 +02:00
|
|
|
{
|
|
|
|
SECURITY_STATUS r;
|
|
|
|
SecBufferDesc out_desc;
|
2007-03-26 19:17:15 +02:00
|
|
|
SecBufferDesc inp_desc;
|
2007-03-26 19:19:33 +02:00
|
|
|
SecPkgContext_Sizes secctx_sizes;
|
|
|
|
BOOL continue_needed;
|
2006-11-15 02:00:36 +01:00
|
|
|
ULONG context_req = ISC_REQ_CONNECTION | ISC_REQ_USE_DCE_STYLE |
|
|
|
|
ISC_REQ_MUTUAL_AUTH | ISC_REQ_DELEGATE;
|
|
|
|
|
|
|
|
if (conn->AuthInfo->AuthnLevel == RPC_C_AUTHN_LEVEL_PKT_INTEGRITY)
|
|
|
|
context_req |= ISC_REQ_INTEGRITY;
|
|
|
|
else if (conn->AuthInfo->AuthnLevel == RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
|
|
|
|
context_req |= ISC_REQ_CONFIDENTIALITY | ISC_REQ_INTEGRITY;
|
2006-05-15 16:04:25 +02:00
|
|
|
|
|
|
|
out->BufferType = SECBUFFER_TOKEN;
|
2007-03-26 19:16:34 +02:00
|
|
|
out->cbBuffer = conn->AuthInfo->cbMaxToken;
|
2007-03-26 19:17:15 +02:00
|
|
|
out->pvBuffer = HeapAlloc(GetProcessHeap(), 0, out->cbBuffer);
|
2007-03-26 19:19:33 +02:00
|
|
|
if (!out->pvBuffer) return ERROR_OUTOFMEMORY;
|
2006-05-15 16:04:25 +02:00
|
|
|
|
|
|
|
out_desc.ulVersion = 0;
|
|
|
|
out_desc.cBuffers = 1;
|
|
|
|
out_desc.pBuffers = out;
|
|
|
|
|
2007-03-26 19:17:15 +02:00
|
|
|
inp_desc.cBuffers = 1;
|
|
|
|
inp_desc.pBuffers = in;
|
|
|
|
inp_desc.ulVersion = 0;
|
|
|
|
|
2008-01-23 17:32:54 +01:00
|
|
|
r = InitializeSecurityContextW(&conn->AuthInfo->cred, in ? &conn->ctx : NULL,
|
|
|
|
in ? NULL : conn->AuthInfo->server_principal_name, context_req, 0,
|
|
|
|
SECURITY_NETWORK_DREP, in ? &inp_desc : NULL, 0, &conn->ctx,
|
|
|
|
&out_desc, &conn->attr, &conn->exp);
|
2007-03-26 19:17:15 +02:00
|
|
|
if (FAILED(r))
|
|
|
|
{
|
|
|
|
WARN("InitializeSecurityContext failed with error 0x%08x\n", r);
|
2007-03-26 19:19:33 +02:00
|
|
|
goto failed;
|
2007-03-26 19:17:15 +02:00
|
|
|
}
|
2006-05-15 16:04:25 +02:00
|
|
|
|
2007-03-26 19:18:01 +02:00
|
|
|
TRACE("r = 0x%08x, attr = 0x%08x\n", r, conn->attr);
|
2007-03-26 19:19:33 +02:00
|
|
|
continue_needed = ((r == SEC_I_CONTINUE_NEEDED) ||
|
|
|
|
(r == SEC_I_COMPLETE_AND_CONTINUE));
|
2007-03-26 19:18:01 +02:00
|
|
|
|
|
|
|
if ((r == SEC_I_COMPLETE_NEEDED) || (r == SEC_I_COMPLETE_AND_CONTINUE))
|
|
|
|
{
|
|
|
|
TRACE("complete needed\n");
|
|
|
|
r = CompleteAuthToken(&conn->ctx, &out_desc);
|
|
|
|
if (FAILED(r))
|
|
|
|
{
|
|
|
|
WARN("CompleteAuthToken failed with error 0x%08x\n", r);
|
2007-03-26 19:19:33 +02:00
|
|
|
goto failed;
|
2007-03-26 19:18:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-06 00:06:04 +01:00
|
|
|
TRACE("cbBuffer = %d\n", out->cbBuffer);
|
2006-05-15 16:04:25 +02:00
|
|
|
|
2007-03-26 19:19:33 +02:00
|
|
|
if (!continue_needed)
|
|
|
|
{
|
|
|
|
r = QueryContextAttributesA(&conn->ctx, SECPKG_ATTR_SIZES, &secctx_sizes);
|
|
|
|
if (FAILED(r))
|
|
|
|
{
|
|
|
|
WARN("QueryContextAttributes failed with error 0x%08x\n", r);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
conn->signature_auth_len = secctx_sizes.cbMaxSignature;
|
|
|
|
conn->encryption_auth_len = secctx_sizes.cbSecurityTrailer;
|
|
|
|
}
|
|
|
|
|
2007-03-26 19:17:15 +02:00
|
|
|
return RPC_S_OK;
|
2007-03-26 19:19:33 +02:00
|
|
|
|
|
|
|
failed:
|
|
|
|
HeapFree(GetProcessHeap(), 0, out->pvBuffer);
|
|
|
|
out->pvBuffer = NULL;
|
|
|
|
return ERROR_ACCESS_DENIED; /* FIXME: is this correct? */
|
2006-05-15 16:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* RPCRT4_AuthorizeBinding (internal)
|
|
|
|
*/
|
2008-06-18 18:32:22 +02:00
|
|
|
RPC_STATUS RPCRT4_AuthorizeConnection(RpcConnection* conn, BYTE *challenge,
|
|
|
|
ULONG count)
|
2006-05-15 16:04:25 +02:00
|
|
|
{
|
|
|
|
SecBuffer inp, out;
|
|
|
|
RpcPktHdr *resp_hdr;
|
|
|
|
RPC_STATUS status;
|
|
|
|
|
2006-11-09 23:04:48 +01:00
|
|
|
TRACE("challenge %s, %d bytes\n", challenge, count);
|
2006-05-15 16:04:25 +02:00
|
|
|
|
|
|
|
inp.BufferType = SECBUFFER_TOKEN;
|
|
|
|
inp.pvBuffer = challenge;
|
|
|
|
inp.cbBuffer = count;
|
|
|
|
|
2007-03-26 19:17:15 +02:00
|
|
|
status = RPCRT4_ClientAuthorize(conn, &inp, &out);
|
|
|
|
if (status) return status;
|
2006-05-15 16:04:25 +02:00
|
|
|
|
|
|
|
resp_hdr = RPCRT4_BuildAuthHeader(NDR_LOCAL_DATA_REPRESENTATION);
|
|
|
|
if (!resp_hdr)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2008-06-18 18:32:05 +02:00
|
|
|
status = RPCRT4_SendWithAuth(conn, resp_hdr, NULL, 0, out.pvBuffer, out.cbBuffer);
|
2006-05-15 16:04:25 +02:00
|
|
|
|
2007-03-26 19:16:34 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, out.pvBuffer);
|
2006-05-15 16:04:25 +02:00
|
|
|
RPCRT4_FreeHeader(resp_hdr);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-05-12 12:20:26 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RPCRT4_Send (internal)
|
|
|
|
*
|
|
|
|
* Transmit a packet over connection in acceptable fragments.
|
|
|
|
*/
|
|
|
|
RPC_STATUS RPCRT4_Send(RpcConnection *Connection, RpcPktHdr *Header,
|
|
|
|
void *Buffer, unsigned int BufferLength)
|
|
|
|
{
|
2006-05-15 16:04:25 +02:00
|
|
|
RPC_STATUS r;
|
|
|
|
SecBuffer out;
|
|
|
|
|
2006-11-21 14:09:53 +01:00
|
|
|
if (!Connection->AuthInfo || SecIsValidHandle(&Connection->ctx))
|
2006-05-15 16:04:25 +02:00
|
|
|
{
|
2008-06-18 18:32:05 +02:00
|
|
|
return RPCRT4_SendWithAuth(Connection, Header, Buffer, BufferLength, NULL, 0);
|
2006-05-15 16:04:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* tack on a negotiate packet */
|
2008-01-23 17:33:03 +01:00
|
|
|
r = RPCRT4_ClientAuthorize(Connection, NULL, &out);
|
|
|
|
if (r == RPC_S_OK)
|
|
|
|
{
|
2008-06-18 18:32:05 +02:00
|
|
|
r = RPCRT4_SendWithAuth(Connection, Header, Buffer, BufferLength, out.pvBuffer, out.cbBuffer);
|
2008-01-23 17:33:03 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, out.pvBuffer);
|
|
|
|
}
|
2006-05-15 16:04:25 +02:00
|
|
|
|
|
|
|
return r;
|
2006-05-12 12:20:26 +02:00
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
/* validates version and frag_len fields */
|
2009-03-18 12:13:19 +01:00
|
|
|
RPC_STATUS RPCRT4_ValidateCommonHeader(const RpcPktCommonHdr *hdr)
|
2008-01-21 11:31:55 +01:00
|
|
|
{
|
|
|
|
DWORD hdr_length;
|
|
|
|
|
|
|
|
/* verify if the header really makes sense */
|
|
|
|
if (hdr->rpc_ver != RPC_VER_MAJOR ||
|
|
|
|
hdr->rpc_ver_minor != RPC_VER_MINOR)
|
|
|
|
{
|
|
|
|
WARN("unhandled packet version\n");
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
hdr_length = RPCRT4_GetHeaderSize((const RpcPktHdr*)hdr);
|
|
|
|
if (hdr_length == 0)
|
|
|
|
{
|
|
|
|
WARN("header length == 0\n");
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hdr->frag_len < hdr_length)
|
|
|
|
{
|
|
|
|
WARN("bad frag length %d\n", hdr->frag_len);
|
|
|
|
return RPC_S_PROTOCOL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
}
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
/***********************************************************************
|
2009-03-18 12:13:19 +01:00
|
|
|
* RPCRT4_default_receive_fragment (internal)
|
2004-04-27 01:33:39 +02:00
|
|
|
*
|
2008-01-21 11:31:55 +01:00
|
|
|
* Receive a fragment from a connection.
|
2004-04-27 01:33:39 +02:00
|
|
|
*/
|
2009-05-13 10:39:33 +02:00
|
|
|
static RPC_STATUS RPCRT4_default_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
|
|
|
RPC_STATUS status;
|
2006-04-19 13:57:00 +02:00
|
|
|
DWORD hdr_length;
|
|
|
|
LONG dwRead;
|
2004-04-27 01:33:39 +02:00
|
|
|
RpcPktCommonHdr common_hdr;
|
|
|
|
|
|
|
|
*Header = NULL;
|
2008-01-21 11:31:55 +01:00
|
|
|
*Payload = NULL;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
TRACE("(%p, %p, %p)\n", Connection, Header, Payload);
|
2007-11-12 21:10:19 +01:00
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
/* read packet common header */
|
2006-04-19 13:57:00 +02:00
|
|
|
dwRead = rpcrt4_conn_read(Connection, &common_hdr, sizeof(common_hdr));
|
2004-04-27 01:33:39 +02:00
|
|
|
if (dwRead != sizeof(common_hdr)) {
|
2006-11-09 23:04:48 +01:00
|
|
|
WARN("Short read of header, %d bytes\n", dwRead);
|
2007-11-29 16:42:20 +01:00
|
|
|
status = RPC_S_CALL_FAILED;
|
2004-04-27 01:33:39 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
status = RPCRT4_ValidateCommonHeader(&common_hdr);
|
|
|
|
if (status != RPC_S_OK) goto fail;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
hdr_length = RPCRT4_GetHeaderSize((RpcPktHdr*)&common_hdr);
|
|
|
|
if (hdr_length == 0) {
|
2005-02-15 21:45:37 +01:00
|
|
|
WARN("header length == 0\n");
|
2004-04-27 01:33:39 +02:00
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*Header = HeapAlloc(GetProcessHeap(), 0, hdr_length);
|
|
|
|
memcpy(*Header, &common_hdr, sizeof(common_hdr));
|
|
|
|
|
|
|
|
/* read the rest of packet header */
|
2006-04-19 13:57:00 +02:00
|
|
|
dwRead = rpcrt4_conn_read(Connection, &(*Header)->common + 1, hdr_length - sizeof(common_hdr));
|
2004-04-27 01:33:39 +02:00
|
|
|
if (dwRead != hdr_length - sizeof(common_hdr)) {
|
2006-11-10 14:29:55 +01:00
|
|
|
WARN("bad header length, %d bytes, hdr_length %d\n", dwRead, hdr_length);
|
2007-11-29 16:42:20 +01:00
|
|
|
status = RPC_S_CALL_FAILED;
|
2004-04-27 01:33:39 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
if (common_hdr.frag_len - hdr_length)
|
|
|
|
{
|
|
|
|
*Payload = HeapAlloc(GetProcessHeap(), 0, common_hdr.frag_len - hdr_length);
|
|
|
|
if (!*Payload)
|
|
|
|
{
|
|
|
|
status = RPC_S_OUT_OF_RESOURCES;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwRead = rpcrt4_conn_read(Connection, *Payload, common_hdr.frag_len - hdr_length);
|
|
|
|
if (dwRead != common_hdr.frag_len - hdr_length)
|
|
|
|
{
|
|
|
|
WARN("bad data length, %d/%d\n", dwRead, common_hdr.frag_len - hdr_length);
|
|
|
|
status = RPC_S_CALL_FAILED;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*Payload = NULL;
|
|
|
|
|
|
|
|
/* success */
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
if (status != RPC_S_OK) {
|
|
|
|
RPCRT4_FreeHeader(*Header);
|
|
|
|
*Header = NULL;
|
|
|
|
HeapFree(GetProcessHeap(), 0, *Payload);
|
|
|
|
*Payload = NULL;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2009-03-18 12:13:19 +01:00
|
|
|
static RPC_STATUS RPCRT4_receive_fragment(RpcConnection *Connection, RpcPktHdr **Header, void **Payload)
|
|
|
|
{
|
|
|
|
if (Connection->ops->receive_fragment)
|
|
|
|
return Connection->ops->receive_fragment(Connection, Header, Payload);
|
|
|
|
else
|
|
|
|
return RPCRT4_default_receive_fragment(Connection, Header, Payload);
|
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
/***********************************************************************
|
2008-06-18 18:32:12 +02:00
|
|
|
* RPCRT4_ReceiveWithAuth (internal)
|
2008-01-21 11:31:55 +01:00
|
|
|
*
|
2008-06-18 18:32:12 +02:00
|
|
|
* Receive a packet from connection, merge the fragments and return the auth
|
|
|
|
* data.
|
2008-01-21 11:31:55 +01:00
|
|
|
*/
|
2008-06-18 18:32:12 +02:00
|
|
|
RPC_STATUS RPCRT4_ReceiveWithAuth(RpcConnection *Connection, RpcPktHdr **Header,
|
|
|
|
PRPC_MESSAGE pMsg,
|
|
|
|
unsigned char **auth_data_out,
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG *auth_length_out)
|
2008-01-21 11:31:55 +01:00
|
|
|
{
|
|
|
|
RPC_STATUS status;
|
|
|
|
DWORD hdr_length;
|
|
|
|
unsigned short first_flag;
|
2009-07-03 13:42:57 +02:00
|
|
|
ULONG data_length;
|
|
|
|
ULONG buffer_length;
|
|
|
|
ULONG auth_length = 0;
|
2008-01-21 11:31:55 +01:00
|
|
|
unsigned char *auth_data = NULL;
|
2008-01-23 07:58:30 +01:00
|
|
|
RpcPktHdr *CurrentHeader = NULL;
|
2008-01-21 11:31:55 +01:00
|
|
|
void *payload = NULL;
|
|
|
|
|
|
|
|
*Header = NULL;
|
2008-02-04 23:22:47 +01:00
|
|
|
pMsg->Buffer = NULL;
|
2008-01-21 11:31:55 +01:00
|
|
|
|
2008-06-18 18:32:12 +02:00
|
|
|
TRACE("(%p, %p, %p, %p)\n", Connection, Header, pMsg, auth_data_out);
|
2008-01-21 11:31:55 +01:00
|
|
|
|
|
|
|
RPCRT4_SetThreadCurrentConnection(Connection);
|
|
|
|
|
|
|
|
status = RPCRT4_receive_fragment(Connection, Header, &payload);
|
|
|
|
if (status != RPC_S_OK) goto fail;
|
|
|
|
|
|
|
|
hdr_length = RPCRT4_GetHeaderSize(*Header);
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
/* read packet body */
|
2008-01-21 11:31:55 +01:00
|
|
|
switch ((*Header)->common.ptype) {
|
2004-04-27 01:33:39 +02:00
|
|
|
case PKT_RESPONSE:
|
|
|
|
pMsg->BufferLength = (*Header)->response.alloc_hint;
|
|
|
|
break;
|
|
|
|
case PKT_REQUEST:
|
|
|
|
pMsg->BufferLength = (*Header)->request.alloc_hint;
|
|
|
|
break;
|
|
|
|
default:
|
2008-01-21 11:31:55 +01:00
|
|
|
pMsg->BufferLength = (*Header)->common.frag_len - hdr_length - RPC_AUTH_VERIFIER_LEN(&(*Header)->common);
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
2005-02-15 21:45:37 +01:00
|
|
|
|
|
|
|
TRACE("buffer length = %u\n", pMsg->BufferLength);
|
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
pMsg->Buffer = I_RpcAllocate(pMsg->BufferLength);
|
|
|
|
if (!pMsg->Buffer)
|
|
|
|
{
|
|
|
|
status = ERROR_OUTOFMEMORY;
|
|
|
|
goto fail;
|
|
|
|
}
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
first_flag = RPC_FLG_FIRST;
|
2008-01-21 11:31:55 +01:00
|
|
|
auth_length = (*Header)->common.auth_len;
|
2006-10-27 00:15:00 +02:00
|
|
|
if (auth_length) {
|
2008-01-21 11:31:55 +01:00
|
|
|
auth_data = HeapAlloc(GetProcessHeap(), 0, RPC_AUTH_VERIFIER_LEN(&(*Header)->common));
|
2006-10-27 00:15:00 +02:00
|
|
|
if (!auth_data) {
|
2007-11-29 16:42:20 +01:00
|
|
|
status = RPC_S_OUT_OF_RESOURCES;
|
2006-10-27 00:15:00 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
}
|
2008-01-21 11:31:55 +01:00
|
|
|
CurrentHeader = *Header;
|
2004-04-27 01:33:39 +02:00
|
|
|
buffer_length = 0;
|
2006-10-27 00:15:11 +02:00
|
|
|
while (TRUE)
|
2004-04-27 01:33:39 +02:00
|
|
|
{
|
2008-01-21 11:31:55 +01:00
|
|
|
unsigned int header_auth_len = RPC_AUTH_VERIFIER_LEN(&CurrentHeader->common);
|
2006-10-27 00:15:00 +02:00
|
|
|
|
|
|
|
/* verify header fields */
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
if ((CurrentHeader->common.frag_len < hdr_length) ||
|
|
|
|
(CurrentHeader->common.frag_len - hdr_length < header_auth_len)) {
|
2006-11-09 23:04:48 +01:00
|
|
|
WARN("frag_len %d too small for hdr_length %d and auth_len %d\n",
|
2008-01-21 11:31:55 +01:00
|
|
|
CurrentHeader->common.frag_len, hdr_length, CurrentHeader->common.auth_len);
|
2006-10-27 00:15:00 +02:00
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-31 15:45:22 +01:00
|
|
|
if (CurrentHeader->common.auth_len != auth_length) {
|
2009-07-03 13:42:57 +02:00
|
|
|
WARN("auth_len header field changed from %d to %d\n",
|
2008-01-31 15:45:22 +01:00
|
|
|
auth_length, CurrentHeader->common.auth_len);
|
2006-10-27 00:15:00 +02:00
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-31 15:45:22 +01:00
|
|
|
if ((CurrentHeader->common.flags & RPC_FLG_FIRST) != first_flag) {
|
2006-10-27 00:16:25 +02:00
|
|
|
TRACE("invalid packet flags\n");
|
2004-04-27 01:33:39 +02:00
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
data_length = CurrentHeader->common.frag_len - hdr_length - header_auth_len;
|
2006-10-27 00:16:25 +02:00
|
|
|
if (data_length + buffer_length > pMsg->BufferLength) {
|
2009-07-03 13:42:57 +02:00
|
|
|
TRACE("allocation hint exceeded, new buffer length = %d\n",
|
2006-10-27 00:16:25 +02:00
|
|
|
data_length + buffer_length);
|
|
|
|
pMsg->BufferLength = data_length + buffer_length;
|
|
|
|
status = I_RpcReAllocateBuffer(pMsg);
|
|
|
|
if (status != RPC_S_OK) goto fail;
|
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
memcpy((unsigned char *)pMsg->Buffer + buffer_length, payload, data_length);
|
2004-04-27 01:33:39 +02:00
|
|
|
|
2006-10-27 00:15:00 +02:00
|
|
|
if (header_auth_len) {
|
2008-01-21 11:31:55 +01:00
|
|
|
if (header_auth_len < sizeof(RpcAuthVerifier) ||
|
|
|
|
header_auth_len > RPC_AUTH_VERIFIER_LEN(&(*Header)->common)) {
|
2006-11-15 02:00:36 +01:00
|
|
|
WARN("bad auth verifier length %d\n", header_auth_len);
|
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2006-10-27 00:15:00 +02:00
|
|
|
/* FIXME: we should accumulate authentication data for the bind,
|
|
|
|
* bind_ack, alter_context and alter_context_response if necessary.
|
|
|
|
* however, the details of how this is done is very sketchy in the
|
|
|
|
* DCE/RPC spec. for all other packet types that have authentication
|
|
|
|
* verifier data then it is just duplicated in all the fragments */
|
2008-01-21 11:31:55 +01:00
|
|
|
memcpy(auth_data, (unsigned char *)payload + data_length, header_auth_len);
|
2006-11-15 02:00:36 +01:00
|
|
|
|
|
|
|
/* these packets are handled specially, not by the generic SecurePacket
|
|
|
|
* function */
|
2008-06-18 18:32:12 +02:00
|
|
|
if (!auth_data_out && SecIsValidHandle(&Connection->ctx))
|
2007-09-11 11:31:54 +02:00
|
|
|
{
|
2006-11-15 02:00:36 +01:00
|
|
|
status = RPCRT4_SecurePacket(Connection, SECURE_PACKET_RECEIVE,
|
2008-01-21 11:31:55 +01:00
|
|
|
CurrentHeader, hdr_length,
|
2006-11-15 02:00:36 +01:00
|
|
|
(unsigned char *)pMsg->Buffer + buffer_length, data_length,
|
|
|
|
(RpcAuthVerifier *)auth_data,
|
2008-01-16 22:57:31 +01:00
|
|
|
auth_data + sizeof(RpcAuthVerifier),
|
2006-11-15 02:00:36 +01:00
|
|
|
header_auth_len - sizeof(RpcAuthVerifier));
|
2007-09-11 11:31:54 +02:00
|
|
|
if (status != RPC_S_OK) goto fail;
|
|
|
|
}
|
2006-10-27 00:15:00 +02:00
|
|
|
}
|
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
buffer_length += data_length;
|
2008-01-21 11:31:55 +01:00
|
|
|
if (!(CurrentHeader->common.flags & RPC_FLG_LAST)) {
|
2004-04-27 01:33:39 +02:00
|
|
|
TRACE("next header\n");
|
|
|
|
|
2008-01-21 11:31:55 +01:00
|
|
|
if (*Header != CurrentHeader)
|
|
|
|
{
|
|
|
|
RPCRT4_FreeHeader(CurrentHeader);
|
|
|
|
CurrentHeader = NULL;
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
2008-01-21 11:31:55 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, payload);
|
|
|
|
payload = NULL;
|
|
|
|
|
|
|
|
status = RPCRT4_receive_fragment(Connection, &CurrentHeader, &payload);
|
|
|
|
if (status != RPC_S_OK) goto fail;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
first_flag = 0;
|
2006-10-27 00:15:11 +02:00
|
|
|
} else {
|
|
|
|
break;
|
2004-04-27 01:33:39 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-27 00:15:11 +02:00
|
|
|
pMsg->BufferLength = buffer_length;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
/* success */
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
|
|
|
fail:
|
2007-11-12 21:10:19 +01:00
|
|
|
RPCRT4_SetThreadCurrentConnection(NULL);
|
2008-01-21 11:31:55 +01:00
|
|
|
if (CurrentHeader != *Header)
|
|
|
|
RPCRT4_FreeHeader(CurrentHeader);
|
2006-10-15 01:03:58 +02:00
|
|
|
if (status != RPC_S_OK) {
|
2008-02-04 23:22:47 +01:00
|
|
|
I_RpcFree(pMsg->Buffer);
|
|
|
|
pMsg->Buffer = NULL;
|
2004-04-27 01:33:39 +02:00
|
|
|
RPCRT4_FreeHeader(*Header);
|
|
|
|
*Header = NULL;
|
|
|
|
}
|
2008-06-18 18:32:12 +02:00
|
|
|
if (auth_data_out && status == RPC_S_OK) {
|
|
|
|
*auth_length_out = auth_length;
|
|
|
|
*auth_data_out = auth_data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
HeapFree(GetProcessHeap(), 0, auth_data);
|
2008-01-21 11:31:55 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, payload);
|
2004-04-27 01:33:39 +02:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-06-18 18:32:12 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* RPCRT4_Receive (internal)
|
|
|
|
*
|
|
|
|
* Receive a packet from connection and merge the fragments.
|
|
|
|
*/
|
|
|
|
RPC_STATUS RPCRT4_Receive(RpcConnection *Connection, RpcPktHdr **Header,
|
|
|
|
PRPC_MESSAGE pMsg)
|
|
|
|
{
|
|
|
|
return RPCRT4_ReceiveWithAuth(Connection, Header, pMsg, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcNegotiateTransferSyntax [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Negotiates the transfer syntax used by a client connection by connecting
|
|
|
|
* to the server.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I] RPC Message structure.
|
|
|
|
* pAsync [I] Asynchronous state to set.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: RPC_S_OK.
|
|
|
|
* Failure: Any error code.
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcNegotiateTransferSyntax(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2008-01-08 13:26:19 +01:00
|
|
|
RpcConnection* conn;
|
|
|
|
RPC_STATUS status = RPC_S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", pMsg);
|
|
|
|
|
|
|
|
if (!bind || bind->server)
|
2008-09-12 13:59:02 +02:00
|
|
|
{
|
|
|
|
ERR("no binding\n");
|
2008-01-08 13:26:19 +01:00
|
|
|
return RPC_S_INVALID_BINDING;
|
2008-09-12 13:59:02 +02:00
|
|
|
}
|
2008-01-08 13:26:19 +01:00
|
|
|
|
|
|
|
/* if we already have a connection, we don't need to negotiate again */
|
|
|
|
if (!pMsg->ReservedForRuntime)
|
|
|
|
{
|
|
|
|
RPC_CLIENT_INTERFACE *cif = pMsg->RpcInterfaceInformation;
|
|
|
|
if (!cif) return RPC_S_INTERFACE_NOT_FOUND;
|
|
|
|
|
|
|
|
if (!bind->Endpoint || !bind->Endpoint[0])
|
|
|
|
{
|
|
|
|
TRACE("automatically resolving partially bound binding\n");
|
|
|
|
status = RpcEpResolveBinding(bind, cif);
|
|
|
|
if (status != RPC_S_OK) return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = RPCRT4_OpenBinding(bind, &conn, &cif->TransferSyntax,
|
|
|
|
&cif->InterfaceId);
|
|
|
|
|
|
|
|
if (status == RPC_S_OK)
|
2008-04-01 13:48:15 +02:00
|
|
|
{
|
2008-01-08 13:26:19 +01:00
|
|
|
pMsg->ReservedForRuntime = conn;
|
2008-04-01 13:48:15 +02:00
|
|
|
RPCRT4_AddRefBinding(bind);
|
|
|
|
}
|
2008-01-08 13:26:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2002-10-10 20:55:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcGetBuffer [RPCRT4.@]
|
2007-02-21 14:58:10 +01:00
|
|
|
*
|
|
|
|
* Allocates a buffer for use by I_RpcSend or I_RpcSendReceive and binds to the
|
|
|
|
* server interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I/O] RPC message information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: RPC_S_OK.
|
|
|
|
* Failure: RPC_S_INVALID_BINDING if pMsg->Handle is invalid.
|
|
|
|
* RPC_S_SERVER_UNAVAILABLE if unable to connect to server.
|
|
|
|
* ERROR_OUTOFMEMORY if buffer allocation failed.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The pMsg->BufferLength field determines the size of the buffer to allocate,
|
|
|
|
* in bytes.
|
|
|
|
*
|
|
|
|
* Use I_RpcFreeBuffer() to unbind from the server and free the message buffer.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* I_RpcFreeBuffer(), I_RpcSend(), I_RpcReceive(), I_RpcSendReceive().
|
2002-10-10 20:55:24 +02:00
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcGetBuffer(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
2008-01-08 13:26:19 +01:00
|
|
|
RPC_STATUS status;
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2008-01-08 13:26:19 +01:00
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
TRACE("(%p): BufferLength=%d\n", pMsg, pMsg->BufferLength);
|
2005-08-03 16:55:05 +02:00
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
if (!bind)
|
2008-09-12 13:59:02 +02:00
|
|
|
{
|
|
|
|
ERR("no binding\n");
|
2008-01-08 13:26:19 +01:00
|
|
|
return RPC_S_INVALID_BINDING;
|
2008-09-12 13:59:02 +02:00
|
|
|
}
|
2008-01-08 13:26:19 +01:00
|
|
|
|
|
|
|
pMsg->Buffer = I_RpcAllocate(pMsg->BufferLength);
|
2004-02-27 05:33:41 +01:00
|
|
|
TRACE("Buffer=%p\n", pMsg->Buffer);
|
2008-01-08 13:26:19 +01:00
|
|
|
|
|
|
|
if (!pMsg->Buffer)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (!bind->server)
|
|
|
|
{
|
|
|
|
status = I_RpcNegotiateTransferSyntax(pMsg);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
I_RpcFree(pMsg->Buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = RPC_S_OK;
|
|
|
|
|
|
|
|
return status;
|
2002-10-10 20:55:24 +02:00
|
|
|
}
|
|
|
|
|
2006-10-27 00:16:25 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcReAllocateBuffer (internal)
|
|
|
|
*/
|
|
|
|
static RPC_STATUS I_RpcReAllocateBuffer(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
|
|
|
TRACE("(%p): BufferLength=%d\n", pMsg, pMsg->BufferLength);
|
|
|
|
pMsg->Buffer = HeapReAlloc(GetProcessHeap(), 0, pMsg->Buffer, pMsg->BufferLength);
|
|
|
|
|
|
|
|
TRACE("Buffer=%p\n", pMsg->Buffer);
|
2008-01-04 18:37:59 +01:00
|
|
|
return pMsg->Buffer ? RPC_S_OK : ERROR_OUTOFMEMORY;
|
2006-10-27 00:16:25 +02:00
|
|
|
}
|
|
|
|
|
2002-10-10 20:55:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcFreeBuffer [RPCRT4.@]
|
2007-02-21 14:58:10 +01:00
|
|
|
*
|
|
|
|
* Frees a buffer allocated by I_RpcGetBuffer or I_RpcReceive and unbinds from
|
|
|
|
* the server interface.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I/O] RPC message information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* RPC_S_OK.
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* I_RpcGetBuffer(), I_RpcReceive().
|
2002-10-10 20:55:24 +02:00
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcFreeBuffer(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2008-01-08 13:26:19 +01:00
|
|
|
|
2003-05-21 20:23:06 +02:00
|
|
|
TRACE("(%p) Buffer=%p\n", pMsg, pMsg->Buffer);
|
2008-01-08 13:26:19 +01:00
|
|
|
|
2008-09-12 13:59:02 +02:00
|
|
|
if (!bind)
|
|
|
|
{
|
|
|
|
ERR("no binding\n");
|
|
|
|
return RPC_S_INVALID_BINDING;
|
|
|
|
}
|
2008-01-08 13:26:19 +01:00
|
|
|
|
|
|
|
if (pMsg->ReservedForRuntime)
|
|
|
|
{
|
|
|
|
RpcConnection *conn = pMsg->ReservedForRuntime;
|
|
|
|
RPCRT4_CloseBinding(bind, conn);
|
2008-04-01 13:48:15 +02:00
|
|
|
RPCRT4_ReleaseBinding(bind);
|
2008-01-08 13:26:19 +01:00
|
|
|
pMsg->ReservedForRuntime = NULL;
|
|
|
|
}
|
|
|
|
I_RpcFree(pMsg->Buffer);
|
2008-01-04 18:37:59 +01:00
|
|
|
return RPC_S_OK;
|
2002-10-10 20:55:24 +02:00
|
|
|
}
|
|
|
|
|
2008-01-21 11:31:40 +01:00
|
|
|
static void CALLBACK async_apc_notifier_proc(ULONG_PTR ulParam)
|
|
|
|
{
|
|
|
|
RPC_ASYNC_STATE *state = (RPC_ASYNC_STATE *)ulParam;
|
|
|
|
state->u.APC.NotificationRoutine(state, NULL, state->Event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI async_notifier_proc(LPVOID p)
|
|
|
|
{
|
|
|
|
RpcConnection *conn = p;
|
|
|
|
RPC_ASYNC_STATE *state = conn->async_state;
|
|
|
|
|
2008-02-13 17:22:08 +01:00
|
|
|
if (state && conn->ops->wait_for_incoming_data(conn) != -1)
|
2008-01-21 11:31:40 +01:00
|
|
|
{
|
|
|
|
state->Event = RpcCallComplete;
|
|
|
|
switch (state->NotificationType)
|
|
|
|
{
|
|
|
|
case RpcNotificationTypeEvent:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeEvent %p\n", state->u.hEvent);
|
2008-01-21 11:31:40 +01:00
|
|
|
SetEvent(state->u.hEvent);
|
|
|
|
break;
|
|
|
|
case RpcNotificationTypeApc:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeApc %p\n", state->u.APC.hThread);
|
2008-01-21 11:31:40 +01:00
|
|
|
QueueUserAPC(async_apc_notifier_proc, state->u.APC.hThread, (ULONG_PTR)state);
|
|
|
|
break;
|
|
|
|
case RpcNotificationTypeIoc:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeIoc %p, 0x%x, 0x%lx, %p\n",
|
|
|
|
state->u.IOC.hIOPort, state->u.IOC.dwNumberOfBytesTransferred,
|
|
|
|
state->u.IOC.dwCompletionKey, state->u.IOC.lpOverlapped);
|
2008-01-21 11:31:40 +01:00
|
|
|
PostQueuedCompletionStatus(state->u.IOC.hIOPort,
|
|
|
|
state->u.IOC.dwNumberOfBytesTransferred,
|
|
|
|
state->u.IOC.dwCompletionKey,
|
|
|
|
state->u.IOC.lpOverlapped);
|
|
|
|
break;
|
|
|
|
case RpcNotificationTypeHwnd:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeHwnd %p 0x%x\n", state->u.HWND.hWnd,
|
|
|
|
state->u.HWND.Msg);
|
2008-01-21 11:31:40 +01:00
|
|
|
PostMessageW(state->u.HWND.hWnd, state->u.HWND.Msg, 0, 0);
|
|
|
|
break;
|
|
|
|
case RpcNotificationTypeCallback:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeCallback %p\n", state->u.NotificationRoutine);
|
2008-01-21 11:31:40 +01:00
|
|
|
state->u.NotificationRoutine(state, NULL, state->Event);
|
|
|
|
break;
|
|
|
|
case RpcNotificationTypeNone:
|
2008-02-13 17:22:08 +01:00
|
|
|
TRACE("RpcNotificationTypeNone\n");
|
|
|
|
break;
|
2008-01-21 11:31:40 +01:00
|
|
|
default:
|
2008-02-13 17:22:08 +01:00
|
|
|
FIXME("unknown NotificationType: %d/0x%x\n", state->NotificationType, state->NotificationType);
|
2008-01-21 11:31:40 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-10-10 20:55:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcSend [RPCRT4.@]
|
2007-02-21 14:58:10 +01:00
|
|
|
*
|
|
|
|
* Sends a message to the server.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I/O] RPC message information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Unknown.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The buffer must have been allocated with I_RpcGetBuffer().
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* I_RpcGetBuffer(), I_RpcReceive(), I_RpcSendReceive().
|
2002-10-10 20:55:24 +02:00
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcSend(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2003-02-19 04:44:35 +01:00
|
|
|
RpcConnection* conn;
|
2002-10-10 20:55:24 +02:00
|
|
|
RPC_STATUS status;
|
2004-04-27 01:33:39 +02:00
|
|
|
RpcPktHdr *hdr;
|
2002-10-10 20:55:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pMsg);
|
2008-01-08 13:26:19 +01:00
|
|
|
if (!bind || bind->server || !pMsg->ReservedForRuntime) return RPC_S_INVALID_BINDING;
|
2002-10-10 20:55:24 +02:00
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
conn = pMsg->ReservedForRuntime;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
2007-07-05 13:47:42 +02:00
|
|
|
hdr = RPCRT4_BuildRequestHeader(pMsg->DataRepresentation,
|
2008-01-07 16:19:57 +01:00
|
|
|
pMsg->BufferLength,
|
|
|
|
pMsg->ProcNum & ~RPC_FLAGS_VALID_BIT,
|
2007-07-05 13:47:42 +02:00
|
|
|
&bind->ObjectUuid);
|
|
|
|
if (!hdr)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
hdr->common.call_id = conn->NextCallId++;
|
2002-10-10 20:55:24 +02:00
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
status = RPCRT4_Send(conn, hdr, pMsg->Buffer, pMsg->BufferLength);
|
|
|
|
|
|
|
|
RPCRT4_FreeHeader(hdr);
|
|
|
|
|
2008-01-21 11:31:40 +01:00
|
|
|
if (status == RPC_S_OK && pMsg->RpcFlags & RPC_BUFFER_ASYNC)
|
|
|
|
{
|
|
|
|
if (!QueueUserWorkItem(async_notifier_proc, conn, WT_EXECUTEDEFAULT | WT_EXECUTELONGFUNCTION))
|
|
|
|
status = RPC_S_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
return status;
|
2002-10-10 20:55:24 +02:00
|
|
|
}
|
|
|
|
|
2007-06-25 15:23:45 +02:00
|
|
|
/* is this status something that the server can't recover from? */
|
|
|
|
static inline BOOL is_hard_error(RPC_STATUS status)
|
|
|
|
{
|
|
|
|
switch (status)
|
|
|
|
{
|
|
|
|
case 0: /* user-defined fault */
|
|
|
|
case ERROR_ACCESS_DENIED:
|
|
|
|
case ERROR_INVALID_PARAMETER:
|
|
|
|
case RPC_S_PROTOCOL_ERROR:
|
|
|
|
case RPC_S_CALL_FAILED:
|
|
|
|
case RPC_S_CALL_FAILED_DNE:
|
2007-07-17 15:05:01 +02:00
|
|
|
case RPC_S_SEC_PKG_ERROR:
|
2007-06-25 15:23:45 +02:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 20:55:24 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcReceive [RPCRT4.@]
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcReceive(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2002-10-10 20:55:24 +02:00
|
|
|
RPC_STATUS status;
|
2004-04-27 01:33:39 +02:00
|
|
|
RpcPktHdr *hdr = NULL;
|
2008-01-08 13:26:19 +01:00
|
|
|
RpcConnection *conn;
|
2002-10-10 20:55:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pMsg);
|
2008-01-08 13:26:19 +01:00
|
|
|
if (!bind || bind->server || !pMsg->ReservedForRuntime) return RPC_S_INVALID_BINDING;
|
2003-02-19 04:44:35 +01:00
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
conn = pMsg->ReservedForRuntime;
|
2004-04-27 01:33:39 +02:00
|
|
|
status = RPCRT4_Receive(conn, &hdr, pMsg);
|
|
|
|
if (status != RPC_S_OK) {
|
2009-01-04 01:49:14 +01:00
|
|
|
WARN("receive failed with error %x\n", status);
|
2004-04-27 01:33:39 +02:00
|
|
|
goto fail;
|
|
|
|
}
|
2003-05-22 05:36:00 +02:00
|
|
|
|
2004-04-27 01:33:39 +02:00
|
|
|
switch (hdr->common.ptype) {
|
|
|
|
case PKT_RESPONSE:
|
2003-02-19 04:44:35 +01:00
|
|
|
break;
|
2004-04-27 01:33:39 +02:00
|
|
|
case PKT_FAULT:
|
2009-07-03 13:42:57 +02:00
|
|
|
ERR ("we got fault packet with status 0x%x\n", hdr->fault.status);
|
2007-07-05 13:46:59 +02:00
|
|
|
status = NCA2RPC_STATUS(hdr->fault.status);
|
2007-06-25 15:23:45 +02:00
|
|
|
if (is_hard_error(status))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2004-04-27 01:33:39 +02:00
|
|
|
default:
|
2005-02-15 21:45:37 +01:00
|
|
|
WARN("bad packet type %d\n", hdr->common.ptype);
|
2007-06-25 15:23:45 +02:00
|
|
|
status = RPC_S_PROTOCOL_ERROR;
|
2004-04-27 01:33:39 +02:00
|
|
|
goto fail;
|
2003-02-19 04:44:35 +01:00
|
|
|
}
|
2004-04-27 01:33:39 +02:00
|
|
|
|
|
|
|
/* success */
|
2007-06-25 15:23:45 +02:00
|
|
|
RPCRT4_FreeHeader(hdr);
|
|
|
|
return status;
|
2004-04-27 01:33:39 +02:00
|
|
|
|
2003-02-19 04:44:35 +01:00
|
|
|
fail:
|
2006-10-15 01:03:58 +02:00
|
|
|
RPCRT4_FreeHeader(hdr);
|
2007-06-25 15:23:45 +02:00
|
|
|
RPCRT4_DestroyConnection(conn);
|
2008-01-08 13:26:19 +01:00
|
|
|
pMsg->ReservedForRuntime = NULL;
|
2003-02-19 04:44:35 +01:00
|
|
|
return status;
|
2002-10-10 20:55:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcSendReceive [RPCRT4.@]
|
2007-02-21 14:58:10 +01:00
|
|
|
*
|
|
|
|
* Sends a message to the server and receives the response.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I/O] RPC message information.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: RPC_S_OK.
|
|
|
|
* Failure: Any error code.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The buffer must have been allocated with I_RpcGetBuffer().
|
|
|
|
*
|
|
|
|
* SEE ALSO
|
|
|
|
* I_RpcGetBuffer(), I_RpcSend(), I_RpcReceive().
|
2002-10-10 20:55:24 +02:00
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcSendReceive(PRPC_MESSAGE pMsg)
|
|
|
|
{
|
|
|
|
RPC_STATUS status;
|
2008-01-08 13:26:19 +01:00
|
|
|
void *original_buffer;
|
2002-10-10 20:55:24 +02:00
|
|
|
|
|
|
|
TRACE("(%p)\n", pMsg);
|
2007-02-21 18:12:41 +01:00
|
|
|
|
2008-01-08 13:26:19 +01:00
|
|
|
original_buffer = pMsg->Buffer;
|
2002-10-10 20:55:24 +02:00
|
|
|
status = I_RpcSend(pMsg);
|
|
|
|
if (status == RPC_S_OK)
|
|
|
|
status = I_RpcReceive(pMsg);
|
2007-02-21 18:12:41 +01:00
|
|
|
/* free the buffer replaced by a new buffer in I_RpcReceive */
|
|
|
|
if (status == RPC_S_OK)
|
2008-01-08 13:26:19 +01:00
|
|
|
I_RpcFree(original_buffer);
|
2002-10-10 20:55:24 +02:00
|
|
|
return status;
|
|
|
|
}
|
2008-01-07 16:20:40 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcAsyncSetHandle [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Sets the asynchronous state of the handle contained in the RPC message
|
|
|
|
* structure.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pMsg [I] RPC Message structure.
|
|
|
|
* pAsync [I] Asynchronous state to set.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: RPC_S_OK.
|
|
|
|
* Failure: Any error code.
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcAsyncSetHandle(PRPC_MESSAGE pMsg, PRPC_ASYNC_STATE pAsync)
|
|
|
|
{
|
2009-02-16 09:54:10 +01:00
|
|
|
RpcBinding* bind = pMsg->Handle;
|
2008-01-21 11:31:40 +01:00
|
|
|
RpcConnection *conn;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", pMsg, pAsync);
|
|
|
|
|
|
|
|
if (!bind || bind->server || !pMsg->ReservedForRuntime) return RPC_S_INVALID_BINDING;
|
|
|
|
|
|
|
|
conn = pMsg->ReservedForRuntime;
|
|
|
|
conn->async_state = pAsync;
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
2008-01-07 16:20:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* I_RpcAsyncAbortCall [RPCRT4.@]
|
|
|
|
*
|
|
|
|
* Aborts an asynchronous call.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* pAsync [I] Asynchronous state.
|
|
|
|
* ExceptionCode [I] Exception code.
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: RPC_S_OK.
|
|
|
|
* Failure: Any error code.
|
|
|
|
*/
|
|
|
|
RPC_STATUS WINAPI I_RpcAsyncAbortCall(PRPC_ASYNC_STATE pAsync, ULONG ExceptionCode)
|
|
|
|
{
|
|
|
|
FIXME("(%p, %d): stub\n", pAsync, ExceptionCode);
|
|
|
|
return RPC_S_INVALID_ASYNC_HANDLE;
|
|
|
|
}
|