+/*
+ * 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.
+ */
+
/*
* -----------------------------------------------------------------------------
*
*
* -----------------------------------------------------------------------------
*/
-/*
- * Hosted at http://sourceforge.net/projects/squidkerbauth
- */
#include "squid.h"
#include "base64.h"
-#if HAVE_STRING_H
-#include <string.h>
-#endif
-#if HAVE_STDIO_H
-#include <stdio.h>
-#endif
-#if HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
+#include <cerrno>
+#include <cstring>
+#include <cstdlib>
+#include <ctime>
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
-#if HAVE_TIME_H
-#include <time.h>
-#endif
-#if HAVE_ERRNO_H
-#include <errno.h>
-#endif
#if !defined(HAVE_DECL_XMALLOC) || !HAVE_DECL_XMALLOC
#define xmalloc malloc
int length;
int nstart = 0, kstart = 0;
int nend = 0, kend = 0;
- char *token;
+ uint8_t *token;
char **nargs, **kargs;
int fpid;
FILE *FDKIN,*FDKOUT;
fprintf(stdout, "BH Invalid negotiate request\n");
continue;
}
- length = base64_decode_len(buf+3);
+ length = BASE64_DECODE_LENGTH(strlen(buf+3));
if (debug)
fprintf(stderr, "%s| %s: Decode '%s' (decoded length: %d).\n",
LogTime(), PROGRAM, buf + 3, (int) length);
- if ((token = (char *)xmalloc(length)) == NULL) {
+ if ((token = static_cast<uint8_t *>(xmalloc(length))) == NULL) {
fprintf(stderr, "%s| %s: Error allocating memory for token\n", LogTime(), PROGRAM);
return 1;
}
- length = base64_decode(token, length, buf+3);
+ struct base64_decode_ctx ctx;
+ base64_decode_init(&ctx);
+ size_t dstLen = 0;
+ if (!base64_decode_update(&ctx, &dstLen, token, strlen(buf+3), reinterpret_cast<const uint8_t*>(buf+3)) ||
+ !base64_decode_final(&ctx)) {
+ if (debug)
+ fprintf(stderr, "%s| %s: Invalid base64 token [%s]\n", LogTime(), PROGRAM, buf+3);
+ fprintf(stdout, "BH Invalid negotiate request token\n");
+ continue;
+ }
+ length = dstLen;
+ token[dstLen] = '\0';
if ((static_cast<size_t>(length) >= sizeof(ntlmProtocol) + 1) &&
(!memcmp(token, ntlmProtocol, sizeof ntlmProtocol))) {
strcpy(buff,tbuff);
}
} else {
- free(token);
+ xfree(token);
if (debug)
fprintf(stderr, "%s| %s: received Kerberos token\n",
LogTime(), PROGRAM);
return 1;
}
+