*/
#include "precomp.h"
+
+#include <winsvc.h>
+
#include "epm_towers.h"
WINE_DEFAULT_DEBUG_CHANNEL(ole);
static BOOL start_rpcss(void)
{
- PROCESS_INFORMATION pi;
- STARTUPINFOW si;
- WCHAR cmd[MAX_PATH];
- static const WCHAR rpcss[] = {'\\','r','p','c','s','s','.','e','x','e',0};
- BOOL rslt;
- void *redir;
+ static const WCHAR rpcssW[] = {'R','p','c','S','s',0};
+ SC_HANDLE scm, service;
+ SERVICE_STATUS_PROCESS status;
+ BOOL ret = FALSE;
TRACE("\n");
- ZeroMemory(&si, sizeof(STARTUPINFOA));
- si.cb = sizeof(STARTUPINFOA);
- GetSystemDirectoryW( cmd, MAX_PATH - sizeof(rpcss)/sizeof(WCHAR) );
- lstrcatW( cmd, rpcss );
-
- Wow64DisableWow64FsRedirection( &redir );
- rslt = CreateProcessW( cmd, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi );
- Wow64RevertWow64FsRedirection( redir );
-
- if (rslt)
+ if (!(scm = OpenSCManagerW( NULL, NULL, 0 )))
+ {
+ ERR( "failed to open service manager\n" );
+ return FALSE;
+ }
+ if (!(service = OpenServiceW( scm, rpcssW, SERVICE_START | SERVICE_QUERY_STATUS )))
+ {
+ ERR( "failed to open RpcSs service\n" );
+ CloseServiceHandle( scm );
+ return FALSE;
+ }
+ if (StartServiceW( service, 0, NULL ) || GetLastError() == ERROR_SERVICE_ALREADY_RUNNING)
{
- CloseHandle(pi.hProcess);
- CloseHandle(pi.hThread);
- Sleep(100);
+ ULONGLONG start_time = GetTickCount64();
+ do
+ {
+ DWORD dummy;
+
+ if (!QueryServiceStatusEx( service, SC_STATUS_PROCESS_INFO,
+ (BYTE *)&status, sizeof(status), &dummy ))
+ break;
+ if (status.dwCurrentState == SERVICE_RUNNING)
+ {
+ ret = TRUE;
+ break;
+ }
+ if (GetTickCount64() - start_time > 30000) break;
+ Sleep( 100 );
+
+ } while (status.dwCurrentState == SERVICE_START_PENDING);
+
+ if (status.dwCurrentState != SERVICE_RUNNING)
+ WARN( "RpcSs failed to start %u\n", status.dwCurrentState );
}
+ else ERR( "failed to start RpcSs service\n" );
- return rslt;
+ CloseServiceHandle( service );
+ CloseServiceHandle( scm );
+ return ret;
}
static inline BOOL is_epm_destination_local(RPC_BINDING_HANDLE handle)
static RPC_STATUS rpcrt4_ncalrpc_open(RpcConnection* Connection)
{
RpcConnection_np *npc = (RpcConnection_np *) Connection;
- static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
RPC_STATUS r;
LPSTR pname;
if (npc->pipe)
return RPC_S_OK;
- /* protseq=ncalrpc: supposed to use NT LPC ports,
- * but we'll implement it with named pipes for now */
- pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
- strcat(strcpy(pname, prefix), Connection->Endpoint);
+ pname = ncalrpc_pipe_name(Connection->Endpoint);
r = rpcrt4_conn_open_pipe(Connection, pname, TRUE);
I_RpcFree(pname);
static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq, const char *endpoint)
{
- static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
RPC_STATUS r;
LPSTR pname;
RpcConnection *Connection;
if (r != RPC_S_OK)
return r;
- /* protseq=ncalrpc: supposed to use NT LPC ports,
- * but we'll implement it with named pipes for now */
- pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
- strcat(strcpy(pname, prefix), Connection->Endpoint);
+ pname = ncalrpc_pipe_name(Connection->Endpoint);
r = rpcrt4_conn_create_pipe(Connection, pname);
I_RpcFree(pname);
static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protseq, const char *endpoint)
{
- static const char prefix[] = "\\\\.";
RPC_STATUS r;
LPSTR pname;
RpcConnection *Connection;
if (r != RPC_S_OK)
return r;
- /* protseq=ncacn_np: named pipes */
- pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
- strcat(strcpy(pname, prefix), Connection->Endpoint);
+ pname = ncacn_pipe_name(Connection->Endpoint);
r = rpcrt4_conn_create_pipe(Connection, pname);
I_RpcFree(pname);
DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
RPC_STATUS status;
LPSTR pname;
- static const char prefix[] = "\\\\.";
rpcrt4_conn_np_handoff((RpcConnection_np *)old_conn, (RpcConnection_np *)new_conn);
- pname = I_RpcAllocate(strlen(prefix) + strlen(old_conn->Endpoint) + 1);
- strcat(strcpy(pname, prefix), old_conn->Endpoint);
+ pname = ncacn_pipe_name(old_conn->Endpoint);
status = rpcrt4_conn_create_pipe(old_conn, pname);
I_RpcFree(pname);
DWORD len = MAX_COMPUTERNAME_LENGTH + 1;
RPC_STATUS status;
LPSTR pname;
- static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
TRACE("%s\n", old_conn->Endpoint);
rpcrt4_conn_np_handoff((RpcConnection_np *)old_conn, (RpcConnection_np *)new_conn);
- pname = I_RpcAllocate(strlen(prefix) + strlen(old_conn->Endpoint) + 1);
- strcat(strcpy(pname, prefix), old_conn->Endpoint);
+ pname = ncalrpc_pipe_name(old_conn->Endpoint);
status = rpcrt4_conn_create_pipe(old_conn, pname);
I_RpcFree(pname);
-diff -pudN --strip-trailing-cr e:\wine\dlls\rpcrt4/cproxy.c e:\reactos\dll\win32\rpcrt4/cproxy.c
---- e:\wine\dlls\rpcrt4/cproxy.c 2016-05-31 18:02:22 +0100
+diff -pudN e:\wine\dlls\rpcrt4/cproxy.c e:\reactos\dll\win32\rpcrt4/cproxy.c
+--- e:\wine\dlls\rpcrt4/cproxy.c 2016-11-16 17:29:34 +0100
+++ e:\reactos\dll\win32\rpcrt4/cproxy.c 2015-08-27 22:03:34 +0100
@@ -150,6 +150,30 @@ static inline void init_thunk( struct th
thunk->call_stubless = call_stubless_func;
#else /* __i386__ */
#warning You must implement stubless proxies for your CPU
-diff -pudN --strip-trailing-cr e:\wine\dlls\rpcrt4/cstub.c e:\reactos\dll\win32\rpcrt4/cstub.c
---- e:\wine\dlls\rpcrt4/cstub.c 2016-05-31 18:02:22 +0100
+diff -pudN e:\wine\dlls\rpcrt4/cstub.c e:\reactos\dll\win32\rpcrt4/cstub.c
+--- e:\wine\dlls\rpcrt4/cstub.c 2016-11-16 17:29:34 +0100
+++ e:\reactos\dll\win32\rpcrt4/cstub.c 2016-05-20 23:26:31 +0100
@@ -156,6 +156,13 @@ typedef struct
#else
#warning You must implement delegated proxies/stubs for your CPU
-diff -pudN --strip-trailing-cr e:\wine\dlls\rpcrt4/rpc_epmap.c e:\reactos\dll\win32\rpcrt4/rpc_epmap.c
---- e:\wine\dlls\rpcrt4/rpc_epmap.c 2016-05-31 18:02:22 +0100
-+++ e:\reactos\dll\win32\rpcrt4/rpc_epmap.c 2015-11-16 22:55:50 +0100
-@@ -150,7 +150,7 @@ static RPC_STATUS get_epm_handle_server(
+
+diff -pudN e:\wine\dlls\rpcrt4/rpc_epmap.c e:\reactos\dll\win32\rpcrt4/rpc_epmap.c
+--- e:\wine\dlls\rpcrt4/rpc_epmap.c 2016-11-16 17:29:34 +0100
++++ e:\reactos\dll\win32\rpcrt4/rpc_epmap.c 2016-11-17 12:09:06 +0100
+@@ -171,7 +173,7 @@ static RPC_STATUS get_epm_handle_server(
static LONG WINAPI rpc_filter(EXCEPTION_POINTERS *__eptr)
{
{
case EXCEPTION_ACCESS_VIOLATION:
case EXCEPTION_ILLEGAL_INSTRUCTION:
-diff -pudN --strip-trailing-cr e:\wine\dlls\rpcrt4/rpc_transport.c e:\reactos\dll\win32\rpcrt4/rpc_transport.c
---- e:\wine\dlls\rpcrt4/rpc_transport.c 2016-05-31 18:02:23 +0100
-+++ e:\reactos\dll\win32\rpcrt4/rpc_transport.c 2015-11-16 22:55:50 +0100
-@@ -79,6 +79,7 @@
+diff -pudN e:\wine\dlls\rpcrt4/rpc_transport.c e:\reactos\dll\win32\rpcrt4/rpc_transport.c
+--- e:\wine\dlls\rpcrt4/rpc_transport.c 2016-11-16 17:33:13 +0100
++++ e:\reactos\dll\win32\rpcrt4/rpc_transport.c 2016-11-17 00:00:46 +0100
+@@ -82,6 +79,7 @@
#define DEFAULT_NCACN_HTTP_TIMEOUT (60 * 1000)
#define ARRAYSIZE(a) (sizeof((a)) / sizeof((a)[0]))
WINE_DEFAULT_DEBUG_CHANNEL(rpc);
-@@ -91,31 +92,41 @@ typedef struct _RpcConnection_np
+@@ -94,31 +92,41 @@ typedef struct _RpcConnection_np
{
RpcConnection common;
HANDLE pipe;
case ERROR_NO_DATA_DETECTED:
/* client has disconnected, retry */
DisconnectNamedPipe( npc->pipe );
-@@ -128,6 +139,7 @@ static DWORD CALLBACK listen_thread(void
+@@ -131,6 +139,7 @@ static DWORD CALLBACK listen_thread(void
}
}
static RPC_STATUS rpcrt4_conn_listen_pipe(RpcConnection_np *npc)
{
if (npc->listening)
-@@ -143,13 +155,14 @@ static RPC_STATUS rpcrt4_conn_listen_pip
+@@ -146,13 +155,14 @@ static RPC_STATUS rpcrt4_conn_listen_pip
}
return RPC_S_OK;
}
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE,
PIPE_UNLIMITED_INSTANCES,
RPC_MAX_PACKET_SIZE, RPC_MAX_PACKET_SIZE, 5000, NULL);
-@@ -161,6 +174,9 @@ static RPC_STATUS rpcrt4_conn_create_pip
+@@ -164,6 +174,9 @@ static RPC_STATUS rpcrt4_conn_create_pip
return RPC_S_CANT_CREATE_ENDPOINT;
}
/* Note: we don't call ConnectNamedPipe here because it must be done in the
* server thread as the thread must be alertable */
return RPC_S_OK;
-@@ -207,6 +223,9 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
+@@ -210,6 +223,9 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
if (err == ERROR_PIPE_BUSY) {
TRACE("connection failed, error=%x\n", err);
return RPC_S_SERVER_TOO_BUSY;
}
if (!wait || !WaitNamedPipeA(pname, NMPWAIT_WAIT_FOREVER)) {
err = GetLastError();
-@@ -216,9 +235,11 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
+@@ -219,9 +235,11 @@ static RPC_STATUS rpcrt4_conn_open_pipe(
}
/* success */
npc->pipe = pipe;
return RPC_S_OK;
-@@ -239,6 +260,7 @@ static char *ncalrpc_pipe_name(const cha
- static RPC_STATUS rpcrt4_ncalrpc_open(RpcConnection* Connection)
- {
- RpcConnection_np *npc = (RpcConnection_np *) Connection;
-+ static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
- RPC_STATUS r;
- LPSTR pname;
-
-@@ -246,7 +268,10 @@ static RPC_STATUS rpcrt4_ncalrpc_open(Rp
- if (npc->pipe)
- return RPC_S_OK;
-
-- pname = ncalrpc_pipe_name(Connection->Endpoint);
-+ /* protseq=ncalrpc: supposed to use NT LPC ports,
-+ * but we'll implement it with named pipes for now */
-+ pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
-+ strcat(strcpy(pname, prefix), Connection->Endpoint);
- r = rpcrt4_conn_open_pipe(Connection, pname, TRUE);
- I_RpcFree(pname);
-
-@@ -255,6 +280,7 @@ static RPC_STATUS rpcrt4_ncalrpc_open(Rp
-
- static RPC_STATUS rpcrt4_protseq_ncalrpc_open_endpoint(RpcServerProtseq* protseq, const char *endpoint)
- {
-+ static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
- RPC_STATUS r;
- LPSTR pname;
- RpcConnection *Connection;
-@@ -275,7 +301,10 @@ static RPC_STATUS rpcrt4_protseq_ncalrpc
- if (r != RPC_S_OK)
- return r;
-
-- pname = ncalrpc_pipe_name(Connection->Endpoint);
-+ /* protseq=ncalrpc: supposed to use NT LPC ports,
-+ * but we'll implement it with named pipes for now */
-+ pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
-+ strcat(strcpy(pname, prefix), Connection->Endpoint);
- r = rpcrt4_conn_create_pipe(Connection, pname);
- I_RpcFree(pname);
-
-@@ -301,15 +330,64 @@ static char *ncacn_pipe_name(const char
+@@ -304,15 +322,64 @@ static char *ncacn_pipe_name(const char
static RPC_STATUS rpcrt4_ncacn_np_open(RpcConnection* Connection)
{
RpcConnection_np *npc = (RpcConnection_np *) Connection;
I_RpcFree(pname);
return r;
-@@ -317,6 +395,7 @@ static RPC_STATUS rpcrt4_ncacn_np_open(R
-
- static RPC_STATUS rpcrt4_protseq_ncacn_np_open_endpoint(RpcServerProtseq *protseq, const char *endpoint)
- {
-+ static const char prefix[] = "\\\\.";
- RPC_STATUS r;
- LPSTR pname;
- RpcConnection *Connection;
-@@ -337,7 +416,9 @@ static RPC_STATUS rpcrt4_protseq_ncacn_n
- if (r != RPC_S_OK)
- return r;
-
-- pname = ncacn_pipe_name(Connection->Endpoint);
-+ /* protseq=ncacn_np: named pipes */
-+ pname = I_RpcAllocate(strlen(prefix) + strlen(Connection->Endpoint) + 1);
-+ strcat(strcpy(pname, prefix), Connection->Endpoint);
- r = rpcrt4_conn_create_pipe(Connection, pname);
- I_RpcFree(pname);
-
-@@ -355,9 +436,9 @@ static void rpcrt4_conn_np_handoff(RpcCo
+@@ -358,9 +425,9 @@ static void rpcrt4_conn_np_handoff(RpcCo
* to the child, then reopen the server binding to continue listening */
new_npc->pipe = old_npc->pipe;
old_npc->listening = FALSE;
}
-@@ -365,10 +446,12 @@ static RPC_STATUS rpcrt4_ncacn_np_handof
- {
- RPC_STATUS status;
- LPSTR pname;
-+ static const char prefix[] = "\\\\.";
-
- rpcrt4_conn_np_handoff((RpcConnection_np *)old_conn, (RpcConnection_np *)new_conn);
-
-- pname = ncacn_pipe_name(old_conn->Endpoint);
-+ pname = I_RpcAllocate(strlen(prefix) + strlen(old_conn->Endpoint) + 1);
-+ strcat(strcpy(pname, prefix), old_conn->Endpoint);
- status = rpcrt4_conn_create_pipe(old_conn, pname);
- I_RpcFree(pname);
-
-@@ -406,12 +489,14 @@ static RPC_STATUS rpcrt4_ncalrpc_handoff
+@@ -444,20 +511,29 @@ static int rpcrt4_conn_np_read(RpcConnec
+ void *buffer, unsigned int count)
{
- RPC_STATUS status;
- LPSTR pname;
-+ static const char prefix[] = "\\\\.\\pipe\\lrpc\\";
-
- TRACE("%s\n", old_conn->Endpoint);
-
- rpcrt4_conn_np_handoff((RpcConnection_np *)old_conn, (RpcConnection_np *)new_conn);
-
-- pname = ncalrpc_pipe_name(old_conn->Endpoint);
-+ pname = I_RpcAllocate(strlen(prefix) + strlen(old_conn->Endpoint) + 1);
-+ strcat(strcpy(pname, prefix), old_conn->Endpoint);
- status = rpcrt4_conn_create_pipe(old_conn, pname);
- I_RpcFree(pname);
-
-@@ -425,12 +510,17 @@ static int rpcrt4_conn_np_read(RpcConnec
+ RpcConnection_np *npc = (RpcConnection_np *) Connection;
+- IO_STATUS_BLOCK io_status;
char *buf = buffer;
- BOOL ret = TRUE;
++ BOOL ret = TRUE;
unsigned int bytes_left = count;
-- DWORD err = GetLastError();
+- NTSTATUS status;
+ OVERLAPPED ovl;
+
+ ZeroMemory(&ovl, sizeof(ovl));
while (bytes_left)
{
- DWORD bytes_read;
-- ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, NULL);
+- status = NtReadFile(npc->pipe, NULL, NULL, NULL, &io_status, buf, bytes_left, NULL, NULL);
+- if (status && status != STATUS_BUFFER_OVERFLOW)
+- return -1;
+- bytes_left -= io_status.Information;
+- buf += io_status.Information;
++ DWORD bytes_read;
+ ret = ReadFile(npc->pipe, buf, bytes_left, &bytes_read, &ovl);
+ if (!ret && GetLastError() == ERROR_IO_PENDING)
+ ret = GetOverlappedResult(npc->pipe, &ovl, &bytes_read, TRUE);
- if (!ret && GetLastError() == ERROR_MORE_DATA)
- ret = TRUE;
- if (!ret || !bytes_read)
-@@ -438,7 +528,7 @@ static int rpcrt4_conn_np_read(RpcConnec
- bytes_left -= bytes_read;
- buf += bytes_read;
++ if (!ret && GetLastError() == ERROR_MORE_DATA)
++ ret = TRUE;
++ if (!ret || !bytes_read)
++ break;
++ bytes_left -= bytes_read;
++ buf += bytes_read;
}
-- if (ret) SetLastError(err);
+- return count;
+ CloseHandle(ovl.hEvent);
- return ret ? count : -1;
++ return ret ? count : -1;
}
-@@ -449,16 +539,23 @@ static int rpcrt4_conn_np_write(RpcConne
+ static int rpcrt4_conn_np_write(RpcConnection *Connection,
+@@ -467,16 +543,23 @@ static int rpcrt4_conn_np_write(RpcConne
const char *buf = buffer;
BOOL ret = TRUE;
unsigned int bytes_left = count;
return ret ? count : -1;
}
-@@ -470,9 +567,9 @@ static int rpcrt4_conn_np_close(RpcConne
+@@ -488,9 +571,9 @@ static int rpcrt4_conn_np_close(RpcConne
CloseHandle(npc->pipe);
npc->pipe = 0;
}
}
return 0;
}
-@@ -676,7 +773,7 @@ static void *rpcrt4_protseq_np_get_wait_
+@@ -694,7 +777,7 @@ static void *rpcrt4_protseq_np_get_wait_
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
while (conn) {
rpcrt4_conn_listen_pipe(conn);
(*count)++;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
}
-@@ -697,7 +794,7 @@ static void *rpcrt4_protseq_np_get_wait_
+@@ -715,7 +798,7 @@ static void *rpcrt4_protseq_np_get_wait_
*count = 1;
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
while (conn) {
(*count)++;
conn = CONTAINING_RECORD(conn->common.Next, RpcConnection_np, common);
}
-@@ -744,18 +841,12 @@ static int rpcrt4_protseq_np_wait_for_ne
+@@ -762,18 +845,12 @@ static int rpcrt4_protseq_np_wait_for_ne
EnterCriticalSection(&protseq->cs);
conn = CONTAINING_RECORD(protseq->conn, RpcConnection_np, common);
while (conn) {