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