mirror of https://github.com/xqemu/xqemu.git
Remove repeated code and enable encrypted SD cards and USB sticks images.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2750 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
c1713132e0
commit
2bac601963
|
@ -522,6 +522,8 @@ USBDevice *usb_msd_init(const char *filename)
|
||||||
bdrv = bdrv_new("usb");
|
bdrv = bdrv_new("usb");
|
||||||
if (bdrv_open(bdrv, filename, 0) < 0)
|
if (bdrv_open(bdrv, filename, 0) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
if (qemu_key_check(bdrv, filename))
|
||||||
|
goto fail;
|
||||||
s->bs = bdrv;
|
s->bs = bdrv;
|
||||||
|
|
||||||
s->dev.speed = USB_SPEED_FULL;
|
s->dev.speed = USB_SPEED_FULL;
|
||||||
|
|
12
monitor.c
12
monitor.c
|
@ -386,8 +386,6 @@ static void do_eject(int force, const char *filename)
|
||||||
static void do_change(const char *device, const char *filename)
|
static void do_change(const char *device, const char *filename)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
int i;
|
|
||||||
char password[256];
|
|
||||||
|
|
||||||
bs = bdrv_find(device);
|
bs = bdrv_find(device);
|
||||||
if (!bs) {
|
if (!bs) {
|
||||||
|
@ -397,15 +395,7 @@ static void do_change(const char *device, const char *filename)
|
||||||
if (eject_device(bs, 0) < 0)
|
if (eject_device(bs, 0) < 0)
|
||||||
return;
|
return;
|
||||||
bdrv_open(bs, filename, 0);
|
bdrv_open(bs, filename, 0);
|
||||||
if (bdrv_is_encrypted(bs)) {
|
qemu_key_check(bs, filename);
|
||||||
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_screen_dump(const char *filename)
|
static void do_screen_dump(const char *filename)
|
||||||
|
|
38
vl.c
38
vl.c
|
@ -6714,6 +6714,24 @@ static uint8_t *signal_stack;
|
||||||
|
|
||||||
/* password input */
|
/* 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)
|
static BlockDriverState *get_bdrv(int index)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
|
@ -6731,21 +6749,12 @@ static BlockDriverState *get_bdrv(int index)
|
||||||
static void read_passwords(void)
|
static void read_passwords(void)
|
||||||
{
|
{
|
||||||
BlockDriverState *bs;
|
BlockDriverState *bs;
|
||||||
int i, j;
|
int i;
|
||||||
char password[256];
|
|
||||||
|
|
||||||
for(i = 0; i < 6; i++) {
|
for(i = 0; i < 6; i++) {
|
||||||
bs = get_bdrv(i);
|
bs = get_bdrv(i);
|
||||||
if (bs && bdrv_is_encrypted(bs)) {
|
if (bs)
|
||||||
term_printf("%s is encrypted.\n", bdrv_get_device_name(bs));
|
qemu_key_check(bs, 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7622,7 +7631,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open the virtual parallel flash bloc devices */
|
/* Open the virtual parallel flash block devices */
|
||||||
for(i = 0; i < MAX_PFLASH; i++) {
|
for(i = 0; i < MAX_PFLASH; i++) {
|
||||||
if (pflash_filename[i]) {
|
if (pflash_filename[i]) {
|
||||||
if (!pflash_table[i]) {
|
if (!pflash_table[i]) {
|
||||||
|
@ -7648,7 +7657,8 @@ int main(int argc, char **argv)
|
||||||
snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
|
snapshot ? BDRV_O_SNAPSHOT : 0) < 0) {
|
||||||
fprintf(stderr, "qemu: could not open SD card image %s\n",
|
fprintf(stderr, "qemu: could not open SD card image %s\n",
|
||||||
sd_filename);
|
sd_filename);
|
||||||
}
|
} else
|
||||||
|
qemu_key_check(bs, sd_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
|
register_savevm("timer", 0, 2, timer_save, timer_load, NULL);
|
||||||
|
|
2
vl.h
2
vl.h
|
@ -632,6 +632,8 @@ void qemu_aio_wait_start(void);
|
||||||
void qemu_aio_wait(void);
|
void qemu_aio_wait(void);
|
||||||
void qemu_aio_wait_end(void);
|
void qemu_aio_wait_end(void);
|
||||||
|
|
||||||
|
int qemu_key_check(BlockDriverState *bs, const char *name);
|
||||||
|
|
||||||
/* Ensure contents are flushed to disk. */
|
/* Ensure contents are flushed to disk. */
|
||||||
void bdrv_flush(BlockDriverState *bs);
|
void bdrv_flush(BlockDriverState *bs);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue