]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
external_acl helpers updated to use the new protocol format based
authorhno <>
Sun, 15 Aug 2004 04:54:52 +0000 (04:54 +0000)
committerhno <>
Sun, 15 Aug 2004 04:54:52 +0000 (04:54 +0000)
on URL-escaped strings rather than quoted words..

helpers/external_acl/ip_user/Makefile.am
helpers/external_acl/ip_user/main.c
helpers/external_acl/ldap_group/ChangeLog
helpers/external_acl/ldap_group/Makefile.am
helpers/external_acl/ldap_group/squid_ldap_group.c
helpers/external_acl/unix_group/Makefile.am
helpers/external_acl/unix_group/check_group.c
helpers/external_acl/wbinfo_group/wbinfo_group.pl
helpers/external_acl/winbind_group/Makefile.am
helpers/external_acl/winbind_group/wb_check_group.c

index 798df2a0935af0df9691438004a8940cb2e0fbed..8748e8afa63bc3a0aba7386a0f165977dac8978f 100644 (file)
@@ -1,7 +1,7 @@
 #
 #  Makefile for the ip_user external_acl helper by Rodrigo Campos
 #
-#  $Id: Makefile.am,v 1.3 2003/01/23 00:36:01 robertc Exp $
+#  $Id: Makefile.am,v 1.4 2004/08/14 22:54:52 hno Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
@@ -24,7 +24,5 @@ EXTRA_DIST = \
 
 # sysconf_DATA = 
 
-LDADD  = @XTRA_LIBS@
-
-INCLUDES      = -I. -I$(top_builddir)/include -I$(top_srcdir)/include \
-               -I$(top_srcdir)/src/
+LDADD          = -L$(top_builddir)/lib -lmiscutil @XTRA_LIBS@
+INCLUDES       = -I. -I$(top_builddir)/include -I$(top_srcdir)/include
index c692edbf6a6c01d598e7720729cfedaf90eb7d6b..7b6bbe28a3b43b043d3dd0300d7821ed61311c1c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: main.c,v 1.3 2003/01/23 00:36:01 robertc Exp $ 
+/* $Id: main.c,v 1.4 2004/08/14 22:54:52 hno Exp $ 
 * Copyright (C) 2002 Rodrigo Campos
 *
 * This program is free software; you can redistribute it and/or modify
@@ -25,7 +25,7 @@
 
 
 #include "ip_user.h"
-
+#include "util.h"
 
 void
 usage (char *program_name)
@@ -65,17 +65,25 @@ main (int argc, char *argv[])
   current_entry = load_dict (FH);
 
   while (fgets (line, sizeof (line), stdin)) {
-    if ((cp = strchr (line, '\n')) != NULL) {
-      *cp = '\0';
+    if ((cp = strchr (line, '\n')) == NULL) {
+       /* too large message received.. skip and deny */
+       fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], line);
+       while (fgets(line, sizeof(line), stdin)) {
+           fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], line);
+           if (strchr(line, '\n') != NULL)
+               break;
+       }
+       goto error;
     }
-    if ((cp = strtok (line, " \t")) != NULL) {
-      address = cp;
-      username = strtok (NULL, " \t");
-    } else {
-      fprintf (stderr, "helper: unable to read tokens\n");
-      printf ("ERR\n");
-      continue;
+    *cp = '\0';
+    address = strtok (line, " \t");
+    username = strtok (NULL, " \t");
+    if (!address || !username) {
+      fprintf (stderr, "%s: unable to read tokens\n", argv[0]);
+      goto error;
     }
+    rfc1738_unescape(address);
+    rfc1738_unescape(username);
 #ifdef DEBUG
     printf ("result: %d\n",
            dict_lookup (current_entry, username, address));
@@ -83,10 +91,9 @@ main (int argc, char *argv[])
     if ((dict_lookup (current_entry, username, address)) != 0) {
       printf ("OK\n");
     } else {
+error:
       printf ("ERR\n");
     }
-
-
   }
 
 
index 562266aa43716c59a210eabe6c780d399c81a402..7914e6cb687843b11d26844a824170d11ca2d0a7 100644 (file)
@@ -1,6 +1,23 @@
+Version 2.15
+
+2004-08-15 Henrik Nordstrom <hno@squid-cache.org>
+       Helper format changed in Squid-3.0 to use URL escaped
+       strings. Simplifies things a bit and well known encoding.
+
+Version 2.14
+
+2004-03-02 Henrik Nordstrom <hno@squid-cache.org>
+       Added -d (debug) flag
+
+2004-02-09 Henrik Nordstrom <hno@squid-cache.org>
+       -E and -S options mismatch
+
+2004-01-08 Henrik Nordstrom <hno@squid-cache.org>
+       Increase buffer size when reading group lookups from Squid
+
 Version 2.13
 
-2003-01-05 Henrik Nordstrom <hno@squid-cache.org>
+2004-01-05 Henrik Nordstrom <hno@squid-cache.org>
        Corrected TLS mode (-Z)
 
 Version 2.12
index 829b31b1f7906723dd9c2b2a847906429dfd3f00..5a9d44b0f187eccbbd86387891f6b2bf65b1f284 100644 (file)
@@ -1,14 +1,15 @@
 #
 #  Makefile for the Squid LDAP authentication helper
 #
-#  $Id: Makefile.am,v 1.4 2003/01/23 00:36:05 robertc Exp $
+#  $Id: Makefile.am,v 1.5 2004/08/14 22:54:53 hno Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
 
-libexec_PROGRAMS       = squid_ldap_group
-man_MANS               = squid_ldap_group.8
-EXTRA_DIST             = squid_ldap_group.8
+libexec_PROGRAMS               = squid_ldap_group
+man_MANS                       = squid_ldap_group.8
+EXTRA_DIST                     = squid_ldap_group.8
 squid_ldap_group_SOURCES       = squid_ldap_group.c
 
-LDADD = -lldap -llber $(XTRA_LIBS)
+LDADD          = -L$(top_builddir)/lib -lmiscutil -lldap -llber @XTRA_LIBS@
+INCLUDES       = -I. -I$(top_builddir)/include -I$(top_srcdir)/include
index 3074a03e6ee2e7d0418005c9b3dc38d61ce32ab7..8280a8d3eeff0cc593ead060e90702461079cb9a 100644 (file)
@@ -43,6 +43,8 @@
 #include <sys/time.h>
 #endif
 
+#include "util.h"
+
 #define PROGRAM_NAME "squid_ldap_group"
 
 /* Globals */
@@ -162,51 +164,6 @@ squid_ldap_memfree(char *p)
   #endif
 #endif
 
-static char *
-strwordtok(char *buf, char **t)
-{
-    unsigned char *word = NULL;
-    unsigned char *p = (unsigned char *) buf;
-    unsigned char *d;
-    unsigned char ch;
-    int quoted = 0;
-    if (!p)
-       p = (unsigned char *) *t;
-    if (!p)
-       goto error;
-    while (*p && isspace(*p))
-       p++;
-    if (!*p)
-       goto error;
-    word = d = p;
-    while ((ch = *p)) {
-       switch (ch) {
-       case '\\':
-           p++;
-           *d++ = ch = *p;
-           if (ch)
-               p++;
-           break;
-       case '"':
-           quoted = !quoted;
-           p++;
-           break;
-       default:
-           if (!quoted && isspace(*p)) {
-               p++;
-               goto done;
-           }
-           *d++ = *p++;
-           break;
-       }
-    }
-  done:
-    *d++ = '\0';
-  error:
-    *t = (char *) p;
-    return (char *) word;
-}
-
 int
 main(int argc, char **argv)
 {
@@ -218,6 +175,7 @@ main(int argc, char **argv)
     int port = LDAP_PORT;
     int use_extension_dn = 0;
     int strip_nt_domain = 0;
+    int err = 0;
 
     setbuf(stdout, NULL);
 
@@ -430,20 +388,41 @@ main(int argc, char **argv)
        exit(1);
     }
     while (fgets(buf, 256, stdin) != NULL) {
-       char *tptr;
        int found = 0;
-       user = strwordtok(buf, &tptr);
-       if (user && strip_nt_domain) {
+       if (!strchr(buf, '\n')) {
+           /* too large message received.. skip and deny */
+           fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], buf);
+           while (fgets(buf, sizeof(buf), stdin)) {
+               fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], buf);
+               if (strchr(buf, '\n') != NULL)
+                   break;
+           }
+           goto error;
+       }
+       user = strtok(buf, " \n");
+       if (!user) {
+           fprintf(stderr, "%s: Invalid request\n", argv[0]);
+           goto error;
+       }
+       rfc1738_unescape(user);
+       if (strip_nt_domain) {
            char *u = strchr(user, '\\');
            if (!u)
                u = strchr(user, '/');
            if (u && u[1])
                user = u + 1;
        }
