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.

230 lines
6.3 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1999 **
  4. //*********************************************************************
  5. //
  6. // auditmd.CPP - Implementation of CObWebBrowser
  7. //
  8. // HISTORY:
  9. //
  10. // 9/17/99 vyung Created.
  11. //
  12. // Class which will call up setupx.dll
  13. #include <windows.h>
  14. #include <windowsx.h>
  15. #include <io.h>
  16. #include <fcntl.h>
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include "appdefs.h"
  20. #include "msobmain.h"
  21. #include "resource.h"
  22. // The licence agreement needs to be in this path
  23. #define SZ_OEMAUDIT_LICENSE_TXT L"%SystemRoot%\\OPTIONS\\OEMLCNS.TXT" // text file for the oem license page
  24. #define SZ_EULA_LICENSE_TXT L"%SystemRoot%\\SYSTEM32\\EULA.TXT" // text file for the oem license page
  25. #define DX_MARGIN 4 // Pixels between status buttons.
  26. #define UI_POS_MARGIN 8 // Pixels to allow on edges.
  27. #define DLG_CENTERH 0x01
  28. #define DLG_CENTERV 0x02
  29. #define DLG_TOP 0x04
  30. #define DLG_BOTTOM 0x08
  31. #define DLG_RIGHT 0x10
  32. #define DLG_LEFT 0x11
  33. HINSTANCE ghInst = NULL;
  34. /****************************************************************************
  35. *
  36. * uiPositionDialog()
  37. *
  38. * This routine will position your dialog based on the flags
  39. * passed to it.
  40. *
  41. * ENTRY:
  42. * hwndDlg - Dialog window.
  43. * wPosFlags - Defines how to position the dialog. Valid flags are
  44. * DLG_CENTERV, DLG_CENTERH, DLG_TOP, DLG_BOTTOM,
  45. * DLG_RIGHT, DLG_LEFT, or DLG_CENTER.
  46. *
  47. * EXIT:
  48. * None.
  49. *
  50. * NOTES:
  51. * None.
  52. *
  53. ***************************************************************************/
  54. BOOL WINAPI uiPositionDialog( HWND hwndDlg, WORD wPosFlags )
  55. {
  56. RECT rc;
  57. int x, y;
  58. int cxDlg, cyDlg;
  59. int cxScreen = GetSystemMetrics( SM_CXSCREEN );
  60. int cyScreen = GetSystemMetrics( SM_CYSCREEN );
  61. GetWindowRect(hwndDlg, &rc);
  62. x = rc.left; // Default is to leave the dialog where the template
  63. y = rc.top; // was going to place it.
  64. cxDlg = rc.right - rc.left;
  65. cyDlg = rc.bottom - rc.top;
  66. if ( wPosFlags & DLG_TOP )
  67. {
  68. y = UI_POS_MARGIN;
  69. }
  70. if ( wPosFlags & DLG_BOTTOM )
  71. y = cyScreen - cyDlg;
  72. if ( wPosFlags & DLG_LEFT )
  73. {
  74. x = UI_POS_MARGIN;
  75. }
  76. if ( wPosFlags & DLG_RIGHT )
  77. {
  78. x = cxScreen - cxDlg;
  79. }
  80. if ( wPosFlags & DLG_CENTERV )
  81. {
  82. y = (cyScreen - cyDlg) / 2;
  83. }
  84. if ( wPosFlags & DLG_CENTERH )
  85. {
  86. x = (cxScreen - cxDlg) / 2;
  87. }
  88. // Position the dialog.
  89. //
  90. return SetWindowPos(hwndDlg, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  91. }
  92. BOOL FillInOEMAuditLicense(HWND hwnd)
  93. {
  94. DWORD reRet = 0;
  95. HANDLE hfile = NULL;
  96. DWORD dwBytesRead;
  97. TCHAR szEulaFile[MAX_PATH];
  98. ExpandEnvironmentStrings(SZ_EULA_LICENSE_TXT,
  99. szEulaFile,
  100. sizeof(szEulaFile)/sizeof(szEulaFile[0]));
  101. if (INVALID_HANDLE_VALUE != (hfile = CreateFile(szEulaFile,
  102. GENERIC_READ,
  103. 0,
  104. NULL,
  105. OPEN_EXISTING,
  106. FILE_ATTRIBUTE_NORMAL,
  107. NULL)))
  108. {
  109. DWORD dwFileSize = GetFileSize(hfile, NULL);
  110. if (dwFileSize <= 0xFFFF)
  111. {
  112. BYTE * lpszText = new BYTE[dwFileSize + 1];
  113. if (lpszText != NULL)
  114. {
  115. // Read complete file
  116. // Attempt a synchronous read operation.
  117. if (ReadFile(hfile, (LPVOID) lpszText, dwFileSize, &dwBytesRead, NULL) &&
  118. ( dwBytesRead != dwFileSize))
  119. {
  120. reRet = 100;
  121. }
  122. SetWindowTextA( GetDlgItem(hwnd, IDC_OEMLICENSE_TEXT), (LPCSTR)lpszText);
  123. delete [] lpszText;
  124. }
  125. else
  126. reRet = 102;
  127. }
  128. else
  129. reRet = 103;
  130. // Close the File
  131. CloseHandle(hfile);
  132. }
  133. else
  134. reRet = 101;
  135. return (reRet == 0);
  136. }
  137. // Dlg proc for the OEM license page. This is used in manual auditing.
  138. INT_PTR CALLBACK sxOemAuditLicenseDlgProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  139. {
  140. static HBRUSH hbrBkGnd = NULL;
  141. static DWORD dwAuditMode;
  142. WCHAR szTitle[MAX_PATH] = L"\0";
  143. switch( msg )
  144. {
  145. case WM_INITDIALOG:
  146. // Look for the OEM audit child windows
  147. LoadString(ghInst, IDS_OEM_LICENSE_DLG_TITLE, szTitle, MAX_CHARS_IN_BUFFER(szTitle));
  148. SetWindowText(hwnd, szTitle);
  149. SetFocus(hwnd);
  150. hbrBkGnd = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  151. // Checks if we allow maual audit boot
  152. if (FillInOEMAuditLicense(hwnd))
  153. uiPositionDialog( hwnd, DLG_CENTERH | DLG_CENTERV );
  154. else
  155. EndDialog(hwnd, IDCANCEL);
  156. return FALSE;
  157. case WM_CTLCOLOR:
  158. SetBkColor( (HDC)wParam, GetSysColor(COLOR_BTNFACE) );
  159. return (INT_PTR)hbrBkGnd;
  160. case WM_DESTROY:
  161. if (hbrBkGnd)
  162. DeleteObject(hbrBkGnd);
  163. hbrBkGnd = NULL;
  164. break;
  165. case WM_COMMAND:
  166. switch( wParam )
  167. {
  168. case IDOK:
  169. case IDCANCEL:
  170. EndDialog(hwnd, wParam);
  171. break;
  172. default:
  173. return FALSE;
  174. }
  175. break;
  176. default:
  177. return FALSE;
  178. }
  179. return TRUE;
  180. }
  181. BOOL ProcessAuditBoot(HINSTANCE hInst, HWND hwndParent)
  182. {
  183. ghInst = hInst;
  184. return (DialogBox(hInst, MAKEINTRESOURCE(IDD_OEMLICENSE), hwndParent, sxOemAuditLicenseDlgProc) == IDOK);
  185. }