From b8b1bc0eb4b567f4a35366e198fda13717ed6a24 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Wed, 21 Mar 2007 04:48:09 +0000 Subject: [PATCH] When using the Vista SDK version of NTSecAPI.h it is necessary to ensure the _WIN32_WINNT have a value of 0x0501 or greater. Otherwise, required LSA type declarations are undeclared. Provide a registry value that can be set to turn on Application Event log messages for debugging. HKLM\System\CurrentControlSet\Services\MIT Kerberos\Network Provider DWORD "Debug" Ensure that KFW_obtain_user_temp_directory() returns a value on error. Correct the declaration of KFW_copy_cache_to_system_file() to match the prototype. ticket: 5469 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@19240 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/kfwlogon/kfwcommon.c | 58 +++++++++++++++++++++----------- src/windows/kfwlogon/kfwlogon.h | 10 +++++- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/windows/kfwlogon/kfwcommon.c b/src/windows/kfwlogon/kfwcommon.c index a3b02eeab..b578d943b 100644 --- a/src/windows/kfwlogon/kfwcommon.c +++ b/src/windows/kfwlogon/kfwcommon.c @@ -24,7 +24,7 @@ SOFTWARE. */ #include "kfwlogon.h" -#include +#include #include #include #include @@ -291,34 +291,54 @@ static HINSTANCE hCCAPI = 0; static DWORD TraceOption = 0; static HANDLE hDLL; +BOOL IsDebugLogging(void) +{ + DWORD LSPtype, LSPsize; + HKEY NPKey; + DWORD dwDebug = FALSE; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, + "System\\CurrentControlSet\\Services\\MIT Kerberos\\Network Provider", + 0, KEY_QUERY_VALUE, &NPKey) == ERROR_SUCCESS) { + LSPsize=sizeof(dwDebug); + if (RegQueryValueEx(NPKey, "Debug", NULL, &LSPtype, (LPBYTE)&dwDebug, &LSPsize) != ERROR_SUCCESS + || LSPtype != REG_DWORD) + dwDebug = FALSE; + + RegCloseKey (NPKey); + } + + return(dwDebug ? TRUE : FALSE); +} + void DebugEvent0(char *a) { -#ifdef DEBUG HANDLE h; char *ptbuf[1]; - h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME); - ptbuf[0] = a; - ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); - DeregisterEventSource(h); -#endif + if (IsDebugLogging()) { + h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME); + ptbuf[0] = a; + ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); + DeregisterEventSource(h); + } } #define MAXBUF_ 512 void DebugEvent(char *b,...) { -#ifdef DEBUG HANDLE h; char *ptbuf[1],buf[MAXBUF_+1]; va_list marker; - h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME); - va_start(marker,b); - StringCbVPrintf(buf, MAXBUF_+1,b,marker); - buf[MAXBUF_] = '\0'; - ptbuf[0] = buf; - ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); - DeregisterEventSource(h); - va_end(marker); -#endif + if (IsDebugLogging()) { + h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME); + va_start(marker,b); + StringCbVPrintf(buf, MAXBUF_+1,b,marker); + buf[MAXBUF_] = '\0'; + ptbuf[0] = buf; + ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL); + DeregisterEventSource(h); + va_end(marker); + } } void @@ -978,7 +998,7 @@ int KFW_obtain_user_temp_directory(HANDLE hUserToken, char *newfilename, int siz DWORD dwLen = 0; if (!hUserToken || !newfilename || size <= 0) - return; + return 1; *newfilename = '\0'; @@ -993,7 +1013,7 @@ int KFW_obtain_user_temp_directory(HANDLE hUserToken, char *newfilename, int siz } void -KFW_copy_cache_to_system_file(char * user, char * filename) +KFW_copy_cache_to_system_file(const char * user, const char * filename) { DWORD count; char cachename[MAX_PATH + 8] = "FILE:"; diff --git a/src/windows/kfwlogon/kfwlogon.h b/src/windows/kfwlogon/kfwlogon.h index a542b81c3..d9bf13d06 100644 --- a/src/windows/kfwlogon/kfwlogon.h +++ b/src/windows/kfwlogon/kfwlogon.h @@ -27,8 +27,16 @@ SOFTWARE. /* We only support VC 1200 and above anyway */ #pragma once +/* _WIN32_WINNT must be 0x0501 or greater to pull in definition of + * all required LSA data types when the Vista SDK NtSecAPI.h is used. + */ #ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0500 +#define _WIN32_WINNT 0x0501 +#else +#if _WIN32_WINNT < 0x0501 +#undef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif #endif #include -- 2.26.2