-       if (use_extension_dn)
-               extension_dn = strwordtok(NULL, &tptr);
+       if (use_extension_dn) {
+           extension_dn = strtok(NULL, " \n");
+           if (!extension_dn) {
+               fprintf(stderr, "%s: Invalid request\n", argv[0]);
+               goto error;
+           }
+           rfc1738_unescape(extension_dn);
+       }
 
-       while (!found && user && (group = strwordtok(NULL, &tptr)) != NULL) {
+       while (!found && user && (group = strtok(NULL, " \n")) != NULL) {
+           rfc1738_unescape(group);
 
          recover:
            if (ld == NULL) {
@@ -528,8 +507,10 @@ main(int argc, char **argv)
        }
        if (found)
            printf("OK\n");
-       else
+       else {
+error:
            printf("ERR\n");
+}
 
        if (ld != NULL) {
            if (!persistent || (squid_ldap_errno(ld) != LDAP_SUCCESS && squid_ldap_errno(ld) != LDAP_INVALID_CREDENTIALS)) {
@@ -539,6 +520,7 @@ main(int argc, char **argv)
                tryagain = 1;
            }
        }
+       err = 0;
     }
     if (ld)
        ldap_unbind(ld);
index b471458c4ac0c015ff83f3cb6d10d95318a3e814..51d0dcb8e985e9ae1b16e9d08352b1e299b6f16c 100644 (file)
@@ -1,12 +1,15 @@
 #
 #  Makefile for the Squid LDAP authentication helper
 #
-#  $Id: Makefile.am,v 1.3 2003/01/23 00:36:12 robertc Exp $
+#  $Id: Makefile.am,v 1.4 2004/08/14 22:54:53 hno Exp $
 #
 #  Uncomment and customize the following to suit your needs:
 #
 
-libexec_PROGRAMS       = squid_unix_group
-man_MANS               = squid_unix_group.8
-EXTRA_DIST             = squid_unix_group.8
+libexec_PROGRAMS               = squid_unix_group
+man_MANS                       = squid_unix_group.8
+EXTRA_DIST                     = squid_unix_group.8
 squid_unix_group_SOURCES       = check_group.c
+
+LDADD          = -L$(top_builddir)/lib -lmiscutil @XTRA_LIBS@
+INCLUDES       = -I. -I$(top_builddir)/include -I$(top_srcdir)/include
index 37539ea33bb15262aa90f32420d34fbeba21b8ba..5f6805d895354ade426a1d75c38606ef97a0205d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: check_group.c,v 1.3 2003/01/23 00:36:13 robertc Exp $
+ * $Id: check_group.c,v 1.4 2004/08/14 22:54:53 hno Exp $
  *
  * This is a helper for the external ACL interface for Squid Cache
  * Copyright (C) 2002 Rodrigo Albani de Campos (rodrigo@geekbunker.org)
@@ -29,6 +29,9 @@
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
  *
  * Change Log:
+ * Revision 1.7  2004/08/15 00:29:33  hno
+ * helper protocol changed to URL-escaped strings in Squid-3.0
+ *
  * Revision 1.6  2002/08/12 15:48:32  hno
  * imported strwordtok from Squid, added man page, some minor fixes
  *
 #include <pwd.h>
 #include <ctype.h>
 
+#include "util.h"
 
 #define BUFSIZE 8192           /* the stdin buffer size */
 #define MAX_GROUP 10           /* maximum number of groups specified 
                                 * on the command line */
 
-
-/*
- * Library function to split external_acl messages into tokens
- * Copied from the Squid sources
- */
-static char *
-strwordtok(char *buf, char **t)
-{
-    unsigned char *word = NULL;
-    unsigned char *p = (unsigned char *) buf;
-    unsigned char *d;
-    unsigned char ch;
-    int quoted = 0;
-    if (!p)
-       p = (unsigned char *) *t;
-    if (!p)
-       goto error;
-    while (*p && isspace(*p))
-       p++;
-    if (!*p)
-       goto error;
-    word = d = p;
-    while ((ch = *p)) {
-       switch (ch) {
-       case '\\':
-           p++;
-           *d++ = ch = *p;
-           if (ch)
-               p++;
-           break;
-       case '"':
-           quoted = !quoted;
-           p++;
-           break;
-       default:
-           if (!quoted && isspace(*p)) {
-               p++;
-               goto done;
-           }
-           *d++ = *p++;
-           break;
-       }
-    }
-  done:
-    *d++ = '\0';
-  error:
-    *t = (char *) p;
-    return (char *) word;
-}
-
-
 /* 
  * Verify if userĀ“s primary group matches groupname
  * Returns 0 if user is not on the group
@@ -181,7 +134,7 @@ usage(char *program)
 int
 main(int argc, char *argv[])
 {
-    char *user, *p, *t;
+    char *user, *p;
     char buf[BUFSIZE];
     char *grents[MAX_GROUP];
     int check_pw = 0, ch, i = 0, j = 0;
@@ -224,26 +177,27 @@ main(int argc, char *argv[])
        usage(argv[0]);
        exit(1);
     }
-    while (fgets(buf, BUFSIZE, stdin)) {
+    while (fgets(buf, sizeof(buf), stdin)) {
        j = 0;
-       if ((p = strchr(buf, '\n')) != NULL) {
-           *p = '\0';
-       } else {
+       if ((p = strchr(buf, '\n')) == NULL) {
            /* too large message received.. skip and deny */
            fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], buf);
