Skip to content

Commit e5a0aec

Browse files
committed
Make digest auth support conditional (issue #232)
When libmicrohttpd is built with --disable-dauth, the digest auth functions (MHD_digest_auth_get_username, MHD_digest_auth_check, MHD_queue_auth_fail_response) are not available, causing linker errors. This change detects digest auth availability at configure time and conditionally compiles the digest auth code, following the existing pattern used for GnuTLS support. Changes: - Add AC_CHECK_LIB detection for MHD_queue_auth_fail_response - Add HAVE_DAUTH preprocessor flag when digest auth is available - Wrap digest auth code in #ifdef HAVE_DAUTH guards - Show digest auth status in configure summary
1 parent 89b55d2 commit e5a0aec

File tree

8 files changed

+84
-3
lines changed

8 files changed

+84
-3
lines changed

.github/workflows/verify-build.yml

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,18 @@ jobs:
248248
debug: nodebug
249249
coverage: nocoverage
250250
shell: bash
251+
# Test build without digest auth support (issue #232)
252+
- test-group: extra
253+
os: ubuntu-latest
254+
os-type: ubuntu
255+
build-type: no-dauth
256+
compiler-family: gcc
257+
c-compiler: gcc
258+
cc-compiler: g++
259+
debug: nodebug
260+
coverage: nocoverage
261+
linking: dynamic
262+
shell: bash
251263
- test-group: extra
252264
os: ubuntu-latest
253265
os-type: ubuntu
@@ -467,7 +479,7 @@ jobs:
467479
with:
468480
path: libmicrohttpd-0.9.77
469481
key: ${{ matrix.os }}-${{ matrix.c-compiler }}-libmicrohttpd-0.9.77-pre-built
470-
if: ${{ matrix.os-type != 'windows' }}
482+
if: ${{ matrix.os-type != 'windows' && matrix.build-type != 'no-dauth' }}
471483

472484
- name: Build libmicrohttpd dependency (if not cached)
473485
run: |
@@ -476,12 +488,31 @@ jobs:
476488
cd libmicrohttpd-0.9.77 ;
477489
./configure --disable-examples ;
478490
make ;
479-
if: ${{ matrix.os-type != 'windows' && steps.cache-libmicrohttpd.outputs.cache-hit != 'true' }}
491+
if: ${{ matrix.os-type != 'windows' && matrix.build-type != 'no-dauth' && steps.cache-libmicrohttpd.outputs.cache-hit != 'true' }}
492+
493+
- name: Build libmicrohttpd without digest auth (no-dauth test)
494+
run: |
495+
curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-0.9.77.tar.gz -o libmicrohttpd-0.9.77.tar.gz ;
496+
tar -xzf libmicrohttpd-0.9.77.tar.gz ;
497+
cd libmicrohttpd-0.9.77 ;
498+
./configure --disable-examples --disable-dauth ;
499+
make ;
500+
if: ${{ matrix.build-type == 'no-dauth' }}
480501

481502
- name: Install libmicrohttpd
482503
run: cd libmicrohttpd-0.9.77 ; sudo make install ;
483504
if: ${{ matrix.os-type != 'windows' }}
484505

506+
- name: Verify digest auth is disabled (no-dauth test)
507+
run: |
508+
# Verify that MHD_queue_auth_fail_response is NOT present in libmicrohttpd
509+
if nm /usr/local/lib/libmicrohttpd.so 2>/dev/null | grep -q MHD_queue_auth_fail_response; then
510+
echo "ERROR: libmicrohttpd was built WITH digest auth support" ;
511+
exit 1 ;
512+
fi
513+
echo "Verified: libmicrohttpd built without digest auth support" ;
514+
if: ${{ matrix.build-type == 'no-dauth' }}
515+
485516
- name: Build and install libmicrohttpd (Windows)
486517
if: ${{ matrix.os-type == 'windows' }}
487518
run: |
@@ -532,6 +563,18 @@ jobs:
532563
../configure --disable-fastopen;
533564
fi
534565
566+
- name: Verify libhttpserver detected no digest auth (no-dauth test)
567+
run: |
568+
cd build ;
569+
if grep -q "Digest Auth.*:.*no" config.log; then
570+
echo "Verified: libhttpserver correctly detected digest auth is disabled" ;
571+
else
572+
echo "ERROR: libhttpserver did not detect that digest auth is disabled" ;
573+
grep "Digest Auth" config.log || echo "Digest Auth line not found" ;
574+
exit 1 ;
575+
fi
576+
if: ${{ matrix.build-type == 'no-dauth' }}
577+
535578
- name: Print config.log
536579
shell: bash
537580
run: |

configure.ac

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ fi
149149
AM_CONDITIONAL([COND_CROSS_COMPILE],[test x"$cond_cross_compile" = x"yes"])
150150
AC_SUBST(COND_CROSS_COMPILE)
151151

152+
# Check for digest auth support in libmicrohttpd
153+
AC_CHECK_LIB([microhttpd], [MHD_queue_auth_fail_response],
154+
[have_dauth="yes"],
155+
[have_dauth="no"; AC_MSG_WARN("libmicrohttpd digest auth support not found. Digest auth will be disabled")])
156+
152157
AC_MSG_CHECKING([whether to build with TCP_FASTOPEN support])
153158
AC_ARG_ENABLE([fastopen],
154159
[AS_HELP_STRING([--enable-fastopen],
@@ -259,6 +264,13 @@ fi
259264

260265
AM_CONDITIONAL([HAVE_GNUTLS],[test x"$have_gnutls" = x"yes"])
261266

267+
if test x"$have_dauth" = x"yes"; then
268+
AM_CXXFLAGS="$AM_CXXFLAGS -DHAVE_DAUTH"
269+
AM_CFLAGS="$AM_CXXFLAGS -DHAVE_DAUTH"
270+
fi
271+
272+
AM_CONDITIONAL([HAVE_DAUTH],[test x"$have_dauth" = x"yes"])
273+
262274
DX_HTML_FEATURE(ON)
263275
DX_CHM_FEATURE(OFF)
264276
DX_CHI_FEATURE(OFF)
@@ -309,6 +321,7 @@ AC_MSG_NOTICE([Configuration Summary:
309321
License : LGPL only
310322
Debug : ${debugit}
311323
TLS Enabled : ${have_gnutls}
324+
Digest Auth : ${have_dauth}
312325
TCP_FASTOPEN : ${is_fastopen_supported}
313326
Static : ${static}
314327
Windows build : ${is_windows}

src/digest_auth_fail_response.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
USA
1919
*/
2020

21+
#ifdef HAVE_DAUTH
22+
2123
#include "httpserver/digest_auth_fail_response.hpp"
2224
#include <microhttpd.h>
2325
#include <iosfwd>
@@ -32,3 +34,5 @@ int digest_auth_fail_response::enqueue_response(MHD_Connection* connection, MHD_
3234
}
3335

3436
} // namespace httpserver
37+
38+
#endif // HAVE_DAUTH

src/http_request.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void http_request::set_method(const std::string& method) {
4242
this->method = string_utilities::to_upper_copy(method);
4343
}
4444

45+
#ifdef HAVE_DAUTH
4546
bool http_request::check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool* reload_nonce) const {
4647
std::string_view digested_user = get_digested_user();
4748

@@ -57,6 +58,7 @@ bool http_request::check_digest_auth(const std::string& realm, const std::string
5758
*reload_nonce = false;
5859
return true;
5960
}
61+
#endif // HAVE_DAUTH
6062

6163
std::string_view http_request::get_connection_value(std::string_view key, enum MHD_ValueKind kind) const {
6264
const char* header_c = MHD_lookup_connection_value(underlying_connection, kind, key.data());
@@ -257,6 +259,7 @@ std::string_view http_request::get_pass() const {
257259
return cache->password;
258260
}
259261

262+
#ifdef HAVE_DAUTH
260263
std::string_view http_request::get_digested_user() const {
261264
if (!cache->digested_user.empty()) {
262265
return cache->digested_user;
@@ -272,6 +275,7 @@ std::string_view http_request::get_digested_user() const {
272275

273276
return cache->digested_user;
274277
}
278+
#endif // HAVE_DAUTH
275279

276280
#ifdef HAVE_GNUTLS
277281
bool http_request::has_tls_session() const {

src/httpserver.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929

3030
#include "httpserver/basic_auth_fail_response.hpp"
3131
#include "httpserver/deferred_response.hpp"
32+
#ifdef HAVE_DAUTH
3233
#include "httpserver/digest_auth_fail_response.hpp"
34+
#endif // HAVE_DAUTH
3335
#include "httpserver/file_response.hpp"
3436
#include "httpserver/http_arg_value.hpp"
3537
#include "httpserver/http_request.hpp"

src/httpserver/digest_auth_fail_response.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifndef SRC_HTTPSERVER_DIGEST_AUTH_FAIL_RESPONSE_HPP_
2626
#define SRC_HTTPSERVER_DIGEST_AUTH_FAIL_RESPONSE_HPP_
2727

28+
#ifdef HAVE_DAUTH
29+
2830
#include <string>
2931
#include "httpserver/http_utils.hpp"
3032
#include "httpserver/string_response.hpp"
@@ -66,4 +68,6 @@ class digest_auth_fail_response : public string_response {
6668

6769
} // namespace httpserver
6870

71+
#endif // HAVE_DAUTH
72+
6973
#endif // SRC_HTTPSERVER_DIGEST_AUTH_FAIL_RESPONSE_HPP_

src/httpserver/http_request.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ class http_request {
6565
**/
6666
std::string_view get_user() const;
6767

68+
#ifdef HAVE_DAUTH
6869
/**
6970
* Method used to get the username extracted from a digest authentication
7071
* @return the username
7172
**/
7273
std::string_view get_digested_user() const;
74+
#endif // HAVE_DAUTH
7375

7476
/**
7577
* Method used to get the password eventually passed through basic authentication.
@@ -250,7 +252,9 @@ class http_request {
250252
**/
251253
uint16_t get_requestor_port() const;
252254

255+
#ifdef HAVE_DAUTH
253256
bool check_digest_auth(const std::string& realm, const std::string& password, int nonce_timeout, bool* reload_nonce) const;
257+
#endif // HAVE_DAUTH
254258

255259
friend std::ostream &operator<< (std::ostream &os, http_request &r);
256260

@@ -412,7 +416,9 @@ class http_request {
412416
std::string password;
413417
std::string querystring;
414418
std::string requestor_ip;
419+
#ifdef HAVE_DAUTH
415420
std::string digested_user;
421+
#endif // HAVE_DAUTH
416422
std::map<std::string, std::vector<std::string>, http::arg_comparator> unescaped_args;
417423

418424
bool args_populated = false;

test/integ/authentication.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ using httpserver::webserver;
4444
using httpserver::create_webserver;
4545
using httpserver::http_response;
4646
using httpserver::basic_auth_fail_response;
47+
#ifdef HAVE_DAUTH
4748
using httpserver::digest_auth_fail_response;
49+
#endif // HAVE_DAUTH
4850
using httpserver::string_response;
4951
using httpserver::http_resource;
5052
using httpserver::http_request;
@@ -74,6 +76,7 @@ class user_pass_resource : public http_resource {
7476
}
7577
};
7678

79+
#ifdef HAVE_DAUTH
7780
class digest_resource : public http_resource {
7881
public:
7982
shared_ptr<http_response> render_GET(const http_request& req) {
@@ -88,6 +91,7 @@ class digest_resource : public http_resource {
8891
return std::make_shared<string_response>("SUCCESS", 200, "text/plain");
8992
}
9093
};
94+
#endif // HAVE_DAUTH
9195

9296
LT_BEGIN_SUITE(authentication_suite)
9397
void set_up() {
@@ -150,7 +154,8 @@ LT_END_AUTO_TEST(base_auth_fail)
150154
// do not run the digest auth tests on windows as curl
151155
// appears to have problems with it.
152156
// Will fix this separately
153-
#ifndef _WINDOWS
157+
// Also skip if libmicrohttpd was built without digest auth support
158+
#if !defined(_WINDOWS) && defined(HAVE_DAUTH)
154159

155160
LT_BEGIN_AUTO_TEST(authentication_suite, digest_auth)
156161
webserver ws = create_webserver(PORT)

0 commit comments

Comments
 (0)