Leaked source code of windows server 2003
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.

774 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 "setpass.h"
  10. #include "setuser.h"
  11. #include "www.h"
  12. #include "rights.hxx"
  13. extern OCMANAGER_ROUTINES gHelperRoutines;
  14. #define Register_iis_www_log _T("Register_iis_www")
  15. INT Register_iis_www()
  16. {
  17. USE_USER_RIGHTS();
  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. // set AppFriendlyName
  166. for (i=0; i<nArray; i++)
  167. {
  168. CString csPath;
  169. csPath = _T("LM/W3SVC/");
  170. csPath += arrayInstance[i];
  171. SetAppFriendlyName(csPath);
  172. }
  173. goto CreateW3SVCInstances_exit;
  174. CreateW3SVCInstances_exit:
  175. return iReturn;
  176. }
  177. #ifndef _CHICAGO_
  178. #define Register_iis_www_handle_iwam_acct_log _T("Register_iis_www_handle_iwam_acct")
  179. int Register_iis_www_handle_iwam_acct(void)
  180. {
  181. int err = FALSE;
  182. int iReturn = TRUE;
  183. INT iUserWasNewlyCreated = 0;
  184. iisDebugOut_Start(Register_iis_www_handle_iwam_acct_log, LOG_TYPE_TRACE);
  185. if (0 != g_pTheApp->dwUnattendConfig)
  186. {
  187. // if some sort of unattended user was specified
  188. // then use it. if they specified only a password,
  189. // then use that password for the default user.
  190. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WAM_USER_NAME)
  191. {
  192. if (_tcsicmp(g_pTheApp->m_csWAMAccountName_Unattend,_T("")) != 0)
  193. {g_pTheApp->m_csWAMAccountName = g_pTheApp->m_csWAMAccountName_Unattend;}
  194. }
  195. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WAM_USER_PASS)
  196. {
  197. g_pTheApp->m_csWAMAccountPassword = g_pTheApp->m_csWAMAccountPassword_Unattend;
  198. }
  199. // let's use the iusr_computername deal
  200. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  201. if ( err != NERR_Success )
  202. {
  203. // something went wrong, set the user back to iwam!!!
  204. g_pTheApp->ReGetMachineAndAccountNames();
  205. g_pTheApp->ResetWAMPassword();
  206. // flow down and process CheckIfThisServerHasAUserThenUseIt()
  207. // since things are now hosed!
  208. }
  209. else
  210. {
  211. // Check if the user was NewlyCreated.
  212. // if it was then add it to list that eventually gets written to
  213. // the registry -- so that when uninstall happens, setup knows
  214. // which users it added -- so that it can remove them!
  215. if (1 == iUserWasNewlyCreated)
  216. {
  217. // Add to the list
  218. g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),g_pTheApp->m_csWAMAccountName);
  219. }
  220. WriteToMD_IWamUserName_WWW();
  221. goto Register_iis_www_handle_iwam_acct_Exit;
  222. }
  223. }
  224. if (TRUE == CheckIfThisServerHasAUserThenUseIt(DO_IT_FOR_W3SVC_WAMUSER))
  225. {goto Register_iis_www_handle_iwam_acct_Exit;}
  226. // if there are no registry/existing user combinations
  227. // then we'll have to create a new iusr for WWW
  228. // let's use the iusr_computername deal
  229. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  230. if ( err != NERR_Success )
  231. {
  232. // regenerate the password and try again...
  233. g_pTheApp->ResetWAMPassword();
  234. err = CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword, &iUserWasNewlyCreated);
  235. }
  236. // Check if the user was NewlyCreated.
  237. // if it was then add it to list that eventually gets written to
  238. // the registry -- so that when uninstall happens, setup knows
  239. // which users it added -- so that it can remove them!
  240. if (1 == iUserWasNewlyCreated)
  241. {
  242. // Add to the list
  243. //g_pTheApp->UnInstallList_Add(_T("IUSR_WAM"),g_pTheApp->m_csWAMAccountName);
  244. }
  245. // Stick iwam username in the metabase
  246. // (this may fail because the password is using encryption -- rsabase.dll)
  247. // ================
  248. // LM/W3SVC/WamUserName
  249. // LM/W3SVC/WamPwd
  250. // ================
  251. WriteToMD_IWamUserName_WWW();
  252. goto Register_iis_www_handle_iwam_acct_Exit;
  253. Register_iis_www_handle_iwam_acct_Exit:
  254. iisDebugOut_End(Register_iis_www_handle_iwam_acct_log, LOG_TYPE_TRACE);
  255. return iReturn;
  256. }
  257. #define Register_iis_www_handle_iusr_acct_log _T("Register_iis_www_handle_iusr_acct")
  258. int Register_iis_www_handle_iusr_acct(void)
  259. {
  260. int err = FALSE;
  261. int iReturn = TRUE;
  262. INT iUserWasNewlyCreated = 0;
  263. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),FALSE);
  264. iisDebugOut_Start(Register_iis_www_handle_iusr_acct_log, LOG_TYPE_TRACE);
  265. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  266. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  267. if (0 != g_pTheApp->dwUnattendConfig)
  268. {
  269. // if some sort of unattended www user was specified
  270. // then use it. if they specified only a password,
  271. // then use that password for the default user.
  272. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WWW_USER_NAME)
  273. {
  274. if (_tcsicmp(g_pTheApp->m_csWWWAnonyName_Unattend,_T("")) != 0)
  275. {g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csWWWAnonyName_Unattend;}
  276. }
  277. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_WWW_USER_PASS)
  278. {
  279. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csWWWAnonyPassword_Unattend;
  280. }
  281. err = CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword, &iUserWasNewlyCreated);
  282. if ( err != NERR_Success )
  283. {
  284. // something went wrong, set the user back to guest!!!
  285. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  286. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  287. // flow down and process CheckIfThisServerHasAUserThenUseIt()
  288. // since things are now hosed!
  289. }
  290. else
  291. {
  292. // Check if the user was NewlyCreated.
  293. // if it was then add it to list that eventually gets written to
  294. // the registry -- so that when uninstall happens, setup knows
  295. // which users it added -- so that it can remove them!
  296. if (1 == iUserWasNewlyCreated)
  297. {
  298. // Add to the list
  299. g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),g_pTheApp->m_csWWWAnonyName);
  300. }
  301. WriteToMD_AnonymousUserName_WWW(FALSE);
  302. goto Register_iis_www_handle_iusr_acct_Exit;
  303. }
  304. }
  305. if (TRUE == CheckIfThisServerHasAUserThenUseIt(DO_IT_FOR_W3SVC_ANONYMOUSUSER))
  306. {goto Register_iis_www_handle_iusr_acct_Exit;}
  307. // Well, i guess the there is no metabase entry for the iusr under ftp.
  308. // see if we can get it from somewhere else...
  309. if (atWWW == AT_INSTALL_FRESH)
  310. {
  311. // if this is a fresh install of ftp, then
  312. // let's try to use the www user
  313. if (TRUE == CheckIfServerAHasAUserThenUseForServerB(_T("LM/MSFTPSVC"), DO_IT_FOR_W3SVC_ANONYMOUSUSER))
  314. {goto Register_iis_www_handle_iusr_acct_Exit;}
  315. }
  316. // if this is an upgrade or fresh or whatevers
  317. // see if we can get it from an older iis place
  318. if (TRUE == CheckForOtherIUsersAndUseItForWWW())
  319. {goto Register_iis_www_handle_iusr_acct_Exit;}
  320. // if there are no registry/existing user combinations
  321. // then we'll have to create a new iusr for WWW
  322. // this was inited in initapp.cpp: CInitApp::SetSetupParams
  323. // and it could have been overridden by the time we get here
  324. // let's use the iusr_computername deal
  325. g_pTheApp->m_csWWWAnonyName = g_pTheApp->m_csGuestName;
  326. g_pTheApp->m_csWWWAnonyPassword = g_pTheApp->m_csGuestPassword;
  327. CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword, &iUserWasNewlyCreated);
  328. if (1 == iUserWasNewlyCreated)
  329. {
  330. // Add to the list
  331. //g_pTheApp->UnInstallList_Add(_T("IUSR_WWW"),g_pTheApp->m_csWWWAnonyName);
  332. }
  333. // ================
  334. // LM/W3SVC/AnonymousUserName
  335. // LM/W3SVC/AnonymousPwd
  336. // ================
  337. WriteToMD_AnonymousUserName_WWW(FALSE);
  338. goto Register_iis_www_handle_iusr_acct_Exit;
  339. Register_iis_www_handle_iusr_acct_Exit:
  340. iisDebugOut_End(Register_iis_www_handle_iusr_acct_log, LOG_TYPE_TRACE);
  341. return iReturn;
  342. }
  343. // Look in the old iis1.0,2.0,3.0 spot for the ftp user and name.
  344. // retrieve it from the registry..
  345. #define CheckForOtherIUsersAndUseItForWWW_log _T("CheckForOtherIUsersAndUseItForWWW")
  346. int CheckForOtherIUsersAndUseItForWWW(void)
  347. {
  348. int iReturn = FALSE;
  349. int IfTheUserNotExistThenDoNotDoThis = TRUE;
  350. CString csAnonyName;
  351. TCHAR szAnonyName[UNLEN+1];
  352. TSTR strAnonyPassword;
  353. iisDebugOut_Start(CheckForOtherIUsersAndUseItForWWW_log);
  354. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, REG_FTPPARAMETERS, KEY_READ);
  355. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, REG_WWWPARAMETERS, KEY_READ);
  356. ACTION_TYPE atWWW = GetSubcompAction(_T("iis_www"),FALSE);
  357. if (atWWW != AT_INSTALL_UPGRADE)
  358. {goto CheckForOtherIUsersAndUseItForWWW_Exit;}
  359. 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)
  360. {goto CheckForOtherIUsersAndUseItForWWW_Exit;}
  361. // retrieve from registry
  362. if ( (HKEY) regWWWParam )
  363. {
  364. regWWWParam.m_iDisplayWarnings = FALSE;
  365. if (ERROR_SUCCESS == regWWWParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  366. {
  367. _tcscpy(szAnonyName, csAnonyName);
  368. if ( !GetAnonymousSecret( _T("W3_ANONYMOUS_DATA"), &strAnonyPassword ) )
  369. {
  370. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  371. }
  372. int iThisIsFalseBecauseNoMetabase = FALSE;
  373. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_W3SVC_ANONYMOUSUSER, szAnonyName, strAnonyPassword.QueryStr(), iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  374. {
  375. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:using old www reg usr:%s.\n"),CheckForOtherIUsersAndUseItForWWW_log,szAnonyName));
  376. iReturn = TRUE;
  377. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  378. }
  379. else
  380. {
  381. // the user was not found, so don't use this registry data
  382. // just flow down to the next check
  383. }
  384. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  385. }
  386. }
  387. if ( (HKEY) regFTPParam )
  388. {
  389. regFTPParam.m_iDisplayWarnings = FALSE;
  390. if (ERROR_SUCCESS == regFTPParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  391. {
  392. _tcscpy(szAnonyName, csAnonyName);
  393. if ( !GetAnonymousSecret( _T("FTPD_ANONYMOUS_DATA"), &strAnonyPassword ) )
  394. {
  395. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  396. }
  397. int iThisIsFalseBecauseNoMetabase = FALSE;
  398. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_W3SVC_ANONYMOUSUSER, szAnonyName, strAnonyPassword.QueryStr(), iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  399. {
  400. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:using old ftp reg usr:%s.\n"),CheckForOtherIUsersAndUseItForWWW_log,szAnonyName));
  401. iReturn = TRUE;
  402. goto CheckForOtherIUsersAndUseItForWWW_Exit;
  403. }
  404. else
  405. {
  406. // if this didn't work, then we'll have to return false
  407. // in other words -- we couldn't find a valid registry and existing user entry...
  408. iReturn = FALSE;
  409. }
  410. }
  411. }
  412. CheckForOtherIUsersAndUseItForWWW_Exit:
  413. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d\n"),CheckForOtherIUsersAndUseItForWWW_log,iReturn));
  414. return iReturn;
  415. }
  416. #define MakeThisUserNameAndPasswordWork_log _T("MakeThisUserNameAndPasswordWork")
  417. int MakeThisUserNameAndPasswordWork(int iForWhichUser, TCHAR *szAnonyName,TCHAR *szAnonyPassword, int iMetabaseUserExistsButCouldntGetPassword, int IfUserNotExistThenReturnFalse)
  418. {
  419. USE_USER_RIGHTS();
  420. int iReturn = TRUE;
  421. int iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = FALSE;
  422. INT iUserWasNewlyCreated = 0;
  423. // We want to see if these users exists
  424. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:usrtype=%d:flag1=%d:flag2=%d\n"),MakeThisUserNameAndPasswordWork_log,iForWhichUser,szAnonyName,iMetabaseUserExistsButCouldntGetPassword,IfUserNotExistThenReturnFalse));
  425. // check if anonyname is blank
  426. if (!szAnonyName) {goto MakeThisUserNameAndPasswordWork_Exit;}
  427. // Check if just contains nothing
  428. if (_tcsicmp(szAnonyName, _T("")) == 0) {goto MakeThisUserNameAndPasswordWork_Exit;}
  429. // Only check if the user exists if this is a user on this machine.
  430. // if it is not a user on this machine, then don't validate the user/password,
  431. // since during Guimode setup, they may not be connected to the network.
  432. if ( IsDomainSpecifiedOtherThanLocalMachine(szAnonyName))
  433. {
  434. // use whatever they had.
  435. // can't verify that the user exists.
  436. // can't verify that the password actually works.
  437. // so we can't verify that the user exists, so let's figure it doesn't
  438. if (IfUserNotExistThenReturnFalse)
  439. {
  440. iReturn = FALSE;
  441. }
  442. }
  443. else
  444. {
  445. // Check if this user actually exists...
  446. if (IsUserExist(szAnonyName))
  447. {
  448. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:The %s user exists\n"),MakeThisUserNameAndPasswordWork_log,szAnonyName));
  449. // The only way we can be down here is if the username is a local account.
  450. // Reset the password to make sure it works!
  451. ChangeUserPassword(szAnonyName, szAnonyPassword);
  452. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  453. {
  454. // IUSR_ account already exist, reuse it
  455. g_pTheApp->m_csWWWAnonyName = szAnonyName;
  456. // But assume that the password is correct!
  457. g_pTheApp->m_csWWWAnonyPassword = szAnonyPassword;
  458. // make sure this user has the appropriate rights..
  459. UpdateUserRights(g_pTheApp->m_csWWWAnonyName,g_pstrRightsFor_IUSR,sizeof(g_pstrRightsFor_IUSR)/sizeof(LPTSTR), TRUE);
  460. }
  461. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  462. {
  463. // IUSR_ account already exist, reuse it
  464. g_pTheApp->m_csFTPAnonyName = szAnonyName;
  465. // But assume that the password is correct!
  466. g_pTheApp->m_csFTPAnonyPassword = szAnonyPassword;
  467. // make sure this user has the appropriate rights..
  468. UpdateUserRights(g_pTheApp->m_csFTPAnonyName,g_pstrRightsFor_IUSR,sizeof(g_pstrRightsFor_IUSR)/sizeof(LPTSTR), TRUE);
  469. }
  470. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  471. {
  472. // IWAM_ account already exist, resue it
  473. g_pTheApp->m_csWAMAccountName = szAnonyName;
  474. // But assume that the password is correct!
  475. g_pTheApp->m_csWAMAccountPassword = szAnonyPassword;
  476. // make sure the user has the appropriate rights
  477. UpdateUserRights(g_pTheApp->m_csWAMAccountName,g_pstrRightsFor_IWAM,sizeof(g_pstrRightsFor_IWAM)/sizeof(LPTSTR), TRUE);
  478. }
  479. }
  480. else
  481. {
  482. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s:The %s user does not exist\n"),MakeThisUserNameAndPasswordWork_log,szAnonyName));
  483. if (IfUserNotExistThenReturnFalse)
  484. {
  485. iReturn = FALSE;
  486. }
  487. else
  488. {
  489. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  490. {
  491. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous W3SVC iusr_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  492. g_pTheApp->m_csWWWAnonyName = szAnonyName;
  493. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  494. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  495. g_pTheApp->m_csWWWAnonyPassword = szAnonyPassword;
  496. CreateIUSRAccount(g_pTheApp->m_csWWWAnonyName, g_pTheApp->m_csWWWAnonyPassword,&iUserWasNewlyCreated);
  497. }
  498. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  499. {
  500. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous MSFTPSVC iusr_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  501. g_pTheApp->m_csFTPAnonyName = szAnonyName;
  502. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  503. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  504. g_pTheApp->m_csFTPAnonyPassword = szAnonyPassword;
  505. CreateIUSRAccount(g_pTheApp->m_csFTPAnonyName, g_pTheApp->m_csFTPAnonyPassword,&iUserWasNewlyCreated);
  506. }
  507. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  508. {
  509. iisDebugOut((LOG_TYPE_WARN, _T("%s():FAIL WARNING: previous W3SVC iwam_ does not exist. creating a new one.\n"),MakeThisUserNameAndPasswordWork_log));
  510. g_pTheApp->m_csWAMAccountName = szAnonyName;
  511. if (!szAnonyPassword || _tcsicmp(szAnonyPassword, _T("")) == 0)
  512. {_tcscpy(szAnonyPassword,g_pTheApp->m_csGuestPassword);}
  513. g_pTheApp->m_csWAMAccountPassword = szAnonyPassword;
  514. CreateIWAMAccount(g_pTheApp->m_csWAMAccountName,g_pTheApp->m_csWAMAccountPassword,&iUserWasNewlyCreated);
  515. }
  516. }
  517. }
  518. }
  519. MakeThisUserNameAndPasswordWork_Exit:
  520. if (iMetabaseUserExistsButCouldntGetPassword)
  521. {
  522. iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = TRUE;
  523. }
  524. if (g_pTheApp->m_bUpgradeTypeHasMetabaseFlag)
  525. {
  526. iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere = TRUE;
  527. }
  528. if (iForWhichUser == DO_IT_FOR_W3SVC_ANONYMOUSUSER)
  529. {
  530. // ================
  531. // LM/W3SVC/AnonymousUserName
  532. // LM/W3SVC/AnonymousPwd
  533. // ================
  534. WriteToMD_AnonymousUserName_WWW(iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere);
  535. }
  536. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  537. {
  538. // ================
  539. // LM/MSFTPSVC/AnonymousUserName
  540. // LM/MSFTPSVC/AnonymousPwd
  541. // ================
  542. WriteToMD_AnonymousUserName_FTP(iMetabaseUpgradeScenarioSoOverWriteOnlyIfAlreadyThere);
  543. }
  544. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  545. {
  546. // ================
  547. // LM/W3SVC/WamUserName
  548. // LM/W3SVC/WamPwd
  549. // ================
  550. WriteToMD_IWamUserName_WWW();
  551. }
  552. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),MakeThisUserNameAndPasswordWork_log,iReturn));
  553. return iReturn;
  554. }
  555. //
  556. // Returns true if it can get the ftp/WWW username and password from the metabase,
  557. // if it can then it will make sure that it can use that user <-- by creating it if it doesn't exist
  558. //
  559. #define CheckIfThisServerHasAUserThenUseIt_log _T("CheckIfThisServerHasAUserThenUseIt")
  560. int CheckIfThisServerHasAUserThenUseIt(int iForWhichUser)
  561. {
  562. int iReturn = FALSE;
  563. TCHAR szAnonyName[UNLEN+1];
  564. TCHAR szAnonyPassword[PWLEN+1];
  565. TCHAR szMetabasePath[_MAX_PATH];
  566. int iMetabaseUserExistsButCouldntGetPassword = TRUE;
  567. // set defaults for the w3svc user
  568. int iMetabaseID_ForUserName = MD_ANONYMOUS_USER_NAME;
  569. int iMetabaseID_ForUserPassword = MD_ANONYMOUS_PWD;
  570. _tcscpy(szMetabasePath,_T("LM/W3SVC"));
  571. if (iForWhichUser == DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER)
  572. {
  573. _tcscpy(szMetabasePath,_T("LM/MSFTPSVC"));
  574. iMetabaseID_ForUserName = MD_ANONYMOUS_USER_NAME;
  575. iMetabaseID_ForUserPassword = MD_ANONYMOUS_PWD;
  576. }
  577. if (iForWhichUser == DO_IT_FOR_W3SVC_WAMUSER)
  578. {
  579. _tcscpy(szMetabasePath,_T("LM/W3SVC"));
  580. iMetabaseID_ForUserName = MD_WAM_USER_NAME;
  581. iMetabaseID_ForUserPassword = MD_WAM_PWD;
  582. }
  583. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():Start:%s:whichuser=%d\n"),CheckIfThisServerHasAUserThenUseIt_log,szMetabasePath,iForWhichUser));
  584. // See if it's already in the metabase if it is then use that.
  585. if (TRUE == GetDataFromMetabase(szMetabasePath, iMetabaseID_ForUserName, (PBYTE)szAnonyName, UNLEN+1))
  586. {
  587. // Check if the username is null
  588. if (!szAnonyName)
  589. {
  590. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is null.fail.\n")));
  591. iReturn = FALSE;
  592. goto CheckIfThisServerHasAUserThenUseIt_Exit;
  593. }
  594. // Check if just contains nothing
  595. if (_tcsicmp(szAnonyName, _T("")) == 0)
  596. {
  597. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is blank.fail.\n")));
  598. iReturn = FALSE;
  599. goto CheckIfThisServerHasAUserThenUseIt_Exit;
  600. }
  601. // see if we can get the password too!
  602. iMetabaseUserExistsButCouldntGetPassword = TRUE;
  603. if (TRUE == GetDataFromMetabase(szMetabasePath, iMetabaseID_ForUserPassword, (PBYTE)szAnonyPassword, PWLEN+1))
  604. {
  605. iMetabaseUserExistsButCouldntGetPassword = FALSE;
  606. }
  607. // Yes, we got the username and password.
  608. // let's see if they are valid...
  609. MakeThisUserNameAndPasswordWork(iForWhichUser, szAnonyName, szAnonyPassword, iMetabaseUserExistsButCouldntGetPassword, FALSE);
  610. iReturn = TRUE;
  611. }
  612. CheckIfThisServerHasAUserThenUseIt_Exit:
  613. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),CheckIfThisServerHasAUserThenUseIt_log,iReturn));
  614. return iReturn;
  615. }
  616. #define CheckIfServerAHasAUserThenUseForServerB_log _T("CheckIfServerAHasAUserThenUseForServerB")
  617. int CheckIfServerAHasAUserThenUseForServerB(TCHAR *szServerAMetabasePath,int iServerBisWhichUser)
  618. {
  619. int iReturn = FALSE;
  620. TCHAR szAnonyName[UNLEN+1];
  621. TCHAR szAnonyPassword[PWLEN+1];
  622. int iMetabaseUserExistsButCouldntGetPassword = TRUE;
  623. iisDebugOut_Start(CheckIfServerAHasAUserThenUseForServerB_log);
  624. // see if www server has a user there, if it does then use that.
  625. // See if it's already in the metabase if it is then use that.
  626. if (TRUE == GetDataFromMetabase(szServerAMetabasePath, MD_ANONYMOUS_USER_NAME, (PBYTE)szAnonyName, UNLEN+1))
  627. {
  628. // Check if the username is null
  629. if (!szAnonyName)
  630. {
  631. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is null.fail.\n")));
  632. iReturn = FALSE;
  633. goto CheckIfServerAHasAUserThenUseForServerB_Exit;
  634. }
  635. // Check if just contains nothing
  636. if (_tcsicmp(szAnonyName, _T("")) == 0)
  637. {
  638. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("...GetDataFromMetabase:username is blank.fail.\n")));
  639. iReturn = FALSE;
  640. goto CheckIfServerAHasAUserThenUseForServerB_Exit;
  641. }
  642. // see if we can get the password too!
  643. iMetabaseUserExistsButCouldntGetPassword = TRUE;
  644. if (TRUE == GetDataFromMetabase(szServerAMetabasePath, MD_ANONYMOUS_PWD, (PBYTE)szAnonyPassword, PWLEN+1))
  645. {
  646. iMetabaseUserExistsButCouldntGetPassword = FALSE;
  647. }
  648. // Yes, we got the username and password.
  649. // let's see if they are valid...
  650. MakeThisUserNameAndPasswordWork(iServerBisWhichUser, szAnonyName, szAnonyPassword, iMetabaseUserExistsButCouldntGetPassword, FALSE);
  651. iReturn = TRUE;
  652. }
  653. CheckIfServerAHasAUserThenUseForServerB_Exit:
  654. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("%s():End.ret=%d.\n"),CheckIfServerAHasAUserThenUseForServerB_log,iReturn));
  655. return iReturn;
  656. }
  657. #endif // _CHICAGO_