diff options
author | Daniel Thornburgh <dthorn@google.com> | 2022-10-18 14:21:32 -0700 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2022-10-28 12:09:07 +0200 |
commit | 13f21dfb9bd09ad4816901ecd63daddc580a8465 (patch) | |
tree | 007d8ea8820df433cdb5810a7802f70127ce3355 /debuginfod | |
parent | 65b3fb51b83b5a37345c6a9ae7c77b2e9d3a6517 (diff) | |
download | elfutils-13f21dfb9bd09ad4816901ecd63daddc580a8465.tar.gz |
debuginfod-client: Add DEBUGINFOD_HEADERS_FILE.
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>
Diffstat (limited to 'debuginfod')
-rw-r--r-- | debuginfod/ChangeLog | 5 | ||||
-rw-r--r-- | debuginfod/debuginfod-client.c | 45 | ||||
-rw-r--r-- | debuginfod/debuginfod.h.in | 1 |
3 files changed, 51 insertions, 0 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog index 59d50df1..1df903fe 100644 --- a/debuginfod/ChangeLog +++ b/debuginfod/ChangeLog @@ -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. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 2a14d9d9..716cb769 100644 --- a/debuginfod/debuginfod-client.c +++ b/debuginfod/debuginfod-client.c @@ -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) { diff --git a/debuginfod/debuginfod.h.in b/debuginfod/debuginfod.h.in index 40b1ea00..7d8e4972 100644 --- a/debuginfod/debuginfod.h.in +++ b/debuginfod/debuginfod.h.in @@ -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@" |