rpcrt4: Compile in RPC over HTTP support even if HAVE_SOCKETPAIR is not defined.
This commit is contained in:
parent
b2a5bfdfc9
commit
ce747f3fac
|
@ -7,6 +7,7 @@ MODULE = rpcrt4.dll
|
|||
IMPORTLIB = rpcrt4
|
||||
IMPORTS = uuid advapi32 kernel32 ntdll
|
||||
DELAYIMPORTS = wininet secur32 user32
|
||||
EXTRALIBS = @SOCKETLIBS@
|
||||
|
||||
C_SRCS = \
|
||||
cproxy.c \
|
||||
|
|
|
@ -762,6 +762,143 @@ static RPC_STATUS rpcrt4_ncalrpc_parse_top_of_tower(const unsigned char *tower_d
|
|||
|
||||
/**** ncacn_ip_tcp support ****/
|
||||
|
||||
static size_t rpcrt4_ip_tcp_get_top_of_tower(unsigned char *tower_data,
|
||||
const char *networkaddr,
|
||||
unsigned char tcp_protid,
|
||||
const char *endpoint)
|
||||
{
|
||||
twr_tcp_floor_t *tcp_floor;
|
||||
twr_ipv4_floor_t *ipv4_floor;
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
int ret;
|
||||
size_t size = sizeof(*tcp_floor) + sizeof(*ipv4_floor);
|
||||
|
||||
TRACE("(%p, %s, %s)\n", tower_data, networkaddr, endpoint);
|
||||
|
||||
if (!tower_data)
|
||||
return size;
|
||||
|
||||
tcp_floor = (twr_tcp_floor_t *)tower_data;
|
||||
tower_data += sizeof(*tcp_floor);
|
||||
|
||||
ipv4_floor = (twr_ipv4_floor_t *)tower_data;
|
||||
|
||||
tcp_floor->count_lhs = sizeof(tcp_floor->protid);
|
||||
tcp_floor->protid = tcp_protid;
|
||||
tcp_floor->count_rhs = sizeof(tcp_floor->port);
|
||||
|
||||
ipv4_floor->count_lhs = sizeof(ipv4_floor->protid);
|
||||
ipv4_floor->protid = EPM_PROTOCOL_IP;
|
||||
ipv4_floor->count_rhs = sizeof(ipv4_floor->ipv4addr);
|
||||
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
/* FIXME: only support IPv4 at the moment. how is IPv6 represented by the EPM? */
|
||||
hints.ai_family = PF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_addrlen = 0;
|
||||
hints.ai_addr = NULL;
|
||||
hints.ai_canonname = NULL;
|
||||
hints.ai_next = NULL;
|
||||
|
||||
ret = getaddrinfo(networkaddr, endpoint, &hints, &ai);
|
||||
if (ret)
|
||||
{
|
||||
ret = getaddrinfo("0.0.0.0", endpoint, &hints, &ai);
|
||||
if (ret)
|
||||
{
|
||||
ERR("getaddrinfo failed: %s\n", gai_strerror(ret));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ai->ai_family == PF_INET)
|
||||
{
|
||||
const struct sockaddr_in *sin = (const struct sockaddr_in *)ai->ai_addr;
|
||||
tcp_floor->port = sin->sin_port;
|
||||
ipv4_floor->ipv4addr = sin->sin_addr.s_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("unexpected protocol family %d\n", ai->ai_family);
|
||||
return 0;
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static RPC_STATUS rpcrt4_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
|
||||
size_t tower_size,
|
||||
char **networkaddr,
|
||||
unsigned char tcp_protid,
|
||||
char **endpoint)
|
||||
{
|
||||
const twr_tcp_floor_t *tcp_floor = (const twr_tcp_floor_t *)tower_data;
|
||||
const twr_ipv4_floor_t *ipv4_floor;
|
||||
struct in_addr in_addr;
|
||||
|
||||
TRACE("(%p, %d, %p, %p)\n", tower_data, (int)tower_size, networkaddr, endpoint);
|
||||
|
||||
if (tower_size < sizeof(*tcp_floor))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
tower_data += sizeof(*tcp_floor);
|
||||
tower_size -= sizeof(*tcp_floor);
|
||||
|
||||
if (tower_size < sizeof(*ipv4_floor))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
ipv4_floor = (const twr_ipv4_floor_t *)tower_data;
|
||||
|
||||
if ((tcp_floor->count_lhs != sizeof(tcp_floor->protid)) ||
|
||||
(tcp_floor->protid != tcp_protid) ||
|
||||
(tcp_floor->count_rhs != sizeof(tcp_floor->port)) ||
|
||||
(ipv4_floor->count_lhs != sizeof(ipv4_floor->protid)) ||
|
||||
(ipv4_floor->protid != EPM_PROTOCOL_IP) ||
|
||||
(ipv4_floor->count_rhs != sizeof(ipv4_floor->ipv4addr)))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
if (endpoint)
|
||||
{
|
||||
*endpoint = I_RpcAllocate(6 /* sizeof("65535") + 1 */);
|
||||
if (!*endpoint)
|
||||
return RPC_S_OUT_OF_RESOURCES;
|
||||
sprintf(*endpoint, "%u", ntohs(tcp_floor->port));
|
||||
}
|
||||
|
||||
if (networkaddr)
|
||||
{
|
||||
*networkaddr = I_RpcAllocate(INET_ADDRSTRLEN);
|
||||
if (!*networkaddr)
|
||||
{
|
||||
if (endpoint)
|
||||
{
|
||||
I_RpcFree(*endpoint);
|
||||
*endpoint = NULL;
|
||||
}
|
||||
return RPC_S_OUT_OF_RESOURCES;
|
||||
}
|
||||
in_addr.s_addr = ipv4_floor->ipv4addr;
|
||||
if (!inet_ntop(AF_INET, &in_addr, *networkaddr, INET_ADDRSTRLEN))
|
||||
{
|
||||
ERR("inet_ntop: %s\n", strerror(errno));
|
||||
I_RpcFree(*networkaddr);
|
||||
*networkaddr = NULL;
|
||||
if (endpoint)
|
||||
{
|
||||
I_RpcFree(*endpoint);
|
||||
*endpoint = NULL;
|
||||
}
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
}
|
||||
}
|
||||
|
||||
return RPC_S_OK;
|
||||
}
|
||||
|
||||
#ifdef HAVE_SOCKETPAIR
|
||||
|
||||
typedef struct _RpcConnection_tcp
|
||||
|
@ -1167,74 +1304,6 @@ static int rpcrt4_conn_tcp_wait_for_incoming_data(RpcConnection *Connection)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static size_t rpcrt4_ip_tcp_get_top_of_tower(unsigned char *tower_data,
|
||||
const char *networkaddr,
|
||||
unsigned char tcp_protid,
|
||||
const char *endpoint)
|
||||
{
|
||||
twr_tcp_floor_t *tcp_floor;
|
||||
twr_ipv4_floor_t *ipv4_floor;
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
int ret;
|
||||
size_t size = sizeof(*tcp_floor) + sizeof(*ipv4_floor);
|
||||
|
||||
TRACE("(%p, %s, %s)\n", tower_data, networkaddr, endpoint);
|
||||
|
||||
if (!tower_data)
|
||||
return size;
|
||||
|
||||
tcp_floor = (twr_tcp_floor_t *)tower_data;
|
||||
tower_data += sizeof(*tcp_floor);
|
||||
|
||||
ipv4_floor = (twr_ipv4_floor_t *)tower_data;
|
||||
|
||||
tcp_floor->count_lhs = sizeof(tcp_floor->protid);
|
||||
tcp_floor->protid = tcp_protid;
|
||||
tcp_floor->count_rhs = sizeof(tcp_floor->port);
|
||||
|
||||
ipv4_floor->count_lhs = sizeof(ipv4_floor->protid);
|
||||
ipv4_floor->protid = EPM_PROTOCOL_IP;
|
||||
ipv4_floor->count_rhs = sizeof(ipv4_floor->ipv4addr);
|
||||
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
/* FIXME: only support IPv4 at the moment. how is IPv6 represented by the EPM? */
|
||||
hints.ai_family = PF_INET;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
hints.ai_addrlen = 0;
|
||||
hints.ai_addr = NULL;
|
||||
hints.ai_canonname = NULL;
|
||||
hints.ai_next = NULL;
|
||||
|
||||
ret = getaddrinfo(networkaddr, endpoint, &hints, &ai);
|
||||
if (ret)
|
||||
{
|
||||
ret = getaddrinfo("0.0.0.0", endpoint, &hints, &ai);
|
||||
if (ret)
|
||||
{
|
||||
ERR("getaddrinfo failed: %s\n", gai_strerror(ret));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ai->ai_family == PF_INET)
|
||||
{
|
||||
const struct sockaddr_in *sin = (const struct sockaddr_in *)ai->ai_addr;
|
||||
tcp_floor->port = sin->sin_port;
|
||||
ipv4_floor->ipv4addr = sin->sin_addr.s_addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ERR("unexpected protocol family %d\n", ai->ai_family);
|
||||
return 0;
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static size_t rpcrt4_ncacn_ip_tcp_get_top_of_tower(unsigned char *tower_data,
|
||||
const char *networkaddr,
|
||||
const char *endpoint)
|
||||
|
@ -1243,75 +1312,6 @@ static size_t rpcrt4_ncacn_ip_tcp_get_top_of_tower(unsigned char *tower_data,
|
|||
EPM_PROTOCOL_TCP, endpoint);
|
||||
}
|
||||
|
||||
static RPC_STATUS rpcrt4_ip_tcp_parse_top_of_tower(const unsigned char *tower_data,
|
||||
size_t tower_size,
|
||||
char **networkaddr,
|
||||
unsigned char tcp_protid,
|
||||
char **endpoint)
|
||||
{
|
||||
const twr_tcp_floor_t *tcp_floor = (const twr_tcp_floor_t *)tower_data;
|
||||
const twr_ipv4_floor_t *ipv4_floor;
|
||||
struct in_addr in_addr;
|
||||
|
||||
TRACE("(%p, %d, %p, %p)\n", tower_data, (int)tower_size, networkaddr, endpoint);
|
||||
|
||||
if (tower_size < sizeof(*tcp_floor))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
tower_data += sizeof(*tcp_floor);
|
||||
tower_size -= sizeof(*tcp_floor);
|
||||
|
||||
if (tower_size < sizeof(*ipv4_floor))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
ipv4_floor = (const twr_ipv4_floor_t *)tower_data;
|
||||
|
||||
if ((tcp_floor->count_lhs != sizeof(tcp_floor->protid)) ||
|
||||
(tcp_floor->protid != tcp_protid) ||
|
||||
(tcp_floor->count_rhs != sizeof(tcp_floor->port)) ||
|
||||
(ipv4_floor->count_lhs != sizeof(ipv4_floor->protid)) ||
|
||||
(ipv4_floor->protid != EPM_PROTOCOL_IP) ||
|
||||
(ipv4_floor->count_rhs != sizeof(ipv4_floor->ipv4addr)))
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
|
||||
if (endpoint)
|
||||
{
|
||||
*endpoint = I_RpcAllocate(6 /* sizeof("65535") + 1 */);
|
||||
if (!*endpoint)
|
||||
return RPC_S_OUT_OF_RESOURCES;
|
||||
sprintf(*endpoint, "%u", ntohs(tcp_floor->port));
|
||||
}
|
||||
|
||||
if (networkaddr)
|
||||
{
|
||||
*networkaddr = I_RpcAllocate(INET_ADDRSTRLEN);
|
||||
if (!*networkaddr)
|
||||
{
|
||||
if (endpoint)
|
||||
{
|
||||
I_RpcFree(*endpoint);
|
||||
*endpoint = NULL;
|
||||
}
|
||||
return RPC_S_OUT_OF_RESOURCES;
|
||||
}
|
||||
in_addr.s_addr = ipv4_floor->ipv4addr;
|
||||
if (!inet_ntop(AF_INET, &in_addr, *networkaddr, INET_ADDRSTRLEN))
|
||||
{
|
||||
ERR("inet_ntop: %s\n", strerror(errno));
|
||||
I_RpcFree(*networkaddr);
|
||||
*networkaddr = NULL;
|
||||
if (endpoint)
|
||||
{
|
||||
I_RpcFree(*endpoint);
|
||||
*endpoint = NULL;
|
||||
}
|
||||
return EPT_S_NOT_REGISTERED;
|
||||
}
|
||||
}
|
||||
|
||||
return RPC_S_OK;
|
||||
}
|
||||
|
||||
typedef struct _RpcServerProtseq_sock
|
||||
{
|
||||
RpcServerProtseq common;
|
||||
|
@ -1461,6 +1461,8 @@ static RPC_STATUS rpcrt4_ncacn_ip_tcp_parse_top_of_tower(const unsigned char *to
|
|||
endpoint);
|
||||
}
|
||||
|
||||
#endif /* HAVE_SOCKETPAIR */
|
||||
|
||||
/**** ncacn_http support ****/
|
||||
|
||||
/* 60 seconds is the period native uses */
|
||||
|
@ -2399,7 +2401,6 @@ static RPC_STATUS rpcrt4_ncacn_http_parse_top_of_tower(const unsigned char *towe
|
|||
networkaddr, EPM_PROTOCOL_HTTP,
|
||||
endpoint);
|
||||
}
|
||||
#endif /* HAVE_SOCKETPAIR */
|
||||
|
||||
static const struct connection_ops conn_protseq_list[] = {
|
||||
{ "ncacn_np",
|
||||
|
@ -2445,6 +2446,7 @@ static const struct connection_ops conn_protseq_list[] = {
|
|||
rpcrt4_ncacn_ip_tcp_parse_top_of_tower,
|
||||
NULL,
|
||||
},
|
||||
#endif
|
||||
{ "ncacn_http",
|
||||
{ EPM_PROTOCOL_NCACN, EPM_PROTOCOL_HTTP },
|
||||
rpcrt4_ncacn_http_alloc,
|
||||
|
@ -2459,7 +2461,6 @@ static const struct connection_ops conn_protseq_list[] = {
|
|||
rpcrt4_ncacn_http_parse_top_of_tower,
|
||||
rpcrt4_ncacn_http_receive_fragment,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue