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.

289 lines
11 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 "setpass.h"
  9. #include "www.h"
  10. int Register_iis_ftp_handle_iusr_acct(void);
  11. int CheckForOtherIUsersAndUseItForFTP(void);
  12. INT Register_iis_ftp(void);
  13. INT Unregister_iis_ftp(void);
  14. // returns true if successfully registered ftp component.
  15. // returns false if failed.
  16. INT Register_iis_ftp()
  17. {
  18. iisDebugOut_Start(_T("Register_iis_ftp"),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 atFTP = GetSubcompAction(_T("iis_ftp"), TRUE);
  25. ProcessSection(g_pTheApp->m_hInfHandle, _T("register_iis_ftp_before"));
  26. AdvanceProgressBarTickGauge();
  27. // Grab the IUSR_machine name account
  28. // so we can save it in the metabase during FTP_Upgrade_RegToMetabase();
  29. Register_iis_ftp_handle_iusr_acct();
  30. SetupSetStringId_Wrapper(g_pTheApp->m_hInfHandle, 33003, g_pTheApp->m_csFTPAnonyName);
  31. AdvanceProgressBarTickGauge();
  32. WriteToMD_Capabilities(_T("MSFTPSVC"));
  33. HandleSecurityTemplates(_T("MSFTPSVC"));
  34. // ================
  35. //
  36. // LM/MSFTPSVC/n/
  37. // LM/MSFTPSVC/n/ServerBindings
  38. // LM/MSFTPSVC/n/SecureBindings
  39. // LM/MSFTPSVC/n/ServerComment
  40. // LM/MSFTPSVC/n/ServerSize
  41. // LM/MSFTPSVC/n/MD_NOT_DELETABLE
  42. //
  43. // fresh = ok.
  44. // reinstall = ok -- Do not re-create these things if it is a reinstall...
  45. // upgrade 1,2,3 = ok, handles upgrades.
  46. // upgrade 4 = ok. if exists, should leave what the user had.
  47. // otherwise write in the default stuff
  48. //
  49. // if the user does not have these virtual roots which we installed during iis4 days
  50. // then we don't need to verify that they are they. the user removed them for some
  51. // reason, and we should honor that.
  52. // a. make sure the iishelp points to the right place though.
  53. // ================
  54. ProgressBarTextStack_Set(IDS_IIS_ALL_CONFIGURE);
  55. AddVRootsToMD(_T("MSFTPSVC"));
  56. iCount = 0;
  57. while(TRUE == iTemp && iCount < 10)
  58. {
  59. iCount++;
  60. _stprintf(szTempSection, _T("register_iis_ftp_%d"),iCount);
  61. // this will return false if the section does not exist
  62. iTemp = ProcessSection(g_pTheApp->m_hInfHandle, szTempSection);
  63. AdvanceProgressBarTickGauge();
  64. }
  65. ProcessSection(g_pTheApp->m_hInfHandle, _T("register_iis_ftp_after"));
  66. ProgressBarTextStack_Pop();
  67. goto Register_iis_ftp_Exit;
  68. Register_iis_ftp_Exit:
  69. iisDebugOut_End(_T("Register_iis_ftp"),LOG_TYPE_TRACE);
  70. return iReturn;
  71. }
  72. INT Unregister_iis_ftp()
  73. {
  74. int iReturn = TRUE;
  75. int iCount = 0;
  76. int iTemp = TRUE;
  77. TCHAR szTempSection[255];
  78. ProcessSection(g_pTheApp->m_hInfHandle, _T("unregister_iis_ftp_before"));
  79. AdvanceProgressBarTickGauge();
  80. iCount = 0;
  81. while(TRUE == iTemp && iCount < 10)
  82. {
  83. iCount++;
  84. _stprintf(szTempSection, _T("unregister_iis_ftp_%d"),iCount);
  85. // this will return false if the section does not exist
  86. iTemp = ProcessSection(g_pTheApp->m_hInfHandle, szTempSection);
  87. AdvanceProgressBarTickGauge();
  88. }
  89. ProcessSection(g_pTheApp->m_hInfHandle, _T("unregister_iis_ftp_after"));
  90. AdvanceProgressBarTickGauge();
  91. return iReturn;
  92. }
  93. int Register_iis_ftp_handle_iusr_acct()
  94. {
  95. int err = FALSE;
  96. int iReturn = TRUE;
  97. INT iUserWasNewlyCreated = 0;
  98. ACTION_TYPE atFTP = GetSubcompAction(_T("iis_ftp"),FALSE);
  99. // this was inited in initapp.cpp: CInitApp::SetSetupParams
  100. // and it could have been overridden by the time we get here
  101. g_pTheApp->m_csFTPAnonyName = g_pTheApp->m_csGuestName;
  102. g_pTheApp->m_csFTPAnonyPassword = g_pTheApp->m_csGuestPassword;
  103. if (0 != g_pTheApp->dwUnattendConfig)
  104. {
  105. // if some sort of unattended www user was specified
  106. // then use it. if they specified only a password,
  107. // then use that password for the default user.
  108. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_FTP_USER_NAME)
  109. {
  110. if (_tcsicmp(g_pTheApp->m_csFTPAnonyName_Unattend,_T("")) != 0)
  111. {
  112. g_pTheApp->m_csFTPAnonyName = g_pTheApp->m_csFTPAnonyName_Unattend;
  113. }
  114. }
  115. if (g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_FTP_USER_PASS)
  116. {
  117. g_pTheApp->m_csFTPAnonyPassword = g_pTheApp->m_csFTPAnonyPassword_Unattend;
  118. }
  119. err = CreateIUSRAccount(g_pTheApp->m_csFTPAnonyName, g_pTheApp->m_csFTPAnonyPassword,&iUserWasNewlyCreated);
  120. if ( err != NERR_Success )
  121. {
  122. // something went wrong, set the user back to guest!!!
  123. g_pTheApp->m_csFTPAnonyName = g_pTheApp->m_csGuestName;
  124. g_pTheApp->m_csFTPAnonyPassword = g_pTheApp->m_csGuestPassword;
  125. // flow down and process CheckIfThisServerHasAUserThenUseIt()
  126. // since things are now hosed!
  127. }
  128. else
  129. {
  130. // Check if the user was NewlyCreated.
  131. // if it was then add it to list that eventually gets written to
  132. // the registry -- so that when uninstall happens, setup knows
  133. // which users it added -- so that it can remove them!
  134. if (1 == iUserWasNewlyCreated)
  135. {
  136. // Add to the list
  137. g_pTheApp->UnInstallList_Add(_T("IUSR_FTP"),g_pTheApp->m_csFTPAnonyName);
  138. }
  139. WriteToMD_AnonymousUserName_FTP(FALSE);
  140. goto Register_iis_ftp_handle_iusr_acct_Exit;
  141. }
  142. }
  143. // check the metabase to see if it already has an entry in it
  144. if (TRUE == CheckIfThisServerHasAUserThenUseIt(DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER))
  145. {goto Register_iis_ftp_handle_iusr_acct_Exit;}
  146. // Well, i guess the there is no metabase entry for the iusr under ftp.
  147. // see if we can get it from somewhere else...
  148. if (atFTP == AT_INSTALL_FRESH)
  149. {
  150. // if this is a fresh install of ftp, then
  151. // let's try to use the www user
  152. if (TRUE == CheckIfServerAHasAUserThenUseForServerB(_T("LM/W3SVC"), DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER))
  153. {goto Register_iis_ftp_handle_iusr_acct_Exit;}
  154. }
  155. // if this is an upgrade or fresh or whatevers
  156. // see if we can get it from an older iis place
  157. if (TRUE == CheckForOtherIUsersAndUseItForFTP())
  158. {goto Register_iis_ftp_handle_iusr_acct_Exit;}
  159. // if there are no registry/existing user combinations
  160. // then we'll have to create a new iusr for ftp
  161. // let's use the iusr_computername deal
  162. g_pTheApp->m_csFTPAnonyName = g_pTheApp->m_csGuestName;
  163. g_pTheApp->m_csFTPAnonyPassword = g_pTheApp->m_csGuestPassword;
  164. CreateIUSRAccount(g_pTheApp->m_csFTPAnonyName, g_pTheApp->m_csFTPAnonyPassword,&iUserWasNewlyCreated);
  165. // ================
  166. // LM/MSFTPSVC/AnonymousUserName
  167. // LM/MSFTPSVC/AnonymousPwd
  168. // ================
  169. WriteToMD_AnonymousUserName_FTP(FALSE);
  170. goto Register_iis_ftp_handle_iusr_acct_Exit;
  171. Register_iis_ftp_handle_iusr_acct_Exit:
  172. return iReturn;
  173. }
  174. // Look in the old iis1.0,2.0,3.0 spot for the ftp user and name.
  175. // retrieve it from the registry..
  176. int CheckForOtherIUsersAndUseItForFTP(void)
  177. {
  178. int iReturn = FALSE;
  179. int IfTheUserNotExistThenDoNotDoThis = TRUE;
  180. TSTR strAnonyName;
  181. CString csAnonyName;
  182. TSTR strAnonyPassword;
  183. CRegKey regFTPParam(HKEY_LOCAL_MACHINE, REG_FTPPARAMETERS, KEY_READ);
  184. CRegKey regWWWParam(HKEY_LOCAL_MACHINE, REG_WWWPARAMETERS, KEY_READ);
  185. iisDebugOut_Start(_T("CheckForOtherIUsersAndUseItForFTP"));
  186. ACTION_TYPE atFTP = GetSubcompAction(_T("iis_ftp"),FALSE);
  187. if (atFTP != AT_INSTALL_UPGRADE)
  188. {goto CheckForOtherIUsersAndUseItForFTP_Exit;}
  189. 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)
  190. {goto CheckForOtherIUsersAndUseItForFTP_Exit;}
  191. if ( (HKEY) regFTPParam )
  192. {
  193. regFTPParam.m_iDisplayWarnings = FALSE;
  194. if (ERROR_SUCCESS == regFTPParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  195. {
  196. if ( !strAnonyName.Copy( csAnonyName.GetBuffer(0) ) ||
  197. !GetAnonymousSecret( _T("FTPD_ANONYMOUS_DATA"), &strAnonyPassword ) )
  198. {
  199. goto CheckForOtherIUsersAndUseItForFTP_Exit;
  200. }
  201. int iThisIsFalseBecauseNoMetabase = FALSE;
  202. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER , strAnonyName.QueryStr(), strAnonyPassword.QueryStr(), iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  203. {
  204. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("CheckForOtherIUsersAndUseItForFTP:using old ftp reg usr:%s.\n"), strAnonyPassword.QueryStr() ));
  205. iReturn = TRUE;
  206. goto CheckForOtherIUsersAndUseItForFTP_Exit;
  207. }
  208. else
  209. {
  210. // the user was not found, so don't use this registry data
  211. // just flow down to the next check
  212. }
  213. }
  214. }
  215. // retrieve from registry
  216. if ( (HKEY) regWWWParam )
  217. {
  218. regWWWParam.m_iDisplayWarnings = FALSE;
  219. if (ERROR_SUCCESS == regWWWParam.QueryValue(_T("AnonymousUserName"), csAnonyName))
  220. {
  221. if ( !strAnonyName.Copy( csAnonyName.GetBuffer(0) ) ||
  222. !GetAnonymousSecret( _T("W3_ANONYMOUS_DATA"), &strAnonyPassword ) )
  223. {
  224. iReturn = FALSE;
  225. goto CheckForOtherIUsersAndUseItForFTP_Exit;
  226. }
  227. int iThisIsFalseBecauseNoMetabase = FALSE;
  228. if (TRUE == MakeThisUserNameAndPasswordWork(DO_IT_FOR_MSFTPSVC_ANONYMOUSUSER , strAnonyName.QueryStr() , strAnonyPassword.QueryStr(), iThisIsFalseBecauseNoMetabase, IfTheUserNotExistThenDoNotDoThis))
  229. {
  230. iisDebugOut((LOG_TYPE_TRACE_WIN32_API, _T("CheckForOtherIUsersAndUseItForFTP:using old www reg usr:%s.\n"),strAnonyName.QueryStr()));
  231. iReturn = TRUE;
  232. }
  233. else
  234. {
  235. // if this didn't work, then we'll have to return false
  236. // in other words -- we couldn't find a valid registry and existing user entry...
  237. iReturn = FALSE;
  238. }
  239. goto CheckForOtherIUsersAndUseItForFTP_Exit;
  240. }
  241. }
  242. CheckForOtherIUsersAndUseItForFTP_Exit:
  243. iisDebugOut_End(_T("CheckForOtherIUsersAndUseItForFTP"));
  244. return iReturn;
  245. }