]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - helpers/external_acl/LDAP_group/ext_ldap_group_acl.cc
SourceFormat Enforcement
[thirdparty/squid.git] / helpers / external_acl / LDAP_group / ext_ldap_group_acl.cc
index 2a1a778ff0b032ea688dbf2787686971d5ebe10a..78cce967d15289e660e450d0b4dc3bec59949406 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 /*
  * ext_ldap_group_acl: lookup group membership in LDAP
  *
  *
  * If you want to make a TLS enabled connection you will also need the
  * OpenSSL libraries linked into openldap. See http://www.openssl.org/
- *
- * License: squid_ldap_group is free software; you can redistribute it
- * and/or modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2,
- * or (at your option) any later version.
  */
 #include "squid.h"
 #include "helpers/defines.h"
 
 #define LDAP_DEPRECATED 1
 
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-#if HAVE_STRING_H
-#include <string.h>
-#endif
-#if HAVE_CTYPE_H
-#include <ctype.h>
-#endif
+#include <cctype>
+#include <cstring>
 
-#if _SQUID_MSWIN_              /* Native Windows port and MinGW */
+#if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
 
 #define snprintf _snprintf
 #include <windows.h>
@@ -89,12 +85,8 @@ PFldap_start_tls_s Win32_ldap_start_tls_s;
 
 #endif
 
-#if defined(LDAP_OPT_NETWORK_TIMEOUT)
-#include <sys/time.h>
-#endif
-
 #define PROGRAM_NAME "ext_ldap_group_acl"
-#define PROGRAM_VERSION "2.17"
+#define PROGRAM_VERSION "2.18"
 
 /* Globals */
 
@@ -251,21 +243,21 @@ main(int argc, char **argv)
                 value = argv[1] + 2;
             } else if (argc > 2) {
                 value = argv[2];
-                argv++;
-                argc--;
+                ++argv;
+                --argc;
             } else
                 value = "";
             break;
         }
-        argv++;
-        argc--;
+        ++argv;
+        --argc;
         switch (option) {
         case 'H':
 #if !HAS_URI_SUPPORT
             fprintf(stderr, "FATAL: Your LDAP library does not have URI support\n");
             exit(1);
 #endif
-            /* Fall thru to -h */
+        /* Fall thru to -h */
         case 'h':
             if (ldapServer) {
                 int len = strlen(ldapServer) + 1 + strlen(value) + 1;
@@ -405,8 +397,8 @@ main(int argc, char **argv)
         } else {
             ldapServer = xstrdup(value);
         }
-        argc--;
-        argv++;
+        --argc;
+        ++argv;
     }
 
     if (!ldapServer)
@@ -451,7 +443,7 @@ main(int argc, char **argv)
     /* On Windows ldap_start_tls_s is available starting from Windows XP,
      * so we need to bind at run-time with the function entry point
      */
-#if _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
     if (use_tls) {
 
         HMODULE WLDAP32Handle;
@@ -528,7 +520,7 @@ recover:
                             fprintf(stderr, "FATAL: Unable to initialise SSL with cert path %s\n", sslpath);
                             exit(1);
                         } else {
-                            sslinit++;
+                            ++sslinit;
                         }
                         if ((ld = ldapssl_init(ldapServer, port, 1)) == NULL) {
                             fprintf(stderr, "FATAL: Unable to connect to SSL LDAP server: %s port:%d\n",
@@ -631,15 +623,19 @@ ldap_escape_value(char *escaped, int size, const char *src)
             n += 3;
             size -= 3;
             if (size > 0) {
-                *escaped++ = '\\';
-                snprintf(escaped, 3, "%02x", (unsigned char) *src++);
+                *escaped = '\\';
+                ++escaped;
+                snprintf(escaped, 3, "%02x", (unsigned char) *src);
+                ++src;
                 escaped += 2;
             }
             break;
         default:
-            *escaped++ = *src++;
-            n++;
-            size--;
+            *escaped = *src;
+            ++escaped;
+            ++src;
+            ++n;
+            --size;
         }
     }
     *escaped = '\0';
@@ -653,18 +649,18 @@ build_filter(char *filter, int size, const char *templ, const char *user, const
     while (*templ && size > 0) {
         switch (*templ) {
         case '%':
-            templ++;
+            ++templ;
             switch (*templ) {
             case 'u':
             case 'v':
-                templ++;
+                ++templ;
                 n = ldap_escape_value(filter, size, user);
                 size -= n;
                 filter += n;
                 break;
             case 'g':
             case 'a':
-                templ++;
+                ++templ;
                 n = ldap_escape_value(filter, size, group);
                 size -= n;
                 filter += n;
@@ -676,15 +672,19 @@ build_filter(char *filter, int size, const char *templ, const char *user, const
             }
             break;
         case '\\':
-            templ++;
+            ++templ;
             if (*templ) {
-                *filter++ = *templ++;
-                size--;
+                *filter = *templ;
+                ++filter;
+                ++templ;
+                --size;
             }
             break;
         default:
-            *filter++ = *templ++;
-            size--;
+            *filter = *templ;
+            ++filter;
+            ++templ;
+            --size;
             break;
         }
     }
@@ -805,7 +805,6 @@ searchLDAP(LDAP * ld, char *group, char *login, char *extension_dn)
     }
 }
 
-
 int
 readSecret(const char *filename)
 {
@@ -836,3 +835,4 @@ readSecret(const char *filename)
 
     return 0;
 }
+