Splashy can display a popup if it needs user interaction. Make user queries go through the splash struct to be able to use that.
- Remove to_silent/to_verbose these are private to bootsplash - Add read_password/getchar to the struct - Ask the password not from within encrypt_init, but separately. - Make some wrapper functions for bootsplash Index: splash.h =================================================================== --- splash.h (revision 160) +++ splash.h (revision 164) @@ -14,11 +14,11 @@ /* generic interface functions for an arbitary splash method */ struct splash { - int (*to_silent) (void); - int (*to_verbose) (void); int (*finish) (void); int (*progress) (int p); void (*switch_to) (void); + void (*read_password) (char *, int); + int (*getchar) (void); }; void splash_prepare(struct splash *splash, int enabled); Index: resume.c =================================================================== --- resume.c (revision 160) +++ resume.c (revision 164) @@ -402,7 +402,7 @@ ivec_buf = key_buf + PK_KEY_SIZE; out = ivec_buf + PK_CIPHER_BLOCK; do { - read_password(pass_buf, 0); + splash.read_password(pass_buf, 0); memset(ivec_buf, 0, PK_CIPHER_BLOCK); strncpy((char *)ivec_buf, pass_buf, PK_CIPHER_BLOCK); md5_init_ctx(&ctx); @@ -567,17 +567,16 @@ static unsigned char key[KEY_SIZE], ivec[CIPHER_BLOCK]; printf("resume: Encrypted image\n"); - splash.to_verbose(); if (header->image_flags & IMAGE_USE_RSA) { error = decrypt_key(header, key, ivec, buffer); } else { int j; - encrypt_init(key, ivec, buffer, 0); + splash.read_password(buffer, 0); + encrypt_init(key, ivec, buffer); for (j = 0; j < CIPHER_BLOCK; j++) ivec[j] ^= header->salt[j]; } - splash.to_silent(); splash.progress(15); if (!error) error = gcry_cipher_open(&handle.cipher_handle, @@ -630,7 +629,7 @@ "\tnow and successful resume. That would badly damage\n" "\taffected filesystems.]\n\n" "\tDo you want to continue boot (Y/n)? "); - c = getchar(); + c = splash.getchar(); ret = (c == 'n' || c == 'N'); if (ret) { close(fd); @@ -671,7 +671,7 @@ } else { printf("resume: Error %d loading the image\n" "\nPress ENTER to continue", error); - getchar(); + splash.getchar(); } return error; } Index: bootsplash.c =================================================================== --- bootsplash.c (revision 160) +++ bootsplash.c (revision 164) @@ -16,6 +16,7 @@ #include <string.h> #include "vt.h" +#include "encrypt.h" #define BOOTSPLASH_PROC "/proc/splash" #define MAX_LINE_SIZE 1024 @@ -32,6 +33,34 @@ return 0; } +static int bootsplash_write(const char *buf) +{ + int error = 0; + + if (!splash_file) + return -1; + + error = fputs(buf, splash_file); + if (error == EOF) { + fprintf(stderr, "Could not write '%s' to %s: %s\n", + buf, BOOTSPLASH_PROC, strerror(errno)); + bootsplash_finish(); + return error; + } + fflush(splash_file); + return 0; +} + +static int bootsplash_to_silent(void) +{ + return bootsplash_write("silent\n"); +} + +static int bootsplash_to_verbose(void) +{ + return bootsplash_write("verbose\n"); +} + int bootsplash_open(void) { char *str, buf[MAX_LINE_SIZE]; @@ -47,6 +76,7 @@ if (!strstr(buf, ": on")) goto close; + bootsplash_to_silent(); return 0; close: bootsplash_finish(); @@ -62,24 +92,6 @@ } } -static int bootsplash_write(const char *buf) -{ - int error = 0; - - if (!splash_file) - return -1; - - error = fputs(buf, splash_file); - if (error == EOF) { - fprintf(stderr, "Could not write '%s' to %s: %s\n", - buf, BOOTSPLASH_PROC, strerror(errno)); - bootsplash_finish(); - return error; - } - fflush(splash_file); - return 0; -} - inline int bootsplash_progress(int p) { char buf[MAX_LINE_SIZE]; @@ -92,12 +104,21 @@ return bootsplash_write(buf); } -int bootsplash_to_silent(void) -{ - return bootsplash_write("silent\n"); -} +void bootsplash_read_password (char * buf, int vrfy) +{ +#if CONFIG_ENCRYPT + bootsplash_to_verbose(); + read_password(buf, vrfy); + bootsplash_to_silent(); +#endif +} -int bootsplash_to_verbose(void) -{ - return bootsplash_write("verbose\n"); -} +int bootsplash_getchar (void) +{ + int ret; + bootsplash_to_verbose(); + ret = getchar(); + bootsplash_to_silent(); + + return ret; +} Index: suspend.c =================================================================== --- suspend.c (revision 160) +++ suspend.c (revision 164) @@ -55,6 +55,7 @@ static char encrypt; static char use_RSA; static char key_name[MAX_STR_LEN] = KEY_FILE; +static char password[PASS_SIZE]; #else #define encrypt 0 #define key_name NULL @@ -541,10 +542,8 @@ int j; No_RSA: - chvt(vt_no); encrypt_init(key_data->key, key_data->ivec, - handle.write_buffer, 1); - splash.switch_to(); + password); splash.progress(20); get_random_salt(header->salt, CIPHER_BLOCK); for (j = 0; j < CIPHER_BLOCK; j++) @@ -1169,6 +1168,12 @@ /* If s2ram_prepare returns != 0, better not try to suspend to RAM */ s2ram = !s2ram_prepare(); #endif +#ifdef CONFIG_ENCRYPT + if (encrypt && ! use_RSA) { + splash.read_password((char *)mem_pool,1); + strncpy(password,(char *)mem_pool,PASS_SIZE); + } +#endif open_printk(); orig_loglevel = get_kernel_console_loglevel(); Index: bootsplash.h =================================================================== --- bootsplash.h (revision 160) +++ bootsplash.h (revision 164) @@ -16,8 +16,8 @@ int bootsplash_prepare(void); int bootsplash_finish(void); int bootsplash_progress(int p); -int bootsplash_to_silent(void); -int bootsplash_to_verbose(void); void bootsplash_switch_to(void); +void bootsplash_read_password(char *, int); +int bootsplash_getchar(void); #endif /* BOOTSPLASH_H */ Index: encrypt.c =================================================================== --- encrypt.c (revision 160) +++ encrypt.c (revision 164) @@ -21,6 +21,11 @@ #include "md5.h" #include "encrypt.h" +/** + * read_password - get non-empty, \0-terminated password from stdin + * passbuf - buffer of at least PASS_SIZE * 2 chars + * vrfy - if verify the password or not + */ void read_password(char *pass_buf, int vrfy) { struct termios termios; @@ -60,13 +65,11 @@ */ void -encrypt_init(unsigned char *key, unsigned char *ivec, char *pass_buf, int vrfy) +encrypt_init(unsigned char *key, unsigned char *ivec, char *pass_buf) { struct md5_ctx ctx; - read_password(pass_buf, vrfy); - memset(ivec, 0, CIPHER_BLOCK); strncpy((char *)ivec, pass_buf, CIPHER_BLOCK); md5_init_ctx(&ctx); Index: encrypt.h =================================================================== --- encrypt.h (revision 160) +++ encrypt.h (revision 164) @@ -55,7 +55,7 @@ }; void read_password(char *pass_buf, int vrfy); -void encrypt_init(unsigned char *, unsigned char *, char *, int); +void encrypt_init(unsigned char *, unsigned char *, char *); void get_random_salt(unsigned char *salt, size_t size); #define KEY_FILE "" Index: splash.c =================================================================== --- splash.c (revision 160) +++ splash.c (revision 164) @@ -14,6 +14,7 @@ #include "splash.h" #include "bootsplash.h" +#include "encrypt.h" /** * dummy functions in case if no splash system was found or @@ -22,29 +23,35 @@ static int splash_dummy_int_void(void) { return 0; } static int splash_dummy_int_int(int p) { return 0; } static void splash_dummy_void_void(void) { return; } +#ifndef CONFIG_ENCRYPT +static void splash_dummy_readpass (char *a, int b) { } +#endif /* Tries to find a splash system and initializes interface functions */ void splash_prepare(struct splash *splash, int enabled) { int error = 0; - splash->to_silent = splash_dummy_int_void; - splash->to_verbose = splash_dummy_int_void; splash->finish = splash_dummy_int_void; splash->progress = splash_dummy_int_int; splash->switch_to = splash_dummy_void_void; - + splash->getchar = getchar; +#ifdef CONFIG_ENCRYPT + splash->read_password = read_password; +#else + splash->read_password = splash_dummy_readpass; +#endif if (!enabled) return; printf("Looking for splash system... "); if (!(error = bootsplash_open())) { - splash->to_silent = bootsplash_to_silent; - splash->to_verbose = bootsplash_to_verbose; splash->finish = bootsplash_finish; splash->progress = bootsplash_progress; splash->switch_to = bootsplash_switch_to; + splash->getchar = bootsplash_getchar; + splash->read_password = bootsplash_read_password; } else if (0) { /* add another splash system here */ } else { @@ -53,6 +60,5 @@ } printf("found\n"); - splash->to_silent(); splash->progress(0); } ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel