From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1GqGL4-0004kb-SF for qemu-devel@nongnu.org; Fri, 01 Dec 2006 16:54:34 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1GqGL3-0004j0-NV for qemu-devel@nongnu.org; Fri, 01 Dec 2006 16:54:34 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1GqGL3-0004ig-In for qemu-devel@nongnu.org; Fri, 01 Dec 2006 16:54:33 -0500 Received: from [64.233.182.187] (helo=nf-out-0910.google.com) by monty-python.gnu.org with esmtp (Exim 4.52) id 1GqGL3-0004OJ-7G for qemu-devel@nongnu.org; Fri, 01 Dec 2006 16:54:33 -0500 Received: by nf-out-0910.google.com with SMTP id c31so5807788nfb for ; Fri, 01 Dec 2006 13:54:31 -0800 (PST) From: "Andrzej Zaborowski" Date: Sat, 2 Dec 2006 00:55:57 +0100 Message-Id: <1165017357438-git-send-email-balrog@zabor.org> Sender: andrzej zaborowski Subject: [Qemu-devel] [PATCH] Handle encrypted usb stick images. Reply-To: balrogg@gmail.com, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel * Move asking for password to vl.c instead of duplicate code in vl.c and monitor.c; * Call the same code for usb mass storage; * Fix a typo where a char * pointer is compared against '\0'; --- hw/usb-msd.c | 2 ++ monitor.c | 12 +----------- vl.c | 35 ++++++++++++++++++++++------------- vl.h | 2 ++ 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/hw/usb-msd.c b/hw/usb-msd.c index 4530a1c..46aa234 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -522,6 +522,8 @@ USBDevice *usb_msd_init(const char *file bdrv = bdrv_new("usb"); if (bdrv_open(bdrv, filename, 0) < 0) goto fail; + if (qemu_key_check(bdrv, filename)) + goto fail; s->bs = bdrv; s->dev.speed = USB_SPEED_FULL; diff --git a/monitor.c b/monitor.c index f2a2417..ad4e018 100644 --- a/monitor.c +++ b/monitor.c @@ -337,8 +337,6 @@ static void do_eject(int force, const ch static void do_change(const char *device, const char *filename) { BlockDriverState *bs; - int i; - char password[256]; bs = bdrv_find(device); if (!bs) { @@ -348,15 +346,7 @@ static void do_change(const char *device if (eject_device(bs, 0) < 0) return; bdrv_open(bs, filename, 0); - if (bdrv_is_encrypted(bs)) { - term_printf("%s is encrypted.\n", device); - for(i = 0; i < 3; i++) { - monitor_readline("Password: ", 1, password, sizeof(password)); - if (bdrv_set_key(bs, password) == 0) - break; - term_printf("invalid password\n"); - } - } + qemu_key_check(bs, filename); } static void do_screen_dump(const char *filename) diff --git a/vl.c b/vl.c index 447da38..1ddedda 100644 --- a/vl.c +++ b/vl.c @@ -6108,6 +6108,24 @@ #endif /* password input */ +int qemu_key_check(BlockDriverState *bs, const char *name) +{ + char password[256]; + int i; + + if (!bdrv_is_encrypted(bs)) + return 0; + + term_printf("%s is encrypted.\n", name); + for(i = 0; i < 3; i++) { + monitor_readline("Password: ", 1, password, sizeof(password)); + if (bdrv_set_key(bs, password) == 0) + return 0; + term_printf("invalid password\n"); + } + return -EPERM; +} + static BlockDriverState *get_bdrv(int index) { BlockDriverState *bs; @@ -6125,21 +6143,12 @@ static BlockDriverState *get_bdrv(int in static void read_passwords(void) { BlockDriverState *bs; - int i, j; - char password[256]; + int i; for(i = 0; i < 6; i++) { bs = get_bdrv(i); - if (bs && bdrv_is_encrypted(bs)) { - term_printf("%s is encrypted.\n", bdrv_get_device_name(bs)); - for(j = 0; j < 3; j++) { - monitor_readline("Password: ", - 1, password, sizeof(password)); - if (bdrv_set_key(bs, password) == 0) - break; - term_printf("invalid password\n"); - } - } + if (bs) + qemu_key_check(bs, bdrv_get_device_name(bs)); } } @@ -6838,7 +6847,7 @@ #endif fd_table[i] = bdrv_new(buf); bdrv_set_type_hint(fd_table[i], BDRV_TYPE_FLOPPY); } - if (fd_filename[i] != '\0') { + if (fd_filename[i][0] != '\0') { if (bdrv_open(fd_table[i], fd_filename[i], snapshot ? BDRV_O_SNAPSHOT : 0) < 0) { fprintf(stderr, "qemu: could not open floppy disk image '%s'\n", diff --git a/vl.h b/vl.h index eedef51..124cda5 100644 --- a/vl.h +++ b/vl.h @@ -585,6 +585,8 @@ void qemu_aio_wait_start(void); void qemu_aio_wait(void); void qemu_aio_wait_end(void); +int qemu_key_check(BlockDriverState *bs, const char *name); + /* Ensure contents are flushed to disk. */ void bdrv_flush(BlockDriverState *bs); -- 1.4.3.2