[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).
This commit is contained in:
Adriaan de Groot 2021-11-02 21:52:13 +01:00
parent f0104af1c3
commit 85debfc69b
2 changed files with 43 additions and 0 deletions

View File

@ -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 << "<password>";
}
else
{
s << item;
}
}
else
{
s << l.list;
}
return s;
}
} // namespace Logger

View File

@ -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
*