From 85debfc69b9ef0bdafbe3309a2cd8157091d4862 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 2 Nov 2021 21:52:13 +0100 Subject: [PATCH] [libcalamares] Add Redacted logging - this was an internal class for logging commands, let's lift it up to the Logger framework where it might be more generally useful (or not .. everything needs special-casing for actual redaction). --- src/libcalamares/utils/Logger.cpp | 24 ++++++++++++++++++++++++ src/libcalamares/utils/Logger.h | 19 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/libcalamares/utils/Logger.cpp b/src/libcalamares/utils/Logger.cpp index c83fea4ae..79ae873db 100644 --- a/src/libcalamares/utils/Logger.cpp +++ b/src/libcalamares/utils/Logger.cpp @@ -228,4 +228,28 @@ toString( const QVariant& v ) } } +QDebug& +operator<<( QDebug& s, const Redacted& l ) +{ + // Special case logging: don't log the (encrypted) password. + if ( l.list.contains( "usermod" ) ) + { + for ( const auto& item : l.list ) + if ( item.startsWith( "$6$" ) ) + { + s << ""; + } + else + { + s << item; + } + } + else + { + s << l.list; + } + + return s; +} + } // namespace Logger diff --git a/src/libcalamares/utils/Logger.h b/src/libcalamares/utils/Logger.h index 1fd534d04..bf6b99d00 100644 --- a/src/libcalamares/utils/Logger.h +++ b/src/libcalamares/utils/Logger.h @@ -207,6 +207,25 @@ public: const QVariantMap& map; }; +/** @brief When logging commands, don't log everything. + * + * The command-line arguments to some commands may contain the + * encrypted password set by the user. Don't log that password, + * since the log may get posted to bug reports, or stored in + * the target system. + */ +struct Redacted +{ + Redacted( const QStringList& l ) + : list( l ) + { + } + + const QStringList& list; +}; + +QDebug& operator<<( QDebug& s, const Redacted& l ); + /** * @brief Formatted logging of a pointer *