From: Roy Marples Date: Thu, 15 May 2008 08:48:17 +0000 (+0000) Subject: When we explictly don't want an option, don't put it in the env. X-Git-Tag: v4.0.2~404 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=35ba5bc0c444ee8b3f9b76ddcc440955940d9786;p=thirdparty%2Fdhcpcd.git When we explictly don't want an option, don't put it in the env. --- diff --git a/client.c b/client.c index ab97dee3..c3681f49 100644 --- a/client.c +++ b/client.c @@ -1018,8 +1018,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, free(addr); if (state->options & DHCPCD_TEST) { - exec_script(options->script, iface->name, - "TEST", dhcp, NULL); + exec_script(options, iface->name, "TEST", dhcp, NULL); return -1; } diff --git a/configure.c b/configure.c index cd241dfc..0029fb8a 100644 --- a/configure.c +++ b/configure.c @@ -49,10 +49,11 @@ #define DEFAULT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" int -exec_script(const char *script, const char *iface, const char *reason, +exec_script(const struct options *options, const char *iface, + const char *reason, const struct dhcp_message *dhcpn, const struct dhcp_message *dhcpo) { - char *const argv[2] = { (char *)script, NULL }; + char *const argv[2] = { (char *)options->script, NULL }; char **env = NULL, **ep; char *path; ssize_t e, elen; @@ -62,7 +63,7 @@ exec_script(const char *script, const char *iface, const char *reason, sigset_t full; sigset_t old; - logger(LOG_DEBUG, "exec `%s'", script); + logger(LOG_DEBUG, "exec `%s'", options->script); /* Make our env */ elen = 4; @@ -84,17 +85,17 @@ exec_script(const char *script, const char *iface, const char *reason, env[3] = xmalloc(e); snprintf(env[3], e, "pid=%d", getpid()); if (dhcpo) { - e = configure_env(NULL, NULL, dhcpo); + e = configure_env(NULL, NULL, dhcpo, options); if (e > 0) { env = xrealloc(env, sizeof(char *) * (elen + e + 1)); - elen += configure_env(env + elen, "old", dhcpo); + elen += configure_env(env + elen, "old", dhcpo, options); } } if (dhcpn) { - e = configure_env(NULL, NULL, dhcpn); + e = configure_env(NULL, NULL, dhcpn, options); if (e > 0) { env = xrealloc(env, sizeof(char *) * (elen + e + 1)); - elen += configure_env(env + elen, "new", dhcpn); + elen += configure_env(env + elen, "new", dhcpn, options); } } env[elen] = '\0'; @@ -124,8 +125,8 @@ exec_script(const char *script, const char *iface, const char *reason, signal_reset(); #endif sigprocmask(SIG_SETMASK, &old, NULL); - execve(script, argv, env); - logger(LOG_ERR, "%s: %s", script, strerror(errno)); + execve(options->script, argv, env); + logger(LOG_ERR, "%s: %s", options->script, strerror(errno)); _exit(111); /* NOTREACHED */ } @@ -433,7 +434,7 @@ configure(struct interface *iface, const char *reason, } } - exec_script(options->script, iface->name, reason, NULL, old); + exec_script(options, iface->name, reason, NULL, old); return 0; } @@ -478,6 +479,6 @@ configure(struct interface *iface, const char *reason, if (write_lease(iface, dhcp) == -1) logger(LOG_ERR, "write_lease: %s", strerror(errno)); - exec_script(options->script, iface->name, reason, dhcp, old); + exec_script(options, iface->name, reason, dhcp, old); return 0; } diff --git a/configure.h b/configure.h index d5d30d45..c4c731ce 100644 --- a/configure.h +++ b/configure.h @@ -32,7 +32,7 @@ #include "dhcp.h" #include "net.h" -int exec_script(const char *, const char *, const char *, +int exec_script(const struct options *, const char *, const char *, const struct dhcp_message *, const struct dhcp_message *); int configure(struct interface *, const char *, const struct dhcp_message *, const struct dhcp_message *, diff --git a/dhcp.c b/dhcp.c index b52041c6..5c826b99 100644 --- a/dhcp.c +++ b/dhcp.c @@ -165,7 +165,7 @@ print_options(void) printf("%03d %s\n", opt->option, opt->var); } -int make_reqmask(struct options *options, char **opts, int add) +int make_reqmask(uint8_t *mask, char **opts, int add) { char *token; char *p = *opts; @@ -179,10 +179,10 @@ int make_reqmask(struct options *options, char **opts, int add) continue; if (strcmp(opt->var, token) == 0) { if (add == 1) - add_reqmask(options->reqmask, + add_reqmask(mask, opt->option); else - del_reqmask(options->reqmask, + del_reqmask(mask, opt->option); break; } @@ -1113,7 +1113,8 @@ _setenv(char ***e, const char *prefix, const char *var, const char *value) } ssize_t -configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp) +configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp, + const struct options *options) { unsigned int i; const uint8_t *p; @@ -1134,6 +1135,8 @@ configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp) for (opt = dhcp_opts; opt->option; opt++) { if (!opt->var) continue; + if (has_reqmask(options->nomask, opt->option)) + continue; if (get_option(dhcp, opt->option)) e++; } @@ -1175,6 +1178,8 @@ configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp) for (opt = dhcp_opts; opt->option; opt++) { if (!opt->var) continue; + if (has_reqmask(options->nomask, opt->option)) + continue; val = NULL; p = _get_option(dhcp, opt->option, &pl, NULL); if (!p) diff --git a/dhcp.h b/dhcp.h index 765f8242..db3a4394 100644 --- a/dhcp.h +++ b/dhcp.h @@ -162,7 +162,7 @@ struct dhcp_lease { #define add_reqmask(var, val) (var[val >> 3] |= 1 << (val & 7)) #define del_reqmask(var, val) (var[val >> 3] &= ~(1 << (val & 7))) #define has_reqmask(var, val) (var[val >> 3] & (1 << (val & 7))) -int make_reqmask(struct options *, char **, int); +int make_reqmask(uint8_t *, char **, int); void print_options(void); const uint8_t *get_option(const struct dhcp_message *, uint8_t); char *get_option_string(const struct dhcp_message *, uint8_t); @@ -171,7 +171,8 @@ int get_option_uint32(uint32_t *, const struct dhcp_message *, uint8_t); int get_option_uint16(uint16_t *, const struct dhcp_message *, uint8_t); int get_option_uint8(uint8_t *, const struct dhcp_message *, uint8_t); struct rt *get_option_routes(const struct dhcp_message *); -ssize_t configure_env(char **, const char *, const struct dhcp_message *); +ssize_t configure_env(char **, const char *, const struct dhcp_message *, + const struct options *); ssize_t make_message(struct dhcp_message **, const struct interface *, const struct dhcp_lease *, diff --git a/dhcpcd.c b/dhcpcd.c index 56ae2acc..eba145cb 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -213,7 +213,7 @@ parse_option(int opt, char *oarg, struct options *options) } break; case 'o': - if (make_reqmask(options, &oarg, 1) != 0) { + if (make_reqmask(options->reqmask, &oarg, 1) != 0) { logger(LOG_ERR, "unknown option `%s'", oarg); return -1; } @@ -613,7 +613,11 @@ main(int argc, char **argv) sig = SIGTERM; break; case 'O': - if (make_reqmask(options, &optarg, -1) != 0) { + if (make_reqmask(options->reqmask, &optarg, -1) != 0) { + logger(LOG_ERR, "unknown option `%s'", optarg); + return -1; + } + if (make_reqmask(options->nomask, &optarg, 1) != 0) { logger(LOG_ERR, "unknown option `%s'", optarg); return -1; } diff --git a/dhcpcd.h b/dhcpcd.h index 1d6fc6e5..8715048c 100644 --- a/dhcpcd.h +++ b/dhcpcd.h @@ -77,6 +77,7 @@ struct options { char clientid[CLIENT_ID_MAX_LEN]; char userclass[USERCLASS_MAX_LEN]; uint8_t reqmask[256 / 8]; + uint8_t nomask[256 / 8]; size_t userclass_len; uint32_t leasetime; time_t timeout;