]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/misc-progs/restartdhcp.c
1 /* SmoothWall helper program - restartdhcp
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
7 * Simple program intended to be installed setuid(0) that can be used for
10 * $Id: restartdhcp.c,v 1.5.2.1 2004/11/03 13:50:26 alanh Exp $
14 #include "libsmooth.h"
20 #include <sys/types.h>
29 char buffer
[STRING_SIZE
];
30 char blue_dev
[STRING_SIZE
] = "", green_dev
[STRING_SIZE
] = "";
32 struct keyvalue
*kv
= NULL
;
37 memset(buffer
, 0, STRING_SIZE
);
39 /* Init the keyvalue structure */
42 /* Read in the current values */
43 if (!readkeyvalues(kv
, CONFIG_ROOT
"/ethernet/settings"))
45 fprintf(stderr
, "Cannot read ethernet settings\n");
49 if (!findkey(kv
, "GREEN_DEV", green_dev
))
51 fprintf(stderr
, "Cannot read GREEN_DEV\n");
55 if (!VALID_DEVICE(green_dev
))
57 fprintf(stderr
, "Bad GREEN_DEV: %s\n", green_dev
);
61 /* Get the BLUE interface details */
62 findkey(kv
, "BLUE_DEV", blue_dev
);
66 if ((fdblue
= open(CONFIG_ROOT
"/dhcp/enable_blue", O_RDONLY
)) != -1)
69 if (!VALID_DEVICE(blue_dev
))
71 fprintf(stderr
, "Bad BLUE_DEV: %s\n", blue_dev
);
76 if ((fd
= open("/var/run/dhcpd.pid", O_RDONLY
)) != -1)
78 if (read(fd
, buffer
, STRING_SIZE
- 1) == -1)
79 fprintf(stderr
, "Couldn't read from pid file\n");
84 fprintf(stderr
, "Bad pid value\n");
87 if (kill(pid
, SIGTERM
) == -1)
88 fprintf(stderr
, "Unable to send SIGTERM\n");
90 unlink("/var/run/dhcpd.pid");
93 safe_system("/bin/killall -KILL dhcpd");
97 safe_system("/sbin/iptables -F DHCPBLUEINPUT");
101 if ((fd
= open(CONFIG_ROOT
"/dhcp/enable_green", O_RDONLY
)) != -1)
104 if ((fdblue
= open(CONFIG_ROOT
"/dhcp/enable_blue", O_RDONLY
)) != -1)
108 snprintf(buffer
, STRING_SIZE
-1, "/sbin/iptables -A DHCPBLUEINPUT -p tcp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev
);
110 snprintf(buffer
, STRING_SIZE
-1, "/sbin/iptables -A DHCPBLUEINPUT -p udp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev
);
112 snprintf(buffer
, STRING_SIZE
-1, "/usr/sbin/dhcpd -q %s %s", green_dev
, blue_dev
);
114 snprintf(buffer
, STRING_SIZE
-1, "/usr/sbin/dhcpd -q %s", green_dev
);
118 if ((fdblue
= open(CONFIG_ROOT
"/dhcp/enable_blue", O_RDONLY
)) != -1)
122 snprintf(buffer
, STRING_SIZE
-1, "/sbin/iptables -A DHCPBLUEINPUT -p tcp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev
);
124 snprintf(buffer
, STRING_SIZE
-1, "/sbin/iptables -A DHCPBLUEINPUT -p udp --source-port 68 --destination-port 67 -i %s -j ACCEPT > /dev/null 2>&1", blue_dev
);
126 snprintf(buffer
, STRING_SIZE
-1, "/usr/sbin/dhcpd -q %s", blue_dev
);
131 if (buffer
[0] != '\0')
133 /* Silly dhcpd creates pids with mode 640 */
135 if ((fd
= open("/var/run/dhcpd.pid", 0)) == -1)
137 fprintf(stderr
, "No pid file\n");