Mercurial > dovecot > core-2.2
changeset 18956:3e1ab97a392c
lib-http auth: Implemented client-side handling of basic authentication scheme.
author | Stephan Bosch <stephan@rename-it.nl> |
---|---|
date | Tue, 18 Aug 2015 20:39:24 +0300 |
parents | cc09fc9194d1 |
children | 1d5d4d469b2b |
files | src/lib-http/http-auth.c src/lib-http/http-auth.h |
diffstat | 2 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-http/http-auth.c Tue Aug 18 20:39:24 2015 +0300 +++ b/src/lib-http/http-auth.c Tue Aug 18 20:39:24 2015 +0300 @@ -2,6 +2,7 @@ #include "lib.h" #include "str.h" +#include "base64.h" #include "array.h" #include "http-parser.h" @@ -420,7 +421,7 @@ const char *realm) { memset(chlng, 0, sizeof(*chlng)); - chlng->scheme = "basic"; + chlng->scheme = "Basic"; if (realm != NULL) { struct http_auth_param param; @@ -432,3 +433,21 @@ array_append(&chlng->params, ¶m, 1); } } + +void http_auth_basic_credentials_init(struct http_auth_credentials *crdts, + const char *username, const char *password) +{ + const char *auth; + string_t *data; + + i_assert(username != NULL && *username != '\0'); + i_assert(strchr(username, ':') == NULL); + + data = t_str_new(64); + auth = t_strconcat(username, ":", password, NULL); + base64_encode(auth, strlen(auth), data); + + memset(crdts, 0, sizeof(*crdts)); + crdts->scheme = "Basic"; + crdts->data = str_c(data); +}
--- a/src/lib-http/http-auth.h Tue Aug 18 20:39:24 2015 +0300 +++ b/src/lib-http/http-auth.h Tue Aug 18 20:39:24 2015 +0300 @@ -65,6 +65,8 @@ void http_auth_basic_challenge_init(struct http_auth_challenge *chlng, const char *realm); +void http_auth_basic_credentials_init(struct http_auth_credentials *crdts, + const char *username, const char *password); #endif