qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "andrzej zaborowski" <balrog@zabor.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Remove repeated code, enable encrypted SD and USB sticks.
Date: Fri, 16 Mar 2007 22:03:21 +0100	[thread overview]
Message-ID: <fb249edb0703161403o4880ca3h264467d9f1af5085@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

Move the code that asks user for password for encrypted images, to one
places instead of having one copy in vl.c and a second one in
monitor.c. Make qemu use it for USB-mass-storage and SD cards too.

I posted this change earlier but without SD support.

Apply this on top of "[PATCH] SecureDigital card emulation".

Cheers,
Andrew

[-- Attachment #2: 0005-Remove-repeated-code-enable-encrypted-SD-and-USB-sticks.txt --]
[-- Type: text/plain, Size: 4019 bytes --]

From e8e50499eb4d1e2cda3cad3265cf8f925dfe520d Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <balrog@zabor.org>
Date: Fri, 16 Mar 2007 16:05:46 +0100
Subject: [PATCH] Remove repeated code, enable encrypted SD and USB sticks.

---
 hw/sd.c      |    2 ++
 hw/usb-msd.c |    2 ++
 monitor.c    |   12 +-----------
 vl.c         |   33 +++++++++++++++++++++------------
 vl.h         |    2 ++
 5 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/hw/sd.c b/hw/sd.c
index 37accde..f91054a 100644
--- a/hw/sd.c
+++ b/hw/sd.c
@@ -416,6 +416,8 @@ struct sd_state_s *sd_init()
                         snapshot ? BDRV_O_SNAPSHOT : 0) < 0)
             fprintf(stderr, "%s: Couldn't open %s\n",
                     __FUNCTION__, sd_filename);
+        else
+            qemu_key_check(bs, sd_filename);
     }
 
     sd = (struct sd_state_s *) qemu_mallocz(sizeof(struct sd_state_s));
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 *filename)
     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 943b25b..3f31904 100644
--- a/monitor.c
+++ b/monitor.c
@@ -380,8 +380,6 @@ static void do_eject(int force, const char *filename)
 static void do_change(const char *device, const char *filename)
 {
     BlockDriverState *bs;
-    int i;
-    char password[256];
 
     bs = bdrv_find(device);
     if (!bs) {
@@ -391,15 +389,7 @@ static void do_change(const char *device, const char *filename)
     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 e5b53d2..a22ef95 100644
--- a/vl.c
+++ b/vl.c
@@ -6705,6 +6705,24 @@ static uint8_t *signal_stack;
 
 /* 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;
@@ -6722,21 +6740,12 @@ static BlockDriverState *get_bdrv(int index)
 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));
     }
 }
 
diff --git a/vl.h b/vl.h
index cfafc08..453e78d 100644
--- a/vl.h
+++ b/vl.h
@@ -632,6 +632,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.4.3


                 reply	other threads:[~2007-03-16 21:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fb249edb0703161403o4880ca3h264467d9f1af5085@mail.gmail.com \
    --to=balrog@zabor.org \
    --cc=balrogg@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).