]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
When we explictly don't want an option, don't put it in the env.
authorRoy Marples <roy@marples.name>
Thu, 15 May 2008 08:48:17 +0000 (08:48 +0000)
committerRoy Marples <roy@marples.name>
Thu, 15 May 2008 08:48:17 +0000 (08:48 +0000)
client.c
configure.c
configure.h
dhcp.c
dhcp.h
dhcpcd.c
dhcpcd.h

index ab97dee3d5b7e176db38d7a5573a5f2bd7cade6e..c3681f49414a79957164b4eca8b2f66ca54c24fb 100644 (file)
--- 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;
                }
 
index cd241dfc3eca273e787c4ec508fe1664a9a571f0..0029fb8ad5db19f252aea8466f09af787755071b 100644 (file)
 #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;
 }
index d5d30d45006c8a0ac67e23aae81820a14becdbb4..c4c731cec2b6da4b9874bfbc885566c0fdd1281e 100644 (file)
@@ -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 b52041c69152119d5903647da26b20027dad68ae..5c826b99385230dcb1616939d51772e12f8a543b 100644 (file)
--- 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 765f8242532697e1acbe5dc6fd6f54911e8c945b..db3a439471ee7bc361b12bc4a86dcd98eb4371b1 100644 (file)
--- 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 *,
index 56ae2acc661d3e9bbd285ff6de9ab4348c6c7e1a..eba145cb22b74a9a323f1a3e7c3d1c73ef45f304 100644 (file)
--- 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;
                        }
index 1d6fc6e5e0e19190473e23e2467258e4b612f848..8715048c8ba349ef8296e138901231864121e655 100644 (file)
--- 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;