aboutsummaryrefslogtreecommitdiff
path: root/src/session.c
diff options
context:
space:
mode:
authorJulien Dessaux2018-08-26 15:55:38 +0200
committerJulien Dessaux2018-08-26 16:04:11 +0200
commitbeff818f25ae69cfe8501e18271b2509320de8df (patch)
treed132e9d366aaebac9f7b91b8a63fcafbbe550af8 /src/session.c
parentAdded address sanitization and fixed found bugs (diff)
downloadbastion-beff818f25ae69cfe8501e18271b2509320de8df.tar.gz
bastion-beff818f25ae69cfe8501e18271b2509320de8df.tar.bz2
bastion-beff818f25ae69cfe8501e18271b2509320de8df.zip
Added session recording with https://github.com/kilobyte/termrec
Diffstat (limited to 'src/session.c')
-rw-r--r--src/session.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/session.c b/src/session.c
index 1031f7d..f5827e8 100644
--- a/src/session.c
+++ b/src/session.c
@@ -11,6 +11,7 @@
#include "../config.h"
#include "proxy.h"
#include "session.h"
+#include "state.h"
static int auth_pubkey(ssh_session session, const char *user,
struct ssh_key_struct *pubkey,
@@ -35,13 +36,12 @@ static int auth_pubkey(ssh_session session, const char *user,
if (!ssh_key_cmp(pubkey, reference_key, SSH_KEY_CMP_PUBLIC)) {
sdata->authenticated = 1;
ssh_key_free(reference_key);
- size_t len = strnlen(user, MAX_HOSTNAME_LENGTH + 1);
- if (len == MAX_HOSTNAME_LENGTH + 1) {
- fprintf(stderr, "Hostname too long, max length is %d.\n", MAX_HOSTNAME_LENGTH);
+ if (state_set_ssh_destination(user) != 0)
return SSH_ERROR;
- }
- sdata->login_username = malloc(len+1);
- strncpy(sdata->login_username, user, len+1);
+ // TODO check access rights and host configs
+ state_set_username(USER_TO_LOGIN_AS);
+ // TODO log session creation in db
+ state_set_session_id(1337);
return SSH_AUTH_SUCCESS;
} else {
ssh_key_free(reference_key);
@@ -68,7 +68,6 @@ void handle_session(ssh_event event, ssh_session session) {
.channel = NULL,
.auth_attempts = 0,
.authenticated = 0,
- .login_username = NULL
};
struct ssh_server_callbacks_struct server_cb = {
@@ -105,7 +104,7 @@ void handle_session(ssh_event event, ssh_session session) {
}
}
- handle_proxy_session(event, session, sdata.channel, sdata.login_username);
+ handle_proxy_session(event, session, sdata.channel);
if (ssh_channel_is_open(sdata.channel)) {
ssh_channel_close(sdata.channel);
@@ -115,6 +114,6 @@ void handle_session(ssh_event event, ssh_session session) {
for (int n = 0; n < 50 && (ssh_get_status(session) & SESSION_END) == 0; n++) {
ssh_event_dopoll(event, 100);
}
- free(sdata.login_username);
+ state_clean();
ssh_event_remove_session(event, session);
}