From a43c8c5c292bc6346633a8c0ba739c9c7f70db75 Mon Sep 17 00:00:00 2001 From: "cbiesinger%web.de" Date: Sat, 8 May 2004 15:05:56 +0000 Subject: [PATCH] Bug 242457 make NTLM Auth Module use nspr logging, instead of #ifdef+printf r+sr=darin --- security/manager/ssl/src/nsNTLMAuthModule.cpp | 96 +++++++++++++------ 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/security/manager/ssl/src/nsNTLMAuthModule.cpp b/security/manager/ssl/src/nsNTLMAuthModule.cpp index 159f2dac549c..4ce206a8d0f7 100644 --- a/security/manager/ssl/src/nsNTLMAuthModule.cpp +++ b/security/manager/ssl/src/nsNTLMAuthModule.cpp @@ -35,6 +35,8 @@ * * ***** END LICENSE BLOCK ***** */ +#include "prlog.h" + #include #include "nsNSSShutDown.h" #include "nsNTLMAuthModule.h" @@ -46,9 +48,13 @@ #include "pk11func.h" #include "md4.h" -#ifdef DEBUG -// enable this directive to turn on extra debug output -#define NTLM_DEBUG +#ifdef PR_LOGGING +PRLogModuleInfo *gNTLMLog = PR_NewLogModule("NTLM"); + +#define LOG(x) PR_LOG(gNTLMLog, PR_LOG_DEBUG, x) +#define LOG_ENABLED() PR_LOG_TEST(gNTLMLog, PR_LOG_DEBUG) +#else +#define LOG(x) #endif static void des_makekey(const PRUint8 *raw, PRUint8 *key); @@ -119,13 +125,18 @@ static const char NTLM_TYPE3_MARKER[] = { 0x03, 0x00, 0x00, 0x00 }; //----------------------------------------------------------------------------- -#ifdef NTLM_DEBUG +#ifdef PR_LOGGING -static void PrintFlags(PRUint32 flags) +/** + * Prints a description of flags to the NSPR Log, if enabled. + */ +static void LogFlags(PRUint32 flags) { + if (!LOG_ENABLED()) + return; #define TEST(_flag) \ if (flags & NTLM_ ## _flag) \ - printf(" 0x%08x (" # _flag ")\n", NTLM_ ## _flag) + PR_LogPrint(" 0x%08x (" # _flag ")\n", NTLM_ ## _flag) TEST(NegotiateUnicode); TEST(NegotiateOEM); @@ -163,37 +174,51 @@ static void PrintFlags(PRUint32 flags) #undef TEST } +/** + * Prints a hexdump of buf to the NSPR Log, if enabled. + * @param tag Description of the data, will be printed in front of the data + * @param buf the data to print + * @param bufLen length of the data + */ static void -PrintBuf(const char *tag, const PRUint8 *buf, PRUint32 bufLen) +LogBuf(const char *tag, const PRUint8 *buf, PRUint32 bufLen) { int i; - printf("%s =\n", tag); + if (!LOG_ENABLED()) + return; + + PR_LogPrint("%s =\n", tag); + char line[80]; while (bufLen > 0) { int count = bufLen; if (count > 8) count = 8; - printf(" "); + strcpy(line, " "); for (i=0; ichallenge, cursor, sizeof(msg->challenge)); cursor += sizeof(msg->challenge); -#ifdef NTLM_DEBUG - printf("NTLM type 2 message:\n"); - PrintBuf("target", (const PRUint8 *) msg->target, msg->targetLen); - PrintBuf("flags", (const PRUint8 *) &msg->flags, 4); - PrintFlags(msg->flags); - PrintBuf("challenge", msg->challenge, sizeof(msg->challenge)); -#endif + + LOG(("NTLM type 2 message:\n")); + LogBuf("target", (const PRUint8 *) msg->target, msg->targetLen); + LogBuf("flags", (const PRUint8 *) &msg->flags, 4); + LogFlags(msg->flags); + LogBuf("challenge", msg->challenge, sizeof(msg->challenge)); // we currently do not implement LMv2/NTLMv2 or NTLM2 responses, // so we can ignore target information. we may want to enable @@ -745,9 +783,7 @@ nsNTLMAuthModule::GetNextToken(const void *inToken, // if inToken is non-null, then assume it contains a type 2 message... if (inToken) { -#ifdef NTLM_DEBUG - PrintToken("in-token", inToken, inTokenLen); -#endif + LogToken("in-token", inToken, inTokenLen); rv = GenerateType3Msg(mDomain, mUsername, mPassword, inToken, inTokenLen, outToken, outTokenLen); } @@ -756,10 +792,8 @@ nsNTLMAuthModule::GetNextToken(const void *inToken, rv = GenerateType1Msg(outToken, outTokenLen); } -#ifdef NTLM_DEBUG if (NS_SUCCEEDED(rv)) - PrintToken("out-token", *outToken, *outTokenLen); -#endif + LogToken("out-token", *outToken, *outTokenLen); return rv; }