diff options
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 87 |
1 files changed, 41 insertions, 46 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 00a4908462c..61688787cc2 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.76 2005/07/16 14:09:51 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.77 2005/08/02 02:34:03 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -277,8 +277,16 @@ main(int argc, char *argv[]) if (argc != 1) usage(); - if ((ifi = calloc(1, sizeof(struct interface_info))) == NULL) - error("calloc"); + ifi = calloc(1, sizeof(*ifi)); + if (ifi == NULL) + error("ifi calloc"); + ifi->client = calloc(1, sizeof(*(ifi->client))); + if (ifi->client == NULL) + error("ifi->client calloc"); + ifi->client->config = calloc(1, sizeof(*(ifi->client->config))); + if (ifi->client->config == NULL) + error("ifi->client->config calloc"); + if (strlcpy(ifi->name, argv[0], IFNAMSIZ) >= IFNAMSIZ) error("Interface name too long"); if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s", @@ -1709,29 +1717,27 @@ script_init(char *reason, struct string_list *medium) void priv_script_init(char *reason, char *medium) { - struct interface_info *ip = ifi; + struct client_state *client = ifi->client; - if (ip) { - ip->client->scriptEnvsize = 100; - if (ip->client->scriptEnv == NULL) - ip->client->scriptEnv = - malloc(ip->client->scriptEnvsize * sizeof(char *)); - if (ip->client->scriptEnv == NULL) - error("script_init: no memory for environment"); + client->scriptEnvsize = 100; + if (client->scriptEnv == NULL) + client->scriptEnv = + malloc(client->scriptEnvsize * sizeof(char *)); + if (client->scriptEnv == NULL) + error("script_init: no memory for environment"); - ip->client->scriptEnv[0] = strdup(CLIENT_PATH); - if (ip->client->scriptEnv[0] == NULL) - error("script_init: no memory for environment"); + client->scriptEnv[0] = strdup(CLIENT_PATH); + if (client->scriptEnv[0] == NULL) + error("script_init: no memory for environment"); - ip->client->scriptEnv[1] = NULL; + client->scriptEnv[1] = NULL; - script_set_env(ip->client, "", "interface", ip->name); + script_set_env("", "interface", ifi->name); - if (medium) - script_set_env(ip->client, "", "medium", medium); + if (medium) + script_set_env("", "medium", medium); - script_set_env(ip->client, "", "reason", reason); - } + script_set_env("", "reason", reason); } void @@ -1742,8 +1748,7 @@ priv_script_write_params(char *prefix, struct client_lease *lease) int i, len = 0; char tbuf[128]; - script_set_env(ip->client, prefix, "ip_address", - piaddr(lease->address)); + script_set_env(prefix, "ip_address", piaddr(lease->address)); if (lease->options[DHO_SUBNET_MASK].len && (lease->options[DHO_SUBNET_MASK].len < @@ -1756,12 +1761,12 @@ priv_script_write_params(char *prefix, struct client_lease *lease) subnet = subnet_number(lease->address, netmask); if (subnet.len) { - script_set_env(ip->client, prefix, "network_number", + script_set_env(prefix, "network_number", piaddr(subnet)); if (!lease->options[DHO_BROADCAST_ADDRESS].len) { broadcast = broadcast_addr(subnet, netmask); if (broadcast.len) - script_set_env(ip->client, prefix, + script_set_env(prefix, "broadcast_address", piaddr(broadcast)); } @@ -1769,9 +1774,9 @@ priv_script_write_params(char *prefix, struct client_lease *lease) } if (lease->filename) - script_set_env(ip->client, prefix, "filename", lease->filename); + script_set_env(prefix, "filename", lease->filename); if (lease->server_name) - script_set_env(ip->client, prefix, "server_name", + script_set_env(prefix, "server_name", lease->server_name); for (i = 0; i < 256; i++) { u_int8_t *dp = NULL; @@ -1840,12 +1845,12 @@ supersede: if (dhcp_option_ev_name(name, sizeof(name), &dhcp_options[i])) - script_set_env(ip->client, prefix, name, + script_set_env(prefix, name, pretty_print_option(i, dp, len, 0, 0)); } } snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry); - script_set_env(ip->client, prefix, "expiry", tbuf); + script_set_env(prefix, "expiry", tbuf); } void @@ -1935,23 +1940,13 @@ script_go(void) int priv_script_go(void) { - char *scriptName, *argv[2], **envp, *epp[3], reason[] = "REASON=NBI"; - static char client_path[] = CLIENT_PATH; - struct interface_info *ip = ifi; + char *scriptName, *argv[2], **envp; int pid, wpid, wstatus; scripttime = time(NULL); - if (ip) { - scriptName = ip->client->config->script_name; - envp = ip->client->scriptEnv; - } else { - scriptName = top_level_config.script_name; - epp[0] = reason; - epp[1] = client_path; - epp[2] = NULL; - envp = epp; - } + scriptName = ifi->client->config->script_name; + envp = ifi->client->scriptEnv; argv[0] = scriptName; argv[1] = NULL; @@ -1973,16 +1968,15 @@ priv_script_go(void) error("execve (%s, ...): %m", scriptName); } - if (ip) - script_flush_env(ip->client); + script_flush_env(); return (wstatus & 0xff); } void -script_set_env(struct client_state *client, const char *prefix, - const char *name, const char *value) +script_set_env(const char *prefix, const char *name, const char *value) { + struct client_state *client = ifi->client; int i, j, namelen; namelen = strlen(name); @@ -2036,8 +2030,9 @@ script_set_env(struct client_state *client, const char *prefix, } void -script_flush_env(struct client_state *client) +script_flush_env(void) { + struct client_state *client = ifi->client; int i; for (i = 0; client->scriptEnv[i]; i++) { |