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.

199 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. snmpapi.c
  5. Abstract:
  6. Contains entry point for SNMPAPI.DLL.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. --*/
  11. ///////////////////////////////////////////////////////////////////////////////
  12. // //
  13. // Include files //
  14. // //
  15. ///////////////////////////////////////////////////////////////////////////////
  16. #include <nt.h>
  17. #include <windef.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <snmp.h>
  22. #include <snmputil.h>
  23. #include "ntfuncs.h"
  24. ///////////////////////////////////////////////////////////////////////////////
  25. // //
  26. // Global Variables //
  27. // //
  28. ///////////////////////////////////////////////////////////////////////////////
  29. DWORD g_dwPlatformId = 0;
  30. AsnObjectIdentifier * g_pEnterpriseOid = NULL;
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // //
  33. // Private Variables //
  34. // //
  35. ///////////////////////////////////////////////////////////////////////////////
  36. static UINT idsWindowsNTWorkstation[] = {1,3,6,1,4,1,311,1,1,3,1,1};
  37. static UINT idsWindowsNTServer[] = {1,3,6,1,4,1,311,1,1,3,1,2};
  38. static UINT idsWindowsNTDC[] = {1,3,6,1,4,1,311,1,1,3,1,3};
  39. static UINT idsWindows[] = {1,3,6,1,4,1,311,1,1,3,2};
  40. static AsnObjectIdentifier oidWindowsNTWorkstation = {
  41. sizeof(idsWindowsNTWorkstation)/sizeof(UINT),
  42. idsWindowsNTWorkstation
  43. };
  44. static AsnObjectIdentifier oidWindowsNTServer = {
  45. sizeof(idsWindowsNTServer)/sizeof(UINT),
  46. idsWindowsNTServer
  47. };
  48. static AsnObjectIdentifier oidWindowsNTDC = {
  49. sizeof(idsWindowsNTDC)/sizeof(UINT),
  50. idsWindowsNTDC
  51. };
  52. static AsnObjectIdentifier oidWindows = {
  53. sizeof(idsWindows)/sizeof(UINT),
  54. idsWindows
  55. };
  56. ///////////////////////////////////////////////////////////////////////////////
  57. // //
  58. // Private Procedures //
  59. // //
  60. ///////////////////////////////////////////////////////////////////////////////
  61. BOOL
  62. InitializeEnterpriseOID(
  63. )
  64. /*++
  65. Routine Description:
  66. Determines the default enterprise object identifier.
  67. Arguments:
  68. None.
  69. Return Values:
  70. Returns true if successful.
  71. --*/
  72. {
  73. NT_PRODUCT_TYPE NtProductType;
  74. // default to generic oid
  75. g_pEnterpriseOid = &oidWindows;
  76. // check to see if the platform is winnt
  77. if (g_dwPlatformId == VER_PLATFORM_WIN32_NT) {
  78. // assume this is just a workstation
  79. g_pEnterpriseOid = &oidWindowsNTWorkstation;
  80. // let the system determine product type
  81. RtlGetNtProductType(&NtProductType);
  82. // point to the correct enterprise oid
  83. if (NtProductType == NtProductServer) {
  84. // this is a stand-alone server
  85. g_pEnterpriseOid = &oidWindowsNTServer;
  86. } else if (NtProductType == NtProductLanManNt) {
  87. // this is a PDC or a BDC
  88. g_pEnterpriseOid = &oidWindowsNTDC;
  89. }
  90. }
  91. SNMPDBG((
  92. SNMP_LOG_TRACE,
  93. "SNMP: INIT: enterprise is %s.\n",
  94. SnmpUtilOidToA(g_pEnterpriseOid)
  95. ));
  96. return TRUE;
  97. }
  98. ///////////////////////////////////////////////////////////////////////////////
  99. // //
  100. // Public Procedures //
  101. // //
  102. ///////////////////////////////////////////////////////////////////////////////
  103. BOOLEAN
  104. InitializeDLL(
  105. PVOID DllHandle,
  106. ULONG Reason,
  107. LPVOID lpReserved
  108. )
  109. /*++
  110. Routine Description:
  111. Dll entry point.
  112. Arguments:
  113. Same as DllMain.
  114. Return Values:
  115. Returns true if successful.
  116. --*/
  117. {
  118. // check if new process attaching
  119. if (Reason == DLL_PROCESS_ATTACH) {
  120. OSVERSIONINFO osInfo;
  121. // initialize os info structure
  122. osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  123. // gather os info
  124. GetVersionEx(&osInfo);
  125. // save platform id for later use
  126. g_dwPlatformId = osInfo.dwPlatformId;
  127. // initialize enterprise
  128. InitializeEnterpriseOID();
  129. // turn off thread attach messages
  130. DisableThreadLibraryCalls(DllHandle);
  131. }
  132. return TRUE;
  133. }