pull up r19289 from trunk
authorTom Yu <tlyu@mit.edu>
Fri, 30 Mar 2007 03:09:02 +0000 (03:09 +0000)
committerTom Yu <tlyu@mit.edu>
Fri, 30 Mar 2007 03:09:02 +0000 (03:09 +0000)
 r19289@cathode-dark-space:  jaltman | 2007-03-27 09:37:30 -0400
 ticket: 5469

 This commit addresses several issues:

 (1) The registry key used for activating event reporting to
     the Windows application log was wrong.  It should be
     "NetworkProvider" not "Network Provider"

 (2) Event logging of the state of the "Debug" value has been
     added so that it is possible to debug the use of event
     reporting.

 (3) The code no longer performs the pre-kinit operations
     if a password was not provided.

 (4) A new function KFW_copy_file_cache_to_api_cache() has
     been added.  This is used instead of
     KFW_copy_file_cache_to_default_cache() permitting the
     default cache to be MSLSA, FILE, or anything else.
     The API cache name will be of the form API:principal
     just as is done by Network Identity Manager.

ticket: 5469
version_fixed: 1.6.1

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19336 dc483132-0cff-0310-8789-dd5450dbe970

src/windows/kfwlogon/kfwcommon.c
src/windows/kfwlogon/kfwcpcc.c

index b578d943b0ecabac442520454e236c6162ca8d93..1a2de0826ee16ee81dddc8e3c3803b6485ae7a3e 100644 (file)
@@ -293,19 +293,41 @@ static HANDLE hDLL;
 \r
 BOOL IsDebugLogging(void)\r
 {\r
-    DWORD LSPtype, LSPsize;\r
+    DWORD LSPsize;\r
     HKEY NPKey;\r
     DWORD dwDebug = FALSE;\r
 \r
     if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, \r
-                    "System\\CurrentControlSet\\Services\\MIT Kerberos\\Network Provider", \r
-                    0, KEY_QUERY_VALUE, &NPKey) == ERROR_SUCCESS) {\r
+                    "System\\CurrentControlSet\\Services\\MIT Kerberos\\NetworkProvider", \r
+                    0, KEY_QUERY_VALUE, &NPKey) == ERROR_SUCCESS) \r
+    {\r
        LSPsize=sizeof(dwDebug);\r
-       if (RegQueryValueEx(NPKey, "Debug", NULL, &LSPtype, (LPBYTE)&dwDebug, &LSPsize) != ERROR_SUCCESS \r
-           || LSPtype != REG_DWORD)\r
+       if (RegQueryValueEx(NPKey, "Debug", NULL, NULL, (LPBYTE)&dwDebug, &LSPsize) != ERROR_SUCCESS) \r
+       {\r
+           static int once = 0;\r
+\r
            dwDebug = FALSE;\r
 \r
+           if (!once) {\r
+               HANDLE h; char *ptbuf[1];\r
+               h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME);\r
+               ptbuf[0] = "Unable to read debug value";\r
+               ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\r
+               DeregisterEventSource(h);\r
+               once++;\r
+           }\r
+       }\r
        RegCloseKey (NPKey);\r
+    } else {\r
+       static int once = 0;\r
+       if (!once) {\r
+           HANDLE h; char *ptbuf[1];\r
+           h = RegisterEventSource(NULL, KFW_LOGON_EVENT_NAME);\r
+           ptbuf[0] = "Unable to open network provider key";\r
+           ReportEvent(h, EVENTLOG_INFORMATION_TYPE, 0, 0, NULL, 1, 0, (const char **)ptbuf, NULL);\r
+           DeregisterEventSource(h);\r
+           once++;\r
+       }\r
     }\r
 \r
     return(dwDebug ? TRUE : FALSE);\r
