SSH working.

This commit is contained in:
Scott Duensing 2022-12-22 18:55:24 -06:00
parent a5a5c70625
commit b7ec93dc3c
2 changed files with 22 additions and 11 deletions

View file

@ -448,18 +448,17 @@ EVENT void menuProjectBuildSettings(GtkWidget *object, gpointer userData) {
ssh = sshConnect(self->buildHost, self->buildPort, self->buildUser, self->buildPassword);
if (ssh) {
debug("Connected!\n");
result = sshExecute(ssh, "echo ${JOEYLIB_SDKS}", &output);
// echo ${JOEYLIB_SDKS}
result = sshExecute(ssh, "ls -la", &output);
debug("----------\n");
if ((result == 0) && (strlen(output) > 0)) {
debug("%s\n", output);
debug("%s", output);
} else {
debug("No output!\n");
}
debug("----------\n");
DEL(output);
sshDisconnect(&ssh);
} else {
debug("Failed to connect.\n");
}
} else {
// Close dialog on OKAY but not TEST.

View file

@ -23,6 +23,7 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "ssh.h"
#include "utils.h"
@ -50,21 +51,33 @@ static int sshWaitSocket(int socket_fd, LIBSSH2_SESSION *session);
SSHT *sshConnect(char *hostname, uint16_t port, char *user, char *password) {
int rc;
unsigned long hostaddr;
struct hostent *hostent;
struct sockaddr_in sin;
in_addr_t hostaddr;
SSHT *data = NULL;
hostent = gethostbyname(hostname);
if (hostent == NULL) {
debug("gethostbyname() failed.\n");
return NULL;
}
hostaddr = inet_addr(inet_ntoa(*(struct in_addr*)*(hostent->h_addr_list)));
if (hostaddr == (in_addr_t)-1) {
debug("inet_addr() failed.\n");
return NULL;
}
data = NEW(SSHT);
if (data) {
hostaddr = inet_addr(hostname);
data->sock = socket(AF_INET, SOCK_STREAM, 0);
sin.sin_family = AF_INET;
sin.sin_port = htons(port);
sin.sin_addr.s_addr = hostaddr;
if (connect(data->sock, (struct sockaddr*)(&sin), sizeof(struct sockaddr_in)) != 0) {
debug("Failed to connect: %d\n", errno);
debug("connect() failed: %d\n", errno);
DEL(data);
return NULL;
}
@ -118,7 +131,6 @@ void sshDisconnect(SSHT **sshData) {
int sshExecute(SSHT *sshData, char *command, char **output) {
int rc;
unsigned char buffer[0x4000];
int exitcode = 127;
char *exitsignal = (char *)"none";
int outputLen = 0;
@ -141,10 +153,10 @@ int sshExecute(SSHT *sshData, char *command, char **output) {
for (;;) {
do {
rc = libssh2_channel_read(sshData->channel, (char *)buffer, sizeof(buffer));
rc = libssh2_channel_read(sshData->channel, (char *)_buffer, sizeof(_buffer));
if (rc > 0) {
utilEnsureBufferSize((unsigned char **)output, &outputLen, strlen((const char *)*output) + rc);
strncat(*output, (char *)buffer, rc);
utilEnsureBufferSize((unsigned char **)output, &outputLen, strlen((const char *)*output) + rc + 1);
strncat(*output, (char *)_buffer, rc);
}
} while (rc > 0);