Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
4.6 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1994 **/
  4. /**********************************************************************/
  5. /*
  6. main.cxx
  7. Library initialization for infocomm.dll --
  8. Internet Information Services Common dll.
  9. FILE HISTORY:
  10. Johnl 06-Oct-1994 Created.
  11. */
  12. #ifndef dllexp
  13. #define dllexp __declspec( dllexport )
  14. #endif
  15. //
  16. // System include files.
  17. //
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. #include <windows.h>
  25. #include <winsock2.h>
  26. #include <lm.h>
  27. #include <stdio.h>
  28. #include <stdarg.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <tchar.h>
  32. //#include "dbgutil.h"
  33. //
  34. // Project include files.
  35. //
  36. //#include <inetcom.h>
  37. //#include <inetamsg.h>
  38. //#include <tcpproc.h>
  39. #ifdef __cplusplus
  40. } // extern "C"
  41. #endif // __cplusplus
  42. //#include <svcloc.h>
  43. //#define SECURITY_WIN32
  44. //#include <sspi.h> // Security Support Provider APIs
  45. //#include <schnlsp.h>
  46. //#include <lonsi.hxx>
  47. //#include "globals.hxx"
  48. #include "isrpc.hxx"
  49. #include "isrpcexp.h"
  50. PISRPC g_pIsrpc = NULL;
  51. HINSTANCE g_hDll = NULL;
  52. PISRPC sm_isrpc = NULL;
  53. BOOL
  54. InitializeServiceRpc(
  55. IN LPCSTR pszServiceName,
  56. IN RPC_IF_HANDLE hRpcInterface
  57. );
  58. BOOL
  59. CleanupServiceRpc(
  60. VOID
  61. );
  62. extern "C"
  63. BOOL WINAPI DLLEntry( HINSTANCE hDll, DWORD dwReason, LPVOID lpvReserved )
  64. {
  65. BOOL fReturn = TRUE;
  66. switch ( dwReason )
  67. {
  68. case DLL_PROCESS_ATTACH:
  69. g_hDll = hDll;
  70. break;
  71. case DLL_PROCESS_DETACH:
  72. break;
  73. case DLL_THREAD_ATTACH:
  74. case DLL_THREAD_DETACH:
  75. default:
  76. break ;
  77. }
  78. return ( fReturn);
  79. } // main()
  80. BOOL
  81. InitializeServiceRpc(
  82. IN LPCSTR pszServiceName,
  83. IN RPC_IF_HANDLE hRpcInterface
  84. )
  85. /*++
  86. Description:
  87. Initializes the rpc endpoint for the infocomm service.
  88. Arguments:
  89. pszServiceName - pointer to null-terminated string containing the name
  90. of the service.
  91. hRpcInterface - Handle for RPC interface.
  92. Returns:
  93. Win32 Error Code.
  94. --*/
  95. {
  96. DWORD dwError = NO_ERROR;
  97. PISRPC pIsrpc;
  98. //DBG_ASSERT( pszServiceName != NULL);
  99. //DBG_ASSERT( sm_isrpc == NULL );
  100. pIsrpc = new ISRPC( pszServiceName);
  101. if ( pIsrpc == NULL) {
  102. dwError = ERROR_NOT_ENOUGH_MEMORY;
  103. goto exit;
  104. }
  105. //
  106. // bind over Named pipe only.
  107. // If needed to bind over TCP, bind with bit flag ISRPC_OVER_TCPIP on.
  108. //
  109. dwError = pIsrpc->AddProtocol( ISRPC_OVER_TCPIP
  110. | ISRPC_OVER_NP | ISRPC_OVER_LPC
  111. );
  112. if( (dwError == RPC_S_DUPLICATE_ENDPOINT) ||
  113. (dwError == RPC_S_OK)
  114. ) {
  115. dwError = pIsrpc->RegisterInterface(hRpcInterface);
  116. }
  117. if ( dwError != RPC_S_OK ) {
  118. goto exit;
  119. }
  120. //
  121. // Start the RPC listen thread
  122. //
  123. #if 0
  124. dwError = pIsrpc->StartServer( );
  125. #endif
  126. exit:
  127. if ( dwError != NO_ERROR ) {
  128. //DBGPRINTF(( DBG_CONTEXT,
  129. // "Cannot start RPC Server for %s, error %lu\n",
  130. // pszServiceName, dwError ));
  131. delete pIsrpc;
  132. SetLastError(dwError);
  133. return(FALSE);
  134. }
  135. sm_isrpc = pIsrpc;
  136. return(TRUE);
  137. } // IIS_SERVICE::InitializeServiceRpc
  138. BOOL
  139. CleanupServiceRpc(
  140. VOID
  141. )
  142. /*++
  143. Description:
  144. Cleanup the data stored and services running.
  145. This function should be called only after freeing all the
  146. services running using this DLL.
  147. This function is called typically when the DLL is unloaded.
  148. Arguments:
  149. pszServiceName - pointer to null-terminated string containing the name
  150. of the service.
  151. hRpcInterface - Handle for RPC interface.
  152. Returns:
  153. Win32 Error Code.
  154. --*/
  155. {
  156. DWORD dwError = NO_ERROR;
  157. if ( sm_isrpc == NULL ) {
  158. //DBGPRINTF((DBG_CONTEXT,
  159. // "no isrpc object to cleanup. Returning success\n"));
  160. return(TRUE);
  161. }
  162. #if 0
  163. (VOID) sm_isrpc->StopServer( );
  164. #endif
  165. //dwError = sm_isrpc->CleanupData();
  166. dwError = sm_isrpc->UnRegisterInterface();
  167. if( dwError != RPC_S_OK ) {
  168. //DBGPRINTF(( DBG_CONTEXT,
  169. // "ISRPC(%08x) Cleanup returns %lu\n", sm_isrpc, dwError ));
  170. //DBG_ASSERT( !"RpcServerUnregisterIf failure" );
  171. SetLastError( dwError);
  172. }
  173. delete sm_isrpc;
  174. sm_isrpc = NULL;
  175. return TRUE;
  176. } // CleanupServiceRpc