wined3d: Only register the np2 texture fixup if needed.
[wine] / programs / 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 <stdio.h>
47 #include <limits.h>
48 #include <assert.h>
49
50 #define NONAMELESSUNION
51 #define NONAMELESSSTRUCT
52 #include "rpcss.h"
53 #include "winnt.h"
54 #include "irot.h"
55 #include "epm.h"
56
57 #include "wine/debug.h"
58
59 WINE_DEFAULT_DEBUG_CHANNEL(ole);
60
61 static HANDLE exit_event;
62
63 extern HANDLE __wine_make_process_system(void);
64
65 static BOOL RPCSS_Initialize(void)
66 {
67   static unsigned short irot_protseq[] = IROT_PROTSEQ;
68   static unsigned short irot_endpoint[] = IROT_ENDPOINT;
69   static unsigned short epm_protseq[] = {'n','c','a','c','n','_','n','p',0};
70   static unsigned short epm_endpoint[] = {'\\','p','i','p','e','\\','e','p','m','a','p','p','e','r',0};
71   RPC_STATUS status;
72
73   WINE_TRACE("\n");
74
75   status = RpcServerRegisterIf(epm_v3_0_s_ifspec, NULL, NULL);
76   if (status != RPC_S_OK)
77     return status;
78   status = RpcServerRegisterIf(Irot_v0_2_s_ifspec, NULL, NULL);
79   if (status != RPC_S_OK)
80   {
81     RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
82     return FALSE;
83   }
84
85   status = RpcServerUseProtseqEpW(epm_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
86                                   epm_endpoint, NULL);
87   if (status != RPC_S_OK)
88     goto fail;
89
90   status = RpcServerUseProtseqEpW(irot_protseq, RPC_C_PROTSEQ_MAX_REQS_DEFAULT,
91                                   irot_endpoint, NULL);
92   if (status != RPC_S_OK)
93     goto fail;
94
95   status = RpcServerListen(1, RPC_C_LISTEN_MAX_CALLS_DEFAULT, TRUE);
96   if (status != RPC_S_OK)
97     goto fail;
98
99   exit_event = __wine_make_process_system();
100
101   return TRUE;
102
103 fail:
104   RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, FALSE);
105   RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, FALSE);
106   return FALSE;
107 }
108
109 /* returns false if we discover at the last moment that we
110    aren't ready to terminate */
111 static BOOL RPCSS_Shutdown(void)
112 {
113   RpcMgmtStopServerListening(NULL);
114   RpcServerUnregisterIf(epm_v3_0_s_ifspec, NULL, TRUE);
115   RpcServerUnregisterIf(Irot_v0_2_s_ifspec, NULL, TRUE);
116
117   CloseHandle(exit_event);
118
119   return TRUE;
120 }
121
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 }