diff options
author | Toni Uhlig <matzeton@googlemail.com> | 2018-05-13 23:43:10 +0200 |
---|---|---|
committer | Toni Uhlig <matzeton@googlemail.com> | 2018-05-13 23:43:10 +0200 |
commit | 3e854ba53063062a4824966ae1b6c93e6100cea4 (patch) | |
tree | dd5de5c014018d7c4ba50dde77d886d2f1c42d10 /src/main.c | |
parent | d336c8771f617df35c43f28feae6c3f83512deaf (diff) |
POTD skeleton #49.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 75 |
1 files changed, 41 insertions, 34 deletions
@@ -6,7 +6,7 @@ #include "log_colored.h" #include "utils.h" #include "redirector.h" -#include "server_ssh.h" +#include "protocol_ssh.h" #include "forward.h" #include "jail.h" #ifdef HAVE_CONFIG_H @@ -16,17 +16,19 @@ int main(int argc, char *argv[]) { - const size_t srv_siz = 3; + const size_t rdr_siz = 3; + const size_t proto_siz = 2; const size_t jail_siz = 2; - const char *ssh_ports[srv_siz]; + const char *rdr_ports[rdr_siz]; + const char *proto_ports[proto_siz]; const char *jail_ports[jail_siz]; - redirector_ctx *rdr[srv_siz]; + redirector_ctx *rdr[rdr_siz]; + protocol_ctx *ssh_proto[proto_siz]; jail_ctx *jail[jail_siz]; - forward_ctx *ssh_fwd = NULL; event_ctx *rdr_event = NULL; event_ctx *jail_event = NULL; int proc_status; - pid_t daemon_pid, rdr_pid, jail_pid, wpid; + pid_t daemon_pid, rdr_pid, jail_pid, child_pid; (void) argc; (void) argv; @@ -66,49 +68,54 @@ int main(int argc, char *argv[]) jail_pid = jail_daemonize(&jail_event, jail, jail_siz); ABORT_ON_FATAL( jail_pid < 1, "Jail daemon startup" ); - { - ABORT_ON_FATAL( fwd_init_ctx(&ssh_fwd, ssh_init_cb), - "Forwarder initialisation" ); - ABORT_ON_FATAL( fwd_setup_client(ssh_fwd, "127.0.0.1", "22222"), - "Forwarder setup" ); - ABORT_ON_FATAL( fwd_validate_ctx( ssh_fwd ), - "Forwarder validation" ); + memset(ssh_proto, 0, sizeof(proto_ports)); + proto_ports[0] = "22222"; + proto_ports[1] = "22223"; + + for (size_t i = 0; i < proto_siz; ++i) { + ABORT_ON_FATAL( proto_init_ctx(&ssh_proto[i], ssh_init_cb), + "SSH Protocol init" ); + ABORT_ON_FATAL( proto_setup(ssh_proto[i], "127.0.0.1", proto_ports[i], + "127.0.0.1", jail_ports[i]), "SSH Protocol setup" ); + ABORT_ON_FATAL( proto_validate_ctx(ssh_proto[i]), + "SSH validation" ); } memset(rdr, 0, sizeof(rdr)); - ssh_ports[0] = "2222"; - ssh_ports[1] = "2223"; - ssh_ports[2] = "22050"; + rdr_ports[0] = "2222"; + rdr_ports[1] = "2223"; + rdr_ports[2] = "22050"; - for (size_t i = 0; i < srv_siz; ++i) { - D("Initialising redirector service on port %s", ssh_ports[i]); + for (size_t i = 0; i < rdr_siz; ++i) { + D("Initialising redirector service on port %s", rdr_ports[i]); - redirector_init_ctx(&rdr[i], ssh_fwd); - ABORT_ON_FATAL( redirector_setup(rdr[i], NULL, ssh_ports[i]), - "Server setup" ); + ABORT_ON_FATAL( redirector_init_ctx(&rdr[i]), + "Redirector init" ); + ABORT_ON_FATAL( redirector_setup(rdr[i], NULL, rdr_ports[i], + "127.0.0.1", "22222"), "Redirector setup" ); ABORT_ON_FATAL( redirector_validate_ctx(rdr[i]), - "Server validation" ); + "Redirector validation" ); } - D2("%s", "Server event setup"); - ABORT_ON_FATAL( redirector_setup_event( rdr, srv_siz, &rdr_event ), - "Server event setup" ); + D2("%s", "Redirector event setup"); + ABORT_ON_FATAL( redirector_setup_event( rdr, rdr_siz, &rdr_event ), + "Redirector event setup" ); - D2("Server dropping privileges to %s:%s", "nobody", "NULL"); + D2("Main process is dropping privileges to %s:%s", "nobody", "NULL"); ABORT_ON_FATAL( change_user_group("nobody", NULL), - "Server dropping privileges" ); + "Main process dropping privileges" ); - N("%s", "Server epoll mainloop"); - rdr_pid = redirector_daemonize( rdr_event, rdr, srv_siz ); + N("%s", "Redirector epoll mainloop"); + rdr_pid = redirector_daemonize( rdr_event, rdr, rdr_siz ); ABORT_ON_FATAL( rdr_pid < 1, "Server epoll mainloop" ); while (1) { - wpid = wait(&proc_status); - if (wpid == jail_pid || - wpid == rdr_pid) { + child_pid = wait(&proc_status); + if (child_pid == jail_pid || + child_pid == rdr_pid) { E2("%s daemon with pid %d terminated, exiting", - (wpid == jail_pid ? "Jail" : "Server"), - (wpid == jail_pid ? jail_pid : rdr_pid)); + (child_pid == jail_pid ? "Jail" : "Server"), + (child_pid == jail_pid ? jail_pid : rdr_pid)); break; } } |