kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit a80808d7795182cf7b0322c4f3cf20c3685ec0c2
parent 9a8092bf414902b61bfbe757e53378d0f9e22498
Author: Joris Vink <joris@coders.se>
Date:   Wed, 22 Jan 2014 23:11:52 +0100

Add header as an option for authentication blocks

Diffstat:
includes/kore.h | 5++---
modules/example/module.conf | 6+++++-
src/auth.c | 23++++++++++++++++++++++-
src/config.c | 2++
4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/includes/kore.h b/includes/kore.h @@ -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 *); diff --git a/modules/example/module.conf b/modules/example/module.conf @@ -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. diff --git a/src/auth.c b/src/auth.c @@ -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) { diff --git a/src/config.c b/src/config.c @@ -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);