X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-autoipd%2Fmain.c;h=3271d83e8f6f0af56f2d1dbe4ff411e85f481d80;hb=52502ca7cb37e480fba67a5e74f4549171cc5817;hp=f4574dc12d15234d70e25d54a49ef39a1a6203c6;hpb=2bbdbf1155cca40d5c89ef4fcd4db40f655b0a93;p=catta diff --git a/avahi-autoipd/main.c b/avahi-autoipd/main.c index f4574dc..3271d83 100644 --- a/avahi-autoipd/main.c +++ b/avahi-autoipd/main.c @@ -136,6 +136,7 @@ static int no_chroot = 0; #endif static int no_drop_root = 0; static int wrote_pid_file = 0; +static char *action_script = NULL; static enum { DAEMON_RUN, @@ -248,13 +249,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 +269,8 @@ fail: if (f) fclose(f); + umask(u); + return -1; } @@ -762,12 +768,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); @@ -836,7 +841,7 @@ static FILE* fork_dispatcher(void) { } if (daemon_exec("/", &k, - AVAHI_IPCONF_SCRIPT, AVAHI_IPCONF_SCRIPT, + action_script, action_script, callout_event_table[info.event], name, inet_ntop(AF_INET, &info.address, buf, sizeof(buf)), NULL) < 0) { @@ -1028,7 +1033,7 @@ static int drop_privs(void) { daemon_log(LOG_INFO, "Successfully dropped root privileges."); } - + return 0; } @@ -1094,7 +1099,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; } @@ -1418,6 +1423,8 @@ static void help(FILE *f, const char *a0) { " -V --version Show version\n" " -S --start=ADDRESS Start with this address from the IPv4LL range\n" " 169.254.0.0/16\n" + " -t --script=script Action script to run (defaults to\n" + " /etc/avahi/avahi-autoipd.action)\n" " -w --wait Wait until an address has been acquired before\n" " daemonizing\n" " --force-bind Assign an IPv4LL address even if a routable address\n" @@ -1453,6 +1460,7 @@ static int parse_command_line(int argc, char *argv[]) { { "check", no_argument, NULL, 'c' }, { "version", no_argument, NULL, 'V' }, { "start", required_argument, NULL, 'S' }, + { "script", required_argument, NULL, 't' }, { "wait", no_argument, NULL, 'w' }, { "force-bind", no_argument, NULL, OPTION_FORCE_BIND }, { "no-drop-root", no_argument, NULL, OPTION_NO_DROP_ROOT }, @@ -1464,8 +1472,7 @@ 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) { + while ((c = getopt_long(argc, argv, "hDskrcVS:t:w", long_options, NULL)) >= 0) { switch(c) { case 's': @@ -1496,6 +1503,10 @@ static int parse_command_line(int argc, char *argv[]) { return -1; } break; + case 't': + avahi_free(action_script); + action_script = avahi_strdup(optarg); + break; case 'w': wait_for_address = 1; break; @@ -1523,7 +1534,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; } } @@ -1545,6 +1555,9 @@ static int parse_command_line(int argc, char *argv[]) { fprintf(stderr, "Too many arguments\n"); return -1; } + + if (!action_script) + action_script = avahi_strdup(AVAHI_IPCONF_SCRIPT); return 0; } @@ -1676,6 +1689,7 @@ finish: avahi_free(pid_file_name); avahi_free(argv0); avahi_free(interface_name); + avahi_free(action_script); return r; }