]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
CAF - Preconfigure the listener + follow guest proxy
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:52 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:52 +0000 (11:23 -0700)
Listener is auto configured during the install upon MA being started.
Listener is started/stopped automatically when tunnel is enabled/disabled.

12 files changed:
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CFileSystemUtils.cpp
open-vm-tools/common-agent/Cpp/Framework/Framework/src/Common/CFileSystemUtils.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/include/CMonitorReadingMessageSource.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnv.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CConfigEnvMerge.h
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/CMonitorReadingMessageSource.cpp
open-vm-tools/common-agent/Cpp/ManagementAgent/Subsystems/MaIntegration/src/stdafx.h
open-vm-tools/common-agent/etc/config/CommAmqpListener-appconfig
open-vm-tools/common-agent/etc/config/ma-appconfig
open-vm-tools/common-agent/etc/config/providerFx-appconfig
open-vm-tools/common-agent/etc/install/preconfigure-listener.sh [new file with mode: 0644]

index 38435f2d64e73d4d67e6861f82961e063c8bf662..d153289dce421712d934defa2b72af6e96ec6d63 100644 (file)
@@ -1286,6 +1286,32 @@ std::string FileSystemUtils::getTempFilename(const std::string& filename_templat
        }
        CAF_CM_EXIT;
        CAF_CM_VALIDATE_STRING(filename);
-       
+
        return filename;
 }
+
+std::string FileSystemUtils::executeScript(
+               const std::string& scriptPath,
+               const std::string& scriptResultsDir) {
+       CAF_CM_STATIC_FUNC_LOG_VALIDATE("FileSystemUtils", "executeScript");
+       CAF_CM_VALIDATE_STRING(scriptPath);
+       CAF_CM_VALIDATE_STRING(scriptResultsDir);
+
+       Cdeqstr argv;
+       argv.push_back(scriptPath);
+
+       const std::string basename = FileSystemUtils::getBasename(scriptPath);
+       const std::string stdoutPath = FileSystemUtils::buildPath(
+                       scriptResultsDir, basename + ".stdout");
+       const std::string stderrPath = FileSystemUtils::buildPath(
+                       scriptResultsDir, basename + ".stderr");
+
+       ProcessUtils::runSyncToFiles(argv, stdoutPath, stderrPath);
+
+       std::string rc;
+       if (FileSystemUtils::doesFileExist(stdoutPath)) {
+               rc = FileSystemUtils::loadTextFile(stdoutPath);
+       }
+
+       return rc;
+}
index c3fbd2a94c875ecf6ceb2ae1dadef97b7c3578b1..c89bf9f3840b3469cf242482ba671b0cc08b724d 100644 (file)
@@ -178,11 +178,15 @@ public:
                const std::string &path);
 
        static int64 getFileSize(const std::string& filename);
-       
+
        static std::string saveTempTextFile(const std::string& filename_template, const std::string& contents);
-       
+
        static std::string getTempFilename(const std::string& filename_template);
 
