Index: apps/plugins/keybox.c =================================================================== --- apps/plugins/keybox.c (revision 25959) +++ apps/plugins/keybox.c (working copy) @@ -24,6 +24,7 @@ PLUGIN_HEADER #define KEYBOX_FILE PLUGIN_APPS_DIR "/keybox.dat" +#define KEYBOX_TXT_FILE PLUGIN_APPS_DIR "/keybox.txt" #define BLOCK_SIZE 8 #define MAX_ENTRIES 12*BLOCK_SIZE /* keep this a multiple of BLOCK_SIZE */ #define FIELD_LEN 32 /* should be enough for anyone ;) */ @@ -71,6 +72,7 @@ static union hash pwhash; static bool data_changed = false; +static void import_file(int selected_item); static void encrypt_buffer(char *buf, size_t size, uint32_t *key); static void decrypt_buffer(char *buf, size_t size, uint32_t *key); @@ -120,6 +122,7 @@ "Add entry", "Edit title", "Edit user name", "Edit password", "Delete entry", + "Import File", "Playback Control"); static const char* kb_list_cb(int selected_item, void *data, @@ -177,7 +180,7 @@ data_changed = true; } -static void add_entry(int selected_item) +static void add_entry(int selected_item, struct pw_entry *new_entry) { int i, j; struct pw_entry *entry = pw_list.first.next; @@ -190,27 +193,36 @@ return; } - rb->splash(HZ, "Enter title"); - pw_list.entries[i].title[0] = '\0'; - if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN) < 0) - return; - - rb->splash(HZ, "Enter name"); - pw_list.entries[i].name[0] = '\0'; - if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN) < 0) + if (new_entry == NULL) { + rb->splash(HZ, "Enter title"); pw_list.entries[i].title[0] = '\0'; - return; - } + if (rb->kbd_input(pw_list.entries[i].title, FIELD_LEN) < 0) + return; - rb->splash(HZ, "Enter password"); - pw_list.entries[i].password[0] = '\0'; - if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN) < 0) - { - pw_list.entries[i].title[0] = '\0'; + rb->splash(HZ, "Enter name"); pw_list.entries[i].name[0] = '\0'; - return; + if (rb->kbd_input(pw_list.entries[i].name, FIELD_LEN) < 0) + { + pw_list.entries[i].title[0] = '\0'; + return; + } + + rb->splash(HZ, "Enter password"); + pw_list.entries[i].password[0] = '\0'; + if (rb->kbd_input(pw_list.entries[i].password, FIELD_LEN) < 0) + { + pw_list.entries[i].title[0] = '\0'; + pw_list.entries[i].name[0] = '\0'; + return; + } } + else + { + rb->strcpy(pw_list.entries[i].title, new_entry->title); + rb->strcpy(pw_list.entries[i].name, new_entry->name); + rb->strcpy(pw_list.entries[i].password, new_entry->password); + } for (j = 0; j < selected_item; j++) { @@ -279,7 +291,7 @@ result = rb->do_menu(&context_m, &selection, NULL, false); switch (result) { case 0: - add_entry(selected_item); + add_entry(selected_item, NULL); return; case 1: edit_title(selected_item); @@ -294,6 +306,10 @@ delete_entry(selected_item); return; case 5: + import_file(selected_item); + exit = true; + break; + case 6: playback_control(NULL); return; default: @@ -594,6 +610,61 @@ return 0; } +static void import_file(int selected_item) +{ + int fd, length, lines_read=1; + char line[FIELD_LEN+1]; + bool no_file = !rb->file_exists(KEYBOX_TXT_FILE); + struct pw_entry new_entry; + + if (no_file) + { + rb->splash(HZ*4, "File"KEYBOX_TXT_FILE" does not exists"); + return; + } + + fd = rb->open(KEYBOX_TXT_FILE, O_RDONLY); + if (fd < 0) + { + rb->splash(HZ*4, "could not open"KEYBOX_TXT_FILE); + return; + } + + do + { + if ((length = rb->read_line(fd, line, FIELD_LEN+1))>FIELD_LEN) + break; + rb->strcpy(new_entry.title,line); + lines_read++; + if ((length = rb->read_line(fd, line, FIELD_LEN+1))>FIELD_LEN) + break; + rb->strcpy(new_entry.name,line); + lines_read++; + if ((length = rb->read_line(fd, line, FIELD_LEN+1))>FIELD_LEN) + break; + rb->strcpy(new_entry.password,line); + lines_read++; + if (length > 0) + add_entry(selected_item++, &new_entry); + rb->yield(); + } + while (length > 0); + + rb->close(fd); + + if (length > FIELD_LEN) + { + rb->splashf(4*HZ, "line #%d longer than %d character", + lines_read,FIELD_LEN-1); + rb->splash(5*HZ, line); + rb->splash(5*HZ, "import interupted!"); + return; + } + rb->splash(5*HZ, "import successful, delete unencrypted file"); + return; + +} + static void reset(void) { static const char *message_lines[]=