]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
ntlm_sspi_auth: convert to new base64 API
authorAmos Jeffries <squid3@treenet.co.nz>
Wed, 31 Dec 2014 05:20:28 +0000 (21:20 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 31 Dec 2014 05:20:28 +0000 (21:20 -0800)
helpers/ntlm_auth/SSPI/Makefile.am
helpers/ntlm_auth/SSPI/ntlm_sspi_auth.cc

index c76576bbed5ee617cb5c35c24a64662cf8963743..3a6f743bf858e619a6d699fd7da1aa9171507fea 100644 (file)
@@ -15,7 +15,7 @@ ntlm_sspi_auth_SOURCES = ntlm_sspi_auth.cc
 
 LDADD = \
        $(top_builddir)/lib/ntlmauth/libntlmauth.la \
-       -L$(top_builddir)/lib -lsspwin32 \
+       $(top_builddir)/lib/libsspwin32.la \
        $(top_builddir)/lib/libmiscencoding.la \
        $(COMPAT_LIB) \
        -lnetapi32 \
index fc17f25345af9282102cec331eecb86cb7f70e34..9c7fee834cb2778e190f258703ce2d8b42354f17 100644 (file)
@@ -413,13 +413,27 @@ process_options(int argc, char *argv[])
         exit(1);
 }
 
+static bool
+token_decode(size_t *decodedLen, uint8_t decoded[], const char *buf)
+{
+    struct base64_decode_ctx ctx;
+    base64_decode_init(&ctx);
+    if (!base64_decode_update(&ctx, decodedLen, decoded, strlen(buf), reinterpret_cast<const uint8_t*>(buf)) ||
+            !base64_decode_final(&ctx)) {
+        SEND_BH("message=\"base64 decode failed\"");
+        fprintf(stderr, "ERROR: base64 decoding failed for: '%s'\n", buf);
+        return false;
+    }
+    return true;
+}
+
 int
 manage_request()
 {
     ntlmhdr *fast_header;
     char buf[HELPER_INPUT_BUFFER];
-    char decoded[HELPER_INPUT_BUFFER];
-    int decodedLen;
+    uint8_t decoded[HELPER_INPUT_BUFFER];
+    size_t decodedLen = 0;
     char helper_command[3];
     int oversized = 0;
     char * ErrorMessage;
@@ -459,7 +473,8 @@ manage_request()
     } while (false);
 
     if ((strlen(buf) > 3) && NTLM_packet_debug_enabled) {
-        decodedLen = base64_decode(decoded, sizeof(decoded), buf+3);
+        if (!token_decode(&decodedLen, decoded, buf+3))
+            return 1;
         strncpy(helper_command, buf, 2);
         debug("Got '%s' from Squid with data:\n", helper_command);
         hex_dump(reinterpret_cast<unsigned char*>(decoded), decodedLen);
@@ -467,15 +482,16 @@ manage_request()
         debug("Got '%s' from Squid\n", buf);
     if (memcmp(buf, "YR", 2) == 0) {    /* refresh-request */
         /* figure out what we got */
-        if (strlen(buf) > 3)
-            decodedLen = base64_decode(decoded, sizeof(decoded), buf+3);
-        else {
+        if (strlen(buf) > 3) {
+            if (!decodedLen /* already decoded*/ && !token_decode(&decodedLen, decoded, buf+3))
+                return 1;
+        } else {
             debug("Negotiate packet not supplied - self generated\n");
             memcpy(decoded, &local_nego, sizeof(local_nego));
             decodedLen = sizeof(local_nego);
         }
         if ((size_t)decodedLen < sizeof(ntlmhdr)) {     /* decoding failure, return error */
-            SEND_ERR("message=\"Packet format error, couldn't base64-decode\"");
+            SEND_ERR("message=\"Packet format error\"");
             return 1;
         }
         /* fast-track-decode request type. */
@@ -494,7 +510,8 @@ manage_request()
             if (c) {
                 SEND_TT(c);
                 if (NTLM_packet_debug_enabled) {
-                    decodedLen = base64_decode(decoded, sizeof(decoded), c);
+                    if (!token_decode(&decodedLen, decoded, c))
+                        return 1;
                     debug("send 'TT' to squid with data:\n");
                     hex_dump(reinterpret_cast<unsigned char*>(decoded), decodedLen);
                     if (NTLM_LocalCall) {
@@ -528,10 +545,11 @@ manage_request()
             return 1;
         }
         /* figure out what we got */
-        decodedLen = base64_decode(decoded, sizeof(decoded), buf+3);
+        if (!decodedLen /* already decoded*/ && !token_decode(&decodedLen, decoded, buf+3))
+            return 1;
 
         if ((size_t)decodedLen < sizeof(ntlmhdr)) {     /* decoding failure, return error */
-            SEND_ERR("message=\"Packet format error, couldn't base64-decode\"");
+            SEND_ERR("message=\"Packet format error\"");
             return 1;
         }
         /* fast-track-decode request type. */