Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-4]: src/usr.sbin/dhcp Apply patch (requested by mellon):
details: https://anonhg.NetBSD.org/src/rev/1962c7dd30ef
branches: netbsd-1-4
changeset: 470793:1962c7dd30ef
user: he <he%NetBSD.org@localhost>
date: Sun Jul 23 17:19:59 2000 +0000
description:
Apply patch (requested by mellon):
Instead of creating a temporary client script, put environment
settings in the environment before the real client script is
executed.
This is relevant parts of diffs between dhcp-2.0pl2 and dhcp-2.0pl3.
diffstat:
usr.sbin/dhcp/client/Makefile | 1 +
usr.sbin/dhcp/client/clparse.c | 6 +-
usr.sbin/dhcp/client/dhclient.c | 229 +++++++++++++++++++++++++--------------
usr.sbin/dhcp/includes/dhcpd.h | 7 +-
4 files changed, 158 insertions(+), 85 deletions(-)
diffs (truncated from 378 to 300 lines):
diff -r 97ffa2ae4034 -r 1962c7dd30ef usr.sbin/dhcp/client/Makefile
--- a/usr.sbin/dhcp/client/Makefile Sun Jul 23 16:30:27 2000 +0000
+++ b/usr.sbin/dhcp/client/Makefile Sun Jul 23 17:19:59 2000 +0000
@@ -36,6 +36,7 @@
SRCS = dhclient.c clparse.c
PROG = dhclient
MAN = dhclient.8 dhclient.conf.5 dhclient.leases.5 dhclient-script.8
+COPTS += -DCLIENT_PATH='"/usr/bin:/usr/sbin:/bin:/sbin"'
# XXX
BINDIR?= /sbin
diff -r 97ffa2ae4034 -r 1962c7dd30ef usr.sbin/dhcp/client/clparse.c
--- a/usr.sbin/dhcp/client/clparse.c Sun Jul 23 16:30:27 2000 +0000
+++ b/usr.sbin/dhcp/client/clparse.c Sun Jul 23 17:19:59 2000 +0000
@@ -42,7 +42,7 @@
#ifndef lint
static char copyright[] =
-"$Id: clparse.c,v 1.1.1.7 1999/03/29 23:00:49 mellon Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
+"$Id: clparse.c,v 1.1.1.7.2.1 2000/07/23 17:20:00 he Exp $ Copyright (c) 1997 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -50,6 +50,8 @@
struct client_config top_level_config;
+char client_script_name [] = "/etc/dhclient-script";
+
/* client-conf-file :== client-declarations EOF
client-declarations :== <nil>
| client-declaration
@@ -79,7 +81,7 @@
top_level_config.backoff_cutoff = 15;
top_level_config.initial_interval = 3;
top_level_config.bootp_policy = ACCEPT;
- top_level_config.script_name = "/etc/dhclient-script";
+ top_level_config.script_name = client_script_name;
top_level_config.requested_options
[top_level_config.requested_option_count++] =
DHO_SUBNET_MASK;
diff -r 97ffa2ae4034 -r 1962c7dd30ef usr.sbin/dhcp/client/dhclient.c
--- a/usr.sbin/dhcp/client/dhclient.c Sun Jul 23 16:30:27 2000 +0000
+++ b/usr.sbin/dhcp/client/dhclient.c Sun Jul 23 17:19:59 2000 +0000
@@ -56,7 +56,7 @@
#ifndef lint
static char ocopyright[] =
-"$Id: dhclient.c,v 1.20.2.2 1999/04/26 16:45:53 mellon Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
+"$Id: dhclient.c,v 1.20.2.3 2000/07/23 17:20:01 he Exp $ Copyright (c) 1995, 1996, 1997, 1998, 1999 The Internet Software Consortium. All rights reserved.\n";
#endif /* not lint */
#include "dhcpd.h"
@@ -142,6 +142,10 @@
no_daemon = 1;
} else if (!strcmp (argv [i], "-D")) {
save_scripts = 1;
+ } else if (!strcmp (argv [i], "-cf")) {
+ if (++i == argc)
+ usage (s);
+ path_dhclient_conf = argv [i];
} else if (!strcmp (argv [i], "-pf")) {
if (++i == argc)
usage (s);
@@ -1921,36 +1925,24 @@
char *reason;
struct string_list *medium;
{
- int fd;
-#ifndef HAVE_MKSTEMP
+ struct string_list *sl, *next;
- do {
-#endif
- strcpy (scriptName, "/tmp/dcsXXXXXX");
-#ifdef HAVE_MKSTEMP
- fd = mkstemp (scriptName);
-#else
- if (!mktemp (scriptName))
- error ("can't create temporary client script %s: %m",
- scriptName);
- fd = creat (scriptName, 0600);
- } while (fd < 0);
-#endif
+ if (ip) {
+ for (sl = ip -> client -> env; sl; sl = next) {
+ next = sl -> next;
+ dfree (sl, "script_init");
+ }
+ ip -> client -> env = (struct string_list *)0;
+ ip -> client -> envc = 0;
- scriptFile = fdopen (fd, "w");
- if (!scriptFile)
- error ("can't write script file: %m");
- fprintf (scriptFile, "#!/bin/sh\n\n");
- if (ip) {
- fprintf (scriptFile, "interface=\"%s\"\n", ip -> name);
- fprintf (scriptFile, "export interface\n");
+ client_envadd (ip -> client, "", "interface", "%s",
+ ip -> name);
+ if (medium)
+ client_envadd (ip -> client,
+ "", "medium", "%s", medium -> string);
+
+ client_envadd (ip -> client, "", "reason", "%s", reason);
}
- if (medium) {
- fprintf (scriptFile, "medium=\"%s\"\n", medium -> string);
- fprintf (scriptFile, "export medium\n");
- }
- fprintf (scriptFile, "reason=\"%s\"\n", reason);
- fprintf (scriptFile, "export reason\n");
}
void script_write_params (ip, prefix, lease)
@@ -1962,9 +1954,8 @@
u_int8_t dbuf [1500];
int len;
- fprintf (scriptFile, "%sip_address=\"%s\"\n",
- prefix, piaddr (lease -> address));
- fprintf (scriptFile, "export %sip_address\n", prefix);
+ client_envadd (ip -> client,
+ prefix, "ip_address", "%s", piaddr (lease -> address));
/* For the benefit of Linux (and operating systems which may
have similar needs), compute the network address based on
@@ -1985,36 +1976,26 @@
subnet = subnet_number (lease -> address, netmask);
if (subnet.len) {
- fprintf (scriptFile, "%snetwork_number=\"%s\";\n",
- prefix, piaddr (subnet));
- fprintf (scriptFile, "export %snetwork_number\n",
- prefix);
+ client_envadd (ip -> client, prefix, "network_number",
+ "%s", piaddr (subnet));
if (!lease -> options [DHO_BROADCAST_ADDRESS].len) {
broadcast = broadcast_addr (subnet, netmask);
if (broadcast.len) {
- fprintf (scriptFile,
- "%s%s=\"%s\";\n", prefix,
- "broadcast_address",
- piaddr (broadcast));
- fprintf (scriptFile,
- "export %s%s\n", prefix,
- "broadcast_address");
+ client_envadd (ip -> client,
+ prefix, "broadcast_address",
+ "%s", piaddr (subnet));
}
}
}
}
- if (lease -> filename) {
- fprintf (scriptFile, "%sfilename=\"%s\";\n",
- prefix, lease -> filename);
- fprintf (scriptFile, "export %sfilename\n", prefix);
- }
- if (lease -> server_name) {
- fprintf (scriptFile, "%sserver_name=\"%s\";\n",
- prefix, lease -> server_name);
- fprintf (scriptFile, "export %sserver_name\n", prefix);
- }
+ if (lease -> filename)
+ client_envadd (ip -> client,
+ prefix, "filename", "%s", lease -> filename);
+ if (lease -> server_name)
+ client_envadd (ip -> client, prefix, "server_name",
+ "%s", lease -> server_name);
for (i = 0; i < 256; i++) {
u_int8_t *dp;
@@ -2087,57 +2068,141 @@
len = 0;
}
if (len) {
- char *s = dhcp_option_ev_name (&dhcp_options [i]);
-
- fprintf (scriptFile, "%s%s=\"%s\"\n", prefix, s,
- pretty_print_option (i, dp, len, 0, 0));
- fprintf (scriptFile, "export %s%s\n", prefix, s);
+ char name [256];
+ if (dhcp_option_ev_name (name, sizeof name,
+ &dhcp_options [i])) {
+ client_envadd (ip -> client, prefix, name, "%s",
+ (pretty_print_option (i, dp,
+ len, 0, 0)));
+ }
}
}
- fprintf (scriptFile, "%sexpiry=\"%d\"\n",
- prefix, (int)lease -> expiry); /* XXX */
- fprintf (scriptFile, "export %sexpiry\n", prefix);
+ client_envadd (ip -> client,
+ prefix, "expiry", "%d", (int)(lease -> expiry));
}
int script_go (ip)
struct interface_info *ip;
{
int rval;
+ char *scriptName;
+ char *argv [2];
+ char **envp;
+ char *epp [3];
+ char reason [] = "REASON=NBI";
+ static char client_path [] = CLIENT_PATH;
+ int i;
+ struct string_list *sp, *next;
+ int pid, wpid, wstatus;
- if (ip)
- fprintf (scriptFile, "%s\n",
- ip -> client -> config -> script_name);
- else
- fprintf (scriptFile, "%s\n",
- top_level_config.script_name);
- fprintf (scriptFile, "exit $?\n");
- fclose (scriptFile);
- chmod (scriptName, 0700);
- rval = system (scriptName);
- if (!save_scripts)
- unlink (scriptName);
- return rval;
+ if (ip) {
+ scriptName = ip -> client -> config -> script_name;
+ envp = dmalloc ((ip -> client -> envc + 2) * sizeof (char *),
+ "script_go");
+ if (!envp) {
+ error ("No memory for client script environment.");
+ return 0;
+ }
+ i = 0;
+ for (sp = ip -> client -> env; sp; sp = sp -> next) {
+ envp [i++] = sp -> string;
+ }
+ envp [i++] = client_path;
+ envp [i] = (char *)0;
+ } else {
+ scriptName = top_level_config.script_name;
+ epp [0] = reason;
+ epp [1] = client_path;
+ epp [2] = (char *)0;
+ envp = epp;
+ }
+
+ argv [0] = scriptName;
+ argv [1] = (char *)0;
+
+ pid = fork ();
+ if (pid < 0) {
+ error ("fork: %m");
+ wstatus = 0;
+ } else if (pid) {
+ do {
+ wpid = wait (&wstatus);
+ } while (wpid != pid && wpid > 0);
+ if (wpid < 0) {
+ error ("wait: %m");
+ wstatus = 0;
+ }
+ } else {
+ execve (scriptName, argv, envp);
+ error ("execve (%s, ...): %m", scriptName);
+ exit (0);
+ }
+
+ if (ip) {
+ for (sp = ip -> client -> env; sp; sp = next) {
+ next = sp -> next;
+ dfree (sp, "script_go");
+ }
+ ip -> client -> env = (struct string_list *)0;
+ ip -> client -> envc = 0;
+ dfree (envp, "script_go");
+ }
+ return wstatus & 0xff;
}
-char *dhcp_option_ev_name (option)
+void client_envadd (struct client_state *client,
+ const char *prefix, const char *name, const char *fmt, ...)
+{
+ char spbuf [1024];
+ char *s;
+ unsigned len, i;
+ struct string_list *val;
+ va_list list;
+
+ va_start (list, fmt);
+ len = vsnprintf (spbuf, sizeof spbuf, fmt, list);
+ va_end (list);
+
+ val = dmalloc (strlen (prefix) + strlen (name) + 1 /* = */ +
+ len + sizeof *val, "client_envadd");
+ if (!val)
Home |
Main Index |
Thread Index |
Old Index