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.

546 lines
16 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. // All rights reserved.
  5. //
  6. // File Name:
  7. // domain.c
  8. //
  9. // Description:
  10. // This file contains the dialog procedure for the domain join
  11. // page (IDD_DOMAINJ).
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "pch.h"
  15. #include "resource.h"
  16. //----------------------------------------------------------------------------
  17. //
  18. // Function: DlgDomainJoinPage
  19. // DomainPageChangeAccount
  20. // DomainPageChangeWorkgroup
  21. //
  22. // Purpose: These are the dialog procedure and friends for the domain
  23. // join page
  24. //
  25. //----------------------------------------------------------------------------
  26. //-------------------------------------------------------------------------
  27. //
  28. // Function: DomainPageChangeAccount
  29. //
  30. // Purpose: This function exists only to support the Domain Join page.
  31. // It is called whenever the user decides to create a computer
  32. // account (or not to). This function handles checking
  33. // the box and all of the (un)greying activities that must occur.
  34. //
  35. //-------------------------------------------------------------------------
  36. static VOID DomainPageChangeAccount(HWND hwnd, BOOL bCreateAccount)
  37. {
  38. EnableWindow( GetDlgItem( hwnd, IDC_DOMAINACCT), bCreateAccount );
  39. EnableWindow( GetDlgItem( hwnd, IDC_DOMAINPASSWD), bCreateAccount );
  40. EnableWindow( GetDlgItem( hwnd, IDC_USERACCOUNTLABEL), bCreateAccount );
  41. EnableWindow( GetDlgItem( hwnd, IDC_ACCTNAMELABEL), bCreateAccount );
  42. EnableWindow( GetDlgItem( hwnd, IDC_ACCTPSWDLABEL), bCreateAccount );
  43. EnableWindow( GetDlgItem( hwnd, IDC_CONFIRMLABEL), bCreateAccount );
  44. EnableWindow( GetDlgItem (hwnd, IDC_CONFIRMPASSWORD), bCreateAccount );
  45. CheckDlgButton( hwnd,
  46. IDC_CREATEACCT,
  47. bCreateAccount ? BST_CHECKED : BST_UNCHECKED );
  48. }
  49. //-------------------------------------------------------------------------
  50. //
  51. // Function: DomainPageChangeWorkgroup
  52. //
  53. // Purpose: This function exists only to support the Domain Join page.
  54. // It is called whenever the user selectes DOMAIN instead of
  55. // workgroup and vice versa. This function handles checking
  56. // the radio button and all of the (un)greying activities
  57. // that must occur.
  58. //
  59. //-------------------------------------------------------------------------
  60. static VOID DomainPageChangeWorkGroup(HWND hwnd,
  61. BOOL bWorkGroup,
  62. BOOL bCreateAccount)
  63. {
  64. BOOL bGreyAccountFields = FALSE;
  65. //
  66. // If workgroup is to be selected do the following:
  67. // 1. check the radio button
  68. // 2. ungrey the edit box for WORKGROUP
  69. // 3. grey the edit box for DOMAIN
  70. // 4. grey the check box for CREATE_ACCT
  71. //
  72. // If workgroup is not selected, then DOMAIN is. In this case,
  73. // do the oppositte.
  74. //
  75. CheckRadioButton(hwnd,
  76. IDC_RAD_WORKGROUP,
  77. IDC_RAD_DOMAIN,
  78. bWorkGroup ? IDC_RAD_WORKGROUP : IDC_RAD_DOMAIN);
  79. EnableWindow(GetDlgItem(hwnd, IDC_WORKGROUP), bWorkGroup);
  80. EnableWindow(GetDlgItem(hwnd, IDC_DOMAIN), !bWorkGroup);
  81. EnableWindow(GetDlgItem(hwnd, IDC_CREATEACCT), !bWorkGroup);
  82. //
  83. // The edit fields for the admin domain acct and passwd must be greyed
  84. // in the following cases:
  85. // 1. if workgroup is selected
  86. // 2. if domain is selected AND bCreateAccount checkbox is on.
  87. //
  88. // In other words, grey these always if workgroup is selected. If
  89. // workgroup is not selected, grey or un-grey them depending on whether
  90. // that bCreateAccount check-box is on or not.
  91. //
  92. // Note that if !bWorkgroup, then the DOMAIN name has been selected.
  93. //
  94. if ( bWorkGroup || !bCreateAccount )
  95. bGreyAccountFields = TRUE;
  96. DomainPageChangeAccount(hwnd, !bGreyAccountFields);
  97. }
  98. //----------------------------------------------------------------------------
  99. //
  100. // Function: OnDomainJoinInitDialog
  101. //
  102. // Purpose:
  103. //
  104. // Arguments:
  105. //
  106. // Returns:
  107. //
  108. //----------------------------------------------------------------------------
  109. VOID
  110. OnDomainJoinInitDialog( IN HWND hwnd ) {
  111. //
  112. // Set the text limits on the edit boxes
  113. //
  114. SendDlgItemMessage( hwnd,
  115. IDC_WORKGROUP,
  116. EM_LIMITTEXT,
  117. (WPARAM) MAX_WORKGROUP_LENGTH,
  118. (LPARAM) 0 );
  119. SendDlgItemMessage( hwnd,
  120. IDC_DOMAIN,
  121. EM_LIMITTEXT,
  122. (WPARAM) MAX_DOMAIN_LENGTH,
  123. (LPARAM) 0 );
  124. SendDlgItemMessage( hwnd,
  125. IDC_DOMAINACCT,
  126. EM_LIMITTEXT,
  127. (WPARAM) MAX_USERNAME_LENGTH,
  128. (LPARAM) 0 );
  129. SendDlgItemMessage( hwnd,
  130. IDC_DOMAINPASSWD,
  131. EM_LIMITTEXT,
  132. (WPARAM) MAX_DOMAIN_PASSWORD_LENGTH,
  133. (LPARAM) 0 );
  134. SendDlgItemMessage( hwnd,
  135. IDC_CONFIRMPASSWORD,
  136. EM_LIMITTEXT,
  137. (WPARAM) MAX_DOMAIN_PASSWORD_LENGTH,
  138. (LPARAM) 0 );
  139. }
  140. //----------------------------------------------------------------------------
  141. //
  142. // Function: OnDomainJoinSetActive
  143. //
  144. // Purpose:
  145. //
  146. // Arguments:
  147. //
  148. // Returns:
  149. //
  150. //----------------------------------------------------------------------------
  151. VOID
  152. OnDomainJoinSetActive( IN HWND hwnd ) {
  153. //
  154. // Make sure the right radio button is checked and controls are greyed out
  155. // properly
  156. //
  157. if( NetSettings.bWorkgroup ) {
  158. CheckRadioButton( hwnd,
  159. IDC_RAD_WORKGROUP,
  160. IDC_RAD_DOMAIN,
  161. IDC_RAD_WORKGROUP );
  162. DomainPageChangeWorkGroup( hwnd,
  163. TRUE,
  164. NetSettings.bCreateAccount );
  165. }
  166. else {
  167. CheckRadioButton( hwnd,
  168. IDC_RAD_WORKGROUP,
  169. IDC_RAD_DOMAIN,
  170. IDC_RAD_DOMAIN );
  171. DomainPageChangeWorkGroup( hwnd,
  172. FALSE,
  173. NetSettings.bCreateAccount );
  174. }
  175. //
  176. // Always re-fill the edit controls with the proper data here because
  177. // they might have reset or loaded from a new answer file
  178. //
  179. SendDlgItemMessage( hwnd,
  180. IDC_WORKGROUP,
  181. WM_SETTEXT,
  182. (WPARAM) MAX_WORKGROUP_LENGTH,
  183. (LPARAM) NetSettings.WorkGroupName );
  184. SendDlgItemMessage( hwnd,
  185. IDC_DOMAIN,
  186. WM_SETTEXT,
  187. (WPARAM) MAX_DOMAIN_LENGTH,
  188. (LPARAM) NetSettings.DomainName );
  189. SendDlgItemMessage( hwnd,
  190. IDC_DOMAINACCT,
  191. WM_SETTEXT,
  192. (WPARAM) MAX_USERNAME_LENGTH,
  193. (LPARAM) NetSettings.DomainAccount );
  194. SendDlgItemMessage( hwnd,
  195. IDC_DOMAINPASSWD,
  196. WM_SETTEXT,
  197. (WPARAM) MAX_DOMAIN_PASSWORD_LENGTH,
  198. (LPARAM) NetSettings.DomainPassword );
  199. SendDlgItemMessage( hwnd,
  200. IDC_CONFIRMPASSWORD,
  201. WM_SETTEXT,
  202. (WPARAM) MAX_DOMAIN_PASSWORD_LENGTH,
  203. (LPARAM) NetSettings.ConfirmPassword );
  204. WIZ_BUTTONS(hwnd, PSWIZB_BACK | PSWIZB_NEXT );
  205. }
  206. //----------------------------------------------------------------------------
  207. //
  208. // Function: OnWizNextDomainPage
  209. //
  210. // Purpose:
  211. //
  212. // Arguments: IN HWND hwnd - handle to the dialog
  213. //
  214. // Returns: BOOL
  215. //
  216. //----------------------------------------------------------------------------
  217. BOOL
  218. OnWizNextDomainPage( IN HWND hwnd ) {
  219. //
  220. // Retrieve all of the settings on this dialog but only
  221. // if they are valid
  222. //
  223. TCHAR szWorkgroupName[MAX_WORKGROUP_LENGTH + 1] = _T("");
  224. TCHAR szDomainName[MAX_DOMAIN_LENGTH + 1] = _T("");
  225. TCHAR szUsername[MAX_USERNAME_LENGTH + 1] = _T("");
  226. TCHAR szDomainPassword[MAX_DOMAIN_PASSWORD_LENGTH + 1] = _T("");
  227. TCHAR szConfirmPassword[MAX_DOMAIN_PASSWORD_LENGTH + 1] = _T("");
  228. BOOL bResult = TRUE;
  229. // ISSUE-2002/02/28-stelo- the only error checking done now is to
  230. // make sure none of the valid fields are empty, when I do more rigourous
  231. // error checking, try to clean up this code
  232. if( IsDlgButtonChecked( hwnd, IDC_RAD_WORKGROUP ) ) {
  233. // user selected to Join a Workgroup
  234. NetSettings.bWorkgroup = TRUE;
  235. //
  236. // Get the Workgroup string
  237. //
  238. SendDlgItemMessage( hwnd,
  239. IDC_WORKGROUP,
  240. WM_GETTEXT,
  241. (WPARAM) AS(szWorkgroupName),
  242. (LPARAM) szWorkgroupName );
  243. //
  244. // see if the string in szPassword is a valid Workgroup name
  245. //
  246. if( szWorkgroupName[0] != _T('\0') ) {
  247. lstrcpyn( NetSettings.WorkGroupName, szWorkgroupName, AS(NetSettings.WorkGroupName) );
  248. }
  249. else if( GenSettings.iUnattendMode == UMODE_FULL_UNATTENDED ) {
  250. //
  251. // only report an error on fully unattended
  252. //
  253. ReportErrorId( hwnd,
  254. MSGTYPE_ERR,
  255. IDS_ENTERWORKGROUP ) ;
  256. bResult = FALSE;
  257. }
  258. else {
  259. lstrcpyn( NetSettings.WorkGroupName, _T(""), AS(NetSettings.WorkGroupName) );
  260. }
  261. }
  262. else {
  263. // user selected to Join a Domain
  264. NetSettings.bWorkgroup = FALSE;
  265. //
  266. // Get the Domain string
  267. //
  268. SendDlgItemMessage( hwnd,
  269. IDC_DOMAIN,
  270. WM_GETTEXT,
  271. (WPARAM) AS(szDomainName),
  272. (LPARAM) szDomainName );
  273. //
  274. // see if the string in szBuffer is a valid Domain name
  275. //
  276. if( szDomainName[0] != _T('\0') ) {
  277. lstrcpyn( NetSettings.DomainName, szDomainName, AS(NetSettings.DomainName) );
  278. }
  279. else if( GenSettings.iUnattendMode == UMODE_FULL_UNATTENDED ) {
  280. //
  281. // only report an error on fully unattended
  282. //
  283. ReportErrorId( hwnd,
  284. MSGTYPE_ERR,
  285. IDS_ENTERNTDOMAIN );
  286. bResult = FALSE;
  287. }
  288. else {
  289. lstrcpyn( NetSettings.DomainName, _T(""), AS(NetSettings.DomainName) );
  290. }
  291. if( IsDlgButtonChecked( hwnd, IDC_CREATEACCT ) ) {
  292. SendDlgItemMessage( hwnd,
  293. IDC_DOMAINACCT,
  294. WM_GETTEXT,
  295. (WPARAM) AS(szUsername),
  296. (LPARAM) szUsername );
  297. if( szUsername[0] != _T('\0') ) {
  298. lstrcpyn( NetSettings.DomainAccount, szUsername, AS(NetSettings.DomainAccount) );
  299. }
  300. else {
  301. // don't print this error if we've already printed an error
  302. if( bResult ) {
  303. ReportErrorId( hwnd,
  304. MSGTYPE_ERR,
  305. IDS_ENTERUSERNAME );
  306. bResult = FALSE;
  307. }
  308. }
  309. SendDlgItemMessage( hwnd,
  310. IDC_DOMAINPASSWD,
  311. WM_GETTEXT,
  312. (WPARAM) AS(szDomainPassword),
  313. (LPARAM) szDomainPassword );
  314. SendDlgItemMessage( hwnd,
  315. IDC_CONFIRMPASSWORD,
  316. WM_GETTEXT,
  317. (WPARAM) AS(szConfirmPassword),
  318. (LPARAM) szConfirmPassword );
  319. if( lstrcmp( szDomainPassword, szConfirmPassword ) != 0 ) {
  320. // don't print this error if we've already printed an error
  321. if( bResult ) {
  322. ReportErrorId( hwnd,
  323. MSGTYPE_ERR,
  324. IDS_PASSWORDS_DONT_MATCH ) ;
  325. bResult = FALSE;
  326. }
  327. }
  328. else {
  329. //
  330. // The only reason why we are saving the confirm password is so that
  331. // the confirm edit box is cleared with the other boxes on a Reset
  332. //
  333. lstrcpyn( NetSettings.DomainPassword, szDomainPassword, AS(NetSettings.DomainPassword) );
  334. lstrcpyn( NetSettings.ConfirmPassword, szConfirmPassword, AS(NetSettings.ConfirmPassword) );
  335. }
  336. }
  337. }
  338. return ( bResult );
  339. }
  340. INT_PTR CALLBACK DlgDomainJoinPage(
  341. IN HWND hwnd,
  342. IN UINT uMsg,
  343. IN WPARAM wParam,
  344. IN LPARAM lParam)
  345. {
  346. BOOL bStatus = TRUE;
  347. switch (uMsg) {
  348. case WM_INITDIALOG:
  349. {
  350. OnDomainJoinInitDialog( hwnd );
  351. break;
  352. }
  353. case WM_COMMAND:
  354. {
  355. int nButtonId=LOWORD(wParam);
  356. switch ( nButtonId ) {
  357. case IDC_RAD_WORKGROUP:
  358. if ( HIWORD(wParam) == BN_CLICKED ) {
  359. DomainPageChangeWorkGroup(
  360. hwnd,
  361. TRUE,
  362. NetSettings.bCreateAccount);
  363. }
  364. break;
  365. case IDC_RAD_DOMAIN:
  366. if ( HIWORD(wParam) == BN_CLICKED ) {
  367. DomainPageChangeWorkGroup(
  368. hwnd,
  369. FALSE,
  370. NetSettings.bCreateAccount);
  371. }
  372. break;
  373. case IDC_CREATEACCT:
  374. if ( HIWORD(wParam) == BN_CLICKED ) {
  375. NetSettings.bCreateAccount =
  376. IsDlgButtonChecked(hwnd, IDC_CREATEACCT);
  377. DomainPageChangeAccount(
  378. hwnd,
  379. NetSettings.bCreateAccount);
  380. }
  381. break;
  382. default:
  383. bStatus = FALSE;
  384. break;
  385. }
  386. }
  387. break;
  388. case WM_NOTIFY:
  389. {
  390. LPNMHDR pnmh = (LPNMHDR)lParam;
  391. switch( pnmh->code ) {
  392. case PSN_QUERYCANCEL:
  393. WIZ_CANCEL(hwnd);
  394. break;
  395. case PSN_SETACTIVE:
  396. g_App.dwCurrentHelp = IDH_WKGP_DOMN;
  397. OnDomainJoinSetActive( hwnd );
  398. break;
  399. case PSN_WIZBACK:
  400. bStatus = FALSE;
  401. break;
  402. case PSN_WIZNEXT:
  403. if ( !OnWizNextDomainPage( hwnd ) )
  404. WIZ_FAIL(hwnd);
  405. else
  406. bStatus = FALSE;
  407. break;
  408. case PSN_HELP:
  409. WIZ_HELP();
  410. break;
  411. default:
  412. bStatus = FALSE;
  413. break;
  414. }
  415. }
  416. break;
  417. default:
  418. bStatus = FALSE;
  419. break;
  420. }
  421. return bStatus;
  422. }