mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-12 01:26:48 +08:00
increased cookie hash table size and better cleanup resources on errors
This commit is contained in:
+1
-1
@@ -37,7 +37,7 @@
|
||||
#include <ccan/htable/htable.h>
|
||||
#include <ccan/hash/hash.h>
|
||||
|
||||
#define MAX_COOKIES(n) ((n>0)?(2*n):4096)
|
||||
#define MAX_COOKIES(n) ((n>0&&n>2048)?(2*n):4096)
|
||||
|
||||
/* receives allocated data and stores them.
|
||||
*/
|
||||
|
||||
+21
-9
@@ -215,7 +215,8 @@ int handle_commands(main_server_st *s, struct proc_st* proc)
|
||||
|
||||
case AUTH_REQ:
|
||||
case AUTH_COOKIE_REQ:
|
||||
|
||||
lease = NULL;
|
||||
|
||||
if (cmd == AUTH_REQ) {
|
||||
if (cmd_data_len != sizeof(cmd_data.auth)) {
|
||||
mslog(s, proc, LOG_ERR, "Error in received message (%u) length (pid: %d, peer: %s).", (unsigned)cmd, proc->pid, peer_ip);
|
||||
@@ -252,8 +253,10 @@ int handle_commands(main_server_st *s, struct proc_st* proc)
|
||||
if (cmd == AUTH_REQ) {
|
||||
/* generate and store cookie */
|
||||
ret = generate_and_store_vals(s, proc);
|
||||
if (ret < 0)
|
||||
return -2;
|
||||
if (ret < 0) {
|
||||
ret = -2;
|
||||
goto lease_cleanup;
|
||||
}
|
||||
mslog(s, proc, LOG_INFO, "User '%s' authenticated", proc->username);
|
||||
} else {
|
||||
mslog(s, proc, LOG_INFO, "User '%s' re-authenticated (using cookie)", proc->username);
|
||||
@@ -262,23 +265,32 @@ int handle_commands(main_server_st *s, struct proc_st* proc)
|
||||
ret = send_auth_reply(s, proc, REP_AUTH_OK, lease);
|
||||
if (ret < 0) {
|
||||
mslog(s, proc, LOG_ERR, "Could not send reply cmd (pid: %d, peer: %s).", proc->pid, peer_ip);
|
||||
return -2;
|
||||
ret = -2;
|
||||
goto lease_cleanup;
|
||||
}
|
||||
|
||||
proc->lease = lease;
|
||||
proc->lease->in_use = 1;
|
||||
if (lease->fd >= 0)
|
||||
close(lease->fd);
|
||||
lease->fd = -1;
|
||||
ret = 0;
|
||||
} else {
|
||||
mslog(s, proc, LOG_INFO, "Failed authentication attempt for user '%s'", proc->username);
|
||||
ret = send_auth_reply( s, proc, REP_AUTH_FAILED, NULL);
|
||||
if (ret < 0) {
|
||||
mslog(s, proc, LOG_ERR, "Could not send reply cmd (pid: %d, peer: %s).", proc->pid, peer_ip);
|
||||
return -2;
|
||||
ret = -2;
|
||||
goto lease_cleanup;
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
|
||||
lease_cleanup:
|
||||
if (lease) {
|
||||
if (lease->fd >= 0)
|
||||
close(lease->fd);
|
||||
lease->fd = -1;
|
||||
}
|
||||
return ret;
|
||||
|
||||
break;
|
||||
default:
|
||||
mslog(s, proc, LOG_ERR, "Unknown CMD 0x%x (pid: %d, peer: %s).", (unsigned)cmd, proc->pid, peer_ip);
|
||||
|
||||
+7
-5
@@ -353,13 +353,15 @@ void clear_lists(main_server_st *s)
|
||||
tls_cache_deinit(s->tls_db);
|
||||
}
|
||||
|
||||
static void kill_children(struct proc_list_st* clist)
|
||||
static void kill_children(main_server_st* s)
|
||||
{
|
||||
struct proc_st *ctmp;
|
||||
|
||||
list_for_each(&clist->head, ctmp, list) {
|
||||
if (ctmp->pid != -1)
|
||||
list_for_each(&s->clist->head, ctmp, list) {
|
||||
if (ctmp->pid != -1) {
|
||||
kill(ctmp->pid, SIGTERM);
|
||||
user_disconnected(s, ctmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,8 +371,8 @@ static void remove_proc(struct proc_st *ctmp)
|
||||
if (ctmp->fd >= 0)
|
||||
close(ctmp->fd);
|
||||
ctmp->fd = -1;
|
||||
|
||||
ctmp->pid = -1;
|
||||
|
||||
if (ctmp->lease)
|
||||
ctmp->lease->in_use = 0;
|
||||
list_del(&ctmp->list);
|
||||
@@ -544,7 +546,7 @@ int main(int argc, char** argv)
|
||||
for (;;) {
|
||||
if (terminate != 0) {
|
||||
mslog(&s, NULL, LOG_DEBUG, "termination signal received; waiting for children to die");
|
||||
kill_children(&clist);
|
||||
kill_children(&s);
|
||||
closelog();
|
||||
while (waitpid(-1, NULL, 0) > 0);
|
||||
exit(0);
|
||||
|
||||
Reference in New Issue
Block a user