diff options
Diffstat (limited to 'dhcpcd.c')
-rw-r--r-- | dhcpcd.c | 40 |
1 files changed, 26 insertions, 14 deletions
@@ -144,14 +144,15 @@ static pid_t read_pid(const char *pidfile) { FILE *fp; - pid_t pid = 0; + pid_t pid; if ((fp = fopen(pidfile, "r")) == NULL) { errno = ENOENT; return 0; } - fscanf(fp, "%d", &pid); + if (fscanf(fp, "%d", &pid) != 1) + pid = 0; fclose(fp); return pid; @@ -240,7 +241,7 @@ parse_string_hwaddr(char *sbuf, ssize_t slen, char *str, int clid) l = 0; /* If processing a string on the clientid, first byte should be * 0 to indicate a non hardware type */ - if (clid) { + if (clid && *str) { *sbuf++ = 0; l++; } @@ -323,7 +324,7 @@ parse_option(int opt, char *oarg, struct options *options) break; case 'h': if (oarg) - s = parse_string(options->hostname + 1, + s = parse_string(options->hostname, HOSTNAME_MAX_LEN, oarg); else s = 0; @@ -331,11 +332,11 @@ parse_option(int opt, char *oarg, struct options *options) logger(LOG_ERR, "hostname: %s", strerror(errno)); return -1; } - if (s != 0 && options->hostname[1] == '.') { + if (s != 0 && options->hostname[0] == '.') { logger(LOG_ERR, "hostname cannot begin with a ."); return -1; } - options->hostname[0] = (uint8_t)s; + options->hostname[s] = '\0'; break; case 'i': if (oarg) @@ -528,10 +529,14 @@ parse_option(int opt, char *oarg, struct options *options) return -1; } options->clientid[0] = (uint8_t)s; +#ifdef CMDLINE_COMPAT if (s == 0) { options->options &= ~DHCPCD_DUID; options->options &= ~DHCPCD_CLIENTID; } +#else + options->options |= DHCPCD_CLIENTID; +#endif break; case 'K': options->options &= ~DHCPCD_LINK; @@ -646,11 +651,11 @@ main(int argc, char **argv) closefrom(3); /* Saves calling fflush(stream) in the logger */ setlinebuf(stdout); - openlog(PACKAGE, LOG_PID, LOG_LOCAL0); + openlog(PACKAGE, LOG_PID, LOG_DAEMON); setlogprefix(PACKAGE ": "); options = xzalloc(sizeof(*options)); - options->options |= DHCPCD_CLIENTID | DHCPCD_GATEWAY | DHCPCD_DAEMONISE; + options->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE; options->options |= DHCPCD_ARP | DHCPCD_IPV4LL | DHCPCD_LINK; options->timeout = DEFAULT_TIMEOUT; strlcpy(options->script, SCRIPT, sizeof(options->script)); @@ -660,6 +665,7 @@ main(int argc, char **argv) "%s %s", PACKAGE, VERSION); #ifdef CMDLINE_COMPAT + options->options |= DHCPCD_CLIENTID; add_option_mask(options->requestmask, DHO_DNSSERVER); add_option_mask(options->requestmask, DHO_DNSDOMAIN); add_option_mask(options->requestmask, DHO_DNSSEARCH); @@ -675,11 +681,12 @@ main(int argc, char **argv) } #endif - gethostname(options->hostname + 1, sizeof(options->hostname)); - if (strcmp(options->hostname + 1, "(none)") == 0 || - strcmp(options->hostname + 1, "localhost") == 0) - options->hostname[1] = '\0'; - *options->hostname = strlen(options->hostname + 1); + gethostname(options->hostname, HOSTNAME_MAX_LEN); + /* Ensure that the hostname is NULL terminated */ + options->hostname[HOSTNAME_MAX_LEN] = '\0'; + if (strcmp(options->hostname, "(none)") == 0 || + strcmp(options->hostname, "localhost") == 0) + options->hostname[0] = '\0'; while ((opt = getopt_long(argc, argv, OPTS EXTRA_OPTS, longopts, &option_index)) != -1) @@ -815,14 +822,17 @@ main(int argc, char **argv) case 'H': /* FALLTHROUGH */ case 'M': del_option_mask(options->requestmask, DHO_MTU); + add_environ(options, "skip_hooks=mtu", 0); break; case 'N': del_option_mask(options->requestmask, DHO_NTPSERVER); + add_environ(options, "skip_hooks=ntp.conf", 0); break; case 'R': del_option_mask(options->requestmask, DHO_DNSSERVER); del_option_mask(options->requestmask, DHO_DNSDOMAIN); del_option_mask(options->requestmask, DHO_DNSSEARCH); + add_environ(options, "skip_hooks=resolv.conf", 0); break; case 'S': add_option_mask(options->requestmask, DHO_MSCSR); @@ -830,6 +840,7 @@ main(int argc, char **argv) case 'Y': del_option_mask(options->requestmask, DHO_NISSERVER); del_option_mask(options->requestmask, DHO_NISDOMAIN); + add_environ(options, "skip_hooks=yp.conf", 0); break; #endif default: @@ -903,7 +914,8 @@ main(int argc, char **argv) goto abort; } - chdir("/"); + if (chdir("/") == -1) + logger(LOG_ERR, "chdir `/': %s", strerror(errno)); umask(022); if (sig != 0 && !(options->options & DHCPCD_DAEMONISED)) { |