Ticket #366: 0001-avahi-daemon-add-support-for-whitelisting-and-blackl.patch

File 0001-avahi-daemon-add-support-for-whitelisting-and-blackl.patch, 11.7 KB (added by jpfau, 13 months ago)

Patch

  • avahi-core/addr-util.h

    From f7b32ed0620937ad5287c6790d88424c43e9a090 Mon Sep 17 00:00:00 2001
    From: Jeffrey Pfau <jeffrey@endrift.com>
    Date: Sat, 12 May 2012 14:13:16 -0700
    Subject: [PATCH] avahi-daemon: add support for whitelisting and blacklisting
     IP addresses
    
    ---
     avahi-core/addr-util.h         |    8 ++++
     avahi-core/core.h              |    3 ++
     avahi-core/iface.c             |   15 +++++++
     avahi-core/server.c            |   93 +++++++++++++++++++++++++++++++---------
     avahi-daemon/avahi-daemon.conf |    2 +
     avahi-daemon/main.c            |   34 +++++++++++++++
     man/avahi-daemon.conf.5.xml.in |   16 +++++++
     7 files changed, 150 insertions(+), 21 deletions(-)
    
    diff --git a/avahi-core/addr-util.h b/avahi-core/addr-util.h
    index 66a9422..cc38a66 100644
    a b  
    2525 
    2626#include <avahi-common/cdecl.h> 
    2727#include <avahi-common/address.h> 
     28#include <avahi-common/llist.h> 
    2829 
    2930AVAHI_C_DECL_BEGIN 
    3031 
     
    4243 * returns 1 if yes, 0 otherwise */ 
    4344int avahi_address_is_link_local(const AvahiAddress *a); 
    4445 
     46typedef struct AvahiAddressList AvahiAddressList; 
     47 
     48struct AvahiAddressList { 
     49    AvahiAddress address; 
     50    AVAHI_LLIST_FIELDS(AvahiAddressList, address); 
     51}; 
     52 
    4553AVAHI_C_DECL_END 
    4654 
    4755#endif 
  • avahi-core/core.h

    diff --git a/avahi-core/core.h b/avahi-core/core.h
    index f50c612..0e2bfa5 100644
    a b  
    3131#include <avahi-common/watch.h> 
    3232#include <avahi-common/timeval.h> 
    3333#include <avahi-core/rr.h> 
     34#include <avahi-core/addr-util.h> 
    3435 
    3536AVAHI_C_DECL_BEGIN 
    3637 
     
    4849    int use_ipv6;                     /**< Enable IPv6 support */ 
    4950    AvahiStringList *allow_interfaces;/**< Allow specific interface to be used for Avahi */ 
    5051    AvahiStringList *deny_interfaces; /**< Deny specific interfaces to be used for Avahi */ 
     52    AVAHI_LLIST_HEAD(AvahiAddressList, allow_addresses); /**< Allow specific IP addresses to be used for Avahi */ 
     53    AVAHI_LLIST_HEAD(AvahiAddressList, deny_addresses); /**< Deny specific IP addresses to be used for Avahi */ 
    5154    int publish_hinfo;                /**< Register a HINFO record for the host containing the local OS and CPU type */ 
    5255    int publish_addresses;            /**< Register A, AAAA and PTR records for all local IP addresses */ 
    5356    int publish_workstation;          /**< Register a _workstation._tcp service */ 
  • avahi-core/iface.c

    diff --git a/avahi-core/iface.c b/avahi-core/iface.c
    index 39a860a..5b3b313 100644
    a b  
    698698 
    699699int avahi_interface_address_is_relevant(AvahiInterfaceAddress *a) { 
    700700    AvahiInterfaceAddress *b; 
     701    AvahiAddressList *l; 
    701702    assert(a); 
    702703 
     704    for (l = a->monitor->server->config.deny_addresses; l; l = l->address_next) 
     705        if (avahi_address_cmp(&l->address, &a->address) == 0) 
     706            return 0; 
     707 
     708    if (a->monitor->server->config.allow_addresses) { 
     709 
     710        for (l = a->monitor->server->config.allow_addresses; l; l = l->address_next) 
     711            if (avahi_address_cmp(&l->address, &a->address) == 0) 
     712                goto good; 
     713 
     714        return 0; 
     715    } 
     716 
     717good: 
    703718    /* Publish public and non-deprecated IP addresses */ 
    704719    if (a->global_scope && !a->deprecated) 
    705720        return 1; 
  • avahi-core/server.c

    diff --git a/avahi-core/server.c b/avahi-core/server.c
    index 69a1d02..e5b540e 100644
    a b  
    15791579    c->use_ipv4 = 1; 
    15801580    c->allow_interfaces = NULL; 
    15811581    c->deny_interfaces = NULL; 
     1582    AVAHI_LLIST_HEAD_INIT(AvahiAddressList, c->allow_addresses); 
     1583    AVAHI_LLIST_HEAD_INIT(AvahiAddressList, c->deny_addresses); 
    15821584    c->host_name = NULL; 
    15831585    c->domain_name = NULL; 
    15841586    c->check_response_ttl = 0; 
     
    16061608} 
    16071609 
    16081610void avahi_server_config_free(AvahiServerConfig *c) { 
     1611    AvahiAddressList *l, *next; 
    16091612    assert(c); 
    16101613 
    16111614    avahi_free(c->host_name); 
     
    16131616    avahi_string_list_free(c->browse_domains); 
    16141617    avahi_string_list_free(c->allow_interfaces); 
    16151618    avahi_string_list_free(c->deny_interfaces); 
     1619    for (l = c->allow_addresses; l; l = next) { 
     1620        next = l->address_next; 
     1621        avahi_free(l); 
     1622    } 
     1623    for (l = c->deny_addresses; l; l = next) { 
     1624        next = l->address_next; 
     1625        avahi_free(l); 
     1626    } 
    16161627} 
    16171628 
    16181629AvahiServerConfig* avahi_server_config_copy(AvahiServerConfig *ret, const AvahiServerConfig *c) { 
    16191630    char *d = NULL, *h = NULL; 
    16201631    AvahiStringList *browse = NULL, *allow = NULL, *deny = NULL; 
     1632    AvahiAddressList *l, *next, *allow_addresses = NULL, *deny_addresses = NULL; 
    16211633    assert(ret); 
    16221634    assert(c); 
    16231635 
     
    16261638            return NULL; 
    16271639 
    16281640    if (c->domain_name) 
    1629         if (!(d = avahi_strdup(c->domain_name))) { 
    1630             avahi_free(h); 
    1631             return NULL; 
     1641        if (!(d = avahi_strdup(c->domain_name))) 
     1642            goto clean; 
     1643 
     1644    if (!(browse = avahi_string_list_copy(c->browse_domains)) && c->browse_domains) 
     1645        goto clean; 
     1646 
     1647    if (!(allow = avahi_string_list_copy(c->allow_interfaces)) && c->allow_interfaces) 
     1648        goto clean; 
     1649 
     1650    if (!(deny = avahi_string_list_copy(c->deny_interfaces)) && c->deny_interfaces) 
     1651        goto clean; 
     1652 
     1653    if (c->allow_addresses) { 
     1654        if (!(allow_addresses = avahi_new(AvahiAddressList, 1))) 
     1655            goto clean; 
     1656        AVAHI_LLIST_INIT(AvahiAddressList, address, allow_addresses); 
     1657        for (l = c->allow_addresses; l; l = l->address_next) { 
     1658            if (!(next = avahi_new(AvahiAddressList, 1))) 
     1659                goto clean; 
     1660            AVAHI_LLIST_INIT(AvahiAddressList, address, next); 
     1661            next->address = l->address; 
     1662            AVAHI_LLIST_PREPEND(AvahiAddressList, address, allow_addresses, next); 
    16321663        } 
    1633  
    1634     if (!(browse = avahi_string_list_copy(c->browse_domains)) && c->browse_domains) { 
    1635         avahi_free(h); 
    1636         avahi_free(d); 
    1637         return NULL; 
    16381664    } 
    16391665 
    1640     if (!(allow = avahi_string_list_copy(c->allow_interfaces)) && c->allow_interfaces) { 
    1641         avahi_string_list_free(browse); 
    1642         avahi_free(h); 
    1643         avahi_free(d); 
    1644         return NULL; 
    1645     } 
    1646  
    1647     if (!(deny = avahi_string_list_copy(c->deny_interfaces)) && c->deny_interfaces) { 
    1648         avahi_string_list_free(allow); 
    1649         avahi_string_list_free(browse); 
    1650         avahi_free(h); 
    1651         avahi_free(d); 
    1652         return NULL; 
     1666    if (c->deny_addresses) { 
     1667        if (!(deny_addresses = avahi_new(AvahiAddressList, 1))) 
     1668            goto clean; 
     1669        AVAHI_LLIST_INIT(AvahiAddressList, address, allow_addresses); 
     1670        for (l = c->deny_addresses; l; l = l->address_next) { 
     1671            if (!(next = avahi_new(AvahiAddressList, 1))) 
     1672                goto clean; 
     1673            AVAHI_LLIST_INIT(AvahiAddressList, address, next); 
     1674            next->address = l->address; 
     1675            AVAHI_LLIST_PREPEND(AvahiAddressList, address, deny_addresses, next); 
     1676        } 
    16531677    } 
    16541678 
    16551679    *ret = *c; 
     
    16581682    ret->browse_domains = browse; 
    16591683    ret->allow_interfaces = allow; 
    16601684    ret->deny_interfaces = deny; 
     1685    ret->allow_addresses = allow_addresses; 
     1686    ret->deny_addresses = deny_addresses; 
    16611687 
    16621688    return ret; 
     1689 
     1690clean: 
     1691    if (deny_addresses) { 
     1692        for (l = deny_addresses; l; l = next) { 
     1693            next = l->address_next; 
     1694            avahi_free(l); 
     1695        } 
     1696    } 
     1697    if (allow_addresses) { 
     1698        for (l = allow_addresses; l; l = next) { 
     1699            next = l->address_next; 
     1700            avahi_free(l); 
     1701        } 
     1702    } 
     1703    if (deny) 
     1704        avahi_string_list_free(deny); 
     1705    if (allow) 
     1706        avahi_string_list_free(allow); 
     1707    if (browse) 
     1708        avahi_string_list_free(browse); 
     1709    if (h) 
     1710        avahi_free(h); 
     1711    if (d) 
     1712        avahi_free(d); 
     1713    return NULL; 
    16631714} 
    16641715 
    16651716int avahi_server_errno(AvahiServer *s) { 
  • avahi-daemon/avahi-daemon.conf

    diff --git a/avahi-daemon/avahi-daemon.conf b/avahi-daemon/avahi-daemon.conf
    index 27e240d..77181bd 100644
    a b  
    2626use-ipv6=no 
    2727#allow-interfaces=eth0 
    2828#deny-interfaces=eth1 
     29#allow-addresses=192.168.50.10, 192.168.50.11 
     30#deny-addresses=192.168.50.20, 192.168.50.21 
    2931#check-response-ttl=no 
    3032#use-iff-running=no 
    3133#enable-dbus=yes 
  • avahi-daemon/main.c

    diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c
    index d46f40a..6ab5861 100644
    a b  
    667667                        c->server_config.deny_interfaces = avahi_string_list_add(c->server_config.deny_interfaces, *t); 
    668668 
    669669                    avahi_strfreev(e); 
     670                } else if (strcasecmp(p->key, "allow-addresses") == 0) { 
     671                    char **e, **t; 
     672 
     673                    e = avahi_split_csv(p->value); 
     674 
     675                    for (t = e; *t; t++) { 
     676                        AvahiAddressList *l = avahi_new(AvahiAddressList, 1); 
     677                        AVAHI_LLIST_INIT(AvahiAddressList, address, l); 
     678                        if (!avahi_address_parse(*t, AVAHI_PROTO_UNSPEC, &l->address)) { 
     679                            avahi_log_error("Invalid allow-addresses setting %s", p->value); 
     680                            avahi_strfreev(e); 
     681                            goto finish; 
     682                        } 
     683                        AVAHI_LLIST_PREPEND(AvahiAddressList, address, c->server_config.allow_addresses, l); 
     684                    } 
     685 
     686                    avahi_strfreev(e); 
     687                } else if (strcasecmp(p->key, "deny-addresses") == 0) { 
     688                    char **e, **t; 
     689 
     690                    e = avahi_split_csv(p->value); 
     691 
     692                    for (t = e; *t; t++) { 
     693                        AvahiAddressList *l = avahi_new(AvahiAddressList, 1); 
     694                        AVAHI_LLIST_INIT(AvahiAddressList, address, l); 
     695                        if (!avahi_address_parse(*t, AVAHI_PROTO_UNSPEC, &l->address)) { 
     696                            avahi_log_error("Invalid deny-addresses setting %s", p->value); 
     697                            avahi_strfreev(e); 
     698                            goto finish; 
     699                        } 
     700                        AVAHI_LLIST_PREPEND(AvahiAddressList, address, c->server_config.deny_addresses, l); 
     701                    } 
     702 
     703                    avahi_strfreev(e); 
    670704                } else if (strcasecmp(p->key, "ratelimit-interval-usec") == 0) { 
    671705                    AvahiUsec k; 
    672706 
  • man/avahi-daemon.conf.5.xml.in

    diff --git a/man/avahi-daemon.conf.5.xml.in b/man/avahi-daemon.conf.5.xml.in
    index bea7ed5..af8208b 100644
    a b  
    8686    </option> 
    8787 
    8888    <option> 
     89      <p><opt>allow-addresses=</opt> Set a comma separated list of 
     90      IP addresses that should be used by the avahi-daemon. 
     91      Traffic on other IP addresses will be ignored. If set to an 
     92      empty list all local IP addresses on the specified network 
     93      interfaces will be used.</p> 
     94    </option> 
     95 
     96    <option> 
     97      <p><opt>deny-addresses=</opt> Set a comma separated list of 
     98      IP addresses that should be ignored by avahi-daemon. Other 
     99      not specified IP addresses will be used, unless 
     100      <opt>allow-addresses=</opt> is set. This option takes 
     101      precedence over <opt>allow-addresses=</opt>.</p> 
     102    </option> 
     103 
     104    <option> 
    89105      <p><opt>check-response-ttl=</opt> Takes a boolean value ("yes" 
    90106      or "no"). If set to "yes", an additional security check is 
    91107      activated: incoming IP packets will be ignored unless the IP