2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afs/param.h>
18 #include "TaAfsAdmSvrInternal.h"
21 * ROUTINES ___________________________________________________________________
26 LPARAM CALLBACK
AfsAdmSvr_Debug_ThreadProc (PVOID lp
)
31 while (GetMessage (&msg
, 0, 0, 0))
33 if (!IsMemoryManagerMessage (&msg
))
35 TranslateMessage (&msg
);
36 DispatchMessage (&msg
);
45 int cdecl main (int argc
, char **argv
)
47 BOOL fSuccess
= FALSE
;
49 Print (TEXT("Initializing..."));
52 WSAStartup (0x0101, &Data
);
54 // Parse the command-line
56 UINT_PTR dwAutoScope
= AFSADMSVR_SCOPE_VOLUMES
| AFSADMSVR_SCOPE_USERS
;
58 for (--argc
,++argv
; argc
; --argc
,++argv
)
60 if (!lstrcmpi (*argv
, AFSADMSVR_KEYWORD_TIMED
))
61 AfsAdmSvr_EnableAutoShutdown (TRUE
);
62 else if (!lstrcmpi (*argv
, AFSADMSVR_KEYWORD_MANUAL
))
64 else if (!lstrcmpi (*argv
, AFSADMSVR_KEYWORD_SCOPE_USERS
))
65 dwAutoScope
&= ~AFSADMSVR_SCOPE_VOLUMES
;
66 else if (!lstrcmpi (*argv
, AFSADMSVR_KEYWORD_SCOPE_VOLUMES
))
67 dwAutoScope
&= ~AFSADMSVR_SCOPE_USERS
;
69 else if (!lstrcmpi (*argv
, AFSADMSVR_KEYWORD_DEBUG
))
70 CreateThread (NULL
, 0, (LPTHREAD_START_ROUTINE
)AfsAdmSvr_Debug_ThreadProc
, 0, 0, 0);
74 // Prepare to listen for RPCs
76 unsigned char *pszPROTOCOL
= (unsigned char *)"ncacn_ip_tcp";
77 unsigned char *pszENTRYNAME
= (unsigned char *)AFSADMSVR_ENTRYNAME_DEFAULT
;
78 unsigned char *pszANNOTATION
= (unsigned char *)"Transarc AFS Administrative Server";
79 unsigned char szEndpoint
[ 32 ];
80 wsprintf ((LPTSTR
)szEndpoint
, "%lu", AFSADMSVR_ENDPOINT_DEFAULT
);
83 // Clean up any broken interface registration
85 RpcServerUnregisterIf (ITaAfsAdminSvr_v1_0_s_ifspec
, 0, FALSE
);
87 RpcNsBindingUnexport (RPC_C_NS_SYNTAX_DEFAULT
, pszENTRYNAME
, ITaAfsAdminSvr_v1_0_s_ifspec
, NULL
);
90 // Register our interface
93 if ((status
= RpcServerUseProtseq (pszPROTOCOL
, cMAX_CALLS
, NULL
)) != 0)
95 Print (dlERROR
, TEXT("RpcServerUseProtseq failed; error 0x%08lX"), status
);
97 else if ((status
= RpcServerRegisterIf (ITaAfsAdminSvr_v1_0_s_ifspec
, 0, 0)) != 0)
99 Print (dlERROR
, TEXT("RpcServerRegisterIf failed; error 0x%08lX"), status
);
103 // Always try to register on port 1025; that's the easiest thing for
104 // some clients to find. We'll only fail if we (a) can't use 1025, and
105 // (b) can't export our bindings.
107 BOOL fGotPort
= FALSE
;
108 if (RpcServerUseProtseqEp (pszPROTOCOL
, cMAX_CALLS
, szEndpoint
, NULL
) == 0)
111 Print (dlWARNING
, TEXT("RpcServerUseProtseqEp failed (benign); error 0x%08lX"), status
);
113 RPC_BINDING_VECTOR
*pBindingVector
;
114 if ((status
= RpcServerInqBindings (&pBindingVector
)) != 0)
116 Print (dlERROR
, TEXT("RpcServerRegisterIf failed; error 0x%08lX"), status
);
118 else if ((status
= RpcEpRegister (ITaAfsAdminSvr_v1_0_s_ifspec
, pBindingVector
, NULL
, pszANNOTATION
)) != 0)
120 Print (dlERROR
, TEXT("RpcEpRegister failed; error 0x%08lX"), status
);
124 BOOL fExportedBinding
= FALSE
;
127 if ((status
= RpcNsBindingExport (RPC_C_NS_SYNTAX_DEFAULT
, pszENTRYNAME
, ITaAfsAdminSvr_v1_0_s_ifspec
, pBindingVector
, NULL
)) == 0)
128 fExportedBinding
= TRUE
;
130 Print (dlWARNING
, TEXT("RpcNsBindingExport failed (benign); error 0x%08lX"), status
);
133 if (!fExportedBinding
&& !fGotPort
)
135 Print (dlERROR
, TEXT("RpcNsBindingExport failed; error 0x%08lX"), status
);
136 Print (dlERROR
, TEXT("Could not bind to port %s or export bindings; terminating"), szEndpoint
);
142 Print (TEXT("Ready.\n"));
144 // If not asked to open cells manually, fork a thread to start opening
145 // the default local cell
150 CreateThread (NULL
, 0, (LPTHREAD_START_ROUTINE
)AfsAdmSvr_AutoOpen_ThreadProc
, (PVOID
)dwAutoScope
, 0, &dwThreadID
);
153 // Listen for requests until someone calls StopListen
155 if ((status
= RpcServerListen (1, cMAX_CALLS
, FALSE
)) != 0)
157 Print (dlERROR
, TEXT("RpcServerListen failed; error 0x%08lX"), status
);
164 AfsAdmSvr_Shutdown();
168 if (fExportedBinding
)
170 if ((status
= RpcNsBindingUnexport (RPC_C_NS_SYNTAX_DEFAULT
, pszENTRYNAME
, ITaAfsAdminSvr_v1_0_s_ifspec
, NULL
)) != 0)
172 Print (dlWARNING
, TEXT("RpcNsBindingExport failed; error 0x%08lX"), status
);
176 if ((status
= RpcEpUnregister (ITaAfsAdminSvr_v1_0_s_ifspec
, pBindingVector
, NULL
)) != 0)
178 Print (dlWARNING
, TEXT("RpcEpUnregister failed; error 0x%08lX"), status
);
183 Print (TEXT("Shutting down...\n"));
185 if ((status
= RpcServerUnregisterIf (0, 0, FALSE
)) != 0)
187 Print (dlWARNING
, TEXT("RpcServerUnregisterIf failed; error 0x%08lX"), status
);
191 return (fSuccess
) ? (0) : (-1);
195 extern "C" void __RPC_FAR
* __RPC_USER
MIDL_user_allocate (size_t cbAllocate
)
197 return (void __RPC_FAR
*)Allocate (cbAllocate
);
201 extern "C" void __RPC_USER
MIDL_user_free (void __RPC_FAR
*pData
)