static int save_address(const char *fn, uint32_t addr) {
FILE *f;
char buf[32];
+ mode_t u;
assert(fn);
-
+
+ u = umask(0033);
if (!(f = fopen(fn, "w"))) {
daemon_log(LOG_ERR, "fopen() failed: %s", strerror(errno));
goto fail;
}
+ umask(u);
fprintf(f, "%s\n", inet_ntop(AF_INET, &addr, buf, sizeof (buf)));
fclose(f);
if (f)
fclose(f);
+ umask(u);
+
return -1;
}
int is_ll_address(uint32_t addr) {
return
- (ntohl(addr) & IPV4LL_NETMASK) == IPV4LL_NETWORK &&
- ntohl(addr) != IPV4LL_NETWORK &&
- ntohl(addr) != IPV4LL_BROADCAST;
+ ((ntohl(addr) & IPV4LL_NETMASK) == IPV4LL_NETWORK) &&
+ ((ntohl(addr) & 0x0000FF00) != 0x0000) &&
+ ((ntohl(addr) & 0x0000FF00) != 0xFF00);
}
-
static struct timeval *elapse_time(struct timeval *tv, unsigned msec, unsigned jitter) {
assert(tv);
set_env("LOGNAME", pw->pw_name);
set_env("HOME", pw->pw_dir);
- daemon_log(LOG_ERR, "Successfully dropped root privileges.");
+ daemon_log(LOG_INFO, "Successfully dropped root privileges.");
}
-
+
return 0;
}
load_address(address_fn, &addr);
if (addr && !is_ll_address(addr)) {
- daemon_log(LOG_WARNING, "Requested address %s is not from IPv4LL range 169.254/16, ignoring.", inet_ntop(AF_INET, &addr, buf, sizeof(buf)));
+ daemon_log(LOG_WARNING, "Requested address %s is not from IPv4LL range 169.254/16 or a reserved address, ignoring.", inet_ntop(AF_INET, &addr, buf, sizeof(buf)));
addr = 0;
}
{ NULL, 0, NULL, 0 }
};
- opterr = 0;
while ((c = getopt_long(argc, argv, "hDskrcVS:w", long_options, NULL)) >= 0) {
switch(c) {
#endif
default:
- fprintf(stderr, "Invalid command line argument: %s\n", argv[optind-1]);
return -1;
}
}