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.

141 lines
3.4 KiB

  1. #include "stdafx.h"
  2. #include "ftpcomp.hxx"
  3. #include "iadm.h"
  4. #include "iiscnfgp.h"
  5. #include "mdkey.h"
  6. #include "mdentry.h"
  7. #include "svc.h"
  8. // GetName
  9. //
  10. // Return the name for the Web Service Component
  11. //
  12. LPTSTR
  13. CFtpServiceInstallComponent::GetName()
  14. {
  15. return _T("iis_ftp");
  16. }
  17. // Post install
  18. //
  19. BOOL
  20. CFtpServiceInstallComponent::PostInstall()
  21. {
  22. iisDebugOut((LOG_TYPE_PROGRAM_FLOW, _T("Executing PostInstall for the FTP component...\n")));
  23. BOOL bResult = TRUE;
  24. // Start the service
  25. // If a flag exists in the unattended file for manual service start - change the servoce startup type
  26. if ( g_pTheApp->dwUnattendConfig & USER_SPECIFIED_INFO_MANUAL_START_FTP )
  27. {
  28. SetServiceStart( _T("MSFTPSVC"), SERVICE_DEMAND_START );
  29. }
  30. else
  31. {
  32. if ( !g_pTheApp->m_fNTGuiMode )
  33. {
  34. // It's not fatal if we fail to start the service, but return result anyway
  35. INT nRes = InetStartService( _T("MSFTPSVC") );
  36. bResult = ( (nRes == ERROR_SUCCESS) || (nRes == ERROR_SERVICE_ALREADY_RUNNING) );
  37. }
  38. }
  39. return bResult;
  40. }
  41. // Install
  42. //
  43. // Install the FTP Component
  44. //
  45. BOOL
  46. CFtpServiceInstallComponent::Install()
  47. {
  48. BOOL bRet = TRUE;
  49. if ( IsUpgrade() )
  50. {
  51. bRet = bRet && IfConflictDisableDefaultSite();
  52. }
  53. return bRet;
  54. }
  55. // IfConflictDisableDefaultSite
  56. //
  57. // If there is already a ftp site on the default ftp site that we just
  58. // created, then disable the default one.
  59. //
  60. // Return Values:
  61. // TRUE - Successfull
  62. // FALSE - Failure checking and setting
  63. BOOL
  64. CFtpServiceInstallComponent::IfConflictDisableDefaultSite()
  65. {
  66. BOOL bDisableDefault = FALSE;
  67. CStringList cslpathList;
  68. CMDKey cmdKey;
  69. POSITION pos;
  70. CMDValue cmdValue;
  71. CString csPath;
  72. BOOL bRet = TRUE;
  73. LPTSTR szPath;
  74. TSTR_MSZ mstrBindings;
  75. if ( FAILED( cmdKey.OpenNode( METABASEPATH_FTP_ROOT ) ) )
  76. {
  77. // Could not open the w3svc node
  78. return FALSE;
  79. }
  80. if (FAILED( cmdKey.GetDataPaths( MD_SERVER_BINDINGS,
  81. MULTISZ_METADATA,
  82. cslpathList) ))
  83. {
  84. // Could not GetDataPaths for this value
  85. return FALSE;
  86. }
  87. pos = cslpathList.GetHeadPosition();
  88. while ( NULL != pos )
  89. {
  90. csPath = cslpathList.GetNext( pos );
  91. szPath = csPath.GetBuffer(0);
  92. if ( ( wcscmp( szPath, L"/1/" ) != 0 ) &&
  93. ( cmdKey.GetData( cmdValue, MD_SERVER_BINDINGS, szPath ) ) &&
  94. ( cmdValue.GetDataType() == MULTISZ_METADATA ) &&
  95. ( mstrBindings.Copy( (LPTSTR) cmdValue.GetData() ) &&
  96. mstrBindings.IsPresent( _T(":21:") ) )
  97. )
  98. {
  99. if ( ( !cmdKey.GetData( cmdValue, MD_SERVER_AUTOSTART, szPath ) ) ||
  100. ( !cmdValue.IsEqual( DWORD_METADATA, 4, (DWORD) 0 ) )
  101. )
  102. {
  103. // If GetData failed, or it succedded and the value is not 0, then we
  104. // have found a match.
  105. bDisableDefault = TRUE;
  106. break;
  107. }
  108. }
  109. }
  110. if ( bDisableDefault )
  111. {
  112. // Now lets set default to not start, since someone else already has this port
  113. if ( !cmdValue.SetValue( MD_SERVER_AUTOSTART, 0, IIS_MD_UT_SERVER, 0 ) ||
  114. !cmdKey.SetData( cmdValue, MD_SERVER_AUTOSTART, L"/1/" ) )
  115. {
  116. bRet = FALSE;
  117. }
  118. }
  119. cmdKey.Close();
  120. return bRet;
  121. }