]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/misc-progs/installfcdsl.c
Squidupdate und QoS-Fix.
[people/pmueller/ipfire-2.x.git] / src / misc-progs / installfcdsl.c
CommitLineData
cd1a2927
MT
1/*\r
2 * This file is part of the IPCop Firewall.\r
3 *\r
4 * IPCop is free software; you can redistribute it and/or modify\r
5 * it under the terms of the GNU General Public License as published by\r
6 * the Free Software Foundation; either version 2 of the License, or\r
7 * (at your option) any later version.\r
8 *\r
9 * IPCop is distributed in the hope that it will be useful,\r
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
12 * GNU General Public License for more details.\r
13 *\r
14 * You should have received a copy of the GNU General Public License\r
15 * along with IPCop; if not, write to the Free Software\r
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
17 *\r
18 * Copyright (C) 2004-10-14 Gilles Espinasse <g.esp.ipcop@free.fr>\r
19 *\r
20 * $Id: installfcdsl.c,v 1.1.2.4 2004/12/11 08:55:37 gespinasse Exp $\r
21 *\r
22 */\r
23\r
24#include <stdio.h>\r
25#include <string.h>\r
26#include <stdlib.h>\r
27#include <unistd.h>\r
28#include <sys/types.h>\r
29#include <fcntl.h>\r
30#include <grp.h>\r
31#include "setuid.h"\r
32\r
33#define FCDSL_TGZ_PATH "/var/patches/fcdsl-x.tgz"\r
34\r
35char command[STRING_SIZE],tmpdir[] = "/tmp/fcdsl_XXXXXX";\r
36\r
37void exithandler(void)\r
38{\r
39 if(strcmp(tmpdir,"/tmp/fcdsl_XXXXXX"))\r
40 {\r
41 chdir("/tmp");\r
42 snprintf(command, STRING_SIZE - 1, "/bin/rm -rf %s", tmpdir);\r
43 if(safe_system(command))\r
44 perror("Couldn't remove temp dir");\r
45 }\r
46 /* remove loaded package */\r
47 snprintf (command, STRING_SIZE-1, FCDSL_TGZ_PATH);\r
48 unlink (command);\r
49}\r
50\r
51int main(void)\r
52{\r
53 if (!(initsetuid()))\r
54 exit(1);\r
55\r
56 atexit(exithandler);\r
57\r
58\r
59 if (close(0)) { fprintf(stderr, "Couldn't close 0\n"); exit(1); }\r
60 if (open("/dev/zero", O_RDONLY) != 0) {fprintf(stderr, "Couldn't reopen stdin from /dev/zero\n"); exit(1); }\r
61 if (close(2)) { fprintf(stderr, "Couldn't close 2\n"); exit(1); }\r
62 if (! dup(1)) { fprintf(stderr, "Couldnt redirect stderr to stdout\n"); exit(1); }\r
63\r
64 /* create temporary directory for testing untar */\r
65 if (mkdtemp (tmpdir)==NULL) {\r
66 exit(1);\r
67 }\r
68\r
69 /* Test untarring files from compressed archive */\r
70 snprintf (command, STRING_SIZE-1, "/bin/tar -C %s -xzf %s lib/modules/*/misc/fcdsl*.o.gz "\r
71 "usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "\r
72 "var/run/need-depmod-* > /dev/null 2> /dev/null", tmpdir, FCDSL_TGZ_PATH);\r
73 if (safe_system (command)) {\r
74 fprintf (stderr, "Invalid archive\n");\r
75 exit(1);\r
76 }\r
77\r
78 /* Start (real) untarring files from compressed archive */\r
79 snprintf (command, STRING_SIZE-1, "/bin/tar -C / -xzvf %s lib/modules/*/misc/fcdsl*.o.gz "\r
80 "usr/lib/isdn/{fds?base.bin,fd?ubase.frm} etc/fcdsl/fcdsl*.conf etc/drdsl/drdsl* "\r
81 "var/run/need-depmod-* ", FCDSL_TGZ_PATH);\r
82 if (safe_system (command)) {\r
83 fprintf (stderr, "Error installing modules\n");\r
84 exit(1);\r
85 }\r
86\r
87 exit(0);\r
88}\r