6 #include "TaAfsAdmSvrInternal.h"
10 * DEFINITIONS ________________________________________________________________
14 extern void AfsAdmSvr_Startup (void);
15 extern void AfsAdmSvr_Shutdown (void);
19 * ROUTINES ___________________________________________________________________
24 LPARAM CALLBACK AfsAdmSvr_Debug_ThreadProc (PVOID lp)
29 while (GetMessage (&msg, 0, 0, 0))
31 if (!IsMemoryManagerMessage (&msg))
33 TranslateMessage (&msg);
34 DispatchMessage (&msg);
43 int cdecl main (int argc, char **argv)
45 BOOL fSuccess = FALSE;
47 Print (TEXT("Initializing..."));
50 WSAStartup (0x0101, &Data);
52 // Parse the command-line
54 DWORD dwAutoScope = AFSADMSVR_SCOPE_VOLUMES | AFSADMSVR_SCOPE_USERS;
56 for (--argc,++argv; argc; --argc,++argv)
58 if (!lstrcmpi (*argv, AFSADMSVR_KEYWORD_TIMED))
59 AfsAdmSvr_EnableAutoShutdown (TRUE);
60 else if (!lstrcmpi (*argv, AFSADMSVR_KEYWORD_MANUAL))
62 else if (!lstrcmpi (*argv, AFSADMSVR_KEYWORD_SCOPE_USERS))
63 dwAutoScope &= ~AFSADMSVR_SCOPE_VOLUMES;
64 else if (!lstrcmpi (*argv, AFSADMSVR_KEYWORD_SCOPE_VOLUMES))
65 dwAutoScope &= ~AFSADMSVR_SCOPE_USERS;
67 else if (!lstrcmpi (*argv, AFSADMSVR_KEYWORD_DEBUG))
68 CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)AfsAdmSvr_Debug_ThreadProc, 0, 0, 0);
72 // Prepare to listen for RPCs
74 unsigned char *pszPROTOCOL = (unsigned char *)"ncacn_ip_tcp";
75 unsigned char *pszENTRYNAME = (unsigned char *)AFSADMSVR_ENTRYNAME_DEFAULT;
76 unsigned char *pszANNOTATION = (unsigned char *)"Transarc AFS Administrative Server";
77 unsigned char szEndpoint[ 32 ];
78 wsprintf ((LPTSTR)szEndpoint, "%lu", AFSADMSVR_ENDPOINT_DEFAULT);
81 // Clean up any broken interface registration
83 RpcServerUnregisterIf (ITaAfsAdminSvr_v1_0_s_ifspec, 0, FALSE);
84 RpcNsBindingUnexport (RPC_C_NS_SYNTAX_DEFAULT, pszENTRYNAME, ITaAfsAdminSvr_v1_0_s_ifspec, NULL);
86 // Register our interface
89 if ((status = RpcServerUseProtseq (pszPROTOCOL, cMAX_CALLS, NULL)) != 0)
91 Print (dlERROR, TEXT("RpcServerUseProtseq failed; error 0x%08lX"), status);
93 else if ((status = RpcServerRegisterIf (ITaAfsAdminSvr_v1_0_s_ifspec, 0, 0)) != 0)
95 Print (dlERROR, TEXT("RpcServerRegisterIf failed; error 0x%08lX"), status);
99 // Always try to register on port 1025; that's the easiest thing for
100 // some clients to find. We'll only fail if we (a) can't use 1025, and
101 // (b) can't export our bindings.
103 BOOL fGotPort = FALSE;
104 if (RpcServerUseProtseqEp (pszPROTOCOL, cMAX_CALLS, szEndpoint, NULL) == 0)
107 Print (dlWARNING, TEXT("RpcServerUseProtseqEp failed (benign); error 0x%08lX"), status);
109 RPC_BINDING_VECTOR *pBindingVector;
110 if ((status = RpcServerInqBindings (&pBindingVector)) != 0)
112 Print (dlERROR, TEXT("RpcServerRegisterIf failed; error 0x%08lX"), status);
114 else if ((status = RpcEpRegister (ITaAfsAdminSvr_v1_0_s_ifspec, pBindingVector, NULL, pszANNOTATION)) != 0)
116 Print (dlERROR, TEXT("RpcEpRegister failed; error 0x%08lX"), status);
120 BOOL fExportedBinding = FALSE;
122 if ((status = RpcNsBindingExport (RPC_C_NS_SYNTAX_DEFAULT, pszENTRYNAME, ITaAfsAdminSvr_v1_0_s_ifspec, pBindingVector, NULL)) == 0)
123 fExportedBinding = TRUE;
125 Print (dlWARNING, TEXT("RpcNsBindingExport failed (benign); error 0x%08lX"), status);
127 if (!fExportedBinding && !fGotPort)
129 Print (dlERROR, TEXT("RpcNsBindingExport failed; error 0x%08lX"), status);
130 Print (dlERROR, TEXT("Could not bind to port %s or export bindings; terminating"), szEndpoint);
136 Print (TEXT("Ready.\n"));
138 // If not asked to open cells manually, fork a thread to start opening
139 // the default local cell
144 CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE)AfsAdmSvr_AutoOpen_ThreadProc, (PVOID)dwAutoScope, 0, &dwThreadID);
147 // Listen for requests until someone calls StopListen
149 if ((status = RpcServerListen (1, cMAX_CALLS, FALSE)) != 0)
151 Print (dlERROR, TEXT("RpcServerListen failed; error 0x%08lX"), status);
158 AfsAdmSvr_Shutdown();
161 if (fExportedBinding)
163 if ((status = RpcNsBindingUnexport (RPC_C_NS_SYNTAX_DEFAULT, pszENTRYNAME, ITaAfsAdminSvr_v1_0_s_ifspec, NULL)) != 0)
165 Print (dlWARNING, TEXT("RpcNsBindingExport failed; error 0x%08lX"), status);
169 if ((status = RpcEpUnregister (ITaAfsAdminSvr_v1_0_s_ifspec, pBindingVector, NULL)) != 0)
171 Print (dlWARNING, TEXT("RpcEpUnregister failed; error 0x%08lX"), status);
176 Print (TEXT("Shutting down...\n"));
178 if ((status = RpcServerUnregisterIf (0, 0, FALSE)) != 0)
180 Print (dlWARNING, TEXT("RpcServerUnregisterIf failed; error 0x%08lX"), status);
184 return (fSuccess) ? (0) : (-1);
188 void __RPC_FAR * __RPC_USER MIDL_user_allocate (size_t cbAllocate)
190 return (void __RPC_FAR *)Allocate (cbAllocate);
194 void __RPC_USER MIDL_user_free (void __RPC_FAR *pData)