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.

138 lines
3.2 KiB

  1. // PPServerClass.cpp : Implementation of CPPServerClass
  2. #include "stdafx.h"
  3. #include "PPServer.h"
  4. #include "PPServerClass.h"
  5. /////////////////////////////////////////////////////////////////////////////
  6. // Keys
  7. #define REG_LOCAL_TS_LOC _T("SOFTWARE\\Microsoft")
  8. #define REG_LOCAL_TS_PROGRAM _T("TShoot")
  9. // Values ///////////////////////////////////////////////////////////////////
  10. #define SNIFF_AUTOMATIC_STR _T("AutomaticSniffing")
  11. /////////////////////////////////////////////////////////////////////////////
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CPPServerClass
  14. bool CPPServerClass::Create(HKEY hKeyParent, LPCTSTR strKeyName, bool* bCreatedNew, REGSAM access)
  15. {
  16. HKEY hRetKey = NULL;
  17. DWORD dwDisposition = 0;
  18. long nWinError = ::RegCreateKeyEx(
  19. hKeyParent,
  20. strKeyName,
  21. 0,
  22. NULL,
  23. REG_OPTION_NON_VOLATILE,
  24. access,
  25. NULL,
  26. &hRetKey,
  27. &dwDisposition
  28. );
  29. if(nWinError == ERROR_SUCCESS)
  30. {
  31. m_hKey = hRetKey;
  32. *bCreatedNew = dwDisposition == REG_CREATED_NEW_KEY ? true : false;
  33. try
  34. {
  35. m_arrKeysToClose.push_back(hRetKey);
  36. }
  37. catch (exception&)
  38. {
  39. return false;
  40. }
  41. return true;
  42. }
  43. return false;
  44. }
  45. bool CPPServerClass::SetNumericValue(LPCTSTR strValueName, DWORD dwValue)
  46. {
  47. BYTE* pData = (BYTE*)&dwValue;
  48. long nWinError = ::RegSetValueEx(
  49. m_hKey,
  50. strValueName,
  51. 0,
  52. REG_DWORD,
  53. pData,
  54. sizeof(DWORD)
  55. );
  56. if (nWinError == ERROR_SUCCESS)
  57. return true;
  58. return false;
  59. }
  60. bool CPPServerClass::GetNumericValue(LPCTSTR strValueName, DWORD& dwValue)
  61. {
  62. DWORD tmp = 0;
  63. BYTE* pData = (BYTE*)&tmp;
  64. DWORD type = 0;
  65. DWORD size = sizeof(DWORD);
  66. long nWinError = ::RegQueryValueEx(
  67. m_hKey,
  68. strValueName,
  69. NULL,
  70. &type,
  71. pData,
  72. &size
  73. );
  74. if (type != REG_DWORD)
  75. return false;
  76. if (nWinError == ERROR_SUCCESS)
  77. {
  78. dwValue = tmp;
  79. return true;
  80. }
  81. return false;
  82. }
  83. void CPPServerClass::Close()
  84. {
  85. for (vector<HKEY>::reverse_iterator i = m_arrKeysToClose.rbegin(); i != m_arrKeysToClose.rend(); i++)
  86. ::RegCloseKey( *i );
  87. m_arrKeysToClose.clear();
  88. }
  89. STDMETHODIMP CPPServerClass::AllowAutomaticSniffing(VARIANT *pvarShow)
  90. {
  91. bool was_created = false;
  92. DWORD dwAllowSniffing = 1;
  93. // [BC - 20010302] - Changed regsitry access level from WRITE to QUERY and READ. Write access
  94. // not allowed for certain user accts, such as WinXP built in guest acct. Write access should
  95. // not be required by this component.
  96. if (Create(HKEY_LOCAL_MACHINE, REG_LOCAL_TS_LOC, &was_created, KEY_QUERY_VALUE))
  97. {
  98. if (Create(m_hKey, REG_LOCAL_TS_PROGRAM, &was_created, KEY_READ))
  99. {
  100. // this call can be not successfull, if there is no such value.
  101. // BUT we do not set this value,
  102. // we leave dwAllowSniffing as initialized ("1")
  103. // This approach will comply the "Sniffing version 3.2.doc" statement,
  104. // that if "AutomaticSniffing" value is missed, we treat it as set to "1"
  105. GetNumericValue(SNIFF_AUTOMATIC_STR, dwAllowSniffing);
  106. }
  107. }
  108. Close();
  109. ::VariantInit(pvarShow);
  110. V_VT(pvarShow) = VT_I4;
  111. if (dwAllowSniffing == 1)
  112. pvarShow->lVal = 1;
  113. else
  114. pvarShow->lVal = 0;
  115. return S_OK;
  116. }