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.

251 lines
8.9 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. dlgsec.c
  5. Abstract:
  6. This file implements the dialog proc for the
  7. security page. This page captures the account
  8. name that the fax service runs under.
  9. Environment:
  10. WIN32 User Mode
  11. Author:
  12. Wesley Witt (wesw) 17-Feb-1996
  13. --*/
  14. #include "wizard.h"
  15. #pragma hdrstop
  16. #define MY_SET_FOCUS (WM_USER+1000)
  17. LRESULT
  18. RouteSecurityDlgProc(
  19. HWND hwnd,
  20. UINT msg,
  21. WPARAM wParam,
  22. LPARAM lParam
  23. )
  24. {
  25. switch( msg ) {
  26. case WM_INITDIALOG:
  27. SendDlgItemMessage( hwnd, IDC_ACCOUNT_NAME, EM_SETLIMITTEXT, LT_ACCOUNT_NAME, 0 );
  28. SendDlgItemMessage( hwnd, IDC_PASSWORD, EM_SETLIMITTEXT, LT_PASSWORD, 0 );
  29. SendDlgItemMessage( hwnd, IDC_PASSWORD2, EM_SETLIMITTEXT, LT_PASSWORD, 0 );
  30. {
  31. HANDLE hProcess, hAccessToken;
  32. BYTE InfoBuffer[1000];
  33. TCHAR szAccountName[200], szDomainName[200];
  34. PTOKEN_USER pTokenUser = (PTOKEN_USER)InfoBuffer;
  35. DWORD dwInfoBufferSize,dwAccountSize = 200, dwDomainSize = 200;
  36. SID_NAME_USE snu;
  37. hProcess = GetCurrentProcess();
  38. OpenProcessToken(
  39. hProcess,
  40. TOKEN_READ,
  41. &hAccessToken
  42. );
  43. GetTokenInformation(
  44. hAccessToken,
  45. TokenUser,
  46. InfoBuffer,
  47. 1000,
  48. &dwInfoBufferSize
  49. );
  50. LookupAccountSid(
  51. NULL,
  52. pTokenUser->User.Sid,
  53. szAccountName,
  54. &dwAccountSize,
  55. szDomainName,
  56. &dwDomainSize,
  57. &snu
  58. );
  59. _stprintf( (LPTSTR)InfoBuffer, TEXT("%s\\%s"), szDomainName, szAccountName );
  60. SetDlgItemText( hwnd, IDC_ACCOUNT_NAME, (LPTSTR)InfoBuffer );
  61. }
  62. PostMessage( hwnd, MY_SET_FOCUS, 0, (LPARAM) GetDlgItem( hwnd, IDC_PASSWORD ) );
  63. return FALSE;
  64. case MY_SET_FOCUS:
  65. SetFocus( (HWND) lParam );
  66. SendMessage( (HWND) lParam, EM_SETSEL, 0, MAKELPARAM( 0, -1 ) );
  67. return FALSE;
  68. case WM_NOTIFY:
  69. switch( ((LPNMHDR)lParam)->code ) {
  70. case PSN_SETACTIVE:
  71. if (Unattended) {
  72. if (!UnAttendGetAnswer(
  73. UAA_ACCOUNT_NAME,
  74. (LPBYTE) WizData.AccountName,
  75. sizeof(WizData.AccountName)/sizeof(WCHAR)))
  76. {
  77. WizData.UseLocalSystem = TRUE;
  78. } else {
  79. if (!UnAttendGetAnswer(
  80. UAA_PASSWORD,
  81. (LPBYTE) WizData.Password,
  82. sizeof(WizData.Password)/sizeof(WCHAR)))
  83. {
  84. WizData.UseLocalSystem = TRUE;
  85. }
  86. }
  87. SetWindowLong( hwnd, DWL_MSGRESULT, -1 );
  88. return TRUE;
  89. }
  90. if (InstallMode != INSTALL_NEW) {
  91. SetWindowLong( hwnd, DWL_MSGRESULT, -1 );
  92. return TRUE;
  93. }
  94. break;
  95. case PSN_WIZNEXT:
  96. {
  97. TCHAR ConfirmPassword[64];
  98. SendDlgItemMessage(
  99. hwnd,
  100. IDC_ACCOUNT_NAME,
  101. WM_GETTEXT,
  102. sizeof(WizData.AccountName),
  103. (LPARAM) WizData.AccountName
  104. );
  105. SendDlgItemMessage(
  106. hwnd,
  107. IDC_PASSWORD,
  108. WM_GETTEXT,
  109. sizeof(WizData.Password),
  110. (LPARAM) WizData.Password
  111. );
  112. if (!WizData.AccountName[0]) {
  113. PopUpMsg( hwnd, IDS_ACCOUNTNAME, TRUE, 0 );
  114. SetWindowLong( hwnd, DWL_MSGRESULT, -1 );
  115. return TRUE;
  116. }
  117. SendDlgItemMessage(
  118. hwnd,
  119. IDC_PASSWORD2,
  120. WM_GETTEXT,
  121. sizeof(ConfirmPassword),
  122. (LPARAM) ConfirmPassword
  123. );
  124. if (_tcscmp( ConfirmPassword, WizData.Password ) != 0) {
  125. PopUpMsg( hwnd, IDS_PASSWORD, TRUE, 0 );
  126. SetWindowLong( hwnd, DWL_MSGRESULT, -1 );
  127. PostMessage( hwnd, MY_SET_FOCUS, 0, (LPARAM) GetDlgItem( hwnd, IDC_PASSWORD ) );
  128. return TRUE;
  129. }
  130. if (!_tcschr( WizData.AccountName, TEXT('\\'))) {
  131. TCHAR ComputerName[128];
  132. DWORD Size = sizeof(ComputerName);
  133. if (GetComputerName( ComputerName, &Size )) {
  134. _tcscat( ComputerName, TEXT("\\") );
  135. _tcscat( ComputerName, WizData.AccountName );
  136. _tcscpy( WizData.AccountName, ComputerName );
  137. SetDlgItemText( hwnd, IDC_ACCOUNT_NAME, WizData.AccountName );
  138. }
  139. }
  140. }
  141. break;
  142. }
  143. break;
  144. }
  145. return FALSE;
  146. }
  147. LRESULT
  148. SecurityErrorDlgProc(
  149. HWND hwnd,
  150. UINT message,
  151. WPARAM wParam,
  152. LPARAM lParam
  153. )
  154. {
  155. static PSECURITY_INFO SecurityInfo;
  156. switch( message ) {
  157. case WM_INITDIALOG:
  158. SendDlgItemMessage( hwnd, IDC_ACCOUNT_NAME, EM_SETLIMITTEXT, LT_ACCOUNT_NAME, 0 );
  159. SendDlgItemMessage( hwnd, IDC_PASSWORD, EM_SETLIMITTEXT, LT_PASSWORD, 0 );
  160. SendDlgItemMessage( hwnd, IDC_PASSWORD2, EM_SETLIMITTEXT, LT_PASSWORD, 0 );
  161. SecurityInfo = (PSECURITY_INFO) lParam;
  162. SetDlgItemText( hwnd, IDC_ACCOUNT_NAME, (LPTSTR) SecurityInfo->AccountName );
  163. SetDlgItemText( hwnd, IDC_PASSWORD, (LPTSTR) SecurityInfo->Password );
  164. SetDlgItemText( hwnd, IDC_PASSWORD2, (LPTSTR) SecurityInfo->Password );
  165. break;
  166. case WM_COMMAND:
  167. switch( wParam ) {
  168. case IDCANCEL:
  169. EndDialog( hwnd, 0 );
  170. return TRUE;
  171. case IDOK:
  172. {
  173. TCHAR ConfirmPassword[64];
  174. SendDlgItemMessage(
  175. hwnd,
  176. IDC_ACCOUNT_NAME,
  177. WM_GETTEXT,
  178. sizeof(SecurityInfo->AccountName),
  179. (LPARAM) SecurityInfo->AccountName
  180. );
  181. SendDlgItemMessage(
  182. hwnd,
  183. IDC_PASSWORD,
  184. WM_GETTEXT,
  185. sizeof(SecurityInfo->Password),
  186. (LPARAM) SecurityInfo->Password
  187. );
  188. if (!SecurityInfo->AccountName[0]) {
  189. PopUpMsg( hwnd, IDS_ACCOUNTNAME, TRUE, 0 );
  190. return TRUE;
  191. }
  192. SendDlgItemMessage(
  193. hwnd,
  194. IDC_PASSWORD2,
  195. WM_GETTEXT,
  196. sizeof(ConfirmPassword),
  197. (LPARAM) ConfirmPassword
  198. );
  199. if (_tcscmp( ConfirmPassword, SecurityInfo->Password ) != 0) {
  200. PopUpMsg( hwnd, IDS_PASSWORD, TRUE, 0 );
  201. return TRUE;
  202. }
  203. if (!_tcschr( SecurityInfo->AccountName, TEXT('\\'))) {
  204. TCHAR ComputerName[128];
  205. DWORD Size = sizeof(ComputerName);
  206. if (GetComputerName( ComputerName, &Size )) {
  207. _tcscat( ComputerName, TEXT("\\") );
  208. _tcscat( ComputerName, SecurityInfo->AccountName );
  209. _tcscpy( SecurityInfo->AccountName, ComputerName );
  210. }
  211. }
  212. }
  213. EndDialog( hwnd, 1 );
  214. return TRUE;
  215. }
  216. break;
  217. }
  218. return FALSE;
  219. }