From: Martin George Date: Wed, 16 Oct 2024 07:56:55 +0000 (+0530) Subject: nvme: update tls_key() handling X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=2dd2870aa44a2183f36232ce324836fab3931ddc;p=users%2Fsagi%2Fnvme-cli.git nvme: update tls_key() handling Few misc issues in current tls_key() implementation: 1) Additional blank line printed in err message if the keyfile cannot be opened. 2) For export, nvme_scan_tls_keys() can return positive values too for successful scenarios. So this currently leads to erroneous return value handling. 3) For import, no return value checking for import_key() failure scenarios. 4) For revoke, return appropriate error immediately when nvme_revoke_tls_key() fails. 5) No helpful success message printed for all the options. Fix the same. Signed-off-by: Martin George --- diff --git a/nvme.c b/nvme.c index 3bb77bfc..0433c2cd 100644 --- a/nvme.c +++ b/nvme.c @@ -9515,7 +9515,7 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin fd = fopen(cfg.keyfile, mode); if (!fd) { - nvme_show_error("Cannot open keyfile %s, error %d\n", + nvme_show_error("Cannot open keyfile %s, error %d", cfg.keyfile, errno); return -errno; } @@ -9536,16 +9536,36 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin return -EINVAL; } else if (cfg.export) { err = nvme_scan_tls_keys(cfg.keyring, __scan_tls_key, fd); - if (err) + if (err < 0) { nvme_show_error("Export of TLS keys failed with '%s'", nvme_strerror(errno)); + return err; + } + + if (argconfig_parse_seen(opts, "verbose")) + printf("exporting to %s\n", cfg.keyfile); + + return 0; } else if (cfg.import) { err = import_key(cfg.keyring, fd); + if (err) { + nvme_show_error("Import of TLS keys failed with '%s'", + nvme_strerror(errno)); + return err; + } + + if (argconfig_parse_seen(opts, "verbose")) + printf("importing from %s\n", cfg.keyfile); } else { err = nvme_revoke_tls_key(cfg.keyring, cfg.keytype, cfg.revoke); - if (err) + if (err) { nvme_show_error("Failed to revoke key '%s'", nvme_strerror(errno)); + return err; + } + + if (argconfig_parse_seen(opts, "verbose")) + printf("revoking key\n"); } return err;