]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/ipacl.c
remap: Change remapping function argument type from void to int16_t / float as approp...
[pulseaudio] / src / pulsecore / ipacl.c
index a240d2a0adc1bfe317fcbaa56ee2d3481c52018d..5455d0e876b11d5f7b9a1ed31a05213ac71c16a0 100644 (file)
@@ -1,5 +1,3 @@
-/* $Id$ */
-
 /***
   This file is part of PulseAudio.
 
@@ -30,9 +28,6 @@
 #include <sys/types.h>
 #include <string.h>
 
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
 #ifdef HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
 #ifdef HAVE_NETINET_IP_H
 #include <netinet/ip.h>
 #endif
-#ifdef HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
-
-#include "winsock.h"
 
 #include <pulse/xmalloc.h>
 
 #include <pulsecore/core-util.h>
 #include <pulsecore/llist.h>
 #include <pulsecore/log.h>
-
-#ifndef HAVE_INET_PTON
-#include "inet_pton.h"
-#endif
+#include <pulsecore/macro.h>
+#include <pulsecore/socket.h>
+#include <pulsecore/arpa-inet.h>
 
 #include "ipacl.h"
 
@@ -64,7 +53,9 @@ struct acl_entry {
     PA_LLIST_FIELDS(struct acl_entry);
     int family;
     struct in_addr address_ipv4;
+#ifdef HAVE_IPV6
     struct in6_addr address_ipv6;
+#endif
     int bits;
 };
 
@@ -77,7 +68,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
     char *a;
     pa_ip_acl *acl;
 
-    assert(s);
+    pa_assert(s);
 
     acl = pa_xnew(pa_ip_acl, 1);
     PA_LLIST_HEAD_INIT(struct acl_entry, acl->entries);
@@ -91,7 +82,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
             *slash = 0;
             slash++;
             if (pa_atou(slash, &bits) < 0) {
-                pa_log("failed to parse number of bits: %s", slash);
+                pa_log_warn("Failed to parse number of bits: %s", slash);
                 goto fail;
             }
         } else
@@ -102,21 +93,22 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
             e.bits = bits == (uint32_t) -1 ? 32 : (int) bits;
 
             if (e.bits > 32) {
-                pa_log("number of bits out of range: %i", e.bits);
+                pa_log_warn("Number of bits out of range: %i", e.bits);
                 goto fail;
             }
 
             e.family = AF_INET;
 
             if (e.bits < 32 && (uint32_t) (ntohl(e.address_ipv4.s_addr) << e.bits) != 0)
-                pa_log_warn("WARNING: Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
+                pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
 
+#ifdef HAVE_IPV6
         } else if (inet_pton(AF_INET6, a, &e.address_ipv6) > 0) {
 
             e.bits = bits == (uint32_t) -1 ? 128 : (int) bits;
 
             if (e.bits > 128) {
-                pa_log("number of bits out of range: %i", e.bits);
+                pa_log_warn("Number of bits out of range: %i", e.bits);
                 goto fail;
             }
             e.family = AF_INET6;
@@ -124,7 +116,7 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
             if (e.bits < 128) {
                 int t = 0, i;
 
-                for (i = 0, bits = e.bits; i < 16; i++) {
+                for (i = 0, bits = (uint32_t) e.bits; i < 16; i++) {
 
                     if (bits >= 8)
                         bits -= 8;
@@ -138,11 +130,12 @@ pa_ip_acl* pa_ip_acl_new(const char *s) {
                 }
 
                 if (t)
-                    pa_log_warn("WARNING: Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
+                    pa_log_warn("Host part of ACL entry '%s/%u' is not zero!", a, e.bits);
             }
+#endif
 
         } else {
-            pa_log("failed to parse address: %s", a);
+            pa_log_warn("Failed to parse address: %s", a);
             goto fail;
         }
 
@@ -162,7 +155,7 @@ fail:
 }
 
 void pa_ip_acl_free(pa_ip_acl *acl) {
-    assert(acl);
+    pa_assert(acl);
 
     while (acl->entries) {
         struct acl_entry *e = acl->entries;
@@ -176,23 +169,29 @@ void pa_ip_acl_free(pa_ip_acl *acl) {
 int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
     struct sockaddr_storage sa;
     struct acl_entry *e;
-    socklen_t  salen;
+    socklen_t salen;
 
-    assert(acl);
-    assert(fd >= 0);
+    pa_assert(acl);
+    pa_assert(fd >= 0);
 
     salen = sizeof(sa);
     if (getpeername(fd, (struct sockaddr*) &sa, &salen) < 0)
         return -1;
 
+#ifdef HAVE_IPV6
     if (sa.ss_family != AF_INET && sa.ss_family != AF_INET6)
+#else
+    if (sa.ss_family != AF_INET)
+#endif
         return -1;
 
     if (sa.ss_family == AF_INET && salen != sizeof(struct sockaddr_in))
         return -1;
 
+#ifdef HAVE_IPV6
     if (sa.ss_family == AF_INET6 && salen != sizeof(struct sockaddr_in6))
         return -1;
+#endif
 
     for (e = acl->entries; e; e = e->next) {
 
@@ -205,8 +204,9 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
             if (e->bits == 0 || /* this needs special handling because >> takes the right-hand side modulo 32 */
                 (ntohl(sai->sin_addr.s_addr ^ e->address_ipv4.s_addr) >> (32 - e->bits)) == 0)
                 return 1;
+#ifdef HAVE_IPV6
         } else if (e->family == AF_INET6) {
-            int i, bits ;
+            int i, bits;
             struct sockaddr_in6 *sai = (struct sockaddr_in6*) &sa;
 
             if (e->bits == 128)
@@ -232,6 +232,7 @@ int pa_ip_acl_check(pa_ip_acl *acl, int fd) {
                 if (bits == 0)
                     return 1;
             }
+#endif
         }
     }