X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;ds=sidebyside;f=avahi-autoipd%2Fmain.c;h=446b8b7ac88cf955e252c1223c6651ab2b7e11c3;hb=747f75372063371865bf5fc9857982defcffdca4;hp=58811a3e91194058a634265419623096d3fe6970;hpb=f10b82b26456f44d03d0c28d93c5118b859d3891;p=catta diff --git a/avahi-autoipd/main.c b/avahi-autoipd/main.c index 58811a3..446b8b7 100644 --- a/avahi-autoipd/main.c +++ b/avahi-autoipd/main.c @@ -248,13 +248,16 @@ fail: 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); @@ -265,6 +268,8 @@ fail: if (f) fclose(f); + umask(u); + return -1; } @@ -762,12 +767,11 @@ recv_packet(int fd __unused, ArpPacket **packet, size_t *packet_len) 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); @@ -1026,9 +1030,9 @@ static int drop_privs(void) { 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; } @@ -1094,7 +1098,7 @@ static int loop(int iface, uint32_t addr) { 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; } @@ -1464,7 +1468,6 @@ static int parse_command_line(int argc, char *argv[]) { { NULL, 0, NULL, 0 } }; - opterr = 0; while ((c = getopt_long(argc, argv, "hDskrcVS:w", long_options, NULL)) >= 0) { switch(c) { @@ -1523,7 +1526,6 @@ static int parse_command_line(int argc, char *argv[]) { #endif default: - fprintf(stderr, "Invalid command line argument: %s\n", argv[optind-1]); return -1; } }