diff --git a/mongoose.c b/mongoose.c index b0ff8243eab04767365a2e2ac31d17a236e4e679..91138490d61fff477e93c1df093991b80e8d8cd8 100644 --- a/mongoose.c +++ b/mongoose.c @@ -2899,8 +2899,9 @@ static int check_password(const char *method, const char *ha1, const char *uri, // Authorize against the opened passwords file. Return 1 if authorized. -static int authorize(struct connection *conn, FILE *fp) { - const char *hdr = mg_get_header(&conn->mg_conn, "Authorization"); +int mg_authorize_digest(struct mg_connection *c, FILE *fp) { + struct connection *conn = (struct connection *) c; + const char *hdr = mg_get_header(c, "Authorization"); char line[256], f_user[256], ha1[256], f_domain[256], user[100], nonce[100], uri[MAX_REQUEST_SIZE], cnonce[100], resp[100], qop[100], nc[100]; @@ -2918,7 +2919,7 @@ static int authorize(struct connection *conn, FILE *fp) { !strcmp(user, f_user) && // NOTE(lsm): due to a bug in MSIE, we do not compare URIs !strcmp(conn->server->config_options[AUTH_DOMAIN], f_domain)) - return check_password(conn->mg_conn.request_method, ha1, uri, + return check_password(c->request_method, ha1, uri, nonce, nc, cnonce, qop, resp); } return 0; @@ -2931,7 +2932,7 @@ static int is_authorized(struct connection *conn, const char *path) { int authorized = 1; if ((fp = open_auth_file(conn, path)) != NULL) { - authorized = authorize(conn, fp); + authorized = mg_authorize_digest(&conn->mg_conn, fp); fclose(fp); } @@ -2944,7 +2945,7 @@ static int is_authorized_for_dav(struct connection *conn) { int authorized = 0; if (auth_file != NULL && (fp = fopen(auth_file, "r")) != NULL) { - authorized = authorize(conn, fp); + authorized = mg_authorize_digest(&conn->mg_conn, fp); fclose(fp); } diff --git a/mongoose.h b/mongoose.h index 5a3e90c4f4b72a298e16bef2263bf9deb178b45d..dc1c65e528e469abd29cd41783c62c3a76fd100f 100644 --- a/mongoose.h +++ b/mongoose.h @@ -96,6 +96,7 @@ int mg_parse_header(const char *hdr, const char *var_name, char *buf, size_t); // Utility functions void *mg_start_thread(void *(*func)(void *), void *param); char *mg_md5(char buf[33], ...); +int mg_authorize_digest(struct mg_connection *c, FILE *fp); #ifdef __cplusplus }