aboutsummaryrefslogtreecommitdiff
path: root/lib/libostp/auth.c
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-10-03 21:22:41 -0500
committerIan Moffett <ian@osmora.org>2024-10-03 21:22:41 -0500
commit7f5b307413a29502791fb8cbe6209c0b0f5d2006 (patch)
treeefb44f9f27580194c91857c9b3138b202ef9da29 /lib/libostp/auth.c
parent85c4c48480c6f0aabcd8ccb38036392b71a05c2e (diff)
server: Fix handling of multiple clients
Improve handling of multiple connected clients. This fixes issues related to blocking of one client while another is connected as well as certain race conditions. Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/libostp/auth.c')
-rw-r--r--lib/libostp/auth.c42
1 files changed, 8 insertions, 34 deletions
diff --git a/lib/libostp/auth.c b/lib/libostp/auth.c
index 559e3b3..b807485 100644
--- a/lib/libostp/auth.c
+++ b/lib/libostp/auth.c
@@ -125,36 +125,6 @@ send_motd(struct ostp_client *c, const unsigned char *session_key)
}
}
-static int
-session_run(struct ostp_listener *lp, const unsigned char *session_key)
-{
- struct ostp_client *c;
- char buf[4096];
- size_t len;
-
- while (1) {
- for (int i = 1; i < MAX_CLIENTS; ++i) {
- c = &lp->clients[i];
- if (c->sockfd <= 0)
- continue;
- if (FD_ISSET(c->sockfd, &lp->client_fds) <= 0)
- continue;
-
- len = recv_frame(c->sockfd, sizeof(buf) - 1, session_key, buf);
- if (len < 0) {
- printf("recv_frame() failure, packet lost\n");
- continue;
- }
- if (len == 0) {
- return 0;
- }
- if (lp->on_recv != NULL) {
- lp->on_recv(c, buf, len);
- }
- }
- }
-}
-
static void *
session_td(void *args)
{
@@ -174,7 +144,7 @@ session_td(void *args)
}
send_motd(tmp->c, tmp->session_key);
- session_run(tmp->lp, tmp->session_key);
+ tmp->c->authed = 1;
free(args);
return NULL;
}
@@ -184,7 +154,7 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque
{
struct x25519_keypair keypair;
struct session_td_args *sargs;
- unsigned char *session_key;
+ struct ostp_session *session;
int error;
if (REQUIRE_USER_AUTH && !ISSET(srq->options, SESSION_REQ_USER)) {
@@ -207,8 +177,12 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque
return error;
}
+ /* Setup client session descriptor */
+ session = &c->session;
+ session->sockfd = c->sockfd;
+
printf("Deriving session key...\n");
- error = gen_session_key(keypair.privkey, srq->pubkey, &session_key);
+ error = gen_session_key(keypair.privkey, srq->pubkey, &session->session_key);
if (error < 0) {
return error;
}
@@ -221,7 +195,7 @@ handle_srq(struct ostp_client *c, struct ostp_listener *lp, struct session_reque
sargs->c = c;
sargs->lp = lp;
- sargs->session_key = session_key;
+ sargs->session_key = session->session_key;
error = pthread_create(&c->td, NULL, session_td, sargs);
if (error != 0) {
return error;