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.

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