]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
debuginfod-client: Add DEBUGINFOD_HEADERS_FILE.
authorDaniel Thornburgh <dthorn@google.com>
Tue, 18 Oct 2022 21:21:32 +0000 (14:21 -0700)
committerMark Wielaard <mark@klomp.org>
Fri, 28 Oct 2022 10:09:07 +0000 (12:09 +0200)
This DEBUGINFOD_HEADERS_FILE environment variable names a file to supply
HTTP headers to outgoing requests. Notably, this allows for
Authorization headers to be added from a file under OS access control.

Signed-off-by: Daniel Thornburgh <dthorn@google.com>
NEWS
debuginfod/ChangeLog
debuginfod/debuginfod-client.c
debuginfod/debuginfod.h.in
doc/ChangeLog
doc/debuginfod-client-config.7
doc/debuginfod_find_debuginfo.3

diff --git a/NEWS b/NEWS
index 6ebd172c5caec6592c04d0bc5d73b250b9e2c56d..3df652e3f4725a161546fb38203bef895bf9973a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ Version 0.188 some time after 0.187
 
 readelf: Add -D, --use-dynamic option.
 
+debuginfod-client: Add $DEBUGINFOD_HEADERS_FILE setting to supply outgoing
+                   HTTP headers.
+
 debuginfod: Add --disable-source-scan option.
 
 libdwfl: Add new function dwfl_get_debuginfod_client.
index 59d50df1fc8abfc7d4f487a4d0891edae00431f9..1df903fe4ac29abb6a68d26d73380d3eabe45ff4 100644 (file)
@@ -1,3 +1,8 @@
+2022-10-18  Daniel Thornburgh <dthorn@google.com>
+
+  * debuginfod-client.c (debuginfod_query_server): Add DEBUGINFOD_HEADERS_FILE
+  setting to supply outgoing HTTP headers.
+
 2022-10-17  Frank Ch. Eigler  <fche@redhat.com>
 
        * debuginfod.cxx (main): Report libmicrohttpd version.
index 2a14d9d96d2bb96c7078c0e9fcfa8f4d75203328..716cb76956173151adec3c5cc69ecd323a4355b9 100644 (file)
@@ -42,6 +42,7 @@
 #include "config.h"
 #include "debuginfod.h"
 #include "system.h"
+#include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 
@@ -447,6 +448,45 @@ add_default_headers(debuginfod_client *client)
   free (utspart);
 }
 
+/* Add HTTP headers found in the given file, one per line. Blank lines or invalid
+ * headers are ignored.
+ */
+static void
+add_headers_from_file(debuginfod_client *client, const char* filename)
+{
+  int vds = client->verbose_fd;
+  FILE *f = fopen (filename, "r");
+  if (f == NULL)
+    {
+      if (vds >= 0)
+       dprintf(vds, "header file %s: %s\n", filename, strerror(errno));
+      return;
+    }
+
+  while (1)
+    {
+      char buf[8192];
+      char *s = &buf[0];
+      if (feof(f))
+        break;
+      if (fgets (s, sizeof(buf), f) == NULL)
+        break;
+      for (char *c = s; *c != '\0'; ++c)
+        if (!isspace(*c))
+          goto nonempty;
+      continue;
+    nonempty:
+      ;
+      size_t last = strlen(s)-1;
+      if (s[last] == '\n')
+        s[last] = '\0';
+      int rc = debuginfod_add_http_header(client, s);
+      if (rc < 0 && vds >= 0)
+        dprintf(vds, "skipping bad header: %s\n", strerror(-rc));
+    }
+  fclose (f);
+}
+
 
 #define xalloc_str(p, fmt, args...)        \
   do                                       \
@@ -610,6 +650,11 @@ debuginfod_query_server (debuginfod_client *c,
   if (maxtime && vfd >= 0)
     dprintf(vfd, "using max time %lds\n", maxtime);
 
+  const char *headers_file_envvar;
+  headers_file_envvar = getenv(DEBUGINFOD_HEADERS_FILE_ENV_VAR);
+  if (headers_file_envvar != NULL)
+    add_headers_from_file(c, headers_file_envvar);
+
   /* Maxsize is valid*/
   if (maxsize > 0)
     {
index 40b1ea00a8081b1c71658c1f339d09f9f7a28c73..7d8e4972b185e5de2ef211647dc5934c2a9ed5f8 100644 (file)
@@ -38,6 +38,7 @@
 #define DEBUGINFOD_RETRY_LIMIT_ENV_VAR "DEBUGINFOD_RETRY_LIMIT"
 #define DEBUGINFOD_MAXSIZE_ENV_VAR "DEBUGINFOD_MAXSIZE"
 #define DEBUGINFOD_MAXTIME_ENV_VAR "DEBUGINFOD_MAXTIME"
+#define DEBUGINFOD_HEADERS_FILE_ENV_VAR "DEBUGINFOD_HEADERS_FILE"
 
 /* The libdebuginfod soname.  */
 #define DEBUGINFOD_SONAME "@LIBDEBUGINFOD_SONAME@"
index b2bb48901ec82199d09290506923497715c5a603..073023b4bf6e5155b4d09f44162b5412656c5b8c 100644 (file)
@@ -1,3 +1,7 @@
+2022-10-18  Daniel Thornburgh  <dthorn@google.com>
+
+       * debuginfod_find_debuginfo.3: Document DEBUGINFOD_HEADERS_FILE.
+
 2022-09-02  Frank Ch. Eigler  <fche@redhat.com>
 
        * debuginfod_find_debuginfo.3: Tweaked debuginfod_get_headers docs.
index fecc6038df7544011dcb00d0dedee53b2c1aa190..53d82806d395dff72b78c4dfa3cd2d926adf1fd5 100644 (file)
@@ -75,6 +75,13 @@ only small files are downloaded. A value of 0 causes no consideration
 for size, and the client may attempt to download a file of any size.
 The default is 0 (infinite size).
 
+.TP
+.B $DEBUGINFOD_HEADERS_FILE
+This environment variable points to a file that supplies headers to
+outbound HTTP requests, one per line. The header lines shouldn't end with
+CRLF, unless that's the system newline convention. Whitespace-only lines
+are skipped.
+
 .SH CACHE
 
 Before each query, the debuginfod client library checks for a need to
index aebbec3f16dc1c6706351485d9b2d8ffe1c2e692..3dd832400ec60c04987a52d53f634fddbb8ca457 100644 (file)
@@ -188,12 +188,18 @@ indicates success, but out-of-memory conditions may result in
 a non-zero \fI-ENOMEM\fP. If the string is in the wrong form
 \fI-EINVAL\fP will be returned.
 
+\fI$DEBUGINFOD_HEADERS_FILE\fP specifies a file to supply headers to
+outgoing requests. Each non-whitespace line of this file is handled
+as if
+.BR \%debuginfod_add_http_header ()
+were called on the contents.
+
 Note that the current debuginfod-client library implementation uses
 libcurl, but you shouldn't rely on that fact. Don't use this function
 for replacing any standard headers, except for the User-Agent mentioned
-below. The only supported usage of this function is for adding an
-optional header which might or might not be passed through to the
-server for logging purposes only.
+below. You can use this function to add authorization information for
+access control, or to provide optional headers to the server for
+logging purposes.
 
 By default, the library adds a descriptive \fIUser-Agent:\fP
 header to outgoing requests.  If the client application adds