Finally got all the ssh stuff working
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 24s
Some checks failed
Dropshell Test / Build_and_Test (push) Failing after 24s
This commit is contained in:
@ -1,8 +1,3 @@
|
||||
#include "execute.hpp"
|
||||
#include "assert.hpp"
|
||||
#include "contrib/base64.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
@ -11,6 +6,12 @@
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <sstream>
|
||||
#include <libassert/assert.hpp>
|
||||
|
||||
#include "execute.hpp"
|
||||
#include "contrib/base64.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
|
||||
bool EXITSTATUSCHECK(int ret) {
|
||||
return (ret != -1 && WIFEXITED(ret) && (WEXITSTATUS(ret) == 0)); // ret is -1 if the command failed to execute.
|
||||
@ -55,9 +56,9 @@ bool execute_local_command_interactive(const sCommand &command, bool silent)
|
||||
|
||||
bool execute_local_command_and_capture_output(const sCommand& command, std::string * output, cMode mode)
|
||||
{
|
||||
ASSERT_MSG(output != nullptr, "Output string must be provided");
|
||||
ASSERT_MSG(is_raw(mode), "Capture output mode requires raw command mode");
|
||||
ASSERT_MSG(!hasFlag(mode, cMode::Silent), "Silent mode is not allowed with capture output mode");
|
||||
ASSERT(output != nullptr, "Output string must be provided");
|
||||
ASSERT(is_raw(mode), "Capture output mode requires raw command mode");
|
||||
ASSERT(!hasFlag(mode, cMode::Silent), "Silent mode is not allowed with capture output mode");
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
cStyle style = getStyle(mode);
|
||||
@ -79,18 +80,18 @@ bool execute_local_command_and_capture_output(const sCommand& command, std::stri
|
||||
bool execute_local_command(const sCommand & command, cMode mode, std::string * output /* = nullptr */)
|
||||
{
|
||||
if (hasFlag(mode, cMode::Interactive)) {
|
||||
ASSERT_MSG(! hasFlag(mode, cMode::CaptureOutput), "Interactive mode and capture output mode cannot be used together");
|
||||
ASSERT_MSG(output == nullptr, "Interactive mode and an output string cannot be used together");
|
||||
ASSERT_MSG(is_raw(mode), "Interactive mode requires raw command mode");
|
||||
ASSERT(! hasFlag(mode, cMode::CaptureOutput), "Interactive mode and capture output mode cannot be used together");
|
||||
ASSERT(output == nullptr, "Interactive mode and an output string cannot be used together");
|
||||
ASSERT(is_raw(mode), "Interactive mode requires raw command mode");
|
||||
|
||||
return execute_local_command_interactive(command, hasFlag(mode, cMode::Silent));
|
||||
}
|
||||
|
||||
if (hasFlag(mode, cMode::CaptureOutput)) {
|
||||
ASSERT_MSG(output != nullptr, "Capture output mode requires an output string to be provided");
|
||||
ASSERT_MSG(is_raw(mode), "Capture output mode requires raw command mode");
|
||||
ASSERT_MSG(!hasFlag(mode, cMode::Silent), "Silent mode is not allowed with capture output mode");
|
||||
|
||||
ASSERT(output != nullptr, "Capture output mode requires an output string to be provided");
|
||||
ASSERT(is_raw(mode), "Capture output mode requires raw command mode");
|
||||
ASSERT(!hasFlag(mode, cMode::Silent), "Silent mode is not allowed with capture output mode");
|
||||
|
||||
return execute_local_command_and_capture_output(command, output, mode);
|
||||
}
|
||||
|
||||
@ -113,8 +114,8 @@ bool execute_ssh_command(const sSSHInfo &ssh_info, const sCommand &command, cMod
|
||||
if (command.get_command_to_run().empty())
|
||||
return false;
|
||||
|
||||
ASSERT_MSG(!(hasFlag(mode, cMode::Interactive) && !is_raw(mode)), "Interactive mode requires raw command mode");
|
||||
ASSERT_MSG(!(hasFlag(mode, cMode::CaptureOutput) && output == nullptr), "Capture output mode must be used with an output string");
|
||||
ASSERT(!(hasFlag(mode, cMode::Interactive) && !is_raw(mode)), "Interactive mode requires raw command mode");
|
||||
ASSERT(!(hasFlag(mode, cMode::CaptureOutput) && output == nullptr), "Capture output mode must be used with an output string");
|
||||
|
||||
std::stringstream ssh_cmd;
|
||||
ssh_cmd << "ssh -p " << ssh_info.port << " " << (hasFlag(mode, cMode::Interactive) ? "-tt " : "")
|
||||
@ -126,9 +127,8 @@ bool execute_ssh_command(const sSSHInfo &ssh_info, const sCommand &command, cMod
|
||||
else
|
||||
{
|
||||
std::string raw_cmd = command.construct_cmd(cStyle::Raw);
|
||||
ASSERT_MSG(raw_cmd.find("'") == std::string::npos, "Raw command must not contain single quotes");
|
||||
ASSERT_MSG(raw_cmd.find("\"") == std::string::npos, "Raw command must not contain double quotes");
|
||||
cmdstr = halfquote("bash -c " + quote(raw_cmd));
|
||||
ASSERT(raw_cmd.find("'") == std::string::npos, "Raw command must not contain single quotes");
|
||||
cmdstr = "bash -c "+ halfquote(raw_cmd);
|
||||
}
|
||||
|
||||
sCommand ssh_command(ssh_cmd.str() + " " + cmdstr);
|
||||
|
Reference in New Issue
Block a user