]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/ipfirerscfg.c
2 * This file is part of the IPCop Firewall.
4 * IPCop is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * IPCop is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with IPCop; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Copyright (C) 2003-06-25 Tim Butterfield <timbutterfield@mindspring.com>
20 * $Id: ipcoprscfg.c,v 1.2.2.6 2005/11/21 00:11:39 franck78 Exp $
28 #include <sys/types.h>
35 #define TMP_FILEZ "/tmp/TMPFILE.tar.gz"
36 #define TMP_FILE "/tmp/TMPFILE.tar"
38 /* check existence of a data file */
39 int data_exists(const char *hostname
) {
40 char fname
[STRING_SIZE
];
41 snprintf (fname
, STRING_SIZE
-1, MOUNTPOINT
"/%s.dat", hostname
);
42 return file_exists(fname
);
46 int main(int argc
, char**argv
) {
48 char command
[STRING_SIZE
];
49 char hostname
[STRING_SIZE
];
51 if (argc
==2 && strcmp(argv
[1],"--hardware")==0)
52 rshardware
=1; // restore hardware settings
54 gethostname(hostname
, STRING_SIZE
-1);
60 /* if a key file exists, an encrypted .dat is required */
61 if (!file_exists(BACKUP_KEY
)) {
62 fprintf (stderr
, "Missing encryption key\n");
67 if (!data_exists(hostname
)) {
68 fprintf (stderr
, "Missing encrypted archive "MOUNTPOINT
"/%s.dat archive\n", hostname
);
72 /* decrypt .dat file to tmp file */
73 snprintf (command
, STRING_SIZE
-1, "/usr/bin/openssl des3 -d -salt -in "MOUNTPOINT
"/%s.dat -out "TMP_FILEZ
" -kfile "BACKUP_KEY
" > /dev/null 2> /dev/null", hostname
);
74 if (safe_system (command
)) {
75 fprintf (stderr
, "Couldn't decrypt "MOUNTPOINT
"/%s.dat archive\n", hostname
);
79 /* create temporary directory for testing untar */
80 char tmp_dir
[STRING_SIZE
];
82 strcpy (tmp_dir
,"cfg_XXXXXXX");
83 if (mkdtemp (tmp_dir
)==NULL
) {
88 /* Start (test) untarring files from compressed archive */
89 snprintf (command
, STRING_SIZE
-1, "/bin/tar -C %s -xzvf "TMP_FILEZ
" > /dev/null 2> /dev/null",tmp_dir
);
90 if (safe_system (command
)) {
91 fprintf (stderr
, "Archive have errors!\n");
96 /* remove temporary directory */
97 snprintf (command
, STRING_SIZE
-1, "/bin/rm -rf %s > /dev/null 2> /dev/null",tmp_dir
);
98 safe_system (command
);
100 /* Start (real) untarring files from compressed archive */
101 char extraX
[STRING_SIZE
] = "";
103 if (rshardware
==0) { /* extra eXclusion from restore */
104 strcpy (extraX
, "-X "CONFIG_ROOT
"/backup/exclude.hardware ");
106 snprintf (command
, STRING_SIZE
-1, "/bin/tar -C / -xzvf "TMP_FILEZ
" -X "CONFIG_ROOT
"/backup/exclude.system %s > /dev/null 2> /dev/null", extraX
);
107 if (safe_system (command
)) {
108 fprintf (stderr
, "Error restoring archive\n");
112 /* remove temporary archive copy */