-           while (fgets(buf, BUFSIZE, stdin)) {
+           while (fgets(buf, sizeof(buf), stdin)) {
                fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], buf);
                if (strchr(buf, '\n') != NULL)
                    break;
            }
            goto error;
        }
-       if ((p = strwordtok(buf, &t)) == NULL) {
+       *p = '\0';
+       if ((p = strtok(buf, " ")) == NULL) {
            goto error;
        } else {
            user = p;
+           rfc1738_unescape(user);
            /* check groups supplied by Squid */
-           while ((p = strwordtok(NULL, &t)) != NULL) {
+           while ((p = strtok(NULL, " ")) != NULL) {
+               rfc1738_unescape(p);
                if (check_pw == 1)
                    j += validate_user_pw(user, p);
 
index 5089433216fa5dcb7ed512b2625ec30b2be40cef..d03a3335718f0037ff3ab791dd59c8ca9f70d76d 100644 (file)
 #   Jerry Murdock <jmurdock@itraktech.com>
 #
 # Version history:
+#   2004-08-15 Henrik Nordstrom <hno@squid-cache.org>
+#              Helper protocol changed to URL escaped in Squid-3.0
 #   2002-07-05 Jerry Murdock <jmurdock@itraktech.com>
 #              Initial release
 #
 
-# external_acl uses shell style lines in it's protocol
-require 'shellwords.pl';
-
 # Disable output buffering
 $|=1;           
 
@@ -47,7 +46,9 @@ sub check {
 while (<STDIN>) {
         chop;
        &debug ("Got $_ from squid");
-        ($user, $group) = &shellwords;
+        ($user, $group) = split(/\s+/);
+       $user =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("c",hex($1))/eg;
+       $group =~ s/%([0-9a-fA-F][0-9a-fA-F])/pack("c",hex($1))/eg;
        $ans = &check($user, $group);
        &debug ("Sending $ans to squid");
        print "$ans\n";
index 46766b4e1e865697074c98ccb71a1ca566413173..b03ee1261146d36466fa5b8bbf330c3104ecfd4d 100755 (executable)
@@ -1,12 +1,12 @@
 #
 #  Makefile for the wb_group external_acl helper
 #
-#  $Id: Makefile.am,v 1.6 2003/05/16 14:36:19 hno Exp $
+#  $Id: Makefile.am,v 1.7 2004/08/14 22:54:53 hno Exp $
 #
 
 libexec_PROGRAMS = wb_group
 wb_group_SOURCES = wb_check_group.c wb_common.c wbntlm.h wb_common.h
 EXTRA_DIST = readme.txt
-INCLUDES = -I. -I$(top_builddir)/include -I$(top_srcdir)/include \
-    -I$(top_srcdir)/src -I@SAMBASOURCES@
-LDADD = -L$(top_builddir)/lib $(XTRA_LIBS)
+
+LDADD          = -L$(top_builddir)/lib -lmiscutil @XTRA_LIBS@
+INCLUDES       = -I. -I$(top_builddir)/include -I$(top_srcdir)/include -I@SAMBASOURCES@
index 3ff1ca51b0bc89ec48ea43bfb5390a2e304f0918..e7ffe704d369e9d5237885c59623a09ba33c4aa3 100755 (executable)
@@ -31,6 +31,9 @@
  *
  * History:
  *
+ * Version 1.21
+ * 15-08-2004 Henrik Nordstrom
+ *             Helper protocol changed to use URL escaped strings in Squid-3.0
  * Version 1.20
  * 10-05-2003 Roberto Moreda
  *              Added support for domain-qualified group Microsoft notation
@@ -79,52 +82,6 @@ const char *myname;
 pid_t mypid;
 static int use_case_insensitive_compare=0;
 
-static char *
-strwordtok(char *buf, char **t)
-{
-    unsigned char *word = NULL;
-    unsigned char *p = (unsigned char *) buf;
-    unsigned char *d;
-    unsigned char ch;
-    int quoted = 0;
-    if (!p)
-       p = (unsigned char *) *t;
-    if (!p)
-       goto error;
-    while (*p && isspace(*p))
-       p++;
-    if (!*p)
-       goto error;
-    word = d = p;
-    while ((ch = *p)) {
-       switch (ch) {
-       case '\\':
-           p++;
-           *d++ = ch = *p;
-           if (ch)
-               p++;
-           break;
-       case '"':
-           quoted = !quoted;
-           p++;
-           break;
-       default:
-           if (!quoted && isspace(*p)) {
-               p++;
-               goto done;
-           }
-           *d++ = *p++;
-           break;
-       }
-    }
-  done:
-    *d++ = '\0';
-  error:
-    *t = (char *) p;
-    return (char *) word;
-}
-
-
 static int strCaseCmp (const char *s1, const char *s2)
 {
     while (*s1 && toupper (*s1) == toupper (*s2)) s1++, s2++;
@@ -317,11 +274,10 @@ check_winbindd()
 int
 main (int argc, char *argv[])
 {
-    char *p, *t;
+    char *p;
     char buf[BUFSIZE];
     char *username;
     char *group;
-    int err = 0;
     const char *groups[512];
     int n;
 
@@ -348,14 +304,16 @@ main (int argc, char *argv[])
     check_winbindd();
 
     /* Main Loop */
-    while (fgets (buf, BUFSIZE, stdin))
+    while (fgets (buf, sizeof(buf), stdin))
     {
        if (NULL == strchr(buf, '\n')) {
-           err = 1;
-           continue;
-       }
-       if (err) {
-           warn("Oversized message\n");
+           /* too large message received.. skip and deny */
+           fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], buf);
+           while (fgets(buf, sizeof(buf), stdin)) {
+               fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], buf);
+               if (strchr(buf, '\n') != NULL)
+                   break;
+           }
            goto error;
        }
        
@@ -371,15 +329,18 @@ main (int argc, char *argv[])
            goto error;
        }
 
-       username = strwordtok(buf, &t);
-       for (n = 0; (group = strwordtok(NULL, &t)) != NULL; n++)
+       username = strtok(buf, " ");
+       for (n = 0; (group = strtok(NULL, " ")) != NULL; n++) {
+           rfc1738_unescape(group);
            groups[n] = group;
+       }
        groups[n] = NULL;
 
         if (NULL == username) {
             warn("Invalid Request\n");
             goto error;
         }
+       rfc1738_unescape(username);
 
        if (Valid_Groups(username, groups)) {
            printf ("OK\n");
@@ -387,7 +348,6 @@ main (int argc, char *argv[])
 error:
            printf ("ERR\n");
        }
-       err = 0;
     }
     return 0;
 }