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;
}
#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;
sigset_t full;
sigset_t old;
- logger(LOG_DEBUG, "exec `%s'", script);
+ logger(LOG_DEBUG, "exec `%s'", options->script);
/* Make our env */
elen = 4;
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';
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 */
}
}
}
- exec_script(options->script, iface->name, reason, NULL, old);
+ exec_script(options, iface->name, reason, NULL, old);
return 0;
}
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;
}
#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 *,
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;
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;
}
}
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;
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++;
}
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)
#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);
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 *,
}
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;
}
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;
}
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;