@@ -43,6 +43,7 @@ struct unixctl_command {
int min_args, max_args;
unixctl_cb_func *cb;
void *aux;
+ bool sensitive; /* Do not log the arguments. */
};
struct unixctl_conn {
@@ -215,9 +216,24 @@ unixctl_command_register(const char *name, const char *usage,
command->max_args = max_args;
command->cb = cb;
command->aux = aux;
+ command->sensitive = false;
shash_add(&commands, name, command);
}
+/* Like unixctl_command_register(), for a command whose arguments contain
+ * secrets, such as keys, that must not be logged. */
+void
+unixctl_command_register_sensitive(const char *name, const char *usage,
+ int min_args, int max_args,
+ unixctl_cb_func *cb, void *aux)
+{
+ struct unixctl_command *command;
+
+ unixctl_command_register(name, usage, min_args, max_args, cb, aux);
+ command = shash_find_data(&commands, name);
+ command->sensitive = true;
+}
+
enum unixctl_output_fmt
unixctl_command_get_output_format(struct unixctl_conn *conn)
{
@@ -376,8 +392,11 @@ process_command(struct unixctl_conn *conn, struct jsonrpc_msg *request)
COVERAGE_INC(unixctl_received);
conn->request_id = json_clone(request->id);
+ command = shash_find_data(&commands, request->method);
if (VLOG_IS_DBG_ENABLED()) {
- char *params_s = json_to_string(request->params, 0);
+ char *params_s = (command && command->sensitive
+ ? xstrdup("[<hidden>]")
+ : json_to_string(request->params, 0));
char *id_s = json_to_string(request->id, 0);
VLOG_DBG("received request %s%s, id=%s",
request->method, params_s, id_s);
@@ -386,7 +405,6 @@ process_command(struct unixctl_conn *conn, struct jsonrpc_msg *request)
}
params = request->params;
- command = shash_find_data(&commands, request->method);
if (!command) {
error = xasprintf("\"%s\" is not a valid command (use "
"\"list-commands\" to see a list of valid commands)",
@@ -56,6 +56,9 @@ typedef void unixctl_cb_func(struct unixctl_conn *,
void unixctl_command_register(const char *name, const char *usage,
int min_args, int max_args,
unixctl_cb_func *cb, void *aux);
+void unixctl_command_register_sensitive(const char *name, const char *usage,
+ int min_args, int max_args,
+ unixctl_cb_func *cb, void *aux);
enum unixctl_output_fmt unixctl_command_get_output_format(
struct unixctl_conn *);
void unixctl_command_reply_error(struct unixctl_conn *, const char *error);
With debug logging enabled, the unixctl server logs every request with its arguments. A command that receives secrets, such as encryption keys, must not have them logged. Add unixctl_command_register_sensitive() for such commands. Their arguments are logged as "[<hidden>]". A later patch, which adds the first such command, tests this. Assisted-by: claude-opus-5-5, Claude Code Signed-off-by: Thilak Raj Surendra Babu <s.thilakraj@gmail.com> --- lib/unixctl.c | 22 ++++++++++++++++++++-- lib/unixctl.h | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-)