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.

846 lines
28 KiB

  1. //
  2. // checker.h <start>
  3. //
  4. #include <lmaccess.h>
  5. #include <lmserver.h>
  6. #include <lmapibuf.h>
  7. #include <lmerr.h>
  8. #define SECURITY_WIN32
  9. #define ISSP_LEVEL 32
  10. #define ISSP_MODE 1
  11. #include <sspi.h>
  12. #ifndef _CHICAGO_
  13. int CheckConfig_DoIt(HWND hDlg, CStringList &strListOfWhatWeDid);
  14. BOOL ValidatePassword(IN LPCWSTR UserName,IN LPCWSTR Domain,IN LPCWSTR Password);
  15. #endif
  16. DWORD WINAPI ChkConfig_MessageDialogThread(void *p);
  17. BOOL CALLBACK ChkConfig_MessageDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam );
  18. void CheckConfig(void);
  19. int g_BigCancel = FALSE;
  20. //
  21. // checker.h <end>
  22. //
  23. #ifndef _CHICAGO_
  24. BOOL ValidatePassword(IN LPCWSTR UserName,IN LPCWSTR Domain,IN LPCWSTR Password)
  25. /*++
  26. Routine Description:
  27. Uses SSPI to validate the specified password
  28. Arguments:
  29. UserName - Supplies the user name
  30. Domain - Supplies the user's domain
  31. Password - Supplies the password
  32. Return Value:
  33. TRUE if the password is valid.
  34. FALSE otherwise.
  35. --*/
  36. {
  37. SECURITY_STATUS SecStatus;
  38. SECURITY_STATUS AcceptStatus;
  39. SECURITY_STATUS InitStatus;
  40. CredHandle ClientCredHandle;
  41. CredHandle ServerCredHandle;
  42. BOOL ClientCredAllocated = FALSE;
  43. BOOL ServerCredAllocated = FALSE;
  44. CtxtHandle ClientContextHandle;
  45. CtxtHandle ServerContextHandle;
  46. TimeStamp Lifetime;
  47. ULONG ContextAttributes;
  48. PSecPkgInfo PackageInfo = NULL;
  49. ULONG ClientFlags;
  50. ULONG ServerFlags;
  51. TCHAR TargetName[100];
  52. SEC_WINNT_AUTH_IDENTITY_W AuthIdentity;
  53. BOOL Validated = FALSE;
  54. SecBufferDesc NegotiateDesc;
  55. SecBuffer NegotiateBuffer;
  56. SecBufferDesc ChallengeDesc;
  57. SecBuffer ChallengeBuffer;
  58. SecBufferDesc AuthenticateDesc;
  59. SecBuffer AuthenticateBuffer;
  60. AuthIdentity.User = (LPWSTR)UserName;
  61. AuthIdentity.UserLength = lstrlenW(UserName);
  62. AuthIdentity.Domain = (LPWSTR)Domain;
  63. AuthIdentity.DomainLength = lstrlenW(Domain);
  64. AuthIdentity.Password = (LPWSTR)Password;
  65. AuthIdentity.PasswordLength = lstrlenW(Password);
  66. AuthIdentity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
  67. NegotiateBuffer.pvBuffer = NULL;
  68. ChallengeBuffer.pvBuffer = NULL;
  69. AuthenticateBuffer.pvBuffer = NULL;
  70. //
  71. // Get info about the security packages.
  72. //
  73. SecStatus = QuerySecurityPackageInfo( _T("NTLM"), &PackageInfo );
  74. if ( SecStatus != STATUS_SUCCESS ) {
  75. goto error_exit;
  76. }
  77. //
  78. // Acquire a credential handle for the server side
  79. //
  80. SecStatus = AcquireCredentialsHandle(
  81. NULL,
  82. _T("NTLM"),
  83. SECPKG_CRED_INBOUND,
  84. NULL,
  85. &AuthIdentity,
  86. NULL,
  87. NULL,
  88. &ServerCredHandle,
  89. &Lifetime );
  90. if ( SecStatus != STATUS_SUCCESS ) {
  91. goto error_exit;
  92. }
  93. ServerCredAllocated = TRUE;
  94. //
  95. // Acquire a credential handle for the client side
  96. //
  97. SecStatus = AcquireCredentialsHandle(
  98. NULL, // New principal
  99. _T("NTLM"),
  100. SECPKG_CRED_OUTBOUND,
  101. NULL,
  102. &AuthIdentity,
  103. NULL,
  104. NULL,
  105. &ClientCredHandle,
  106. &Lifetime );
  107. if ( SecStatus != STATUS_SUCCESS ) {
  108. goto error_exit;
  109. }
  110. ClientCredAllocated = TRUE;
  111. //
  112. // Get the NegotiateMessage (ClientSide)
  113. //
  114. NegotiateDesc.ulVersion = 0;
  115. NegotiateDesc.cBuffers = 1;
  116. NegotiateDesc.pBuffers = &NegotiateBuffer;
  117. NegotiateBuffer.cbBuffer = PackageInfo->cbMaxToken;
  118. NegotiateBuffer.BufferType = SECBUFFER_TOKEN;
  119. NegotiateBuffer.pvBuffer = LocalAlloc( 0, NegotiateBuffer.cbBuffer );
  120. if ( NegotiateBuffer.pvBuffer == NULL ) {
  121. goto error_exit;
  122. }
  123. ClientFlags = ISC_REQ_MUTUAL_AUTH | ISC_REQ_REPLAY_DETECT;
  124. InitStatus = InitializeSecurityContext(
  125. &ClientCredHandle,
  126. NULL, // No Client context yet
  127. NULL,
  128. ClientFlags,
  129. 0, // Reserved 1
  130. SECURITY_NATIVE_DREP,
  131. NULL, // No initial input token
  132. 0, // Reserved 2
  133. &ClientContextHandle,
  134. &NegotiateDesc,
  135. &ContextAttributes,
  136. &Lifetime );
  137. if ( !NT_SUCCESS(InitStatus) ) {
  138. goto error_exit;
  139. }
  140. //
  141. // Get the ChallengeMessage (ServerSide)
  142. //
  143. NegotiateBuffer.BufferType |= SECBUFFER_READONLY;
  144. ChallengeDesc.ulVersion = 0;
  145. ChallengeDesc.cBuffers = 1;
  146. ChallengeDesc.pBuffers = &ChallengeBuffer;
  147. ChallengeBuffer.cbBuffer = PackageInfo->cbMaxToken;
  148. ChallengeBuffer.BufferType = SECBUFFER_TOKEN;
  149. ChallengeBuffer.pvBuffer = LocalAlloc( 0, ChallengeBuffer.cbBuffer );
  150. if ( ChallengeBuffer.pvBuffer == NULL ) {
  151. goto error_exit;
  152. }
  153. ServerFlags = ASC_REQ_EXTENDED_ERROR;
  154. AcceptStatus = AcceptSecurityContext(
  155. &ServerCredHandle,
  156. NULL, // No Server context yet
  157. &NegotiateDesc,
  158. ServerFlags,
  159. SECURITY_NATIVE_DREP,
  160. &ServerContextHandle,
  161. &ChallengeDesc,
  162. &ContextAttributes,
  163. &Lifetime );
  164. if ( !NT_SUCCESS(AcceptStatus) ) {
  165. goto error_exit;
  166. }
  167. if (InitStatus != STATUS_SUCCESS)
  168. {
  169. //
  170. // Get the AuthenticateMessage (ClientSide)
  171. //
  172. ChallengeBuffer.BufferType |= SECBUFFER_READONLY;
  173. AuthenticateDesc.ulVersion = 0;
  174. AuthenticateDesc.cBuffers = 1;
  175. AuthenticateDesc.pBuffers = &AuthenticateBuffer;
  176. AuthenticateBuffer.cbBuffer = PackageInfo->cbMaxToken;
  177. AuthenticateBuffer.BufferType = SECBUFFER_TOKEN;
  178. AuthenticateBuffer.pvBuffer = LocalAlloc( 0, AuthenticateBuffer.cbBuffer );
  179. if ( AuthenticateBuffer.pvBuffer == NULL ) {
  180. goto error_exit;
  181. }
  182. SecStatus = InitializeSecurityContext(
  183. NULL,
  184. &ClientContextHandle,
  185. TargetName,
  186. 0,
  187. 0, // Reserved 1
  188. SECURITY_NATIVE_DREP,
  189. &ChallengeDesc,
  190. 0, // Reserved 2
  191. &ClientContextHandle,
  192. &AuthenticateDesc,
  193. &ContextAttributes,
  194. &Lifetime );
  195. if ( !NT_SUCCESS(SecStatus) ) {
  196. goto error_exit;
  197. }
  198. if (AcceptStatus != STATUS_SUCCESS) {
  199. //
  200. // Finally authenticate the user (ServerSide)
  201. //
  202. AuthenticateBuffer.BufferType |= SECBUFFER_READONLY;
  203. SecStatus = AcceptSecurityContext(
  204. NULL,
  205. &ServerContextHandle,
  206. &AuthenticateDesc,
  207. ServerFlags,
  208. SECURITY_NATIVE_DREP,
  209. &ServerContextHandle,
  210. NULL,
  211. &ContextAttributes,
  212. &Lifetime );
  213. if ( !NT_SUCCESS(SecStatus) ) {
  214. goto error_exit;
  215. }
  216. Validated = TRUE;
  217. }
  218. }
  219. error_exit:
  220. if (ServerCredAllocated) {
  221. FreeCredentialsHandle( &ServerCredHandle );
  222. }
  223. if (ClientCredAllocated) {
  224. FreeCredentialsHandle( &ClientCredHandle );
  225. }
  226. //
  227. // Final Cleanup
  228. //
  229. if ( NegotiateBuffer.pvBuffer != NULL ) {
  230. (VOID) LocalFree( NegotiateBuffer.pvBuffer );
  231. }
  232. if ( ChallengeBuffer.pvBuffer != NULL ) {
  233. (VOID) LocalFree( ChallengeBuffer.pvBuffer );
  234. }
  235. if ( AuthenticateBuffer.pvBuffer != NULL ) {
  236. (VOID) LocalFree( AuthenticateBuffer.pvBuffer );
  237. }
  238. return(Validated);
  239. }
  240. #endif
  241. DWORD WINAPI ChkConfig_MessageDialogThread(void *p)
  242. {
  243. HWND hDlg = (HWND)p;
  244. int iReturn = TRUE;
  245. CStringList strWhatWeDidList;
  246. CString csBigString;
  247. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Scanning..."));
  248. // call our function
  249. #ifndef _CHICAGO_
  250. CheckConfig_DoIt(hDlg, strWhatWeDidList);
  251. #endif
  252. // check for cancellation
  253. if (g_BigCancel == TRUE) goto ChkConfig_MessageDialogThread_Cancelled;
  254. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Completed."));
  255. // Hide the Search window
  256. ShowWindow(hDlg, SW_HIDE);
  257. // Loop thru the what we did list and display the messages:
  258. //strWhatWeDidList
  259. if (strWhatWeDidList.IsEmpty() == FALSE)
  260. {
  261. POSITION pos = NULL;
  262. CString csEntry;
  263. pos = strWhatWeDidList.GetHeadPosition();
  264. while (pos)
  265. {
  266. csEntry = strWhatWeDidList.GetAt(pos);
  267. //iisDebugOutSafeParams((LOG_TYPE_WARN, _T("%1!s!\n"), csEntry));
  268. csBigString = csBigString + csEntry;
  269. csBigString = csBigString + _T("\n");
  270. strWhatWeDidList.GetNext(pos);
  271. }
  272. }
  273. else
  274. {
  275. csBigString = _T("No changes.");
  276. }
  277. TCHAR szBiggerString[_MAX_PATH];
  278. _stprintf(szBiggerString, _T("Changes:\n%s"), csBigString);
  279. MyMessageBox((HWND) GetDesktopWindow(), szBiggerString, _T("Check Config Done"), MB_OK);
  280. ChkConfig_MessageDialogThread_Cancelled:
  281. PostMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
  282. return iReturn;
  283. }
  284. //***************************************************************************
  285. //*
  286. //* purpose: display the wait dailog and spawn thread to do stuff
  287. //*
  288. //***************************************************************************
  289. BOOL CALLBACK ChkConfig_MessageDialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
  290. {
  291. static HANDLE hProc = NULL;
  292. DWORD id;
  293. switch (uMsg)
  294. {
  295. case WM_INITDIALOG:
  296. uiCenterDialog(hDlg);
  297. hProc = CreateThread(NULL, 0, ChkConfig_MessageDialogThread, (LPVOID)hDlg, 0, &id);
  298. if (hProc == NULL)
  299. {
  300. MyMessageBox((HWND) GetDesktopWindow(), _T("Failed to CreateThread MessageDialogThread.\n"), MB_ICONSTOP);
  301. EndDialog(hDlg, -1);
  302. }
  303. UpdateWindow(hDlg);
  304. break;
  305. case WM_COMMAND:
  306. switch (wParam)
  307. {
  308. case IDOK:
  309. case IDCANCEL:
  310. g_BigCancel = TRUE;
  311. EndDialog(hDlg, (int)wParam);
  312. return TRUE;
  313. }
  314. break;
  315. default:
  316. return(FALSE);
  317. }
  318. return(TRUE);
  319. }
  320. void CheckConfig(void)
  321. {
  322. _tcscpy(g_MyLogFile.m_szLogPreLineInfo2, _T("CheckConfig:"));
  323. DWORD err = FALSE;
  324. // Search for the ie setup program
  325. g_BigCancel = FALSE;
  326. if (-1 == DialogBox((HINSTANCE) g_MyModuleHandle, MAKEINTRESOURCE(IDD_DIALOG_MSG), NULL, (DLGPROC) ChkConfig_MessageDialogProc))
  327. {
  328. GetErrorMsg(GetLastError(), _T(": on CheckConfig"));
  329. }
  330. _tcscpy(g_MyLogFile.m_szLogPreLineInfo2, _T(""));
  331. return;
  332. }
  333. //
  334. // Function will open the metabase and check the iusr_ and iwam_ usernames.
  335. // it will check if the names are still valid and if the passwords are still valid.
  336. //
  337. #ifndef _CHICAGO_
  338. #define CheckConfig_DoIt_log _T("CheckConfig_DoIt")
  339. int CheckConfig_DoIt(HWND hDlg, CStringList &strListOfWhatWeDid)
  340. {
  341. int iReturn = FALSE;
  342. iisDebugOut_Start(CheckConfig_DoIt_log,LOG_TYPE_PROGRAM_FLOW);
  343. TCHAR szAnonyName_WAM[_MAX_PATH];
  344. TCHAR szAnonyPass_WAM[LM20_PWLEN+1];
  345. TCHAR szAnonyName_WWW[_MAX_PATH];
  346. TCHAR szAnonyPass_WWW[LM20_PWLEN+1];
  347. TCHAR szAnonyName_FTP[_MAX_PATH];
  348. TCHAR szAnonyPass_FTP[LM20_PWLEN+1];
  349. int iGotName_WWW = FALSE;
  350. int iGotPass_WWW = FALSE;
  351. int iGotName_WAM = FALSE;
  352. int iGotPass_WAM = FALSE;
  353. int iGotName_FTP = FALSE;
  354. int iGotPass_FTP = FALSE;
  355. INT iUserWasNewlyCreated = 0;
  356. TCHAR szEntry[_MAX_PATH];
  357. // Call CreatePassword to fill
  358. LPTSR pszPassword = NULL;
  359. pszPassword = CreatePassword(LM20_PWLEN+1);
  360. if (!pszPassword)
  361. {
  362. goto CheckConfig_DoIt_Exit;
  363. }
  364. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Checking for IISADMIN Service..."));
  365. if (CheckifServiceExist(_T("IISADMIN")) != 0 )
  366. {
  367. // the iisadmin service does not exist
  368. // so there is no way we can do anything with the metabase.
  369. goto CheckConfig_DoIt_Exit;
  370. }
  371. //
  372. // Get the WAM username and password
  373. //
  374. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Lookup iWam username..."));
  375. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  376. if (TRUE == GetDataFromMetabase(_T("LM/W3SVC"), MD_WAM_USER_NAME, (PBYTE)szAnonyName_WAM, _MAX_PATH))
  377. {iGotName_WAM = TRUE;}
  378. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  379. if (TRUE == GetDataFromMetabase(_T("LM/W3SVC"), MD_WAM_PWD, (PBYTE)szAnonyPass_WAM, _MAX_PATH))
  380. {iGotPass_WAM = TRUE;}
  381. //
  382. // Get the WWW username and password
  383. //
  384. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Lookup iUsr username..."));
  385. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  386. if (TRUE == GetDataFromMetabase(_T("LM/W3SVC"), MD_ANONYMOUS_USER_NAME, (PBYTE)szAnonyName_WWW, _MAX_PATH))
  387. {iGotName_WWW = TRUE;}
  388. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  389. if (TRUE == GetDataFromMetabase(_T("LM/W3SVC"), MD_ANONYMOUS_PWD, (PBYTE)szAnonyPass_WWW, _MAX_PATH))
  390. {iGotPass_WWW = TRUE;}
  391. //
  392. // Get the FTP username and password
  393. //
  394. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Lookup iUsr (ftp) username..."));
  395. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  396. if (TRUE == GetDataFromMetabase(_T("LM/MSFTPSVC"), MD_ANONYMOUS_USER_NAME, (PBYTE)szAnonyName_FTP, _MAX_PATH))
  397. {iGotName_FTP = TRUE;}
  398. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  399. if (TRUE == GetDataFromMetabase(_T("LM/MSFTPSVC"), MD_ANONYMOUS_PWD, (PBYTE)szAnonyPass_FTP, _MAX_PATH))
  400. {iGotPass_FTP = TRUE;}
  401. // Now check if the actual user accounts actually exist....
  402. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  403. if (iGotName_WAM)
  404. {
  405. // check if username is blank
  406. if (szAnonyName_WAM)
  407. {
  408. // Check if this user actually exists...
  409. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Checking if Wam user exists..."));
  410. if (IsUserExist(szAnonyName_WAM))
  411. {
  412. // Fine, the user exists.... let's validate the password too
  413. // Let's validate that the user has at least the appropriate rights...
  414. if (iGotPass_WAM)
  415. {
  416. ChangeUserPassword((LPTSTR) szAnonyName_WAM, (LPTSTR) szAnonyPass_WAM);
  417. }
  418. }
  419. else
  420. {
  421. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  422. // the user does not exist, so let's create it
  423. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Creating Wam Account..."));
  424. // Add it if it is not already there.
  425. _stprintf(szEntry,_T("Created the iwam_ account = %s."),szAnonyName_WAM);
  426. if (TRUE != IsThisStringInThisCStringList(strListOfWhatWeDid, szEntry))
  427. {strListOfWhatWeDid.AddTail(szEntry);}
  428. if (iGotPass_WAM)
  429. {
  430. // We were able to get the password from the metabase
  431. // so lets create the user with that password
  432. CreateIWAMAccount(szAnonyName_WAM,szAnonyPass_WAM,&iUserWasNewlyCreated);
  433. if (1 == iUserWasNewlyCreated)
  434. {
  435. // Add to the list
  436. g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),szAnonyName_WAM);
  437. }
  438. }
  439. else
  440. {
  441. // we were not able to get the password from the metabase
  442. // so let's just create one and write it back to the metabase
  443. CreateIWAMAccount(szAnonyName_WAM,pszPassword,&iUserWasNewlyCreated);
  444. if (1 == iUserWasNewlyCreated)
  445. {
  446. // Add to the list
  447. g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),szAnonyName_WAM);
  448. }
  449. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  450. // write it to the metabase.
  451. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Writing Wam Account to Metabase..."));
  452. g_pTheApp->m_csWAMAccountName = szAnonyName_WAM;
  453. g_pTheApp->m_csWAMAccountPassword = pszPassword;
  454. WriteToMD_IWamUserName_WWW();
  455. }
  456. // Do Dcomcnfg?????
  457. }
  458. }
  459. }
  460. // Now check if the actual user accounts actually exist....
  461. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  462. if (iGotName_WWW)
  463. {
  464. // check if username is blank
  465. if (szAnonyName_WWW)
  466. {
  467. // Check if this user actually exists...
  468. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Checking if iUsr user exists..."));
  469. if (IsUserExist(szAnonyName_WWW))
  470. {
  471. // Fine, the user exists.... let's validate the password too
  472. // Let's validate that the user has at least the appropriate rights...
  473. if (iGotPass_WWW)
  474. {
  475. ChangeUserPassword((LPTSTR) szAnonyName_WWW, (LPTSTR) szAnonyPass_WWW);
  476. }
  477. }
  478. else
  479. {
  480. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  481. // the user does not exist, so let's create it
  482. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Creating iUsr Account..."));
  483. // Add it if it is not already there.
  484. _stprintf(szEntry,_T("Created the iusr_ account = %s."),szAnonyName_WWW);
  485. if (TRUE != IsThisStringInThisCStringList(strListOfWhatWeDid, szEntry))
  486. {strListOfWhatWeDid.AddTail(szEntry);}
  487. if (iGotPass_WWW)
  488. {
  489. // We were able to get the password from the metabase
  490. // so lets create the user with that password
  491. CreateIUSRAccount(szAnonyName_WWW,szAnonyPass_WWW,&iUserWasNewlyCreated);
  492. if (1 == iUserWasNewlyCreated)
  493. {
  494. // Add to the list
  495. g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),szAnonyName_WWW);
  496. }
  497. }
  498. else
  499. {
  500. // see if we can enumerate thru the lower nodes to find the password??????
  501. // check if maybe the ftp stuff has the password there????
  502. // we were not able to get the password from the metabase
  503. // so let's just create one and write it back to the metabase
  504. CreateIUSRAccount(szAnonyName_WWW,pszPassword,&iUserWasNewlyCreated);
  505. if (1 == iUserWasNewlyCreated)
  506. {
  507. // Add to the list
  508. g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),szAnonyName_WWW);
  509. }
  510. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  511. // write it to the metabase.
  512. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Writing iUsr Account to Metabase..."));
  513. g_pTheApp->m_csWWWAnonyName = szAnonyName_WAM;
  514. g_pTheApp->m_csWWWAnonyPassword = pszPassword;
  515. WriteToMD_AnonymousUserName_WWW(FALSE);
  516. }
  517. // Do Dcomcnfg?????
  518. }
  519. }
  520. }
  521. // Now check if the actual user accounts actually exist....
  522. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  523. if (iGotName_FTP)
  524. {
  525. // check if username is blank
  526. if (szAnonyName_FTP)
  527. {
  528. // Check if this user actually exists...
  529. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Checking if iUsr (ftp) user exists..."));
  530. if (IsUserExist(szAnonyName_FTP))
  531. {
  532. // Fine, the user exists.... let's validate the password too
  533. // Let's validate that the user has at least the appropriate rights...
  534. if (iGotPass_FTP)
  535. {
  536. ChangeUserPassword((LPTSTR) szAnonyName_FTP, (LPTSTR) szAnonyPass_FTP);
  537. }
  538. }
  539. else
  540. {
  541. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Creating iUsr (ftp) Account..."));
  542. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  543. // Add it if it is not already there.
  544. _stprintf(szEntry,_T("Created the iusr_ account = %s."),szAnonyName_FTP);
  545. if (TRUE != IsThisStringInThisCStringList(strListOfWhatWeDid, szEntry))
  546. {strListOfWhatWeDid.AddTail(szEntry);}
  547. // the user does not exist, so let's create it
  548. if (iGotPass_FTP)
  549. {
  550. // We were able to get the password from the metabase
  551. // so lets create the user with that password
  552. CreateIUSRAccount(szAnonyName_FTP,szAnonyPass_FTP,&iUserWasNewlyCreated);
  553. if (1 == iUserWasNewlyCreated)
  554. {
  555. // Add to the list
  556. g_pTheApp->UnInstallList_Add(_T("IUSR_FTP"),szAnonyName_FTP);
  557. }
  558. }
  559. else
  560. {
  561. // see if we can enumerate thru the lower nodes to find the password??????
  562. // check if maybe the www stuff has the password there????
  563. // we were not able to get the password from the metabase
  564. // so let's just create one and write it back to the metabase
  565. CreateIUSRAccount(szAnonyName_FTP,pszPassword,&iUserWasNewlyCreated);
  566. if (1 == iUserWasNewlyCreated)
  567. {
  568. // Add to the list
  569. g_pTheApp->UnInstallList_Add(_T("IUSR_FTP"),szAnonyName_FTP);
  570. }
  571. if (g_BigCancel == TRUE) goto CheckConfig_DoIt_Exit;
  572. // write it to the metabase.
  573. SetWindowText(GetDlgItem(hDlg, IDC_STATIC_TOPLINE), _T("Writing iUsr (ftp) Account to Metabase..."));
  574. g_pTheApp->m_csFTPAnonyName = szAnonyName_WAM;
  575. g_pTheApp->m_csFTPAnonyPassword = pszPassword;
  576. WriteToMD_AnonymousUserName_FTP(FALSE);
  577. }
  578. // Do Dcomcnfg?????
  579. }
  580. }
  581. }
  582. // If we did anything, then popup a messagebox to the user
  583. // about the warnings: changes....
  584. CheckConfig_DoIt_Exit:
  585. if (pszPassword) {GlobalFree(pszPassword);pszPassword = NULL;}
  586. iisDebugOut_End(CheckConfig_DoIt_log,LOG_TYPE_PROGRAM_FLOW);
  587. return iReturn;
  588. }
  589. #endif
  590. const TCHAR REG_MTS_INSTALLED_KEY1[] = _T("SOFTWARE\\Microsoft\\Transaction Server\\Setup(OCM)");
  591. const TCHAR REG_MTS_INSTALLED_KEY2[] = _T("SOFTWARE\\Microsoft\\Transaction Server\\Setup");
  592. int ReturnTrueIfMTSInstalled(void)
  593. {
  594. int iReturn = TRUE;
  595. if (!g_pTheApp->m_fInvokedByNT)
  596. {
  597. int bMTSInstalledFlag = FALSE;
  598. CRegKey regMTSInstalledKey1( HKEY_LOCAL_MACHINE, REG_MTS_INSTALLED_KEY1, KEY_READ);
  599. CRegKey regMTSInstalledKey2( HKEY_LOCAL_MACHINE, REG_MTS_INSTALLED_KEY2, KEY_READ);
  600. if ( (HKEY)regMTSInstalledKey1 ) {bMTSInstalledFlag = TRUE;}
  601. if ( (HKEY)regMTSInstalledKey2 ) {bMTSInstalledFlag = TRUE;}
  602. if (bMTSInstalledFlag == TRUE)
  603. {
  604. // check if we can get to the MTS catalog object
  605. if (NOERROR != DoesMTSCatalogObjectExist())
  606. {
  607. bMTSInstalledFlag = FALSE;
  608. iReturn = FALSE;
  609. MyMessageBox(NULL, IDS_MTS_INCORRECTLY_INSTALLED, MB_OK | MB_SETFOREGROUND);
  610. goto ReturnTrueIfMTSInstalled_Exit;
  611. }
  612. }
  613. if (bMTSInstalledFlag != TRUE)
  614. {
  615. iReturn = FALSE;
  616. MyMessageBox(NULL, IDS_MTS_NOT_INSTALLED, MB_OK | MB_SETFOREGROUND);
  617. goto ReturnTrueIfMTSInstalled_Exit;
  618. }
  619. }
  620. ReturnTrueIfMTSInstalled_Exit:
  621. return iReturn;
  622. }
  623. #ifndef _CHICAGO_
  624. /*===================================================================
  625. DoGoryCoInitialize
  626. Description:
  627. CoInitialize() of COM is extremely funny function. It can fail
  628. and respond with S_FALSE which is to be ignored by the callers!
  629. On other error conditions it is possible that there is a threading
  630. mismatch. Rather than replicate the code in multiple places, here
  631. we try to consolidate the functionality in some rational manner.
  632. Arguments:
  633. None
  634. Returns:
  635. HRESULT = NOERROR on (S_OK & S_FALSE)
  636. other errors if any failure
  637. ===================================================================*/
  638. HRESULT DoGoryCoInitialize(void)
  639. {
  640. HRESULT hr;
  641. // do the call to CoInitialize()
  642. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoInitializeEx().Start.")));
  643. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  644. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoInitializeEx().End.")));
  645. //
  646. // S_FALSE and S_OK are success. Everything else is a failure and you don't need to call CoUninitialize.
  647. //
  648. if ( S_OK == hr || S_FALSE == hr)
  649. {
  650. //
  651. // It is okay to have failure (S_FALSE) in CoInitialize()
  652. // This error is to be ignored and balanced with CoUninitialize()
  653. // We will reset the hr so that subsequent use is rational
  654. //
  655. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("DoGoryCoInitialize found duplicate CoInitialize\n")));
  656. hr = NOERROR;
  657. }
  658. else if (FAILED (hr))
  659. {
  660. iisDebugOut((LOG_TYPE_ERROR, _T("DoGoryCoInitialize found Failed error 0x%x\n"), hr));
  661. }
  662. return ( hr);
  663. }
  664. #endif // _CHICAGO_
  665. HRESULT DoesMTSCatalogObjectExist(void)
  666. {
  667. HRESULT hr = NOERROR;
  668. #ifndef _CHICAGO_
  669. ICatalog* m_pCatalog = NULL;
  670. ICatalogCollection* m_pPkgCollection = NULL;
  671. hr = DoGoryCoInitialize();
  672. if ( FAILED(hr)) {return ( hr);}
  673. // Create instance of the catalog object
  674. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoCreateInstance().Start.")));
  675. hr = CoCreateInstance(CLSID_Catalog, NULL, CLSCTX_SERVER, IID_ICatalog, (void**)&m_pCatalog);
  676. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoCreateInstance().End.")));
  677. if (FAILED(hr))
  678. {
  679. iisDebugOut((LOG_TYPE_ERROR, _T("Failed to CoCreateInstance of Catalog Object.,hr = %08x\n"), hr));
  680. }
  681. else
  682. {
  683. BSTR bstr;
  684. //
  685. // Get the Packages collection
  686. //
  687. bstr = SysAllocString(L"Packages");
  688. if (bstr)
  689. {
  690. hr = m_pCatalog->GetCollection(bstr, (IDispatch**)&m_pPkgCollection);
  691. FREEBSTR(bstr);
  692. if (FAILED(hr))
  693. {
  694. iisDebugOut((LOG_TYPE_ERROR, _T("m_pCatalog(%08x)->GetCollection() failed, hr = %08x\n"), m_pCatalog, hr));
  695. }
  696. else
  697. {
  698. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("m_pCatalog(%08x)->GetCollection() Succeeded!, hr = %08x\n"), m_pCatalog, hr));
  699. //DBG_ASSERT( m_pPkgCollection != NULL);
  700. }
  701. }
  702. else
  703. {
  704. iisDebugOut((LOG_TYPE_ERROR, _T("m_pCatalog(%08x)->GetCollection() failed. out of memory!\n"), m_pCatalog));
  705. }
  706. }
  707. if (m_pPkgCollection != NULL )
  708. {
  709. RELEASE(m_pPkgCollection);
  710. m_pPkgCollection = NULL;
  711. }
  712. if (m_pCatalog != NULL )
  713. {
  714. RELEASE(m_pCatalog);
  715. m_pCatalog = NULL;
  716. }
  717. //iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoUninitialize().Start.")));
  718. CoUninitialize();
  719. //iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("ole32:CoUninitialize().End.")));
  720. #endif // _CHICAGO_
  721. return hr;
  722. }