chiark / gitweb /
Report to stderr if we can't use getentropy
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Sep 2026 11:17:37 +0000 (12:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 11 Sep 2026 11:48:01 +0000 (12:48 +0100)
regress/m1test
regress/shlib
src/adns.h
src/internal.h
src/nextid.c
src/setup.c

index 37fab254f7c1dc2403e8b1d07fb70dc42afb5be0..58bae068e18908c4d4649d93d738bdfe857fe429 100755 (executable)
@@ -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
index eabe631bb3013abe9d643579b79449dc68308e3e..7ede3fdd0e4dd341a49dda4b1f4aae12426e5739 100644 (file)
@@ -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
index e8e108d793486d35bf82b4ccb036905ea13ede2f..ed3c955aec5a745f59b641e08515ac4719d0c5c8 100644 (file)
@@ -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
index 90e63d68dd090c07532b9ac833c61c566560c467..1c4976d519f862999b1220226689512c4374792b 100644 (file)
@@ -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];
 };
 
index d30eabcc9790281c43758eb9938a33cc0ac0ad61..c33e175bdf569d756600a4214ae1b5c1864c5a5c 100644 (file)
 
 #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;
 }
 
index dd72eac22c7855ce04fceb3de1de0063eb6fe153..02ce6df04b03a47889155b281df2ce13b662632f 100644 (file)
@@ -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;