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.

796 lines
30 KiB

  1. #include "stdafx.h"
  2. #include <ole2.h>
  3. #include "iadmw.h"
  4. #include "iiscnfg.h"
  5. #include "mdkey.h"
  6. #include "mdentry.h"
  7. #include "mdacl.h"
  8. #include "other.h"
  9. #include "ocmanage.h"
  10. #include "setpass.h"
  11. #include "setuser.h"
  12. #include "www.h"
  13. #include "dllmain.h"
  14. extern OCMANAGER_ROUTINES gHelperRoutines;
  15. #define Register_iis_www_log _T("Register_iis_www")
  16. INT Register_iis_www()
  17. {
  18. iisDebugOut_Start(Register_iis_www_log, LOG_TYPE_TRACE);
  19. int iReturn = TRUE;
  20. int iTempFlag = TRUE;
  21. int iCount = 0;
  22. int iTemp = TRUE;
  23. TCHAR szTempSection[255];
  24. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"), TRUE);
  25. CMDKey cmdKey;
  26. ProcessSection(g_pTheApp->m_hInfHandle, _T("register_iis_www_before"));
  27. // ---------------------------------------------------
  28. //
  29. // Here is the first place where we try to access the metabase!
  30. //
  31. // ---------------------------------------------------
  32. // create node /LM/W3SVC before wamreg.dll create IIS package
  33. // the registration of w3svc.dll will also require these initial entries to be here
  34. cmdKey.CreateNode(METADATA_MASTER_ROOT_HANDLE, _T("LM/W3SVC"));
  35. if ( !(METADATA_HANDLE)cmdKey )
  36. {
  37. // We failed to create node on the metabase
  38. // this is pretty serious.
  39. // we failed to create the ftp service.
  40. iisDebugOut((LOG_TYPE_ERROR, _T("%s(): failed to create initial node is metabase 'LM/W3SVC'. GetLastError()=0x%x\n"), Register_iis_www_log, GetLastError()));
  41. iReturn = FALSE;
  42. goto Register_iis_www_exit;
  43. }
  44. cmdKey.Close();
  45. // ---------------------------------------------------
  46. //
  47. // Get the anonymous username/passowrd and iwam username/password accounts.
  48. // And verify that the accounts exist and have the right privledges.
  49. //
  50. // ---------------------------------------------------
  51. #ifndef _CHICAGO_
  52. // IUSR_(computername)
  53. Register_iis_www_handle_iusr_acct();
  54. SetupSetStringId_Wrapper(g_pTheApp->m_hInfHandle, 33002, g_pTheApp->m_csWWWAnonyName);
  55. AdvanceProgressBarTickGauge();
  56. // IWAM_(computername)
  57. Register_iis_www_handle_iwam_acct();
  58. SetupSetStringId_Wrapper(g_pTheApp->m_hInfHandle, 33001, g_pTheApp->m_csWAMAccountName);
  59. AdvanceProgressBarTickGauge();
  60. #endif // _CHICAGO_
  61. // ---------------------------------------------------
  62. //
  63. // Install any services or whatever
  64. //
  65. // when we get out of this:
  66. // MAKE SURE THE IISADMIN SERVICE IS RUNNING.
  67. // This is because we don't want the startup code called twice.
  68. // example: start the metabase, but it takes a minute,
  69. // meanwhile, thru com, the metabase tries to get started again,
  70. // it will then error out with a "instance of the service is already running" error or something like it.
  71. // ---------------------------------------------------
  72. WriteToMD_Capabilities(_T("W3SVC"));
  73. ProcessSection(g_pTheApp->m_hInfHandle, _T("register_iis_www_1"));
  74. AdvanceProgressBarTickGauge();
  75. ProgressBarTextStack_Set(IDS_IIS_ALL_CONFIGURE);
  76. InstallMimeMap();
  77. HandleSecurityTemplates(_T("W3SVC"));
  78. // ================
  79. //
  80. // LM/W3SVC/n/
  81. // LM/W3SVC/n/ServerBindings
  82. // LM/W3SVC/n/SecureBindings
  83. // LM/W3SVC/n/ServerComment
  84. // LM/W3SVC/n/ServerSize
  85. // LM/W3SVC/n/MD_NOT_DELETABLE
  86. //
  87. // fresh = ok.
  88. // reinstall = ok -- Do not re-create these things if it is a reinstall...
  89. // upgrade 1,2,3 = ok, handles upgrades.
  90. // upgrade 4 = ok. if exists, should leave what the user had.
  91. // otherwise write in the default stuff
  92. //
  93. // if the user does not have these virtual roots which we installed during iis4 days
  94. // then we don't need to verify that they are they. the user removed them for some
  95. // reason, and we should honor that.
  96. // a. make sure the iishelp points to the right place though.
  97. // ================
  98. // About Virtual Roots
  99. AddVRootsToMD(_T("W3SVC"));
  100. AdvanceProgressBarTickGauge();
  101. LoopThruW3SVCInstancesAndSetStuff();
  102. LogHeapState(FALSE, __FILE__, __LINE__);
  103. AdvanceProgressBarTickGauge();
  104. iCount = 1;
  105. while(TRUE == iTemp && iCount < 10)
  106. {
  107. iCount++;
  108. _stprintf(szTempSection, _T("register_iis_www_%d"),iCount);
  109. // this will return false if the section does not exist
  110. iTemp = ProcessSection(g_pTheApp->m_hInfHandle, szTempSection);
  111. AdvanceProgressBarTickGauge();
  112. }
  113. //
  114. // Finaly Save the path to the WWW Root
  115. //
  116. ProcessSection(g_pTheApp->m_hInfHandle, _T("register_iis_www_after"));
  117. ProgressBarTextStack_Pop();
  118. Register_iis_www_exit:
  119. iisDebugOut_End(Register_iis_www_log, LOG_TYPE_TRACE);
  120. return iReturn;
  121. }
  122. INT Unregister_iis_www()
  123. {
  124. int iCount = 0;
  125. int iTemp = TRUE;
  126. TCHAR szTempSection[255];
  127. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),TRUE);
  128. ProcessSection(g_pTheApp->m_hInfHandle, _T("unregister_iis_www_before"));
  129. AdvanceProgressBarTickGauge();
  130. iCount = 0;
  131. while(TRUE == iTemp && iCount < 10)
  132. {
  133. iCount++;
  134. _stprintf(szTempSection, _T("unregister_iis_www_%d"),iCount);
  135. // this will return false if the section does not exist
  136. iTemp = ProcessSection(g_pTheApp->m_hInfHandle, szTempSection);
  137. AdvanceProgressBarTickGauge();
  138. }
  139. ProcessSection(g_pTheApp->m_hInfHandle, _T("unregister_iis_www_after"));
  140. AdvanceProgressBarTickGauge();
  141. return 0;
  142. }
  143. int LoopThruW3SVCInstancesAndSetStuff()
  144. {
  145. int iReturn = TRUE;
  146. CMDKey cmdKey;
  147. CStringArray arrayInstance;
  148. int nArray = 0, i = 0;
  149. // get all instances into an array
  150. cmdKey.OpenNode(_T("LM/W3SVC"));
  151. if ( (METADATA_HANDLE)cmdKey )
  152. {
  153. CMDKeyIter cmdKeyEnum(cmdKey);
  154. CString csKeyName;
  155. while (cmdKeyEnum.Next(&csKeyName) == ERROR_SUCCESS)
  156. {
  157. if (IsValidNumber((LPCTSTR)csKeyName))
  158. {
  159. arrayInstance.Add(csKeyName);
  160. }
  161. }
  162. cmdKey.Close();
  163. }
  164. nArray = (int)arrayInstance.GetSize();
  165. /*
  166. #ifndef _CHICAGO_
  167. for (i=0; i<nArray; i++)
  168. {
  169. CString csPath;
  170. csPath = _T("LM/W3SVC/");
  171. csPath += arrayInstance[i];
  172. csPath += _T("/ROOT/IISHELP");
  173. // bug#142508 - Remove restriction on iishelp dir
  174. // Set LocalhostAccess Only Only
  175. //SetLocalHostRestriction(csPath);
  176. // Bug114531: no need to add scriptmap under iisHelp
  177. // add script map for IISHelp
  178. // WriteScriptMapListToMetabase(&ScriptMapList, (LPTSTR)(LPCTSTR)csPath, MD_SCRIPTMAPFLAG_SCRIPT | MD_SCRIPTMAPFLAG_CHECK_PATH_INFO);
  179. }
  180. #endif
  181. //FreeScriptMapList(&ScriptMapList);
  182. */
  183. // set AppFriendlyName, IP restriction and customerror in each non-HTMLA instance
  184. for (i=0; i<nArray; i++)
  185. {
  186. CString csPath;
  187. csPath = _T("LM/W3SVC/");
  188. csPath += arrayInstance[i];
  189. SetAppFriendlyName(csPath);
  190. #ifndef _CHICAGO_
  191. csPath += _T("/Root/iisadmin");
  192. if (!g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  193. {
  194. // do not reset the admin restriction on iisadmin if doing an upgrade
  195. // over an existing metabase
  196. SetIISADMINRestriction(csPath);
  197. }
  198. #endif
  199. }
  200. goto CreateW3SVCInstances_exit;
  201. CreateW3SVCInstances_exit:
  202. return iReturn;
  203. }
  204. #ifndef _CHICAGO_
  205. #define Register_iis_www_handle_iwam_acct_log _T("Register_iis_www_handle_iwam_acct")
  206. int Register_iis_www_handle_iwam_acct(void)
  207. {
  208. int err = FALSE;
  209. int iReturn = TRUE;
  210. INT iUserWasNewlyCreated = 0;
  211. iisDebugOut_Start(Register_iis_www_handle_iwam_acct_log, LOG_TYPE_TRACE);
  212. if (0 != g_pTheApp->dwUnattendConfig)
  213. {
  214. // if some sort of unattended user was specified
  215. // then use it. if they specified only a password,
  216. // then use that password for the default user.
  217. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WAM_USER_NAME)
  218. {
  219. if (_tcsicmp(g_pTheApp->m_csWAMAccountName_Unattend,_T("")) != 0)
  220. {g_pTheApp->m_csWAMAccountName = g_pTheApp->m_csWAMAccountName_Unattend;}
  221. }
  222. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WAM_USER_PASS)
  223. {
  224. g_pTheApp->m_csWAMAccountPassword = g_pTheApp->m_csWAMAccountPassword_Unattend;
  225. }
  226. // let's use the iusr_computername deal
  227. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  228. if ( err != NERR_Success )
  229. {
  230. // something went wrong, set the user back to iwam!!!
  231. g_pTheApp->ReGetMachineAndAccountNames();
  232. g_pTheApp->ResetWAMPassword();
  233. // flow down and process CheckIfThisServerHasAUserThenUseIt()
  234. // since things are now hosed!
  235. }
  236. else
  237. {
  238. // Check if the user was NewlyCreated.
  239. // if it was then add it to list that eventually gets written to
  240. // the registry -- so that when uninstall happens, setup knows
  241. // which users it added -- so that it can remove them!
  242. if (1 == iUserWasNewlyCreated)
  243. {
  244. // Add to the list
  245. g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),g_pTheApp->m_csWAMAccountName);
  246. }
  247. WriteToMD_IWamUserName_WWW();
  248. goto Register_iis_www_handle_iwam_acct_Exit;
  249. }
  250. }
  251. if (TRUE == CheckIfThisServerHasAUserThenUseIt(DO_IT_FOR_W3SVC_WAMUSER))
  252. {goto Register_iis_www_handle_iwam_acct_Exit;}
  253. // if there are no registry/existing user combinations
  254. // then we'll have to create a new iusr for WWW
  255. // let's use the iusr_computername deal
  256. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  257. if ( err != NERR_Success )
  258. {
  259. // regenerate the password and try again...
  260. g_pTheApp->ResetWAMPassword();
  261. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  262. }
  263. // Check if the user was NewlyCreated.
  264. // if it was then add it to list that eventually gets written to
  265. // the registry -- so that when uninstall happens, setup knows
  266. // which users it added -- so that it can remove them!
  267. if (1 == iUserWasNewlyCreated)
  268. {
  269. // Add to the list
  270. //g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),g_pTheApp->m_csWAMAccountName);
  271. }
  272. // Stick iwam username in the metabase
  273. // (this may fail because the password is using encryption -- rsabase.dll)
  274. // ================
  275. // LM/W3SVC/WamUserName
  276. // LM/W3SVC/WamPwd
  277. // ================
  278. WriteToMD_IWamUserName_WWW();
  279. goto Register_iis_www_handle_iwam_acct_Exit;
  280. Register_iis_www_handle_iwam_acct_Exit:
  281. iisDebugOut_End(Register_iis_www_handle_iwam_acct_log, LOG_TYPE_TRACE);
  282. return iReturn;
  283. }
  284. #define Register_iis_www_handle_iusr_acct_log _T("Register_iis_www_handle_iusr_acct")
  285. int Register_iis_www_handle_iusr_acct(void)
  286. {
  287. int err = FALSE;
  288. int iReturn = TRUE;
  289. INT iUserWasNewlyCreated = 0;
  290. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),FALSE);
  291. iisDebugOut_Start(Register_iis_www_handle_iusr_acct_log, LOG_TYPE_TRACE);
  292. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  293. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  294. if (0 != g_pTheApp->dwUnattendConfig)
  295. {
  296. // if some sort of unattended www user was specified
  297. // then use it. if they specified only a password,
  298. // then use that password for the default user.
  299. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WWW_USER_NAME)
  300. {
  301. if (_tcsicmp(g_pTheApp->m_csWWWAnonyName_Unattend,_T("")) != 0)
  302. {g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csWWWAnonyName_Unattend;}
  303. }
  304. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WWW_USER_PASS)
  305. {
  306. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csWWWAnonyPassword_Unattend;
  307. }
  308. err = CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword, &iUserWasNewlyCreated);
  309. if ( err != NERR_Success )
  310. {
  311. // something went wrong, set the user back to guest!!!
  312. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  313. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  314. // flow down and process CheckIfThisServerHasAUserThenUseIt()
  315. // since things are now hosed!
  316. }
  317. else
  318. {
  319. // Check if the user was NewlyCreated.
  320. // if it was then add it to list that eventually gets written to
  321. // the registry -- so that when uninstall happens, setup knows
  322. // which users it added -- so that it can remove them!
  323. if (1 == iUserWasNewlyCreated)
  324. {
  325. // Add to the list
  326. g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),g_pTheApp->m_csWWWAnonyName);
  327. }
  328. WriteToMD_AnonymousUserName_WWW(FALSE);
  329. goto Register_iis_www_handle_iusr_acct_Exit;
  330. }
  331. }
  332. if (TRUE == CheckIfThisServerHasAUserThenUseIt(DO_IT_FOR_W3SVC_ANONYMOUSUSER))
  333. {goto Register_iis_www_handle_iusr_acct_Exit;}
  334. // Well, i guess the there is no metabase entry for the iusr under ftp.
  335. // see if we can get it from somewhere else...
  336. if (atWWW == AT_INSTALL_FRESH)
  337. {
  338. // if this is a fresh install of ftp, then
  339. // let's try to use the www user
  340. if (TRUE == CheckIfServerAHasAUserThenUseForServerB(_T("LM/MSFTPSVC"), DO_IT_FOR_W3SVC_ANONYMOUSUSER))
  341. {goto Register_iis_www_handle_iusr_acct_Exit;}
  342. }
  343. // if this is an upgrade or fresh or whatevers
  344. // see if we can get it from an older iis place
  345. if (TRUE == CheckForOtherIUsersAndUseItForWWW())
  346. {goto Register_iis_www_handle_iusr_acct_Exit;}
  347. // if there are no registry/existing user combinations
  348. // then we'll have to create a new iusr for WWW
  349. // this was inited in initapp.cpp: CInitApp::SetSetupParams
  350. // and it could have been overridden by the time we get here
  351. // let's use the iusr_computername deal
  352. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  353. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  354. CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword, &iUserWasNewlyCreated);
  355. if (1 == iUserWasNewlyCreated)
  356. {
  357. // Add to the list
  358. //g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),g_pTheApp->m_csWWWAnonyName);
  359. }
  360. // ================
  361. // LM/W3SVC/AnonymousUserName
  362. // LM/W3SVC/AnonymousPwd
  363. // ================
  364. WriteToMD_AnonymousUserName_WWW(FALSE);
  365. goto Register_iis_www_handle_iusr_acct_Exit;
  366. Register_iis_www_handle_iusr_acct_Exit:
  367. iisDebugOut_End(Register_iis_www_handle_iusr_acct_log, LOG_TYPE_TRACE);
  368. return iReturn;
  369. }
  370. // Look in the old iis1.0,2.0,3.0 spot for the ftp user and name.
  371. // retrieve it from the registry..
  372. #define CheckForOtherIUsersAndUseItForWWW_log _T("CheckForOtherIUsersAndUseItForWWW")
  373. int CheckForOtherIUsersAndUseItForWWW(void)
  374. {
  375. int iReturn = FALSE;
  376. int IfTheUserNotExistThenDoNotDoThis = TRUE;
  377. CString csAnonyName;
  378. TCHAR szAnonyName[UNLEN+1];
  379. TCHAR szAnonyPassword[PWLEN+1];
  380. iisDebugOut_Start(CheckForOtherIUsersAndUseItForWWW_log);
  381. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, REG_FTPPARAMETERS, KEY_READ);
  382. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, REG_WWWPARAMETERS, KEY_READ);
  383. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),FALSE);
  384. if (atWWW != AT_INSTALL_UPGRADE)
  385. {goto CheckForOtherIUsersAndUseItForWWW_Exit;}
  386. if (g_pTheApp->m_eUpgradeType != UT_351 && g_pTheApp->m_eUpgradeType != UT_10 && g_pTheApp->m_eUpgradeType != UT_20 && g_pTheApp->m_eUpgradeType != UT_30)
  387. {goto CheckForOtherIUsersAndUseItForWWW_Exit;}
  388. // retrieve from registry
  389. if ( (HKEY) regWWWParam )
  390. {
  391. regWWWParam.m_iDisplayWarnings = FALSE;
  392. if (ERROR_SUCCESS == regWWWParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  393. {
  394. _tcscpy(szAnonyName, csAnonyName);
  395. GetAnonymousSecret( _T("W3_ANONYMOUS_DATA"), szAnonyPassword );
  396. int iThisIsFalseBecauseNoMetabase = FALSE;
  397. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_W3SVC_ANONYMOUSUSER, szAnonyName, szAnonyPassword, iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  398. {
  399. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:using old www reg usr:%s.\n"),CheckForOtherIUsersAndUseItForWWW_log,szAnonyName));
  400. iReturn = TRUE;
  401. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  402. }
  403. else
  404. {
  405. // the user was not found, so don't use this registry data
  406. // just flow down to the next check
  407. }
  408. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  409. }
  410. }
  411. if ( (HKEY) regFTPParam )
  412. {
  413. regFTPParam.m_iDisplayWarnings = FALSE;
  414. if (ERROR_SUCCESS == regFTPParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  415. {
  416. _tcscpy(szAnonyName, csAnonyName);
  417. GetAnonymousSecret( _T("FTPD_ANONYMOUS_DATA"), (LPTSTR)szAnonyPassword );
  418. int iThisIsFalseBecauseNoMetabase = FALSE;
  419. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_W3SVC_ANONYMOUSUSER, szAnonyName, szAnonyPassword, iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  420. {
  421. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:using old ftp reg usr:%s.\n"),CheckForOtherIUsersAndUseItForWWW_log,szAnonyName));
  422. iReturn = TRUE;
  423. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  424. }
  425. else
  426. {
  427. // if this didn't work, then we'll have to return false
  428. // in other words -- we couldn't find a valid registry and existing user entry...
  429. iReturn = FALSE;
  430. }
  431. }
  432. }
  433. CheckForOtherIUsersAndUseItForWWW_Exit:
  434. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d\n"),CheckForOtherIUsersAndUseItForWWW_log,iReturn));
  435. return iReturn;
  436. }
  437. #define MakeThisUserNameAndPasswordWork_log _T("MakeThisUserNameAndPasswordWork")
  438. int MakeThisUserNameAndPasswordWork(int iForWhichUser, TCHAR *szAnonyName,TCHAR *szAnonyPassword, int iMetabaseUserExistsButCouldntGetPassword, int IfUserNotExistThenReturnFalse)
  439. {
  440. int iReturn = TRUE;
  441. int iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = FALSE;
  442. INT iUserWasNewlyCreated = 0;
  443. // We want to see if these users exists
  444. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:usrtype=%d:flag1=%d:flag2=%d\n"),MakeThisUserNameAndPasswordWork_log,iForWhichUser,szAnonyName,iMetabaseUserExistsButCouldntGetPassword,IfUserNotExistThenReturnFalse));
  445. // check if anonyname is blank
  446. if (!szAnonyName) {goto MakeThisUserNameAndPasswordWork_Exit;}
  447. // Check if just contains nothing
  448. if (_tcsicmp(szAnonyName, _T("")) == 0) {goto MakeThisUserNameAndPasswordWork_Exit;}
  449. // Only check if the user exists if this is a user on this machine.
  450. // if it is not a user on this machine, then don't validate the user/password,
  451. // since during Guimode setup, they may not be connected to the network.
  452. if ( IsDomainSpecifiedOtherThanLocalMachine(szAnonyName))
  453. {
  454. // use whatever they had.
  455. // can't verify that the user exists.
  456. // can't verify that the password actually works.
  457. // so we can't verify that the user exists, so let's figure it doesn't
  458. if (IfUserNotExistThenReturnFalse)
  459. {
  460. iReturn = FALSE;
  461. }
  462. }
  463. else
  464. {
  465. // Check if this user actually exists...
  466. if (IsUserExist(szAnonyName))
  467. {
  468. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:The %s user exists\n"),MakeThisUserNameAndPasswordWork_log,szAnonyName));
  469. // The only way we can be down here is if the username is a local account.
  470. // Reset the password to make sure it works!
  471. ChangeUserPassword(szAnonyName, szAnonyPassword);
  472. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  473. {
  474. // IUSR_ account already exist, reuse it
  475. g_pTheApp->m_csWWWAnonyName = szAnonyName;
  476. // But assume that the password is correct!
  477. g_pTheApp->m_csWWWAnonyPassword = szAnonyPassword;
  478. // make sure this user has the appropriate rights..
  479. RegisterAccountUserRights(g_pTheApp->m_csWWWAnonyName, TRUE, FALSE);
  480. }
  481. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  482. {
  483. // IUSR_ account already exist, reuse it
  484. g_pTheApp->m_csFTPAnonyName = szAnonyName;
  485. // But assume that the password is correct!
  486. g_pTheApp->m_csFTPAnonyPassword = szAnonyPassword;
  487. // make sure this user has the appropriate rights..
  488. RegisterAccountUserRights(g_pTheApp->m_csFTPAnonyName, TRUE, FALSE);
  489. }
  490. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  491. {
  492. // IWAM_ account already exist, resue it
  493. g_pTheApp->m_csWAMAccountName = szAnonyName;
  494. // But assume that the password is correct!
  495. g_pTheApp->m_csWAMAccountPassword = szAnonyPassword;
  496. // make sure the user has the appropriate rights
  497. RegisterAccountUserRights(g_pTheApp->m_csWAMAccountName, TRUE, TRUE);
  498. }
  499. }
  500. else
  501. {
  502. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:The %s user does not exist\n"),MakeThisUserNameAndPasswordWork_log,szAnonyName));
  503. if (IfUserNotExistThenReturnFalse)
  504. {
  505. iReturn = FALSE;
  506. }
  507. else
  508. {
  509. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  510. {
  511. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous W3SVC iusr_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  512. g_pTheApp->m_csWWWAnonyName = szAnonyName;
  513. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  514. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  515. g_pTheApp->m_csWWWAnonyPassword = szAnonyPassword;
  516. CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword,&iUserWasNewlyCreated);
  517. }
  518. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  519. {
  520. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous MSFTPSVC iusr_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  521. g_pTheApp->m_csFTPAnonyName = szAnonyName;
  522. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  523. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  524. g_pTheApp->m_csFTPAnonyPassword = szAnonyPassword;
  525. CreateIUSRAccount(g_pTheApp->m_csFTPAnonyName, g_pTheApp->m_csFTPAnonyPassword,&iUserWasNewlyCreated);
  526. }
  527. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  528. {
  529. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous W3SVC iwam_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  530. g_pTheApp->m_csWAMAccountName = szAnonyName;
  531. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  532. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  533. g_pTheApp->m_csWAMAccountPassword = szAnonyPassword;
  534. CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword,&iUserWasNewlyCreated);
  535. }
  536. }
  537. }
  538. }
  539. MakeThisUserNameAndPasswordWork_Exit:
  540. if (iMetabaseUserExistsButCouldntGetPassword)
  541. {
  542. iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = TRUE;
  543. }
  544. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  545. {
  546. iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = TRUE;
  547. }
  548. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  549. {
  550. // ================
  551. // LM/W3SVC/AnonymousUserName
  552. // LM/W3SVC/AnonymousPwd
  553. // ================
  554. WriteToMD_AnonymousUserName_WWW(iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere);
  555. }
  556. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  557. {
  558. // ================
  559. // LM/MSFTPSVC/AnonymousUserName
  560. // LM/MSFTPSVC/AnonymousPwd
  561. // ================
  562. WriteToMD_AnonymousUserName_FTP(iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere);
  563. }
  564. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  565. {
  566. // ================
  567. // LM/W3SVC/WamUserName
  568. // LM/W3SVC/WamPwd
  569. // ================
  570. WriteToMD_IWamUserName_WWW();
  571. }
  572. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),MakeThisUserNameAndPasswordWork_log,iReturn));
  573. return iReturn;
  574. }
  575. //
  576. // Returns true if it can get the ftp/WWW username and password from the metabase,
  577. // if it can then it will make sure that it can use that user <-- by creating it if it doesn't exist
  578. //
  579. #define CheckIfThisServerHasAUserThenUseIt_log _T("CheckIfThisServerHasAUserThenUseIt")
  580. int CheckIfThisServerHasAUserThenUseIt(int iForWhichUser)
  581. {
  582. int iReturn = FALSE;
  583. TCHAR szAnonyName[UNLEN+1];
  584. TCHAR szAnonyPassword[PWLEN+1];
  585. TCHAR szMetabasePath[_MAX_PATH];
  586. int iMetabaseUserExistsButCouldntGetPassword = TRUE;
  587. // set defaults for the w3svc user
  588. int iMetabaseID_ForUserName = MD_ANONYMOUS_USER_NAME;
  589. int iMetabaseID_ForUserPassword = MD_ANONYMOUS_PWD;
  590. _tcscpy(szMetabasePath,_T("LM/W3SVC"));
  591. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  592. {
  593. _tcscpy(szMetabasePath,_T("LM/MSFTPSVC"));
  594. iMetabaseID_ForUserName = MD_ANONYMOUS_USER_NAME;
  595. iMetabaseID_ForUserPassword = MD_ANONYMOUS_PWD;
  596. }
  597. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  598. {
  599. _tcscpy(szMetabasePath,_T("LM/W3SVC"));
  600. iMetabaseID_ForUserName = MD_WAM_USER_NAME;
  601. iMetabaseID_ForUserPassword = MD_WAM_PWD;
  602. }
  603. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():Start:%s:whichuser=%d\n"),CheckIfThisServerHasAUserThenUseIt_log,szMetabasePath,iForWhichUser));
  604. // See if it's already in the metabase if it is then use that.
  605. if (TRUE == GetDataFromMetabase(szMetabasePath, iMetabaseID_ForUserName, (PBYTE)szAnonyName, UNLEN+1))
  606. {
  607. // Check if the username is null
  608. if (!szAnonyName)
  609. {
  610. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is null.fail.\n")));
  611. iReturn = FALSE;
  612. goto CheckIfThisServerHasAUserThenUseIt_Exit;
  613. }
  614. // Check if just contains nothing
  615. if (_tcsicmp(szAnonyName, _T("")) == 0)
  616. {
  617. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is blank.fail.\n")));
  618. iReturn = FALSE;
  619. goto CheckIfThisServerHasAUserThenUseIt_Exit;
  620. }
  621. // see if we can get the password too!
  622. iMetabaseUserExistsButCouldntGetPassword = TRUE;
  623. if (TRUE == GetDataFromMetabase(szMetabasePath, iMetabaseID_ForUserPassword, (PBYTE)szAnonyPassword, PWLEN+1))
  624. {
  625. iMetabaseUserExistsButCouldntGetPassword = FALSE;
  626. }
  627. // Yes, we got the username and password.
  628. // let's see if they are valid...
  629. MakeThisUserNameAndPasswordWork(iForWhichUser, szAnonyName, szAnonyPassword, iMetabaseUserExistsButCouldntGetPassword, FALSE);
  630. iReturn = TRUE;
  631. }
  632. CheckIfThisServerHasAUserThenUseIt_Exit:
  633. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),CheckIfThisServerHasAUserThenUseIt_log,iReturn));
  634. return iReturn;
  635. }
  636. #define CheckIfServerAHasAUserThenUseForServerB_log _T("CheckIfServerAHasAUserThenUseForServerB")
  637. int CheckIfServerAHasAUserThenUseForServerB(TCHAR *szServerAMetabasePath,int iServerBisWhichUser)
  638. {
  639. int iReturn = FALSE;
  640. TCHAR szAnonyName[UNLEN+1];
  641. TCHAR szAnonyPassword[PWLEN+1];
  642. int iMetabaseUserExistsButCouldntGetPassword = TRUE;
  643. iisDebugOut_Start(CheckIfServerAHasAUserThenUseForServerB_log);
  644. // see if www server has a user there, if it does then use that.
  645. // See if it's already in the metabase if it is then use that.
  646. if (TRUE == GetDataFromMetabase(szServerAMetabasePath, MD_ANONYMOUS_USER_NAME, (PBYTE)szAnonyName, UNLEN+1))
  647. {
  648. // Check if the username is null
  649. if (!szAnonyName)
  650. {
  651. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is null.fail.\n")));
  652. iReturn = FALSE;
  653. goto CheckIfServerAHasAUserThenUseForServerB_Exit;
  654. }
  655. // Check if just contains nothing
  656. if (_tcsicmp(szAnonyName, _T("")) == 0)
  657. {
  658. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is blank.fail.\n")));
  659. iReturn = FALSE;
  660. goto CheckIfServerAHasAUserThenUseForServerB_Exit;
  661. }
  662. // see if we can get the password too!
  663. iMetabaseUserExistsButCouldntGetPassword = TRUE;
  664. if (TRUE == GetDataFromMetabase(szServerAMetabasePath, MD_ANONYMOUS_PWD, (PBYTE)szAnonyPassword, PWLEN+1))
  665. {
  666. iMetabaseUserExistsButCouldntGetPassword = FALSE;
  667. }
  668. // Yes, we got the username and password.
  669. // let's see if they are valid...
  670. MakeThisUserNameAndPasswordWork(iServerBisWhichUser, szAnonyName, szAnonyPassword, iMetabaseUserExistsButCouldntGetPassword, FALSE);
  671. iReturn = TRUE;
  672. }
  673. CheckIfServerAHasAUserThenUseForServerB_Exit:
  674. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),CheckIfServerAHasAUserThenUseForServerB_log,iReturn));
  675. return iReturn;
  676. }
  677. #endif // _CHICAGO_