Leaked source code of windows server 2003
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.

166 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1990-1992 Microsoft Corporation
  3. Module Name:
  4. apisubs.c
  5. Abstract:
  6. Subroutines for LAN Manager APIs.
  7. Author:
  8. Chuck Lenzmeier (chuckl) 25-Jul-90
  9. Revision History:
  10. 08-Sept-1992 Danl
  11. Dll Cleanup routines used to be called for DLL_PROCESS_DETACH.
  12. Thus they were called for FreeLibrary or ExitProcess reasons.
  13. Now they are only called for the case of a FreeLibrary. ExitProcess
  14. will automatically clean up process resources.
  15. 03-Aug-1992 JohnRo
  16. Use FORMAT_ and PREFIX_ equates.
  17. --*/
  18. // These must be included first:
  19. #include <nt.h>
  20. #include <ntrtl.h>
  21. #include <nturtl.h>
  22. #define NOMINMAX // Avoid stdlib.h vs. windows.h warnings.
  23. #include <windows.h>
  24. #include <lmcons.h>
  25. #include <ntsam.h>
  26. #include <netdebug.h>
  27. // These may be included in any order:
  28. #include <accessp.h>
  29. #include <configp.h>
  30. #include <lmerr.h>
  31. #include <netdebug.h>
  32. #include <netlib.h>
  33. #include <prefix.h> // PREFIX_ equates.
  34. #include <secobj.h>
  35. #include <stdarg.h>
  36. #include <stdio.h>
  37. #include <rpcutil.h>
  38. #include <thread.h>
  39. #include <stdlib.h>
  40. #include <netbios.h>
  41. #include <dfsp.h>
  42. #include <winsock2.h> // needed by dsgetdcp.h
  43. #include <dsgetdc.h> // needed by dsgetdcp.h
  44. #include <dsgetdcp.h> // DCNameInitialize/Close
  45. #include <overflow.h>
  46. #define INIT_NETBIOS 0x00000001
  47. #define INIT_DCNAME 0x00000002
  48. #define INIT_CRITSEC 0x00000004
  49. BOOLEAN
  50. NetapipInitialize (
  51. IN PVOID DllHandle,
  52. IN ULONG Reason,
  53. IN LPVOID lpReserved OPTIONAL
  54. )
  55. {
  56. //
  57. // Handle attaching netapi.dll to a new process.
  58. //
  59. static DWORD s_dwInitLevel;
  60. if (Reason == DLL_PROCESS_ATTACH)
  61. {
  62. NET_API_STATUS NetStatus;
  63. NTSTATUS Status;
  64. DisableThreadLibraryCalls(DllHandle);
  65. //
  66. // Initialize Netbios
  67. //
  68. if (!NetbiosInitialize(DllHandle))
  69. {
  70. NetpKdPrint(( "[netapi.dll] Failed NetbiosInitialize\n"));
  71. return FALSE;
  72. }
  73. s_dwInitLevel |= INIT_NETBIOS;
  74. //
  75. // Initialize the NetGetDCName PDC Name cache
  76. //
  77. if ((NetStatus = DCNameInitialize()) != NERR_Success)
  78. {
  79. return FALSE;
  80. }
  81. s_dwInitLevel |= INIT_DCNAME;
  82. //
  83. // Initialize the NetDfsXXX API Critical Section
  84. //
  85. Status = RtlInitializeCriticalSection( &NetDfsApiCriticalSection );
  86. if (!NT_SUCCESS(Status))
  87. {
  88. return FALSE;
  89. }
  90. s_dwInitLevel |= INIT_CRITSEC;
  91. NetDfsApiInitialize();
  92. //
  93. // Initialize NetJoin logging
  94. //
  95. NetpInitializeLogFile();
  96. //
  97. // When DLL_PROCESS_DETACH and lpReserved is NULL, then a FreeLibrary
  98. // call is being made. If lpReserved is Non-NULL, and ExitProcess is
  99. // in progress. These cleanup routines will only be called when
  100. // a FreeLibrary is being called. ExitProcess will automatically
  101. // clean up all process resources, handles, and pending io.
  102. //
  103. }
  104. else if ((Reason == DLL_PROCESS_DETACH) && (lpReserved == NULL))
  105. {
  106. if (s_dwInitLevel & INIT_NETBIOS)
  107. {
  108. NetbiosDelete();
  109. }
  110. if (s_dwInitLevel & INIT_DCNAME)
  111. {
  112. DCNameClose();
  113. }
  114. //
  115. // Delete the NetDfsXXX API critical section
  116. //
  117. if (s_dwInitLevel & INIT_CRITSEC)
  118. {
  119. DeleteCriticalSection(&NetDfsApiCriticalSection);
  120. }
  121. //
  122. // Shut down NetJoin logging
  123. //
  124. NetpShutdownLogFile();
  125. }
  126. return TRUE;
  127. } // NetapipInitialize