[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] branch master updated (1b1361e4 -> 1a7e4a5a)
From: |
gnunet |
Subject: |
[libmicrohttpd] branch master updated (1b1361e4 -> 1a7e4a5a) |
Date: |
Thu, 27 Jan 2022 17:18:21 +0100 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a change to branch master
in repository libmicrohttpd.
from 1b1361e4 test_postprocessor_md: used the new source file instead of
the local substitution
new 07008a6f test_digestauth: use new API
new e0cb9221 test_quiesce: minor code unification
new b5b731a4 test_digestauth: added more detailed error reporting
new f20f9b5b test_digestauth: correctly use MHD API
new 1a7e4a5a Updated docs, test, and example to use correct digest auth API
The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
doc/libmicrohttpd.texi | 2 +-
src/examples/digest_auth_example.c | 20 +-
src/testcurl/test_digestauth.c | 279 ++++++++++++++++++--------
src/testcurl/test_digestauth_sha256.c | 2 +-
src/testcurl/test_digestauth_with_arguments.c | 22 +-
src/testcurl/test_quiesce.c | 9 +-
6 files changed, 227 insertions(+), 107 deletions(-)
diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi
index 46eed3b0..dfe8a686 100644
--- a/doc/libmicrohttpd.texi
+++ b/doc/libmicrohttpd.texi
@@ -3332,7 +3332,7 @@ ahc_echo (void *cls,
password,
300,
MHD_DIGEST_ALG_SHA256);
- free(username);
+ MHD_free(username);
if ( (ret == MHD_INVALID_NONCE) ||
(ret == MHD_NO) )
@{
diff --git a/src/examples/digest_auth_example.c
b/src/examples/digest_auth_example.c
index ea3da19a..68d13c84 100644
--- a/src/examples/digest_auth_example.c
+++ b/src/examples/digest_auth_example.c
@@ -70,10 +70,11 @@ ahc_echo (void *cls,
response = MHD_create_response_from_buffer (strlen (DENIED),
DENIED,
MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_auth_fail_response (connection, realm,
- MY_OPAQUE_STR,
- response,
- MHD_NO);
+ ret = MHD_queue_auth_fail_response2 (connection, realm,
+ MY_OPAQUE_STR,
+ response,
+ MHD_NO,
+ MHD_DIGEST_ALG_MD5);
MHD_destroy_response (response);
return ret;
}
@@ -90,11 +91,12 @@ ahc_echo (void *cls,
MHD_RESPMEM_PERSISTENT);
if (NULL == response)
return MHD_NO;
- ret = MHD_queue_auth_fail_response (connection, realm,
- MY_OPAQUE_STR,
- response,
- (res == MHD_INVALID_NONCE) ? MHD_YES :
- MHD_NO);
+ ret = MHD_queue_auth_fail_response2 (connection, realm,
+ MY_OPAQUE_STR,
+ response,
+ (res == MHD_INVALID_NONCE) ? MHD_YES :
+ MHD_NO,
+ MHD_DIGEST_ALG_MD5);
MHD_destroy_response (response);
return ret;
}
diff --git a/src/testcurl/test_digestauth.c b/src/testcurl/test_digestauth.c
index 5dd9d466..93f79a6a 100644
--- a/src/testcurl/test_digestauth.c
+++ b/src/testcurl/test_digestauth.c
@@ -1,7 +1,7 @@
/*
This file is part of libmicrohttpd
Copyright (C) 2010 Christian Grothoff
- Copyright (C) 2016-2021 Evgeny Grin (Karlson2k)
+ Copyright (C) 2016-2022 Evgeny Grin (Karlson2k)
libmicrohttpd is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@ -46,6 +46,119 @@
#include <wincrypt.h>
#endif
+
+#if defined(HAVE___FUNC__)
+#define externalErrorExit(ignore) \
+ _externalErrorExit_func(NULL, __func__, __LINE__)
+#define externalErrorExitDesc(errDesc) \
+ _externalErrorExit_func(errDesc, __func__, __LINE__)
+#define libcurlErrorExit(ignore) \
+ _libcurlErrorExit_func(NULL, __func__, __LINE__)
+#define libcurlErrorExitDesc(errDesc) \
+ _libcurlErrorExit_func(errDesc, __func__, __LINE__)
+#define mhdErrorExit(ignore) \
+ _mhdErrorExit_func(NULL, __func__, __LINE__)
+#define mhdErrorExitDesc(errDesc) \
+ _mhdErrorExit_func(errDesc, __func__, __LINE__)
+#elif defined(HAVE___FUNCTION__)
+#define externalErrorExit(ignore) \
+ _externalErrorExit_func(NULL, __FUNCTION__, __LINE__)
+#define externalErrorExitDesc(errDesc) \
+ _externalErrorExit_func(errDesc, __FUNCTION__, __LINE__)
+#define libcurlErrorExit(ignore) \
+ _libcurlErrorExit_func(NULL, __FUNCTION__, __LINE__)
+#define libcurlErrorExitDesc(errDesc) \
+ _libcurlErrorExit_func(errDesc, __FUNCTION__, __LINE__)
+#define mhdErrorExit(ignore) \
+ _mhdErrorExit_func(NULL, __FUNCTION__, __LINE__)
+#define mhdErrorExitDesc(errDesc) \
+ _mhdErrorExit_func(errDesc, __FUNCTION__, __LINE__)
+#else
+#define externalErrorExit(ignore) _externalErrorExit_func(NULL, NULL, __LINE__)
+#define externalErrorExitDesc(errDesc) \
+ _externalErrorExit_func(errDesc, NULL, __LINE__)
+#define libcurlErrorExit(ignore) _libcurlErrorExit_func(NULL, NULL, __LINE__)
+#define libcurlErrorExitDesc(errDesc) \
+ _libcurlErrorExit_func(errDesc, NULL, __LINE__)
+#define mhdErrorExit(ignore) _mhdErrorExit_func(NULL, NULL, __LINE__)
+#define mhdErrorExitDesc(errDesc) _mhdErrorExit_func(errDesc, NULL, __LINE__)
+#endif
+
+
+_MHD_NORETURN static void
+_externalErrorExit_func (const char *errDesc, const char *funcName, int
lineNum)
+{
+ fflush (stdout);
+ if ((NULL != errDesc) && (0 != errDesc[0]))
+ fprintf (stderr, "%s", errDesc);
+ else
+ fprintf (stderr, "System or external library call failed");
+ if ((NULL != funcName) && (0 != funcName[0]))
+ fprintf (stderr, " in %s", funcName);
+ if (0 < lineNum)
+ fprintf (stderr, " at line %d", lineNum);
+
+ fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
+ strerror (errno));
+#ifdef MHD_WINSOCK_SOCKETS
+ fprintf (stderr, "WSAGetLastError() value: %d\n", (int) WSAGetLastError ());
+#endif /* MHD_WINSOCK_SOCKETS */
+ fflush (stderr);
+ exit (99);
+}
+
+
+static char libcurl_errbuf[CURL_ERROR_SIZE] = "";
+
+_MHD_NORETURN static void
+_libcurlErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
+{
+ fflush (stdout);
+ if ((NULL != errDesc) && (0 != errDesc[0]))
+ fprintf (stderr, "%s", errDesc);
+ else
+ fprintf (stderr, "CURL library call failed");
+ if ((NULL != funcName) && (0 != funcName[0]))
+ fprintf (stderr, " in %s", funcName);
+ if (0 < lineNum)
+ fprintf (stderr, " at line %d", lineNum);
+
+ fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
+ strerror (errno));
+ if (0 != libcurl_errbuf[0])
+ fprintf (stderr, "Last libcurl error details: %s\n", libcurl_errbuf);
+
+ fflush (stderr);
+ exit (99);
+}
+
+
+_MHD_NORETURN static void
+_mhdErrorExit_func (const char *errDesc, const char *funcName, int lineNum)
+{
+ fflush (stdout);
+ if ((NULL != errDesc) && (0 != errDesc[0]))
+ fprintf (stderr, "%s", errDesc);
+ else
+ fprintf (stderr, "MHD unexpected error");
+ if ((NULL != funcName) && (0 != funcName[0]))
+ fprintf (stderr, " in %s", funcName);
+ if (0 < lineNum)
+ fprintf (stderr, " at line %d", lineNum);
+
+ fprintf (stderr, ".\nLast errno value: %d (%s)\n", (int) errno,
+ strerror (errno));
+
+ fflush (stderr);
+ exit (8);
+}
+
+
+/* Could be increased to facilitate debugging */
+#define TIMEOUTS_VAL 5
+
+#define MHD_URI_BASE_PATH "/bar%%20foo%%3Fkey%%3Dvalue"
+
#define PAGE \
"<html><head><title>libmicrohttpd demo</title></head><body>Access
granted</body></html>"
@@ -71,7 +184,7 @@ copyBuffer (void *ptr,
struct CBC *cbc = ctx;
if (cbc->pos + size * nmemb > cbc->size)
- return 0; /* overflow */
+ mhdErrorExitDesc ("Wrong too large data"); /* overflow */
memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb);
cbc->pos += size * nmemb;
return size * nmemb;
@@ -113,20 +226,26 @@ ahc_echo (void *cls,
response = MHD_create_response_from_buffer (strlen (DENIED),
DENIED,
MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_auth_fail_response (connection,
- realm,
- MY_OPAQUE,
- response,
- MHD_NO);
+ if (NULL == response)
+ mhdErrorExitDesc ("MHD_create_response_from_buffer failed");
+ ret = MHD_queue_auth_fail_response2 (connection,
+ realm,
+ MY_OPAQUE,
+ response,
+ MHD_NO,
+ MHD_DIGEST_ALG_MD5);
+ if (MHD_YES != ret)
+ mhdErrorExitDesc ("MHD_queue_auth_fail_response2 failed");
MHD_destroy_response (response);
return ret;
}
- ret_i = MHD_digest_auth_check (connection,
- realm,
- username,
- password,
- 300);
- free (username);
+ ret_i = MHD_digest_auth_check2 (connection,
+ realm,
+ username,
+ password,
+ 300,
+ MHD_DIGEST_ALG_MD5);
+ MHD_free (username);
if ( (ret_i == MHD_INVALID_NONCE) ||
(ret_i == MHD_NO) )
{
@@ -134,27 +253,68 @@ ahc_echo (void *cls,
DENIED,
MHD_RESPMEM_PERSISTENT);
if (NULL == response)
- return MHD_NO;
- ret = MHD_queue_auth_fail_response (connection,
- realm,
- MY_OPAQUE,
- response,
- (MHD_INVALID_NONCE == ret_i) ?
- MHD_YES : MHD_NO);
+ mhdErrorExitDesc ("MHD_create_response_from_buffer() failed");
+ ret = MHD_queue_auth_fail_response2 (connection,
+ realm,
+ MY_OPAQUE,
+ response,
+ (MHD_INVALID_NONCE == ret_i) ?
+ MHD_YES : MHD_NO,
+ MHD_DIGEST_ALG_MD5);
+ if (MHD_YES != ret)
+ mhdErrorExitDesc ("MHD_queue_auth_fail_response2() failed");
MHD_destroy_response (response);
return ret;
}
response = MHD_create_response_from_buffer (strlen (PAGE),
PAGE,
MHD_RESPMEM_PERSISTENT);
+ if (NULL == response)
+ mhdErrorExitDesc ("MHD_create_response_from_buffer() failed");
ret = MHD_queue_response (connection,
MHD_HTTP_OK,
response);
+ if (MHD_YES != ret)
+ mhdErrorExitDesc ("MHD_queue_auth_fail_response2() failed");
MHD_destroy_response (response);
return ret;
}
+static CURL *
+setupCURL (void *cbc, int port)
+{
+ CURL *c;
+
+ c = curl_easy_init ();
+ if (NULL == c)
+ libcurlErrorExitDesc ("curl_easy_init() failed");
+
+ if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_URL,
+ "http://127.0.0.1" MHD_URI_BASE_PATH)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_PORT, (long) port)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEFUNCTION,
+ ©Buffer)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_WRITEDATA, cbc)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT,
+ (long) TIMEOUTS_VAL)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_TIMEOUT,
+ (long) TIMEOUTS_VAL)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER,
+ libcurl_errbuf)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTP_VERSION,
+ CURL_HTTP_VERSION_1_1)))
+ libcurlErrorExitDesc ("curl_easy_setopt() failed");
+ if ((CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST)) ||
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_USERPWD,
+ "testuser:testpass")))
+ libcurlErrorExitDesc ("curl_easy_setopt() authorization options failed");
+ return c;
+}
+
+
static int
testDigestAuth ()
{
@@ -165,7 +325,6 @@ testDigestAuth ()
char buf[2048];
char rnd[8];
int port;
- char url[128];
#ifndef WINDOWS
int fd;
size_t len;
@@ -184,27 +343,15 @@ testDigestAuth ()
fd = open ("/dev/urandom",
O_RDONLY);
if (-1 == fd)
- {
- fprintf (stderr,
- "Failed to open `%s': %s\n",
- "/dev/urandom",
- strerror (errno));
- return 1;
- }
+ externalErrorExitDesc ("Failed to open '/dev/urandom'");
+
while (off < 8)
{
len = read (fd,
rnd,
8);
if (len == (size_t) -1)
- {
- fprintf (stderr,
- "Failed to read `%s': %s\n",
- "/dev/urandom",
- strerror (errno));
- (void) close (fd);
- return 1;
- }
+ externalErrorExitDesc ("Failed to read '/dev/urandom'");
off += len;
}
(void) close (fd);
@@ -219,22 +366,11 @@ testDigestAuth ()
PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT);
if (b == 0)
- {
- fprintf (stderr,
- "Failed to acquire crypto provider context: %lu\n",
- GetLastError ());
- return 1;
- }
+ externalErrorExitDesc ("CryptAcquireContext() failed");
b = CryptGenRandom (cc, 8, (BYTE *) rnd);
if (b == 0)
- {
- fprintf (stderr,
- "Failed to generate 8 random bytes: %lu\n",
- GetLastError ());
- }
+ externalErrorExitDesc ("CryptGenRandom() failed");
CryptReleaseContext (cc, 0);
- if (b == 0)
- return 1;
}
#endif
d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
@@ -253,45 +389,26 @@ testDigestAuth ()
MHD_DAEMON_INFO_BIND_PORT);
if ( (NULL == dinfo) ||
(0 == dinfo->port) )
- {
- MHD_stop_daemon (d);
- return 32;
- }
+ mhdErrorExitDesc ("MHD_get_daemon_info() failed");
port = (int) dinfo->port;
}
- snprintf (url,
- sizeof (url),
- "http://127.0.0.1:%d/bar%%20foo%%3Fkey%%3Dvalue",
- port);
- c = curl_easy_init ();
- curl_easy_setopt (c, CURLOPT_URL, url);
- curl_easy_setopt (c, CURLOPT_WRITEFUNCTION, ©Buffer);
- curl_easy_setopt (c, CURLOPT_WRITEDATA, &cbc);
- curl_easy_setopt (c, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
- curl_easy_setopt (c, CURLOPT_USERPWD, "testuser:testpass");
- curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L);
- curl_easy_setopt (c, CURLOPT_TIMEOUT, 150L);
- curl_easy_setopt (c, CURLOPT_CONNECTTIMEOUT, 150L);
- curl_easy_setopt (c, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
- /* NOTE: use of CONNECTTIMEOUT without also
- setting NOSIGNAL results in really weird
- crashes on my system!*/
- curl_easy_setopt (c, CURLOPT_NOSIGNAL, 1L);
+ c = setupCURL (&cbc, port);
if (CURLE_OK != (errornum = curl_easy_perform (c)))
- {
- fprintf (stderr,
- "curl_easy_perform failed: `%s'\n",
- curl_easy_strerror (errornum));
- curl_easy_cleanup (c);
- MHD_stop_daemon (d);
- return 2;
- }
+ mhdErrorExitDesc ("curl_easy_perform() failed");
curl_easy_cleanup (c);
MHD_stop_daemon (d);
if (cbc.pos != strlen (PAGE))
- return 4;
+ {
+ fprintf (stderr, "Got %u bytes ('%.*s'), expected %u bytes. ",
+ (unsigned) cbc.pos, (int) cbc.pos, cbc.buf,
+ (unsigned) strlen (MHD_URI_BASE_PATH));
+ mhdErrorExitDesc ("Wrong returned data length");
+ }
if (0 != strncmp (PAGE, cbc.buf, strlen (PAGE)))
- return 8;
+ {
+ fprintf (stderr, "Got invalid response '%.*s'. ", (int) cbc.pos, cbc.buf);
+ mhdErrorExitDesc ("Wrong returned data");
+ }
return 0;
}
diff --git a/src/testcurl/test_digestauth_sha256.c
b/src/testcurl/test_digestauth_sha256.c
index fff3a1d7..f6df664e 100644
--- a/src/testcurl/test_digestauth_sha256.c
+++ b/src/testcurl/test_digestauth_sha256.c
@@ -129,7 +129,7 @@ ahc_echo (void *cls,
password,
300,
MHD_DIGEST_ALG_SHA256);
- free (username);
+ MHD_free (username);
if ( (ret_i == MHD_INVALID_NONCE) ||
(ret_i == MHD_NO) )
{
diff --git a/src/testcurl/test_digestauth_with_arguments.c
b/src/testcurl/test_digestauth_with_arguments.c
index 91f2dd67..ac1aed56 100644
--- a/src/testcurl/test_digestauth_with_arguments.c
+++ b/src/testcurl/test_digestauth_with_arguments.c
@@ -107,10 +107,11 @@ ahc_echo (void *cls,
response = MHD_create_response_from_buffer (strlen (DENIED),
DENIED,
MHD_RESPMEM_PERSISTENT);
- ret = MHD_queue_auth_fail_response (connection, realm,
- MY_OPAQUE,
- response,
- MHD_NO);
+ ret = MHD_queue_auth_fail_response2 (connection, realm,
+ MY_OPAQUE,
+ response,
+ MHD_NO,
+ MHD_DIGEST_ALG_MD5);
MHD_destroy_response (response);
return ret;
}
@@ -118,7 +119,7 @@ ahc_echo (void *cls,
username,
password,
300);
- free (username);
+ MHD_free (username);
if ( (ret_i == MHD_INVALID_NONCE) ||
(ret_i == MHD_NO) )
{
@@ -127,11 +128,12 @@ ahc_echo (void *cls,
MHD_RESPMEM_PERSISTENT);
if (NULL == response)
return MHD_NO;
- ret = MHD_queue_auth_fail_response (connection, realm,
- MY_OPAQUE,
- response,
- (ret_i == MHD_INVALID_NONCE) ?
- MHD_YES : MHD_NO);
+ ret = MHD_queue_auth_fail_response2 (connection, realm,
+ MY_OPAQUE,
+ response,
+ (ret_i == MHD_INVALID_NONCE) ?
+ MHD_YES : MHD_NO,
+ MHD_DIGEST_ALG_MD5);
MHD_destroy_response (response);
return ret;
}
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index 1e0eb0c4..f9bca831 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -331,11 +331,10 @@ setupCURL (void *cbc)
(CURLE_OK != curl_easy_setopt (c, CURLOPT_ERRORBUFFER,
libcurl_errbuf)) ||
(CURLE_OK != curl_easy_setopt (c, CURLOPT_FAILONERROR, 1L)) ||
- ((oneone) ?
- (CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTP_VERSION,
- CURL_HTTP_VERSION_1_1)) :
- (CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTP_VERSION,
- CURL_HTTP_VERSION_1_0))))
+ (CURLE_OK != curl_easy_setopt (c, CURLOPT_HTTP_VERSION,
+ (oneone) ?
+ CURL_HTTP_VERSION_1_1 :
+ CURL_HTTP_VERSION_1_0)))
libcurlErrorExitDesc ("curl_easy_setopt() failed");
return c;
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (1b1361e4 -> 1a7e4a5a),
gnunet <=
- [libmicrohttpd] 01/05: test_digestauth: use new API, gnunet, 2022/01/27
- [libmicrohttpd] 04/05: test_digestauth: correctly use MHD API, gnunet, 2022/01/27
- [libmicrohttpd] 03/05: test_digestauth: added more detailed error reporting, gnunet, 2022/01/27
- [libmicrohttpd] 02/05: test_quiesce: minor code unification, gnunet, 2022/01/27
- [libmicrohttpd] 05/05: Updated docs, test, and example to use correct digest auth API, gnunet, 2022/01/27