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.

200 lines
6.8 KiB

  1. #include <precomp.hxx>
  2. #pragma hdrstop
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: policy.cpp
  5. Description: A system administrator is able to specify control parameters
  6. for the watchdog. These include:
  7. Show popup dialog to user (yes/no)
  8. Send user email message (yes/no)
  9. Minimum period between popup dialogs (minutes)
  10. Minimum period between email messages (minutes)
  11. Add users to "To:" email list <email address list>
  12. Add users to "Cc:" email list <email address list>
  13. Add users to "Bcc:" email list <email address list>
  14. A client of the object is able to ask it if a given action should be
  15. performed (dialog, email) and for the additional email names.
  16. CPolicy
  17. Revision History:
  18. Date Description Programmer
  19. -------- --------------------------------------------------- ----------
  20. 07/01/97 Initial creation. BrianAu
  21. 07/10/97 Store info in HKEY_CURRENT_USER instead of BrianAu
  22. policy.ini.
  23. */
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #include "policy.h"
  26. //
  27. // Defined in dskquowd.cpp
  28. //
  29. extern TCHAR g_szRegSubKeyUser[];
  30. extern TCHAR g_szRegSubKeyAdmin[];
  31. //
  32. // Names of registry file sections and values.
  33. //
  34. const TCHAR CPolicy::SZ_REG_SHOW_USER_POPUP[] = TEXT("ShowUserPopup");
  35. const TCHAR CPolicy::SZ_REG_MIN_PERIOD_POPUP[] = TEXT("MinNotifyMinutesPopup");
  36. const TCHAR CPolicy::SZ_REG_MIN_PERIOD_EMAIL[] = TEXT("MinNotifyMinutesEmail");
  37. const TCHAR CPolicy::SZ_REG_SEND_USER_EMAIL[] = TEXT("SendUserEmail");
  38. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_TO[] = TEXT("SendEmailTo");
  39. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_CC[] = TEXT("SendEmailCc");
  40. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_BCC[] = TEXT("SendEmailBcc");
  41. //
  42. // Default values written to empty registry key.
  43. //
  44. const INT CPolicy::I_REG_SEND_USER_EMAIL_DEFAULT = 1;
  45. const INT CPolicy::I_REG_SHOW_USER_POPUP_DEFAULT = 1;
  46. const INT CPolicy::I_REG_MIN_PERIOD_POPUP_DEFAULT = 240;
  47. const INT CPolicy::I_REG_MIN_PERIOD_EMAIL_DEFAULT = 240;
  48. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_TO_DEFAULT[] = TEXT("");
  49. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_CC_DEFAULT[] = TEXT("");
  50. const TCHAR CPolicy::SZ_REG_SEND_EMAIL_BCC_DEFAULT[] = TEXT("");
  51. CPolicy::CPolicy(
  52. VOID
  53. ) : m_bSendUserEmail(FALSE),
  54. m_bPopupDialog(FALSE),
  55. m_iMinPeriodPopupDialog(I_REG_MIN_PERIOD_POPUP_DEFAULT),
  56. m_iMinPeriodEmail(I_REG_MIN_PERIOD_EMAIL_DEFAULT)
  57. {
  58. //
  59. // Create the registry param table entries we'll be using.
  60. // These statements also specify the default values to use as well
  61. // as allowable limits (for DWORD values).
  62. //
  63. m_RegParams.AddDWordParam(HKEY_CURRENT_USER,
  64. g_szRegSubKeyAdmin,
  65. SZ_REG_SEND_USER_EMAIL,
  66. 0,
  67. 1,
  68. I_REG_SEND_USER_EMAIL_DEFAULT);
  69. m_RegParams.AddDWordParam(HKEY_CURRENT_USER,
  70. g_szRegSubKeyAdmin,
  71. SZ_REG_SHOW_USER_POPUP,
  72. 0,
  73. 1,
  74. I_REG_SHOW_USER_POPUP_DEFAULT);
  75. m_RegParams.AddDWordParam(HKEY_CURRENT_USER,
  76. g_szRegSubKeyAdmin,
  77. SZ_REG_MIN_PERIOD_POPUP,
  78. 0,
  79. 0xFFFFFFFF,
  80. I_REG_MIN_PERIOD_POPUP_DEFAULT);
  81. m_RegParams.AddDWordParam(HKEY_CURRENT_USER,
  82. g_szRegSubKeyAdmin,
  83. SZ_REG_MIN_PERIOD_EMAIL,
  84. 0,
  85. 0xFFFFFFFF,
  86. I_REG_MIN_PERIOD_EMAIL_DEFAULT);
  87. m_RegParams.AddSzParam(HKEY_CURRENT_USER,
  88. g_szRegSubKeyAdmin,
  89. SZ_REG_SEND_EMAIL_TO,
  90. SZ_REG_SEND_EMAIL_TO_DEFAULT);
  91. m_RegParams.AddSzParam(HKEY_CURRENT_USER,
  92. g_szRegSubKeyAdmin,
  93. SZ_REG_SEND_EMAIL_CC,
  94. SZ_REG_SEND_EMAIL_CC_DEFAULT);
  95. m_RegParams.AddSzParam(HKEY_CURRENT_USER,
  96. g_szRegSubKeyAdmin,
  97. SZ_REG_SEND_EMAIL_BCC,
  98. SZ_REG_SEND_EMAIL_BCC_DEFAULT);
  99. //
  100. // Now retrieve our parameters from the registry.
  101. // If the parameters don't exist, they'll be created.
  102. //
  103. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  104. g_szRegSubKeyAdmin,
  105. SZ_REG_SEND_EMAIL_TO,
  106. m_strOtherEmailTo.GetBuffer(MAX_PATH),
  107. MAX_PATH);
  108. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  109. g_szRegSubKeyAdmin,
  110. SZ_REG_SEND_EMAIL_CC,
  111. m_strOtherEmailCc.GetBuffer(MAX_PATH),
  112. MAX_PATH);
  113. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  114. g_szRegSubKeyAdmin,
  115. SZ_REG_SEND_EMAIL_BCC,
  116. m_strOtherEmailBcc.GetBuffer(MAX_PATH),
  117. MAX_PATH);
  118. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  119. g_szRegSubKeyAdmin,
  120. SZ_REG_SHOW_USER_POPUP,
  121. (LPDWORD)&m_bPopupDialog);
  122. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  123. g_szRegSubKeyAdmin,
  124. SZ_REG_SEND_USER_EMAIL,
  125. (LPDWORD)&m_bSendUserEmail);
  126. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  127. g_szRegSubKeyAdmin,
  128. SZ_REG_MIN_PERIOD_POPUP,
  129. (LPDWORD)&m_iMinPeriodPopupDialog);
  130. m_RegParams.GetParameter(HKEY_CURRENT_USER,
  131. g_szRegSubKeyAdmin,
  132. SZ_REG_MIN_PERIOD_EMAIL,
  133. (LPDWORD)&m_iMinPeriodEmail);
  134. }
  135. CPolicy::~CPolicy(
  136. VOID
  137. )
  138. {
  139. //
  140. // Nothing to do.
  141. //
  142. }
  143. //
  144. // Should we send any email?
  145. //
  146. BOOL
  147. CPolicy::ShouldSendEmail(
  148. VOID
  149. ) const
  150. {
  151. return ShouldSendUserEmail() ||
  152. 0 != m_strOtherEmailTo.Length() ||
  153. 0 != m_strOtherEmailCc.Length() ||
  154. 0 != m_strOtherEmailBcc.Length();
  155. }
  156. //
  157. // Should we do any notifications (popup or email) ?
  158. //
  159. BOOL
  160. CPolicy::ShouldDoAnyNotifications(
  161. VOID
  162. ) const
  163. {
  164. return ShouldSendEmail() ||
  165. ShouldPopupDialog();
  166. }