Add --pipe mode for SSH ProxyCommand support

- Add MODE_PIPE constant to wsssht.h
- Implement run_pipe_mode() function with proper tunnel negotiation
- Add --pipe and --mode pipe command line options
- Pipe mode negotiates tunnel (tunnel_request -> tunnel_ack) like other modes
- Redirects raw tunnelled data to stdin/stdout instead of binding to TCP ports
- Silent operation with no terminal output
- Compatible with SSH ProxyCommand for transparent WebSocket SSH tunneling
- Update include paths in all affected files after moving headers to libwsssht/
- Update configure.sh to generate correct makefile with new file locations
parent de71d0fc
...@@ -56,7 +56,7 @@ CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE $(shell pkg-config --cflags openssl) ...@@ -56,7 +56,7 @@ CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE $(shell pkg-config --cflags openssl)
LDFLAGS = $(shell pkg-config --libs openssl) LDFLAGS = $(shell pkg-config --libs openssl)
# Source files # Source files
LIB_SRCS = wssshlib.c websocket.c wssh_ssl.c tunnel.c libwsssht/utils.c libwsssht/modes.c libwsssht/threads.c LIB_SRCS = libwsssht/wssshlib.c libwsssht/websocket.c libwsssht/wssh_ssl.c libwsssht/tunnel.c libwsssht/utils.c libwsssht/modes.c libwsssht/threads.c
LIB_OBJS = $(LIB_SRCS:.c=.o) LIB_OBJS = $(LIB_SRCS:.c=.o)
SRCS = wssshc.c wsssh.c wsscp.c wsssht.c SRCS = wssshc.c wsssh.c wsscp.c wsssht.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
...@@ -69,13 +69,13 @@ MANPAGES = man/wssshc.1 man/wsssh.1 man/wsscp.1 man/wsssht.1 ...@@ -69,13 +69,13 @@ MANPAGES = man/wssshc.1 man/wsssh.1 man/wsscp.1 man/wsssht.1
all: $(TARGETS) all: $(TARGETS)
# Individual targets # Individual targets
wssshc: wssshc.o wssshlib.o websocket.o wssh_ssl.o tunnel.o wssshc: wssshc.o libwsssht/wssshlib.o libwsssht/websocket.o libwsssht/wssh_ssl.o libwsssht/tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsssh: wsssh.o wssshlib.o websocket.o wssh_ssl.o tunnel.o wsssh: wsssh.o libwsssht/wssshlib.o libwsssht/websocket.o libwsssht/wssh_ssl.o libwsssht/tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsscp: wsscp.o wssshlib.o websocket.o wssh_ssl.o tunnel.o wsscp: wsscp.o libwsssht/wssshlib.o libwsssht/websocket.o libwsssht/wssh_ssl.o libwsssht/tunnel.o
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
wsssht: wsssht.o $(LIB_OBJS) wsssht: wsssht.o $(LIB_OBJS)
...@@ -87,7 +87,7 @@ wsssht: wsssht.o $(LIB_OBJS) ...@@ -87,7 +87,7 @@ wsssht: wsssht.o $(LIB_OBJS)
# Clean # Clean
clean: clean:
rm -f $(OBJS) $(LIB_OBJS) $(TARGETS) libwsssht/*.o rm -f $(OBJS) $(LIB_OBJS) $(TARGETS)
# Install (optional) # Install (optional)
install: all install: all
......
This diff is collapsed.
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#ifndef MODES_H #ifndef MODES_H
#define MODES_H #define MODES_H
#include "../wssshlib.h" #include "wssshlib.h"
// Function declarations for mode-specific functions // Function declarations for mode-specific functions
int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port); int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
......
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include "../wssshlib.h" #include "wssshlib.h"
#include "../websocket.h" #include "websocket.h"
#include "../wssh_ssl.h" #include "wssh_ssl.h"
#include "../tunnel.h" #include "tunnel.h"
#include "wsssht.h" #include "wsssht.h"
#include "threads.h" #include "threads.h"
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include "../wssshlib.h" #include "wssshlib.h"
#include "utils.h" #include "utils.h"
void print_usage(const char *program_name) { void print_usage(const char *program_name) {
...@@ -42,10 +42,11 @@ void print_usage(const char *program_name) { ...@@ -42,10 +42,11 @@ void print_usage(const char *program_name) {
fprintf(stderr, " --tunnel TRANSPORT Transport for data channel (comma-separated or 'any', or 'websocket' default: any)\n"); fprintf(stderr, " --tunnel TRANSPORT Transport for data channel (comma-separated or 'any', or 'websocket' default: any)\n");
fprintf(stderr, " --tunnel-control TYPES Transport types for control channel (comma-separated or 'any', default: any)\n"); fprintf(stderr, " --tunnel-control TYPES Transport types for control channel (comma-separated or 'any', default: any)\n");
fprintf(stderr, " --service SERVICE Service type (default: ssh)\n"); fprintf(stderr, " --service SERVICE Service type (default: ssh)\n");
fprintf(stderr, " --mode MODE Operating mode: interactive, silent, bridge, script (default: interactive)\n"); fprintf(stderr, " --mode MODE Operating mode: interactive, silent, bridge, script, pipe (default: interactive)\n");
fprintf(stderr, " --silent Shortcut for --mode silent\n"); fprintf(stderr, " --silent Shortcut for --mode silent\n");
fprintf(stderr, " --bridge Shortcut for --mode bridge\n"); fprintf(stderr, " --bridge Shortcut for --mode bridge\n");
fprintf(stderr, " --script Shortcut for --mode script\n"); fprintf(stderr, " --script Shortcut for --mode script\n");
fprintf(stderr, " --pipe Shortcut for --mode pipe\n");
fprintf(stderr, " --daemon Enable daemon mode for lazy initialization\n"); fprintf(stderr, " --daemon Enable daemon mode for lazy initialization\n");
fprintf(stderr, " --help Show this help\n"); fprintf(stderr, " --help Show this help\n");
fprintf(stderr, "\nExamples:\n"); fprintf(stderr, "\nExamples:\n");
...@@ -158,6 +159,8 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar ...@@ -158,6 +159,8 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar
config->mode = MODE_BRIDGE; config->mode = MODE_BRIDGE;
} else if (strcmp(argv[i + 1], "script") == 0) { } else if (strcmp(argv[i + 1], "script") == 0) {
config->mode = MODE_SCRIPT; config->mode = MODE_SCRIPT;
} else if (strcmp(argv[i + 1], "pipe") == 0) {
config->mode = MODE_PIPE;
} else { } else {
fprintf(stderr, "Error: Invalid mode: %s\n", argv[i + 1]); fprintf(stderr, "Error: Invalid mode: %s\n", argv[i + 1]);
print_usage(argv[0]); print_usage(argv[0]);
...@@ -172,6 +175,8 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar ...@@ -172,6 +175,8 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar
config->mode = MODE_BRIDGE; config->mode = MODE_BRIDGE;
} else if (strcmp(argv[i], "--script") == 0) { } else if (strcmp(argv[i], "--script") == 0) {
config->mode = MODE_SCRIPT; config->mode = MODE_SCRIPT;
} else if (strcmp(argv[i], "--pipe") == 0) {
config->mode = MODE_PIPE;
} else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
print_usage(argv[0]); print_usage(argv[0]);
return 0; return 0;
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#ifndef UTILS_H #ifndef UTILS_H
#define UTILS_H #define UTILS_H
#include "../wssshlib.h" #include "wssshlib.h"
// Function declarations for utility functions // Function declarations for utility functions
void print_usage(const char *program_name); void print_usage(const char *program_name);
......
...@@ -57,7 +57,8 @@ typedef enum { ...@@ -57,7 +57,8 @@ typedef enum {
MODE_INTERACTIVE = 0, // Default: current functionality MODE_INTERACTIVE = 0, // Default: current functionality
MODE_SILENT, // Same as interactive but no output MODE_SILENT, // Same as interactive but no output
MODE_BRIDGE, // JSON stdin/stdout bridge MODE_BRIDGE, // JSON stdin/stdout bridge
MODE_SCRIPT // JSON protocol for scripting MODE_SCRIPT, // JSON protocol for scripting
MODE_PIPE // ProxyCommand mode: stdin/stdout proxy
} wsssh_mode_t; } wsssh_mode_t;
// Config structures // Config structures
......
...@@ -35,10 +35,10 @@ ...@@ -35,10 +35,10 @@
#include <pthread.h> #include <pthread.h>
#include <sys/select.h> #include <sys/select.h>
#include "../wssshlib.h" #include "wssshlib.h"
#include "../websocket.h" #include "websocket.h"
#include "../wssh_ssl.h" #include "wssh_ssl.h"
#include "../tunnel.h" #include "tunnel.h"
// Thread arguments structure for concurrent tunnel handling // Thread arguments structure for concurrent tunnel handling
typedef struct { typedef struct {
...@@ -57,6 +57,7 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar ...@@ -57,6 +57,7 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar
int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port); int run_bridge_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_script_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port); int run_script_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_daemon_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port); int run_daemon_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
int run_pipe_mode(wsssh_config_t *config, const char *client_id, const char *wssshd_host, int wssshd_port);
void *run_tunnel_thread(void *arg); void *run_tunnel_thread(void *arg);
#endif // WSSSHT_H #endif // WSSSHT_H
\ No newline at end of file
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
#include <errno.h> #include <errno.h>
#include <sys/select.h> #include <sys/select.h>
#include "wssshlib.h" #include "libwsssht/wssshlib.h"
#include "websocket.h" #include "libwsssht/websocket.h"
#include "wssh_ssl.h" #include "libwsssht/wssh_ssl.h"
#include "tunnel.h" #include "libwsssht/tunnel.h"
......
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
#include <pthread.h> #include <pthread.h>
#include <sys/select.h> #include <sys/select.h>
#include "wssshlib.h" #include "libwsssht/wssshlib.h"
#include "websocket.h" #include "libwsssht/websocket.h"
#include "wssh_ssl.h" #include "libwsssht/wssh_ssl.h"
#include "tunnel.h" #include "libwsssht/tunnel.h"
......
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include "wssshlib.h" #include "libwsssht/wssshlib.h"
#include "websocket.h" #include "libwsssht/websocket.h"
#include "wssh_ssl.h" #include "libwsssht/wssh_ssl.h"
#include "tunnel.h" #include "libwsssht/tunnel.h"
......
...@@ -32,10 +32,10 @@ ...@@ -32,10 +32,10 @@
#include <pthread.h> #include <pthread.h>
#include <sys/select.h> #include <sys/select.h>
#include "wssshlib.h" #include "libwsssht/wssshlib.h"
#include "websocket.h" #include "libwsssht/websocket.h"
#include "wssh_ssl.h" #include "libwsssht/wssh_ssl.h"
#include "tunnel.h" #include "libwsssht/tunnel.h"
#include "libwsssht/wsssht.h" #include "libwsssht/wsssht.h"
#include "libwsssht/utils.h" #include "libwsssht/utils.h"
...@@ -64,6 +64,8 @@ int main(int argc, char *argv[]) { ...@@ -64,6 +64,8 @@ int main(int argc, char *argv[]) {
initial_mode = MODE_BRIDGE; initial_mode = MODE_BRIDGE;
} else if (strcmp(config_mode, "script") == 0) { } else if (strcmp(config_mode, "script") == 0) {
initial_mode = MODE_SCRIPT; initial_mode = MODE_SCRIPT;
} else if (strcmp(config_mode, "pipe") == 0) {
initial_mode = MODE_PIPE;
} }
free(config_mode); free(config_mode);
} }
...@@ -203,6 +205,8 @@ int main(int argc, char *argv[]) { ...@@ -203,6 +205,8 @@ int main(int argc, char *argv[]) {
return run_bridge_mode(&config, client_id, wssshd_host, wssshd_port); return run_bridge_mode(&config, client_id, wssshd_host, wssshd_port);
} else if (config.mode == MODE_SCRIPT) { } else if (config.mode == MODE_SCRIPT) {
return run_script_mode(&config, client_id, wssshd_host, wssshd_port); return run_script_mode(&config, client_id, wssshd_host, wssshd_port);
} else if (config.mode == MODE_PIPE) {
return run_pipe_mode(&config, client_id, wssshd_host, wssshd_port);
} }
// MODE_INTERACTIVE and MODE_SILENT continue with normal flow // MODE_INTERACTIVE and MODE_SILENT continue with normal flow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment