Add header as an option for authentication blocks

This commit is contained in:
Joris Vink 2014-01-22 23:11:52 +01:00
parent 9a8092bf41
commit a80808d779
4 changed files with 31 additions and 5 deletions

View File

@ -172,6 +172,7 @@ struct kore_handler_params {
};
#define KORE_AUTH_TYPE_COOKIE 1
#define KORE_AUTH_TYPE_HEADER 2
struct kore_auth {
u_int8_t type;
@ -342,9 +343,7 @@ void kore_accesslog_init(void);
int kore_accesslog_wait(void);
void kore_accesslog_worker_init(void);
int kore_auth(struct http_request *, struct kore_auth *);
int kore_auth_cookie(struct http_request *, struct kore_auth *);
int kore_auth(struct http_request *, struct kore_auth *);
void kore_auth_init(void);
int kore_auth_new(char *);
struct kore_auth *kore_auth_lookup(char *);

View File

@ -89,7 +89,11 @@ ssl_no_compression
# authentication block at the end of the page directive (see below).
authentication auth_example {
# The authentication type denotes the way the user should
# be authenticated. Right now only cookie is available.
# be authenticated.
#
# Allow values:
# - cookie (checks for the cookie presence + pass to validator)
# - header (checks for header presence + pass to validator)
authentication_type cookie
# The name of the cookie to look for.

View File

@ -23,6 +23,9 @@
TAILQ_HEAD(, kore_auth) auth_list;
static int kore_auth_cookie(struct http_request *, struct kore_auth *);
static int kore_auth_header(struct http_request *, struct kore_auth *);
void
kore_auth_init(void)
{
@ -60,6 +63,9 @@ kore_auth(struct http_request *req, struct kore_auth *auth)
case KORE_AUTH_TYPE_COOKIE:
r = kore_auth_cookie(req, auth);
break;
case KORE_AUTH_TYPE_HEADER:
r = kore_auth_header(req, auth);
break;
default:
kore_log(LOG_NOTICE, "unknown auth type %d", auth->type);
return (KORE_RESULT_ERROR);
@ -83,7 +89,7 @@ kore_auth(struct http_request *req, struct kore_auth *auth)
return (KORE_RESULT_ERROR);
}
int
static int
kore_auth_cookie(struct http_request *req, struct kore_auth *auth)
{
int i, v;
@ -121,6 +127,21 @@ kore_auth_cookie(struct http_request *req, struct kore_auth *auth)
return (i);
}
static int
kore_auth_header(struct http_request *req, struct kore_auth *auth)
{
int r;
char *header;
if (!http_request_header_get(req, auth->value, &header))
return (KORE_RESULT_ERROR);
r = kore_validator_check(auth->validator, header);
kore_mem_free(header);
return (r);
}
struct kore_auth *
kore_auth_lookup(char *name)
{

View File

@ -789,6 +789,8 @@ configure_authentication_type(char **argv)
if (!strcmp(argv[1], "cookie")) {
current_auth->type = KORE_AUTH_TYPE_COOKIE;
} else if (!strcmp(argv[1], "header")) {
current_auth->type = KORE_AUTH_TYPE_HEADER;
} else {
printf("unknown authentication type '%s'\n", argv[1]);
return (KORE_RESULT_ERROR);