mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-10-14 02:22:03 +08:00
eliminated auth message upper limit
This commit is contained in:
+7
-3
@@ -226,18 +226,22 @@ static int gssapi_auth_pass(void *ctx, const char *spnego, unsigned spnego_len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gssapi_auth_msg(void *ctx, char *msg, size_t msg_size)
|
static int gssapi_auth_msg(void *ctx, void *pool, char **msg)
|
||||||
{
|
{
|
||||||
struct gssapi_ctx_st *pctx = ctx;
|
struct gssapi_ctx_st *pctx = ctx;
|
||||||
OM_uint32 min;
|
OM_uint32 min;
|
||||||
|
unsigned length;
|
||||||
|
|
||||||
/* our msg is our SPNEGO reply */
|
/* our msg is our SPNEGO reply */
|
||||||
if (pctx->msg.value != NULL) {
|
if (pctx->msg.value != NULL) {
|
||||||
base64_encode((char *)pctx->msg.value, pctx->msg.length, (char *)msg, msg_size);
|
length = BASE64_LENGTH(pctx->msg.length)+1;
|
||||||
|
*msg = talloc_size(pool, length);
|
||||||
|
|
||||||
|
base64_encode((char *)pctx->msg.value, pctx->msg.length, *msg, length);
|
||||||
gss_release_buffer(&min, &pctx->msg);
|
gss_release_buffer(&min, &pctx->msg);
|
||||||
pctx->msg.value = NULL;
|
pctx->msg.value = NULL;
|
||||||
} else {
|
} else {
|
||||||
msg[0] = 0;
|
*msg = NULL;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -200,10 +200,9 @@ fail1:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pam_auth_msg(void* ctx, char* msg, size_t msg_size)
|
static int pam_auth_msg(void* ctx, void *pool, char** msg)
|
||||||
{
|
{
|
||||||
struct pam_ctx_st * pctx = ctx;
|
struct pam_ctx_st * pctx = ctx;
|
||||||
int size;
|
|
||||||
|
|
||||||
if (pctx->state != PAM_S_INIT && pctx->state != PAM_S_WAIT_FOR_PASS) {
|
if (pctx->state != PAM_S_INIT && pctx->state != PAM_S_WAIT_FOR_PASS) {
|
||||||
syslog(LOG_AUTH, "PAM-auth: conversation in wrong state (%d)", pctx->state);
|
syslog(LOG_AUTH, "PAM-auth: conversation in wrong state (%d)", pctx->state);
|
||||||
@@ -224,13 +223,14 @@ int size;
|
|||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
if (pctx->msg.length == 0)
|
if (pctx->msg.length == 0)
|
||||||
if (pctx->changing)
|
if (pctx->changing)
|
||||||
strlcpy(msg, "Please enter the new password.", msg_size);
|
*msg = talloc_strdup(pool, "Please enter the new password.");
|
||||||
else
|
else
|
||||||
strlcpy(msg, "Please enter your password.", msg_size);
|
*msg = talloc_strdup(pool, "Please enter your password.");
|
||||||
else {
|
else {
|
||||||
size = MIN(msg_size-1, pctx->msg.length);
|
if (str_append_data(&pctx->msg, "\0", 1) < 0)
|
||||||
memcpy(msg, pctx->msg.data, size);
|
return -1;
|
||||||
msg[size] = 0;
|
|
||||||
|
*msg = talloc_strdup(pool, (char*)pctx->msg.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -250,11 +250,11 @@ static int plain_auth_pass(void *ctx, const char *pass, unsigned pass_len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int plain_auth_msg(void *ctx, char *msg, size_t msg_size)
|
static int plain_auth_msg(void *ctx, void *pool, char **msg)
|
||||||
{
|
{
|
||||||
struct plain_ctx_st *pctx = ctx;
|
struct plain_ctx_st *pctx = ctx;
|
||||||
|
|
||||||
strlcpy(msg, pctx->pass_msg, msg_size);
|
*msg = talloc_strdup(pool, pctx->pass_msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -295,11 +295,11 @@ static int radius_auth_pass(void *ctx, const char *pass, unsigned pass_len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int radius_auth_msg(void *ctx, char *msg, size_t msg_size)
|
static int radius_auth_msg(void *ctx, void *pool, char **msg)
|
||||||
{
|
{
|
||||||
struct radius_ctx_st *pctx = ctx;
|
struct radius_ctx_st *pctx = ctx;
|
||||||
|
|
||||||
strlcpy(msg, pctx->pass_msg, msg_size);
|
*msg = talloc_strdup(pool, pctx->pass_msg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+8
-2
@@ -123,7 +123,7 @@ int send_sec_auth_reply(int cfd, sec_mod_st * sec, client_entry_st * entry, AUTH
|
|||||||
|
|
||||||
msg.user_name = entry->username;
|
msg.user_name = entry->username;
|
||||||
|
|
||||||
if (entry->msg_str[0] != 0) {
|
if (entry->msg_str != NULL) {
|
||||||
msg.msg = entry->msg_str;
|
msg.msg = entry->msg_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,6 +156,9 @@ int send_sec_auth_reply(int cfd, sec_mod_st * sec, client_entry_st * entry, AUTH
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
talloc_free(entry->msg_str);
|
||||||
|
entry->msg_str = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +182,9 @@ int send_sec_auth_reply_msg(int cfd, sec_mod_st * sec, client_entry_st * e)
|
|||||||
seclog(sec, LOG_ERR, "send_auth_reply_msg error");
|
seclog(sec, LOG_ERR, "send_auth_reply_msg error");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
talloc_free(e->msg_str);
|
||||||
|
e->msg_str = NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -550,7 +556,7 @@ int handle_sec_auth_init(int cfd, sec_mod_st * sec, const SecAuthInitMsg * req)
|
|||||||
strlcpy(e->username, req->user_name, sizeof(e->username));
|
strlcpy(e->username, req->user_name, sizeof(e->username));
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = e->module->auth_msg(e->auth_ctx, e->msg_str, sizeof(e->msg_str));
|
ret = e->module->auth_msg(e->auth_ctx, e, &e->msg_str);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|||||||
+1
-1
@@ -32,7 +32,7 @@ struct auth_mod_st {
|
|||||||
void (*global_init)(void *pool, void* additional);
|
void (*global_init)(void *pool, void* additional);
|
||||||
void (*global_deinit)(void);
|
void (*global_deinit)(void);
|
||||||
int (*auth_init)(void** ctx, void *pool, const char* username, const char* ip, void* additional);
|
int (*auth_init)(void** ctx, void *pool, const char* username, const char* ip, void* additional);
|
||||||
int (*auth_msg)(void* ctx, char* msg, size_t msg_size);
|
int (*auth_msg)(void* ctx, void *pool, char** msg);
|
||||||
int (*auth_pass)(void* ctx, const char* pass, unsigned pass_len);
|
int (*auth_pass)(void* ctx, const char* pass, unsigned pass_len);
|
||||||
int (*auth_group)(void* ctx, const char *suggested, char *groupname, int groupname_size);
|
int (*auth_group)(void* ctx, const char *suggested, char *groupname, int groupname_size);
|
||||||
int (*auth_user)(void* ctx, char *groupname, int groupname_size);
|
int (*auth_user)(void* ctx, char *groupname, int groupname_size);
|
||||||
|
|||||||
@@ -138,6 +138,7 @@ client_entry_st *find_client_entry(sec_mod_st *sec, uint8_t sid[SID_SIZE])
|
|||||||
static void clean_entry(sec_mod_st *sec, client_entry_st * e)
|
static void clean_entry(sec_mod_st *sec, client_entry_st * e)
|
||||||
{
|
{
|
||||||
sec_auth_user_deinit(sec, e);
|
sec_auth_user_deinit(sec, e);
|
||||||
|
talloc_free(e->msg_str);
|
||||||
talloc_free(e);
|
talloc_free(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -56,7 +56,7 @@ typedef struct client_entry_st {
|
|||||||
unsigned in_use; /* counter of users of this structure */
|
unsigned in_use; /* counter of users of this structure */
|
||||||
unsigned tls_auth_ok;
|
unsigned tls_auth_ok;
|
||||||
|
|
||||||
char msg_str[MAX_MSG_SIZE];
|
char *msg_str;
|
||||||
|
|
||||||
stats_st stats;
|
stats_st stats;
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ extern int syslog_open;
|
|||||||
|
|
||||||
|
|
||||||
#define MAX_CIPHERSUITE_NAME 64
|
#define MAX_CIPHERSUITE_NAME 64
|
||||||
#define MAX_MSG_SIZE 2048
|
|
||||||
#define SID_SIZE 16
|
#define SID_SIZE 16
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|||||||
+19
-13
@@ -696,8 +696,7 @@ int connect_to_secmod(worker_st * ws)
|
|||||||
return sd;
|
return sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int recv_auth_reply(worker_st * ws, int sd, char *txt,
|
static int recv_auth_reply(worker_st * ws, int sd, char **txt)
|
||||||
size_t max_txt_size)
|
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
SecAuthReplyMsg *msg = NULL;
|
SecAuthReplyMsg *msg = NULL;
|
||||||
@@ -713,7 +712,7 @@ static int recv_auth_reply(worker_st * ws, int sd, char *txt,
|
|||||||
oclog(ws, LOG_DEBUG, "received auth reply message (value: %u)",
|
oclog(ws, LOG_DEBUG, "received auth reply message (value: %u)",
|
||||||
(unsigned)msg->reply);
|
(unsigned)msg->reply);
|
||||||
|
|
||||||
if (txt) txt[0] = 0;
|
if (txt) *txt = NULL;
|
||||||
|
|
||||||
switch (msg->reply) {
|
switch (msg->reply) {
|
||||||
case AUTH__REP__MSG:
|
case AUTH__REP__MSG:
|
||||||
@@ -722,7 +721,7 @@ static int recv_auth_reply(worker_st * ws, int sd, char *txt,
|
|||||||
return ERR_AUTH_FAIL;
|
return ERR_AUTH_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(txt, msg->msg, max_txt_size);
|
*txt = talloc_strdup(ws, msg->msg);
|
||||||
if (msg->has_sid && msg->sid.len == sizeof(ws->sid)) {
|
if (msg->has_sid && msg->sid.len == sizeof(ws->sid)) {
|
||||||
/* update our sid */
|
/* update our sid */
|
||||||
memcpy(ws->sid, msg->sid.data, sizeof(ws->sid));
|
memcpy(ws->sid, msg->sid.data, sizeof(ws->sid));
|
||||||
@@ -761,8 +760,8 @@ static int recv_auth_reply(worker_st * ws, int sd, char *txt,
|
|||||||
memcpy(ws->session_id, msg->dtls_session_id.data,
|
memcpy(ws->session_id, msg->dtls_session_id.data,
|
||||||
msg->dtls_session_id.len);
|
msg->dtls_session_id.len);
|
||||||
|
|
||||||
if (msg->msg && txt)
|
if (txt)
|
||||||
strlcpy(txt, msg->msg, max_txt_size);
|
*txt = talloc_strdup(ws, msg->msg);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case AUTH__REP__FAILED:
|
case AUTH__REP__FAILED:
|
||||||
@@ -1143,7 +1142,7 @@ int post_auth_handler(worker_st * ws, unsigned http_ver)
|
|||||||
char *password = NULL;
|
char *password = NULL;
|
||||||
char *groupname = NULL;
|
char *groupname = NULL;
|
||||||
char ipbuf[128];
|
char ipbuf[128];
|
||||||
char msg[MAX_MSG_SIZE];
|
char *msg = NULL;
|
||||||
unsigned def_group = 0;
|
unsigned def_group = 0;
|
||||||
|
|
||||||
if (req->body_length > 0) {
|
if (req->body_length > 0) {
|
||||||
@@ -1328,7 +1327,7 @@ int post_auth_handler(worker_st * ws, unsigned http_ver)
|
|||||||
goto auth_fail;
|
goto auth_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = recv_auth_reply(ws, sd, msg, sizeof(msg));
|
ret = recv_auth_reply(ws, sd, &msg);
|
||||||
if (sd != -1) {
|
if (sd != -1) {
|
||||||
close(sd);
|
close(sd);
|
||||||
sd = -1;
|
sd = -1;
|
||||||
@@ -1339,10 +1338,12 @@ int post_auth_handler(worker_st * ws, unsigned http_ver)
|
|||||||
ws->username);
|
ws->username);
|
||||||
ws->auth_state = S_AUTH_REQ;
|
ws->auth_state = S_AUTH_REQ;
|
||||||
|
|
||||||
if (ws->selected_auth->type & AUTH_TYPE_GSSAPI)
|
if (ws->selected_auth->type & AUTH_TYPE_GSSAPI) {
|
||||||
return basic_auth_handler(ws, http_ver, msg);
|
ret = basic_auth_handler(ws, http_ver, msg);
|
||||||
else
|
} else {
|
||||||
return get_auth_handler2(ws, http_ver, msg);
|
ret = get_auth_handler2(ws, http_ver, msg);
|
||||||
|
}
|
||||||
|
goto cleanup;
|
||||||
} else if (ret < 0) {
|
} else if (ret < 0) {
|
||||||
oclog(ws, LOG_ERR, "failed authentication for '%s'",
|
oclog(ws, LOG_ERR, "failed authentication for '%s'",
|
||||||
ws->username);
|
ws->username);
|
||||||
@@ -1352,7 +1353,8 @@ int post_auth_handler(worker_st * ws, unsigned http_ver)
|
|||||||
oclog(ws, LOG_HTTP_DEBUG, "user '%s' obtained cookie", ws->username);
|
oclog(ws, LOG_HTTP_DEBUG, "user '%s' obtained cookie", ws->username);
|
||||||
ws->auth_state = S_AUTH_COOKIE;
|
ws->auth_state = S_AUTH_COOKIE;
|
||||||
|
|
||||||
return post_common_handler(ws, http_ver, msg);
|
ret = post_common_handler(ws, http_ver, msg);
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
ask_auth:
|
ask_auth:
|
||||||
|
|
||||||
@@ -1366,5 +1368,9 @@ int post_auth_handler(worker_st * ws, unsigned http_ver)
|
|||||||
"HTTP/1.1 401 Unauthorized\r\nX-Reason: %s\r\n\r\n",
|
"HTTP/1.1 401 Unauthorized\r\nX-Reason: %s\r\n\r\n",
|
||||||
reason);
|
reason);
|
||||||
cstp_fatal_close(ws, GNUTLS_A_ACCESS_DENIED);
|
cstp_fatal_close(ws, GNUTLS_A_ACCESS_DENIED);
|
||||||
|
talloc_free(msg);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
cleanup:
|
||||||
|
talloc_free(msg);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user