s3-idmap-hash: Make "hashed_domains" properly talloced
[nivanova/samba-autobuild/.git] / source3 / winbindd / idmap_hash / idmap_hash.c
index de4652d68488216527112bcbf599e57768cc0be7..816e3a05320a6583224f0c9383aca13915aed852 100644 (file)
 
 #include "includes.h"
 #include "winbindd/winbindd.h"
+#include "idmap.h"
 #include "idmap_hash.h"
+#include "ads.h"
 #include "nss_info.h"
+#include "../libcli/security/dom_sid.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_IDMAP
@@ -30,8 +33,6 @@ struct sid_hash_table {
        struct dom_sid *sid;
 };
 
-struct sid_hash_table *hashed_domains = NULL;
-
 /*********************************************************************
  Hash a domain SID (S-1-5-12-aaa-bbb-ccc) to a 12bit number
  ********************************************************************/
@@ -106,15 +107,16 @@ static void separate_hashes(uint32_t id,
 static NTSTATUS be_init(struct idmap_domain *dom,
                        const char *params)
 {
+       struct sid_hash_table *hashed_domains;
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        struct winbindd_tdc_domain *dom_list = NULL;
        size_t num_domains = 0;
        int i;
 
-       /* If the domain SID hash talbe has been initialized, assume
+       /* If the domain SID hash table has been initialized, assume
           that we completed this function previously */
 
-       if ( hashed_domains ) {
+       if (dom->private_data != NULL) {
                nt_status = NT_STATUS_OK;
                goto done;
        }
@@ -126,7 +128,7 @@ static NTSTATUS be_init(struct idmap_domain *dom,
 
        /* Create the hash table of domain SIDs */
 
-       hashed_domains = TALLOC_ZERO_ARRAY(NULL, struct sid_hash_table, 4096);
+       hashed_domains = TALLOC_ZERO_ARRAY(dom, struct sid_hash_table, 4096);
        BAIL_ON_PTR_NT_ERROR(hashed_domains, nt_status);
 
        /* create the hash table of domain SIDs */
@@ -148,6 +150,8 @@ static NTSTATUS be_init(struct idmap_domain *dom,
                sid_copy(hashed_domains[hash].sid, &dom_list[i].sid);
        }
 
+       dom->private_data = hashed_domains;
+
 done:
        return nt_status;
 }
@@ -158,6 +162,8 @@ done:
 static NTSTATUS unixids_to_sids(struct idmap_domain *dom,
                                struct id_map **ids)
 {
+       struct sid_hash_table *hashed_domains = talloc_get_type_abort(
+               dom->private_data, struct sid_hash_table);
        NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
        int i;
 
@@ -165,7 +171,7 @@ static NTSTATUS unixids_to_sids(struct idmap_domain *dom,
        for (i = 0; ids[i]; i++) {
                ids[i]->status = ID_UNKNOWN;
        }
-       
+
        nt_status = be_init(dom, NULL);
        BAIL_ON_NTSTATUS_ERROR(nt_status);
 
@@ -215,7 +221,7 @@ static NTSTATUS sids_to_unixids(struct idmap_domain *dom,
        for (i = 0; ids[i]; i++) {
                ids[i]->status = ID_UNKNOWN;
        }
-       
+
        nt_status = be_init(dom, NULL);
        BAIL_ON_NTSTATUS_ERROR(nt_status);
 
@@ -254,9 +260,6 @@ done:
 
 static NTSTATUS be_close(struct idmap_domain *dom)
 {
-       if (hashed_domains)
-               talloc_free(hashed_domains);
-
        return NT_STATUS_OK;
 }
 
@@ -274,8 +277,6 @@ static NTSTATUS nss_hash_init(struct nss_domain_entry *e )
 static NTSTATUS nss_hash_get_info(struct nss_domain_entry *e,
                                    const struct dom_sid *sid,
                                    TALLOC_CTX *ctx,
-                                   ADS_STRUCT *ads,
-                                   LDAPMessage *msg,
                                    const char **homedir,
                                    const char **shell,
                                    const char **gecos,