* [Qemu-devel] [PATCH] Correct the password prompt management.
@ 2008-09-02 8:33 Laurent Vivier
2008-09-08 0:16 ` Anthony Liguori
0 siblings, 1 reply; 3+ messages in thread
From: Laurent Vivier @ 2008-09-02 8:33 UTC (permalink / raw)
To: qemu-devel@nongnu.org
This patch allows to provide a password for encrypted disks by moving
the password prompt after the monitor initialisation and by removing the
explicit start of the monitor command input.
The start of the command input is triggered by the term event
CHR_EVENT_RESET.
Moreover, during a password read, the term event CHR_EVENT_RESET is
ignored to avoid a reset to the command prompt and delayed after the end
of password input.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
---
monitor.c | 17 ++++++++++++++++-
vl.c | 19 ++++++-------------
2 files changed, 22 insertions(+), 14 deletions(-)
Index: qemu/monitor.c
===================================================================
--- qemu.orig/monitor.c 2008-09-02 09:46:53.000000000 +0200
+++ qemu/monitor.c 2008-09-02 10:14:38.000000000 +0200
@@ -69,6 +69,8 @@ typedef struct term_cmd_t {
#define MAX_MON 4
static CharDriverState *monitor_hd[MAX_MON];
static int hide_banner;
+static int read_password;
+static int need_reset;
static term_cmd_t term_cmds[];
static term_cmd_t info_cmds[];
@@ -2703,6 +2705,11 @@ static void term_event(void *opaque, int
if (event != CHR_EVENT_RESET)
return;
+ if (read_password) { /* ignore reset when reading password */
+ need_reset = 1;
+ return;
+ }
+
if (!hide_banner)
term_printf("QEMU %s monitor - type 'help' for more information
\n",
QEMU_VERSION);
@@ -2735,7 +2742,8 @@ void monitor_init(CharDriverState *hd, i
qemu_chr_add_handlers(hd, term_can_read, term_read, term_event,
NULL);
- readline_start("", 0, monitor_handle_command1, NULL);
+ read_password = 0;
+ need_reset = 0;
}
/* XXX: use threads ? */
@@ -2756,6 +2764,8 @@ void monitor_readline(const char *prompt
int i;
int old_focus[MAX_MON];
+ read_password = is_password;
+
if (is_password) {
for (i = 0; i < MAX_MON; i++) {
old_focus[i] = 0;
@@ -2779,5 +2789,10 @@ void monitor_readline(const char *prompt
for (i = 0; i < MAX_MON; i++)
if (old_focus[i])
monitor_hd[i]->focus = old_focus[i];
+ read_password = 0;
+ if (need_reset) {
+ term_event(NULL, CHR_EVENT_RESET);
+ need_reset = 0;
+ }
}
}
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c 2008-09-02 09:46:53.000000000 +0200
+++ qemu/vl.c 2008-09-02 10:04:38.000000000 +0200
@@ -5737,7 +5737,7 @@ static int drive_init(struct drive_opt *
bdrv_flags |= BDRV_O_SNAPSHOT;
if (!cache)
bdrv_flags |= BDRV_O_DIRECT;
- if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 ||
qemu_key_check(bdrv, file)) {
+ if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
fprintf(stderr, "qemu: could not open disk image %s\n",
file);
return -1;
@@ -8040,22 +8040,14 @@ int qemu_key_check(BlockDriverState *bs,
return -EPERM;
}
-static BlockDriverState *get_bdrv(int index)
-{
- if (index > nb_drives)
- return NULL;
- return drives_table[index].bdrv;
-}
-
static void read_passwords(void)
{
BlockDriverState *bs;
int i;
- for(i = 0; i < 6; i++) {
- bs = get_bdrv(i);
- if (bs)
- qemu_key_check(bs, bdrv_get_device_name(bs));
+ for(i = 0; i < nb_drives; i++) {
+ bs = drives_table[i].bdrv;
+ qemu_key_check(bs, bdrv_get_device_name(bs));
}
}
@@ -9199,12 +9191,13 @@ int main(int argc, char **argv)
}
#endif
+ read_passwords();
+
if (loadvm)
do_loadvm(loadvm);
{
/* XXX: simplify init */
- read_passwords();
if (autostart) {
vm_start();
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Correct the password prompt management.
2008-09-02 8:33 [Qemu-devel] [PATCH] Correct the password prompt management Laurent Vivier
@ 2008-09-08 0:16 ` Anthony Liguori
2008-09-08 7:43 ` Laurent Vivier
0 siblings, 1 reply; 3+ messages in thread
From: Anthony Liguori @ 2008-09-08 0:16 UTC (permalink / raw)
To: qemu-devel; +Cc: Laurent Vivier
Hi Laurent,
This patch is whitespace damaged..
Laurent Vivier wrote:
> if (!hide_banner)
> term_printf("QEMU %s monitor - type 'help' for more information
> \n",
>
Right here, for instance.
Regards,
Anthony Liguori
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] Correct the password prompt management.
2008-09-08 0:16 ` Anthony Liguori
@ 2008-09-08 7:43 ` Laurent Vivier
0 siblings, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2008-09-08 7:43 UTC (permalink / raw)
To: Anthony Liguori; +Cc: qemu-devel
[-- Attachment #1: Type: text/plain, Size: 534 bytes --]
Le dimanche 07 septembre 2008 à 19:16 -0500, Anthony Liguori a écrit :
> Hi Laurent,
>
> This patch is whitespace damaged..
>
> Laurent Vivier wrote:
> > if (!hide_banner)
> > term_printf("QEMU %s monitor - type 'help' for more information
> > \n",
> >
Sorry, find the good one attached.
Regards,
Laurent
--
----------------- Laurent.Vivier@bull.net ------------------
"La perfection est atteinte non quand il ne reste rien à
ajouter mais quand il ne reste rien à enlever." Saint Exupéry
[-- Attachment #2: qemu-encrypted.patch --]
[-- Type: text/x-patch, Size: 3792 bytes --]
Subject: Correct the password prompt management.
This patch allows to provide a password for encrypted disks by moving the
password prompt after the monitor initialisation and by removing the
explicit start of the monitor command input.
The start of the command input is triggered by the term event CHR_EVENT_RESET.
Moreover, during a password read, the term event CHR_EVENT_RESET is ignored
to avoid a reset to the command prompt and delayed after the end of password
input.
Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
---
monitor.c | 17 ++++++++++++++++-
vl.c | 19 ++++++-------------
2 files changed, 22 insertions(+), 14 deletions(-)
Index: qemu/monitor.c
===================================================================
--- qemu.orig/monitor.c 2008-09-04 16:27:30.000000000 +0200
+++ qemu/monitor.c 2008-09-08 09:35:17.000000000 +0200
@@ -69,6 +69,8 @@ typedef struct term_cmd_t {
#define MAX_MON 4
static CharDriverState *monitor_hd[MAX_MON];
static int hide_banner;
+static int read_password;
+static int need_reset;
static term_cmd_t term_cmds[];
static term_cmd_t info_cmds[];
@@ -2703,6 +2705,11 @@ static void term_event(void *opaque, int
if (event != CHR_EVENT_RESET)
return;
+ if (read_password) { /* ignore reset when reading password */
+ need_reset = 1;
+ return;
+ }
+
if (!hide_banner)
term_printf("QEMU %s monitor - type 'help' for more information\n",
QEMU_VERSION);
@@ -2735,7 +2742,8 @@ void monitor_init(CharDriverState *hd, i
qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
- readline_start("", 0, monitor_handle_command1, NULL);
+ read_password = 0;
+ need_reset = 0;
}
/* XXX: use threads ? */
@@ -2756,6 +2764,8 @@ void monitor_readline(const char *prompt
int i;
int old_focus[MAX_MON];
+ read_password = is_password;
+
if (is_password) {
for (i = 0; i < MAX_MON; i++) {
old_focus[i] = 0;
@@ -2779,5 +2789,10 @@ void monitor_readline(const char *prompt
for (i = 0; i < MAX_MON; i++)
if (old_focus[i])
monitor_hd[i]->focus = old_focus[i];
+ read_password = 0;
+ if (need_reset) {
+ term_event(NULL, CHR_EVENT_RESET);
+ need_reset = 0;
+ }
}
}
Index: qemu/vl.c
===================================================================
--- qemu.orig/vl.c 2008-09-05 11:17:44.000000000 +0200
+++ qemu/vl.c 2008-09-08 09:35:17.000000000 +0200
@@ -5737,7 +5737,7 @@ static int drive_init(struct drive_opt *
bdrv_flags |= BDRV_O_SNAPSHOT;
if (!cache)
bdrv_flags |= BDRV_O_DIRECT;
- if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 || qemu_key_check(bdrv, file)) {
+ if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
fprintf(stderr, "qemu: could not open disk image %s\n",
file);
return -1;
@@ -8039,22 +8039,14 @@ int qemu_key_check(BlockDriverState *bs,
return -EPERM;
}
-static BlockDriverState *get_bdrv(int index)
-{
- if (index > nb_drives)
- return NULL;
- return drives_table[index].bdrv;
-}
-
static void read_passwords(void)
{
BlockDriverState *bs;
int i;
- for(i = 0; i < 6; i++) {
- bs = get_bdrv(i);
- if (bs)
- qemu_key_check(bs, bdrv_get_device_name(bs));
+ for(i = 0; i < nb_drives; i++) {
+ bs = drives_table[i].bdrv;
+ qemu_key_check(bs, bdrv_get_device_name(bs));
}
}
@@ -9198,12 +9190,13 @@ int main(int argc, char **argv)
}
#endif
+ read_passwords();
+
if (loadvm)
do_loadvm(loadvm);
{
/* XXX: simplify init */
- read_passwords();
if (autostart) {
vm_start();
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-08 7:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-02 8:33 [Qemu-devel] [PATCH] Correct the password prompt management Laurent Vivier
2008-09-08 0:16 ` Anthony Liguori
2008-09-08 7:43 ` Laurent Vivier
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).