Sync with trunk r63192.
[reactos.git] / base / services / rpcss / rpcss_main.c
1 /*
2 * Copyright 2001, Ove Kåven, TransGaming Technologies Inc.
3 * Copyright 2002 Greg Turner
4 *
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.
9 *
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.
14 *
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
18 *
19 * ---- rpcss_main.c:
20 * Initialize and start serving requests. Bail if rpcss already is
21 * running.
22 *
23 * ---- RPCSS.EXE:
24 *
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.
31 *
32 * ---- KNOWN BUGS / TODO:
33 *
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.
38 *
39 * o There is a looming problem regarding listening on privileged
40 * ports. We will need to be able to coexist with SAMBA, and be able
41 * to function without running winelib code as root. This may
42 * take some doing, including significant reconceptualization of the
43 * role of rpcss.exe in wine.
44 */
45
46 #include "rpcss.h"
47
48 #include <wine/debug.h>
49
50 WINE_DEFAULT_DEBUG_CHANNEL(ole);
51
52 HANDLE exit_event;
53
54 //extern HANDLE __wine_make_process_system(void);
55
56 BOOL RPCSS_Initialize(void)
57 {
58 static unsigned short irot_protseq[] = IROT_PROTSEQ;
59 static unsigned short irot_endpoint[] = IROT_ENDPOINT;
60 static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0};
61 static unsigned short epm_endpoint[] = {'\\','p','i','p','e','\\','e','p','m','a','p','p','e','r',0};
62 static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0};
63 static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0};
64 RPC_STATUS status;
65
66 WINE_TRACE("\n");
67
68 status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL);
69 if (status != RPC_S_OK)
70 return status;
71 status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
72 if (status != RPC_S_OK)
73 {
74 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
75 return FALSE;
76 }
77
78 status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
79 epm_endpoint, NULL);
80 if (status != RPC_S_OK)
81 goto fail;
82
83 status = RpcServerUseProtseqEpW(epm_protseq_lrpc, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
84 epm_endpoint_lrpc, NULL);
85 if (status != RPC_S_OK)
86 goto fail;
87
88 status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
89 irot_endpoint, NULL);
90 if (status != RPC_S_OK)
91 goto fail;
92
93 status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
94 if (status != RPC_S_OK)
95 goto fail;
96
97 //exit_event = __wine_make_process_system();
98 exit_event = CreateEventW(NULL, FALSE, FALSE, NULL); // never fires
99
100 return TRUE;
101
102 fail:
103 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
104 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
105 return FALSE;
106 }
107
108 /* returns false if we discover at the last moment that we
109 aren't ready to terminate */
110 BOOL RPCSS_Shutdown(void)
111 {
112 RpcMgmtStopServerListening(NULL);
113 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, TRUE);
114 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, TRUE);
115
116 CloseHandle(exit_event);
117
118 return TRUE;
119 }
120
121 #ifndef __REACTOS__
122 int main( int argc, char **argv )
123 {
124 /*
125 * We are invoked as a standard executable; we act in a
126 * "lazy" manner. We register our interfaces and endpoints, and hang around
127 * until we all user processes exit, and then silently terminate.
128 */
129
130 if (RPCSS_Initialize()) {
131 WaitForSingleObject(exit_event, INFINITE);
132 RPCSS_Shutdown();
133 }
134
135 return 0;
136 }
137 #endif