|
1 | 1 | /* |
2 | 2 | * This file is part of John the Ripper password cracker, |
3 | 3 | * Copyright (c) 1996-2003,2005,2006,2009,2010,2013,2017 by Solar Designer |
4 | | - * |
5 | | - * ...with changes in the jumbo patch, by JimF and magnum. |
| 4 | + * Copyright (c) 2009-2026, magnum |
| 5 | + * Copyright (c) 2009-2018, JimF |
6 | 6 | * |
7 | 7 | * Redistribution and use in source and binary forms, with or without |
8 | 8 | * modification, are permitted. |
@@ -763,3 +763,72 @@ uint64_t rec_read_cands(char *session) |
763 | 763 |
|
764 | 764 | return ret; |
765 | 765 | } |
| 766 | + |
| 767 | +void rec_add_files(char *session) |
| 768 | +{ |
| 769 | + char *other_name; |
| 770 | + FILE *other_file = NULL; |
| 771 | + int64_t other_size = 0; |
| 772 | + |
| 773 | + if (!john_main_process && options.node_min) { |
| 774 | + char suffix[1 + 20 + sizeof(RECOVERY_SUFFIX)]; |
| 775 | + |
| 776 | + sprintf(suffix, ".%u%s", options.node_min, RECOVERY_SUFFIX); |
| 777 | + other_name = path_session(session, suffix); |
| 778 | + } else { |
| 779 | + other_name = path_session(session, RECOVERY_SUFFIX); |
| 780 | + } |
| 781 | + |
| 782 | + if (!(other_file = fopen(other_name, "r+"))) |
| 783 | + pexit("fopen catch-up file: '%s'", other_name); |
| 784 | + |
| 785 | +#if !(__MINGW32__ || _MSC_VER) |
| 786 | + if (jtr_lock(fileno(other_file), F_SETLK, F_WRLCK, other_name)) |
| 787 | + error_msg("Catch-Up session file '%s' is locked\n", other_name); |
| 788 | +#endif |
| 789 | + |
| 790 | + jtr_fseek64(other_file, 0, SEEK_END); |
| 791 | + if ((other_size = jtr_ftell64(other_file)) == -1) |
| 792 | + pexit("ftell"); |
| 793 | + jtr_fseek64(other_file, 0, SEEK_SET); |
| 794 | + if (other_size == 0) { |
| 795 | + error_msg("Error, %s is empty\n", other_name); |
| 796 | + } |
| 797 | + |
| 798 | + char *other_data = mem_alloc_tiny(other_size + 1, MEM_ALIGN_NONE); |
| 799 | + memset(other_data, 0, other_size + 1); |
| 800 | + |
| 801 | + if (fread(other_data, 1, (size_t)other_size, other_file) != other_size) { |
| 802 | + if (ferror(other_file)) |
| 803 | + pexit("fread"); |
| 804 | + error_msg("fread: Unexpected EOF\n"); |
| 805 | + } |
| 806 | + |
| 807 | + char magic[16]; |
| 808 | + int argc; |
| 809 | + unsigned offset; |
| 810 | + sscanf(other_data, "%15s\n%d\n%nu", magic, &argc, &offset); |
| 811 | + |
| 812 | + jtr_fseek64(other_file, 0, SEEK_SET); |
| 813 | + |
| 814 | + fprintf(other_file, "%s\n%d\n", magic, argc + (int)options.passwd->count); |
| 815 | + |
| 816 | + struct list_entry *current; |
| 817 | + if ((current = options.passwd->head)) { |
| 818 | + do { |
| 819 | + fprintf(other_file, "%s\n", current->data); |
| 820 | + } while ((current = current->next)); |
| 821 | + } |
| 822 | + |
| 823 | + fprintf(other_file, "%s", other_data + offset); |
| 824 | + fclose(other_file); |
| 825 | + |
| 826 | + if (unlink(path_expand(rec_name))) |
| 827 | + pexit("unlink: %s", path_expand(rec_name)); |
| 828 | + |
| 829 | + if (rec_file) { |
| 830 | + if (fclose(rec_file)) |
| 831 | + pexit("fclose"); |
| 832 | + rec_file = NULL; |
| 833 | + } |
| 834 | +} |
0 commit comments