]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - helpers/digest_auth/eDirectory/ldap_backend.cc
Boilerplate: update copyright blurbs on Squid helpers
[thirdparty/squid.git] / helpers / digest_auth / eDirectory / ldap_backend.cc
index 6d69aa9af03a463c25439690f43eaa8353bdeafc..ec6b6baa035b24d6dcfe3b26c45ab8d73aa2e0d1 100644 (file)
@@ -1,18 +1,21 @@
 /*
+ * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
  *
- *
- *
- * ldap_backend.c
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+/*
  * AUTHOR: Flavio Pescuma, MARA Systems AB <flavio@marasystems.com>
  */
-#define SQUID_NO_ALLOC_PROTECT 1
-#include "config.h"
+#include "squid.h"
 
 #define LDAP_DEPRECATED 1
 
 #include "ldap_backend.h"
 
-#ifdef _SQUID_MSWIN_           /* Native Windows port and MinGW */
+#if _SQUID_WINDOWS_ && !_SQUID_CYGWIN_
 
 #define snprintf _snprintf
 #include <windows.h>
@@ -172,15 +175,19 @@ ldap_escape_value(char *escaped, int size, const char *src)
             n += 3;
             size -= 3;
             if (size > 0) {
-                *escaped++ = '\\';
-                snprintf(escaped, 3, "%02x", (int) *src++);
+                *escaped = '\\';
+                ++escaped;
+                snprintf(escaped, 3, "%02x", (int) *src);
+                ++src;
                 escaped += 2;
             }
             break;
         default:
-            *escaped++ = *src++;
-            n++;
-            size--;
+            *escaped = *src;
+            ++escaped;
+            ++src;
+            ++n;
+            --size;
         }
     }
     *escaped = '\0';
@@ -231,7 +238,7 @@ retrysrch:
                     ldap_msgfree(res);
                     /* try to connect to the LDAP server agin, maybe my persisten conexion failed. */
                     if (!retry) {
-                        retry++;
+                        ++retry;
                         ldap_unbind(ld);
                         ld = NULL;
                         ldapconnect();
@@ -283,7 +290,8 @@ retrydnattr:
             value = values;
             while (*value) {
                 if (encrpass) {
-                    if (strcmp(strtok(*value, delimiter), realm) == 0) {
+                    const char *t = strtok(*value, delimiter);
+                    if (t && strcmp(t, realm) == 0) {
                         password = strtok(NULL, delimiter);
                         break;
                     }
@@ -291,7 +299,7 @@ retrydnattr:
                     password = *value;
                     break;
                 }
-                value++;
+                ++value;
             }
             debug("password: %s\n", password);
             if (password)
@@ -308,7 +316,7 @@ retrydnattr:
             fprintf(stderr, PROGRAM_NAME " WARNING, LDAP error '%s'\n", ldap_err2string(rc));
             /* try to connect to the LDAP server agin, maybe my persisten conexion failed. */
             if (!retry) {
-                retry++;
+                ++retry;
                 ldap_unbind(ld);
                 ld = NULL;
                 ldapconnect();
@@ -320,8 +328,6 @@ retrydnattr:
     return NULL;
 }
 
-
-
 static void
 ldapconnect(void)
 {
@@ -330,7 +336,7 @@ ldapconnect(void)
     /* 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
      */
-#ifdef _SQUID_MSWIN_
+#if _SQUID_WINDOWS_
     if (use_tls) {
 
         HMODULE WLDAP32Handle;
@@ -359,7 +365,7 @@ ldapconnect(void)
                             sslpath);
                     exit(1);
                 } else {
-                    sslinit++;
+                    ++sslinit;
                 }
                 if ((ld = ldapssl_init(ldapServer, port, 1)) == NULL) {
                     fprintf(stderr, "\nUnable to connect to SSL LDAP server: %s port:%d\n",
@@ -437,14 +443,14 @@ LDAPArguments(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
@@ -591,8 +597,8 @@ LDAPArguments(int argc, char **argv)
         } else {
             ldapServer = xstrdup(value);
         }
-        argc--;
-        argv++;
+        --argc;
+        ++argv;
     }
 
     if (!ldapServer)