Package: ifupdown
Version: 0.7.8
Severity: wishlist
Tags: patch
Dear Maintainer,
I've attached a patch series that fixes ifupdown to work properly on
Debian/Hurd.
The first patch makes ifupdown use inetutils-ifconfig instead of ifconfig and
fixes its use in two cases.
The second patch sanitizes the file names of pid files written by ifupdown and
provides the macro %iface_file_name% that provides the interface name sanitized
in a way so that it is safe to use as a file name fragment. This is motivated
by the fact that on the Hurd network interfaces are made available as files (e.
g. /dev/eth0) and so they can contain slashes.
The third patch uses the new %iface_file_name% for pid and dhcp lease file
names on the Hurd.
-- System Information:
Debian Release: 7.1
APT prefers stable
APT policy: (900, 'stable'), (350, 'unstable'), (300, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.2.0-3-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages ifupdown depends on:
ii dpkg 1.16.10
ii initscripts 2.88dsf-41
ii iproute 20120521-3+b3
ii libc6 2.17-92
ii lsb-base 4.1+Debian8+deb7u1
ifupdown recommends no packages.
Versions of packages ifupdown suggests:
ii isc-dhcp-client [dhcp-client] 4.2.2.dfsg.1-5+deb70u6
ii net-tools 1.60-24.2
ii ppp 2.4.5-5.1+b1
pn rdnssd <none>
# HG changeset patch
# Parent 8a2f8cf2cae4658ec472c0bd59f8bf3962946ac8
Sanitize pidfile name, provide %iface_file_name% that is safe to use as filename fragment
diff --git a/execute.c b/execute.c
--- a/execute.c
+++ b/execute.c
@@ -215,7 +215,7 @@
{
if (!no_act) {
char pidfilename[100];
- snprintf(pidfilename, sizeof(pidfilename), RUN_DIR "ifup-%s.pid", iface->real_iface);
+ make_pidfile_name(pidfilename, sizeof pidfilename, "ifup", iface);
FILE *pidfile = fopen(pidfilename, "r");
if (pidfile) {
int pid;
@@ -442,6 +442,14 @@
return strdup(ifd->real_iface);
}
+ if (strncmpz(id, "iface_file_name", idlen) == 0) {
+ char *p = strdup(ifd->real_iface);
+ if (p) {
+ sanitize_file_name(p);
+ }
+ return p;
+ }
+
{
for (i = 0; i < ifd->n_options; i++) {
if (strncmpz(id, ifd->option[i].name, idlen) == 0) {
diff --git a/header.h b/header.h
--- a/header.h
+++ b/header.h
@@ -130,6 +130,8 @@
int var_set(char *id, interface_defn * ifd);
int var_set_anywhere(char *id, interface_defn * ifd);
int run_mapping(char *physical, char *logical, int len, mapping_defn * map);
+void sanitize_file_name(char *name);
+int make_pidfile_name(char *name, size_t size, const char *command, interface_defn *ifd);
extern int no_act;
extern int verbose;
extern int run_scripts;
diff --git a/main.c b/main.c
--- a/main.c
+++ b/main.c
@@ -356,6 +356,33 @@
return 0;
}
+void sanitize_file_name(char *name)
+{
+ for (; *name; name++) {
+ if (*name == '/') {
+ *name = '-';
+ }
+ }
+}
+
+int make_pidfile_name(char *name, size_t size,
+ const char *command, interface_defn *ifd)
+{
+ char *interface = strdup(ifd->real_iface);
+ if (!interface) {
+ return 0;
+ }
+ sanitize_file_name(interface);
+
+ int n = snprintf(name, size, RUN_DIR "%s-%s.pid", command, interface);
+ if (n < 0 || (size_t) n >= size) {
+ free(interface);
+ return 0;
+ }
+
+ return 1;
+}
+
int main(int argc, char **argv)
{
int (*cmds) (interface_defn *) = NULL;
@@ -813,7 +840,9 @@
} else {
command = argv[0]; /* no /'s in argv[0] */
}
- snprintf(pidfilename, sizeof(pidfilename), RUN_DIR "%s-%s.pid", command, currif->real_iface);
+ make_pidfile_name(pidfilename,
+ sizeof pidfilename,
+ command, currif);
if (!no_act) {
FILE *pidfile = fopen(pidfilename, "w");
if (pidfile) {
# HG changeset patch
# Parent a93db3ecb8f0e30dde02fc8ce0bddde38d48d8a7
Hurd: use inetutils-ifconfig, fix invocation of inetutils-ifconfig
diff --git a/inet.defn b/inet.defn
--- a/inet.defn
+++ b/inet.defn
@@ -360,7 +360,7 @@
This method may be used to define the IPv4 loopback interface.
up
- inetutils-ifconfig --interface %iface% 127.0.0.1 --up \
+ inetutils-ifconfig --interface %iface% --address 127.0.0.1 --up \
if (!iface_is_lo())
down
@@ -443,7 +443,7 @@
dhcpcd -k %iface% \
elsif (execable("/sbin/dhcpcd"))
- ifconfig --interface %iface% --down
+ inetutils-ifconfig --interface %iface% --down
method bootp
description
@@ -463,7 +463,7 @@
down
ip link set dev %iface% down \
if (execable("/sbin/ip") && iface_is_link())
- ifconfig %iface% down \
+ inetutils-ifconfig --interface %iface% --down \
elsif (1)
method ppp
diff --git a/link.defn b/link.defn
--- a/link.defn
+++ b/link.defn
@@ -41,7 +41,7 @@
method none
description
up
- -inetutils-ifconfig --interface %iface% 127.0.0.1 --up \
+ -inetutils-ifconfig --interface %iface% --address 127.0.0.1 --up \
if (iface_is_lo())
down
-inetutils-ifconfig --interface %iface% --down \
# HG changeset patch
# Parent 9ad214c389bd636b8a8afff8450b894b2b60f0fd
Hurd: Use %iface_file_name% for pid files and lease files
diff --git a/inet.defn b/inet.defn
--- a/inet.defn
+++ b/inet.defn
@@ -426,9 +426,9 @@
up
[[Warning: Option hwaddress: %hwaddress% not yet supported]]
- dhclient -v -pf /run/dhclient.%iface%.pid -lf /var/lib/dhcp/dhclient.%iface%.leases %iface% \
+ dhclient -v -pf /run/dhclient.%iface_file_name%.pid -lf /var/lib/dhcp/dhclient.%iface_file_name%.leases %iface% \
if (execable("/sbin/dhclient"))
- udhcpc -n -p /run/udhcpc.%iface%.pid -i %iface% [[-H %hostname%]] \
+ udhcpc -n -p /run/udhcpc.%iface_file_name%.pid -i %iface% [[-H %hostname%]] \
[[-c %client%]] \
elsif (execable("/sbin/udhcpc"))
dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %client%]] \
@@ -436,9 +436,9 @@
elsif (execable("/sbin/dhcpcd"))
down
- dhclient -v -r -pf /run/dhclient.%iface%.pid -lf /var/lib/dhcp/dhclient.%iface%.leases %iface% \
+ dhclient -v -r -pf /run/dhclient.%iface_file_name%.pid -lf /var/lib/dhcp/dhclient.%iface_file_name%.leases %iface% \
if (execable("/sbin/dhclient"))
- kill -USR2 $(cat /run/udhcpc.%iface%.pid); kill -TERM $(cat /run/udhcpc.%iface%.pid) \
+ kill -USR2 $(cat /run/udhcpc.%iface_file_name%.pid); kill -TERM $(cat /run/udhcpc.%iface_file_name%.pid) \
elsif (execable("/sbin/udhcpc"))
dhcpcd -k %iface% \
elsif (execable("/sbin/dhcpcd"))
@@ -487,10 +487,10 @@
provider name -- Use /name/ as the provider (from /etc/wvdial.conf).
up
/sbin/start-stop-daemon --start -x /usr/bin/wvdial \
- -p /run/wvdial.%iface%.pid -b -m -- [[ %provider% ]]
+ -p /run/wvdial.%iface_file_name%.pid -b -m -- [[ %provider% ]]
down
/sbin/start-stop-daemon --stop -x /usr/bin/wvdial \
- -p /run/wvdial.%iface%.pid -s 2
+ -p /run/wvdial.%iface_file_name%.pid -s 2
method ipv4ll
diff --git a/inet6.defn b/inet6.defn
--- a/inet6.defn
+++ b/inet6.defn
@@ -327,11 +327,11 @@
up
[[Warning: Option hwaddress: %hwaddress% not yet supported]]
inetutils-ifconfig --interface %iface% --up
- dhclient -6 -pf /run/dhclient6.%iface%.pid -lf /var/lib/dhcp/dhclient6.%iface%.leases %iface% \
+ dhclient -6 -pf /run/dhclient6.%iface_file_name%.pid -lf /var/lib/dhcp/dhclient6.%iface_file_name%.leases %iface% \
if (execable("/sbin/dhclient"))
down
- dhclient -6 -r -pf /run/dhclient6.%iface%.pid -lf /var/lib/dhcp/dhclient6.%iface%.leases %iface% \
+ dhclient -6 -r -pf /run/dhclient6.%iface_file_name%.pid -lf /var/lib/dhcp/dhclient6.%iface_file_name%.leases %iface% \
if (execable("/sbin/dhclient"))
inetutils-ifconfig --interface %iface% --down