From: Ian Jackson Date: Fri, 11 Sep 2026 11:17:37 +0000 (+0100) Subject: Report to stderr if we can't use getentropy X-Git-Tag: adns-1.7.0~8 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=838cef86ec44b12b6c35b50317bcc5e99c7c4765;p=adns.git Report to stderr if we can't use getentropy --- diff --git a/regress/m1test b/regress/m1test index 37fab25..58bae06 100755 --- a/regress/m1test +++ b/regress/m1test @@ -62,6 +62,9 @@ fi queryargs="$*" initstring="`cat $srcdir/init-$initfile.text`" +initstring="$initstring +options adns_qid_predictable_ok +" xinitflagsf=$srcdir/$program-xinitflags.text if test -e $xinitflagsf then diff --git a/regress/shlib b/regress/shlib index eabe631..7ede3fd 100644 --- a/regress/shlib +++ b/regress/shlib @@ -16,6 +16,9 @@ playback_prepare () { read <&4 queryargs initstring="`cat $srcdir/init-$initfile.text`" + initstring="$initstring +options adns_qid_predictable_ok +" xinitflagsf=$srcdir/$program-xinitflags.text if test -e $xinitflagsf then diff --git a/src/adns.h b/src/adns.h index e8e108d..ed3c955 100644 --- a/src/adns.h +++ b/src/adns.h @@ -600,6 +600,10 @@ int adns_init_logfn(adns_state *newstate_r, adns_initflags flags, * control the relative order of addresses in answers. This option * overrides the corresponding init flags (covered by adns_if_afmask). * + * adns_qid_predictable_ok + * Do not print an error message to stderr if we cannot use getentropy() + * to generate random query-ids. In this case, + * * adns_ignoreunkcfg * Ignore unknown options and configuration directives, rather than * logging them. To be effective, appear in the configuration diff --git a/src/internal.h b/src/internal.h index 90e63d6..1c4976d 100644 --- a/src/internal.h +++ b/src/internal.h @@ -407,6 +407,7 @@ struct adns__state { } sortlist[MAXSORTLIST]; char **searchlist; unsigned config_report_unknown:1; + unsigned nextid_report_fallback:1; unsigned short rand48xsubi[3]; }; diff --git a/src/nextid.c b/src/nextid.c index d30eabc..c33e175 100644 --- a/src/nextid.c +++ b/src/nextid.c @@ -22,6 +22,24 @@ #include "internal.h" +/* common, error handling */ + +static void good_failure(adns_state ads, const char *fmt, ...) + PRINTFFORMAT(2,3); + +static void good_failure(adns_state ads, const char *fmt, ...) { + va_list al; + + if (!ads->nextid_report_fallback) return; + ads->nextid_report_fallback= 0; + + va_start(al,fmt); + adns__vdiag(ads, + " warning (suppress with 'options adns_qid_predictable_ok')", + adns_if_noerrprint, -1,0, fmt, al); + va_end(al); +} + #ifdef HAVE_GETENTROPY /* use getentropy */ @@ -36,7 +54,7 @@ static int32_t good_nextid(adns_state ads) { if (!ads->nextid.full) { r= getentropy(ads->nextid.buf, sizeof(ads->nextid.buf)); if (r) { - // XXXX log a warning + good_failure(ads, "getentropy() failed: %s", strerror(errno)); return -1; } ads->nextid.full= NEXTID_RANDOM_BUF_COUNT; @@ -52,7 +70,7 @@ static int32_t good_nextid(adns_state ads) { static void good_init(struct nextid_state *state) { } static int32_t good_nextid(adns_state ads) { - // XXXX log a warning + good_failure(ads, "getentropy() not available on this operating system"); return -1; } diff --git a/src/setup.c b/src/setup.c index dd72eac..02ce6df 100644 --- a/src/setup.c +++ b/src/setup.c @@ -335,6 +335,10 @@ static void ccf_options(adns_state ads, const char *fn, ads->config_report_unknown=0; continue; } + if (WORD_IS("adns_qid_predictable_ok")) { + ads->nextid_report_fallback= 0; + continue; + } if (/* adns's query strategy is not configurable */ WORD_STARTS("timeout:") || WORD_STARTS("attempts:") || @@ -639,6 +643,7 @@ static int init_begin(adns_state *ads_r, adns_initflags flags, timerclear(&ads->tcptimeout); ads->searchlist= 0; ads->config_report_unknown=1; + ads->nextid_report_fallback=1; pid= getpid(); ads->rand48xsubi[0]= pid;