aboutsummaryrefslogtreecommitdiff
path: root/src/microhttpd/digestauth.c
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-30 20:21:25 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2022-04-30 20:21:25 +0300
commitfbf3b5341164f956fa0ad3cacf61475a3aaef70c (patch)
tree258fd2ef4523f5893e05f7035d210f816c90a667 /src/microhttpd/digestauth.c
parentbf9ca17361a998b27c7f091af7b0ab6966c995e0 (diff)
downloadlibmicrohttpd-fbf3b5341164f956fa0ad3cacf61475a3aaef70c.tar.gz
libmicrohttpd-fbf3b5341164f956fa0ad3cacf61475a3aaef70c.zip
digestauth: added dedicated function for adding the new nonces
Diffstat (limited to 'src/microhttpd/digestauth.c')
-rw-r--r--src/microhttpd/digestauth.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 232d0e23..84fceeae 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -532,6 +532,42 @@ fast_simple_hash (const uint8_t *data,
532 532
533 533
534/** 534/**
535 * Add the new nonce to the nonce-nc map array.
536 *
537 * @param connection The MHD connection structure
538 * @param nonce A pointer that referenced a zero-terminated array of nonce
539 * @param noncelen the lenth of @a nonce, in characters
540 * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
541 */
542static bool
543add_nonce (struct MHD_Connection *connection,
544 const char *nonce,
545 size_t noncelen)
546{
547 struct MHD_Daemon *const daemon = connection->daemon;
548 unsigned int arr_size;
549 struct MHD_NonceNc *nn;
550
551 mhd_assert (MAX_NONCE_LENGTH >= noncelen);
552 arr_size = daemon->nonce_nc_size;
553 if (0 == arr_size)
554 return false;
555
556 nn = &daemon->nnc[fast_simple_hash ((const uint8_t *) nonce, noncelen)
557 % arr_size];
558
559 MHD_mutex_lock_chk_ (&daemon->nnc_lock);
560 memcpy (nn->nonce,
561 nonce,
562 noncelen + 1);
563 nn->nc = 0;
564 nn->nmask = 0;
565 MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
566 return true;
567}
568
569
570/**
535 * Check nonce-nc map array with either new nonce counter 571 * Check nonce-nc map array with either new nonce counter
536 * or a whole new nonce. 572 * or a whole new nonce.
537 * 573 *
@@ -1395,11 +1431,9 @@ MHD_queue_auth_fail_response2 (struct MHD_Connection *connection,
1395 realm, 1431 realm,
1396 &da, 1432 &da,
1397 nonce); 1433 nonce);
1398 if (MHD_NO == 1434 if (! add_nonce (connection,
1399 check_nonce_nc (connection, 1435 nonce,
1400 nonce, 1436 NONCE_STD_LEN (da.digest_size)))
1401 NONCE_STD_LEN (da.digest_size),
1402 0))
1403 { 1437 {
1404#ifdef HAVE_MESSAGES 1438#ifdef HAVE_MESSAGES
1405 MHD_DLOG (connection->daemon, 1439 MHD_DLOG (connection->daemon,