[RPCSS]
[reactos.git] / reactos / 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 #define NONAMELESSUNION
47 #define NONAMELESSSTRUCT
48 #include "rpcss.h"
49 #include <irot_s.h>
50 #include <epm_s.h>
51
52 #include <wine/debug.h>
53
54 WINE_DEFAULT_DEBUG_CHANNEL(ole);
55
56 HANDLE exit_event;
57
58 //extern HANDLE __wine_make_process_system(void);
59
60 BOOL RPCSS_Initialize(void)
61 {
62 static unsigned short irot_protseq[] = IROT_PROTSEQ;
63 static unsigned short irot_endpoint[] = IROT_ENDPOINT;
64 static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0};
65 static unsigned short epm_endpoint[] = {'\\','p','i','p','e','\\','e','p','m','a','p','p','e','r',0};
66 static unsigned short epm_protseq_lrpc[] = {'n','c','a','l','r','p','c',0};
67 static unsigned short epm_endpoint_lrpc[] = {'e','p','m','a','p','p','e','r',0};
68 RPC_STATUS status;
69
70 WINE_TRACE("\n");
71
72 status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL);
73 if (status != RPC_S_OK)
74 return status;
75 status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
76 if (status != RPC_S_OK)
77 {
78 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
79 return FALSE;
80 }
81
82 status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
83 epm_endpoint, NULL);
84 if (status != RPC_S_OK)
85 goto fail;
86
87 status = RpcServerUseProtseqEpW(epm_protseq_lrpc, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
88 epm_endpoint_lrpc, NULL);
89 if (status != RPC_S_OK)
90 goto fail;
91
92 status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
93 irot_endpoint, NULL);
94 if (status != RPC_S_OK)
95 goto fail;
96
97 status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
98 if (status != RPC_S_OK)
99 goto fail;
100
101 //exit_event = __wine_make_process_system();
102 exit_event = CreateEventW(NULL, FALSE, FALSE, NULL); // never fires
103
104 return TRUE;
105
106 fail:
107 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
108 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
109 return FALSE;
110 }
111
112 /* returns false if we discover at the last moment that we
113 aren't ready to terminate */
114 BOOL RPCSS_Shutdown(void)
115 {
116 RpcMgmtStopServerListening(NULL);
117 RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, TRUE);
118 RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, TRUE);
119
120 CloseHandle(exit_event);
121
122 return TRUE;
123 }
124
125 #ifndef __REACTOS__
126 int main( int argc, char **argv )
127 {
128 /*
129 * We are invoked as a standard executable; we act in a
130 * "lazy" manner. We register our interfaces and endpoints, and hang around
131 * until we all user processes exit, and then silently terminate.
132 */
133
134 if (RPCSS_Initialize()) {
135 WaitForSingleObject(exit_event, INFINITE);
136 RPCSS_Shutdown();
137 }
138
139 return 0;
140 }
141 #endif