mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
ifupdown: fix for standalone shell; removed hardcoded PATH
This commit is contained in:
parent
0534125ccc
commit
2f4399c6cc
@ -106,6 +106,8 @@ enum {
|
|||||||
|
|
||||||
static char **__myenviron;
|
static char **__myenviron;
|
||||||
|
|
||||||
|
static char *startup_PATH;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
|
#if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_IFUPDOWN_IP
|
#ifdef CONFIG_FEATURE_IFUPDOWN_IP
|
||||||
@ -448,50 +450,29 @@ static int static_down(struct interface_defn_t *ifd, execfn *exec)
|
|||||||
return ((result == 2) ? 2 : 0);
|
return ((result == 2) ? 2 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int execable(char *program)
|
|
||||||
{
|
|
||||||
struct stat buf;
|
|
||||||
if (0 == stat(program, &buf)) {
|
|
||||||
if (S_ISREG(buf.st_mode) && (S_IXUSR & buf.st_mode)) {
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
|
static int dhcp_up(struct interface_defn_t *ifd, execfn *exec)
|
||||||
{
|
{
|
||||||
if (execable("/sbin/udhcpc")) {
|
if (execute("udhcpc -n -p /var/run/udhcpc.%iface%.pid -i "
|
||||||
return( execute("udhcpc -n -p /var/run/udhcpc.%iface%.pid -i "
|
"%iface% [[-H %hostname%]] [[-c %clientid%]]", ifd, exec)) return 1;
|
||||||
"%iface% [[-H %hostname%]] [[-c %clientid%]]", ifd, exec));
|
if (execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", ifd, exec)) return 1;
|
||||||
} else if (execable("/sbin/pump")) {
|
if (execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", ifd, exec)) return 1;
|
||||||
return( execute("pump -i %iface% [[-h %hostname%]] [[-l %leasehours%]]", ifd, exec));
|
if (execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] "
|
||||||
} else if (execable("/sbin/dhclient")) {
|
"[[-l %leasetime%]] %iface%", ifd, exec)) return 1;
|
||||||
return( execute("dhclient -pf /var/run/dhclient.%iface%.pid %iface%", ifd, exec));
|
return 0;
|
||||||
} else if (execable("/sbin/dhcpcd")) {
|
|
||||||
return( execute("dhcpcd [[-h %hostname%]] [[-i %vendor%]] [[-I %clientid%]] "
|
|
||||||
"[[-l %leasetime%]] %iface%", ifd, exec));
|
|
||||||
}
|
|
||||||
return(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
static int dhcp_down(struct interface_defn_t *ifd, execfn *exec)
|
||||||
{
|
{
|
||||||
int result = 0;
|
/* SIGUSR2 forces udhcpc to release the current lease and go inactive,
|
||||||
if (execable("/sbin/udhcpc")) {
|
* and SIGTERM causes udhcpc to exit. Signals are queued and processed
|
||||||
/* SIGUSR2 forces udhcpc to release the current lease and go inactive,
|
* sequentially so we don't need to sleep */
|
||||||
* and SIGTERM causes udhcpc to exit. Signals are queued and processed
|
if (execute("kill -USR2 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec)
|
||||||
* sequentially so we don't need to sleep */
|
|| execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec))
|
||||||
result = execute("kill -USR2 `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
|
return 1;
|
||||||
result += execute("kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec);
|
if (execute("pump -i %iface% -k", ifd, exec)) return 1;
|
||||||
} else if (execable("/sbin/pump")) {
|
if (execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec)) return 1;
|
||||||
result = execute("pump -i %iface% -k", ifd, exec);
|
if (execute("dhcpcd -k %iface%", ifd, exec)) return 1;
|
||||||
} else if (execable("/sbin/dhclient")) {
|
return static_down(ifd, exec);
|
||||||
result = execute("kill -9 `cat /var/run/dhclient.%iface%.pid` 2>/dev/null", ifd, exec);
|
|
||||||
} else if (execable("/sbin/dhcpcd")) {
|
|
||||||
result = execute("dhcpcd -k %iface%", ifd, exec);
|
|
||||||
}
|
|
||||||
return (result || static_down(ifd, exec));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
|
static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
|
||||||
@ -875,9 +856,7 @@ static void set_environ(struct interface_defn_t *iface, const char *mode)
|
|||||||
*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
|
*(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name);
|
||||||
*(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
|
*(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name);
|
||||||
*(environend++) = setlocalenv("%s=%s", "MODE", mode);
|
*(environend++) = setlocalenv("%s=%s", "MODE", mode);
|
||||||
/* FIXME: we must not impose our own PATH, it is admin's job!
|
*(environend++) = setlocalenv("%s=%s", "PATH", startup_PATH);
|
||||||
Use PATH from parent env */
|
|
||||||
*(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int doit(char *str)
|
static int doit(char *str)
|
||||||
@ -1103,6 +1082,9 @@ int ifupdown_main(int argc, char **argv)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startup_PATH = getenv("PATH");
|
||||||
|
if (!startup_PATH) startup_PATH = "";
|
||||||
|
|
||||||
/* Create a list of interfaces to work on */
|
/* Create a list of interfaces to work on */
|
||||||
if (DO_ALL) {
|
if (DO_ALL) {
|
||||||
if (cmds == iface_up) {
|
if (cmds == iface_up) {
|
||||||
|
Loading…
Reference in New Issue
Block a user