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.

197 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1995-2001 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This module contains the startup and termination code for the Configuration
  7. Manager (cfgmgr32).
  8. Author:
  9. Paula Tomlinson (paulat) 6-20-1995
  10. Environment:
  11. User mode only.
  12. Revision History:
  13. 3-Mar-1995 paulat
  14. Creation and initial implementation.
  15. --*/
  16. //
  17. // includes
  18. //
  19. #include "precomp.h"
  20. #include "cfgi.h"
  21. #include "setupapi.h"
  22. #include "spapip.h"
  23. //
  24. // global data
  25. //
  26. HANDLE hInst;
  27. PVOID hLocalStringTable = NULL; // handle to local string table
  28. PVOID hLocalBindingHandle = NULL; // rpc binding handle to local machine
  29. WORD LocalServerVersion = 0; // local machine internal server version
  30. WCHAR LocalMachineNameNetBIOS[MAX_PATH + 3];
  31. WCHAR LocalMachineNameDnsFullyQualified[MAX_PATH + 3];
  32. CRITICAL_SECTION BindingCriticalSection;
  33. CRITICAL_SECTION StringTableCriticalSection;
  34. BOOL
  35. CfgmgrEntry(
  36. PVOID hModule,
  37. ULONG Reason,
  38. PCONTEXT pContext
  39. )
  40. /*++
  41. Routine Description:
  42. This is the standard DLL entrypoint routine, called whenever a process
  43. or thread attaches or detaches.
  44. Arguments:
  45. hModule - PVOID parameter that specifies the handle of the DLL
  46. Reason - ULONG parameter that specifies the reason this entrypoint
  47. was called (either PROCESS_ATTACH, PROCESS_DETACH,
  48. THREAD_ATTACH, or THREAD_DETACH).
  49. pContext - Not used.
  50. (when cfgmgr32 is initialized by setupapi - as should almost
  51. always be the case - this is the 'Reserved' argument supplied to
  52. setupapi's DllMain entrypoint)
  53. Return value:
  54. Returns true if initialization compeleted successfully, false is not.
  55. --*/
  56. {
  57. UNREFERENCED_PARAMETER(pContext);
  58. hInst = (HANDLE)hModule;
  59. switch(Reason) {
  60. case DLL_PROCESS_ATTACH: {
  61. WCHAR szTemp[MAX_PATH + 1];
  62. ULONG ulSize = SIZECHARS(szTemp);
  63. try {
  64. InitializeCriticalSection(&BindingCriticalSection);
  65. InitializeCriticalSection(&StringTableCriticalSection);
  66. } except(EXCEPTION_EXECUTE_HANDLER) {
  67. //
  68. // InitializeCriticalSection may raise STATUS_NO_MEMORY
  69. // exception
  70. //
  71. return FALSE;
  72. }
  73. //
  74. // save the name of the local NetBIOS machine for later use
  75. //
  76. if(!GetComputerNameEx(ComputerNameNetBIOS, szTemp, &ulSize)) {
  77. //
  78. // ISSUE: (lonnym)--can we actually run w/o knowing the local
  79. // machine name???
  80. //
  81. *LocalMachineNameNetBIOS = L'\0';
  82. } else {
  83. //
  84. // always save local machine name in "\\name format"
  85. //
  86. if((lstrlen(szTemp) > 2) &&
  87. (szTemp[0] == L'\\') && (szTemp[1] == L'\\')) {
  88. //
  89. // The name is already in the correct format.
  90. //
  91. lstrcpy(LocalMachineNameNetBIOS, szTemp);
  92. } else {
  93. //
  94. // Prepend UNC path prefix
  95. //
  96. lstrcpy(LocalMachineNameNetBIOS, L"\\\\");
  97. lstrcat(LocalMachineNameNetBIOS, szTemp);
  98. }
  99. }
  100. //
  101. // save the name of the local Dns machine for later use
  102. //
  103. ulSize = SIZECHARS(szTemp);
  104. if(!GetComputerNameEx(ComputerNameDnsFullyQualified, szTemp, &ulSize)) {
  105. //
  106. // ISSUE: (lonnym)--can we actually run w/o knowing the local
  107. // machine name???
  108. //
  109. *LocalMachineNameDnsFullyQualified = L'\0';
  110. } else {
  111. //
  112. // always save local machine name in "\\name format"
  113. //
  114. if((lstrlen(szTemp) > 2) &&
  115. (szTemp[0] == L'\\') && (szTemp[1] == L'\\')) {
  116. //
  117. // The name is already in the correct format.
  118. //
  119. lstrcpy(LocalMachineNameDnsFullyQualified, szTemp);
  120. } else {
  121. //
  122. // Prepend UNC path prefix
  123. //
  124. lstrcpy(LocalMachineNameDnsFullyQualified, L"\\\\");
  125. lstrcat(LocalMachineNameDnsFullyQualified, szTemp);
  126. }
  127. }
  128. break;
  129. }
  130. case DLL_PROCESS_DETACH:
  131. //
  132. // release the rpc binding for the local machine
  133. //
  134. if (hLocalBindingHandle != NULL) {
  135. PNP_HANDLE_unbind(NULL, (handle_t)hLocalBindingHandle);
  136. hLocalBindingHandle = NULL;
  137. }
  138. //
  139. // release the string table for the local machine
  140. //
  141. if (hLocalStringTable != NULL) {
  142. pSetupStringTableDestroy(hLocalStringTable);
  143. hLocalStringTable = NULL;
  144. }
  145. DeleteCriticalSection(&BindingCriticalSection);
  146. DeleteCriticalSection(&StringTableCriticalSection);
  147. break;
  148. case DLL_THREAD_ATTACH:
  149. case DLL_THREAD_DETACH:
  150. break;
  151. }
  152. return TRUE;
  153. } // CfgmgrEntry