Commit 396f929762d10ba2c7b38f7e8a2276dd066be2d7

Authored by aliguori
1 parent ccf21c31

Ask password when encrypted disk image is used (Laurent Vivier)

This patch repairs the management of encrypted disk images and allows to
enter the password.

Changelog:
v2:
- move read_password() before do_loadvm()
- really start monitor if output is stdio.

Signed-off-by: Laurent Vivier <Laurent.Vivier@bull.net>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4976 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 3 changed files with 16 additions and 20 deletions
console.h
... ... @@ -160,6 +160,7 @@ extern uint8_t _translate_keycode(const int key);
160 160 does not need to include console.h */
161 161 /* monitor.c */
162 162 void monitor_init(CharDriverState *hd, int show_banner);
  163 +void monitor_start_input(void);
163 164 void term_puts(const char *str);
164 165 void term_vprintf(const char *fmt, va_list ap);
165 166 void term_printf(const char *fmt, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
... ...
monitor.c
... ... @@ -76,8 +76,6 @@ static term_cmd_t info_cmds[];
76 76 static uint8_t term_outbuf[1024];
77 77 static int term_outbuf_index;
78 78  
79   -static void monitor_start_input(void);
80   -
81 79 CPUState *mon_cpu = NULL;
82 80  
83 81 void term_flush(void)
... ... @@ -2659,15 +2657,13 @@ static void term_read(void *opaque, const uint8_t *buf, int size)
2659 2657 readline_handle_byte(buf[i]);
2660 2658 }
2661 2659  
2662   -static void monitor_start_input(void);
2663   -
2664 2660 static void monitor_handle_command1(void *opaque, const char *cmdline)
2665 2661 {
2666 2662 monitor_handle_command(cmdline);
2667 2663 monitor_start_input();
2668 2664 }
2669 2665  
2670   -static void monitor_start_input(void)
  2666 +void monitor_start_input(void)
2671 2667 {
2672 2668 readline_start("(qemu) ", 0, monitor_handle_command1, NULL);
2673 2669 }
... ... @@ -2708,8 +2704,6 @@ void monitor_init(CharDriverState *hd, int show_banner)
2708 2704 hide_banner = !show_banner;
2709 2705  
2710 2706 qemu_chr_add_handlers(hd, term_can_read, term_read, term_event, NULL);
2711   -
2712   - readline_start("", 0, monitor_handle_command1, NULL);
2713 2707 }
2714 2708  
2715 2709 /* XXX: use threads ? */
... ...
... ... @@ -5687,7 +5687,7 @@ static int drive_init(struct drive_opt *arg, int snapshot,
5687 5687 bdrv_flags |= BDRV_O_SNAPSHOT;
5688 5688 if (!cache)
5689 5689 bdrv_flags |= BDRV_O_DIRECT;
5690   - if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0 || qemu_key_check(bdrv, file)) {
  5690 + if (bdrv_open2(bdrv, file, bdrv_flags, drv) < 0) {
5691 5691 fprintf(stderr, "qemu: could not open disk image %s\n",
5692 5692 file);
5693 5693 return -1;
... ... @@ -7975,22 +7975,14 @@ int qemu_key_check(BlockDriverState *bs, const char *name)
7975 7975 return -EPERM;
7976 7976 }
7977 7977  
7978   -static BlockDriverState *get_bdrv(int index)
7979   -{
7980   - if (index > nb_drives)
7981   - return NULL;
7982   - return drives_table[index].bdrv;
7983   -}
7984   -
7985 7978 static void read_passwords(void)
7986 7979 {
7987 7980 BlockDriverState *bs;
7988 7981 int i;
7989 7982  
7990   - for(i = 0; i < 6; i++) {
7991   - bs = get_bdrv(i);
7992   - if (bs)
7993   - qemu_key_check(bs, bdrv_get_device_name(bs));
  7983 + for(i = 0; i < nb_drives; i++) {
  7984 + bs = drives_table[i].bdrv;
  7985 + qemu_key_check(bs, bdrv_get_device_name(bs));
7994 7986 }
7995 7987 }
7996 7988  
... ... @@ -8159,6 +8151,7 @@ int main(int argc, char **argv)
8159 8151 int optind;
8160 8152 const char *r, *optarg;
8161 8153 CharDriverState *monitor_hd;
  8154 + int has_monitor;
8162 8155 const char *monitor_device;
8163 8156 const char *serial_devices[MAX_SERIAL_PORTS];
8164 8157 int serial_device_index;
... ... @@ -9023,6 +9016,8 @@ int main(int argc, char **argv)
9023 9016 }
9024 9017  
9025 9018 /* Maintain compatibility with multiple stdio monitors */
  9019 +
  9020 + has_monitor = 0;
9026 9021 if (!strcmp(monitor_device,"stdio")) {
9027 9022 for (i = 0; i < MAX_SERIAL_PORTS; i++) {
9028 9023 const char *devname = serial_devices[i];
... ... @@ -9035,6 +9030,7 @@ int main(int argc, char **argv)
9035 9030 break;
9036 9031 }
9037 9032 }
  9033 + has_monitor = 1;
9038 9034 }
9039 9035 if (monitor_device) {
9040 9036 monitor_hd = qemu_chr_open(monitor_device);
... ... @@ -9043,6 +9039,7 @@ int main(int argc, char **argv)
9043 9039 exit(1);
9044 9040 }
9045 9041 monitor_init(monitor_hd, !nographic);
  9042 + has_monitor = 1;
9046 9043 }
9047 9044  
9048 9045 for(i = 0; i < MAX_SERIAL_PORTS; i++) {
... ... @@ -9103,12 +9100,16 @@ int main(int argc, char **argv)
9103 9100 }
9104 9101 #endif
9105 9102  
  9103 + read_passwords();
  9104 +
  9105 + if (has_monitor)
  9106 + monitor_start_input();
  9107 +
9106 9108 if (loadvm)
9107 9109 do_loadvm(loadvm);
9108 9110  
9109 9111 {
9110 9112 /* XXX: simplify init */
9111   - read_passwords();
9112 9113 if (autostart) {
9113 9114 vm_start();
9114 9115 }
... ...