aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/daemon/digestauth.c6
-rw-r--r--src/examples/digest_auth_example.c39
-rw-r--r--src/include/microhttpd.h4
3 files changed, 34 insertions, 15 deletions
diff --git a/src/daemon/digestauth.c b/src/daemon/digestauth.c
index f607debb..8c09b3a6 100644
--- a/src/daemon/digestauth.c
+++ b/src/daemon/digestauth.c
@@ -505,16 +505,13 @@ int
505MHD_queue_auth_fail_response(struct MHD_Connection *connection, 505MHD_queue_auth_fail_response(struct MHD_Connection *connection,
506 const char *realm, 506 const char *realm,
507 const char *opaque, 507 const char *opaque,
508 struct MHD_Response *response,
508 int signal_stale) 509 int signal_stale)
509{ 510{
510 int ret; 511 int ret;
511 size_t hlen; 512 size_t hlen;
512 char nonce[HASH_MD5_HEX_LEN + 9]; 513 char nonce[HASH_MD5_HEX_LEN + 9];
513 struct MHD_Response *response;
514 514
515 response = MHD_create_response_from_data(0, NULL, MHD_NO, MHD_NO);
516 if (NULL == response)
517 return MHD_NO;
518 515
519 /* Generating the server nonce */ 516 /* Generating the server nonce */
520 calculate_nonce ((uint32_t) time(NULL), 517 calculate_nonce ((uint32_t) time(NULL),
@@ -549,7 +546,6 @@ MHD_queue_auth_fail_response(struct MHD_Connection *connection,
549 ret = MHD_queue_response(connection, 546 ret = MHD_queue_response(connection,
550 MHD_HTTP_UNAUTHORIZED, 547 MHD_HTTP_UNAUTHORIZED,
551 response); 548 response);
552 MHD_destroy_response(response);
553 return ret; 549 return ret;
554} 550}
555 551
diff --git a/src/examples/digest_auth_example.c b/src/examples/digest_auth_example.c
index 8f3ed4ec..51c81b83 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -26,7 +26,9 @@
26#include <microhttpd.h> 26#include <microhttpd.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" 29#define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>Access granted</body></html>"
30
31#define DENIED "<html><head><title>libmicrohttpd demo</title></head><body>Access denied</body></html>"
30 32
31#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4" 33#define OPAQUE "11733b200778ce33060f31c9af70a870ba96ddd4"
32 34
@@ -46,20 +48,37 @@ ahc_echo (void *cls,
46 48
47 username = MHD_digest_auth_get_username(connection); 49 username = MHD_digest_auth_get_username(connection);
48 if (username == NULL) 50 if (username == NULL)
49 return MHD_queue_auth_fail_response(connection, realm, 51 {
50 OPAQUE, 52 response = MHD_create_response_from_data(strlen (DENIED),
51 MHD_NO); 53 DENIED,
54 MHD_NO, MHD_NO);
55 ret = MHD_queue_auth_fail_response(connection, realm,
56 OPAQUE,
57 response,
58 MHD_NO);
59 MHD_destroy_response(response);
60 return ret;
61 }
52 ret = MHD_digest_auth_check(connection, realm, 62 ret = MHD_digest_auth_check(connection, realm,
53 username, 63 username,
54 password, 64 password,
55 300); 65 300);
56 free(username); 66 free(username);
57 if (ret == MHD_INVALID_NONCE) 67 if ( (ret == MHD_INVALID_NONCE) ||
58 return MHD_queue_auth_fail_response(connection, realm, 68 (ret == MHD_NO) )
59 OPAQUE, MHD_YES); 69 {
60 if (ret == MHD_NO) 70 response = MHD_create_response_from_data(strlen (DENIED),
61 return MHD_queue_auth_fail_response(connection, realm, 71 DENIED,
62 OPAQUE, MHD_NO); 72 MHD_NO, MHD_NO);
73 if (NULL == response)
74 return MHD_NO;
75 ret = MHD_queue_auth_fail_response(connection, realm,
76 OPAQUE,
77 response,
78 (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO);
79 MHD_destroy_response(response);
80 return ret;
81 }
63 response = MHD_create_response_from_data(strlen(PAGE), PAGE, 82 response = MHD_create_response_from_data(strlen(PAGE), PAGE,
64 MHD_NO, MHD_NO); 83 MHD_NO, MHD_NO);
65 ret = MHD_queue_response(connection, MHD_HTTP_OK, response); 84 ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index be003dac..a74bf558 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -1316,6 +1316,9 @@ MHD_digest_auth_check(struct MHD_Connection *connection,
1316 * @param connection The MHD connection structure 1316 * @param connection The MHD connection structure
1317 * @param realm The realm presented to the client 1317 * @param realm The realm presented to the client
1318 * @param opaque string to user for opaque value 1318 * @param opaque string to user for opaque value
1319 * @param response reply to send; should contain the "access denied"
1320 * body; note that this function will set the "WWW Authenticate"
1321 * header and that the caller should not do this
1319 * @param signal_stale MHD_YES if the nonce is invalid to add 1322 * @param signal_stale MHD_YES if the nonce is invalid to add
1320 * 'stale=true' to the authentication header 1323 * 'stale=true' to the authentication header
1321 * @return MHD_YES on success, MHD_NO otherwise 1324 * @return MHD_YES on success, MHD_NO otherwise
@@ -1324,6 +1327,7 @@ int
1324MHD_queue_auth_fail_response(struct MHD_Connection *connection, 1327MHD_queue_auth_fail_response(struct MHD_Connection *connection,
1325 const char *realm, 1328 const char *realm,
1326 const char *opaque, 1329 const char *opaque,
1330 struct MHD_Response *response,
1327 int signal_stale); 1331 int signal_stale);
1328 1332
1329 1333