Author: gd
Date: 2006-05-02 19:15:14 +0000 (Tue, 02 May 2006)
New Revision: 15396

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=15396

Log:
Cleanup credential caches from winbind's linked list.

Guenther

Modified:
   branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
   branches/SAMBA_3_0/source/nsswitch/winbindd_pam.c
   trunk/source/nsswitch/winbindd_cred_cache.c
   trunk/source/nsswitch/winbindd_pam.c


Changeset:
Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c    2006-05-02 
19:00:19 UTC (rev 15395)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_cred_cache.c    2006-05-02 
19:15:14 UTC (rev 15396)
@@ -75,6 +75,7 @@
                        DLIST_REMOVE(ccache_list, entry);
                        TALLOC_FREE(entry->event); /* unregisters events */
                        TALLOC_FREE(entry);
+                       DEBUG(10,("remove_ccache_by_ccname: removed ccache 
%s\n", ccname));
                        return NT_STATUS_OK;
                }
        }
@@ -171,6 +172,7 @@
                            BOOL schedule_refresh_event)
 {
        struct WINBINDD_CCACHE_ENTRY *new_entry = NULL;
+       struct WINBINDD_CCACHE_ENTRY *old_entry = NULL;
        NTSTATUS status;
 
        if ((username == NULL && sid_string == NULL && princ_name == NULL) || 
@@ -192,6 +194,16 @@
                return NT_STATUS_NO_MORE_ENTRIES;
        }
 
+       /* get rid of old entries */
+       old_entry = get_ccache_by_username(username);
+       if (old_entry) {
+               status = remove_ccache_by_ccname(old_entry->ccname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(10,("add_ccache_to_list: failed to delete old 
ccache entry\n"));
+                       return status;
+               }
+       }
+       
        new_entry = TALLOC_P(mem_ctx, struct WINBINDD_CCACHE_ENTRY);
        if (new_entry == NULL) {
                return NT_STATUS_NO_MEMORY;

Modified: branches/SAMBA_3_0/source/nsswitch/winbindd_pam.c
===================================================================
--- branches/SAMBA_3_0/source/nsswitch/winbindd_pam.c   2006-05-02 19:00:19 UTC 
(rev 15395)
+++ branches/SAMBA_3_0/source/nsswitch/winbindd_pam.c   2006-05-02 19:15:14 UTC 
(rev 15396)
@@ -611,11 +611,16 @@
 
        krb5_ret = ads_kdestroy(cc);
        if (krb5_ret) {
-               DEBUG(0,("winbindd_raw_kerberos_login: "
+               DEBUG(3,("winbindd_raw_kerberos_login: "
                         "could not destroy krb5 credential cache: "
                         "%s\n", error_message(krb5_ret)));
        }
 
+       if (!NT_STATUS_IS_OK(remove_ccache_by_ccname(cc))) {
+               DEBUG(3,("winbindd_raw_kerberos_login: "
+                         "could not remove ccache\n"));
+       }
+
 done:
        data_blob_free(&session_key);
        data_blob_free(&session_key_krb5);

Modified: trunk/source/nsswitch/winbindd_cred_cache.c
===================================================================
--- trunk/source/nsswitch/winbindd_cred_cache.c 2006-05-02 19:00:19 UTC (rev 
15395)
+++ trunk/source/nsswitch/winbindd_cred_cache.c 2006-05-02 19:15:14 UTC (rev 
15396)
@@ -75,6 +75,7 @@
                        DLIST_REMOVE(ccache_list, entry);
                        TALLOC_FREE(entry->event); /* unregisters events */
                        TALLOC_FREE(entry);
+                       DEBUG(10,("remove_ccache_by_ccname: removed ccache 
%s\n", ccname));
                        return NT_STATUS_OK;
                }
        }
@@ -171,6 +172,7 @@
                            BOOL schedule_refresh_event)
 {
        struct WINBINDD_CCACHE_ENTRY *new_entry = NULL;
+       struct WINBINDD_CCACHE_ENTRY *old_entry = NULL;
        NTSTATUS status;
 
        if ((username == NULL && sid_string == NULL && princ_name == NULL) || 
@@ -192,6 +194,16 @@
                return NT_STATUS_NO_MORE_ENTRIES;
        }
 
+       /* get rid of old entries */
+       old_entry = get_ccache_by_username(username);
+       if (old_entry) {
+               status = remove_ccache_by_ccname(old_entry->ccname);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(10,("add_ccache_to_list: failed to delete old 
ccache entry\n"));
+                       return status;
+               }
+       }
+       
        new_entry = TALLOC_P(mem_ctx, struct WINBINDD_CCACHE_ENTRY);
        if (new_entry == NULL) {
                return NT_STATUS_NO_MEMORY;

Modified: trunk/source/nsswitch/winbindd_pam.c
===================================================================
--- trunk/source/nsswitch/winbindd_pam.c        2006-05-02 19:00:19 UTC (rev 
15395)
+++ trunk/source/nsswitch/winbindd_pam.c        2006-05-02 19:15:14 UTC (rev 
15396)
@@ -611,11 +611,16 @@
 
        krb5_ret = ads_kdestroy(cc);
        if (krb5_ret) {
-               DEBUG(0,("winbindd_raw_kerberos_login: "
+               DEBUG(3,("winbindd_raw_kerberos_login: "
                         "could not destroy krb5 credential cache: "
                         "%s\n", error_message(krb5_ret)));
        }
 
+       if (!NT_STATUS_IS_OK(remove_ccache_by_ccname(cc))) {
+               DEBUG(3,("winbindd_raw_kerberos_login: "
+                         "could not remove ccache\n"));
+       }
+
 done:
        data_blob_free(&session_key);
        data_blob_free(&session_key_krb5);

Reply via email to