2002-12-02 22:17:04 +01:00
|
|
|
/*
|
2008-10-18 19:22:19 +02:00
|
|
|
* Copyright 2001, Ove Kåven, TransGaming Technologies Inc.
|
2002-12-02 22:17:04 +01:00
|
|
|
* Copyright 2002 Greg Turner
|
|
|
|
*
|
|
|
|
* 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-12-02 22:17:04 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-12-03 16:41:39 +01:00
|
|
|
#include <stdarg.h>
|
2002-12-02 22:17:04 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2008-12-03 16:41:39 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2002-12-02 22:17:04 +01:00
|
|
|
#include "winnt.h"
|
2016-08-31 15:21:17 +02:00
|
|
|
#include "winsvc.h"
|
2007-09-10 17:10:45 +02:00
|
|
|
#include "irot.h"
|
2008-06-25 19:26:48 +02:00
|
|
|
#include "epm.h"
|
2002-12-02 22:17:04 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
2016-08-31 15:21:17 +02:00
|
|
|
static WCHAR rpcssW[] = {'R','p','c','S','s',0};
|
2007-06-19 14:12:07 +02:00
|
|
|
static HANDLE exit_event;
|
2016-08-31 15:21:17 +02:00
|
|
|
static SERVICE_STATUS_HANDLE service_handle;
|
2002-12-02 22:17:04 +01:00
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static BOOL RPCSS_Initialize(void)
|
2002-12-02 22:17:04 +01:00
|
|
|
{
|
2007-09-10 17:10:45 +02:00
|
|
|
static unsigned short irot_protseq[] = IROT_PROTSEQ;
|
|
|
|
static unsigned short irot_endpoint[] = IROT_ENDPOINT;
|
2008-06-25 19:26:48 +02:00
|
|
|
static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0};
|
|
|
|
static unsigned short epm_endpoint[] = {'\\','p','i','p','e','\\','e','p','m','a','p','p','e','r',0};
|
2008-08-10 19:24:09 +02:00
|
|
|
static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0};
|
|
|
|
static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0};
|
2007-09-10 17:10:45 +02:00
|
|
|
RPC_STATUS status;
|
|
|
|
|
2002-12-02 22:17:04 +01:00
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
2008-06-25 19:26:48 +02:00
|
|
|
status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
return status;
|
|
|
|
status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
{
|
|
|
|
RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
|
|
|
|
epm_endpoint, NULL);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
goto fail;
|
|
|
|
|
2008-08-10 19:24:09 +02:00
|
|
|
status = RpcServerUseProtseqEpW(epm_protseq_lrpc, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
|
|
|
|
epm_endpoint_lrpc, NULL);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
goto fail;
|
|
|
|
|
2007-09-10 17:10:45 +02:00
|
|
|
status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
|
|
|
|
irot_endpoint, NULL);
|
2008-06-25 19:26:48 +02:00
|
|
|
if (status != RPC_S_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
|
|
|
|
if (status != RPC_S_OK)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
|
|
|
|
RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
|
|
|
|
return FALSE;
|
2002-12-02 22:17:04 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 15:21:17 +02:00
|
|
|
static DWORD WINAPI service_handler( DWORD ctrl, DWORD event_type, LPVOID event_data, LPVOID context )
|
|
|
|
{
|
|
|
|
SERVICE_STATUS status;
|
|
|
|
|
|
|
|
status.dwServiceType = SERVICE_WIN32;
|
|
|
|
status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
|
|
|
status.dwWin32ExitCode = 0;
|
|
|
|
status.dwServiceSpecificExitCode = 0;
|
|
|
|
status.dwCheckPoint = 0;
|
|
|
|
status.dwWaitHint = 0;
|
|
|
|
|
|
|
|
switch (ctrl)
|
|
|
|
{
|
|
|
|
case SERVICE_CONTROL_STOP:
|
|
|
|
case SERVICE_CONTROL_SHUTDOWN:
|
|
|
|
TRACE( "shutting down\n" );
|
|
|
|
RpcMgmtStopServerListening( NULL );
|
|
|
|
RpcServerUnregisterIf( epm_v3_0_s_ifspec, NULL, TRUE );
|
|
|
|
RpcServerUnregisterIf( Irot_v0_2_s_ifspec, NULL, TRUE );
|
|
|
|
status.dwCurrentState = SERVICE_STOP_PENDING;
|
|
|
|
status.dwControlsAccepted = 0;
|
|
|
|
SetServiceStatus( service_handle, &status );
|
|
|
|
SetEvent( exit_event );
|
|
|
|
return NO_ERROR;
|
|
|
|
default:
|
|
|
|
FIXME( "got service ctrl %x\n", ctrl );
|
|
|
|
status.dwCurrentState = SERVICE_RUNNING;
|
|
|
|
SetServiceStatus( service_handle, &status );
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void WINAPI ServiceMain( DWORD argc, LPWSTR *argv )
|
2002-12-02 22:17:04 +01:00
|
|
|
{
|
2016-08-31 15:21:17 +02:00
|
|
|
SERVICE_STATUS status;
|
2007-09-10 17:10:45 +02:00
|
|
|
|
2016-08-31 15:21:17 +02:00
|
|
|
TRACE( "starting service\n" );
|
2007-06-19 14:12:07 +02:00
|
|
|
|
2016-08-31 15:21:17 +02:00
|
|
|
if (!RPCSS_Initialize()) return;
|
|
|
|
|
|
|
|
exit_event = CreateEventW( NULL, TRUE, FALSE, NULL );
|
|
|
|
|
|
|
|
service_handle = RegisterServiceCtrlHandlerExW( rpcssW, service_handler, NULL );
|
|
|
|
if (!service_handle) return;
|
|
|
|
|
|
|
|
status.dwServiceType = SERVICE_WIN32;
|
|
|
|
status.dwCurrentState = SERVICE_RUNNING;
|
|
|
|
status.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
|
|
|
|
status.dwWin32ExitCode = 0;
|
|
|
|
status.dwServiceSpecificExitCode = 0;
|
|
|
|
status.dwCheckPoint = 0;
|
|
|
|
status.dwWaitHint = 10000;
|
|
|
|
SetServiceStatus( service_handle, &status );
|
|
|
|
|
|
|
|
WaitForSingleObject( exit_event, INFINITE );
|
|
|
|
|
|
|
|
status.dwCurrentState = SERVICE_STOPPED;
|
|
|
|
status.dwControlsAccepted = 0;
|
|
|
|
SetServiceStatus( service_handle, &status );
|
|
|
|
TRACE( "service stopped\n" );
|
2002-12-02 22:17:04 +01:00
|
|
|
}
|
|
|
|
|
2016-08-31 15:21:17 +02:00
|
|
|
int wmain( int argc, WCHAR *argv[] )
|
2002-12-02 22:17:04 +01:00
|
|
|
{
|
2016-08-31 15:21:17 +02:00
|
|
|
static const SERVICE_TABLE_ENTRYW service_table[] =
|
|
|
|
{
|
|
|
|
{ rpcssW, ServiceMain },
|
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
StartServiceCtrlDispatcherW( service_table );
|
|
|
|
return 0;
|
2002-12-02 22:17:04 +01:00
|
|
|
}
|