]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/misc-progs/installfcdsl.c
e3e8a6ac5dd0d9aa7094459dec2758d7a8a94df6
[people/pmueller/ipfire-2.x.git] / src / misc-progs / installfcdsl.c
1 /*
2 * This file is part of the IPCop Firewall.
3 *
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.
8 *
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.
13 *
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
17 *
18 * Copyright (C) 2004-10-14 Gilles Espinasse <g.esp.ipcop@free.fr>
19 *
20 * $Id: installfcdsl.c,v 1.1.2.4 2004/12/11 08:55:37 gespinasse Exp $
21 *
22 */
23
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/types.h>
29 #include <fcntl.h>
30 #include <grp.h>
31 #include "setuid.h"
32
33 #define FCDSL_TGZ_PATH "/var/patches/fcdsl-x.tgz"
34
35 char command[STRING_SIZE],tmpdir[] = "/tmp/fcdsl_XXXXXX";
36
37 void exithandler(void)
38 {
39 if(strcmp(tmpdir,"/tmp/fcdsl_XXXXXX"))
40 {
41 chdir("/tmp");
42 snprintf(command, STRING_SIZE - 1, "/bin/rm -rf %s", tmpdir);
43 if(safe_system(command))
44 perror("Couldn't remove temp dir");
45 }
46 /* remove loaded package */
47 snprintf (command, STRING_SIZE-1, FCDSL_TGZ_PATH);
48 unlink (command);
49 }
50
51 int main(void)
52 {
53 if (!(initsetuid()))
54 exit(1);
55
56 atexit(exithandler);
57
58
59 if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }
60 if (open("/dev/zero", O_RDONLY) != 0) {fprintf(stderr, "Couldn't reopen stdin from /dev/zero\n"); exit(1); }
61 if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); exit(1); }
62 if (! dup(1)) { fprintf(stderr, "Couldnt redirect stderr to stdout\n"); exit(1); }
63
64 /* create temporary directory for testing untar */
65 if (mkdtemp (tmpdir)==NULL) {
66 exit(1);
67 }
68
69 /* Test untarring files from compressed archive */
70 snprintf (command, STRING_SIZE-1, "/bin/tar -C %s -xzf %s lib/modules/*/misc/fcdsl*.o.gz "
71 "usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "
72 "var/run/need-depmod-* > /dev/null 2> /dev/null", tmpdir, FCDSL_TGZ_PATH);
73 if (safe_system (command)) {
74 fprintf (stderr, "Invalid archive\n");
75 exit(1);
76 }
77
78 /* Start (real) untarring files from compressed archive */
79 snprintf (command, STRING_SIZE-1, "/bin/tar -C / -xzvf %s lib/modules/*/misc/fcdsl*.o.gz "
80 "usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "
81 "var/run/need-depmod-* ", FCDSL_TGZ_PATH);
82 if (safe_system (command)) {
83 fprintf (stderr, "Error installing modules\n");
84 exit(1);
85 }
86
87 exit(0);
88 }