aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/script.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/script.c')
-rw-r--r--networking/udhcp/script.c29
1 files changed, 8 insertions, 21 deletions
diff --git a/networking/udhcp/script.c b/networking/udhcp/script.c
index 2a4732104..d1b272de6 100644
--- a/networking/udhcp/script.c
+++ b/networking/udhcp/script.c
@@ -4,19 +4,7 @@
4 * 4 *
5 * Russ Dill <Russ.Dill@asu.edu> July 2001 5 * Russ Dill <Russ.Dill@asu.edu> July 2001
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 8 */
21 9
22#include <string.h> 10#include <string.h>
@@ -33,7 +21,6 @@
33#include "options.h" 21#include "options.h"
34#include "dhcpd.h" 22#include "dhcpd.h"
35#include "dhcpc.h" 23#include "dhcpc.h"
36#include "script.h"
37 24
38/* get a rough idea of how long an option will be (rounding up...) */ 25/* get a rough idea of how long an option will be (rounding up...) */
39static const int max_option_length[] = { 26static const int max_option_length[] = {
@@ -161,10 +148,10 @@ static char **fill_envp(struct dhcpMessage *packet)
161 148
162 envp = xzalloc(sizeof(char *) * (num_options + 5)); 149 envp = xzalloc(sizeof(char *) * (num_options + 5));
163 j = 0; 150 j = 0;
164 asprintf(&envp[j++], "interface=%s", client_config.interface); 151 envp[j++] = bb_xasprintf("interface=%s", client_config.interface);
165 asprintf(&envp[j++], "%s=%s", "PATH", 152 envp[j++] = bb_xasprintf("PATH=%s",
166 getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin"); 153 getenv("PATH") ? : "/bin:/usr/bin:/sbin:/usr/sbin");
167 asprintf(&envp[j++], "%s=%s", "HOME", getenv("HOME") ? : "/"); 154 envp[j++] = bb_xasprintf("HOME=%s", getenv("HOME") ? : "/");
168 155
169 if (packet == NULL) return envp; 156 if (packet == NULL) return envp;
170 157
@@ -182,7 +169,7 @@ static char **fill_envp(struct dhcpMessage *packet)
182 /* Fill in a subnet bits option for things like /24 */ 169 /* Fill in a subnet bits option for things like /24 */
183 if (dhcp_options[i].code == DHCP_SUBNET) { 170 if (dhcp_options[i].code == DHCP_SUBNET) {
184 memcpy(&subnet, temp, 4); 171 memcpy(&subnet, temp, 4);
185 asprintf(&envp[j++], "mask=%d", mton(&subnet)); 172 envp[j++] = bb_xasprintf("mask=%d", mton(&subnet));
186 } 173 }
187 } 174 }
188 if (packet->siaddr) { 175 if (packet->siaddr) {
@@ -192,19 +179,19 @@ static char **fill_envp(struct dhcpMessage *packet)
192 if (!(over & FILE_FIELD) && packet->file[0]) { 179 if (!(over & FILE_FIELD) && packet->file[0]) {
193 /* watch out for invalid packets */ 180 /* watch out for invalid packets */
194 packet->file[sizeof(packet->file) - 1] = '\0'; 181 packet->file[sizeof(packet->file) - 1] = '\0';
195 asprintf(&envp[j++], "boot_file=%s", packet->file); 182 envp[j++] = bb_xasprintf("boot_file=%s", packet->file);
196 } 183 }
197 if (!(over & SNAME_FIELD) && packet->sname[0]) { 184 if (!(over & SNAME_FIELD) && packet->sname[0]) {
198 /* watch out for invalid packets */ 185 /* watch out for invalid packets */
199 packet->sname[sizeof(packet->sname) - 1] = '\0'; 186 packet->sname[sizeof(packet->sname) - 1] = '\0';
200 asprintf(&envp[j++], "sname=%s", packet->sname); 187 envp[j++] = bb_xasprintf("sname=%s", packet->sname);
201 } 188 }
202 return envp; 189 return envp;
203} 190}
204 191
205 192
206/* Call a script with a par file and env vars */ 193/* Call a script with a par file and env vars */
207void run_script(struct dhcpMessage *packet, const char *name) 194void udhcp_run_script(struct dhcpMessage *packet, const char *name)
208{ 195{
209 int pid; 196 int pid;
210 char **envp, **curr; 197 char **envp, **curr;