Commit 5905b2e5fd051b046bf531c9b251fd6559145497
1 parent
7e2515e8
password input support
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1035 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
87 additions
and
36 deletions
vl.c
@@ -982,6 +982,12 @@ void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) | @@ -982,6 +982,12 @@ void qemu_chr_printf(CharDriverState *s, const char *fmt, ...) | ||
982 | va_end(ap); | 982 | va_end(ap); |
983 | } | 983 | } |
984 | 984 | ||
985 | +void qemu_chr_send_event(CharDriverState *s, int event) | ||
986 | +{ | ||
987 | + if (s->chr_send_event) | ||
988 | + s->chr_send_event(s, event); | ||
989 | +} | ||
990 | + | ||
985 | void qemu_chr_add_read_handler(CharDriverState *s, | 991 | void qemu_chr_add_read_handler(CharDriverState *s, |
986 | IOCanRWHandler *fd_can_read, | 992 | IOCanRWHandler *fd_can_read, |
987 | IOReadHandler *fd_read, void *opaque) | 993 | IOReadHandler *fd_read, void *opaque) |
@@ -2179,7 +2185,7 @@ static void main_cpu_reset(void *opaque) | @@ -2179,7 +2185,7 @@ static void main_cpu_reset(void *opaque) | ||
2179 | #endif | 2185 | #endif |
2180 | } | 2186 | } |
2181 | 2187 | ||
2182 | -int main_loop(void) | 2188 | +void main_loop_wait(int timeout) |
2183 | { | 2189 | { |
2184 | #ifndef _WIN32 | 2190 | #ifndef _WIN32 |
2185 | struct pollfd ufds[MAX_IO_HANDLERS + 1], *pf; | 2191 | struct pollfd ufds[MAX_IO_HANDLERS + 1], *pf; |
@@ -2187,39 +2193,12 @@ int main_loop(void) | @@ -2187,39 +2193,12 @@ int main_loop(void) | ||
2187 | uint8_t buf[4096]; | 2193 | uint8_t buf[4096]; |
2188 | int n, max_size; | 2194 | int n, max_size; |
2189 | #endif | 2195 | #endif |
2190 | - int ret, timeout; | ||
2191 | - CPUState *env = global_env; | ||
2192 | - | ||
2193 | - for(;;) { | ||
2194 | - if (vm_running) { | ||
2195 | - ret = cpu_exec(env); | ||
2196 | - if (shutdown_requested) { | ||
2197 | - ret = EXCP_INTERRUPT; | ||
2198 | - break; | ||
2199 | - } | ||
2200 | - if (reset_requested) { | ||
2201 | - reset_requested = 0; | ||
2202 | - qemu_system_reset(); | ||
2203 | - ret = EXCP_INTERRUPT; | ||
2204 | - } | ||
2205 | - if (ret == EXCP_DEBUG) { | ||
2206 | - vm_stop(EXCP_DEBUG); | ||
2207 | - } | ||
2208 | - /* if hlt instruction, we wait until the next IRQ */ | ||
2209 | - /* XXX: use timeout computed from timers */ | ||
2210 | - if (ret == EXCP_HLT) | ||
2211 | - timeout = 10; | ||
2212 | - else | ||
2213 | - timeout = 0; | ||
2214 | - } else { | ||
2215 | - timeout = 10; | ||
2216 | - } | 2196 | + int ret; |
2217 | 2197 | ||
2218 | #ifdef _WIN32 | 2198 | #ifdef _WIN32 |
2219 | if (timeout > 0) | 2199 | if (timeout > 0) |
2220 | Sleep(timeout); | 2200 | Sleep(timeout); |
2221 | #else | 2201 | #else |
2222 | - | ||
2223 | /* poll any events */ | 2202 | /* poll any events */ |
2224 | /* XXX: separate device handlers from system ones */ | 2203 | /* XXX: separate device handlers from system ones */ |
2225 | pf = ufds; | 2204 | pf = ufds; |
@@ -2269,7 +2248,7 @@ int main_loop(void) | @@ -2269,7 +2248,7 @@ int main_loop(void) | ||
2269 | } | 2248 | } |
2270 | } | 2249 | } |
2271 | } | 2250 | } |
2272 | - | 2251 | +#endif /* !defined(_WIN32) */ |
2273 | #if defined(CONFIG_SLIRP) | 2252 | #if defined(CONFIG_SLIRP) |
2274 | /* XXX: merge with poll() */ | 2253 | /* XXX: merge with poll() */ |
2275 | if (slirp_inited) { | 2254 | if (slirp_inited) { |
@@ -2291,8 +2270,6 @@ int main_loop(void) | @@ -2291,8 +2270,6 @@ int main_loop(void) | ||
2291 | } | 2270 | } |
2292 | #endif | 2271 | #endif |
2293 | 2272 | ||
2294 | -#endif | ||
2295 | - | ||
2296 | if (vm_running) { | 2273 | if (vm_running) { |
2297 | qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], | 2274 | qemu_run_timers(&active_timers[QEMU_TIMER_VIRTUAL], |
2298 | qemu_get_clock(vm_clock)); | 2275 | qemu_get_clock(vm_clock)); |
@@ -2309,6 +2286,38 @@ int main_loop(void) | @@ -2309,6 +2286,38 @@ int main_loop(void) | ||
2309 | /* real time timers */ | 2286 | /* real time timers */ |
2310 | qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], | 2287 | qemu_run_timers(&active_timers[QEMU_TIMER_REALTIME], |
2311 | qemu_get_clock(rt_clock)); | 2288 | qemu_get_clock(rt_clock)); |
2289 | +} | ||
2290 | + | ||
2291 | +int main_loop(void) | ||
2292 | +{ | ||
2293 | + int ret, timeout; | ||
2294 | + CPUState *env = global_env; | ||
2295 | + | ||
2296 | + for(;;) { | ||
2297 | + if (vm_running) { | ||
2298 | + ret = cpu_exec(env); | ||
2299 | + if (shutdown_requested) { | ||
2300 | + ret = EXCP_INTERRUPT; | ||
2301 | + break; | ||
2302 | + } | ||
2303 | + if (reset_requested) { | ||
2304 | + reset_requested = 0; | ||
2305 | + qemu_system_reset(); | ||
2306 | + ret = EXCP_INTERRUPT; | ||
2307 | + } | ||
2308 | + if (ret == EXCP_DEBUG) { | ||
2309 | + vm_stop(EXCP_DEBUG); | ||
2310 | + } | ||
2311 | + /* if hlt instruction, we wait until the next IRQ */ | ||
2312 | + /* XXX: use timeout computed from timers */ | ||
2313 | + if (ret == EXCP_HLT) | ||
2314 | + timeout = 10; | ||
2315 | + else | ||
2316 | + timeout = 0; | ||
2317 | + } else { | ||
2318 | + timeout = 10; | ||
2319 | + } | ||
2320 | + main_loop_wait(timeout); | ||
2312 | } | 2321 | } |
2313 | cpu_disable_ticks(); | 2322 | cpu_disable_ticks(); |
2314 | return ret; | 2323 | return ret; |
@@ -2509,6 +2518,43 @@ static uint8_t *signal_stack; | @@ -2509,6 +2518,43 @@ static uint8_t *signal_stack; | ||
2509 | 2518 | ||
2510 | #endif | 2519 | #endif |
2511 | 2520 | ||
2521 | +/* password input */ | ||
2522 | + | ||
2523 | +static BlockDriverState *get_bdrv(int index) | ||
2524 | +{ | ||
2525 | + BlockDriverState *bs; | ||
2526 | + | ||
2527 | + if (index < 4) { | ||
2528 | + bs = bs_table[index]; | ||
2529 | + } else if (index < 6) { | ||
2530 | + bs = fd_table[index - 4]; | ||
2531 | + } else { | ||
2532 | + bs = NULL; | ||
2533 | + } | ||
2534 | + return bs; | ||
2535 | +} | ||
2536 | + | ||
2537 | +static void read_passwords(void) | ||
2538 | +{ | ||
2539 | + BlockDriverState *bs; | ||
2540 | + int i, j; | ||
2541 | + char password[256]; | ||
2542 | + | ||
2543 | + for(i = 0; i < 6; i++) { | ||
2544 | + bs = get_bdrv(i); | ||
2545 | + if (bs && bdrv_is_encrypted(bs)) { | ||
2546 | + term_printf("%s is encrypted.\n", bdrv_get_device_name(bs)); | ||
2547 | + for(j = 0; j < 3; j++) { | ||
2548 | + monitor_readline("Password: ", | ||
2549 | + 1, password, sizeof(password)); | ||
2550 | + if (bdrv_set_key(bs, password) == 0) | ||
2551 | + break; | ||
2552 | + term_printf("invalid password\n"); | ||
2553 | + } | ||
2554 | + } | ||
2555 | + } | ||
2556 | +} | ||
2557 | + | ||
2512 | #define NET_IF_TUN 0 | 2558 | #define NET_IF_TUN 0 |
2513 | #define NET_IF_USER 1 | 2559 | #define NET_IF_USER 1 |
2514 | #define NET_IF_DUMMY 2 | 2560 | #define NET_IF_DUMMY 2 |
@@ -2952,6 +2998,7 @@ int main(int argc, char **argv) | @@ -2952,6 +2998,7 @@ int main(int argc, char **argv) | ||
2952 | #endif | 2998 | #endif |
2953 | 2999 | ||
2954 | /* we always create the cdrom drive, even if no disk is there */ | 3000 | /* we always create the cdrom drive, even if no disk is there */ |
3001 | + bdrv_init(); | ||
2955 | if (has_cdrom) { | 3002 | if (has_cdrom) { |
2956 | bs_table[2] = bdrv_new("cdrom"); | 3003 | bs_table[2] = bdrv_new("cdrom"); |
2957 | bdrv_set_type_hint(bs_table[2], BDRV_TYPE_CDROM); | 3004 | bdrv_set_type_hint(bs_table[2], BDRV_TYPE_CDROM); |
@@ -2966,7 +3013,7 @@ int main(int argc, char **argv) | @@ -2966,7 +3013,7 @@ int main(int argc, char **argv) | ||
2966 | bs_table[i] = bdrv_new(buf); | 3013 | bs_table[i] = bdrv_new(buf); |
2967 | } | 3014 | } |
2968 | if (bdrv_open(bs_table[i], hd_filename[i], snapshot) < 0) { | 3015 | if (bdrv_open(bs_table[i], hd_filename[i], snapshot) < 0) { |
2969 | - fprintf(stderr, "qemu: could not open hard disk image '%s\n", | 3016 | + fprintf(stderr, "qemu: could not open hard disk image '%s'\n", |
2970 | hd_filename[i]); | 3017 | hd_filename[i]); |
2971 | exit(1); | 3018 | exit(1); |
2972 | } | 3019 | } |
@@ -3106,13 +3153,17 @@ int main(int argc, char **argv) | @@ -3106,13 +3153,17 @@ int main(int argc, char **argv) | ||
3106 | } else { | 3153 | } else { |
3107 | printf("Waiting gdb connection on port %d\n", gdbstub_port); | 3154 | printf("Waiting gdb connection on port %d\n", gdbstub_port); |
3108 | } | 3155 | } |
3156 | + term_init(); | ||
3109 | } else | 3157 | } else |
3110 | #endif | 3158 | #endif |
3111 | - if (start_emulation) | ||
3112 | { | 3159 | { |
3113 | - vm_start(); | 3160 | + term_init(); |
3161 | + /* XXX: simplify init */ | ||
3162 | + read_passwords(); | ||
3163 | + if (start_emulation) { | ||
3164 | + vm_start(); | ||
3165 | + } | ||
3114 | } | 3166 | } |
3115 | - term_init(); | ||
3116 | main_loop(); | 3167 | main_loop(); |
3117 | quit_timers(); | 3168 | quit_timers(); |
3118 | return 0; | 3169 | return 0; |