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.

276 lines
5.3 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. #include "smtpinc.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #include <nt.h>
  23. #include <ntrtl.h>
  24. #include <nturtl.h>
  25. #include <windows.h>
  26. #include <winsock2.h>
  27. #include <lm.h>
  28. #include <stdio.h>
  29. #include <stdarg.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <tchar.h>
  33. //#include "dbgutil.h"
  34. //
  35. // Project include files.
  36. //
  37. //#include <inetcom.h>
  38. //#include <inetamsg.h>
  39. //#include <tcpproc.h>
  40. #ifdef __cplusplus
  41. } // extern "C"
  42. #endif // __cplusplus
  43. //#include <svcloc.h>
  44. //#define SECURITY_WIN32
  45. //#include <sspi.h> // Security Support Provider APIs
  46. //#include <schnlsp.h>
  47. //#include <lonsi.hxx>
  48. //#include "globals.hxx"
  49. #include <isrpc.hxx>
  50. PISRPC g_pIsrpc = NULL;
  51. HINSTANCE g_hDll = NULL;
  52. PISRPC sm_isrpc = NULL;
  53. BOOL
  54. InitializeSmtpServiceRpc(
  55. IN LPCSTR pszServiceName,
  56. IN RPC_IF_HANDLE hRpcInterface
  57. );
  58. BOOL CleanupSmtpServiceRpc(
  59. VOID
  60. );
  61. #if 0
  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 WINAPI DllMain (HANDLE hInst, ULONG dwReason, LPVOID lpvReserve)
  81. {
  82. return DLLEntry((HINSTANCE) hInst, dwReason, lpvReserve);
  83. }
  84. #endif
  85. #if 0
  86. BOOL
  87. InitDlls(
  88. VOID
  89. )
  90. /*++
  91. Description:
  92. DLL Init and uninit functions that don't have to worry about the
  93. peb lock being taken during PROCESS_ATTACH/DETACH.
  94. --*/
  95. {
  96. BOOL fReturn = TRUE;
  97. if ( !InitializeServiceRpc(
  98. NNTP_TEST_SERVICE_NAME,
  99. nntptest_ServerIfHandle
  100. ) )
  101. {
  102. fReturn = FALSE;
  103. }
  104. return fReturn;
  105. }
  106. BOOL
  107. TerminateDlls(
  108. VOID
  109. )
  110. {
  111. CleanupSmtpServiceRpc( );
  112. return TRUE;
  113. }
  114. #endif
  115. BOOL
  116. InitializeSmtpServiceRpc(
  117. IN LPCSTR pszServiceName,
  118. IN RPC_IF_HANDLE hRpcInterface
  119. )
  120. /*++
  121. Description:
  122. Initializes the rpc endpoint for the infocomm service.
  123. Arguments:
  124. pszServiceName - pointer to null-terminated string containing the name
  125. of the service.
  126. hRpcInterface - Handle for RPC interface.
  127. Returns:
  128. Win32 Error Code.
  129. --*/
  130. {
  131. DWORD dwError = NO_ERROR;
  132. PISRPC pIsrpc;
  133. //DBG_ASSERT( pszServiceName != NULL);
  134. //DBG_ASSERT( sm_isrpc == NULL );
  135. pIsrpc = new ISRPC( pszServiceName);
  136. if ( pIsrpc == NULL) {
  137. dwError = ERROR_NOT_ENOUGH_MEMORY;
  138. goto exit;
  139. }
  140. //
  141. // bind over Named pipe only.
  142. // If needed to bind over TCP, bind with bit flag ISRPC_OVER_TCPIP on.
  143. //
  144. dwError = pIsrpc->AddProtocol( ISRPC_OVER_TCPIP
  145. | ISRPC_OVER_NP | ISRPC_OVER_LPC
  146. );
  147. if( (dwError == RPC_S_DUPLICATE_ENDPOINT) ||
  148. (dwError == RPC_S_OK)
  149. ) {
  150. dwError = pIsrpc->RegisterInterface(hRpcInterface);
  151. }
  152. if ( dwError != RPC_S_OK ) {
  153. goto exit;
  154. }
  155. //
  156. // Start the RPC listen thread
  157. //
  158. #if 0
  159. dwError = pIsrpc->StartServer( );
  160. #endif
  161. exit:
  162. if ( dwError != NO_ERROR ) {
  163. //DBGPRINTF(( DBG_CONTEXT,
  164. // "Cannot start RPC Server for %s, error %lu\n",
  165. // pszServiceName, dwError ));
  166. delete pIsrpc;
  167. SetLastError(dwError);
  168. return(FALSE);
  169. }
  170. sm_isrpc = pIsrpc;
  171. return(TRUE);
  172. } // IIS_SERVICE::InitializeServiceRpc
  173. BOOL CleanupSmtpServiceRpc(
  174. VOID
  175. )
  176. /*++
  177. Description:
  178. Cleanup the data stored and services running.
  179. This function should be called only after freeing all the
  180. services running using this DLL.
  181. This function is called typically when the DLL is unloaded.
  182. Arguments:
  183. pszServiceName - pointer to null-terminated string containing the name
  184. of the service.
  185. hRpcInterface - Handle for RPC interface.
  186. Returns:
  187. Win32 Error Code.
  188. --*/
  189. {
  190. DWORD dwError = NO_ERROR;
  191. if ( sm_isrpc == NULL ) {
  192. //DBGPRINTF((DBG_CONTEXT,
  193. // "no isrpc object to cleanup. Returning success\n"));
  194. return(TRUE);
  195. }
  196. //(VOID) sm_isrpc->StopServer( );
  197. // dwError = sm_isrpc->CleanupData();
  198. sm_isrpc->UnRegisterInterface();
  199. // if( dwError != RPC_S_OK ) {
  200. //DBGPRINTF(( DBG_CONTEXT,
  201. // "ISRPC(%08x) Cleanup returns %lu\n", sm_isrpc, dwError ));
  202. //DBG_ASSERT( !"RpcServerUnregisterIf failure" );
  203. // SetLastError( dwError);
  204. //}
  205. delete sm_isrpc;
  206. sm_isrpc = NULL;
  207. return TRUE;
  208. } // CleanupSmtpServiceRpc