\r
void DebugEvent0(char *a) \r
{\r
+#ifdef DEBUG\r
HANDLE h; char *ptbuf[1];\r
\r
h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME);\r
ptbuf[0] = a;\r
ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\r
DeregisterEventSource(h);\r
+#endif\r
}\r
\r
#define MAXBUF_ 512\r
void DebugEvent(char *b,...) \r
{\r
+#ifdef DEBUG\r
HANDLE h; char *ptbuf[1],buf[MAXBUF_+1];\r
va_list marker;\r
\r
ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\r
DeregisterEventSource(h);\r
va_end(marker);\r
+#endif\r
}\r
\r
void\r
\r
ccname = (char *)malloc(strlen(pname) + 5);\r
sprintf(ccname,"API:%s",pname);\r
- \r
+\r
+ DebugEvent0(ccname);\r
code = pkrb5_cc_resolve(ctx, ccname, cc);\r
} else {\r
code = pkrb5_cc_default(ctx, cc);\r
{\r
krb5_context ctx = 0;\r
krb5_ccache cc = 0;\r
- char * realm = 0, * userrealm = 0;\r
- int free_realm = 0;\r
+ char * realm = 0;\r
krb5_principal principal = 0;\r
char * pname = 0;\r
krb5_error_code code;\r
\r
- if (!pkrb5_init_context)\r
+ if (!pkrb5_init_context || !username || !password)\r
return 0;\r
\r
- if ( IsDebuggerPresent() ) {\r
- OutputDebugString("KFW_get_cred for token ");\r
- OutputDebugString(username);\r
- OutputDebugString("\n");\r
- }\r
+ DebugEvent0(username);\r
\r
code = pkrb5_init_context(&ctx);\r
if ( code ) goto cleanup;\r
\r
code = pkrb5_get_default_realm(ctx, &realm);\r
\r
- userrealm = strchr(username,'@');\r
if (realm) {\r
- free_realm = 1;\r
pname = malloc(strlen(username) + strlen(realm) + 2);\r
- userrealm = strchr(pname, '@');\r
- userrealm++;\r
- strcat(userrealm, realm);\r
+ if (!pname)\r
+ goto cleanup;\r
+ strcpy(pname, username);\r
+ strcat(pname, "@");\r
+ strcat(pname, realm);\r
} else {\r
- pname = strdup(username);\r
- userrealm = strchr(pname, '@');\r
- userrealm++;\r
- realm = userrealm;\r
+ goto cleanup;\r
}\r
\r
- if ( IsDebuggerPresent() ) {\r
- OutputDebugString("Realm: ");\r
- OutputDebugString(realm);\r
- OutputDebugString("\n");\r
- }\r
+ DebugEvent0(realm);\r
+ DebugEvent0(pname);\r
\r
code = pkrb5_parse_name(ctx, pname, &principal);\r
if ( code ) goto cleanup;\r
\r
+ DebugEvent0("parsed name");\r
code = KFW_get_ccache(ctx, principal, &cc);\r
if ( code ) goto cleanup;\r
\r
+ DebugEvent0("got ccache");\r
if ( lifetime == 0 )\r
lifetime = pLeash_get_default_lifetime();\r
\r
- if ( password && password[0] ) {\r
+ if ( password[0] ) {\r
code = KFW_kinit( ctx, cc, HWND_DESKTOP, \r
pname, \r
password,\r
pLeash_get_default_renewable() ? pLeash_get_default_renew_till() : 0,\r
pLeash_get_default_noaddresses(),\r
pLeash_get_default_publicip());\r
- if ( IsDebuggerPresent() ) {\r
- char message[256];\r
- sprintf(message,"KFW_kinit() returns: %d\n",code);\r
- OutputDebugString(message);\r
- }\r
+ DebugEvent0("kinit returned");\r
if ( code ) goto cleanup;\r
}\r
\r
cleanup:\r
if ( pname )\r
free(pname);\r
+ if ( realm )\r
+ pkrb5_free_default_realm(ctx, realm);\r
if ( cc )\r
pkrb5_cc_close(ctx, cc);\r
\r
GetWindowsDirectory(filename, sizeof(filename));\r
}\r
\r
- if ( strlen(filename) + strlen(szLogonId) + 2 > sizeof(filename) )\r
+ DebugEvent0(filename);\r
+ if ( strlen(filename) + strlen(szLogonId) + 2 > sizeof(filename) ) {\r
+ DebugEvent0("filename buffer too small");\r
return;\r
+ }\r
\r
strcat(filename, "\\");\r
strcat(filename, szLogonId); \r
DeleteFile(filename);\r
\r
code = pkrb5_init_context(&ctx);\r
- if (code) ctx = 0;\r
+ if (code) goto cleanup;\r
\r
code = pkrb5_parse_name(ctx, user, &princ);\r
if (code) goto cleanup;\r
if (!pkrb5_init_context)\r
return 0;\r
\r
- if ( IsDebuggerPresent() ) {\r
- OutputDebugString("KFW_destroy_tickets_for_user: ");\r
- OutputDebugString(user);\r
- OutputDebugString("\n");\r
- }\r
-\r
code = pkrb5_init_context(&ctx);\r
if (code) ctx = 0;\r
\r
if ( wcscmp(lpAuthentInfoType,L"MSV1_0:Interactive") && \r
wcscmp(lpAuthentInfoType,L"Kerberos:Interactive") )\r
{\r
- DebugEvent("Unsupported Authentication Info Type: %S",\r
- lpAuthentInfoType);\r
+ char msg[64];\r
+ WideCharToMultiByte(CP_ACP, 0, lpAuthentInfoType, 0, \r
+ msg, sizeof(msg), NULL, NULL);\r
+ msg[sizeof(msg)-1]='\0';\r
+ DebugEvent("NPLogonNotify - Unsupported Authentication Info Type: %s", msg);\r
return 0;\r
}\r
\r
UnicodeStringToANSI(IL->Password, password, MAX_PASSWORD_LENGTH);\r
UnicodeStringToANSI(IL->LogonDomainName, logonDomain, MAX_DOMAIN_LENGTH);\r
\r
- /* Make sure AD-DOMANS sent from login that is sent to us is stripped */\r
+ /* Make sure AD-DOMAINS sent from login that is sent to us is stripped */\r
ctemp = strchr(uname, '@');\r
if (ctemp) *ctemp = 0;\r
\r
}\r
\r
code = KFW_get_cred(uname, password, 0, &reason);\r
- DebugEvent("KFW_get_cred uname=[%s] code=[%d]",uname, code);\r
+ DebugEvent("NPLogonNotify - KFW_get_cred uname=[%s] code=[%d]",uname, code);\r
\r
/* remove any kerberos 5 tickets currently held by the SYSTEM account\r
* for this user \r
*/\r
- sprintf(szLogonId,"kfwlogon-%d.%d",lpLogonId->HighPart, lpLogonId->LowPart);\r
- KFW_copy_cache_to_system_file(uname, szLogonId);\r
+ if (!code) {\r
+ sprintf(szLogonId,"kfwlogon-%d.%d",lpLogonId->HighPart, lpLogonId->LowPart);\r
+ KFW_copy_cache_to_system_file(uname, szLogonId);\r
+ }\r
\r
KFW_destroy_tickets_for_principal(uname);\r
\r
SetLastError(code);\r
}\r
\r
+ if (code)\r
+ DebugEvent0("NPLogonNotify failure");\r
+ else\r
+ DebugEvent0("NPLogonNotify success");\r
+\r
return code;\r
} \r
\r