2006-04-21 06:38:57 +00:00
|
|
|
|
/*
|
|
|
|
|
* RPC transport layer
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2001 Ove K<EFBFBD>ven, TransGaming Technologies
|
|
|
|
|
* Copyright 2003 Mike Hearn
|
|
|
|
|
* Copyright 2004 Filip Navara
|
|
|
|
|
* Copyright 2006 Mike McCormack
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2006-04-21 09:20:16 +00:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2006-05-11 22:27:02 +00:00
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
2006-04-21 09:20:16 +00:00
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2006-05-11 22:27:02 +00:00
|
|
|
|
# include <sys/socket.h>
|
2006-04-21 09:20:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2006-05-11 22:27:02 +00:00
|
|
|
|
# include <netinet/in.h>
|
2006-04-21 09:20:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef HAVE_ARPA_INET_H
|
2006-05-11 22:27:02 +00:00
|
|
|
|
# include <arpa/inet.h>
|
2006-04-21 09:20:16 +00:00
|
|
|
|
#endif
|
2006-05-01 09:37:32 +00:00
|
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#endif
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
#include "windef.h"
|
|
|
|
|
#include "winbase.h"
|
|
|
|
|
#include "winnls.h"
|
|
|
|
|
#include "winerror.h"
|
|
|
|
|
#include "winreg.h"
|
|
|
|
|
#include "winternl.h"
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
|
|
#include "rpc.h"
|
|
|
|
|
#include "rpcndr.h"
|
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
|
|
#include "rpc_binding.h"
|
|
|
|
|
#include "rpc_message.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
|
|
|
|
|
|
2006-04-21 09:20:16 +00:00
|
|
|
|
/**** ncacn_np support ****/
|
|
|
|
|
|
2006-04-21 06:40:06 +00:00
|
|
|
|
typedef struct _RpcConnection_np
|
|
|
|
|
{
|
|
|
|
|
RpcConnection common;
|
|
|
|
|
HANDLE pipe, thread;
|
|
|
|
|
OVERLAPPED ovl;
|
|
|
|
|
} RpcConnection_np;
|
|
|
|
|
|
|
|
|
|
static RpcConnection *rpcrt4_conn_np_alloc(void)
|
|
|
|
|
{
|
|
|
|
|
return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcConnection_np));
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
static RPC_STATUS rpcrt4_connect_pipe(RpcConnection *Connection, LPCSTR pname)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
TRACE("listening on %s\n", pname);
|
|
|
|
|
|
2006-04-21 06:40:06 +00:00
|
|
|
|
npc->pipe = CreateNamedPipeA(pname, PIPE_ACCESS_DUPLEX,
|
|
|
|
|
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
|
|
|
|
|
PIPE_UNLIMITED_INSTANCES,
|
|
|
|
|
RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
|
|
|
|
|
memset(&npc->ovl, 0, sizeof(npc->ovl));
|
|
|
|
|
npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
if (ConnectNamedPipe(npc->pipe, &npc->ovl))
|
2006-04-21 06:38:57 +00:00
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
|
|
|
|
|
WARN("Couldn't ConnectNamedPipe (error was %ld)\n", GetLastError());
|
|
|
|
|
if (GetLastError() == ERROR_PIPE_CONNECTED) {
|
2006-04-21 06:40:06 +00:00
|
|
|
|
SetEvent(npc->ovl.hEvent);
|
2006-04-21 06:38:57 +00:00
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
if (GetLastError() == ERROR_IO_PENDING) {
|
|
|
|
|
/* FIXME: looks like we need to GetOverlappedResult here? */
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS rpcrt4_open_pipe(RpcConnection *Connection, LPCSTR pname, BOOL wait)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
|
|
|
|
HANDLE pipe;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
DWORD err, dwMode;
|
|
|
|
|
|
|
|
|
|
TRACE("connecting to %s\n", pname);
|
|
|
|
|
|
|
|
|
|
while (TRUE) {
|
2006-04-21 06:40:06 +00:00
|
|
|
|
pipe = CreateFileA(pname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
OPEN_EXISTING, 0, 0);
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (pipe != INVALID_HANDLE_VALUE) break;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
err = GetLastError();
|
|
|
|
|
if (err == ERROR_PIPE_BUSY) {
|
|
|
|
|
TRACE("connection failed, error=%lx\n", err);
|
|
|
|
|
return RPC_S_SERVER_TOO_BUSY;
|
|
|
|
|
}
|
|
|
|
|
if (!wait)
|
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
if (!WaitNamedPipeA(pname, NMPWAIT_WAIT_FOREVER)) {
|
|
|
|
|
err = GetLastError();
|
|
|
|
|
WARN("connection failed, error=%lx\n", err);
|
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* success */
|
2006-04-21 06:40:06 +00:00
|
|
|
|
memset(&npc->ovl, 0, sizeof(npc->ovl));
|
2006-04-21 06:38:57 +00:00
|
|
|
|
/* pipe is connected; change to message-read mode. */
|
|
|
|
|
dwMode = PIPE_READMODE_MESSAGE;
|
2006-04-21 06:40:06 +00:00
|
|
|
|
SetNamedPipeHandleState(pipe, &dwMode, NULL, NULL);
|
|
|
|
|
npc->ovl.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
|
|
|
|
|
npc->pipe = pipe;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS rpcrt4_ncalrpc_open(RpcConnection* Connection)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
static LPCSTR prefix = "\\\\.\\pipe\\lrpc\\";
|
|
|
|
|
RPC_STATUS r;
|
|
|
|
|
LPSTR pname;
|
|
|
|
|
|
2006-04-21 06:39:41 +00:00
|
|
|
|
/* already connected? */
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (npc->pipe)
|
2006-04-21 06:39:41 +00:00
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
/* protseq=ncalrpc: supposed to use NT LPC ports,
|
|
|
|
|
* but we'll implement it with named pipes for now */
|
|
|
|
|
pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Connection->Endpoint) + 1);
|
|
|
|
|
strcat(strcpy(pname, prefix), Connection->Endpoint);
|
|
|
|
|
|
|
|
|
|
if (Connection->server)
|
|
|
|
|
r = rpcrt4_connect_pipe(Connection, pname);
|
|
|
|
|
else
|
|
|
|
|
r = rpcrt4_open_pipe(Connection, pname, TRUE);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pname);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS rpcrt4_ncacn_np_open(RpcConnection* Connection)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
static LPCSTR prefix = "\\\\.";
|
|
|
|
|
RPC_STATUS r;
|
|
|
|
|
LPSTR pname;
|
|
|
|
|
|
2006-04-21 06:39:41 +00:00
|
|
|
|
/* already connected? */
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (npc->pipe)
|
2006-04-21 06:39:41 +00:00
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
/* protseq=ncacn_np: named pipes */
|
|
|
|
|
pname = HeapAlloc(GetProcessHeap(), 0, strlen(prefix) + strlen(Connection->Endpoint) + 1);
|
|
|
|
|
strcat(strcpy(pname, prefix), Connection->Endpoint);
|
|
|
|
|
if (Connection->server)
|
|
|
|
|
r = rpcrt4_connect_pipe(Connection, pname);
|
|
|
|
|
else
|
|
|
|
|
r = rpcrt4_open_pipe(Connection, pname, FALSE);
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, pname);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 06:40:06 +00:00
|
|
|
|
static HANDLE rpcrt4_conn_np_get_connect_event(RpcConnection *Connection)
|
2006-04-21 06:38:57 +00:00
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
|
|
|
|
return npc->ovl.hEvent;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 06:39:27 +00:00
|
|
|
|
static RPC_STATUS rpcrt4_conn_np_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *old_npc = (RpcConnection_np *) old_conn;
|
|
|
|
|
RpcConnection_np *new_npc = (RpcConnection_np *) new_conn;
|
2006-04-21 06:39:27 +00:00
|
|
|
|
/* because of the way named pipes work, we'll transfer the connected pipe
|
|
|
|
|
* to the child, then reopen the server binding to continue listening */
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
2006-04-21 06:40:06 +00:00
|
|
|
|
new_npc->pipe = old_npc->pipe;
|
|
|
|
|
new_npc->ovl = old_npc->ovl;
|
|
|
|
|
old_npc->pipe = 0;
|
|
|
|
|
memset(&old_npc->ovl, 0, sizeof(old_npc->ovl));
|
2006-04-21 06:39:27 +00:00
|
|
|
|
return RPCRT4_OpenConnection(old_conn);
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
static int rpcrt4_conn_np_read(RpcConnection *Connection,
|
|
|
|
|
void *buffer, unsigned int count)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
DWORD dwRead = 0;
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (!ReadFile(npc->pipe, buffer, count, &dwRead, NULL) &&
|
2006-04-21 06:38:57 +00:00
|
|
|
|
(GetLastError() != ERROR_MORE_DATA))
|
|
|
|
|
return -1;
|
|
|
|
|
return dwRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rpcrt4_conn_np_write(RpcConnection *Connection,
|
|
|
|
|
const void *buffer, unsigned int count)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
DWORD dwWritten = 0;
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (!WriteFile(npc->pipe, buffer, count, &dwWritten, NULL))
|
2006-04-21 06:38:57 +00:00
|
|
|
|
return -1;
|
|
|
|
|
return dwWritten;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rpcrt4_conn_np_close(RpcConnection *Connection)
|
|
|
|
|
{
|
2006-04-21 06:40:06 +00:00
|
|
|
|
RpcConnection_np *npc = (RpcConnection_np *) Connection;
|
|
|
|
|
if (npc->pipe) {
|
|
|
|
|
FlushFileBuffers(npc->pipe);
|
|
|
|
|
CloseHandle(npc->pipe);
|
|
|
|
|
npc->pipe = 0;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
}
|
2006-04-21 06:40:06 +00:00
|
|
|
|
if (npc->ovl.hEvent) {
|
|
|
|
|
CloseHandle(npc->ovl.hEvent);
|
|
|
|
|
npc->ovl.hEvent = 0;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 09:20:16 +00:00
|
|
|
|
/**** ncacn_ip_tcp support ****/
|
|
|
|
|
|
2006-04-21 07:07:35 +00:00
|
|
|
|
typedef struct _RpcConnection_tcp
|
|
|
|
|
{
|
|
|
|
|
RpcConnection common;
|
2006-04-21 09:20:16 +00:00
|
|
|
|
int sock;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
} RpcConnection_tcp;
|
|
|
|
|
|
|
|
|
|
static RpcConnection *rpcrt4_conn_tcp_alloc(void)
|
|
|
|
|
{
|
2006-04-21 09:38:01 +00:00
|
|
|
|
RpcConnection_tcp *tcpc;
|
|
|
|
|
tcpc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(RpcConnection_tcp));
|
|
|
|
|
tcpc->sock = -1;
|
|
|
|
|
return &tcpc->common;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS rpcrt4_ncacn_ip_tcp_open(RpcConnection* Connection)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
|
|
|
|
|
int sock;
|
2006-05-01 09:37:32 +00:00
|
|
|
|
int ret;
|
|
|
|
|
struct addrinfo *ai;
|
|
|
|
|
struct addrinfo *ai_cur;
|
|
|
|
|
struct addrinfo hints;
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
|
|
|
|
TRACE("(%s, %s)\n", Connection->NetworkAddr, Connection->Endpoint);
|
|
|
|
|
|
|
|
|
|
if (Connection->server)
|
|
|
|
|
{
|
|
|
|
|
ERR("ncacn_ip_tcp servers not supported yet\n");
|
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 09:38:01 +00:00
|
|
|
|
if (tcpc->sock != -1)
|
2006-04-21 09:20:16 +00:00
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
|
2006-05-01 09:37:32 +00:00
|
|
|
|
hints.ai_flags = 0;
|
|
|
|
|
hints.ai_family = PF_UNSPEC;
|
|
|
|
|
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(Connection->NetworkAddr, Connection->Endpoint, &hints, &ai);
|
|
|
|
|
if (ret < 0)
|
2006-04-21 09:20:16 +00:00
|
|
|
|
{
|
2006-05-01 09:37:32 +00:00
|
|
|
|
ERR("getaddrinfo failed with %d\n", ret);
|
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
2006-04-21 09:20:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-05-01 09:37:32 +00:00
|
|
|
|
for (ai_cur = ai; ai_cur; ai_cur = ai->ai_next)
|
2006-04-21 09:20:16 +00:00
|
|
|
|
{
|
2006-05-01 09:37:32 +00:00
|
|
|
|
if (TRACE_ON(rpc))
|
|
|
|
|
{
|
|
|
|
|
char host[256];
|
|
|
|
|
char service[256];
|
|
|
|
|
getnameinfo(ai_cur->ai_addr, ai_cur->ai_addrlen,
|
|
|
|
|
host, sizeof(host), service, sizeof(service),
|
|
|
|
|
NI_NUMERICHOST | NI_NUMERICSERV);
|
|
|
|
|
TRACE("trying %s:%s\n", host, service);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sock = socket(ai_cur->ai_family, ai_cur->ai_socktype, ai_cur->ai_protocol);
|
|
|
|
|
if (sock < 0)
|
|
|
|
|
{
|
|
|
|
|
WARN("socket() failed\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
2006-05-01 09:37:32 +00:00
|
|
|
|
if (0>connect(sock, ai_cur->ai_addr, ai_cur->ai_addrlen))
|
|
|
|
|
{
|
|
|
|
|
WARN("connect() failed\n");
|
|
|
|
|
close(sock);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
2006-05-01 09:37:32 +00:00
|
|
|
|
tcpc->sock = sock;
|
|
|
|
|
|
|
|
|
|
freeaddrinfo(ai);
|
|
|
|
|
TRACE("connected\n");
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
2006-04-21 09:20:16 +00:00
|
|
|
|
|
2006-05-01 09:37:32 +00:00
|
|
|
|
freeaddrinfo(ai);
|
|
|
|
|
ERR("couldn't connect to %s:%s\n", Connection->NetworkAddr, Connection->Endpoint);
|
2006-04-21 07:07:35 +00:00
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static HANDLE rpcrt4_conn_tcp_get_wait_handle(RpcConnection *Connection)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
assert(0);
|
|
|
|
|
return 0;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static RPC_STATUS rpcrt4_conn_tcp_handoff(RpcConnection *old_conn, RpcConnection *new_conn)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
assert(0);
|
2006-04-21 07:07:35 +00:00
|
|
|
|
return RPC_S_SERVER_UNAVAILABLE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rpcrt4_conn_tcp_read(RpcConnection *Connection,
|
|
|
|
|
void *buffer, unsigned int count)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
|
|
|
|
|
int r = read(tcpc->sock, buffer, count);
|
|
|
|
|
TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, r);
|
|
|
|
|
return r;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rpcrt4_conn_tcp_write(RpcConnection *Connection,
|
|
|
|
|
const void *buffer, unsigned int count)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
|
|
|
|
|
int r = write(tcpc->sock, buffer, count);
|
|
|
|
|
TRACE("%d %p %u -> %d\n", tcpc->sock, buffer, count, r);
|
|
|
|
|
return r;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int rpcrt4_conn_tcp_close(RpcConnection *Connection)
|
|
|
|
|
{
|
2006-04-21 09:20:16 +00:00
|
|
|
|
RpcConnection_tcp *tcpc = (RpcConnection_tcp *) Connection;
|
|
|
|
|
|
|
|
|
|
TRACE("%d\n", tcpc->sock);
|
2006-04-21 09:38:01 +00:00
|
|
|
|
if (tcpc->sock != -1)
|
2006-04-21 09:20:16 +00:00
|
|
|
|
close(tcpc->sock);
|
2006-04-21 09:38:01 +00:00
|
|
|
|
tcpc->sock = -1;
|
2006-04-21 09:20:16 +00:00
|
|
|
|
return 0;
|
2006-04-21 07:07:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
struct protseq_ops protseq_list[] = {
|
|
|
|
|
{ "ncacn_np",
|
2006-04-21 06:40:06 +00:00
|
|
|
|
rpcrt4_conn_np_alloc,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
rpcrt4_ncalrpc_open,
|
|
|
|
|
rpcrt4_conn_np_get_connect_event,
|
2006-04-21 06:39:27 +00:00
|
|
|
|
rpcrt4_conn_np_handoff,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
rpcrt4_conn_np_read,
|
|
|
|
|
rpcrt4_conn_np_write,
|
|
|
|
|
rpcrt4_conn_np_close,
|
|
|
|
|
},
|
|
|
|
|
{ "ncalrpc",
|
2006-04-21 06:40:06 +00:00
|
|
|
|
rpcrt4_conn_np_alloc,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
rpcrt4_ncacn_np_open,
|
|
|
|
|
rpcrt4_conn_np_get_connect_event,
|
2006-04-21 06:39:27 +00:00
|
|
|
|
rpcrt4_conn_np_handoff,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
rpcrt4_conn_np_read,
|
|
|
|
|
rpcrt4_conn_np_write,
|
|
|
|
|
rpcrt4_conn_np_close,
|
|
|
|
|
},
|
2006-04-21 07:07:35 +00:00
|
|
|
|
{ "ncacn_ip_tcp",
|
|
|
|
|
rpcrt4_conn_tcp_alloc,
|
|
|
|
|
rpcrt4_ncacn_ip_tcp_open,
|
|
|
|
|
rpcrt4_conn_tcp_get_wait_handle,
|
|
|
|
|
rpcrt4_conn_tcp_handoff,
|
|
|
|
|
rpcrt4_conn_tcp_read,
|
|
|
|
|
rpcrt4_conn_tcp_write,
|
|
|
|
|
rpcrt4_conn_tcp_close,
|
|
|
|
|
}
|
2006-04-21 06:38:57 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define MAX_PROTSEQ (sizeof protseq_list / sizeof protseq_list[0])
|
|
|
|
|
|
|
|
|
|
static struct protseq_ops *rpcrt4_get_protseq_ops(const char *protseq)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0; i<MAX_PROTSEQ; i++)
|
|
|
|
|
if (!strcmp(protseq_list[i].name, protseq))
|
|
|
|
|
return &protseq_list[i];
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-21 09:20:16 +00:00
|
|
|
|
/**** interface to rest of code ****/
|
|
|
|
|
|
2006-04-21 06:38:57 +00:00
|
|
|
|
RPC_STATUS RPCRT4_OpenConnection(RpcConnection* Connection)
|
|
|
|
|
{
|
|
|
|
|
TRACE("(Connection == ^%p)\n", Connection);
|
|
|
|
|
|
|
|
|
|
return Connection->ops->open_connection(Connection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPC_STATUS RPCRT4_CloseConnection(RpcConnection* Connection)
|
|
|
|
|
{
|
|
|
|
|
TRACE("(Connection == ^%p)\n", Connection);
|
|
|
|
|
rpcrt4_conn_close(Connection);
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-18 02:40:42 +00:00
|
|
|
|
RPC_STATUS RPCRT4_CreateConnection(RpcConnection** Connection, BOOL server,
|
|
|
|
|
LPCSTR Protseq, LPCSTR NetworkAddr, LPCSTR Endpoint,
|
|
|
|
|
LPCSTR NetworkOptions, RpcAuthInfo* AuthInfo, RpcBinding* Binding)
|
2006-04-21 06:38:57 +00:00
|
|
|
|
{
|
|
|
|
|
struct protseq_ops *ops;
|
|
|
|
|
RpcConnection* NewConnection;
|
|
|
|
|
|
|
|
|
|
ops = rpcrt4_get_protseq_ops(Protseq);
|
|
|
|
|
if (!ops)
|
|
|
|
|
return RPC_S_PROTSEQ_NOT_SUPPORTED;
|
|
|
|
|
|
2006-04-21 06:40:06 +00:00
|
|
|
|
NewConnection = ops->alloc();
|
2006-04-21 06:38:57 +00:00
|
|
|
|
NewConnection->server = server;
|
|
|
|
|
NewConnection->ops = ops;
|
|
|
|
|
NewConnection->NetworkAddr = RPCRT4_strdupA(NetworkAddr);
|
|
|
|
|
NewConnection->Endpoint = RPCRT4_strdupA(Endpoint);
|
|
|
|
|
NewConnection->Used = Binding;
|
|
|
|
|
NewConnection->MaxTransmissionSize = RPC_MAX_PACKET_SIZE;
|
2006-05-18 02:39:42 +00:00
|
|
|
|
NewConnection->NextCallId = 1;
|
2006-05-18 02:40:42 +00:00
|
|
|
|
if (AuthInfo) RpcAuthInfo_AddRef(AuthInfo);
|
|
|
|
|
NewConnection->AuthInfo = AuthInfo;
|
2006-04-21 06:38:57 +00:00
|
|
|
|
|
|
|
|
|
TRACE("connection: %p\n", NewConnection);
|
|
|
|
|
*Connection = NewConnection;
|
|
|
|
|
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPC_STATUS RPCRT4_SpawnConnection(RpcConnection** Connection, RpcConnection* OldConnection)
|
|
|
|
|
{
|
|
|
|
|
RPC_STATUS err;
|
|
|
|
|
|
2006-04-21 06:39:27 +00:00
|
|
|
|
err = RPCRT4_CreateConnection(Connection, OldConnection->server,
|
2006-04-21 06:38:57 +00:00
|
|
|
|
rpcrt4_conn_get_name(OldConnection),
|
|
|
|
|
OldConnection->NetworkAddr,
|
2006-05-18 02:40:42 +00:00
|
|
|
|
OldConnection->Endpoint, NULL,
|
|
|
|
|
OldConnection->AuthInfo, NULL);
|
2006-04-21 06:39:27 +00:00
|
|
|
|
if (err == RPC_S_OK)
|
|
|
|
|
rpcrt4_conn_handoff(OldConnection, *Connection);
|
2006-04-21 06:38:57 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RPC_STATUS RPCRT4_DestroyConnection(RpcConnection* Connection)
|
|
|
|
|
{
|
|
|
|
|
TRACE("connection: %p\n", Connection);
|
|
|
|
|
|
|
|
|
|
RPCRT4_CloseConnection(Connection);
|
|
|
|
|
RPCRT4_strfree(Connection->Endpoint);
|
|
|
|
|
RPCRT4_strfree(Connection->NetworkAddr);
|
2006-05-18 02:40:42 +00:00
|
|
|
|
RpcAuthInfo_Release(Connection->AuthInfo);
|
2006-04-21 06:38:57 +00:00
|
|
|
|
HeapFree(GetProcessHeap(), 0, Connection);
|
|
|
|
|
return RPC_S_OK;
|
|
|
|
|
}
|