+       static std::string executeScript(
+               const std::string& scriptPath,
+               const std::string& scriptResultsDir);
+
 private:
        static void saveFileSafely(
                const std::string& filePath,
index 79524055581c0429edac9a10ac3ab429935592e6..66ac5a319ed7079623c63a2305bccd16015affd0 100644 (file)
@@ -77,6 +77,8 @@ private:
        int32 _listenerRetryCnt;
        int32 _listenerRetryMax;
 
+       SmartPtrCMonitorListener _monitorListener;
+
 private:
        CAF_CM_CREATE;
        CAF_CM_CREATE_LOG;
index ec20955a8aae3f83a00671d9a9cb54d1b8a3531a..c26e3adfdeb11e83e59ab1ded93ada9384fdf06d 100644 (file)
@@ -42,6 +42,9 @@ void CConfigEnv::initialize(
                        _persistenceRemove = persistenceRemove;
                }
        } else {
+               _monitorListener.CreateInstance();
+               _monitorListener->initialize();
+
                _persistenceRemove = persistenceRemove;
 
                _persistenceDir = AppConfigUtils::getRequiredString("persistence_dir");
@@ -78,16 +81,20 @@ SmartPtrCPersistenceDoc CConfigEnv::getUpdated(
        CAF_CM_LOCK_UNLOCK;
        CAF_CM_PRECOND_ISINITIALIZED(_isInitialized);
 
+       bool preConfigDoneNow = _monitorListener->preConfigureListener();
        if (FileSystemUtils::doesFileExist(_listenerConfiguredStage1Path)) {
-               if (_persistence.IsNull()) {
+               if (_persistence.IsNull() || preConfigDoneNow) {
                        _persistence = CPersistenceUtils::loadPersistence(_persistenceDir);
                        if (FileSystemUtils::doesFileExist(_listenerConfiguredStage2Path)) {
                                _persistenceUpdated = _persistence;
                        }
                }
 
-               const SmartPtrCPersistenceDoc persistenceTmp =
-                               CConfigEnvMerge::mergePersistence(_persistence, _cacertPath, _vcidPath);
+               SmartPtrCPersistenceDoc persistenceTmp;
+               if (preConfigDoneNow) {
+                       persistenceTmp = CConfigEnvMerge::mergePersistence(
+                                       _persistence, _cacertPath, _vcidPath);
+               }
                if (! persistenceTmp.IsNull()) {
                        CPersistenceUtils::savePersistence(persistenceTmp, _persistenceDir);
                        _persistence = CPersistenceUtils::loadPersistence(_persistenceDir);
@@ -117,6 +124,8 @@ void CConfigEnv::update(
        CAF_CM_LOCK_UNLOCK;
        CAF_CM_PRECOND_ISINITIALIZED(_isInitialized);
 
+       getUpdated(0);
+
        const SmartPtrCPersistenceDoc persistenceTmp1 =
                        CPersistenceMerge::mergePersistence(_persistence, persistence);
 
index 35a19eeac56be54bc3996c4b1412285ac4b8aef4..4931a0704c9f90edc448f2bc060a58e424e6518a 100644 (file)
@@ -91,6 +91,7 @@ private:
        SmartPtrCPersistenceDoc _persistence;
        SmartPtrCPersistenceDoc _persistenceUpdated;
        SmartPtrIPersistence _persistenceRemove;
+       SmartPtrCMonitorListener _monitorListener;
 
 private:
        CAF_CM_CREATE;
index 50c66f2bea558011da924c91198c633de9023d92..7d2a6729ac52cab84926442545ab56054d3d9e14 100644 (file)
@@ -23,6 +23,8 @@ public:
                        const std::string& cacertPath,
                        const std::string& vcidPath);
 
+       static bool isTunnelEnabledFunc();
+
 private:
        static std::deque<SmartPtrCPersistenceProtocolDoc> mergePersistenceProtocolCollectionInner(
                        const std::deque<SmartPtrCPersistenceProtocolDoc>& persistenceProtocolCollectionInner,
@@ -43,8 +45,6 @@ private:
                        const std::string& cacert);
 
 private:
-       static bool isTunnelEnabledFunc();
-
        static std::string loadTextFile(
                        const std::string& path);
 
index e31b09c91ffbd1e00245319004225657d07b1853..d5fd0f1c794a2f3a3ff628d15afb0ccf2095e977 100644 (file)
@@ -15,6 +15,8 @@
 
 using namespace Caf;
 
+#define LISTENER_STARTUP_TYPE_AUTOMATIC "Automatic"
+
 CMonitorReadingMessageSource::CMonitorReadingMessageSource() :
                _isInitialized(false),
                _listenerStartTimeMs(0),
@@ -38,6 +40,10 @@ void CMonitorReadingMessageSource::initialize(
        const SmartPtrIDocument pollerDoc = configSection->findOptionalChild("poller");
        setPollerMetadata(pollerDoc);
 
+
+       _monitorListener.CreateInstance();
+       _monitorListener->initialize();
+
        _monitorDir = AppConfigUtils::getRequiredString("monitor_dir");
        _restartListenerPath = FileSystemUtils::buildPath(_monitorDir, "restartListener.txt");
        _listenerConfiguredStage2Path = FileSystemUtils::buildPath(_monitorDir, "listenerConfiguredStage2.txt");
@@ -89,6 +95,10 @@ SmartPtrIIntMessage CMonitorReadingMessageSource::doReceive(
        }
 
        std::string reason;
+       // If Listener is pre-configured and Tunnel enabled, start listener
+       // Sets startup type if it is following tunnel
+       _monitorListener->followTunnel(_listenerStartupType);
+
        if (FileSystemUtils::doesFileExist(_listenerConfiguredStage2Path)) {
                if (FileSystemUtils::doesFileExist(_restartListenerPath)) {
                        reason = FileSystemUtils::loadTextFile(_restartListenerPath);
@@ -115,7 +125,7 @@ SmartPtrIIntMessage CMonitorReadingMessageSource::doReceive(
                                                                + CStringConv::toString<int32>(_listenerRetryMax);
                                                _listenerRetryCnt++;
                                                _listenerStartTimeMs = CDateTimeUtils::getTimeMs();
-                                               startListener(reason);
+                                               _monitorListener->startListener(reason);
                                        } else {
                                                reason = "Listener not running... Retries exhausted - "
                                                                + CStringConv::toString<int32>(_listenerRetryCnt + 1) + " of "
index d5706154baa9c6919124ab1d1a280bc4c04ecf8f..7b151e19e28b41183a00af16b03d0653c6763dbe 100644 (file)
@@ -30,6 +30,8 @@
 #include "CPersistenceInboundChannelAdapterInstance.h"
 #include "CPersistenceOutboundChannelAdapterInstance.h"
 
+#include "CMonitorListener.h"
+
 #include "CPersistenceMerge.h"
 #include "CConfigEnvMerge.h"
 #include "CConfigEnv.h"
@@ -37,7 +39,6 @@
 #include "CConfigEnvInboundChannelAdapterInstance.h"
 #include "CConfigEnvOutboundChannelAdapterInstance.h"
 
-
 #include "CCollectSchemaExecutor.h"
 #include "CProviderCollectSchemaExecutor.h"
 #include "CProviderExecutor.h"
index b34e557511407b30b5fa380b71f29d073b0e5ef9..e5825e2519598498de8c90b8a9f1e72d8d305a73 100644 (file)
@@ -40,9 +40,9 @@ channel_cache_size=4
 reply_timeout=5000
 
 [security]
-cms_policy=CAF_Encrypted_And_Signed
-is_signing_enforced=true
-is_encryption_enforced=true
+cms_policy=None
+is_signing_enforced=false
+is_encryption_enforced=false
 
 tls_protocol=TLSv1_2
 tls_ciphers=SRP-RSA-AES-128-CBC-SHA
index 1818b9bac7459f0440ed2756638219e32a5ef1b0..4393ac70660b7905d4f004c24508991e5e002fc6 100644 (file)
@@ -8,6 +8,7 @@ tmp_dir=${output_dir}/tmp
 bean_config_file=${config_dir}/ma-context.xml
 log_config_file=${config_dir}/ma-log4cpp_config
 scripts_dir=${config_dir}/../scripts
+install_dir=${config_dir}/../install
 
 thread_stack_size_kb=0
 
@@ -17,7 +18,7 @@ schema_location_root=${input_dir}/schemas/caf
 remap_logging_location=false
 
 [security]
-cms_policy=CAF_Encrypted_And_Signed
+cms_policy=None
 
 [managementAgent]
 host_delay_sec=5
@@ -49,6 +50,8 @@ diagFileAlias_IntBeanConfigFile=file://${root_dir}/config/IntBeanConfigFile.xml?
 listener_retry_max=-1
 listener_startup_type=Automatic
 listener_restart_hours=48
+listener_ctrl_preconfigure=1
+listener_ctrl_follow_tunnel=1
 nsdb_poller_signal_file=${monitor_dir}/nsdbPollerSignal.txt
 nsdb_polling_interval_secs=86400
 
index 94858c318fec0dd70dd4a64d8324953b43847032..50e775ac92e8f103d428f93ff7908f00c4621ab5 100644 (file)
@@ -21,4 +21,4 @@ provider_reg_dir=${input_dir}/providerReg
 common_packages_dir=${input_dir}/commonPackages
 
 [security]
-cms_policy=CAF_Encrypted_And_Signed
\ No newline at end of file
+cms_policy=None
\ No newline at end of file
diff --git a/open-vm-tools/common-agent/etc/install/preconfigure-listener.sh b/open-vm-tools/common-agent/etc/install/preconfigure-listener.sh
new file mode 100644 (file)
index 0000000..75d49b6
--- /dev/null
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+#Standard env
+SCRIPT=`basename "$0"`
+
+installDir=$(dirname $(readlink -f $0))
+scriptsDir=$installDir/../scripts
+configDir=$installDir/../config
+
+set_caf_pme_paths()
+{
+       PATH=$PATH:$installDir:$scriptsDir
+       PERSISTENCE_DIR=${CAF_INPUT_DIR}/persistence
+        CERTS_DIR=${CERTS_DIR:-'/etc/vmware-tools/GuestProxyData/server'}
+}
+
+configure_caf_common()
+{
+    mkdir -p ${PERSISTENCE_DIR}/local
+    mkdir -p ${PERSISTENCE_DIR}/remote/remote_default/cmsCertCollection
+    mkdir -p ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCertCollection
+    mkdir -p ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCipherCollection/
+
+    echo "amqpBroker_default" > ${PERSISTENCE_DIR}/remote/remote_default/protocolName.txt
+    echo "remote_default" > ${PERSISTENCE_DIR}/remote/remote_default/remoteId.txt
+    echo "des-ede3-cbc" > ${PERSISTENCE_DIR}/remote/remote_default/cmsCipherName.txt
+
+    echo "SRP-RSA-AES-128-CBC-SHA" > ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCipherCollection/tlsCipher0.txt
+    echo "amqpBroker_default" >  ${PERSISTENCE_DIR}/protocol/amqpBroker_default/protocolName.txt
+    echo "TLSv1" >  ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsProtocol.txt
+
+    cp -rf ${CERTS_DIR}/cert.pem ${PERSISTENCE_DIR}/local/cert.pem
+    cp -rf ${CERTS_DIR}/key.pem ${PERSISTENCE_DIR}/local/privateKey.pem
+
+    cp -rf ${CERTS_DIR}/cert.pem ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCert.pem
+    cp -rf ${CERTS_DIR}/cert.pem ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCertCollection/tlsCert0.pem
+
+    cp -rf ${CERTS_DIR}/cert.pem ${PERSISTENCE_DIR}/remote/remote_default/cmsCertCollection/cmsCert0.pem
+    cp -rf ${CERTS_DIR}/cert.pem ${PERSISTENCE_DIR}/remote/remote_default/cmsCert.pem
+
+    /usr/bin/vmware-guestproxycerttool -a ${PERSISTENCE_DIR}/local/cert.pem
+    /usr/bin/vmware-guestproxycerttool -a ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCert.pem
+    /usr/bin/vmware-guestproxycerttool -a ${PERSISTENCE_DIR}/protocol/amqpBroker_default/tlsCertCollection/tlsCert0.pem
+
+}
+
+##=============================================================================
+## Main
+##=============================================================================
+. $scriptsDir/caf-common
+sourceCafenv "$configDir"
+
+set_caf_pme_paths
+configure_caf_common
+
+#echo QUIT | openssl s_client -connect localhost:6672 -cert ${CERTS_DIR}/cert.pem -key ${CERTS_DIR}/key.pem -CAfile ${CERTS_DIR}/cert.pem  -tls1_2
+#echo QUIT | openssl s_client -connect localhost:6672 -cert ${CERTS_DIR}/cert.pem -key ${CERTS_DIR}/key.pem -CAfile ${CERTS_DIR}/cert.pem  -tls1_2
+
+echo -n true
+