@@ -719,7 +741,7 @@ KFW_get_cred( char * username,
     char * pname = 0;\r
     krb5_error_code code;\r
 \r
-    if (!pkrb5_init_context || !username || !password)\r
+    if (!pkrb5_init_context || !username || !password || !password[0])\r
         return 0;\r
 \r
     DebugEvent0(username);\r
@@ -751,22 +773,23 @@ KFW_get_cred( char * username,
     if ( code ) goto cleanup;\r
 \r
     DebugEvent0("got ccache");\r
+\r
     if ( lifetime == 0 )\r
         lifetime = pLeash_get_default_lifetime();\r
 \r
-    if ( password[0] ) {\r
-        code = KFW_kinit( ctx, cc, HWND_DESKTOP, \r
-                          pname\r
-                          password,\r
-                          lifetime,\r
-                          pLeash_get_default_forwardable(),\r
-                          pLeash_get_default_proxiable(),\r
-                          pLeash_get_default_renewable() ? pLeash_get_default_renew_till() : 0,\r
-                          pLeash_get_default_noaddresses(),\r
-                          pLeash_get_default_publicip());\r
-       DebugEvent0("kinit returned");\r
-        if ( code ) goto cleanup;\r
-    }\r
+    DebugEvent0("got lifetime");\r
+\r
+    code = KFW_kinit( ctx, cc, HWND_DESKTOP\r
+                     pname, \r
+                     password,\r
+                     lifetime,\r
+                     pLeash_get_default_forwardable(),\r
+                     pLeash_get_default_proxiable(),\r
+                     pLeash_get_default_renewable() ? pLeash_get_default_renew_till() : 0,\r
+                     pLeash_get_default_noaddresses(),\r
+                     pLeash_get_default_publicip());\r
+    DebugEvent0("kinit returned");\r
+    if ( code ) goto cleanup;\r
 \r
   cleanup:\r
     if ( pname )\r
@@ -1148,6 +1171,94 @@ KFW_copy_file_cache_to_default_cache(char * filename)
 }\r
 \r
 \r
+int\r
+KFW_copy_file_cache_to_api_cache(char * filename)\r
+{\r
+    char cachename[MAX_PATH + 8] = "FILE:";\r
+    krb5_context               ctx = 0;\r
+    krb5_error_code            code;\r
+    krb5_principal              princ = 0;\r
+    krb5_ccache                        cc  = 0;\r
+    krb5_ccache                 ncc = 0;\r
+    char                       *name = NULL;\r
+    int retval = 1;\r
+\r
+    if (!pkrb5_init_context || !filename)\r
+        return 1;\r
+\r
+    if ( strlen(filename) + sizeof("FILE:") > sizeof(cachename) )\r
+        return 1;\r
+\r
+    strcat(cachename, filename);\r
+\r
+    code = pkrb5_init_context(&ctx);\r
+    if (code) ctx = 0;\r
+\r
+    code = pkrb5_cc_resolve(ctx, cachename, &cc);\r
+    if (code) {\r
+       DebugEvent0("kfwcpcc krb5_cc_resolve failed");\r
+       goto cleanup;\r
+    }\r
+    \r
+    code = pkrb5_cc_get_principal(ctx, cc, &princ);\r
+    if (code) {\r
+       DebugEvent0("kfwcpcc krb5_cc_get_principal failed");\r
+       goto cleanup;\r
+    }\r
+\r
+    code = pkrb5_unparse_name(ctx, princ, &name);\r
+    if (code) {\r
+       DebugEvent0("kfwcpcc krb5_unparse_name failed");\r
+       goto cleanup;\r
+    }\r
+\r
+    sprintf(cachename, "API:%s", name);\r
+\r
+    code = pkrb5_cc_resolve(ctx, cachename, &ncc);\r
+    if (code) {\r
+       DebugEvent0("kfwcpcc krb5_cc_default failed");\r
+       goto cleanup;\r
+    }\r
+    if (!code) {\r
+        code = pkrb5_cc_initialize(ctx, ncc, princ);\r
+\r
+        if (!code)\r
+            code = pkrb5_cc_copy_creds(ctx,cc,ncc);\r
+       if (code) {\r
+           DebugEvent0("kfwcpcc krb5_cc_copy_creds failed");\r
+           goto cleanup;\r
+       }\r
+    }\r
+    if ( ncc ) {\r
+        pkrb5_cc_close(ctx, ncc);\r
+        ncc = 0;\r
+    }\r
+\r
+    retval=0;   /* success */\r
+\r
+  cleanup:\r
+    if (name)\r
+       pkrb5_free_unparsed_name(ctx, name);\r
+\r
+    if ( cc ) {\r
+        pkrb5_cc_close(ctx, cc);\r
+        cc = 0;\r
+    }\r
+\r
+    DeleteFile(filename);\r
+\r
+    if ( princ ) {\r
+        pkrb5_free_principal(ctx, princ);\r
+        princ = 0;\r
+    }\r
+\r
+    if (ctx)\r
+        pkrb5_free_context(ctx);\r
+\r
+    return 0;\r
+}\r
+\r
+\r
 int \r
 KFW_destroy_tickets_for_principal(char * user)\r
 {\r
index c3485c02d024d0019fef9d196bba40bb24e46751..5ff778552704d982f93e9a9910f7899a04d6ebcc 100644 (file)
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
 \r
     KFW_initialize();\r
 \r
-    return KFW_copy_file_cache_to_default_cache(argv[1]);\r
+    return KFW_copy_file_cache_to_api_cache(argv[1]);\r
 }\r
 \r
 \r