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.

316 lines
11 KiB

  1. // File: seccpl.cpp
  2. #include "precomp.h"
  3. #include "conf.h"
  4. #include <tsecctrl.h>
  5. #include <certui.h>
  6. #include <help_ids.h>
  7. #include "ConfPolicies.h"
  8. // Dialog ID to Help ID mapping
  9. static const DWORD rgHelpIdsSecurity[] = {
  10. IDC_SEC_GENERAL, IDH_SECURITY_SECURITY,
  11. IDC_SEC_GEN_TEXT, IDH_SECURITY_SECURITY,
  12. IDC_SEC_INCOMING, IDH_SECURITY_INCOMING,
  13. IDC_SEC_OUTGOING, IDH_SECURITY_OUTGOING,
  14. IDC_SEC_CRED, IDH_SECURITY_CERTIFICATE,
  15. IDC_SEC_CRED_TEXT, IDH_SECURITY_CERTIFICATE,
  16. IDC_SECURE_CALL_EDIT, IDH_SECURITY_CERTIFICATE_LIST,
  17. IDC_SEC_CHANGECERT, IDH_SECURITY_CHANGE_CERTIFICATE,
  18. IDC_SEC_PRIVACY_ONLY, IDH_SECURITY_CERTIFICATE_PRIVACY,
  19. IDC_SEC_PRIVACY_AUTH, IDH_SECURITY_CERTIFICATE_PRIV_AUTH,
  20. 0, 0 // terminator
  21. };
  22. extern INmSysInfo2 * g_pNmSysInfo;
  23. static PBYTE g_pbEncodedCert = NULL;
  24. static DWORD g_cbEncodedCert = 0;
  25. INT_PTR APIENTRY SecurityDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  26. {
  27. switch (message)
  28. {
  29. case WM_DESTROY:
  30. if ( g_pbEncodedCert )
  31. {
  32. FreeT120EncodedCert ( g_pbEncodedCert );
  33. g_pbEncodedCert = NULL;
  34. }
  35. break;
  36. case WM_INITDIALOG:
  37. {
  38. int security;
  39. BOOL fIncomingOn;
  40. BOOL fOutgoingOn;
  41. BOOL fBtnsAlterable;
  42. //
  43. // Get the current cert used by T.120
  44. //
  45. security = ConfPolicies::GetSecurityLevel();
  46. switch (security)
  47. {
  48. case DISABLED_POL_SECURITY:
  49. fBtnsAlterable = FALSE;
  50. fIncomingOn = FALSE;
  51. fOutgoingOn = FALSE;
  52. break;
  53. case REQUIRED_POL_SECURITY:
  54. fBtnsAlterable = FALSE;
  55. fIncomingOn = TRUE;
  56. fOutgoingOn = TRUE;
  57. break;
  58. default:
  59. fBtnsAlterable = TRUE;
  60. fIncomingOn = ConfPolicies::IncomingSecurityRequired();
  61. fOutgoingOn = ConfPolicies::OutgoingSecurityPreferred();
  62. break;
  63. }
  64. // Incoming
  65. ::CheckDlgButton(hDlg, IDC_SEC_INCOMING, fIncomingOn);
  66. ::EnableWindow(::GetDlgItem(hDlg, IDC_SEC_INCOMING), fBtnsAlterable);
  67. // Outgoing
  68. ::CheckDlgButton(hDlg, IDC_SEC_OUTGOING, fOutgoingOn);
  69. ::EnableWindow(::GetDlgItem(hDlg, IDC_SEC_OUTGOING), fBtnsAlterable);
  70. //
  71. // Set privacy versus authentication (cert used for security)
  72. //
  73. RegEntry re(CONFERENCING_KEY, HKEY_CURRENT_USER);
  74. BOOL fAuthentication = re.GetNumber(REGVAL_SECURITY_AUTHENTICATION,
  75. DEFAULT_SECURITY_AUTHENTICATION);
  76. //
  77. // If the user cert store is empty, reset the choice back
  78. // to privacy only
  79. //
  80. if ( fAuthentication && !NumUserCerts() )
  81. {
  82. re.SetValue(REGVAL_SECURITY_AUTHENTICATION, (DWORD)0);
  83. fAuthentication = 0;
  84. }
  85. // Handle certificate combo box.
  86. if (security != DISABLED_POL_SECURITY)
  87. {
  88. if ( !fAuthentication )
  89. {
  90. if ( TCHAR * pCertText = new TCHAR[MAX_PATH] )
  91. {
  92. FLoadString(IDS_GENERIC_NMDC_TEXT, pCertText, MAX_PATH);
  93. SetDlgItemText(hDlg,IDC_SECURE_CALL_EDIT,pCertText);
  94. delete [] pCertText;
  95. }
  96. }
  97. else
  98. {
  99. if ( GetT120ActiveCert( &g_pbEncodedCert,
  100. &g_cbEncodedCert ))
  101. {
  102. if (TCHAR * pCertText = FormatCert(g_pbEncodedCert,
  103. g_cbEncodedCert))
  104. {
  105. SetDlgItemText(hDlg,IDC_SECURE_CALL_EDIT,pCertText);
  106. delete [] pCertText;
  107. }
  108. else
  109. {
  110. WARNING_OUT(("FormatCert returns NULL"));
  111. }
  112. }
  113. else
  114. {
  115. WARNING_OUT(("SecurityDlgProc init: no T120 cert"));
  116. }
  117. }
  118. }
  119. else
  120. {
  121. EnableWindow(GetDlgItem(hDlg,IDC_SECURE_CALL_EDIT), FALSE);
  122. EnableWindow(GetDlgItem(hDlg,IDC_SEC_CHANGECERT), FALSE);
  123. EnableWindow(GetDlgItem(hDlg,IDC_SEC_PRIVACY_ONLY), FALSE);
  124. EnableWindow(GetDlgItem(hDlg,IDC_SEC_PRIVACY_AUTH), FALSE);
  125. }
  126. // Check the appropriate box:
  127. if (fAuthentication)
  128. {
  129. CheckRadioButton(hDlg, IDC_SEC_PRIVACY_ONLY, IDC_SEC_PRIVACY_AUTH,
  130. IDC_SEC_PRIVACY_AUTH);
  131. }
  132. else
  133. {
  134. CheckRadioButton(hDlg, IDC_SEC_PRIVACY_ONLY, IDC_SEC_PRIVACY_AUTH,
  135. IDC_SEC_PRIVACY_ONLY);
  136. EnableWindow(GetDlgItem(hDlg,IDC_SEC_CHANGECERT), FALSE);
  137. }
  138. return (TRUE);
  139. }
  140. case WM_NOTIFY:
  141. if (((NMHDR FAR *) lParam)->code == PSN_APPLY)
  142. {
  143. //
  144. // User can only change these settings if no policy
  145. // disabling security.
  146. //
  147. if (ConfPolicies::GetSecurityLevel() != DISABLED_POL_SECURITY)
  148. {
  149. RegEntry re(CONFERENCING_KEY, HKEY_CURRENT_USER);
  150. if (ConfPolicies::GetSecurityLevel() == DEFAULT_POL_SECURITY)
  151. {
  152. // Incoming
  153. re.SetValue(REGVAL_SECURITY_INCOMING_REQUIRED,
  154. (::IsDlgButtonChecked(hDlg, IDC_SEC_INCOMING) != FALSE));
  155. // Outgoing
  156. re.SetValue(REGVAL_SECURITY_OUTGOING_PREFERRED,
  157. (::IsDlgButtonChecked(hDlg, IDC_SEC_OUTGOING) != FALSE));
  158. }
  159. BOOL fAuth = (::IsDlgButtonChecked(hDlg,
  160. IDC_SEC_PRIVACY_AUTH) != FALSE);
  161. if ( fAuth )
  162. {
  163. if ( !SetT120ActiveCert ( FALSE, g_pbEncodedCert,
  164. g_cbEncodedCert ))
  165. {
  166. //
  167. // Did the new cert fail? if so put
  168. // up an error dialog.
  169. ConfMsgBox(hDlg, (LPCSTR)IDS_CERT_FAILED);
  170. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, -1);
  171. return PSNRET_INVALID_NOCHANGEPAGE;
  172. }
  173. else
  174. {
  175. SetT120CertInRegistry ( g_pbEncodedCert,
  176. g_cbEncodedCert );
  177. }
  178. }
  179. else
  180. {
  181. SetT120ActiveCert( TRUE, NULL, 0);
  182. }
  183. re.SetValue(REGVAL_SECURITY_AUTHENTICATION, fAuth );
  184. }
  185. }
  186. break;
  187. case WM_COMMAND:
  188. switch (GET_WM_COMMAND_ID(wParam, lParam))
  189. {
  190. case IDC_SEC_CHANGECERT:
  191. if (ChangeCertDlg(hDlg, ::GetInstanceHandle(),
  192. &g_pbEncodedCert, &g_cbEncodedCert ))
  193. {
  194. TCHAR * pCertText = FormatCert(g_pbEncodedCert,
  195. g_cbEncodedCert);
  196. if (pCertText)
  197. {
  198. SetDlgItemText(hDlg,IDC_SECURE_CALL_EDIT,pCertText);
  199. delete [] pCertText;
  200. }
  201. else
  202. {
  203. ERROR_OUT(("SEC_CHANGECERT: FormatCert failed"));
  204. }
  205. }
  206. break;
  207. case IDC_SEC_PRIVACY_AUTH:
  208. if (!NumUserCerts())
  209. {
  210. if ( SendDlgItemMessage(hDlg, IDC_SEC_PRIVACY_AUTH,
  211. BM_GETCHECK, 0, 0 ))
  212. {
  213. // Force setting back
  214. CheckRadioButton(hDlg, IDC_SEC_PRIVACY_ONLY,
  215. IDC_SEC_PRIVACY_AUTH, IDC_SEC_PRIVACY_ONLY);
  216. SetFocus(GetDlgItem(hDlg, IDC_SEC_PRIVACY_ONLY));
  217. // Bring up message box that this won't work:
  218. ConfMsgBox(hDlg, (LPCSTR)IDS_NO_USER_CERTS);
  219. }
  220. return (TRUE);
  221. }
  222. if ( !g_pbEncodedCert )
  223. {
  224. if ( !GetDefaultSystemCert( &g_pbEncodedCert,
  225. &g_cbEncodedCert ))
  226. {
  227. WARNING_OUT(("GetDefaultSystemCert failed"));
  228. }
  229. }
  230. if ( g_pbEncodedCert )
  231. {
  232. if (TCHAR * pCertText = FormatCert(g_pbEncodedCert,
  233. g_cbEncodedCert))
  234. {
  235. SetDlgItemText(hDlg,IDC_SECURE_CALL_EDIT,pCertText);
  236. delete [] pCertText;
  237. }
  238. else
  239. {
  240. WARNING_OUT(("FormatCert returns NULL"));
  241. }
  242. }
  243. else
  244. {
  245. WARNING_OUT(("SecurityDlgProc init: no T120 cert"));
  246. }
  247. EnableWindow(GetDlgItem(hDlg,IDC_SEC_CHANGECERT), TRUE);
  248. break;
  249. case IDC_SEC_PRIVACY_ONLY:
  250. if ( TCHAR * pCertText = new TCHAR[MAX_PATH] )
  251. {
  252. FLoadString(IDS_GENERIC_NMDC_TEXT, pCertText, MAX_PATH);
  253. SetDlgItemText(hDlg,IDC_SECURE_CALL_EDIT,pCertText);
  254. delete [] pCertText;
  255. }
  256. EnableWindow(GetDlgItem(hDlg,IDC_SEC_CHANGECERT), FALSE);
  257. break;
  258. }
  259. break;
  260. case WM_CONTEXTMENU:
  261. DoHelpWhatsThis(wParam, rgHelpIdsSecurity);
  262. break;
  263. case WM_HELP:
  264. DoHelp(lParam, rgHelpIdsSecurity);
  265. break;
  266. }
  267. return (FALSE);
  268. }