ole32: Don't consider RPC_S_UUID_LOCAL_ONLY an error in CoCreateGuid.
[wine/wine64.git] / programs / rpcss / rpcss_main.c
blob99b2d001502882bbcbcd5c424a8b4acd351e62b6
1 /*
2 * Copyright 2001, Ove Kåven, TransGaming Technologies Inc.
3 * Copyright 2002 Greg Turner
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 * ---- rpcss_main.c:
20 * Initialize and start serving requests. Bail if rpcss already is
21 * running.
23 * ---- RPCSS.EXE:
25 * Wine needs a server whose role is somewhat like that
26 * of rpcss.exe in windows. This is not a clone of
27 * windows rpcss at all. It has been given the same name, however,
28 * to provide for the possibility that at some point in the future,
29 * it may become interface compatible with the "real" rpcss.exe on
30 * Windows.
32 * ---- KNOWN BUGS / TODO:
34 * o Service hooks are unimplemented (if you bother to implement
35 * these, also implement net.exe, at least for "net start" and
36 * "net stop" (should be pretty easy I guess, assuming the rest
37 * of the services API infrastructure works.
39 * o Is supposed to use RPC, not random kludges, to map endpoints.
41 * o Probably name services should be implemented here as well.
43 * o Wine's named pipes (in general) may not interoperate with those of
44 * Windows yet (?)
46 * o There is a looming problem regarding listening on privileged
47 * ports. We will need to be able to coexist with SAMBA, and be able
48 * to function without running winelib code as root. This may
49 * take some doing, including significant reconceptualization of the
50 * role of rpcss.exe in wine.
52 * o Who knows? Whatever rpcss does, we ought to at
53 * least think about doing... but what /does/ it do?
56 #include <stdio.h>
57 #include <limits.h>
58 #include <assert.h>
60 #define NONAMELESSUNION
61 #define NONAMELESSSTRUCT
62 #include "rpcss.h"
63 #include "winnt.h"
64 #include "irot.h"
66 #include "wine/debug.h"
68 WINE_DEFAULT_DEBUG_CHANNEL(ole);
70 static HANDLE master_mutex;
71 static HANDLE exit_event;
73 extern HANDLE __wine_make_process_system(void);
75 HANDLE RPCSS_GetMasterMutex(void)
77 return master_mutex;
80 static BOOL RPCSS_work(HANDLE exit_event)
82 return RPCSS_NPDoWork(exit_event);
85 static BOOL RPCSS_Initialize(void)
87 static unsigned short irot_protseq[] = IROT_PROTSEQ;
88 static unsigned short irot_endpoint[] = IROT_ENDPOINT;
89 RPC_STATUS status;
91 WINE_TRACE("\n");
93 exit_event = __wine_make_process_system();
95 master_mutex = CreateMutexA( NULL, FALSE, RPCSS_MASTER_MUTEX_NAME);
96 if (!master_mutex) {
97 WINE_ERR("Failed to create master mutex\n");
98 return FALSE;
101 if (!RPCSS_BecomePipeServer()) {
102 WINE_WARN("Server already running: exiting.\n");
104 CloseHandle(master_mutex);
105 master_mutex = NULL;
107 return FALSE;
110 status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
111 irot_endpoint, NULL);
112 if (status == RPC_S_OK)
113 status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
114 if (status == RPC_S_OK)
115 status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
116 else
117 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
119 return status == RPC_S_OK;
122 /* returns false if we discover at the last moment that we
123 aren't ready to terminate */
124 static BOOL RPCSS_Shutdown(void)
126 if (!RPCSS_UnBecomePipeServer())
127 return FALSE;
129 if (!CloseHandle(master_mutex))
130 WINE_WARN("Failed to release master mutex\n");
132 master_mutex = NULL;
134 RpcMgmtStopServerListening(NULL);
135 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, TRUE);
137 CloseHandle(exit_event);
139 return TRUE;
142 static void RPCSS_MainLoop(void)
144 WINE_TRACE("\n");
146 while ( RPCSS_work(exit_event) )
150 int main( int argc, char **argv )
153 * We are invoked as a standard executable; we act in a
154 * "lazy" manner. We open up our pipe, and hang around until we all
155 * user processes exit, and then silently terminate.
158 if (RPCSS_Initialize()) {
159 RPCSS_MainLoop();
160 RPCSS_Shutdown();
163 return 0;