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.

811 lines
24 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. Finish.cpp : implementation file
  5. CPropertyPage support for User mgmt wizard
  6. File History:
  7. JonY Apr-96 created
  8. --*/
  9. #include "stdafx.h"
  10. #include "Speckle.h"
  11. #include "wizbased.h"
  12. #include "Finish.h"
  13. #include "transbmp.h"
  14. #include <lmaccess.h>
  15. #include <lmapibuf.h>
  16. #include <lmcons.h>
  17. typedef long NTSTATUS;
  18. extern "C"
  19. {
  20. #include <fpnwcomm.h>
  21. #include <usrprop.h>
  22. }
  23. #include <rassapi.h>
  24. #include "dapi.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. typedef ULONG (*SWAPOBJECTID) (ULONG);
  30. typedef ULONG (*MAPRIDTOOBJECTID) (DWORD, LPWSTR, BOOL, BOOL);
  31. typedef NTSTATUS (*GETREMOTENCPSECRETKEY) (PUNICODE_STRING, CHAR *);
  32. typedef NTSTATUS (*RETURNNETWAREFORM)(const char *, DWORD, const WCHAR *, UCHAR *);
  33. typedef NTSTATUS (*SETUSERPROPERTY)(LPWSTR, LPWSTR, UNICODE_STRING, WCHAR, LPWSTR*, BOOL*);
  34. typedef DWORD (*RASADMINGETUSERACCOUNTSERVER)(const WCHAR*, const WCHAR*, LPWSTR);
  35. typedef DWORD (*RASADMINUSERSETINFO)(const WCHAR*, const WCHAR*, const PRAS_USER_0);
  36. typedef DWORD (*BATCHIMPORT) (LPBIMPORT_PARMSW);
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CFinish property page
  39. IMPLEMENT_DYNCREATE(CFinish, CWizBaseDlg)
  40. CFinish::CFinish() : CWizBaseDlg(CFinish::IDD)
  41. {
  42. //{{AFX_DATA_INIT(CFinish)
  43. m_csCaption = _T("");
  44. //}}AFX_DATA_INIT
  45. }
  46. CFinish::~CFinish()
  47. {
  48. }
  49. void CFinish::DoDataExchange(CDataExchange* pDX)
  50. {
  51. CPropertyPage::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(CFinish)
  53. DDX_Text(pDX, IDC_STATIC1, m_csCaption);
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(CFinish, CWizBaseDlg)
  57. //{{AFX_MSG_MAP(CFinish)
  58. ON_WM_SHOWWINDOW()
  59. ON_WM_PAINT()
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CFinish message handlers
  64. BOOL CFinish::OnInitDialog()
  65. {
  66. CPropertyPage::OnInitDialog();
  67. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  68. return TRUE; // return TRUE unless you set the focus to a control
  69. // EXCEPTION: OCX Property Pages should return FALSE
  70. }
  71. LRESULT CFinish::OnWizardBack()
  72. {
  73. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  74. pApp->m_cps1.SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
  75. if (pApp->m_bNW & pApp->m_bEnableRestrictions) return IDD_NWLOGON_DIALOG;
  76. else if (pApp->m_bWorkstation & pApp->m_bEnableRestrictions) return IDD_LOGONTO_DLG;
  77. else if (pApp->m_bHours & pApp->m_bEnableRestrictions) return IDD_HOURS_DLG;
  78. else if (pApp->m_bExpiration & pApp->m_bEnableRestrictions) return IDD_ACCOUNT_EXP_DIALOG;
  79. return IDD_RESTRICTIONS_DIALOG;
  80. }
  81. BOOL CFinish::OnWizardFinish()
  82. {
  83. CString csSuccess, csTemp;
  84. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  85. CWaitCursor wait;
  86. TCHAR* pDomainServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  87. PUSER_INFO_3 pui1 = (PUSER_INFO_3)VirtualAlloc(NULL, sizeof(_USER_INFO_3), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  88. pui1->usri3_name = pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength());
  89. pui1->usri3_password = pApp->m_csPassword1.GetBuffer(pApp->m_csPassword1.GetLength());
  90. pui1->usri3_priv = USER_PRIV_USER;
  91. pui1->usri3_comment = pApp->m_csDescription.GetBuffer(pApp->m_csDescription.GetLength());
  92. pui1->usri3_flags = dwPasswordFlags();
  93. // availability hours - has to stay here to get the proper defaults!
  94. if (pApp->m_bHours) pui1->usri3_logon_hours = NULL;
  95. DWORD dwRet;
  96. NET_API_STATUS napi = NetUserAdd((unsigned short*)pDomainServer, (DWORD)1, (unsigned char*)pui1, &dwRet);
  97. VirtualFree(pui1, 0, MEM_RELEASE | MEM_DECOMMIT);
  98. if (napi != 0)
  99. {
  100. csTemp.LoadString(IDS_NO_NEW_USER);
  101. csSuccess.Format(csTemp, pApp->m_csFullName, pApp->m_csUserName);
  102. if (AfxMessageBox(csSuccess, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
  103. {
  104. pApp->m_cps1.SetActivePage(0);
  105. return FALSE;
  106. }
  107. else return TRUE;
  108. }
  109. // set local group memberships
  110. short sGroupCount = pApp->m_csaSelectedLocalGroups.GetSize();
  111. short sCount;
  112. CString csVal;
  113. for (sCount = 0; sCount < sGroupCount; sCount++)
  114. {
  115. csVal = pApp->m_csaSelectedLocalGroups.GetAt(sCount);
  116. if (!bAddLocalGroups(csVal.GetBuffer(csVal.GetLength())))
  117. {
  118. AfxMessageBox(IDS_NO_LOCAL_GROUP);
  119. break;
  120. }
  121. }
  122. // set global group memberships
  123. sGroupCount = pApp->m_csaSelectedGlobalGroups.GetSize();
  124. for (sCount = 0; sCount < sGroupCount; sCount++)
  125. {
  126. csVal = pApp->m_csaSelectedGlobalGroups.GetAt(sCount);
  127. if (!bAddGlobalGroups(csVal.GetBuffer(csVal.GetLength())))
  128. {
  129. AfxMessageBox(IDS_NO_GLOBAL_GROUP);
  130. break;
  131. }
  132. }
  133. pApp->m_csUserName.ReleaseBuffer();
  134. pApp->m_csPassword1.ReleaseBuffer();
  135. pApp->m_csDescription.ReleaseBuffer();
  136. // more information to be set
  137. PUSER_INFO_3 pui2 = (PUSER_INFO_3)VirtualAlloc(NULL, sizeof(_USER_INFO_3), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  138. napi = NetUserGetInfo((unsigned short*)pDomainServer,
  139. pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength()),
  140. 3,
  141. (LPBYTE*)&pui2);
  142. if (napi != ERROR_SUCCESS) goto failure;
  143. if (pApp->m_bHours) pui2->usri3_logon_hours = pApp->m_pHours;
  144. // full name
  145. pui2->usri3_full_name = pApp->m_csFullName.GetBuffer(pApp->m_csFullName.GetLength());
  146. pApp->m_csFullName.ReleaseBuffer();
  147. // seconds till expiration
  148. if (pApp->m_bExpiration) pui2->usri3_acct_expires = pApp->m_dwExpirationDate;
  149. if (pApp->m_bLoginScript)
  150. {
  151. pui2->usri3_script_path = pApp->m_csLogonScript.GetBuffer(pApp->m_csLogonScript.GetLength());
  152. pApp->m_csLogonScript.ReleaseBuffer();
  153. }
  154. if (pApp->m_bHomeDir)
  155. {
  156. pui2->usri3_home_dir = pApp->m_csHomeDir.GetBuffer(pApp->m_csHomeDir.GetLength());
  157. pApp->m_csHomeDir.ReleaseBuffer();
  158. }
  159. if (pApp->m_bProfile)
  160. {
  161. pui2->usri3_profile = pApp->m_csProfilePath.GetBuffer(pApp->m_csProfilePath.GetLength());
  162. pApp->m_csProfilePath.ReleaseBuffer();
  163. }
  164. // home dir drive
  165. if (pApp->m_bHomeDir)
  166. {
  167. pui2->usri3_home_dir_drive = pApp->m_csHome_dir_drive.GetBuffer(pApp->m_csHome_dir_drive.GetLength());
  168. pApp->m_csHome_dir_drive.ReleaseBuffer();
  169. }
  170. // available workstations
  171. if (pApp->m_bWorkstation)
  172. {
  173. pui2->usri3_workstations = pApp->m_csAllowedMachines.GetBuffer(pApp->m_csAllowedMachines.GetLength());
  174. pApp->m_csAllowedMachines.ReleaseBuffer();
  175. }
  176. if (pApp->m_bMust_Change_PW) pui2->usri3_password_expired = 1;
  177. // primary group id //accept the default! will become domain users.
  178. pui2->usri3_primary_group_id = DOMAIN_GROUP_RID_USERS;
  179. DWORD dwBuf;
  180. napi = NetUserSetInfo((unsigned short*)pDomainServer,
  181. pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength()),
  182. 3,
  183. (LPBYTE)pui2,
  184. &dwBuf);
  185. VirtualFree(pui2, 0, MEM_RELEASE | MEM_DECOMMIT);
  186. if (napi != ERROR_SUCCESS) goto failure;
  187. // NetWare compatible?
  188. if (pApp->m_bNW)
  189. {
  190. TCHAR* pUsername = pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength());
  191. pApp->m_csUserName.ReleaseBuffer();
  192. // get NWSETINFO fn
  193. HINSTANCE hLib = LoadLibrary(L"fpnwclnt.dll");
  194. //
  195. // SetUserProperty has been moved from fpnwclnt.dll to netapi32.dll
  196. // for the RAS guys. We no longer have to dynamically link it in.
  197. //
  198. #if 0
  199. SETUSERPROPERTY pSetUserProperty = (SETUSERPROPERTY)GetProcAddress(hLib, "SetUserProperty");
  200. #endif
  201. UNICODE_STRING uString;
  202. BOOL bRet;
  203. // first set the password
  204. CString ucPW = pApp->m_csPassword1;
  205. ucPW.MakeUpper();
  206. UCHAR* pNWPW = (UCHAR*)malloc(16);
  207. ULONG ulRet = ReturnNetwareEncryptedPassword(pui2->usri3_user_id,
  208. pui2->usri3_name,
  209. pApp->m_bDomain,
  210. (LPCTSTR)ucPW,
  211. pNWPW);
  212. if (ulRet != 0)
  213. {
  214. AfxMessageBox(IDS_NW_PW_ERROR);
  215. goto failure;
  216. }
  217. try
  218. {
  219. uString.Length = NWENCRYPTEDPASSWORDLENGTH * sizeof(WCHAR);
  220. uString.MaximumLength = NWENCRYPTEDPASSWORDLENGTH * sizeof(WCHAR);
  221. uString.Buffer = (PWCHAR)pNWPW;
  222. bRet = SetUserParam(uString, NWPASSWORD);
  223. }
  224. catch(...)
  225. {
  226. AfxMessageBox(IDS_NW_PW_ERROR);
  227. goto failure;
  228. }
  229. // grace logins - allowed
  230. try
  231. {
  232. uString.Length = 2;
  233. uString.MaximumLength = 2;
  234. uString.Buffer = &pApp->m_sNWRemainingGraceLogins;
  235. bRet = SetUserParam(uString, GRACELOGINREMAINING);
  236. uString.Buffer = &pApp->m_sNWAllowedGraceLogins;
  237. bRet = SetUserParam(uString, GRACELOGINALLOWED);
  238. }
  239. catch(...)
  240. {
  241. AfxMessageBox(IDS_NW_GRACELOGIN_ERROR);
  242. goto failure;
  243. }
  244. // concurrent connections
  245. try
  246. {
  247. uString.Length = 2;
  248. uString.MaximumLength = 2;
  249. uString.Buffer = &pApp->m_sNWConcurrentConnections;
  250. bRet = SetUserParam(uString, MAXCONNECTIONS);
  251. }
  252. catch(...)
  253. {
  254. AfxMessageBox(IDS_NW_CONCON_ERROR);
  255. goto failure;
  256. }
  257. // set allowed machines
  258. try
  259. {
  260. TCHAR* pNWWks = pApp->m_csAllowedLoginFrom.GetBuffer(pApp->m_csAllowedLoginFrom.GetLength());
  261. pApp->m_csAllowedLoginFrom.ReleaseBuffer();
  262. if (SetNWWorkstations(pNWWks) != ERROR_SUCCESS)
  263. {
  264. AfxMessageBox(IDS_NOFP_WS);
  265. goto failure;
  266. }
  267. }
  268. catch(...)
  269. {
  270. AfxMessageBox(IDS_NOFP_WS);
  271. goto failure;
  272. }
  273. // all done?
  274. FreeLibrary(hLib);
  275. if (pNWPW != NULL) free(pNWPW);
  276. }
  277. // RAS
  278. HINSTANCE hLib;
  279. if ((hLib = LoadLibrary(L"rassapi.dll")) != NULL && pApp->m_bRAS)
  280. {
  281. RASADMINGETUSERACCOUNTSERVER pRasAdminGetUserAccountServer = (RASADMINGETUSERACCOUNTSERVER)GetProcAddress(hLib, "RasAdminGetUserAccountServer");
  282. RASADMINUSERSETINFO pRasAdminUserSetInfo = (RASADMINUSERSETINFO)GetProcAddress(hLib, "RasAdminUserSetInfo");
  283. TCHAR pAccount[30];
  284. TCHAR* pDomain = pApp->m_csDomain.GetBuffer(pApp->m_csDomain.GetLength());
  285. pApp->m_csDomain.ReleaseBuffer();
  286. DWORD dwErr = pRasAdminGetUserAccountServer(pDomain, pDomainServer, pAccount);
  287. PRAS_USER_0 pBit = (PRAS_USER_0)malloc(sizeof(_RAS_USER_0) + 1);
  288. ZeroMemory(pBit, sizeof(RAS_USER_0));
  289. pBit->bfPrivilege = 0;
  290. // this is always set since they selected RAS in the first place
  291. pBit->bfPrivilege |= RASPRIV_DialinPrivilege;
  292. switch(pApp->m_sCallBackType)
  293. {
  294. case 0:
  295. pBit->bfPrivilege |= RASPRIV_NoCallback;
  296. break;
  297. case 1:
  298. pBit->bfPrivilege |= RASPRIV_CallerSetCallback;
  299. break;
  300. case 2:
  301. pBit->bfPrivilege |= RASPRIV_AdminSetCallback;
  302. _tcscpy(pBit->szPhoneNumber, (LPCTSTR)pApp->m_csRasPhoneNumber);
  303. break;
  304. }
  305. dwErr = pRasAdminUserSetInfo(pAccount, pui1->usri3_name, pBit);
  306. if (dwErr != ERROR_SUCCESS)
  307. {
  308. AfxMessageBox(IDS_RAS_ERROR);
  309. DWORD dd = GetLastError();
  310. CString cs;
  311. cs.Format(L"getlasterror = %d, dwerr = %d", dd, dwErr);
  312. AfxMessageBox(cs);
  313. goto failure;
  314. }
  315. FreeLibrary(hLib);
  316. free(pBit);
  317. }
  318. // exchange?
  319. if (pApp->m_bExchange)
  320. {
  321. // pApp->m_csExchangeServer = L"IRIS2";
  322. // first create the script file
  323. TCHAR lpPath[MAX_PATH];
  324. UINT ui = GetTempFileName(L".", L"auw", 0, lpPath);
  325. if (ui == 0)
  326. goto failure;
  327. HANDLE hFile = CreateFile(lpPath,
  328. GENERIC_READ | GENERIC_WRITE,
  329. 0,
  330. NULL,
  331. CREATE_ALWAYS,
  332. FILE_ATTRIBUTE_NORMAL,
  333. NULL);
  334. if (hFile == INVALID_HANDLE_VALUE)
  335. goto failure;
  336. TCHAR pHeader[] = L"OBJ-CLASS, Common-Name, Home-Server, Comment, Hide-from-address-book, Display-name\n\r";
  337. DWORD dwLen = _tcslen(pHeader) * sizeof(TCHAR);
  338. DWORD dwBytesWritten;
  339. BOOL bVal = WriteFile(hFile,
  340. pHeader,
  341. dwLen,
  342. &dwBytesWritten,
  343. NULL);
  344. if (!bVal)
  345. goto failure;
  346. // now write the user's info
  347. CString csExchangeVal;
  348. csExchangeVal.Format(L"MAILBOX, %s, %s, %s, 0, %s",
  349. pApp->m_csUserName,
  350. pApp->m_csExchangeServer,
  351. pApp->m_csDescription,
  352. pApp->m_csFullName);
  353. bVal = WriteFile(hFile,
  354. (LPCTSTR)csExchangeVal,
  355. csExchangeVal.GetLength() * sizeof(TCHAR),
  356. &dwBytesWritten,
  357. NULL);
  358. if (!bVal)
  359. goto failure;
  360. // batch import function
  361. BIMPORT_PARMSW* pBImport = (BIMPORT_PARMSW*)malloc(sizeof(BIMPORT_PARMSW) * sizeof(TCHAR));
  362. ZeroMemory(pBImport, sizeof(BIMPORT_PARMSW) * sizeof(TCHAR));
  363. pBImport->dwDAPISignature = DAPI_SIGNATURE;
  364. pBImport->dwFlags = DAPI_YES_TO_ALL | DAPI_SUPPRESS_PROGRESS |
  365. DAPI_SUPPRESS_COMPLETION | DAPI_SUPPRESS_ARCHIVES;
  366. pBImport->hwndParent = GetSafeHwnd();
  367. pBImport->pszImportFile = lpPath; // path to filename
  368. pBImport->uCodePage = DAPI_UNICODE_FILE; // UNICODE file
  369. pBImport->pszDSAName = pApp->m_csExchangeServer.GetBuffer(pApp->m_csExchangeServer.GetLength()); // this is the exchange server we are adding to
  370. pApp->m_csExchangeServer.ReleaseBuffer();
  371. pBImport->pszBasePoint = NULL;
  372. pBImport->pszContainer = L"Recipients";
  373. pBImport->chColSep = DAPI_DEFAULT_DELIMW; // default column sep
  374. pBImport->chQuote = DAPI_DEFAULT_QUOTEW; // default quote mark
  375. pBImport->chMVSep = DAPI_DEFAULT_MV_SEPW; // multi value column sep
  376. pBImport->pszNTDomain = pApp->m_csDomain.GetBuffer(pApp->m_csDomain.GetLength());// Domain to lookup accounts in
  377. pApp->m_csDomain.ReleaseBuffer();
  378. pBImport->pszCreateTemplate = NULL; // template user
  379. HINSTANCE hExLib = LoadLibrary(L"dapi.dll");
  380. if (hExLib == NULL)
  381. goto failure;
  382. BATCHIMPORT pBatchImport = (BATCHIMPORT)GetProcAddress(hExLib, "BatchImportW@4");
  383. if (pBatchImport == NULL)
  384. goto failure;
  385. CloseHandle(hFile);// have to close the file before exch can see it
  386. DWORD dw = pBatchImport(pBImport);
  387. // don't forget to delete the tmp file
  388. FreeLibrary(hExLib);
  389. DeleteFile(lpPath);
  390. free(pBImport);
  391. if (dw != ERROR_SUCCESS) goto failure;
  392. }
  393. if (pApp->m_csFullName != L"")
  394. {
  395. csTemp.LoadString(IDS_SUCCESS);
  396. csSuccess.Format(csTemp, pApp->m_csFullName, pApp->m_csUserName);
  397. }
  398. else
  399. {
  400. csTemp.LoadString(IDS_SUCCESS2);
  401. csSuccess.Format(csTemp, pApp->m_csUserName);
  402. }
  403. if (AfxMessageBox(csSuccess, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
  404. {
  405. pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT);
  406. pApp->m_cps1.SetActivePage(0);
  407. pApp->m_bPRSReset = TRUE;
  408. pApp->m_bPWReset = TRUE;
  409. // pApp->m_bGReset = TRUE;
  410. return FALSE;
  411. }
  412. else return TRUE;
  413. failure:
  414. if (pApp->m_csFullName != L"")
  415. {
  416. csTemp.LoadString(IDS_BAD_USER_DATA);
  417. csSuccess.Format(csTemp, pApp->m_csFullName, pApp->m_csUserName);
  418. }
  419. else
  420. {
  421. csTemp.LoadString(IDS_BAD_USER_DATA2);
  422. csSuccess.Format(csTemp, pApp->m_csUserName);
  423. }
  424. csSuccess.Format(csTemp, pApp->m_csFullName, pApp->m_csUserName);
  425. if (AfxMessageBox(csSuccess, MB_YESNO | MB_ICONEXCLAMATION) == IDYES)
  426. {
  427. pApp->m_cps1.SetWizardButtons(PSWIZB_NEXT);
  428. pApp->m_cps1.SetActivePage(0);
  429. pApp->m_bPRSReset = TRUE;
  430. pApp->m_bPWReset = TRUE;
  431. return FALSE;
  432. }
  433. else return TRUE;
  434. }
  435. DWORD CFinish::dwPasswordFlags()
  436. {
  437. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  438. DWORD dwFlags = UF_SCRIPT;
  439. if (pApp->m_bDisabled) dwFlags |= UF_ACCOUNTDISABLE;
  440. if (!pApp->m_bChange_Password) dwFlags |= UF_PASSWD_CANT_CHANGE;
  441. if (pApp->m_bPW_Never_Expires) dwFlags |= UF_DONT_EXPIRE_PASSWD;
  442. return dwFlags;
  443. }
  444. BOOL CFinish::bAddLocalGroups(LPWSTR lpwGroupName)
  445. {
  446. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  447. TCHAR* pDomainServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  448. LOCALGROUP_MEMBERS_INFO_3 localgroup_members;
  449. localgroup_members.lgrmi3_domainandname = pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength());
  450. DWORD err = NetLocalGroupAddMembers( (unsigned short*)pDomainServer, /* PDC name */
  451. lpwGroupName, /* group name */
  452. 3, /* passing in name */
  453. (LPBYTE)&localgroup_members, /* Buffer */
  454. 1 ); /* count passed in */
  455. pApp->m_csUserName.ReleaseBuffer();
  456. pApp->m_csServer.ReleaseBuffer();
  457. if (err != 0) return FALSE;
  458. return TRUE;
  459. }
  460. BOOL CFinish::bAddGlobalGroups(LPTSTR lpwGroupName)
  461. {
  462. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  463. TCHAR* pDomainServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  464. DWORD dwErr = NetGroupAddUser((LPTSTR)pDomainServer,
  465. lpwGroupName,
  466. pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength()));
  467. pApp->m_csUserName.ReleaseBuffer();
  468. pApp->m_csServer.ReleaseBuffer();
  469. if ((dwErr != 0) && (dwErr != 2236)) return FALSE;
  470. return TRUE;
  471. }
  472. ULONG
  473. CFinish::ReturnNetwareEncryptedPassword(DWORD UserId,
  474. LPWSTR pszUserName,
  475. BOOL bDomain,
  476. LPCTSTR clearTextPassword,
  477. UCHAR* NetwareEncryptedPassword ) // 16 byte encrypted password
  478. {
  479. char lsaSecret[20];
  480. NTSTATUS status;
  481. ULONG objectId;
  482. HINSTANCE hLib = LoadLibrary(L"fpnwclnt.dll");
  483. if (hLib == NULL) return 1;
  484. // if this is a server, modify the User ID:
  485. if (bDomain) UserId |= 0x10000000;
  486. // get lsa key from GetNcpSecretKey
  487. GETREMOTENCPSECRETKEY pGetRemoteNcpSecretKey = (GETREMOTENCPSECRETKEY)GetProcAddress(hLib, "GetRemoteNcpSecretKey");
  488. if (pGetRemoteNcpSecretKey == NULL) return 1;
  489. UNICODE_STRING usServer;
  490. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  491. usServer.Length = pApp->m_csServer.GetLength() * sizeof(WCHAR);
  492. usServer.MaximumLength = pApp->m_csServer.GetLength() * sizeof(WCHAR);
  493. usServer.Buffer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  494. pApp->m_csServer.ReleaseBuffer();
  495. status = (*pGetRemoteNcpSecretKey)( &usServer, lsaSecret );
  496. if (status != ERROR_SUCCESS) return 1;
  497. // Convert rid to object id
  498. MAPRIDTOOBJECTID pMapRidToObjectId = (MAPRIDTOOBJECTID)GetProcAddress(hLib, "MapRidToObjectId");
  499. if (pMapRidToObjectId == NULL) return 1;
  500. objectId = (*pMapRidToObjectId)( UserId, pszUserName, bDomain, FALSE );
  501. // now get the password
  502. RETURNNETWAREFORM pReturnNetwareForm = (RETURNNETWAREFORM)GetProcAddress(hLib, "ReturnNetwareForm");
  503. if (pReturnNetwareForm == NULL) return 1;
  504. try
  505. {
  506. status = (*pReturnNetwareForm)( lsaSecret,
  507. objectId,
  508. clearTextPassword,
  509. NetwareEncryptedPassword);
  510. }
  511. catch(...)
  512. {
  513. FreeLibrary(hLib);
  514. return 1L;
  515. }
  516. // clean up
  517. FreeLibrary(hLib);
  518. return 0L;
  519. }
  520. BOOL CFinish::SetUserParam(UNICODE_STRING uString, LPWSTR lpwProp)
  521. {
  522. // get existing prop value
  523. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  524. TCHAR* pUsername = pApp->m_csUserName.GetBuffer(pApp->m_csUserName.GetLength());
  525. pApp->m_csUserName.ReleaseBuffer();
  526. TCHAR* pServer = pApp->m_csServer.GetBuffer(pApp->m_csServer.GetLength());
  527. pApp->m_csServer.ReleaseBuffer();
  528. PUSER_INFO_3 pui2 = (PUSER_INFO_3)VirtualAlloc(NULL, sizeof(_USER_INFO_3), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
  529. NET_API_STATUS napi = NetUserGetInfo(pServer,
  530. pUsername,
  531. 3,
  532. (LPBYTE*)&pui2);
  533. // set NW prop
  534. //
  535. // SetUserProperty has been moved from fpnwclnt.dll to netapi32.dll
  536. // for the RAS guys. We no longer have to dynamically link it in.
  537. //
  538. #if 0
  539. HINSTANCE hLib = LoadLibrary(L"fpnwclnt.dll");
  540. SETUSERPROPERTY pSetUserProperty = (SETUSERPROPERTY)GetProcAddress(hLib, "SetUserProperty");
  541. #endif
  542. LPWSTR lpNewProp = NULL;
  543. BOOL bUpdate;
  544. NTSTATUS status = NetpParmsSetUserProperty((LPWSTR)pui2->usri3_parms,
  545. (LPWSTR)lpwProp,
  546. uString,
  547. USER_PROPERTY_TYPE_ITEM,
  548. &lpNewProp,
  549. &bUpdate);
  550. if (status != ERROR_SUCCESS) return FALSE;
  551. // reset user prop
  552. DWORD dwBuf;
  553. if (bUpdate)
  554. {
  555. pui2->usri3_parms = lpNewProp;
  556. napi = NetUserSetInfo(pServer,
  557. pUsername,
  558. 3,
  559. (LPBYTE)pui2,
  560. &dwBuf);
  561. }
  562. if (lpNewProp != NULL) NetpParmsUserPropertyFree(lpNewProp);
  563. VirtualFree(pui2, 0, MEM_RELEASE | MEM_DECOMMIT);
  564. // FreeLibrary(hLib);
  565. return TRUE;
  566. }
  567. void CFinish::OnShowWindow(BOOL bShow, UINT nStatus)
  568. {
  569. CWizBaseDlg::OnShowWindow(bShow, nStatus);
  570. CSpeckleApp* pApp = (CSpeckleApp*)AfxGetApp();
  571. if (bShow)
  572. {
  573. pApp->m_cps1.SetWizardButtons(PSWIZB_BACK | PSWIZB_FINISH);
  574. CString csTemp;
  575. csTemp.LoadString(IDS_FINISH_CAPTION);
  576. CString csTemp2;
  577. csTemp2.Format(csTemp, pApp->m_csUserName);
  578. m_csCaption = csTemp2;
  579. UpdateData(FALSE);
  580. }
  581. // else pApp->m_cps1.SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT);
  582. }
  583. /*******************************************************************
  584. NAME: USER_NW::SetNWWorkstations
  585. SYNOPSIS: Store NetWare allowed workstation addresses to UserParms
  586. If pchNWWorkstations is NULL, this function will delete
  587. "NWLgonFrom" field from UserParms.
  588. EXIT:
  589. HISTORY:
  590. CongpaY 01-Oct-93 Created.
  591. ********************************************************************/
  592. DWORD CFinish::SetNWWorkstations( const TCHAR * pchNWWorkstations)
  593. {
  594. DWORD err = ERROR_SUCCESS;
  595. UNICODE_STRING uniNWWorkstations;
  596. CHAR * pchTemp = NULL;
  597. if (pchNWWorkstations == NULL)
  598. {
  599. uniNWWorkstations.Buffer = NULL;
  600. uniNWWorkstations.Length = 0;
  601. uniNWWorkstations.MaximumLength = 0;
  602. }
  603. else
  604. {
  605. BOOL fDummy;
  606. INT nStringLength = lstrlen(pchNWWorkstations) + 1;
  607. pchTemp = (CHAR *) LocalAlloc (LPTR, nStringLength);
  608. if ( pchTemp == NULL )
  609. err = ERROR_NOT_ENOUGH_MEMORY;
  610. if ( err == ERROR_SUCCESS &&
  611. !WideCharToMultiByte (CP_ACP,
  612. 0,
  613. pchNWWorkstations,
  614. nStringLength,
  615. pchTemp,
  616. nStringLength,
  617. NULL,
  618. &fDummy))
  619. {
  620. err = ::GetLastError();
  621. }
  622. if ( err == ERROR_SUCCESS )
  623. {
  624. uniNWWorkstations.Buffer = (WCHAR *) pchTemp;
  625. uniNWWorkstations.Length = nStringLength;
  626. uniNWWorkstations.MaximumLength = nStringLength;
  627. }
  628. }
  629. if (!SetUserParam(uniNWWorkstations, NWLOGONFROM)) err = 1;
  630. else err = ERROR_SUCCESS;
  631. if (pchTemp != NULL)
  632. {
  633. LocalFree (pchTemp);
  634. }
  635. return err;
  636. }
  637. void CFinish::OnPaint()
  638. {
  639. CPaintDC dc(this); // device context for painting
  640. CTransBmp* pBitmap = new CTransBmp;
  641. pBitmap->LoadBitmap(IDB_ENDFLAG);
  642. pBitmap->DrawTrans(&dc, 0,0);
  643. delete pBitmap;
  644. }