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.

128 lines
3.0 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. BOOLEAN
  46. NetapipInitialize (
  47. IN PVOID DllHandle,
  48. IN ULONG Reason,
  49. IN LPVOID lpReserved OPTIONAL
  50. )
  51. {
  52. //
  53. // Handle attaching netapi.dll to a new process.
  54. //
  55. if (Reason == DLL_PROCESS_ATTACH) {
  56. NET_API_STATUS NetStatus;
  57. NTSTATUS Status;
  58. if ( !DisableThreadLibraryCalls( DllHandle ) )
  59. {
  60. NetpKdPrint((
  61. PREFIX_NETAPI "DisableThreadLibraryCalls failed: "
  62. FORMAT_API_STATUS "\n", GetLastError()));
  63. }
  64. //
  65. // Initialize Netbios
  66. //
  67. NetbiosInitialize(DllHandle);
  68. //
  69. // Initialize the NetGetDCName PDC Name cache
  70. //
  71. if (( NetStatus = DCNameInitialize()) != NERR_Success) {
  72. NetpKdPrint(( "[netapi.dll] Failed initialize DCName APIs%lu\n",
  73. NetStatus));
  74. return FALSE;
  75. }
  76. //
  77. // Initialize the NetDfsXXX API Critical Section
  78. //
  79. InitializeCriticalSection( &NetDfsApiCriticalSection );
  80. NetDfsApiInitialize();
  81. //
  82. // When DLL_PROCESS_DETACH and lpReserved is NULL, then a FreeLibrary
  83. // call is being made. If lpReserved is Non-NULL, and ExitProcess is
  84. // in progress. These cleanup routines will only be called when
  85. // a FreeLibrary is being called. ExitProcess will automatically
  86. // clean up all process resources, handles, and pending io.
  87. //
  88. } else if ((Reason == DLL_PROCESS_DETACH) &&
  89. (lpReserved == NULL)) {
  90. NetbiosDelete();
  91. DCNameClose();
  92. //
  93. // Delete the NetDfsXXX API critical section
  94. //
  95. DeleteCriticalSection( &NetDfsApiCriticalSection );
  96. }
  97. return TRUE;
  98. } // NetapipInitialize