Skip to content

Commit 2dd2870

Browse files
martin-gpyigaw
authored andcommitted
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 <marting@netapp.com>
1 parent 2ecd546 commit 2dd2870

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

nvme.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -9515,7 +9515,7 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
95159515

95169516
fd = fopen(cfg.keyfile, mode);
95179517
if (!fd) {
9518-
nvme_show_error("Cannot open keyfile %s, error %d\n",
9518+
nvme_show_error("Cannot open keyfile %s, error %d",
95199519
cfg.keyfile, errno);
95209520
return -errno;
95219521
}
@@ -9536,16 +9536,36 @@ static int tls_key(int argc, char **argv, struct command *command, struct plugin
95369536
return -EINVAL;
95379537
} else if (cfg.export) {
95389538
err = nvme_scan_tls_keys(cfg.keyring, __scan_tls_key, fd);
9539-
if (err)
9539+
if (err < 0) {
95409540
nvme_show_error("Export of TLS keys failed with '%s'",
95419541
nvme_strerror(errno));
9542+
return err;
9543+
}
9544+
9545+
if (argconfig_parse_seen(opts, "verbose"))
9546+
printf("exporting to %s\n", cfg.keyfile);
9547+
9548+
return 0;
95429549
} else if (cfg.import) {
95439550
err = import_key(cfg.keyring, fd);
9551+
if (err) {
9552+
nvme_show_error("Import of TLS keys failed with '%s'",
9553+
nvme_strerror(errno));
9554+
return err;
9555+
}
9556+
9557+
if (argconfig_parse_seen(opts, "verbose"))
9558+
printf("importing from %s\n", cfg.keyfile);
95449559
} else {
95459560
err = nvme_revoke_tls_key(cfg.keyring, cfg.keytype, cfg.revoke);
9546-
if (err)
9561+
if (err) {
95479562
nvme_show_error("Failed to revoke key '%s'",
95489563
nvme_strerror(errno));
9564+
return err;
9565+
}
9566+
9567+
if (argconfig_parse_seen(opts, "verbose"))
9568+
printf("revoking key\n");
95499569
}
95509570

95519571
return err;

0 commit comments

Comments
 (0)