mit_samba: Always save a copy of the principal
authorSimo Sorce <idra@samba.org>
Thu, 14 Jan 2010 01:24:18 +0000 (20:24 -0500)
committerSimo Sorce <idra@samba.org>
Tue, 1 Feb 2011 15:25:35 +0000 (10:25 -0500)
Fix a segfault, the original principal is needed i the pac code.

src/plugins/kdb/samba/kdb_samba.c
src/plugins/kdb/samba/kdb_samba.h
src/plugins/kdb/samba/kdb_samba_util.c

index 5095338cdc4263337c90943f9b312f4ab7bd1fb1..f1a9dc7531a2081a2e2586783bf9f86550e01e81 100644 (file)
@@ -267,7 +267,7 @@ ks_get_principal(krb5_context context,
         goto cleanup;
     }
 
-    code = ks_unmarshal_hdb_entry(context, &hentry->entry, kentry);
+    code = ks_unmarshal_hdb_entry(context, hentry, kentry);
     if (code != 0) {
         goto cleanup;
     }
@@ -277,8 +277,10 @@ cleanup:
     if (principal_string) {
         krb5_free_unparsed_name(context, principal_string);
     }
-    if (hentry) {
-        KS_FREE_DB_ENTRY(ks, hentry);
+    if (code != 0) {
+        if (hentry) {
+            KS_FREE_DB_ENTRY(ks, hentry);
+        }
     }
 
     return code;
@@ -575,14 +577,12 @@ ks_db_iterate(krb5_context context,
     while (code == 0) {
         krb5_db_entry kentry;
 
-        code = ks_unmarshal_hdb_entry(context, &hentry->entry, &kentry);
+        code = ks_unmarshal_hdb_entry(context, hentry, &kentry);
         if (code == 0) {
             code = (*func)(func_arg, &kentry);
             ks_free_krb5_db_entry(context, &kentry);
         }
 
-        KS_FREE_DB_ENTRY(ks, hentry);
-
         if (code != 0) {
             break;
         }
index 1537cf583afebbeab27263ddb8eac9b73d9ddadb..efcaf09b7c33fd73369277d10a2a61a52c1fc280 100644 (file)
@@ -63,7 +63,7 @@ typedef struct hdb_entry_ex {
 
 /* NOTE: Relies on the fact that samba doesn't use the context
  * for free_entry(), that's why we declare it (void *) */
-#define KS_FREE_DB_ENTRY(ks_ctx, hentry) hentry->free_entry(NULL, hentry);
+#define KS_FREE_DB_ENTRY(ks_ctx, hentry) (hentry)->free_entry(NULL, (hentry));
 
 #include "kdb_samba_interface.h"
 
@@ -104,7 +104,7 @@ ks_unmarshal_Principal(krb5_context context,
 
 krb5_error_code
 ks_unmarshal_hdb_entry(krb5_context context,
-                       const hdb_entry *hentry,
+                       struct hdb_entry_ex *hentry,
                        krb5_db_entry *kentry);
 
 /* from kdb_samba_policies.c */
index 3e60af943aa8a4ea98416de47a121d88e8784a56..acdb2b794118e1337a9743b74bf764e5a0749e0a 100644 (file)
@@ -100,7 +100,9 @@ ks_free_krb5_db_entry(krb5_context context,
     krb5_tl_data *tl_data = NULL;
     int i, j;
 
-    assert(entry->e_data == NULL);
+    if (entry->e_data) {
+        KS_FREE_DB_ENTRY(ks, (struct hdb_entry_ex *)(entry->e_data));
+    }
 
     krb5_free_principal(context, entry->princ);
 
@@ -440,9 +442,10 @@ ks_unmarshal_HDB_extensions(krb5_context context,
 
 krb5_error_code
 ks_unmarshal_hdb_entry(krb5_context context,
-                       const hdb_entry *hentry,
+                       struct hdb_entry_ex *hentry_ex,
                        krb5_db_entry *kentry)
 {
+    const hdb_entry *hentry = &hentry_ex->entry;
     krb5_error_code code;
     unsigned int i;
 
@@ -506,6 +509,8 @@ ks_unmarshal_hdb_entry(krb5_context context,
         kentry->n_key_data++;
     }
 
+    kentry->e_data = (void *)hentry_ex;
+
 cleanup:
     if (code != 0) {
         ks_free_krb5_db_entry(context, kentry);