summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@redhat.com>2020-01-06 04:29:21 -0500
committerFrank Ch. Eigler <fche@redhat.com>2020-01-06 04:55:38 -0500
commitadbb21fb59fd46a3f1af25d00d0327d2b411f302 (patch)
treef77f2af77fc25764f4dab8cf78789644d6352303
parent785c8abdf40f52aa55c24aa1b8918461be3c625f (diff)
debuginfod: pass a distro-summary User-Agent request header
It may be useful for a debuginfod server operator to know what kinds of clients make webapi requests. This is mainly as a telemetry/diagnostic (though the data cannot be really trusted). It may also be useful to automate downloading of distro packages to a debuginfod server in the case of an unknown hex buildid. doc/testing not affected as these are diagnostics.
-rw-r--r--debuginfod/ChangeLog7
-rw-r--r--debuginfod/Makefile.am16
-rw-r--r--debuginfod/debuginfod-client.c3
-rw-r--r--debuginfod/debuginfod-find.c2
-rw-r--r--debuginfod/debuginfod.cxx9
5 files changed, 32 insertions, 5 deletions
diff --git a/debuginfod/ChangeLog b/debuginfod/ChangeLog
index 9888868b..49a7c26c 100644
--- a/debuginfod/ChangeLog
+++ b/debuginfod/ChangeLog
@@ -1,3 +1,10 @@
+2020-01-06 Frank Ch. Eigler <fche@redhat.com>
+
+ * Makefile.am: Create a build-time header with lsb/uname info.
+ * debuginfod-client.c: Pass above as additional User-Agent request header.
+ * debuginfod.cxx (conninfo): Print this and X-Forwarded-For, as per
+ apache httpd reverse-proxy chain.
+
2019-12-31 Frank Ch. Eigler <fche@redhat.com>
* debuginfod.cxx: Rework threading model.
diff --git a/debuginfod/Makefile.am b/debuginfod/Makefile.am
index 52ead30a..20a70545 100644
--- a/debuginfod/Makefile.am
+++ b/debuginfod/Makefile.am
@@ -67,6 +67,20 @@ debuginfod_find_LDADD = $(libeu) $(libdebuginfod)
noinst_LIBRARIES = libdebuginfod.a
noinst_LIBRARIES += libdebuginfod_pic.a
+debuginfod-client-useragent.h:
+ if type uname 2>/dev/null; then \
+ echo '#define DEBUGINFOD_CLIENT_USERAGENT_1 "'`uname -sm | sed -e 's, ,/,g'`'"' > $@; \
+ else \
+ echo '#define DEBUGINFOD_CLIENT_USERAGENT_1 ""' > $@; \
+ fi
+ if type lsb_release 2>/dev/null; then \
+ echo '#define DEBUGINFOD_CLIENT_USERAGENT_2 "'`lsb_release -sir | sed -e 's, ,/,g'`'"' >> $@; \
+ else \
+ echo '#define DEBUGINFOD_CLIENT_USERAGENT_2 ""' > $@; \
+ fi
+ echo '#define DEBUGINFOD_CLIENT_USERAGENT DEBUGINFOD_CLIENT_USERAGENT_1 "," DEBUGINFOD_CLIENT_USERAGENT_2' >> $@
+
+libdebuginfod: debuginfod-client-useragent.h
libdebuginfod_a_SOURCES = debuginfod-client.c
libdebuginfod_pic_a_SOURCES = debuginfod-client.c
am_libdebuginfod_pic_a_OBJECTS = $(libdebuginfod_a_SOURCES:.c=.os)
@@ -98,7 +112,7 @@ uninstall: uninstall-am
EXTRA_DIST = libdebuginfod.map
MOSTLYCLEANFILES = $(am_libdebuginfod_pic_a_OBJECTS) libdebuginfod.so.$(VERSION)
-CLEANFILES += $(am_libdebuginfod_pic_a_OBJECTS) libdebuginfod.so
+CLEANFILES += $(am_libdebuginfod_pic_a_OBJECTS) libdebuginfod.so debuginfod-client-useragent.h
# automake std-options override: arrange to pass LD_LIBRARY_PATH
installcheck-binPROGRAMS: $(bin_PROGRAMS)
diff --git a/debuginfod/debuginfod-client.c b/debuginfod/debuginfod-client.c
index 9a4a0e0f..3c361002 100644
--- a/debuginfod/debuginfod-client.c
+++ b/debuginfod/debuginfod-client.c
@@ -40,6 +40,7 @@
#include "config.h"
#include "debuginfod.h"
+#include "debuginfod-client-useragent.h"
#include "system.h"
#include <assert.h>
#include <dirent.h>
@@ -514,7 +515,7 @@ debuginfod_query_server (debuginfod_client *c,
curl_easy_setopt(data[i].handle, CURLOPT_NOSIGNAL, (long) 1);
curl_easy_setopt(data[i].handle, CURLOPT_AUTOREFERER, (long) 1);
curl_easy_setopt(data[i].handle, CURLOPT_ACCEPT_ENCODING, "");
- curl_easy_setopt(data[i].handle, CURLOPT_USERAGENT, (void*) PACKAGE_STRING);
+ curl_easy_setopt(data[i].handle, CURLOPT_USERAGENT, (void*) PACKAGE_NAME "/" PACKAGE_VERSION "," DEBUGINFOD_CLIENT_USERAGENT);
curl_multi_add_handle(curlm, data[i].handle);
server_url = strtok_r(NULL, url_delim, &strtok_saveptr);
diff --git a/debuginfod/debuginfod-find.c b/debuginfod/debuginfod-find.c
index 8bd3a3db..fc7c373c 100644
--- a/debuginfod/debuginfod-find.c
+++ b/debuginfod/debuginfod-find.c
@@ -1,6 +1,6 @@
/* Command-line frontend for retrieving ELF / DWARF / source files
from the debuginfod.
- Copyright (C) 2019 Red Hat, Inc.
+ Copyright (C) 2019-2020 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 4482af71..45b2d7a7 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -1,5 +1,5 @@
/* Debuginfo-over-http server.
- Copyright (C) 2019 Red Hat, Inc.
+ Copyright (C) 2019-2020 Red Hat, Inc.
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
@@ -783,7 +783,12 @@ conninfo (struct MHD_Connection * conn)
hostname[0] = servname[0] = '\0';
}
- return string(hostname) + string(":") + string(servname);
+ // extract headers relevant to administration
+ const char* user_agent = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "User-Agent") ?: "";
+ const char* x_forwarded_for = MHD_lookup_connection_value (conn, MHD_HEADER_KIND, "X-Forwarded-For") ?: "";
+ // NB: these are untrustworthy, beware if machine-processing log files
+
+ return string(hostname) + string(":") + string(servname) + string(" UA:") + string(user_agent) + string(" XFF:") + string(x_forwarded_for);
}