chiark / gitweb /
fixes, also do uncompressed v6 addr
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jun 2012 00:38:47 +0000 (01:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 2 Jun 2012 00:38:47 +0000 (01:38 +0100)
authbind.1
helper.c

index b8710f5e807f2460335131904153886cc5f6c0a5..52f0204f38eeb39440e50d9085749895867801b0 100644 (file)
@@ -86,10 +86,14 @@ Secondly, if that test fails to resolve the matter,
 (any protocol) or failing that
 .BI /etc/authbind/byaddr/ addr : port
 (IPv4 only)
-is tested, in the same manner as above.  (Here
+is tested, in the same manner as above.  Here
 .I addr
 is as from
-.BR inet_ntop .)
+.BR inet_ntop .
+Since this is not completely predictable for IPv6,
+for IPv6 a variant of
+.I addr
+is also tested which does not contain any ommitted zeroes or colons.
 .PP
 Thirdly, if the question is still unresolved, the file
 .BI /etc/authbind/byuid/ uid
index f58ee9ec4f30c9a4aa359b6e7bcd3b608ee46b4f..c3133eb885893f12b9ef979aa270225357b44732 100644 (file)
--- a/helper.c
+++ b/helper.c
@@ -148,9 +148,19 @@ int main(int argc, const char *const *argv) {
   if (errno != ENOENT) exiterrno(errno);
 
   if (af == AF_INET6) {
-    char sbuf[addrlen_any*2+1];
-    bytes2hex(addr_any,sbuf,addrlen_any);
+    char sbuf[addrlen_any*3+1], *sp = sbuf;
+    const unsigned char *ip = addr_any;
+    int i;
+    for (i=0; i<8; i++) {
+      unsigned val = 0;
+      val |= *ip++;  val <<= 8;
+      val |= *ip++;
+      if (i) *sp++ = ':';
+      sp += sprintf(sp,"%x",val);
+    }
     snprintf(fnbuf,sizeof(fnbuf)-1,"byaddr/%s%s,%u",tophalfchar,sbuf,hport);
+    if (!access(fnbuf,X_OK)) authorised();
+    if (errno != ENOENT) exiterrno(errno);
   }
 
   uid= getuid(); if (uid==(uid_t)-1) perrorfail("getuid");
@@ -161,10 +171,11 @@ int main(int argc, const char *const *argv) {
 
   while (fgets(fnbuf,sizeof(fnbuf)-1,file)) {
     unsigned int a1,a2,a3,a4, alen,pmin,pmax;
-    int nchar= -1;
+    int nchar;
 
     if (af == AF_INET &&
-       (sscanf(fnbuf," %u.%u.%u.%u/%u: %u,%u %n",
+       (nchar = -1,
+        sscanf(fnbuf," %u.%u.%u.%u/%u: %u,%u %n",
                &a1,&a2,&a3,&a4,&alen,&pmin,&pmax,&nchar),
         nchar == strlen(fnbuf))) {
 
@@ -180,7 +191,7 @@ int main(int argc, const char *const *argv) {
     } else {
 
       char *comma = strchr(fnbuf,',');
-      if (comma) continue;
+      if (!comma) continue;
       *comma++ = '\0';
 
       char *hyphen = strchr(fnbuf,'-');
@@ -202,6 +213,7 @@ int main(int argc, const char *const *argv) {
          memcmp(addr_any,maxaddr,addrlen_any) > 0)
        continue;
 
+      nchar = -1;
       sscanf(comma," %u-%u %n",
             &pmin,&pmax,&nchar);
       if (nchar != strlen(comma))