From b062ad86dcd33ab39be5060b0655d8e13834b167 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 12 May 2015 09:10:56 -0600 Subject: qemu-io: Use getopt() correctly POSIX says getopt() returns -1 on completion. While Linux happens to define EOF as -1, this definition is not required by POSIX, and there may be platforms where checking for EOF instead of -1 would lead to an infinite loop. Signed-off-by: Eric Blake Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- qemu-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'qemu-io.c') diff --git a/qemu-io.c b/qemu-io.c index 8e41080..ae5e274 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -120,7 +120,7 @@ static int open_f(BlockBackend *blk, int argc, char **argv) QemuOpts *qopts; QDict *opts; - while ((c = getopt(argc, argv, "snrgo:")) != EOF) { + while ((c = getopt(argc, argv, "snrgo:")) != -1) { switch (c) { case 's': flags |= BDRV_O_SNAPSHOT; -- cgit v1.1 From 8caf02127e92939fff39b63a7ff1a5834d320191 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 12 May 2015 17:09:21 +0100 Subject: qemu-io: prompt for encryption keys when required The qemu-io tool does not check if the image is encrypted so historically would silently corrupt the sectors by writing plain text data into them instead of cipher text. The earlier commit turns this mistake into a fatal abort, so check for encryption and prompt for key when required. This enables us to add unit tests to ensure we don't break the ability of qemu-img to convert existing encrypted qcow2 files into a non-encrypted format. Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- qemu-io.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'qemu-io.c') diff --git a/qemu-io.c b/qemu-io.c index ae5e274..9bc83c6 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -52,6 +52,7 @@ static const cmdinfo_t close_cmd = { static int openfile(char *name, int flags, QDict *opts) { Error *local_err = NULL; + BlockDriverState *bs; if (qemuio_blk) { fprintf(stderr, "file open already, try 'help close'\n"); @@ -68,7 +69,27 @@ static int openfile(char *name, int flags, QDict *opts) return 1; } + bs = blk_bs(qemuio_blk); + if (bdrv_is_encrypted(bs)) { + char password[256]; + printf("Disk image '%s' is encrypted.\n", name); + if (qemu_read_password(password, sizeof(password)) < 0) { + error_report("No password given"); + goto error; + } + if (bdrv_set_key(bs, password) < 0) { + error_report("invalid password"); + goto error; + } + } + + return 0; + + error: + blk_unref(qemuio_blk); + qemuio_blk = NULL; + return 1; } static void open_help(void) -- cgit v1.1