added client callbacks to ssh server
This commit is contained in:
@@ -9,5 +9,5 @@ set(CMAKE_COLOR_MAKEFILE ON)
|
|||||||
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
add_subdirectory(source)
|
|
||||||
add_subdirectory(external)
|
add_subdirectory(external)
|
||||||
|
add_subdirectory(source)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ find_package(mongoc 2.1.2 REQUIRED)
|
|||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
ssh
|
ssh
|
||||||
tart
|
TartLib
|
||||||
mongoc::static
|
mongoc::static
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
target_sources( ${PROJECT_NAME}
|
||||||
|
PUBLIC client.c
|
||||||
|
)
|
||||||
|
|||||||
22
source/client_source/client.c
Normal file
22
source/client_source/client.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,16 @@
|
|||||||
#ifndef CLIENT_H
|
#ifndef CLIENT_H
|
||||||
#define 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
|
#endif
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
/* This is a sample implementation of a libssh based SSH server */
|
/* This is a sample implementation of a libssh based SSH server */
|
||||||
#include "ssh_server_client.h"
|
#include "ssh_server_client.h"
|
||||||
|
#include "client_source/client.h"
|
||||||
|
|
||||||
int test(void*);
|
int test(void*);
|
||||||
int testrun(void*, void*);
|
int testrun(void*, void*);
|
||||||
@@ -18,9 +19,9 @@ int main() {
|
|||||||
.id = 123,
|
.id = 123,
|
||||||
.port = 2222,
|
.port = 2222,
|
||||||
.cbs = (ServerLoopCallbacks){
|
.cbs = (ServerLoopCallbacks){
|
||||||
.ssh_init = test,
|
.ssh_init = client_init,
|
||||||
.ssh_stop = test,
|
.ssh_stop = client_stop,
|
||||||
.ssh_run = testrun,
|
.ssh_run = client_update,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ssh_start(&conf);
|
ssh_start(&conf);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "ssh_server_client.h"
|
#include "ssh_server_client.h"
|
||||||
|
#include "client_source/client.h"
|
||||||
#include <libssh/libssh.h>
|
#include <libssh/libssh.h>
|
||||||
#include <libssh/server.h>
|
#include <libssh/server.h>
|
||||||
#include <libssh/callbacks.h>
|
#include <libssh/callbacks.h>
|
||||||
@@ -194,28 +195,36 @@ void* Handel_Client(void* d) {
|
|||||||
printf("Error, exiting loop\n");
|
printf("Error, exiting loop\n");
|
||||||
} else
|
} else
|
||||||
printf("Authenticated and got a channel\n");
|
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);
|
data.config->cbs.ssh_init(data.config->cbs.init_var);
|
||||||
do{
|
|
||||||
|
do{ // Update
|
||||||
i = 1;
|
i = 1;
|
||||||
snprintf(sendBuf, 1024, "Counter: %d, id: %d\r", counter, data.config->id);
|
//snprintf(sendBuf, 1024, "Counter: %d, id: %d\r", counter, data.config->id);
|
||||||
char kittyBuffer[30] = {0};
|
//char kittyBuffer[30] = {0};
|
||||||
sprintf(kittyBuffer, "\e[>%d", 0b1000);
|
//sprintf(kittyBuffer, "\e[>%d", 0b1000);
|
||||||
if (ssh_channel_write(c, kittyBuffer, 30) == SSH_ERROR) {
|
//if (ssh_channel_write(c, kittyBuffer, 30) == SSH_ERROR) {
|
||||||
printf("error writing to channel\n");
|
// printf("error writing to channel\n");
|
||||||
return NULL;
|
// return NULL;
|
||||||
}
|
//}
|
||||||
i = ssh_channel_read_nonblocking(c, buf, sizeof(buf)-1, 0);
|
i = ssh_channel_read_nonblocking(c, buf, sizeof(buf)-1, 0);
|
||||||
counter++;
|
counter++;
|
||||||
// code go here
|
// code go here
|
||||||
ssh_terminal_data db = {
|
ssh_terminal_data tb = {
|
||||||
.inputBuffer = buf,
|
.inputBuffer = buf,
|
||||||
.outputBuffer = sendBuf,
|
.outputBuffer = sendBuf,
|
||||||
.inputSize = 1024,
|
.inputSize = 1024,
|
||||||
.outputSize = &sendBuffSize,
|
.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
|
// 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");
|
printf("error writing to channel\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -244,12 +253,12 @@ int ssh_start(ServerConfig* conf){
|
|||||||
ssh_session session;
|
ssh_session session;
|
||||||
ssh_bind sshbind;
|
ssh_bind sshbind;
|
||||||
|
|
||||||
int port = conf->port;
|
int port = 2222;// conf->port;
|
||||||
int r =0;
|
int r =0;
|
||||||
|
|
||||||
sshbind=ssh_bind_new();
|
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);
|
ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_BINDPORT, &port);
|
||||||
|
|
||||||
while(sshbind) {
|
while(sshbind) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ typedef struct {
|
|||||||
}ssh_terminal_data;
|
}ssh_terminal_data;
|
||||||
|
|
||||||
typedef int(*ssh_server_callback)(void* userdata);
|
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 {
|
typedef struct {
|
||||||
void* init_var;
|
void* init_var;
|
||||||
|
|||||||
Reference in New Issue
Block a user