From patchwork Tue Oct 18 21:21:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Thornburgh X-Patchwork-Id: 59019 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41C953858282 for ; Tue, 18 Oct 2022 21:21:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41C953858282 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666128106; bh=vR68IUIinWBMmzXDtlmi4MkOQLz9NSS4jOapQLvEBGQ=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Help: List-Subscribe:From:Reply-To:Cc:From; b=iNpboWhfNMwe8LJ8WopY8WlhCVrKaRctp4A5ueyWDR+KdMzgKFscDEh6GeZKY1g+K 4uTIELkBxotC0N8ezoAdeIKUPUe8rcLNK4pik1qS4jJ3ID/R9nNOvJf5C7vxz2Pxjm kqrOrcmKeRaxbpfKFxcPDAMCd2pf7esFG/YEqcDo= X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by sourceware.org (Postfix) with ESMTPS id A8D1F3858D32 for ; Tue, 18 Oct 2022 21:21:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A8D1F3858D32 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-3538689fc60so150924407b3.3 for ; Tue, 18 Oct 2022 14:21:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vR68IUIinWBMmzXDtlmi4MkOQLz9NSS4jOapQLvEBGQ=; b=AJvRxdQacv0bunvyIIsrX++TgZ+ffwYLFYmiFDwCoPldQmOovo52L1MeqqRkjChiCn dXAinXZTLY6Q8/A0uCD70ETyBmcyNEzR8EcspGYUHSBnhRo4TV5XATxQS0V3dOneJ0BL qRHHOfvUpN0Xge4CyCDVwqHY1z3QiIg5Hq45LpjAP4/zvIxRIyxbwEtUkqkeyqY4s6Qt MoWijdUd0sBGX7MQpnD1DagW6SFY7voWaOooJyiv7GZx84bAfaR6koQmzwerTYrHV4z0 GKHwqcVGxMTJX5l5XfgfwayOzI6np/EUyXG4doJ6SlEPMQmhz8RWvQVp1a27sXlN+pvR WRIw== X-Gm-Message-State: ACrzQf349NqM3wZ+xOgIhb+GEgdqa27Gxc+/k7z5E13do1bhKelbXDLa ZpazRcxiUWArO3oOYo235x5U/XxnmzP4hx4B09UYD4oyuWSFGvbEouL+AAYeFGugDtVeTYzjB4t Cdvi5xLEyd1MUUys5SmGX22F7IibURPXurefDEK9DnGncu4YP4U23kfCh4Jyw7nNU3d5Yf3Y= X-Google-Smtp-Source: AMsMyM5BOUdPpLvFA+6riiQcQSCReZHuftVcWtnu+AZRd+/nC9TBY2ypkOHWQX8/M3AGR6DzSRwvufwqD6Y= X-Received: from lore.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:2142]) (user=dthorn job=sendgmr) by 2002:a25:4942:0:b0:6bd:29b0:3ed8 with SMTP id w63-20020a254942000000b006bd29b03ed8mr4315048yba.79.1666128095070; Tue, 18 Oct 2022 14:21:35 -0700 (PDT) Date: Tue, 18 Oct 2022 14:21:32 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221018212132.53883-1-dthorn@google.com> Subject: [PATCH] debuginfod-client: Add DEBUGINFOD_HEADERS_FILE. To: elfutils-devel@sourceware.org X-Spam-Status: No, score=-18.2 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-Patchwork-Original-From: Daniel Thornburgh via Elfutils-devel From: Daniel Thornburgh Reply-To: Daniel Thornburgh Cc: Daniel Thornburgh Errors-To: elfutils-devel-bounces+patchwork=sourceware.org@sourceware.org Sender: "Elfutils-devel" 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 --- NEWS | 3 +++ debuginfod/ChangeLog | 5 ++++ debuginfod/debuginfod-client.c | 44 +++++++++++++++++++++++++++++++++ debuginfod/debuginfod.h.in | 1 + doc/ChangeLog | 4 +++ doc/debuginfod-client-config.7 | 7 ++++++ doc/debuginfod_find_debuginfo.3 | 12 ++++++--- 7 files changed, 73 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 6ebd172c..3df652e3 100644 --- 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. 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 + + * debuginfod-client.c (debuginfod_query_server): Add DEBUGINFOD_HEADERS_FILE + setting to supply outgoing HTTP headers. + 2022-10-17 Frank Ch. Eigler * debuginfod.cxx (main): Report libmicrohttpd version. diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c index 2a14d9d9..549520c1 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 #include #include @@ -447,6 +448,44 @@ 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) + { + 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) + dprintf(vds, "skipping bad header: %s\n", strerror(-rc)); + } + fclose (f); +} + #define xalloc_str(p, fmt, args...) \ do \ @@ -610,6 +649,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@" diff --git a/doc/ChangeLog b/doc/ChangeLog index b2bb4890..073023b4 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,7 @@ +2022-10-18 Daniel Thornburgh + + * debuginfod_find_debuginfo.3: Document DEBUGINFOD_HEADERS_FILE. + 2022-09-02 Frank Ch. Eigler * debuginfod_find_debuginfo.3: Tweaked debuginfod_get_headers docs. diff --git a/doc/debuginfod-client-config.7 b/doc/debuginfod-client-config.7 index fecc6038..53d82806 100644 --- a/doc/debuginfod-client-config.7 +++ b/doc/debuginfod-client-config.7 @@ -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 diff --git a/doc/debuginfod_find_debuginfo.3 b/doc/debuginfod_find_debuginfo.3 index aebbec3f..3dd83240 100644 --- a/doc/debuginfod_find_debuginfo.3 +++ b/doc/debuginfod_find_debuginfo.3 @@ -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