added client callbacks to ssh server

This commit is contained in:
2026-03-16 14:01:34 -07:00
parent 76d2e27879
commit b6c9afaf20
8 changed files with 64 additions and 19 deletions

View File

@@ -9,5 +9,5 @@ set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(source)
add_subdirectory(external)
add_subdirectory(source)

View File

@@ -11,7 +11,7 @@ find_package(mongoc 2.1.2 REQUIRED)
target_link_libraries(
${PROJECT_NAME}
ssh
tart
TartLib
mongoc::static
)

View File

@@ -0,0 +1,3 @@
target_sources( ${PROJECT_NAME}
PUBLIC client.c
)

View File

@@ -0,0 +1,22 @@
#include "client.h"
#include <string.h>
#include <tart.h>
int client_auth(void* userdata);
int client_init(void* cli) {
return 0;
}
int client_update(ssh_terminal_data* td, void* cli) {
client* c = (client*)cli;
strcpy(td->outputBuffer, "testing 1212\n\r");
return 0;
}
int client_stop(void* cli) {
return 0;
}

View File

@@ -1,6 +1,16 @@
#ifndef CLIENT_H
#define CLIENT_H
#include "../ssh_server_client.h"
typedef struct {} client;
int client_auth(void* userdata);
int client_init(void*);
int client_update(ssh_terminal_data* td, void*);
int client_stop(void*);
#endif

View File

@@ -8,6 +8,7 @@
*/
/* This is a sample implementation of a libssh based SSH server */
#include "ssh_server_client.h"
#include "client_source/client.h"
int test(void*);
int testrun(void*, void*);
@@ -18,9 +19,9 @@ int main() {
.id = 123,
.port = 2222,
.cbs = (ServerLoopCallbacks){
.ssh_init = test,
.ssh_stop = test,
.ssh_run = testrun,
.ssh_init = client_init,
.ssh_stop = client_stop,
.ssh_run = client_update,
}
};
ssh_start(&conf);

View File

@@ -12,6 +12,7 @@
#include "ssh_server_client.h"
#include "client_source/client.h"
#include <libssh/libssh.h>
#include <libssh/server.h>
#include <libssh/callbacks.h>
@@ -194,28 +195,36 @@ void* Handel_Client(void* d) {
printf("Error, exiting loop\n");
} else
printf("Authenticated and got a channel\n");
client* cli = NULL;
// Data Init
data.config->cbs.init_var = cli;
data.config->cbs.run_var = cli;
data.config->cbs.stop_var = cli;
data.config->cbs.ssh_init(data.config->cbs.init_var);
do{
do{ // Update
i = 1;
snprintf(sendBuf, 1024, "Counter: %d, id: %d\r", counter, data.config->id);
char kittyBuffer[30] = {0};
sprintf(kittyBuffer, "\e[>%d", 0b1000);
if (ssh_channel_write(c, kittyBuffer, 30) == SSH_ERROR) {
printf("error writing to channel\n");
return NULL;
}
//snprintf(sendBuf, 1024, "Counter: %d, id: %d\r", counter, data.config->id);
//char kittyBuffer[30] = {0};
//sprintf(kittyBuffer, "\e[>%d", 0b1000);
//if (ssh_channel_write(c, kittyBuffer, 30) == SSH_ERROR) {
// printf("error writing to channel\n");
// return NULL;
//}
i = ssh_channel_read_nonblocking(c, buf, sizeof(buf)-1, 0);
counter++;
// code go here
ssh_terminal_data db = {
ssh_terminal_data tb = {
.inputBuffer = buf,
.outputBuffer = sendBuf,
.inputSize = 1024,
.outputSize = &sendBuffSize,
};
data.config->cbs.ssh_run(&db,data.config->cbs.run_var);
data.config->cbs.ssh_run(&tb,data.config->cbs.run_var);
// code go here
if (ssh_channel_write(c, sendBuf, 1024) == SSH_ERROR) {
if (ssh_channel_write(c, tb.outputBuffer, 1024) == SSH_ERROR) {
printf("error writing to channel\n");
return NULL;
}
@@ -244,12 +253,12 @@ int ssh_start(ServerConfig* conf){
ssh_session session;
ssh_bind sshbind;
int port = conf->port;
int port = 2222;// conf->port;
int r =0;
sshbind=ssh_bind_new();
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "./rsa.key");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_HOSTKEY, "/home/preacher/.ssh/id_rsa");
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
while(sshbind) {

View File

@@ -10,7 +10,7 @@ typedef struct {
}ssh_terminal_data;
typedef int(*ssh_server_callback)(void* userdata);
typedef int(*ssh_server_run_callback)(void* ssh_terminal_data, void* userdata);
typedef int(*ssh_server_run_callback)(ssh_terminal_data* ssh_terminal_data, void* userdata);
typedef struct {
void* init_var;