source: trunk/mondo/mondo/mondorestore/mondo-restore.c @ 142

Last change on this file since 142 was 142, checked in by bcornec, 14 years ago

merge -r139:141 $SVN_M/branches/2.05
splint improvements (begin)

  • Property svn:keywords set to Id
File size: 113.3 KB
Line 
1/***************************************************************************
2       mondo-restore.c  -  restores mondoarchive data
3                             -------------------
4    begin                : Fri May 19 2000
5    copyright            : (C) 2000 by Hugo Rabson
6    email                : Hugo Rabson <hugorabson@msn.com>
7    cvsid                : $Id: mondo-restore.c 142 2005-11-27 21:38:41Z bcornec $
8***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation; either version 2 of the License, or     *
15 *   (at your option) any later version.                                   *
16 *                                                                         *
17 ***************************************************************************/
18
19/***************************************************************************
20 *                         Change Log                                      *
21 ***************************************************************************
22.
23
24
2507/26
26- workaround - if not /dev then don't call partimagehack
27
2807/21
29- if switch to Interactive Mode during nuke then don't nuke twice :) just once
30
3107/18
32- better support of users who boot from LVM CD and nuke-restore non-LVM backups
33
3407/10
35- when using 'star', exclude all 'not removed.' messages from log (misleading, they are)
36- try w/ ACLs, then w/o ACLs if star fails w/ ACLs
37- added ACL, xattr support for afio
38
3906/26
40- remove make_relevant_partition_bootable(); roll into mondo-prep.c
41- changed various newtDrawRootText() calls to use g_noof_rows instead of
42  integers
43
4406/19
45- don't try to access biggiestruct before it is populated w/ data relating
46  to biggiefile; instead, use control char to find out if biggiefile is
47  to be restored w/ partimagehack or not
48- added AUX_VER
49
5006/15
51- read_cfg_file_into_bkpinfo() --- use user-supplied 'isodir' instead of
52  archive's 'isodir' if different
53  Conor Daly <conor.daly@met.ie>
54
5506/17
56- restore with partimagehack if NTFS device; dd, if non-NTFS device
57
5806/14
59- unmount all; remount, run grub-mr; unmount again
60
6104/09
62- fixed subset restoration bug introduced when I added 'star' support
63
6404/04
65- cleaned up restore_a_tarball_from_stream()
66
6704/03
68- added star support
69- pause for 3s between partitioning and formatting (if in Nuke Mode)
70
7103/28
72- check that g_mountlist_fname was correcfly set; abort if it wasn't
73
7403/25
75- removed dev_null code
76
7703/22/04
78- added mode_of_file()
79- added code to check for unauthorised modification of /dev/null
80  by afio (for instance)
81
8212/27/03
83- check /tmp/cmdline instead of /proc/cmdline if on FreeBSD
84
8511/15
86- added g_fprep
87- "Switch to interactive mode?" msg is now more informative
88
8911/05
90- after 'Are you sure?' when user specifies / as restore path, set
91  restore_path[] to "" so that files are restored to [blank]/file/name :)
92
9310/29
94- moved "No restoring or comparing will take place today" block
95  up to before iso_fiddly_bits (if iso) is called - fix bug
96  if you're in ISO Mode and you say "exit to shell"
97
9810/22
99- swapped calls to chmod() and chown() after restoration
100  of big files (Jens)
101
10210/21
103- changed "/mnt/cdrom" to MNT_CDROM
104
10510/19
106- restore biggiefiles selectively from CD properly
107- use find_my_editor() to find pico/vi/whatever
108- better use of call_program_and_get_last_line_of_output() to
109  scan /proc/cmdline
110
11110/18
112- don't report 'missing compressor' if no compressor used at all
113
11410/14
115- log afio's error messages to /var/log/mondo-archive.log
116  when restoring :)
117- call vi if pico is not available
118
11910/09
120- better logging if fatal error (cannot openout bigfile)
121- better GUI feedback when restoring big files
122- restore_everything() now uses s_node* instead of char*
123- ditto restore_all_*_from_*()
124
12510/02
126- succinct msg instead of pop-ups, if used -H
127
12809/27
129- tweaked restore-time gui
130
13109/26
132- proper reporting of DVD/CDR/etc. type in displayed dialogs
133
13409/23
135- malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
136  and free_libmondo_global_strings() - which are in libmondo-tools.c
137
13809/21
139- trying to fix "mondorestore <no params>" segfault
140
14109/18
142- better remounting of /
143- cleaned up run_grub()
144- sensible command-line handling in Live Mode
145
14609/17
147- cleaned up GRUB installer script a bit
148
14909/15
150- remount / as r/w if in disaster recovery mode;
151  helps for b0rken distros
152
15309/13
154- major NTFS hackage
155
15609/12
157- changed some in-sub var decl'ns to malloc()'s
158
15909/05
160- don't let me run unless I'm root
161- finished NTFS/partimagehack support (CD only); working on tape now
162
16309/01
164- fixed cosmetic bug in biggiefile restore window
165
16606/01 - 08/31
167- added code to main() to make sure NFS
168  (backup) share is mounted in Nuke and Compare Modes
169- added code to run_grub() to mount /boot before running grub-install
170- fixed some stray assert()'s in restore_a_biggiefile_from_stream()
171- fixed bugs in extract_config_file_from_ramdisk()
172  and get_cfg_file_from_archive() which
173  stopped fape+floppy users from being able to
174  boot from floppy and leave floppy in drive :)
175- added hooks to partimage for doing imagedevs
176- fixed calls to popup_and_get_string()
177
17805/01 - 05/31
179- fixed biggiefile atime/utime dates restoration bug, I think
180- added misc clean-up (Steve Hindle)
181- fixed support for subdir-within-NFS-mount
182- if nuke mode fails & user reverts to interactive mode _and succeeds_,
183  don't claim nuke mode aborted :)
184- unmount_all_devices() uses mountlist->el[lino].mountpt
185  instead of mountlist->el[lino].device where possible
186- added Joshua Oreman's FreeBSD patches
187- copied missing paragraph from 1.6x's read_cfg_file_into_bkpinfo()
188  to 1.7x's; affected tape streamer users (badly!)
189- cleaned up some paranoid assert()'s
190- use which("post-nuke") instead of find_home_of_exe("post-nuke")
191- fixed "Don't eject while restoring" mode
192- get_cfg_file_from_archive() --- also recovers mountlist.txt now :)
193- don't eject if 'donteject' is in kernel's command line
194- added 'don't panic' msg to start of log
195
19604/01 - 04/30
197- added text mode (cat /proc/cmdline; if textonly then text mode is on)
198- delete /var/lock/subsys/ * when nuking
199- don't resize mountlist if "noresize" present in /proc/cmdline
200- changed from chmod -R 1777 tmp to chmod 1777 tmp
201- replace newtFinished() and newtInit() with
202  newtSuspend() and newtResume()
203- get_cfg_file_from_archive() returns 1 instead of aborting now
204- read_cfg_file_into_bkpinfo) --- if autorun CD but its config
205  file indicates a non-CD backup media then ask, just in case
206- sped up restore_a_tarball_from_CD() a bit
207- line 4469 --- if post-nuke not found then don't run it :)
208- replaced "/mnt/RESTORING" with MNT_RESTORING (#define'd)
209- moved compare_*() into mondorestore/mondo-rstr-compare.c
210- moved some RAID subroutines into common/libmondo-raid.c
211- fixed some iso live compare problems
212- replaced FILELIST_FULL with g_filelist_full and FILELIST_FULL_STUB;
213  g_filelist_full being the full path of the filelist.full text file and
214  FILELIST_FULL_STUB being "tmp/filelist.full" (relative path);
215- ditto BIGGIELIST_TXT, MONDO_CFG_FILE
216- added lots of assert()'s and log_OS_error()'s
217- in Nuke Mode, check mountlist's sanity before doing anything else;
218  if it fails sanity test, offer to revert to Interactive Mode (or abort)
219- copy log to /mnt/RESTORING/root at end
220- read_cfg_file_into_bkpinfo() --- read iso-dev and isodir if bkptype==iso
221- line 1701 --- delete ramdisk file after extracting config info
222- moved call to make_relevant_partitions_bootable() from
223  within run_boot_loader() to within interactive_mode() and
224  nuke_mode(), after unmounting disks
225- if editing fstab or *.conf, try to use pico if available
226- better calling of make-me-bootable
227- don't sort mountlist anywhere anymore except _locally_ in
228  mount_all_devices() and unmount_all_devices()
229- edit fstab, grub.conf _after_ stabgrub-me if it fails
230- run_boot_loader() --- backup all crucial files to /etc/ *.pristine first
231- added iso_fiddly_bits()
232- fixed ISO mode support
233- mount_cdrom() only searches for device if NOT in disaster recovery mode
234- changed lost of system()'s into run_program_and_log_output()'s
235- don't eject if bkpinfo->please_dont_eject_when_restoring
236- cleaned up post-nuke handling code
237- always eject CD at end, unless bkpinfo->please_dont_...
238- misc clean-up (Tom Mortell)
239- afio uses -c (1024L*1024L)/TAPE_BLOCK_SIZE now
240  instead of -c 1024
241
24201/01 - 03/31/2003
243- commented out sort_... line (BB)
244- clean-up (Stan Benoit)
245- added code for LVM and SW Raid (Brian Borgeson)
246- line 814 - added -p to 'mkdir -p tmp'
247- mount_cdrom() - calls find_cdrom_device() if
248  bkpinfo->media_device is blank (to fill it)
249
25011/01 - 12/31/2002
251- mount_cdrom() better at handling multiple CD drives
252- minor clean-up in restore_a_tarball_from_CD()
253- if --live-from-cd then assume restoring live from CD
254- tweaked it to run better w/ ArkLinux
255- create /mnt/RESTORING/mnt/.boot.d for Gentoo users
256  after restoring
257- cleaned up iso_mode(); no longer asks for NFS info 3 times
258- mount_cdrom() was trying to mount /mnt/isodir/%s/%d.iso;
259  is now just %s/%d.iso
260- mount/unmount /boot if necessary (Gentoo)
261- added RAW MBR support; added run_raw_mbr() for the purpose
262- unmount & remount supermounts at start/end of live restore
263- copy /tmp/mountlist.txt to /tmp/mountlist.txt.orig at start
264- cleaned up string-handling in get_cfg_info_from_archives()
265- fixed run_grub() to call new stabgrub-me script
266- popup list of changed files after Compare Mode
267- permit mondorestore --edit-mountlist even if live mode
268- create a repaired copy of grub-install which is RAID-friendly;
269  use it when initializing boot sector with run_grub()
270- use grub-MR instead of grub-install
271- fixed read_cfg_file_into_bkpinfo() to ignore cfg file's backup_media_type
272  if user has already specified a backup media type interactively
273
27410/01 - 10/31
275- run_grub() will let you specify the boot device as well as edit the system
276  files, if grub-install fails
277- fixed bug in fwrite() call in restore_biggiefile_from_CD()
278- fixed bug affecting restoration of bigfiles from CD's w/0 compression
279- run_grub() will run 'grub-install {boot device}' instead of
280  'grub-install (hd0)'
281
28209/01 - 09/30
283- use /tmp/tmpfs/mondo.tmp instead of /tmp/mondo.tmp
284- initialize MOUNTLIST_FNAME at start of main()
285- differential-related cleanup
286- better handling of CD-ROM drives which aren't /dev/cdrom :)
287- run_program_and_log_output() now takes boolean operator to specify
288  whether it will log its activities in the event of _success_
289- always load config file from archive before operating on it
290- moved some subroutines around; now closer to alphabetical order
291- changed mount.mindi to mount.bootisk
292- mount disks readonly if in Compare Mode
293- set /dev/null's permissions to 777, just in case it somehow gets mangled
294  ...which apparently happen with some devfs-based Linux distributions
295- remove /var/run/ *.pid after restoring
296- move spurious lockfiles from /home/ * to /home/ * /.disabled
297- if Interactive Mode then ask user which media, etc. (i.e. catchall mode
298  is now same as Interactive Mode)
299
30008/01 - 08/30
301- use data structure to store the fname, checksum, mods & perms of each bigfile
302  ... biggiestruct :)
303- if a filelist is tiny (2 bytes or less) then ignore it
304- insist_on_this_cd_number() --- now takes 2 params, not 1
305- re-enabled 'g_current_media_number = 1' in restore_everything()
306- added same to compare_mode()
307- replaced lots of global char[]'s with malloc()'s
308- if differential backup then don't permit formatting or fdisking,
309  whether Interactive or Nuke mode
310- added call to register_pid() at start of main()
311- if Nuke Mode & it succeeds then ask user if they have contributed yet
312- changed tape-size to media-size (config file)
313- changed using_* to backup_media_type
314- changed *_from_tape to *_from_stream
315
31607/01 - 07/31
317- added find_and_mount_actual_cdrom()
318- temp dir is always random
319- skip tarballs if they don't contain files we're looking for
320  (used to read the whole thing & _then_ skip)
321- use media_size[1] instead of media_size[0]
322- fixed serious bug in line 1546 - should have been !=, not ==; stopped
323  mondorestore from correctly restoring big files
324- bigfile piping enhancements (Philippe de Muyter)
325- unmount CD-ROM after restoring from live filesystem
326- TAPE_BLOCK_SIZE treated as %ld, not %d
327
32806/01 - 06/30
329- added signal-trapping
330- disabled 'nr-failed-disks' flag
331- fixed problem w/selective restore
332- don't change /tmp's permissions unless it doesn't exist & must be created
333- fixed bug in --mbr
334- is_file_in_list() enhanced to exclude /mnt/RESTORING or whatever
335- added support for uncompressed archives
336- --monitas-live now accepts path-to-restore_to_, not just path to restore
337- added some debugging/tracking code to the NFS section
338- various monitas-related enhancements
339- added --isonuke and --mbr switches
340- better logging in run_grub()
341- improved --monitas-live
342- mkdir -p /mnt/RESTORING/var/run/console just in case user excludes it
343- afio now uses 16MB buffer instead of 8MB
344- always use bkpinfo->media_size[0], now that -s has been expanded
345- popup and ask where to restore data, if restoring selectively
346
34705/01 - 05/31
348- add '--monitas' flag
349- don't run chmod -R 1777 /mnt/RESTORING/tmp before unmounting unless
350  restoring at the time...
351
35204/01 - 04/30
353- delete old /tmp/filelist.full,biggielist.txt if found when restoring to
354  live filesystem
355- replace MONDO_VERSION #define with VERSION from ../config.h
356- write fname of bigfile to screen when having trouble reading/comparing it
357- if restoring to live filesystem then wipe /tmp/tmpfs/ * afterwards
358- removed spurious finish(0) from main()
359
36003/01 - 03/31/2002
361- if /tmp/m*ndo-restore.cfg not found then assume live restore; restore
362  to / instead of /mnt/RESTORING
363- clean up is_file_in_list() to deal with the /mnt/RESTORING/ prefix
364- exclude leading '/' from filelist.restore-these
365- if /tmp/fstab.new exists then use _it_ instead of /tmp/fstab to label
366  ext2 or ext3 partitions
367- improved logging
368
369[...]
370
37107/10/2001 --- first incarnation
372*/
373
374
375/**
376 * @file
377 * The main file for mondorestore.
378 */
379
380/**************************************************************************
381 * #include statements                                                    *
382 **************************************************************************/
383#include "../common/my-stuff.h"
384#include "../common/mondostructures.h"
385#include "../common/libmondo.h"
386#include "mr-externs.h"
387#include "mondo-restore.h"
388#include "mondo-rstr-compare-EXT.h"
389#include "mondo-rstr-tools-EXT.h"
390#ifndef S_SPLINT_S
391#include <pthread.h>
392#endif
393
394extern void success_message(void);
395extern void twenty_seconds_til_yikes(void);
396
397
398/* For use in other programs (ex. XMondo) */
399#ifdef MONDORESTORE_MODULE
400#define main __mondorestore_main
401#define g_ISO_restore_mode __mondorestore_g_ISO_restore_mode
402#endif
403
404#ifndef VERSION
405#define VERSION AUX_VER
406#endif
407
408char g_version[] = VERSION;
409
410
411//static char cvsid[] = "$Id: mondo-restore.c 142 2005-11-27 21:38:41Z bcornec $";
412
413/**************************************************************************
414 * Globals                                                                *
415 **************************************************************************/
416extern char *g_tmpfs_mountpt;   // declared in libmondo-tools.c
417extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free
418                                                // up global bkpinfo struct
419extern bool g_text_mode;
420extern FILE *g_fprep;
421extern double g_kernel_version;
422extern int g_partition_table_locked_up;
423extern int g_noof_rows;
424
425extern int partition_everything(struct mountlist_itself *mountlist);
426
427
428/**
429 * @name Restore-Time Globals
430 * @ingroup globalGroup
431 * @{
432 */
433/**
434 * If TRUE, then SIGPIPE was just caught.
435 * Set by the signal handler; cleared after it's handled.
436 */
437bool g_sigpipe_caught = FALSE;
438
439/**
440 * If TRUE, then we're restoring from ISOs or an NFS server.
441 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.)
442 */
443bool g_ISO_restore_mode = FALSE;    /* are we in Iso Mode? */
444
445/**
446 * If TRUE, then we have had a successful "nuke" restore.
447 */
448bool g_I_have_just_nuked = FALSE;
449
450/**
451 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
452 */
453char *g_isodir_device;
454
455/**
456 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
457 */
458char *g_isodir_format;
459
460/**
461 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set.
462 */
463char *g_biggielist_txt;
464
465/**
466 * The location of 'filelist.full', containing all files (<em>including biggiefiles</em>) on
467 * the current archive set.
468 */
469char *g_filelist_full;
470
471/**
472 * The location of a file containing a list of the devices that were archived
473 * as images, not as individual files.
474 */
475char *g_filelist_imagedevs;
476
477/**
478 * The location of a file containing a list of imagedevs to actually restore.
479 * @see g_filelist_imagedevs
480 */
481char *g_imagedevs_restthese;
482
483/**
484 * The location of 'mondo-restore.cfg', containing the metadata
485 * information for this backup.
486 */
487char *g_mondo_cfg_file;
488
489/**
490 * The location of 'mountlist.txt', containing the information on the
491 * user's partitions and hard drives.
492 */
493char *g_mountlist_fname;
494
495/**
496 * Mondo's home directory during backup. Unused in mondo-restore; included
497 * to avoid link errors.
498 */
499char *g_mondo_home;
500
501/* @} - end of "Restore-Time Globals" in globalGroup */
502
503
504
505extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived,
506                                 char direction);
507
508
509
510/**************************************************************************
511 * COMPAQ PROLIANT Stuff:  needs some special help                        *
512**************************************************************************/
513
514/**
515 * The message to display if we detect that the user is using a Compaq Proliant.
516 */
517#define COMPAQ_PROLIANTS_SUCK "Partition and format your disk using Compaq's disaster recovery CD. After you've done that, please reboot with your Mondo CD/floppy in Interactive Mode."
518
519
520
521
522/**
523 * Allow the user to modify the mountlist before we partition & format their drives.
524 * @param bkpinfo The backup information structure. @c disaster_recovery is the only field used.
525 * @param mountlist The mountlist to let the user modify.
526 * @param raidlist The raidlist that goes with @p mountlist.
527 * @return 0 for success, nonzero for failure.
528 * @ingroup restoreGuiGroup
529 */
530int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo,
531                                struct mountlist_itself *mountlist,
532                                struct raidlist_itself *raidlist)
533{
534    int retval = 0, res = 0;
535
536    log_msg(2, "let_user_edit_the_mountlist() --- starting");
537
538    assert(bkpinfo != NULL);
539    assert(mountlist != NULL);
540    assert(raidlist != NULL);
541    if (!bkpinfo->disaster_recovery) {
542        strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
543        log_msg(2, "I guess you're testing edit_mountlist()");
544    }
545    if (!does_file_exist(g_mountlist_fname)) {
546        log_to_screen(g_mountlist_fname);
547        log_to_screen("does not exist");
548        return (1);
549    }
550
551    retval = load_mountlist(mountlist, g_mountlist_fname);
552    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
553    if (retval) {
554        log_to_screen
555            ("Warning - load_raidtab_into_raidlist returned an error");
556    }
557    res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
558    if (res) {
559        return (1);
560    }
561
562    save_mountlist_to_disk(mountlist, g_mountlist_fname);
563    save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
564
565    log_to_screen("I have finished editing the mountlist for you.");
566
567    return (retval);
568}
569
570
571
572
573
574/**
575 * Determine whether @p mountlist contains a Compaq diagnostic partition.
576 * @param mountlist The mountlist to examine.
577 * @return TRUE if there's a Compaq diagnostic partition; FALSE if not.
578 * @ingroup restoreUtilityGroup
579 */
580bool
581partition_table_contains_Compaq_diagnostic_partition(struct
582                                                     mountlist_itself *
583                                                     mountlist)
584{
585    int i;
586
587    assert(mountlist != NULL);
588
589    for (i = 0; i < mountlist->entries; i++) {
590        if (strstr(mountlist->el[i].format, "ompaq")) {
591            log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)",
592                    i, mountlist->el[i].device, mountlist->el[i].format);
593
594            return (TRUE);
595        }
596    }
597    return (FALSE);
598}
599
600/**************************************************************************
601 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION                *
602 **************************************************************************/
603
604
605/**
606 * Allow the user to abort the backup if we find that there is a Compaq diagnostic partition.
607 * @note This function does not actually check for the presence of a Compaq partition.
608 * @ingroup restoreUtilityGroup
609 */
610void offer_to_abort_because_Compaq_Proliants_suck(void)
611{
612    popup_and_OK(COMPAQ_PROLIANTS_SUCK);
613    if (ask_me_yes_or_no
614        ("Would you like to reboot and use your Compaq CD to prep your hard drive?"))
615    {
616        fatal_error
617            ("Aborting. Please reboot and prep your hard drive with your Compaq CD.");
618    }
619}
620
621/**************************************************************************
622 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK                        *
623 **************************************************************************/
624
625
626
627/**
628 * Call interactive_mode(), nuke_mode(), or compare_mode() depending on the user's choice.
629 * @param bkpinfo The backup information structure. Most fields are used.
630 * @param mountlist The mountlist containing information about the user's partitions.
631 * @param raidlist The raidlist to go with @p mountlist.
632 * @return The return code from the mode function called.
633 * @ingroup restoreGroup
634 */
635int
636catchall_mode(struct s_bkpinfo *bkpinfo,
637              struct mountlist_itself *mountlist,
638              struct raidlist_itself *raidlist)
639{
640    char c, *tmp;
641    int retval = 0;
642
643    iamhere("inside catchall");
644    assert(bkpinfo != NULL);
645    assert(mountlist != NULL);
646    assert(raidlist != NULL);
647    malloc_string(tmp);
648    iamhere("pre wrm");
649    c = which_restore_mode();
650    iamhere("post wrm");
651    if (c == 'I' || c == 'N' || c == 'C') {
652        interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
653    } else {
654        popup_and_OK("No restoring or comparing will take place today.");
655        if (is_this_device_mounted("/mnt/cdrom")) {
656            run_program_and_log_output("umount /mnt/cdrom", FALSE);
657        }
658        if (g_ISO_restore_mode) {
659            sprintf(tmp, "umount %s", bkpinfo->isodir);
660            run_program_and_log_output(tmp, FALSE);
661        }
662        paranoid_MR_finish(0);
663    }
664
665    iamhere("post int");
666
667    if (bkpinfo->backup_media_type == iso) {
668        if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) {
669            log_msg(2,
670                    "catchall_mode --- iso_fiddly_bits returned w/ error");
671            return (1);
672        } else {
673            log_msg(2, "catchall_mode --- iso_fiddly_bits ok");
674        }
675    }
676
677    if (c == 'I') {
678        log_msg(2, "IM selected");
679        retval += interactive_mode(bkpinfo, mountlist, raidlist);
680    } else if (c == 'N') {
681        log_msg(2, "NM selected");
682        retval += nuke_mode(bkpinfo, mountlist, raidlist);
683    } else if (c == 'C') {
684        log_msg(2, "CM selected");
685        retval += compare_mode(bkpinfo, mountlist, raidlist);
686    }
687    paranoid_free(tmp);
688    return (retval);
689}
690
691/**************************************************************************
692 *END_CATCHALL_MODE                                                      *
693 **************************************************************************/
694
695/**************************************************************************
696 *END_  EXTRACT_CONFIG_FILE_FROM_RAMDISK                                  *
697 **************************************************************************/
698
699
700/**
701 * Locate an executable in the directory structure rooted at @p restg.
702 * @param out_path Where to put the executable.
703 * @param fname The basename of the executable.
704 * @param restg The directory structure to look in.
705 * @note If it could not be found in @p restg then @p fname is put in @p out_path.
706 * @ingroup restoreUtilityGroup
707 */
708void
709find_pathname_of_executable_preferably_in_RESTORING(char *out_path,
710                                                    char *fname,
711                                                    char *restg)
712{
713    assert(out_path != NULL);
714    assert_string_is_neither_NULL_nor_zerolength(fname);
715
716    sprintf(out_path, "%s/sbin/%s", restg, fname);
717    if (does_file_exist(out_path)) {
718        sprintf(out_path, "%s/usr/sbin/%s", restg, fname);
719        if (does_file_exist(out_path)) {
720            sprintf(out_path, "%s/bin/%s", restg, fname);
721            if (does_file_exist(out_path)) {
722                sprintf(out_path, "%s/usr/bin/%s", restg, fname);
723                if (does_file_exist(out_path)) {
724                    strcpy(out_path, fname);
725                }
726            }
727        }
728    }
729}
730
731/**************************************************************************
732 *END_FIND_PATHNAME_OF_EXECUTABLE_PREFERABLY_IN_RESTORING                 *
733 **************************************************************************/
734
735
736
737
738/**
739 * @addtogroup restoreGroup
740 * @{
741 */
742/**
743 * Restore the user's data, in a disaster recovery situation, prompting the
744 * user about whether or not to do every step.
745 * The user can edit the mountlist, choose files to restore, etc.
746 * @param bkpinfo The backup information structure. Most fields are used.
747 * @param mountlist The mountlist containing information about the user's partitions.
748 * @param raidlist The raidlist to go with @p mountlist.
749 * @return 0 for success, or the number of errors encountered.
750 */
751int
752interactive_mode(struct s_bkpinfo *bkpinfo,
753                 struct mountlist_itself *mountlist,
754                 struct raidlist_itself *raidlist)
755{
756    int retval = 0;
757    int res;
758    int ptn_errs = 0;
759    int fmt_errs = 0;
760
761    bool done;
762    bool restore_all;
763
764  /** needs malloc **********/
765    char *tmp;
766    char *fstab_fname;
767    char *old_restpath;
768
769    struct s_node *filelist;
770
771    /* try to partition and format */
772
773    log_msg(2, "interactive_mode --- starting (great, assertions OK)");
774
775    malloc_string(tmp);
776    malloc_string(fstab_fname);
777    malloc_string(old_restpath);
778    assert(bkpinfo != NULL);
779    assert(mountlist != NULL);
780    assert(raidlist != NULL);
781
782    log_msg(2, "interactive_mode --- assertions OK");
783
784    if (g_text_mode) {
785        if (!ask_me_yes_or_no
786            ("Interactive Mode + textonly = experimental! Proceed anyway?"))
787        {
788            fatal_error("Wise move.");
789        }
790    }
791
792    iamhere("About to load config file");
793    get_cfg_file_from_archive_or_bust(bkpinfo);
794    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
795    iamhere("Done loading config file; resizing ML");
796#ifdef __FreeBSD__
797    if (strstr
798        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
799         "noresize"))
800#else
801    if (strstr
802        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
803         "noresize"))
804#endif
805    {
806        log_msg(1, "Not resizing mountlist.");
807    } else {
808        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
809    }
810    for (done = FALSE; !done;) {
811        iamhere("About to edit mountlist");
812        if (g_text_mode) {
813            save_mountlist_to_disk(mountlist, g_mountlist_fname);
814            sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname);
815            res = system(tmp);
816            load_mountlist(mountlist, g_mountlist_fname);
817        } else {
818            res = edit_mountlist(g_mountlist_fname, mountlist, raidlist);
819        }
820        iamhere("Finished editing mountlist");
821        if (res) {
822            paranoid_MR_finish(1);
823        }
824        log_msg(2, "Proceeding...");
825        save_mountlist_to_disk(mountlist, g_mountlist_fname);
826        save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME);
827        mvaddstr_and_log_it(1, 30, "Restoring Interactively");
828        if (bkpinfo->differential) {
829            log_to_screen("Because this is a differential backup, disk");
830            log_to_screen
831                (" partitioning and formatting will not take place.");
832            done = TRUE;
833        } else {
834            if (ask_me_yes_or_no
835                ("Do you want to erase and partition your hard drives?")) {
836                if (partition_table_contains_Compaq_diagnostic_partition
837                    (mountlist)) {
838                    offer_to_abort_because_Compaq_Proliants_suck();
839                    done = TRUE;
840                } else {
841                    twenty_seconds_til_yikes();
842                    g_fprep = fopen("/tmp/prep.sh", "w");
843                    ptn_errs = partition_everything(mountlist);
844                    if (ptn_errs) {
845                        log_to_screen
846                            ("Warning. Errors occurred during disk partitioning.");
847                    }
848
849                    fmt_errs = format_everything(mountlist, FALSE);
850                    if (!fmt_errs) {
851                        log_to_screen
852                            ("Errors during disk partitioning were handled OK.");
853                        log_to_screen
854                            ("Partitions were formatted OK despite those errors.");
855                        ptn_errs = 0;
856                    }
857                    if (!ptn_errs && !fmt_errs) {
858                        done = TRUE;
859                    }
860                }
861                paranoid_fclose(g_fprep);
862            } else {
863                mvaddstr_and_log_it(g_currentY++, 0,
864                                    "User opted not to partition the devices");
865                if (ask_me_yes_or_no
866                    ("Do you want to format your hard drives?")) {
867                    fmt_errs = format_everything(mountlist, TRUE);
868                    if (!fmt_errs) {
869                        done = TRUE;
870                    }
871                } else {
872                    ptn_errs = fmt_errs = 0;
873                    done = TRUE;
874                }
875            }
876            if (fmt_errs) {
877                mvaddstr_and_log_it(g_currentY++,
878                                    0,
879                                    "Errors occurred. Please repartition and format drives manually.");
880                done = FALSE;
881            }
882            if (ptn_errs & !fmt_errs) {
883                mvaddstr_and_log_it(g_currentY++,
884                                    0,
885                                    "Errors occurred during partitioning. Formatting, however, went OK.");
886                done = TRUE;
887            }
888            if (!done) {
889                if (!ask_me_yes_or_no("Re-edit the mountlist?")) {
890                    retval++;
891                    goto end_of_func;
892                }
893            }
894        }
895    }
896
897    /* mount */
898    if (mount_all_devices(mountlist, TRUE)) {
899        unmount_all_devices(mountlist);
900        retval++;
901        goto end_of_func;
902    }
903    /* restore */
904    if ((restore_all =
905         ask_me_yes_or_no("Do you want me to restore all of your data?")))
906    {
907        log_msg(1, "Restoring all data");
908        retval += restore_everything(bkpinfo, NULL);
909    } else
910        if ((restore_all =
911             ask_me_yes_or_no
912             ("Do you want me to restore _some_ of your data?"))) {
913        strcpy(old_restpath, bkpinfo->restore_path);
914        for (done = FALSE; !done;) {
915            unlink("/tmp/filelist.full");
916            filelist = process_filelist_and_biggielist(bkpinfo);
917            /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these;
918               the former is a list of regular files; the latter, biggiefiles and imagedevs.
919             */
920            if (filelist) {
921              gotos_suck:
922                strcpy(tmp, old_restpath);
923// (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING);
924                if (popup_and_get_string
925                    ("Restore path", "Restore files to where?", tmp,
926                     MAX_STR_LEN / 4)) {
927                    if (!strcmp(tmp, "/")) {
928                        if (!ask_me_yes_or_no("Are you sure?")) {
929                            goto gotos_suck;
930                        }
931                        tmp[0] = '\0';  // so we restore to [blank]/file/name :)
932                    }
933                    strcpy(bkpinfo->restore_path, tmp);
934                    log_msg(1, "Restoring subset");
935                    retval += restore_everything(bkpinfo, filelist);
936                    free_filelist(filelist);
937                } else {
938                    strcpy(bkpinfo->restore_path, old_restpath);
939                    free_filelist(filelist);
940                }
941                if (!ask_me_yes_or_no
942                    ("Restore another subset of your backup?")) {
943                    done = TRUE;
944                }
945            } else {
946                done = TRUE;
947            }
948        }
949        strcpy(old_restpath, bkpinfo->restore_path);
950    } else {
951        mvaddstr_and_log_it(g_currentY++,
952                            0,
953                            "User opted not to restore any data.                                  ");
954    }
955    if (retval) {
956        mvaddstr_and_log_it(g_currentY++,
957                            0,
958                            "Errors occurred during the restore phase.            ");
959    }
960
961    if (ask_me_yes_or_no("Initialize the boot loader?")) {
962        run_boot_loader(TRUE);
963    } else {
964        mvaddstr_and_log_it(g_currentY++,
965                            0,
966                            "User opted not to initialize the boot loader.");
967    }
968
969//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
970    protect_against_braindead_sysadmins();
971    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
972    retval += unmount_all_devices(mountlist);
973    /*  if (restore_some || restore_all || */
974    if (ask_me_yes_or_no
975        ("Label your ext2 and ext3 partitions if necessary?")) {
976        mvaddstr_and_log_it(g_currentY, 0,
977                            "Using e2label to label your ext2,3 partitions");
978        if (does_file_exist("/tmp/fstab.new")) {
979            strcpy(fstab_fname, "/tmp/fstab.new");
980        } else {
981            strcpy(fstab_fname, "/tmp/fstab");
982        }
983        sprintf(tmp,
984                "label-partitions-as-necessary %s < %s >> %s 2>> %s",
985                g_mountlist_fname, fstab_fname, MONDO_LOGFILE,
986                MONDO_LOGFILE);
987        res = system(tmp);
988        if (res) {
989            log_to_screen
990                ("label-partitions-as-necessary returned an error");
991            mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
992        } else {
993            mvaddstr_and_log_it(g_currentY++, 74, "Done.");
994        }
995        retval += res;
996    }
997
998    iamhere("About to leave interactive_mode()");
999    if (retval) {
1000        mvaddstr_and_log_it(g_currentY++,
1001                            0,
1002                            "Warning - errors occurred during the restore phase.");
1003    }
1004  end_of_func:
1005    paranoid_free(tmp);
1006    paranoid_free(fstab_fname);
1007    paranoid_free(old_restpath);
1008    iamhere("Leaving interactive_mode()");
1009    return (retval);
1010}
1011
1012/**************************************************************************
1013 *END_INTERACTIVE_MODE                                                    *
1014 **************************************************************************/
1015
1016
1017
1018/**
1019 * Run an arbitrary restore mode (prompt the user), but from ISO images
1020 * instead of real media.
1021 * @param bkpinfo The backup information structure. Most fields are used.
1022 * @param mountlist The mountlist containing information about the user's partitions.
1023 * @param raidlist The raidlist that goes with @p mountlist.
1024 * @param nuke_me_please If TRUE, we plan to run Nuke Mode.
1025 * @return 0 for success, or the number of errors encountered.
1026 */
1027int
1028iso_mode(struct s_bkpinfo *bkpinfo,
1029         struct mountlist_itself *mountlist,
1030         struct raidlist_itself *raidlist, bool nuke_me_please)
1031{
1032    char c;
1033    int retval = 0;
1034
1035    assert(bkpinfo != NULL);
1036    assert(mountlist != NULL);
1037    assert(raidlist != NULL);
1038    if (iso_fiddly_bits(bkpinfo, nuke_me_please)) {
1039        log_msg(1, "iso_mode --- returning w/ error");
1040        return (1);
1041    } else {
1042        c = which_restore_mode();
1043        if (c == 'I' || c == 'N' || c == 'C') {
1044            interactively_obtain_media_parameters_from_user(bkpinfo,
1045                                                            FALSE);
1046        }
1047        if (c == 'I') {
1048            retval += interactive_mode(bkpinfo, mountlist, raidlist);
1049        } else if (c == 'N') {
1050            retval += nuke_mode(bkpinfo, mountlist, raidlist);
1051        } else if (c == 'C') {
1052            retval += compare_mode(bkpinfo, mountlist, raidlist);
1053        } else {
1054            log_to_screen("OK, I shan't restore/compare any files.");
1055        }
1056    }
1057    if (is_this_device_mounted(MNT_CDROM)) {
1058        paranoid_system("umount " MNT_CDROM);
1059    }
1060//  if (! already_mounted)
1061//    {
1062    if (system("umount /tmp/isodir 2> /dev/null")) {
1063        log_to_screen
1064            ("WARNING - unable to unmount device where the ISO files are stored.");
1065    }
1066//    }
1067    return (retval);
1068}
1069
1070/**************************************************************************
1071 *END_ISO_MODE                                                            *
1072 **************************************************************************/
1073
1074
1075/*            MONDO - saving your a$$ since Feb 18th, 2000            */
1076
1077
1078
1079
1080/**
1081 * Restore the user's data automatically (no prompts), after a twenty-second
1082 * warning period.
1083 * @param bkpinfo The backup information structure. Most fields are used.
1084 * @param mountlist The mountlist containing information about the user's partitions.
1085 * @param raidlist The raidlist that goes with @p mountlist.
1086 * @return 0 for success, or the number of errors encountered.
1087 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b>
1088 */
1089int
1090nuke_mode(struct s_bkpinfo *bkpinfo,
1091          struct mountlist_itself *mountlist,
1092          struct raidlist_itself *raidlist)
1093{
1094    int retval = 0;
1095    int res = 0;
1096    bool boot_loader_installed = FALSE;
1097  /** malloc **/
1098    char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN],
1099        tmpC[MAX_STR_LEN];
1100
1101    assert(bkpinfo != NULL);
1102    assert(mountlist != NULL);
1103    assert(raidlist != NULL);
1104
1105    log_msg(2, "nuke_mode --- starting");
1106
1107    get_cfg_file_from_archive_or_bust(bkpinfo);
1108    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo updated the mountlist
1109#ifdef __FreeBSD__
1110    if (strstr
1111        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
1112         "noresize"))
1113#else
1114    if (strstr
1115        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
1116         "noresize"))
1117#endif
1118    {
1119        log_msg(2, "Not resizing mountlist.");
1120    } else {
1121        resize_mountlist_proportionately_to_suit_new_drives(mountlist);
1122    }
1123    if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) {
1124        sprintf(tmp,
1125                "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?",
1126                tmpA, tmpB, tmpC);
1127        if (ask_me_yes_or_no(tmp)) {
1128            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1129            finish(retval);
1130        } else {
1131            fatal_error("Nuke Mode aborted. ");
1132        }
1133    }
1134    save_mountlist_to_disk(mountlist, g_mountlist_fname);
1135    mvaddstr_and_log_it(1, 30, "Restoring Automatically");
1136    if (bkpinfo->differential) {
1137        log_to_screen("Because this is a differential backup, disk");
1138        log_to_screen("partitioning and formatting will not take place.");
1139        res = 0;
1140    } else {
1141        if (partition_table_contains_Compaq_diagnostic_partition
1142            (mountlist)) {
1143            offer_to_abort_because_Compaq_Proliants_suck();
1144        } else {
1145            twenty_seconds_til_yikes();
1146            g_fprep = fopen("/tmp/prep.sh", "w");
1147#ifdef __FreeBSD__
1148            if (strstr
1149                (call_program_and_get_last_line_of_output
1150                 ("cat /tmp/cmdline"), "nopart"))
1151#else
1152            if (strstr
1153                (call_program_and_get_last_line_of_output
1154                 ("cat /proc/cmdline"), "nopart"))
1155#endif
1156            {
1157                log_msg(2,
1158                        "Not partitioning drives due to 'nopart' option.");
1159                res = 0;
1160            } else {
1161                res = partition_everything(mountlist);
1162                if (res) {
1163                    log_to_screen
1164                        ("Warning. Errors occurred during partitioning.");
1165                    res = 0;
1166                }
1167            }
1168            retval += res;
1169            if (!res) {
1170                log_to_screen("Preparing to format your disk(s)");
1171                sleep(1);
1172                system("sync");
1173                log_to_screen("Please wait. This may take a few minutes.");
1174                res += format_everything(mountlist, FALSE);
1175            }
1176            paranoid_fclose(g_fprep);
1177        }
1178    }
1179    retval += res;
1180    if (res) {
1181        mvaddstr_and_log_it(g_currentY++,
1182                            0,
1183                            "Failed to partition and/or format your hard drives.");
1184
1185        if (ask_me_yes_or_no("Try in interactive mode instead?")) {
1186            retval = interactive_mode(bkpinfo, mountlist, raidlist);
1187            goto after_the_nuke;
1188        } else
1189            if (!ask_me_yes_or_no
1190                ("Would you like to try to proceed anyway?")) {
1191            return (retval);
1192        }
1193    }
1194    retval = mount_all_devices(mountlist, TRUE);
1195    if (retval) {
1196        unmount_all_devices(mountlist);
1197        log_to_screen
1198            ("Unable to mount all partitions. Sorry, I cannot proceed.");
1199        return (retval);
1200    }
1201    iamhere("Restoring everything");
1202    retval += restore_everything(bkpinfo, NULL);
1203    if (!run_boot_loader(FALSE)) {
1204        log_msg(1,
1205                "Great! Boot loader was installed. No need for msg at end.");
1206        boot_loader_installed = TRUE;
1207    }
1208    protect_against_braindead_sysadmins();
1209//  run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1);
1210    //  modify_rclocal_one_time( MNT_RESTORING "/etc" );
1211    retval += unmount_all_devices(mountlist);
1212    mvaddstr_and_log_it(g_currentY,
1213                        0,
1214                        "Using e2label to label your ext2,3 partitions");
1215
1216    sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab",
1217            g_mountlist_fname);
1218    res = run_program_and_log_output(tmp, TRUE);
1219    if (res) {
1220        log_to_screen("label-partitions-as-necessary returned an error");
1221        mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1222    } else {
1223        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1224    }
1225    retval += res;
1226
1227  after_the_nuke:
1228    if (retval) {
1229        log_to_screen("Errors occurred during the nuke phase.");
1230    } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE"))    // Bruno's thing
1231    {
1232        log_to_screen
1233            ("PC was restored successfully. Thank you for using Mondo Rescue.");
1234        log_to_screen
1235            ("Please visit http://www.mondorescue.org and thank the dev team.");
1236    } else {
1237#ifdef FREELOADER
1238        success_message();
1239#else
1240        log_to_screen("PC was restored successfully!");
1241#endif
1242    }
1243    g_I_have_just_nuked = TRUE;
1244/*
1245  if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE))
1246    {
1247      log_to_screen("PLEASE RUN 'mondorestore --mbr' NOW TO INITIALIZE YOUR BOOT SECTOR");
1248      write_one_liner_data_file(DO_MBR_PLEASE, "mondorestore --mbr");
1249    }
1250*/
1251    return (retval);
1252}
1253
1254/**************************************************************************
1255 *END_NUKE_MODE                                                           *
1256 **************************************************************************/
1257
1258
1259
1260/**
1261 * Restore the user's data (or a subset of it) to the live filesystem.
1262 * This should not be called if we're booted from CD!
1263 * @param bkpinfo The backup information structure. Most fields are used.
1264 * @return 0 for success, or the number of errors encountered.
1265 */
1266int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo)
1267{
1268    int retval = 0;
1269
1270  /** malloc **/
1271    char *old_restpath;
1272
1273    struct mountlist_itself *mountlist;
1274//  static
1275    struct raidlist_itself *raidlist;
1276    struct s_node *filelist;
1277
1278    log_msg(1, "restore_to_live_filesystem() - starting");
1279    assert(bkpinfo != NULL);
1280    malloc_string(old_restpath);
1281    mountlist = malloc(sizeof(struct mountlist_itself));
1282    raidlist = malloc(sizeof(struct raidlist_itself));
1283    if (!mountlist || !raidlist) {
1284        fatal_error("Cannot malloc() mountlist and/or raidlist");
1285    }
1286
1287    strcpy(bkpinfo->restore_path, "/");
1288    if (!g_restoring_live_from_cd) {
1289        popup_and_OK
1290            ("Please insert tape/CD/boot floppy, then hit 'OK' to continue.");
1291        sleep(1);
1292    }
1293    interactively_obtain_media_parameters_from_user(bkpinfo, FALSE);
1294    log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
1295    if (!bkpinfo->media_device[0]) {
1296        log_msg(2, "Warning - failed to find media dev");
1297    }
1298
1299
1300    log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir);
1301
1302    open_evalcall_form("Thinking...");
1303
1304    get_cfg_file_from_archive_or_bust(bkpinfo);
1305    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
1306    load_mountlist(mountlist, g_mountlist_fname);   // in case read_cfg_file_into_bkpinfo
1307
1308    close_evalcall_form();
1309    retval = load_mountlist(mountlist, g_mountlist_fname);
1310    load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
1311    filelist = process_filelist_and_biggielist(bkpinfo);
1312    if (filelist) {
1313        save_filelist(filelist, "/tmp/selected-files.txt");
1314        strcpy(old_restpath, bkpinfo->restore_path);
1315        if (popup_and_get_string("Restore path",
1316                                 "Restore files to where? )",
1317                                 bkpinfo->restore_path, MAX_STR_LEN / 4)) {
1318            iamhere("Restoring everything");
1319            retval += restore_everything(bkpinfo, filelist);
1320            free_filelist(filelist);
1321            strcpy(bkpinfo->restore_path, old_restpath);
1322        } else {
1323            free_filelist(filelist);
1324        }
1325        strcpy(bkpinfo->restore_path, old_restpath);
1326    }
1327    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1328        log_msg(2,
1329                "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway.");
1330    }
1331    run_program_and_log_output("umount " MNT_CDROM, FALSE);
1332    if (!bkpinfo->please_dont_eject) {
1333        eject_device(bkpinfo->media_device);
1334    }
1335    paranoid_free(old_restpath);
1336    free(mountlist);
1337    free(raidlist);
1338    return (retval);
1339}
1340
1341/**************************************************************************
1342 *END_RESTORE_TO_LIVE_FILESYSTEM                                          *
1343 **************************************************************************/
1344
1345/* @} - end of restoreGroup */
1346
1347
1348#include <utime.h>
1349/**
1350 * @addtogroup LLrestoreGroup
1351 * @{
1352 */
1353/**
1354 * Restore biggiefile @p bigfileno from the currently mounted CD.
1355 * @param bkpinfo The backup information structure. Fields used:
1356 * - @c bkpinfo->backup_media_type
1357 * - @c bkpinfo->restore_path
1358 * @param bigfileno The biggiefile number (starting from 0) to restore.
1359 * @param filelist The node structure containing the list of files to restore.
1360 * If the biggiefile is not in this list, it will be skipped (return value will
1361 * still indicate success).
1362 * @return 0 for success (or skip), nonzero for failure.
1363 */
1364int
1365restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo,
1366                             long bigfileno,
1367                             struct s_node *filelist,
1368                             char *pathname_of_last_file_restored)
1369{
1370    FILE *fin;
1371    FILE *fout;
1372    FILE *fbzip2;
1373
1374  /** malloc ***/
1375    char *checksum, *outfile_fname, *tmp, *bzip2_command,
1376        *partimagehack_command, *suffix, *sz_devfile;
1377    char *bigblk;
1378    char *p;
1379    int retval = 0;
1380    int finished = FALSE;
1381    long sliceno;
1382    long siz;
1383    char partimagehack_fifo[MAX_STR_LEN];
1384    char *file_to_openout = NULL;
1385    struct s_filename_and_lstat_info biggiestruct;
1386    struct utimbuf the_utime_buf, *ubuf;
1387    bool use_partimage_hack = FALSE;
1388    pid_t pid;
1389    int res = 0;
1390    int old_loglevel;
1391    char sz_msg[MAX_STR_LEN];
1392    struct s_node *node;
1393
1394    old_loglevel = g_loglevel;
1395    ubuf = &the_utime_buf;
1396    assert(bkpinfo != NULL);
1397
1398    malloc_string(checksum);
1399    malloc_string(outfile_fname);
1400    malloc_string(tmp);
1401    malloc_string(bzip2_command);
1402    malloc_string(partimagehack_command);
1403    malloc_string(suffix);
1404    malloc_string(sz_devfile);
1405
1406    pathname_of_last_file_restored[0] = '\0';
1407    if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) {
1408        fatal_error("Cannot malloc bigblk");
1409    }
1410
1411    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
1412        log_to_screen("Cannot even open bigfile's info file");
1413        return (1);
1414    }
1415
1416    memset((void *) &biggiestruct, 0, sizeof(biggiestruct));
1417    if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) <
1418        sizeof(biggiestruct)) {
1419        log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d",
1420                bigfileno + 1);
1421    }
1422    paranoid_fclose(fin);
1423
1424    strcpy(checksum, biggiestruct.checksum);
1425
1426    if (!checksum[0]) {
1427        sprintf(tmp, "Warning - bigfile %ld does not have a checksum",
1428                bigfileno + 1);
1429        log_msg(3, tmp);
1430        p = checksum;
1431    }
1432
1433    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
1434    {
1435        strcpy(outfile_fname, biggiestruct.filename);
1436    } else {
1437        sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1438                biggiestruct.filename);
1439    }
1440
1441    /* skip file if we have a selective restore subset & it doesn't match */
1442    if (filelist != NULL) {
1443        node = find_string_at_node(filelist, biggiestruct.filename);
1444        if (!node) {
1445            log_msg(0, "Skipping %s (name isn't in filelist)",
1446                    biggiestruct.filename);
1447            pathname_of_last_file_restored[0] = '\0';
1448            return (0);
1449        } else if (!(node->selected)) {
1450            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1451                    biggiestruct.filename);
1452            pathname_of_last_file_restored[0] = '\0';
1453            return (0);
1454        }
1455    }
1456    /* otherwise, continue */
1457
1458    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
1459    if (biggiestruct.use_partimagehack) {
1460        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
1461            log_msg(1,
1462                    "I was in error when I set biggiestruct.use_partimagehack to TRUE.");
1463            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
1464            biggiestruct.use_partimagehack = FALSE;
1465        }
1466    }
1467
1468    if (biggiestruct.use_partimagehack) // if it's an NTFS device
1469//  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
1470    {
1471        g_loglevel = 4;
1472        use_partimage_hack = TRUE;
1473        log_msg(2,
1474                "Calling partimagehack in background because %s is an NTFS /dev entry",
1475                outfile_fname);
1476        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1477                (int) (random() % 32768));
1478        mkfifo(sz_devfile, 0x770);
1479        strcpy(partimagehack_fifo, sz_devfile);
1480        file_to_openout = partimagehack_fifo;
1481        switch (pid = fork()) {
1482        case -1:
1483            fatal_error("Fork failure");
1484        case 0:
1485            log_msg(3,
1486                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
1487                    biggiestruct.filename, partimagehack_fifo);
1488            res =
1489                feed_outfrom_partimage(biggiestruct.filename,
1490                                       partimagehack_fifo);
1491//          log_msg(3, "CHILD - fip - exiting");
1492            exit(res);
1493            break;
1494        default:
1495            log_msg(3,
1496                    "feed_into_partimage() called in background --- pid=%ld",
1497                    (long int) (pid));
1498        }
1499    } else {
1500        use_partimage_hack = FALSE;
1501        partimagehack_fifo[0] = '\0';
1502        file_to_openout = outfile_fname;
1503        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1504        {
1505            make_hole_for_file(outfile_fname);
1506        }
1507    }
1508
1509    sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1,
1510            outfile_fname);
1511    log_msg(2, tmp);
1512
1513    /*
1514       last slice is zero-length and uncompressed; when we find it, we stop.
1515       We DON'T wait until there are no more slices; if we did that,
1516       We might stop at end of CD, not at last slice (which is 0-len and uncompd)
1517     */
1518
1519    strncpy(pathname_of_last_file_restored, biggiestruct.filename,
1520            MAX_STR_LEN - 1);
1521    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1522
1523    log_msg(3, "file_to_openout = %s", file_to_openout);
1524    if (!(fout = fopen(file_to_openout, "w"))) {
1525        log_to_screen("Cannot openout outfile_fname - hard disk full?");
1526        return (1);
1527    }
1528    log_msg(3, "Opened out to %s", outfile_fname);  // CD/DVD --> mondorestore --> partimagehack --> hard disk itself
1529
1530    for (sliceno = 1, finished = FALSE; !finished;) {
1531        if (!does_file_exist
1532            (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
1533            &&
1534            !does_file_exist(slice_fname
1535                             (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
1536            &&
1537            !does_file_exist(slice_fname
1538                             (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1539            log_msg(3,
1540                    "Cannot find a data slice or terminator slice on CD %d",
1541                    g_current_media_number);
1542            g_current_media_number++;
1543            sprintf(tmp,
1544                    "Asking for %s #%d so that I may read slice #%ld\n",
1545                    media_descriptor_string(bkpinfo->backup_media_type),
1546                    g_current_media_number, sliceno);
1547            log_msg(2, tmp);
1548            sprintf(tmp, "Restoring from %s #%d",
1549                    media_descriptor_string(bkpinfo->backup_media_type),
1550                    g_current_media_number);
1551            log_to_screen(tmp);
1552            insist_on_this_cd_number(bkpinfo, g_current_media_number);
1553            log_to_screen("Continuing to restore.");
1554        } else {
1555            strcpy(tmp,
1556                   slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
1557            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
1558                log_msg(2,
1559                        "End of bigfile # %ld (slice %ld is the terminator)",
1560                        bigfileno + 1, sliceno);
1561                finished = TRUE;
1562                continue;
1563            } else {
1564                if (does_file_exist
1565                    (slice_fname
1566                     (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
1567                    strcpy(bzip2_command, "lzop");
1568                    strcpy(suffix, "lzo");
1569                } else
1570                    if (does_file_exist
1571                        (slice_fname
1572                         (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
1573                    strcpy(bzip2_command, "bzip2");
1574                    strcpy(suffix, "bz2");
1575                } else
1576                    if (does_file_exist
1577                        (slice_fname
1578                         (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
1579                    strcpy(bzip2_command, "");
1580                    strcpy(suffix, "");
1581                } else {
1582                    log_to_screen("OK, that's pretty fsck0red...");
1583                    return (1);
1584                }
1585            }
1586            if (bzip2_command[0] != '\0') {
1587                sprintf(bzip2_command + strlen(bzip2_command),
1588                        " -dc %s 2>> %s",
1589                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1590                                    suffix), MONDO_LOGFILE);
1591            } else {
1592                sprintf(bzip2_command, "cat %s 2>> %s",
1593                        slice_fname(bigfileno, sliceno, ARCHIVES_PATH,
1594                                    suffix), MONDO_LOGFILE);
1595            }
1596            sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ",
1597                    media_descriptor_string(bkpinfo->backup_media_type),
1598                    g_current_media_number, bigfileno + 1, sliceno);
1599            log_msg(2, tmp);
1600
1601            if (!g_text_mode) {
1602                newtDrawRootText(0, g_noof_rows - 2, tmp);
1603                newtRefresh();
1604                strip_spaces(tmp);
1605                update_progress_form(tmp);
1606            }
1607            if (!(fbzip2 = popen(bzip2_command, "r"))) {
1608                fatal_error("Can't run popen command");
1609            }
1610            while (!feof(fbzip2)) {
1611                siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2);
1612                if (siz > 0) {
1613                    sprintf(sz_msg, "Read %ld from fbzip2", siz);
1614                    siz = fwrite(bigblk, 1, siz, fout);
1615                    sprintf(sz_msg + strlen(sz_msg),
1616                            "; written %ld to fout", siz);
1617//        log_msg(2. sz_msg);
1618                }
1619            }
1620            paranoid_pclose(fbzip2);
1621
1622
1623            sliceno++;
1624            g_current_progress++;
1625        }
1626    }
1627/*
1628  memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy...
1629  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1630  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1631  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1632  fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout);
1633*/
1634    paranoid_fclose(fout);
1635    g_loglevel = old_loglevel;
1636
1637    if (use_partimage_hack) {
1638        log_msg(3, "Waiting for partimage to finish");
1639        sprintf(tmp,
1640                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
1641        while (system(tmp) == 0) {
1642            sleep(1);
1643        }
1644        log_it("OK, partimage has really finished");
1645    }
1646
1647    if (strcmp(outfile_fname, "/dev/null")) {
1648        chown(outfile_fname, biggiestruct.properties.st_uid,
1649              biggiestruct.properties.st_gid);
1650        chmod(outfile_fname, biggiestruct.properties.st_mode);
1651        ubuf->actime = biggiestruct.properties.st_atime;
1652        ubuf->modtime = biggiestruct.properties.st_mtime;
1653        utime(outfile_fname, ubuf);
1654    }
1655    paranoid_free(bigblk);
1656    paranoid_free(checksum);
1657    paranoid_free(outfile_fname);
1658    paranoid_free(tmp);
1659    paranoid_free(bzip2_command);
1660    paranoid_free(partimagehack_command);
1661    paranoid_free(suffix);
1662    paranoid_free(sz_devfile);
1663
1664    return (retval);
1665}
1666
1667/**************************************************************************
1668 *END_ RESTORE_A_BIGGIEFILE_FROM_CD                                       *
1669 **************************************************************************/
1670
1671
1672
1673/**
1674 * Restore a biggiefile from the currently opened stream.
1675 * @param bkpinfo The backup information structure. Fields used:
1676 * - @c bkpinfo->restore_path
1677 * - @c bkpinfo->zip_exe
1678 * @param orig_bf_fname The original filename of the biggiefile.
1679 * @param biggiefile_number The number of the biggiefile (starting from 0).
1680 * @param orig_checksum Unused.
1681 * @param biggiefile_size Unused.
1682 * @param filelist The node structure containing the list of files to be restored.
1683 * If @p orig_bf_fname is not in the list, it will be ignored.
1684 * @return 0 for success (or skip), nonzero for failure.
1685 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL).
1686 */
1687int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum,   //UNUSED
1688                                     long long biggiefile_size, //UNUSED
1689                                     struct s_node *filelist,
1690                                     int use_partimagehack,
1691                                     char *pathname_of_last_file_restored)
1692{
1693    FILE *pout;
1694    FILE *fin;
1695
1696  /** mallocs ********/
1697    char *tmp;
1698    char *command;
1699    char *outfile_fname;
1700    char *partimagehack_command;
1701    char *sz_devfile;
1702    char *partimagehack_fifo;
1703    char *file_to_openout = NULL;
1704
1705    struct s_node *node;
1706
1707    int old_loglevel;
1708    long current_slice_number = 0;
1709    int retval = 0;
1710    int res = 0;
1711    int ctrl_chr = '\0';
1712    long long slice_siz;
1713    bool dummy_restore = FALSE;
1714    bool use_partimage_hack = FALSE;
1715    pid_t pid;
1716    struct s_filename_and_lstat_info biggiestruct;
1717    struct utimbuf the_utime_buf, *ubuf;
1718    ubuf = &the_utime_buf;
1719
1720    malloc_string(tmp);
1721    malloc_string(partimagehack_fifo);
1722    malloc_string(outfile_fname);
1723    malloc_string(command);
1724    malloc_string(sz_devfile);
1725    malloc_string(partimagehack_command);
1726    old_loglevel = g_loglevel;
1727    assert(bkpinfo != NULL);
1728    assert(orig_bf_fname != NULL);
1729    assert(orig_checksum != NULL);
1730
1731    pathname_of_last_file_restored[0] = '\0';
1732    if (use_partimagehack == BLK_START_A_PIHBIGGIE) {
1733        use_partimagehack = 1;
1734        log_msg(1, "%s --- pih=YES", orig_bf_fname);
1735    } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) {
1736        use_partimagehack = 0;
1737        log_msg(1, "%s --- pih=NO", orig_bf_fname);
1738    } else {
1739        use_partimagehack = 0;
1740        log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname);
1741    }
1742
1743    strncpy(pathname_of_last_file_restored, orig_bf_fname,
1744            MAX_STR_LEN - 1);
1745    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
1746
1747    /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */
1748
1749    if (filelist != NULL) {
1750        node = find_string_at_node(filelist, orig_bf_fname);
1751        if (!node) {
1752            dummy_restore = TRUE;
1753            log_msg(1,
1754                    "Skipping big file %ld (%s) - not in biggielist subset",
1755                    biggiefile_number + 1, orig_bf_fname);
1756            pathname_of_last_file_restored[0] = '\0';
1757        } else if (!(node->selected)) {
1758            dummy_restore = TRUE;
1759            log_msg(1, "Skipping %s (name isn't in biggielist subset)",
1760                    orig_bf_fname);
1761            pathname_of_last_file_restored[0] = '\0';
1762        }
1763    }
1764
1765    if (use_partimagehack) {
1766        if (strncmp(orig_bf_fname, "/dev/", 5)) {
1767            log_msg(1,
1768                    "I was in error when I set use_partimagehack to TRUE.");
1769            log_msg(1, "%s isn't even in /dev", orig_bf_fname);
1770            use_partimagehack = FALSE;
1771        }
1772    }
1773
1774    if (use_partimagehack) {
1775        g_loglevel = 4;
1776        strcpy(outfile_fname, orig_bf_fname);
1777        use_partimage_hack = TRUE;
1778        log_msg(2,
1779                "Calling partimagehack in background because %s is a /dev entry",
1780                outfile_fname);
1781        sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768),
1782                (int) (random() % 32768));
1783        mkfifo(sz_devfile, 0x770);
1784        strcpy(partimagehack_fifo, sz_devfile);
1785        file_to_openout = partimagehack_fifo;
1786        switch (pid = fork()) {
1787        case -1:
1788            fatal_error("Fork failure");
1789        case 0:
1790            log_msg(3,
1791                    "CHILD - fip - calling feed_outfrom_partimage(%s, %s)",
1792                    outfile_fname, partimagehack_fifo);
1793            res =
1794                feed_outfrom_partimage(outfile_fname, partimagehack_fifo);
1795//          log_msg(3, "CHILD - fip - exiting");
1796            exit(res);
1797            break;
1798        default:
1799            log_msg(3,
1800                    "feed_into_partimage() called in background --- pid=%ld",
1801                    (long int) (pid));
1802        }
1803    } else {
1804        if (!strncmp(orig_bf_fname, "/dev/", 5))    // non-NTFS partition
1805        {
1806            strcpy(outfile_fname, orig_bf_fname);
1807        } else                  // biggiefile
1808        {
1809            sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path,
1810                    orig_bf_fname);
1811        }
1812        use_partimage_hack = FALSE;
1813        partimagehack_fifo[0] = '\0';
1814        file_to_openout = outfile_fname;
1815        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
1816        {
1817            make_hole_for_file(outfile_fname);
1818        }
1819        sprintf(tmp, "Reassembling big file %ld (%s)",
1820                biggiefile_number + 1, orig_bf_fname);
1821        log_msg(2, tmp);
1822    }
1823
1824    if (dummy_restore) {
1825        sprintf(outfile_fname, "/dev/null");
1826    }
1827
1828    if (!bkpinfo->zip_exe[0]) {
1829        sprintf(command, "cat > \"%s\"", file_to_openout);
1830    } else {
1831        sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe,
1832                file_to_openout, MONDO_LOGFILE);
1833    }
1834    sprintf(tmp, "Pipe command = '%s'", command);
1835    log_msg(3, tmp);
1836
1837    /* restore biggiefile, one slice at a time */
1838    if (!(pout = popen(command, "w"))) {
1839        fatal_error("Cannot pipe out");
1840    }
1841    for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1842         ctrl_chr != BLK_STOP_A_BIGGIE;
1843         res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) {
1844        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
1845            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
1846        }
1847        sprintf(tmp, "Working on file #%ld, slice #%ld    ",
1848                biggiefile_number + 1, current_slice_number);
1849        log_msg(2, tmp);
1850        if (!g_text_mode) {
1851            newtDrawRootText(0, g_noof_rows - 2, tmp);
1852            newtRefresh();
1853        }
1854        strip_spaces(tmp);
1855        update_progress_form(tmp);
1856        if (current_slice_number == 0) {
1857            res =
1858                read_file_from_stream_to_file(bkpinfo,
1859                                              "/tmp/biggie-blah.txt",
1860                                              slice_siz);
1861            if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) {
1862                log_OS_error("blah blah");
1863            } else {
1864                if (fread
1865                    ((void *) &biggiestruct, 1, sizeof(biggiestruct),
1866                     fin) < sizeof(biggiestruct)) {
1867                    log_msg(2,
1868                            "Warning - unable to get biggiestruct of bigfile #%d",
1869                            biggiefile_number + 1);
1870                }
1871                paranoid_fclose(fin);
1872            }
1873        } else {
1874            res =
1875                read_file_from_stream_to_stream(bkpinfo, pout, slice_siz);
1876        }
1877        retval += res;
1878        res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr);
1879        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
1880            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
1881        }
1882        current_slice_number++;
1883        g_current_progress++;
1884    }
1885    paranoid_pclose(pout);
1886
1887    log_msg(1, "pathname_of_last_file_restored is now %s",
1888            pathname_of_last_file_restored);
1889
1890    if (use_partimage_hack) {
1891        log_msg(3, "Waiting for partimage to finish");
1892        sprintf(tmp,
1893                " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null");
1894        while (system(tmp) == 0) {
1895            sleep(1);
1896        }
1897        log_msg(3, "OK, partimage has really finished");
1898    }
1899
1900    log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename);
1901    log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum);
1902    if (strcmp(outfile_fname, "/dev/null")) {
1903        chmod(outfile_fname, biggiestruct.properties.st_mode);
1904        chown(outfile_fname, biggiestruct.properties.st_uid,
1905              biggiestruct.properties.st_gid);
1906        ubuf->actime = biggiestruct.properties.st_atime;
1907        ubuf->modtime = biggiestruct.properties.st_mtime;
1908        utime(outfile_fname, ubuf);
1909    }
1910
1911    paranoid_free(tmp);
1912    paranoid_free(outfile_fname);
1913    paranoid_free(command);
1914    paranoid_free(partimagehack_command);
1915    paranoid_free(sz_devfile);
1916    paranoid_free(partimagehack_fifo);
1917    g_loglevel = old_loglevel;
1918    return (retval);
1919}
1920
1921/**************************************************************************
1922 *END_RESTORE_A_BIGGIEFILE_FROM_STREAM                                    *
1923 **************************************************************************/
1924
1925
1926
1927/**
1928 * Restore @p tarball_fname from CD.
1929 * @param tarball_fname The filename of the tarball to restore (in /mnt/cdrom).
1930 * This will be used unmodified.
1931 * @param current_tarball_number The number (starting from 0) of the fileset
1932 * we're restoring now.
1933 * @param filelist The node structure containing the list of files to be
1934 * restored. If no file in the afioball is in this list, afio will still be
1935 * called, but nothing will be written.
1936 * @return 0 for success, nonzero for failure.
1937 */
1938int
1939restore_a_tarball_from_CD(char *tarball_fname,
1940                          long current_tarball_number,
1941                          struct s_node *filelist)
1942{
1943    int retval = 0;
1944    int res;
1945    char *p;
1946
1947  /** malloc **/
1948    char *command;
1949    char *tmp;
1950    char *filelist_name;
1951    char *filelist_subset_fname;
1952    char *executable;
1953    char *temp_log;
1954    char screen_message[100];
1955    long matches = 0;
1956    bool use_star;
1957    char *xattr_fname;
1958    char *acl_fname;
1959//  char files_to_restore_this_time_fname[MAX_STR_LEN];
1960
1961    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
1962    malloc_string(command);
1963    malloc_string(tmp);
1964    malloc_string(filelist_name);
1965    malloc_string(filelist_subset_fname);
1966    malloc_string(executable);
1967    malloc_string(temp_log);
1968    malloc_string(xattr_fname);
1969    malloc_string(acl_fname);
1970
1971    log_msg(5, "Entering");
1972    filelist_subset_fname[0] = '\0';
1973    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
1974//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
1975    sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
1976    run_program_and_log_output(command, 9);
1977    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
1978            (int) (random() % 32768));
1979
1980    sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld",
1981            current_tarball_number);
1982    if (length_of_file(filelist_name) <= 2) {
1983        log_msg(2, "There are _zero_ files in filelist '%s'",
1984                filelist_name);
1985        log_msg(2,
1986                "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)");
1987        log_msg(2,
1988                "but it's non-critical. It's cosmetic. Don't worry about it.");
1989        retval = 0;
1990        goto leave_sub;
1991    }
1992    if (count_lines_in_file(filelist_name) <= 0
1993        || length_of_file(tarball_fname) <= 0) {
1994        log_msg(3, "length_of_file(%s) = %ld", tarball_fname,
1995                length_of_file(tarball_fname));
1996        sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)",
1997                current_tarball_number);
1998        log_to_screen(tmp);
1999        retval = 1;
2000        goto leave_sub;
2001    }
2002
2003    if (filelist) {
2004        sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp",
2005                current_tarball_number);
2006        if ((matches =
2007             save_filelist_entries_in_common(filelist_name, filelist,
2008                                             filelist_subset_fname,
2009                                             use_star))
2010            <= 0) {
2011            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2012            log_msg(1, tmp);
2013        } else {
2014            log_msg(3, "Saved fileset %ld's subset to %s",
2015                    current_tarball_number, filelist_subset_fname);
2016        }
2017        sprintf(screen_message, "Tarball #%ld --- %ld matches",
2018                current_tarball_number, matches);
2019        log_to_screen(screen_message);
2020    } else {
2021        filelist_subset_fname[0] = '\0';
2022    }
2023
2024    if (filelist == NULL || matches > 0) {
2025        sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ,
2026                MNT_CDROM "/archives", current_tarball_number);
2027        sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives",
2028                current_tarball_number);
2029        if (strstr(tarball_fname, ".bz2")) {
2030            strcpy(executable, "bzip2");
2031        } else if (strstr(tarball_fname, ".lzo")) {
2032            strcpy(executable, "lzop");
2033        } else {
2034            executable[0] = '\0';
2035        }
2036        if (executable[0]) {
2037            sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable);
2038            if (run_program_and_log_output(tmp, FALSE)) {
2039                log_to_screen
2040                    ("(compare_a_tarball) Compression program not found - oh no!");
2041                paranoid_MR_finish(1);
2042            }
2043            strcpy(tmp, executable);
2044            sprintf(executable, "-P %s -Z", tmp);
2045        }
2046#ifdef __FreeBSD__
2047#define BUFSIZE 512
2048#else
2049#define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE
2050#endif
2051
2052//      if (strstr(tarball_fname, ".star."))
2053        if (use_star) {
2054            sprintf(command,
2055                    "star -x -force-remove -U " STAR_ACL_SZ
2056                    " errctl= file=%s", tarball_fname);
2057            if (strstr(tarball_fname, ".bz2")) {
2058                strcat(command, " -bz");
2059            }
2060        } else {
2061            if (filelist_subset_fname[0] != '\0') {
2062                sprintf(command,
2063                        "afio -i -M 8m -b %ld -c %ld %s -w %s %s",
2064                        TAPE_BLOCK_SIZE,
2065                        BUFSIZE, executable, filelist_subset_fname,
2066//             files_to_restore_this_time_fname,
2067                        tarball_fname);
2068            } else {
2069                sprintf(command,
2070                        "afio -i -b %ld -c %ld -M 8m %s %s",
2071                        TAPE_BLOCK_SIZE,
2072                        BUFSIZE, executable, tarball_fname);
2073            }
2074        }
2075#undef BUFSIZE
2076        sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
2077                temp_log);
2078        log_msg(1, "command = '%s'", command);
2079        unlink(temp_log);
2080        res = system(command);
2081        if (res) {
2082            p = strstr(command, "-acl ");
2083            if (p) {
2084                p[0] = p[1] = p[2] = p[3] = ' ';
2085                log_msg(1, "new command = '%s'", command);
2086                res = system(command);
2087            }
2088        }
2089        if (res && length_of_file(temp_log) < 5) {
2090            res = 0;
2091        }
2092
2093        log_msg(1, "Setting fattr list %s", xattr_fname);
2094        if (length_of_file(xattr_fname) > 0) {
2095            res = set_fattr_list(filelist_subset_fname, xattr_fname);
2096            if (res) {
2097                log_to_screen
2098                    ("Errors occurred while setting extended attributes");
2099            } else {
2100                log_msg(1, "I set xattr OK");
2101            }
2102            retval += res;
2103        }
2104        if (length_of_file(acl_fname) > 0) {
2105            log_msg(1, "Setting acl list %s", acl_fname);
2106            res = set_acl_list(filelist_subset_fname, acl_fname);
2107            if (res) {
2108                log_to_screen
2109                    ("Errors occurred while setting access control lists");
2110            } else {
2111                log_msg(1, "I set ACL OK");
2112            }
2113            retval += res;
2114        }
2115        if (retval) {
2116            sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
2117            system(command);
2118            log_msg(2, "Errors occurred while processing fileset #%d",
2119                    current_tarball_number);
2120        } else {
2121            log_msg(2, "Fileset #%d processed OK", current_tarball_number);
2122        }
2123    }
2124    if (does_file_exist("/PAUSE")) {
2125        popup_and_OK
2126            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2127    }
2128    unlink(filelist_subset_fname);
2129    unlink(xattr_fname);
2130    unlink(acl_fname);
2131    unlink(temp_log);
2132
2133  leave_sub:
2134    paranoid_free(command);
2135    paranoid_free(tmp);
2136    paranoid_free(filelist_name);
2137    paranoid_free(filelist_subset_fname);
2138    paranoid_free(executable);
2139    paranoid_free(temp_log);
2140    paranoid_free(xattr_fname);
2141    paranoid_free(acl_fname);
2142    log_msg(5, "Leaving");
2143    return (retval);
2144}
2145
2146/**************************************************************************
2147 *END_RESTORE_A_TARBALL_FROM_CD                                           *
2148 **************************************************************************/
2149
2150
2151/**
2152 * Restore a tarball from the currently opened stream.
2153 * @param bkpinfo The backup information structure. Fields used:
2154 * - @c bkpinfo->backup_media_type
2155 * - @c bkpinfo->media_device
2156 * - @c bkpinfo->zip_exe
2157 * @param tarball_fname The filename of the afioball to restore.
2158 * @param current_tarball_number The number (starting from 0) of the fileset
2159 * we're restoring now.
2160 * @param filelist The node structure containing the list of files to be
2161 * restored. If no file in the afioball is in this list, afio will still be
2162 * called, but nothing will be written.
2163 * @param size The size (in @b bytes) of the afioball.
2164 * @return 0 for success, nonzero for failure.
2165 */
2166int
2167restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo,
2168                              char *tarball_fname,
2169                              long current_tarball_number,
2170                              struct s_node *filelist,
2171                              long long size, char *xattr_fname,
2172                              char *acl_fname)
2173{
2174    int retval = 0;
2175    int res = 0;
2176
2177  /** malloc add ***/
2178    char *tmp;
2179    char *command;
2180    char *afio_fname;
2181    char *filelist_fname;
2182    char *filelist_subset_fname;
2183    char *executable;
2184    long matches = 0;
2185    bool restore_this_fileset = FALSE;
2186    bool use_star;
2187
2188    assert(bkpinfo != NULL);
2189    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
2190    malloc_string(filelist_subset_fname);
2191    malloc_string(filelist_fname);
2192    malloc_string(afio_fname);
2193    malloc_string(executable);
2194    malloc_string(command);
2195    malloc_string(tmp);
2196    filelist_subset_fname[0] = '\0';
2197    /* to do it with a file... */
2198    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
2199    sprintf(tmp,
2200            "Restoring from fileset #%ld (%ld KB) on %s #%d",
2201            current_tarball_number, (long) size >> 10,
2202            media_descriptor_string(bkpinfo->backup_media_type),
2203            g_current_media_number);
2204    log_msg(2, tmp);
2205    run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE);
2206
2207  /****************************************************************************
2208   * Use RAMDISK's /tmp; saves time; oh wait, it's too small                  *
2209   * Well, pipe from tape to afio, then; oh wait, can't do that either: bug   *
2210   * in afio or someting; oh darn.. OK, use tmpfs :-)                         *
2211   ****************************************************************************/
2212    filelist_fname[0] = filelist_subset_fname[0] = '\0';
2213    sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld",
2214            current_tarball_number);
2215    sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir,
2216            current_tarball_number);
2217    sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp",
2218            bkpinfo->tmpdir, current_tarball_number);
2219//  sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number);
2220    res = read_file_from_stream_to_file(bkpinfo, afio_fname, size);
2221    if (strstr(tarball_fname, ".star")) {
2222        bkpinfo->use_star = TRUE;
2223    }
2224    if (res) {
2225        log_msg(1, "Warning - error reading afioball from tape");
2226    }
2227    if (bkpinfo->compression_level == 0) {
2228        executable[0] = '\0';
2229    } else {
2230        if (bkpinfo->use_star) {
2231            strcpy(executable, " -bz");
2232        } else {
2233            sprintf(executable, "-P %s -Z", bkpinfo->zip_exe);
2234        }
2235    }
2236
2237    if (!filelist)              // if unconditional restore then restore entire fileset
2238    {
2239        restore_this_fileset = TRUE;
2240    } else                      // If restoring selectively then get TOC from tarball
2241    {
2242        if (strstr(tarball_fname, ".star.")) {
2243            use_star = TRUE;
2244            sprintf(command, "star -t file=%s %s", afio_fname, executable);
2245        } else {
2246            use_star = FALSE;
2247            sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE,
2248                    executable, afio_fname);
2249        }
2250        sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname,
2251                MONDO_LOGFILE);
2252        log_msg(1, "command = %s", command);
2253        if (system(command)) {
2254            log_msg(4, "Warning - error occurred while retrieving TOC");
2255        }
2256        if ((matches =
2257             save_filelist_entries_in_common(filelist_fname, filelist,
2258                                             filelist_subset_fname,
2259                                             use_star))
2260            <= 0 || length_of_file(filelist_subset_fname) < 2) {
2261            if (length_of_file(filelist_subset_fname) < 2) {
2262                log_msg(1, "No matches found in fileset %ld",
2263                        current_tarball_number);
2264            }
2265            sprintf(tmp, "Skipping fileset %ld", current_tarball_number);
2266            log_msg(2, tmp);
2267            restore_this_fileset = FALSE;
2268        } else {
2269            log_msg(5, "%ld matches. Saved fileset %ld's subset to %s",
2270                    matches, current_tarball_number,
2271                    filelist_subset_fname);
2272            restore_this_fileset = TRUE;
2273        }
2274    }
2275
2276// Concoct the call to star/afio to restore files
2277    if (strstr(tarball_fname, ".star."))    // star
2278    {
2279        sprintf(command, "star -x file=%s %s", afio_fname, executable);
2280        if (filelist) {
2281            sprintf(command + strlen(command), " list=%s",
2282                    filelist_subset_fname);
2283        }
2284    } else                      // afio
2285    {
2286        sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE,
2287                executable);
2288        if (filelist) {
2289            sprintf(command + strlen(command), " -w %s",
2290                    filelist_subset_fname);
2291        }
2292        sprintf(command + strlen(command), " %s", afio_fname);
2293    }
2294    sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
2295
2296// Call if IF there are files to restore (selectively/unconditionally)
2297    if (restore_this_fileset) {
2298        log_msg(1, "Calling command='%s'", command);
2299        paranoid_system(command);
2300
2301        iamhere("Restoring xattr, acl stuff");
2302        res = set_fattr_list(filelist_subset_fname, xattr_fname);
2303        if (res) {
2304            log_msg(1, "Errors occurred while setting xattr");
2305        } else {
2306            log_msg(1, "I set xattr OK");
2307        }
2308        retval += res;
2309
2310        res = set_acl_list(filelist_subset_fname, acl_fname);
2311        if (res) {
2312            log_msg(1, "Errors occurred while setting ACL");
2313        } else {
2314            log_msg(1, "I set ACL OK");
2315        }
2316        retval += res;
2317
2318    } else {
2319        log_msg(1, "NOT CALLING '%s'", command);
2320    }
2321
2322    if (does_file_exist("/PAUSE") && current_tarball_number >= 50) {
2323        log_to_screen("Paused after set %ld", current_tarball_number);
2324        popup_and_OK("Pausing. Press ENTER to continue.");
2325    }
2326
2327    unlink(filelist_subset_fname);
2328    unlink(filelist_fname);
2329    unlink(afio_fname);
2330
2331    paranoid_free(filelist_subset_fname);
2332    paranoid_free(filelist_fname);
2333    paranoid_free(afio_fname);
2334    paranoid_free(command);
2335    paranoid_free(tmp);
2336    return (retval);
2337}
2338
2339/**************************************************************************
2340 *END_RESTORE_A_TARBALL_FROM_STREAM                                       *
2341 **************************************************************************/
2342
2343
2344
2345
2346/**
2347 * Restore all biggiefiles from all media in this CD backup.
2348 * The CD with the last afioball should be currently mounted.
2349 * @param bkpinfo The backup information structure. @c backup_media_type is the
2350 * only field used in this function.
2351 * @param filelist The node structure containing the list of files to be
2352 * restored. If a prospective biggiefile is not in this list, it will be ignored.
2353 * @return 0 for success, nonzero for failure.
2354 */
2355int
2356restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo,
2357                                struct s_node *filelist)
2358{
2359    int retval = 0;
2360    int res;
2361    long noof_biggiefiles, bigfileno = 0, total_slices;
2362  /** malloc **/
2363    char *tmp;
2364    bool just_changed_cds = FALSE, finished;
2365    char *xattr_fname;
2366    char *acl_fname;
2367    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2368    char *pathname_of_last_biggie_restored;
2369    FILE *fbw = NULL;
2370
2371    malloc_string(xattr_fname);
2372    malloc_string(acl_fname);
2373    malloc_string(tmp);
2374    malloc_string(biggies_whose_EXATs_we_should_set);
2375    malloc_string(pathname_of_last_biggie_restored);
2376    assert(bkpinfo != NULL);
2377
2378    sprintf(biggies_whose_EXATs_we_should_set,
2379            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2380    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2381        log_msg(1, "Warning - cannot openout %s",
2382                biggies_whose_EXATs_we_should_set);
2383    }
2384
2385    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2386    total_slices = atol(tmp);
2387    sprintf(tmp, "Reassembling large files      ");
2388    mvaddstr_and_log_it(g_currentY, 0, tmp);
2389    if (length_of_file(BIGGIELIST) < 6) {
2390        log_msg(1, "OK, no biggielist; not restoring biggiefiles");
2391        return (0);
2392    }
2393    noof_biggiefiles = count_lines_in_file(BIGGIELIST);
2394    if (noof_biggiefiles <= 0) {
2395        log_msg(2,
2396                "OK, no biggiefiles in biggielist; not restoring biggiefiles");
2397        return (0);
2398    }
2399    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2400            noof_biggiefiles);
2401    log_msg(2, tmp);
2402
2403    open_progress_form("Reassembling large files",
2404                       "I am now reassembling all the large files.",
2405                       "Please wait. This may take some time.",
2406                       "", total_slices);
2407    for (bigfileno = 0, finished = FALSE; !finished;) {
2408        log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1);
2409        if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) {
2410            log_msg(3,
2411                    "...but its first slice isn't on this CD. Perhaps this was a selective restore?");
2412            log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d",
2413                    bigfileno + 1,
2414                    media_descriptor_string(bkpinfo->backup_media_type),
2415                    g_current_media_number);
2416            log_msg(3, "Slicename would have been %s",
2417                    slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, ""));
2418            // I'm not positive 'just_changed_cds' is even necessary...
2419            if (just_changed_cds) {
2420                just_changed_cds = FALSE;
2421                log_msg(3,
2422                        "I'll continue to scan this CD for bigfiles to be restored.");
2423            } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) {
2424                insist_on_this_cd_number(bkpinfo,
2425                                         ++g_current_media_number);
2426                sprintf(tmp, "Restoring from %s #%d",
2427                        media_descriptor_string(bkpinfo->
2428                                                backup_media_type),
2429                        g_current_media_number);
2430                log_to_screen(tmp);
2431                just_changed_cds = TRUE;
2432            } else {
2433                log_msg(2, "There was no bigfile #%ld. That's OK.",
2434                        bigfileno + 1);
2435                log_msg(2, "I'm going to stop restoring bigfiles now.");
2436                finished = TRUE;
2437            }
2438        } else {
2439            just_changed_cds = FALSE;
2440            sprintf(tmp, "Restoring big file %ld", bigfileno + 1);
2441            update_progress_form(tmp);
2442            res =
2443                restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist,
2444                                             pathname_of_last_biggie_restored);
2445            iamhere(pathname_of_last_biggie_restored);
2446            if (fbw && pathname_of_last_biggie_restored[0]) {
2447                fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2448            }
2449            retval += res;
2450            bigfileno++;
2451
2452        }
2453    }
2454
2455    if (fbw) {
2456        fclose(fbw);
2457        sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2458        sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH);
2459        if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) {
2460            set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2461        }
2462        if (length_of_file(xattr_fname) > 0
2463            && find_home_of_exe("setfattr")) {
2464            set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname);
2465        }
2466    }
2467    if (does_file_exist("/PAUSE")) {
2468        popup_and_OK
2469            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2470    }
2471    close_progress_form();
2472    if (retval) {
2473        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2474    } else {
2475        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2476    }
2477    paranoid_free(xattr_fname);
2478    paranoid_free(acl_fname);
2479    paranoid_free(tmp);
2480    paranoid_free(biggies_whose_EXATs_we_should_set);
2481    paranoid_free(pathname_of_last_biggie_restored);
2482    return (retval);
2483}
2484
2485/**************************************************************************
2486 *END_RESTORE_ALL_BIGGIFILES_FROM_CD                                      *
2487 **************************************************************************/
2488
2489
2490
2491/**
2492 * Restore all afioballs from all CDs in the backup.
2493 * The first CD should be inserted (if not, it will be asked for).
2494 * @param bkpinfo The backup information structure. @c backup_media_type is the
2495 * only field used in @e this function.
2496 * @param filelist The node structure containing the list of files to be
2497 * restored. If no file in some particular afioball is in this list, afio will
2498 * still be called for that fileset, but nothing will be written.
2499 * @return 0 for success, or the number of filesets that failed.
2500 */
2501int
2502restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo,
2503                             struct s_node *filelist)
2504{
2505    int retval = 0;
2506    int res;
2507    int attempts;
2508    long current_tarball_number = 0;
2509    long max_val;
2510  /**malloc ***/
2511    char *tmp;
2512    char *tarball_fname;
2513    char *progress_str;
2514    char *comment;
2515
2516    malloc_string(tmp);
2517    malloc_string(tarball_fname);
2518    malloc_string(progress_str);
2519    malloc_string(comment);
2520
2521    assert(bkpinfo != NULL);
2522
2523    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2524    log_msg(2,
2525            "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER");
2526    if (g_current_media_number != 1) {
2527        log_msg(3, "OK, that's jacked up.");
2528        g_current_media_number = 1;
2529    }
2530    insist_on_this_cd_number(bkpinfo, g_current_media_number);
2531    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2532    max_val = atol(tmp) + 1;
2533    sprintf(progress_str, "Restoring from %s #%d",
2534            media_descriptor_string(bkpinfo->backup_media_type),
2535            g_current_media_number);
2536    log_to_screen(progress_str);
2537    open_progress_form("Restoring from archives",
2538                       "Restoring data from the archives.",
2539                       "Please wait. This may take some time.",
2540                       progress_str, max_val);
2541    for (;;) {
2542        insist_on_this_cd_number(bkpinfo, g_current_media_number);
2543        update_progress_form(progress_str);
2544        sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2",
2545                current_tarball_number);
2546        if (!does_file_exist(tarball_fname)) {
2547            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo",
2548                    current_tarball_number);
2549        }
2550        if (!does_file_exist(tarball_fname)) {
2551            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.",
2552                    current_tarball_number);
2553        }
2554        if (!does_file_exist(tarball_fname)) {
2555            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2",
2556                    current_tarball_number);
2557        }
2558        if (!does_file_exist(tarball_fname)) {
2559            sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.",
2560                    current_tarball_number);
2561        }
2562        if (!does_file_exist(tarball_fname)) {
2563            if (current_tarball_number == 0) {
2564                log_to_screen
2565                    ("No tarballs. Strange. Maybe you only backed up freakin' big files?");
2566                return (0);
2567            }
2568            if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")
2569                || system("find " MNT_CDROM
2570                          "/archives/slice* > /dev/null 2> /dev/null") ==
2571                0) {
2572                break;
2573            }
2574            g_current_media_number++;
2575            sprintf(progress_str, "Restoring from %s #%d",
2576                    media_descriptor_string(bkpinfo->backup_media_type),
2577                    g_current_media_number);
2578            log_to_screen(progress_str);
2579        } else {
2580            sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2581                    current_tarball_number,
2582                    media_descriptor_string(bkpinfo->backup_media_type),
2583                    g_current_media_number);
2584//    log_msg(3, "progress_str = %s", progress_str);
2585            for (res = 999, attempts = 0; attempts < 3 && res != 0;
2586                 attempts++) {
2587                res =
2588                    restore_a_tarball_from_CD(tarball_fname,
2589                                              current_tarball_number,
2590                                              filelist);
2591            }
2592            sprintf(tmp, "%s #%d, fileset #%ld - restore ",
2593                    media_descriptor_string(bkpinfo->backup_media_type),
2594                    g_current_media_number, current_tarball_number);
2595            if (res) {
2596                strcat(tmp, "reported errors");
2597            } else if (attempts > 1) {
2598                strcat(tmp, "succeeded");
2599            } else {
2600                strcat(tmp, "succeeded");
2601            }
2602            if (attempts > 1) {
2603                sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
2604                        attempts);
2605            }
2606            strcpy(comment, tmp);
2607            if (attempts > 1) {
2608                log_to_screen(comment);
2609            }
2610
2611            retval += res;
2612            current_tarball_number++;
2613            g_current_progress++;
2614        }
2615    }
2616    close_progress_form();
2617    if (retval) {
2618        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2619    } else {
2620        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2621    }
2622    paranoid_free(tmp);
2623    paranoid_free(tarball_fname);
2624    paranoid_free(progress_str);
2625    paranoid_free(comment);
2626
2627    return (retval);
2628}
2629
2630/**************************************************************************
2631 *END_RESTORE_ALL_TARBALLS_FROM_CD                                        *
2632 **************************************************************************/
2633
2634
2635
2636/**
2637 * Restore all biggiefiles from the currently opened stream.
2638 * @param bkpinfo The backup information structure. Passed to other functions.
2639 * @param filelist The node structure containing the list of files to be
2640 * restored. If a prospective biggiefile is not in the list, it will be ignored.
2641 * @return 0 for success, or the number of biggiefiles that failed.
2642 */
2643int
2644restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo,
2645                                    struct s_node *filelist)
2646{
2647    long noof_biggiefiles;
2648    long current_bigfile_number = 0;
2649    long total_slices;
2650
2651    int retval = 0;
2652    int res = 0;
2653    int ctrl_chr;
2654
2655  /** malloc add ****/
2656    char *tmp;
2657    char *biggie_fname;
2658    char *biggie_cksum;
2659    char *xattr_fname;
2660    char *acl_fname;
2661    char *p;
2662    char *pathname_of_last_biggie_restored;
2663    char *biggies_whose_EXATs_we_should_set;    // EXtended ATtributes
2664    long long biggie_size;
2665    FILE *fbw = NULL;
2666
2667    malloc_string(tmp);
2668    malloc_string(biggie_fname);
2669    malloc_string(biggie_cksum);
2670    malloc_string(xattr_fname);
2671    malloc_string(acl_fname);
2672    malloc_string(biggies_whose_EXATs_we_should_set);
2673    malloc_string(pathname_of_last_biggie_restored);
2674    assert(bkpinfo != NULL);
2675
2676    read_cfg_var(g_mondo_cfg_file, "total-slices", tmp);
2677
2678    total_slices = atol(tmp);
2679    sprintf(tmp, "Reassembling large files      ");
2680    sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2681    sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2682    mvaddstr_and_log_it(g_currentY, 0, tmp);
2683    sprintf(biggies_whose_EXATs_we_should_set,
2684            "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir);
2685    if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) {
2686        log_msg(1, "Warning - cannot openout %s",
2687                biggies_whose_EXATs_we_should_set);
2688    }
2689// get xattr and acl files if they're there
2690    res =
2691        read_header_block_from_stream(&biggie_size, biggie_fname,
2692                                      &ctrl_chr);
2693    if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2694        res =
2695            read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname,
2696                                      &ctrl_chr, xattr_fname, acl_fname);
2697    }
2698
2699    noof_biggiefiles = atol(biggie_fname);
2700    sprintf(tmp, "OK, there are %ld biggiefiles in the archives",
2701            noof_biggiefiles);
2702    log_msg(2, tmp);
2703    open_progress_form("Reassembling large files",
2704                       "I am now reassembling all the large files.",
2705                       "Please wait. This may take some time.",
2706                       "", total_slices);
2707
2708    for (res =
2709         read_header_block_from_stream(&biggie_size, biggie_fname,
2710                                       &ctrl_chr);
2711         ctrl_chr != BLK_STOP_BIGGIEFILES;
2712         res =
2713         read_header_block_from_stream(&biggie_size, biggie_fname,
2714                                       &ctrl_chr)) {
2715        if (ctrl_chr != BLK_START_A_NORMBIGGIE
2716            && ctrl_chr != BLK_START_A_PIHBIGGIE) {
2717            wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr);
2718        }
2719        p = strrchr(biggie_fname, '/');
2720        if (!p) {
2721            p = biggie_fname;
2722        } else {
2723            p++;
2724        }
2725        sprintf(tmp, "Restoring big file %ld (%lld K)",
2726                current_bigfile_number + 1, biggie_size / 1024);
2727        update_progress_form(tmp);
2728        res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname,
2729                                               current_bigfile_number,
2730                                               biggie_cksum,
2731                                               biggie_size,
2732                                               filelist, ctrl_chr,
2733                                               pathname_of_last_biggie_restored);
2734        log_msg(1, "I believe I have restored %s",
2735                pathname_of_last_biggie_restored);
2736        if (fbw && pathname_of_last_biggie_restored[0]) {
2737            fprintf(fbw, "%s\n", pathname_of_last_biggie_restored);
2738        }
2739        retval += res;
2740        current_bigfile_number++;
2741
2742    }
2743    if (current_bigfile_number != noof_biggiefiles
2744        && noof_biggiefiles != 0) {
2745        sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",
2746                current_bigfile_number, noof_biggiefiles);
2747    } else {
2748        sprintf(tmp,
2749                "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.",
2750                noof_biggiefiles, current_bigfile_number);
2751    }
2752    log_msg(1, tmp);
2753
2754    if (fbw) {
2755        fclose(fbw);
2756        if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) {
2757            iamhere("Setting biggie-EXATs");
2758            if (length_of_file(acl_fname) > 0) {
2759                log_msg(1, "set_acl_list(%s,%s)",
2760                        biggies_whose_EXATs_we_should_set, acl_fname);
2761                set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname);
2762            }
2763            if (length_of_file(xattr_fname) > 0) {
2764                log_msg(1, "set_fattr_List(%s,%s)",
2765                        biggies_whose_EXATs_we_should_set, xattr_fname);
2766                set_fattr_list(biggies_whose_EXATs_we_should_set,
2767                               xattr_fname);
2768            }
2769        } else {
2770            iamhere
2771                ("No biggiefiles selected. So, no biggie-EXATs to set.");
2772        }
2773    }
2774    if (does_file_exist("/PAUSE")) {
2775        popup_and_OK
2776            ("Press ENTER to go on. Delete /PAUSE to stop these pauses.");
2777    }
2778
2779    close_progress_form();
2780    if (retval) {
2781        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2782    } else {
2783        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2784    }
2785    paranoid_free(biggies_whose_EXATs_we_should_set);
2786    paranoid_free(pathname_of_last_biggie_restored);
2787    paranoid_free(biggie_fname);
2788    paranoid_free(biggie_cksum);
2789    paranoid_free(xattr_fname);
2790    paranoid_free(acl_fname);
2791    paranoid_free(tmp);
2792    return (retval);
2793}
2794
2795/**************************************************************************
2796 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM                                 *
2797 **************************************************************************/
2798
2799
2800
2801
2802
2803
2804/**
2805 * Restore all afioballs from the currently opened tape stream.
2806 * @param bkpinfo The backup information structure. Fields used:
2807 * - @c bkpinfo->backup_media_type
2808 * - @c bkpinfo->restore_path
2809 * @param filelist The node structure containing the list of files to be
2810 * restored. If no file in an afioball is in this list, afio will still be
2811 * called for that fileset, but nothing will be written.
2812 * @return 0 for success, or the number of filesets that failed.
2813 */
2814int
2815restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo,
2816                                 struct s_node *filelist)
2817{
2818    int retval = 0;
2819    int res;
2820    long current_afioball_number = 0;
2821    int ctrl_chr;
2822    long max_val /*, total_noof_files */ ;
2823
2824  /** malloc **/
2825    char *tmp;
2826    char *progress_str;
2827    char *tmp_fname;
2828    char *xattr_fname;
2829    char *acl_fname;
2830
2831    long long tmp_size;
2832
2833    malloc_string(tmp);
2834    malloc_string(progress_str);
2835    malloc_string(tmp_fname);
2836    assert(bkpinfo != NULL);
2837    malloc_string(xattr_fname);
2838    malloc_string(acl_fname);
2839    mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives");
2840    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
2841    max_val = atol(tmp) + 1;
2842
2843    chdir(bkpinfo->restore_path);   /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */
2844
2845    run_program_and_log_output("pwd", 5);
2846
2847    sprintf(progress_str, "Restoring from media #%d",
2848            g_current_media_number);
2849    log_to_screen(progress_str);
2850    open_progress_form("Restoring from archives",
2851                       "Restoring data from the archives.",
2852                       "Please wait. This may take some time.",
2853                       progress_str, max_val);
2854
2855    log_msg(3, "hey");
2856
2857    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2858    if (res) {
2859        log_msg(2, "Warning - error reading afioball from tape");
2860    }
2861    retval += res;
2862    if (ctrl_chr != BLK_START_AFIOBALLS) {
2863        wrong_marker(BLK_START_AFIOBALLS, ctrl_chr);
2864    }
2865    log_msg(2, "ho");
2866    res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2867    while (ctrl_chr != BLK_STOP_AFIOBALLS) {
2868        update_progress_form(progress_str);
2869        sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir,
2870                current_afioball_number);
2871        sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir,
2872                current_afioball_number);
2873        unlink(xattr_fname);
2874        unlink(acl_fname);
2875        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
2876            iamhere("Reading EXAT files from tape");
2877            res =
2878                read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname,
2879                                          &ctrl_chr, xattr_fname,
2880                                          acl_fname);
2881        }
2882        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
2883            wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
2884        }
2885        sprintf(tmp,
2886                "Restoring from fileset #%ld (name=%s, size=%ld K)",
2887                current_afioball_number, tmp_fname, (long) tmp_size >> 10);
2888        res =
2889            restore_a_tarball_from_stream(bkpinfo, tmp_fname,
2890                                          current_afioball_number,
2891                                          filelist, tmp_size, xattr_fname,
2892                                          acl_fname);
2893        retval += res;
2894        if (res) {
2895            sprintf(tmp, "Fileset %ld - errors occurred",
2896                    current_afioball_number);
2897            log_to_screen(tmp);
2898        }
2899        res =
2900            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2901        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
2902            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
2903        }
2904
2905        current_afioball_number++;
2906        g_current_progress++;
2907        sprintf(progress_str, "Restoring from fileset #%ld on %s #%d",
2908                current_afioball_number,
2909                media_descriptor_string(bkpinfo->backup_media_type),
2910                g_current_media_number);
2911        res =
2912            read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr);
2913        unlink(xattr_fname);
2914        unlink(acl_fname);
2915    }                           // next
2916    log_msg(1, "All done with afioballs");
2917    close_progress_form();
2918    if (retval) {
2919        mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2920    } else {
2921        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2922    }
2923    paranoid_free(tmp);
2924    paranoid_free(progress_str);
2925    paranoid_free(tmp_fname);
2926    paranoid_free(xattr_fname);
2927    paranoid_free(acl_fname);
2928    return (retval);
2929}
2930
2931/**************************************************************************
2932 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM                                   *
2933 **************************************************************************/
2934
2935/* @} - end of LLrestoreGroup */
2936
2937
2938/**
2939 * Restore all files in @p filelist.
2940 * @param bkpinfo The backup information structure. Most fields are used.
2941 * @param filelist The node structure containing the list of files to be
2942 * restored.
2943 * @return 0 for success, or the number of afioballs and biggiefiles that failed.
2944 * @ingroup restoreGroup
2945 */
2946int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist)
2947{
2948    int resA;
2949    int resB;
2950
2951  /** mallco ***/
2952    char *cwd;
2953    char *newpath;
2954    char *tmp;
2955    assert(bkpinfo != NULL);
2956
2957    malloc_string(cwd);
2958    malloc_string(newpath);
2959    malloc_string(tmp);
2960    log_msg(2, "restore_everything() --- starting");
2961    g_current_media_number = 1;
2962    getcwd(cwd, MAX_STR_LEN - 1);
2963    sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path);
2964    run_program_and_log_output(tmp, FALSE);
2965    log_msg(1, "Changing dir to %s", bkpinfo->restore_path);
2966    chdir(bkpinfo->restore_path);
2967    getcwd(newpath, MAX_STR_LEN - 1);
2968    log_msg(1, "path is now %s", newpath);
2969    log_msg(1, "restoring everything");
2970    if (!find_home_of_exe("petris") && !g_text_mode) {
2971        newtDrawRootText(0, g_noof_rows - 2,
2972                         "Press ALT-<left cursor> twice to play Petris :-) ");
2973        newtRefresh();
2974    }
2975    mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives");
2976    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2977        mount_cdrom(bkpinfo);
2978        mvaddstr_and_log_it(g_currentY++, 0,
2979                            "Restoring OS and data from streaming media");
2980        if (bkpinfo->backup_media_type == cdstream) {
2981            openin_cdstream(bkpinfo);
2982        } else {
2983            assert_string_is_neither_NULL_nor_zerolength(bkpinfo->
2984                                                         media_device);
2985            openin_tape(bkpinfo);
2986        }
2987        resA = restore_all_tarballs_from_stream(bkpinfo, filelist);
2988        resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist);
2989        if (bkpinfo->backup_media_type == cdstream) {
2990            closein_cdstream(bkpinfo);
2991        } else {
2992            closein_tape(bkpinfo);
2993        }
2994    } else {
2995        mvaddstr_and_log_it(g_currentY++, 0,
2996                            "Restoring OS and data from CD       ");
2997        mount_cdrom(bkpinfo);
2998        resA = restore_all_tarballs_from_CD(bkpinfo, filelist);
2999        resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist);
3000    }
3001    chdir(cwd);
3002    if (resA + resB) {
3003        log_to_screen("Errors occurred while data was being restored.");
3004    }
3005    if (length_of_file("/etc/raidtab") > 0) {
3006        log_msg(2, "Copying local raidtab to restored filesystem");
3007        run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING
3008                                   "/etc/raidtab", FALSE);
3009    }
3010    kill_petris();
3011    log_msg(2, "restore_everything() --- leaving");
3012    paranoid_free(cwd);
3013    paranoid_free(newpath);
3014    paranoid_free(tmp);
3015    return (resA + resB);
3016}
3017
3018/**************************************************************************
3019 *END_RESTORE_EVERYTHING                                                  *
3020 **************************************************************************/
3021
3022
3023
3024/**
3025 * @brief Haha. You wish! (This function is not implemented :-)
3026 */
3027int
3028restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo,
3029                                 char *monitas_device,
3030                                 char *restore_this_directory,
3031                                 char *restore_here)
3032     /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */
3033{
3034    FILE *fout;
3035    int retval = 0;
3036    int i;
3037    int j;
3038    struct mountlist_itself the_mountlist;
3039    static struct raidlist_itself the_raidlist;
3040  /** malloc **/
3041    char tmp[MAX_STR_LEN + 1];
3042    char command[MAX_STR_LEN + 1];
3043    char datablock[256 * 1024];
3044    char datadisks_fname[MAX_STR_LEN + 1];
3045    long k;
3046    long length;
3047    long long llt;
3048    struct s_node *filelist = NULL;
3049    assert(bkpinfo != NULL);
3050    assert_string_is_neither_NULL_nor_zerolength(monitas_device);
3051    assert(restore_this_directory != NULL);
3052    assert(restore_here != NULL);
3053
3054    sprintf(tmp, "restore_here = '%s'", restore_here);
3055
3056    log_msg(2, tmp);
3057
3058    log_msg(2, "restore_live_from_monitas_server() - starting");
3059    unlink("/tmp/mountlist.txt");
3060    unlink("/tmp/filelist.full");
3061    unlink("/tmp/biggielist.txt");
3062    if (restore_here[0] == '\0') {
3063        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3064    } else {
3065        strcpy(bkpinfo->restore_path, restore_here);
3066    }
3067    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3068    sprintf(tmp, "FYI - data will be restored to %s",
3069            bkpinfo->restore_path);
3070    log_msg(3, tmp);
3071    log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI");
3072    sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d",
3073            (int) (random() % 32768));
3074    chdir(bkpinfo->tmpdir);
3075
3076    sprintf(command, "cat %s", monitas_device);
3077    g_tape_stream = popen(command, "r");    // for compatibility with openin_tape()
3078    if (!(fout = fopen(datadisks_fname, "w"))) {
3079        log_OS_error(datadisks_fname);
3080        return (1);
3081    }
3082    for (i = 0; i < 32; i++) {
3083        for (j = 0; j < 4; j++) {
3084            for (length = k = 0; length < 256 * 1024; length += k) {
3085                k = fread(datablock + length, 1, 256 * 1024 - length,
3086                          g_tape_stream);
3087            }
3088            fwrite(datablock, 1, length, fout);
3089            g_tape_posK += length;
3090        }
3091    }
3092    paranoid_fclose(fout);
3093    sprintf(command,
3094            "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt",
3095            datadisks_fname);
3096    run_program_and_log_output(command, 4);
3097    read_header_block_from_stream(&llt, tmp, &i);
3098    read_header_block_from_stream(&llt, tmp, &i);
3099
3100    unlink(datadisks_fname);
3101    read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3102    retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo   strcpy(bkpinfo->media_device, monitas_device);
3103
3104
3105    load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME);
3106    iamhere("FIXME");
3107    fatal_error("This will fail");
3108    sprintf(command,
3109            "cat %s | grep -x \"%s.*\" > %s",
3110            g_filelist_full, restore_this_directory, g_filelist_full);
3111    if (system(command)) {
3112        retval++;
3113        log_to_screen
3114            ("Error(s) occurred while processing filelist and wildcard");
3115    }
3116    iamhere("FIXME");
3117    fatal_error("This will fail");
3118    sprintf(command,
3119            "cat %s | grep -x \"%s.*\" > %s",
3120            g_biggielist_txt, restore_this_directory, g_biggielist_txt);
3121    if (system(command)) {
3122        log_msg(1,
3123                "Error(s) occurred while processing biggielist and wildcard");
3124    }
3125    sprintf(command, "touch %s", g_biggielist_txt);
3126    run_program_and_log_output(command, FALSE);
3127//  filelist = load_filelist(g_filelist_restthese);  // FIXME --- this probably doesn't work because it doesn't include the biggiefiles
3128    retval += restore_everything(bkpinfo, filelist);
3129    free_filelist(filelist);
3130    log_msg(2, "--------End of restore_live_from_monitas_server--------");
3131    return (retval);
3132}
3133
3134/**************************************************************************
3135 *END_RESTORE_LIVE_FROM_MONITAS_SERVER                                    *
3136 **************************************************************************/
3137
3138
3139
3140
3141extern void wait_until_software_raids_are_prepped(char *, int);
3142
3143
3144char which_restore_mode(void);
3145
3146
3147/**
3148 * Log a "don't panic" message to the logfile.
3149 */
3150void welcome_to_mondorestore()
3151{
3152    log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION);
3153    log_msg(0,
3154            "DON'T PANIC! Mondorestore logs almost everything, so please ");
3155    log_msg(0,
3156            "don't break out in a cold sweat just because you see a few  ");
3157    log_msg(0,
3158            "error messages in the log. Read them; analyze them; see if  ");
3159    log_msg(0,
3160            "they are significant; above all, verify your backups! Please");
3161    log_msg(0,
3162            "attach a compressed copy of this log to any e-mail you send ");
3163    log_msg(0,
3164            "to the Mondo mailing list when you are seeking technical    ");
3165    log_msg(0,
3166            "support. Without it, we can't help you.               - Hugo");
3167    log_msg(0,
3168            "------------------------------------------------------------");
3169    log_msg(0,
3170            "BTW, despite (or perhaps because of) the wealth of messages,");
3171    log_msg(0,
3172            "some users are inclined to stop reading this log.  If Mondo ");
3173    log_msg(0,
3174            "stopped for some reason, chances are it's detailed here.    ");
3175    log_msg(0,
3176            "More than likely there's a message at the very end of this  ");
3177    log_msg(0,
3178            "log that will tell you what is wrong.  Please read it!      ");
3179    log_msg(0,
3180            "------------------------------------------------------------");
3181}
3182
3183
3184
3185/**
3186 * Restore the user's data.
3187 * What did you think it did, anyway? :-)
3188 */
3189int main(int argc, char *argv[])
3190{
3191    FILE *fin;
3192    FILE *fout;
3193    int retval = 0;
3194    int res;
3195//  int c;
3196    char *tmp;
3197
3198#ifndef VERSION
3199#define VERSION "1.7x_cvs"
3200#endif
3201
3202    struct mountlist_itself *mountlist;
3203    struct raidlist_itself *raidlist;
3204    struct s_bkpinfo *bkpinfo;
3205    struct s_node *filelist;
3206    char *a, *b;
3207
3208  /**************************************************************************
3209   * hugo-                                                                  *
3210   * busy stuff here - it needs some comments -stan                           *
3211   *                                                                        *
3212   **************************************************************************/
3213    if (getuid() != 0) {
3214        fprintf(stderr, "Please run as root.\r\n");
3215        exit(127);
3216    }
3217
3218    g_loglevel = DEFAULT_MR_LOGLEVEL;
3219    malloc_string(tmp);
3220
3221/* Configure global variables */
3222#ifdef __FreeBSD__
3223    if (strstr
3224        (call_program_and_get_last_line_of_output("cat /tmp/cmdline"),
3225         "textonly"))
3226#else
3227    if (strstr
3228        (call_program_and_get_last_line_of_output("cat /proc/cmdline"),
3229         "textonly"))
3230#endif
3231    {
3232        g_text_mode = TRUE;
3233        log_msg(1, "TEXTONLY MODE");
3234    } else {
3235        g_text_mode = FALSE;
3236    }                           // newt :-)
3237    if (!
3238        (bkpinfo = g_bkpinfo_DONTUSETHIS =
3239         malloc(sizeof(struct s_bkpinfo)))) {
3240        fatal_error("Cannot malloc bkpinfo");
3241    }
3242    if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) {
3243        fatal_error("Cannot malloc mountlist");
3244    }
3245    if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) {
3246        fatal_error("Cannot malloc raidlist");
3247    }
3248
3249    malloc_libmondo_global_strings();
3250
3251    asprintf(&g_mondo_home,
3252             call_program_and_get_last_line_of_output
3253             ("which mondorestore"));
3254    sprintf(g_tmpfs_mountpt, "/tmp/tmpfs");
3255    make_hole_for_dir(g_tmpfs_mountpt);
3256    g_current_media_number = 1; // precaution
3257
3258    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
3259    run_program_and_log_output("mkdir -p /mnt/floppy", FALSE);
3260
3261    malloc_string(tmp);
3262    malloc_string(a);
3263    malloc_string(b);
3264    setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc.
3265    reset_bkpinfo(bkpinfo);
3266    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
3267    bkpinfo->restore_data = TRUE;   // Well, yeah :-)
3268    if (am_I_in_disaster_recovery_mode()) {
3269        run_program_and_log_output("mount / -o remount,rw", 2);
3270    }                           // for b0rken distros
3271    g_main_pid = getpid();
3272    srandom((int) (time(NULL)));
3273    register_pid(getpid(), "mondo");
3274    set_signals(TRUE);
3275    g_kernel_version = get_kernel_version();
3276
3277    log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname);
3278    if (strlen(g_mountlist_fname) < 3) {
3279        fatal_error
3280            ("Serious error in malloc()'ing. Could be a bug in your glibc.");
3281    }
3282    mkdir(MNT_CDROM, 0x770);
3283
3284/* Backup original mountlist.txt */
3285    sprintf(tmp, "%s.orig", g_mountlist_fname);
3286    if (!does_file_exist(g_mountlist_fname)) {
3287        log_msg(2,
3288                "%ld: Warning - g_mountlist_fname (%s) does not exist yet",
3289                __LINE__, g_mountlist_fname);
3290    } else if (!does_file_exist(tmp)) {
3291        sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,
3292                g_mountlist_fname);
3293        run_program_and_log_output(tmp, FALSE);
3294    }
3295
3296/* Init directories */
3297    make_hole_for_dir(bkpinfo->tmpdir);
3298    sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir);
3299    run_program_and_log_output(tmp, FALSE);
3300    make_hole_for_dir("/var/log");
3301    make_hole_for_dir("/tmp/tmpfs");    /* just in case... */
3302    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3303    run_program_and_log_output
3304        ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log",
3305         FALSE);
3306
3307    run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE);
3308
3309/* Init GUI */
3310    malloc_libmondo_global_strings();
3311    setup_newt_stuff();         /* call newtInit and setup screen log */
3312    welcome_to_mondorestore();
3313    if (bkpinfo->disaster_recovery) {
3314        log_msg(1, "I am in disaster recovery mode");
3315    } else {
3316        log_msg(1, "I am in normal, live mode");
3317    }
3318
3319    iamhere("what time is it");
3320
3321/* Process command-line parameters */
3322    if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) {
3323#ifdef __FreeBSD__
3324        system("mv -f /tmp/raidconf.txt /etc/raidtab");
3325        if (!does_file_exist("/etc/raidtab"))
3326            system("vinum printconfig > /etc/raidtab");
3327#endif
3328        load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3329        if (!does_file_exist(g_mountlist_fname)) {
3330            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3331        }
3332        res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist);
3333#ifdef __FreeBSD__
3334        system("mv -f /etc/raidtab /tmp/raidconf.txt");
3335#endif
3336        paranoid_MR_finish(res);
3337    }
3338
3339    g_loglevel = DEFAULT_MR_LOGLEVEL;
3340    if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) {
3341        fout = fopen("/tmp/out.txt", "w");
3342        fput_string_one_char_at_a_time(stderr, argv[2]);
3343        finish(0);
3344    }
3345
3346    if (argc == 3 && strcmp(argv[1], "--gendf") == 0) {
3347        make_grub_install_scriptlet(argv[2]);
3348        finish(0);
3349    }
3350
3351    if (argc >= 2 && strcmp(argv[1], "--pih") == 0) {
3352        if (system("mount | grep cdrom 2> /dev/null > /dev/null")) {
3353            system("mount " MNT_CDROM);
3354        }
3355        bkpinfo->compression_level = 1;
3356        g_current_media_number = 2;
3357        strcpy(bkpinfo->restore_path, "/tmp/TESTING");
3358        bkpinfo->backup_media_type = dvd;
3359        open_progress_form("Reassembling /dev/hda1",
3360                           "Shark is a bit of a silly person.",
3361                           "Please wait. This may take some time.",
3362                           "", 1999);
3363        system("rm -Rf /tmp/*pih*");
3364
3365        restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp);
3366    }
3367
3368    if (argc == 5 && strcmp(argv[1], "--common") == 0) {
3369        g_loglevel = 6;
3370        filelist = load_filelist(argv[2]);
3371        if (!filelist) {
3372            fatal_error("Failed to load filelist");
3373        }
3374        toggle_node_selection(filelist, FALSE);
3375        toggle_all_root_dirs_on(filelist);
3376        toggle_path_selection(filelist, "/usr/share", TRUE);
3377//      show_filelist(filelist);
3378        save_filelist(filelist, "/tmp/out.txt");
3379//      finish(0);
3380//      toggle_path_selection (filelist, "/root/stuff", TRUE);
3381        strcpy(a, argv[3]);
3382        strcpy(b, argv[4]);
3383
3384        res = save_filelist_entries_in_common(a, filelist, b, FALSE);
3385        free_filelist(filelist);
3386        printf("res = %d", res);
3387        finish(0);
3388    }
3389
3390    if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) {
3391        popup_changelist_from_file(argv[2]);
3392        paranoid_MR_finish(0);
3393    }
3394
3395    if (argc == 5 && strcmp(argv[1], "--copy") == 0) {
3396        log_msg(1, "SCORE");
3397        g_loglevel = 10;
3398        if (strstr(argv[2], "save")) {
3399            log_msg(1, "Saving from %s to %s", argv[3], argv[4]);
3400            fin = fopen(argv[3], "r");
3401            fout = fopen(argv[4], "w");
3402            copy_from_src_to_dest(fin, fout, 'w');
3403            fclose(fin);
3404            fin = fopen(argv[3], "r");
3405            copy_from_src_to_dest(fin, fout, 'w');
3406            fclose(fout);
3407            fclose(fin);
3408        } else if (strstr(argv[2], "restore")) {
3409            fout = fopen(argv[3], "w");
3410            fin = fopen(argv[4], "r");
3411            copy_from_src_to_dest(fout, fin, 'r');
3412            fclose(fin);
3413            fin = fopen(argv[4], "r");
3414            copy_from_src_to_dest(fout, fin, 'r');
3415            fclose(fout);
3416            fclose(fin);
3417        } else {
3418            fatal_error("Unknown additional param");
3419        }
3420        finish(0);
3421    }
3422
3423    if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) {
3424        wait_until_software_raids_are_prepped(argv[2], 100);
3425        finish(0);
3426    }
3427
3428    if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) {
3429        finish(create_raidtab_from_mdstat(argv[2], argv[3]));
3430    }
3431
3432
3433    if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) {
3434        retval = run_grub(FALSE, "/dev/hda");
3435        if (retval) {
3436            log_to_screen("Failed to write Master Boot Record");
3437        }
3438        paranoid_MR_finish(0);
3439    }
3440    if (argc == 3 && strcmp(argv[1], "--paa") == 0) {
3441        g_current_media_number = atoi(argv[2]);
3442        pause_and_ask_for_cdr(5, NULL);
3443        paranoid_MR_finish(0);
3444    } else if (!bkpinfo->disaster_recovery) {   // live!
3445        if (argc != 1) {
3446            popup_and_OK
3447                ("Live mode doesn't support command-line parameters yet.");
3448            paranoid_MR_finish(1);
3449//    return(1);
3450        }
3451        log_msg(1, "I am in normal, live mode.");
3452        log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname);
3453        mount_boot_if_necessary();  /* for Gentoo users */
3454        log_msg(2, "Still here.");
3455        if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) {
3456            g_restoring_live_from_cd = TRUE;
3457        }
3458        if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) {
3459            retval =
3460                restore_live_from_monitas_server(bkpinfo,
3461                                                 argv[2],
3462                                                 argv[3], argv[4]);
3463        } else {
3464            log_msg(2, "Calling restore_to_live_filesystem()");
3465            retval = restore_to_live_filesystem(bkpinfo);
3466        }
3467        log_msg(2, "Still here. Yay.");
3468        if (strlen(bkpinfo->tmpdir) > 0) {
3469            sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir);
3470            run_program_and_log_output(tmp, FALSE);
3471        }
3472        unmount_boot_if_necessary();    /* for Gentoo users */
3473        paranoid_MR_finish(retval);
3474    } else {
3475/* Disaster recovery mode (must be) */
3476        log_msg(1, "I must be in disaster recovery mode.");
3477        log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname);
3478        if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) {
3479            log_to_screen("Uh, that hasn't been implemented yet.");
3480            paranoid_MR_finish(1);
3481        }
3482
3483        iamhere("About to call load_mountlist and load_raidtab");
3484        strcpy(bkpinfo->restore_path, MNT_RESTORING);
3485        read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo);
3486        retval = load_mountlist(mountlist, g_mountlist_fname);
3487        retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3488        iamhere
3489            ("Returned from calling load_mountlist and load_raidtab successfully");
3490
3491        if (argc > 1
3492            && (strcmp(argv[1], "--compare") == 0
3493                || strcmp(argv[1], "--nuke") == 0)) {
3494            if (bkpinfo->backup_media_type == nfs
3495                && !is_this_device_mounted(bkpinfo->nfs_mount)) {
3496                log_msg(1, "Mounting nfs dir");
3497                sprintf(bkpinfo->isodir, "/tmp/isodir");
3498                run_program_and_log_output("mkdir -p /tmp/isodir", 5);
3499                sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir",
3500                        bkpinfo->nfs_mount);
3501                run_program_and_log_output(tmp, 1);
3502            }
3503        }
3504
3505
3506        if (retval) {
3507            log_to_screen
3508                ("Warning - load_raidtab_into_raidlist returned an error");
3509        }
3510
3511
3512        log_msg(1, "Send in the clowns.");
3513
3514        if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) {
3515            log_msg(0, "Partitioning only.");
3516            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3517            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3518            load_mountlist(mountlist, g_mountlist_fname);
3519            res = partition_everything(mountlist);
3520            finish(res);
3521        }
3522
3523        if (argc == 2 && strcmp(argv[1], "--format-only") == 0) {
3524            log_msg(0, "Formatting only.");
3525            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3526            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3527            load_mountlist(mountlist, g_mountlist_fname);
3528            res = format_everything(mountlist, FALSE);
3529            finish(res);
3530        }
3531
3532        if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) {
3533            log_msg(0, "Stopping LVM and RAID");
3534            load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
3535            strcpy(g_mountlist_fname, "/tmp/mountlist.txt");
3536            load_mountlist(mountlist, g_mountlist_fname);
3537            res = do_my_funky_lvm_stuff(TRUE, FALSE);
3538            res += stop_all_raid_devices(mountlist);
3539            finish(res);
3540        }
3541
3542        if (argc == 2 && strcmp(argv[1], "--nuke") == 0) {
3543            iamhere("nuking");
3544            retval += nuke_mode(bkpinfo, mountlist, raidlist);
3545        } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) {
3546            iamhere("catchall");
3547            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3548        } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) {
3549            iamhere("compare");
3550            retval += compare_mode(bkpinfo, mountlist, raidlist);
3551        } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) {
3552            iamhere("iso");
3553            retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE);
3554        } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) {
3555            iamhere("mbr");
3556            retval = mount_all_devices(mountlist, TRUE);
3557            if (!retval) {
3558                retval += run_boot_loader(FALSE);
3559                retval += unmount_all_devices(mountlist);
3560            }
3561            if (retval) {
3562                log_to_screen("Failed to write Master Boot Record");
3563            }
3564        } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) {
3565            iamhere("isonuke");
3566            retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE);
3567        } else if (argc != 1) {
3568            log_to_screen("Invalid paremeters");
3569            paranoid_MR_finish(1);
3570        } else {
3571            iamhere("catchall (no mode specified in command-line call");
3572            retval += catchall_mode(bkpinfo, mountlist, raidlist);
3573        }
3574    }
3575
3576    /* clean up at the end */
3577    if (retval) {
3578        if (does_file_exist("/tmp/changed.files")) {
3579            log_to_screen
3580                ("See /tmp/changed.files for list of files that have changed.");
3581        }
3582        mvaddstr_and_log_it(g_currentY++,
3583                            0,
3584                            "Run complete. Errors were reported. Please review the logfile.");
3585    } else {
3586        if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3587            mvaddstr_and_log_it(g_currentY++,
3588                                0,
3589                                "Run complete. Please remove floppy/CD/media and reboot.");
3590        } else {
3591            run_program_and_log_output("sync", FALSE);
3592            if (is_this_device_mounted(MNT_CDROM)) {
3593                res =
3594                    run_program_and_log_output("umount " MNT_CDROM, FALSE);
3595            } else {
3596                res = 0;
3597            }
3598
3599            if (!bkpinfo->please_dont_eject) {
3600                res = eject_device("/dev/cdrom");
3601/*
3602              if (res)
3603        {
3604          log_to_screen( "WARNING - failed to eject CD-ROM disk" );
3605        }
3606*/
3607            }
3608            mvaddstr_and_log_it(g_currentY++,
3609                                0,
3610                                "Run complete. Please remove media and reboot.");
3611        }
3612    }
3613
3614// g_I_have_just_nuked is set true by nuke_mode() just before it returns
3615    if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) {
3616        if (!system("which post-nuke > /dev/null 2> /dev/null")) {
3617            log_msg(1, "post-nuke found; running...");
3618            if (mount_all_devices(mountlist, TRUE)) {
3619                log_to_screen
3620                    ("Unable to re-mount partitions for post-nuke stuff");
3621            } else {
3622                log_msg(1, "Re-mounted partitions for post-nuke stuff");
3623                sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path,
3624                        retval);
3625                if (!g_text_mode) {
3626                    newtSuspend();
3627                }
3628                log_msg(2, "Calling '%s'", tmp);
3629                if ((res = system(tmp))) {
3630                    log_OS_error(tmp);
3631                }
3632                if (!g_text_mode) {
3633                    newtResume();
3634                }
3635//              newtCls();
3636                log_msg(1, "post-nuke returned w/ res=%d", res);
3637            }
3638            unmount_all_devices(mountlist);
3639            log_msg(1, "I've finished post-nuking.");
3640        }
3641    }
3642/* 
3643  log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now.");
3644  log_to_screen("Otherwise, please wait until the RAID disks are done.");
3645  wait_until_software_raids_are_prepped("/proc/mdstat", 100);
3646  log_to_screen("Thank you.");
3647*/
3648    unlink("/tmp/mondo-run-prog.tmp");
3649    set_signals(FALSE);
3650    sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir);
3651    run_program_and_log_output(tmp, FALSE);
3652    log_to_screen
3653        ("Restore log copied to /tmp/mondo-restore.log on your hard disk");
3654    sprintf(tmp,
3655            "Mondo-restore is exiting (retval=%d)                                      ",
3656            retval);
3657    log_to_screen(tmp);
3658    sprintf(tmp, "umount %s", bkpinfo->isodir);
3659    run_program_and_log_output(tmp, 5);
3660    paranoid_free(mountlist);
3661    paranoid_free(raidlist);
3662    if (am_I_in_disaster_recovery_mode()) {
3663        run_program_and_log_output("mount / -o remount,rw", 2);
3664    }                           // for b0rken distros
3665    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
3666    free_libmondo_global_strings(); // it's fine to have this here :) really :)
3667    paranoid_free(a);
3668    paranoid_free(b);
3669    paranoid_free(tmp);
3670
3671    unlink("/tmp/filelist.full");
3672    unlink("/tmp/filelist.full.gz");
3673
3674    exit(retval);
3675}
3676
3677/**************************************************************************
3678 *END_MAIN                                                                *
3679 **************************************************************************/
3680
3681
3682
3683
3684
3685/**************************************************************************
3686 *END_MONDO-RESTORE.C                                                     *
3687 **************************************************************************/
Note: See TracBrowser for help on using the repository browser.