From 486645a1b6ed3a12c938201e7729b4aeed5e1f93 Mon Sep 17 00:00:00 2001 From: lns Date: Mon, 16 Jul 2018 19:32:30 +0200 Subject: added skeleton code for a complex jail protocol (instead of a raw tcp2pty communication) Signed-off-by: lns --- src/jail_protocol.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/jail_protocol.h (limited to 'src/jail_protocol.h') diff --git a/src/jail_protocol.h b/src/jail_protocol.h new file mode 100644 index 0000000..fee2ef8 --- /dev/null +++ b/src/jail_protocol.h @@ -0,0 +1,46 @@ +#ifndef POTD_JAIL_PROTOCOL_H +#define POTD_JAIL_PROTOCOL_H 1 + +#include +#include + +#include "jail.h" +#include "pevent.h" + +#define USER_LEN 255 +#define PASS_LEN 255 + +#define PROTO_MAGIC 0xdeadc0de +#define PROTO_TYPE_EHLO 0xcafebabe +#define PROTO_TYPE_USER 0x41414141 +#define PROTO_TYPE_PASS 0x42424242 +#define PROTO_TYPE_DATA 0x43434343 + +typedef struct __attribute__((packed, aligned(4))) jail_data { + int used; + char user[USER_LEN+1]; + char pass[PASS_LEN+1]; +} jail_data; + +typedef struct jail_protocol_hdr { + uint32_t magic; + uint32_t type; + uint32_t size; +} jail_protocol_hdr; + + +ssize_t jail_protocol_readhdr(jail_data *dst, unsigned char *buf, + size_t bufsiz); + +ssize_t jail_protocol_writehdr(jail_protocol_hdr *hdr, int type, + unsigned char *buf, size_t bufsiz); + +int jail_protocol_handshake_read(event_ctx *ev_client, int client_fd, + int tty_fd, jail_data *dst); + +int jail_protocol_handshake_write(event_ctx *ev_server, int server_fd, + int proto_fd, jail_data *dst); + +int jail_protocol_loop(event_ctx *ctx, on_event_cb on_event, void *user_data); + +#endif -- cgit v1.2.3