]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: add verb for dumping SMBIOS Type #11 data
authorLennart Poettering <lennart@poettering.net>
Sat, 11 May 2024 14:59:17 +0000 (16:59 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 12 Jun 2024 10:48:28 +0000 (12:48 +0200)
I find myself wanting to check this data with a quick command, and
browsing through /sys/ manually getting binary data sucks. Hence let's
do add a nice little analysis tool.

man/systemd-analyze.xml
src/analyze/analyze-smbios11.c [new file with mode: 0644]
src/analyze/analyze-smbios11.h [new file with mode: 0644]
src/analyze/analyze.c
src/analyze/meson.build
test/units/TEST-65-ANALYZE.sh

index 9a4b0cada41acd88b8a583ee1967ecf40fc7ac13..67c7e07778a6c2dda5fe03afd2cdf2921a407819 100644 (file)
       <arg choice="plain">architectures</arg>
       <arg choice="opt" rep="repeat"><replaceable>NAME</replaceable></arg>
     </cmdsynopsis>
+    <cmdsynopsis>
+      <command>systemd-analyze</command>
+      <arg choice="opt" rep="repeat">OPTIONS</arg>
+      <arg choice="plain">smbios11</arg>
+    </cmdsynopsis>
   </refsynopsisdiv>
 
   <refsect1>
@@ -979,6 +984,26 @@ x86-64      native</programlisting>
       </example>
     </refsect2>
 
+    <refsect2>
+      <title><command>systemd-analyze smbios11</command></title>
+
+      <para>Shows a list of SMBIOS Type #11 strings passed to the system. Also see
+      <citerefentry><refentrytitle>smbios-type-11</refentrytitle><manvolnum>7</manvolnum></citerefentry>.</para>
+
+      <example>
+        <title>Example output</title>
+        <programlisting>$ systemd-analyze smbios11
+io.systemd.stub.kernel-cmdline-extra=console=ttyS0
+io.systemd.credential.binary:ssh.ephemeral-authorized_keys-all=c3NoLWVkMjU1MTkgQUFBQUMzTnphQzFsWkRJMU5URTVBQUFBSURGd20xbFp4WlRGclJteG9ZQlozOTYzcE1uYlJCaDMwM1MxVXhLSUM2NmYgbGVubmFydEB6ZXRhCg==
+io.systemd.credential:vmm.notify_socket=vsock-stream:2:254570042
+
+3 SMBIOS Type #11 strings passed.
+</programlisting>
+      </example>
+
+      <xi:include href="version-info.xml" xpointer="v257"/>
+    </refsect2>
+
   </refsect1>
 
   <refsect1>
diff --git a/src/analyze/analyze-smbios11.c b/src/analyze/analyze-smbios11.c
new file mode 100644 (file)
index 0000000..cee5a3a
--- /dev/null
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "analyze.h"
+#include "analyze-smbios11.h"
+#include "escape.h"
+#include "smbios11.h"
+#include "virt.h"
+
+int verb_smbios11(int argc, char *argv[], void *userdata) {
+        unsigned n = 0;
+        int r;
+
+        for (unsigned i = 0;; i++) {
+                _cleanup_free_ char *data = NULL;
+                bool written = false;
+                size_t size;
+
+                r = read_smbios11_field(i, SIZE_MAX, &data, &size);
+                if (r == -ENOENT) /* Reached the end */
+                        break;
+                if (r < 0)
+                        return log_error_errno(r, "Failed to read SMBIOS Type #11 string %u: %m", i);
+                bool incomplete = r == 0;
+
+                size_t left, skip;
+                const char *p;
+                for (p = data, left = size; left > 0; p += skip, left -= skip) {
+                        const char *nul;
+
+                        nul = memchr(p, 0, left);
+                        if (nul)
+                                skip = (nul - p) + 1;
+                        else {
+                                nul = p + left;
+                                skip = left;
+                        }
+
+                        if (nul - p == 0) /* Skip empty strings */
+                                continue;
+
+                        _cleanup_free_ char *escaped = NULL;
+                        escaped = cescape_length(p, nul - p);
+                        if (!escaped)
+                                return log_oom();
+
+                        if (written)
+                                fputc('\n', stdout);
+
+                        fputs(escaped, stdout);
+                        written = true;
+                        n++;
+                }
+
+                if (written) {
+                        if (incomplete)
+                                fputs(special_glyph(SPECIAL_GLYPH_ELLIPSIS), stdout);
+
+                        fputc('\n', stdout);
+                }
+
+                if (i == UINT_MAX) /* Prevent overflow */
+                        break;
+        }
+
+        if (!arg_quiet) {
+                if (n == 0)
+                        log_info("No SMBIOS Type #11 strings passed.");
+                else
+                        log_info("\n%u SMBIOS Type #11 strings passed.", n);
+        }
+
+        return EXIT_SUCCESS;
+}
diff --git a/src/analyze/analyze-smbios11.h b/src/analyze/analyze-smbios11.h
new file mode 100644 (file)
index 0000000..4b1f334
--- /dev/null
@@ -0,0 +1,4 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#pragma once
+
+int verb_smbios11(int argc, char *argv[], void *userdata);
index cf4894a9d3bef362978b20afb06f195f94512015..db3996faea4451e111fc380ad7d49701bef3630a 100644 (file)
@@ -34,6 +34,7 @@
 #include "analyze-plot.h"
 #include "analyze-security.h"
 #include "analyze-service-watchdogs.h"
+#include "analyze-smbios11.h"
 #include "analyze-srk.h"
 #include "analyze-syscall-filter.h"
 #include "analyze-time.h"
@@ -241,6 +242,7 @@ static int help(int argc, char *argv[], void *userdata) {
                "  image-policy POLICY...     Analyze image policy string\n"
                "  pcrs [PCR...]              Show TPM2 PCRs and their names\n"
                "  srk [>FILE]                Write TPM2 SRK (to FILE)\n"
+               "  smbios11                   List strings passed via SMBIOS Type #11\n"
                "\nOptions:\n"
                "     --recursive-errors=MODE Control which units are verified\n"
                "     --offline=BOOL          Perform a security review on unit file(s)\n"
@@ -657,6 +659,7 @@ static int run(int argc, char *argv[]) {
                 { "pcrs",              VERB_ANY, VERB_ANY, 0,            verb_pcrs              },
                 { "srk",               VERB_ANY, 1,        0,            verb_srk               },
                 { "architectures",     VERB_ANY, VERB_ANY, 0,            verb_architectures     },
+                { "smbios11",          VERB_ANY, 1,        0,            verb_smbios11          },
                 {}
         };
 
index f150ed7613b558c43f4f6f5d702f10b5a83827eb..a307923c22eab12273d574aac1b3294c61a2f69b 100644 (file)
@@ -22,6 +22,7 @@ systemd_analyze_sources = files(
         'analyze-plot.c',
         'analyze-security.c',
         'analyze-service-watchdogs.c',
+        'analyze-smbios11.c',
         'analyze-srk.c',
         'analyze-syscall-filter.c',
         'analyze-time.c',
index 18f5c4d804a0adc302517fcfc1392d4936f806ea..fde15192f78af651d9226bc96c04884bd6e0d78b 100755 (executable)
@@ -947,6 +947,9 @@ systemd-analyze architectures x86-64
 systemd-analyze architectures native
 systemd-analyze architectures uname
 
+systemd-analyze smbios11
+systemd-analyze smbios11 -q
+
 systemd-analyze log-level info
 
 touch /testok