2002-12-02 22:17:04 +01:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2001, Ove K<EFBFBD>ven, TransGaming Technologies Inc.
|
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
|
* ---- rpcss_main.c:
|
|
|
|
|
* Initialize and start serving requests. Bail if rpcss already is
|
|
|
|
|
* running.
|
|
|
|
|
*
|
|
|
|
|
* ---- RPCSS.EXE:
|
|
|
|
|
*
|
|
|
|
|
* Wine needs a server whose role is somewhat like that
|
|
|
|
|
* of rpcss.exe in windows. This is not a clone of
|
|
|
|
|
* windows rpcss at all. It has been given the same name, however,
|
|
|
|
|
* to provide for the possibility that at some point in the future,
|
|
|
|
|
* it may become interface compatible with the "real" rpcss.exe on
|
|
|
|
|
* Windows.
|
|
|
|
|
*
|
|
|
|
|
* ---- KNOWN BUGS / TODO:
|
|
|
|
|
*
|
|
|
|
|
* o Service hooks are unimplemented (if you bother to implement
|
|
|
|
|
* these, also implement net.exe, at least for "net start" and
|
|
|
|
|
* "net stop" (should be pretty easy I guess, assuming the rest
|
|
|
|
|
* of the services API infrastructure works.
|
|
|
|
|
*
|
|
|
|
|
* o Is supposed to use RPC, not random kludges, to map endpoints.
|
|
|
|
|
*
|
|
|
|
|
* o Probably name services should be implemented here as well.
|
|
|
|
|
*
|
|
|
|
|
* o Wine's named pipes (in general) may not interoperate with those of
|
|
|
|
|
* Windows yet (?)
|
|
|
|
|
*
|
2003-05-13 02:41:57 +02:00
|
|
|
|
* o There is a looming problem regarding listening on privileged
|
|
|
|
|
* ports. We will need to be able to coexist with SAMBA, and be able
|
2002-12-02 22:17:04 +01:00
|
|
|
|
* to function without running winelib code as root. This may
|
|
|
|
|
* take some doing, including significant reconceptualization of the
|
|
|
|
|
* role of rpcss.exe in wine.
|
|
|
|
|
*
|
|
|
|
|
* o Who knows? Whatever rpcss does, we ought to at
|
|
|
|
|
* least think about doing... but what /does/ it do?
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2003-01-08 00:11:12 +01:00
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
#define NONAMELESSSTRUCT
|
2002-12-02 22:17:04 +01:00
|
|
|
|
#include "rpcss.h"
|
|
|
|
|
#include "winnt.h"
|
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ole);
|
|
|
|
|
|
|
|
|
|
static HANDLE master_mutex;
|
2007-06-19 14:12:07 +02:00
|
|
|
|
static HANDLE exit_event;
|
|
|
|
|
|
|
|
|
|
extern HANDLE __wine_make_process_system(void);
|
2002-12-02 22:17:04 +01:00
|
|
|
|
|
|
|
|
|
HANDLE RPCSS_GetMasterMutex(void)
|
|
|
|
|
{
|
|
|
|
|
return master_mutex;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-19 14:12:07 +02:00
|
|
|
|
static BOOL RPCSS_work(HANDLE exit_event)
|
2002-12-02 22:17:04 +01:00
|
|
|
|
{
|
2007-06-19 14:12:07 +02:00
|
|
|
|
return RPCSS_NPDoWork(exit_event);
|
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
|
|
|
|
{
|
|
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
|
2007-06-19 14:12:07 +02:00
|
|
|
|
exit_event = __wine_make_process_system();
|
|
|
|
|
|
2002-12-02 22:17:04 +01:00
|
|
|
|
master_mutex = CreateMutexA( NULL, FALSE, RPCSS_MASTER_MUTEX_NAME);
|
|
|
|
|
if (!master_mutex) {
|
|
|
|
|
WINE_ERR("Failed to create master mutex\n");
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!RPCSS_BecomePipeServer()) {
|
|
|
|
|
WINE_WARN("Server already running: exiting.\n");
|
|
|
|
|
|
|
|
|
|
CloseHandle(master_mutex);
|
|
|
|
|
master_mutex = NULL;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* returns false if we discover at the last moment that we
|
|
|
|
|
aren't ready to terminate */
|
2005-06-04 12:01:25 +02:00
|
|
|
|
static BOOL RPCSS_Shutdown(void)
|
2002-12-02 22:17:04 +01:00
|
|
|
|
{
|
|
|
|
|
if (!RPCSS_UnBecomePipeServer())
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
if (!CloseHandle(master_mutex))
|
|
|
|
|
WINE_WARN("Failed to release master mutex\n");
|
|
|
|
|
|
2003-01-15 00:43:41 +01:00
|
|
|
|
master_mutex = NULL;
|
2002-12-02 22:17:04 +01:00
|
|
|
|
|
2007-06-19 14:12:07 +02:00
|
|
|
|
CloseHandle(exit_event);
|
|
|
|
|
|
2002-12-02 22:17:04 +01:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
|
static void RPCSS_MainLoop(void)
|
2002-12-02 22:17:04 +01:00
|
|
|
|
{
|
|
|
|
|
WINE_TRACE("\n");
|
|
|
|
|
|
2007-06-19 14:12:07 +02:00
|
|
|
|
while ( RPCSS_work(exit_event) )
|
|
|
|
|
;
|
2002-12-02 22:17:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main( int argc, char **argv )
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* We are invoked as a standard executable; we act in a
|
2007-06-19 14:12:07 +02:00
|
|
|
|
* "lazy" manner. We open up our pipe, and hang around until we all
|
|
|
|
|
* user processes exit, and then silently terminate.
|
2002-12-02 22:17:04 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (RPCSS_Initialize()) {
|
2007-06-19 14:12:07 +02:00
|
|
|
|
RPCSS_MainLoop();
|
|
|
|
|
RPCSS_Shutdown();
|
2002-12-02 22:17:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|