Fixed the handle leak in the connection management code (this code is crap
authorJeremy Allison <jra@samba.org>
Thu, 4 Apr 2002 02:39:57 +0000 (02:39 +0000)
committerJeremy Allison <jra@samba.org>
Thu, 4 Apr 2002 02:39:57 +0000 (02:39 +0000)
and should be rewritten, just not now... :-).
Jeremy.
(This used to be commit 5de792e7e9c2ad1422ac146caba632baa3f4e5c5)

source3/nsswitch/winbindd_cm.c
source3/nsswitch/winbindd_rpc.c
source3/rpc_parse/parse_lsa.c

index f4abf86c47d0c45107ca4a7bc34e05ed6edf7992..ce484795f846ad2c30211f2c376bcdb917f74e9a 100644 (file)
@@ -459,6 +459,13 @@ CLI_POLICY_HND *cm_get_lsa_handle(char *domain)
        if (!NT_STATUS_IS_OK(result = get_connection_from_cache(domain, PIPE_LSARPC, &conn))) {
                return NULL;
        }
+
+       /* This *shitty* code needs scrapping ! JRA */
+       if (policy_handle_is_valid(&conn->pol)) {
+               hnd.pol = conn->pol;
+               hnd.cli = conn->cli;
+               return &hnd;
+       }
        
        result = cli_lsa_open_policy(conn->cli, conn->cli->mem_ctx, False, 
                                     des_access, &conn->pol);
@@ -503,6 +510,12 @@ CLI_POLICY_HND *cm_get_sam_handle(char *domain)
                return NULL;
        }
        
+       /* This *shitty* code needs scrapping ! JRA */
+       if (policy_handle_is_valid(&conn->pol)) {
+               hnd.pol = conn->pol;
+               hnd.cli = conn->cli;
+               return &hnd;
+       }
        result = cli_samr_connect(conn->cli, conn->cli->mem_ctx,
                                  des_access, &conn->pol);
 
index c56b553bdca87747711fb7b95da3c67ce29ce146..53c39b2f5709438131beb18a11c06238f315f278 100644 (file)
@@ -67,7 +67,10 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
                ctr.sam.info1 = &info1;
 
                ctx2 = talloc_init_named("winbindd dispinfo");
-               if (!ctx2) return NT_STATUS_NO_MEMORY;
+               if (!ctx2) {
+                       result = NT_STATUS_NO_MEMORY;
+                       goto done;
+               }
                
                /* Query display info level 1 */
                result = cli_samr_query_dispinfo(hnd->cli, ctx2,
@@ -83,7 +86,9 @@ static NTSTATUS query_user_list(struct winbindd_domain *domain,
                (*info) = talloc_realloc(mem_ctx, *info,
                                         (*num_entries)*sizeof(WINBIND_USERINFO));
                if (!(*info)) {
-                       return NT_STATUS_NO_MEMORY;
+                       result = NT_STATUS_NO_MEMORY;
+                       talloc_destroy(ctx2);
+                       goto done;
                }
 
                for (j=0;j<count;i++, j++) {
@@ -157,6 +162,7 @@ static NTSTATUS enum_dom_groups(struct winbindd_domain *domain,
                                         sizeof(**info) * ((*num_entries) + count));
                if (! *info) {
                        talloc_destroy(mem_ctx2);
+                       cli_samr_close(hnd->cli, mem_ctx, &dom_pol);
                        return NT_STATUS_NO_MEMORY;
                }
 
@@ -286,11 +292,14 @@ static NTSTATUS query_user(struct winbindd_domain *domain,
        if (!NT_STATUS_IS_OK(result))
                goto done;
 
+       got_user_pol = True;
+
        /* Get user info */
        result = cli_samr_query_userinfo(hnd->cli, mem_ctx, &user_pol, 
                                         0x15, &ctr);
 
        cli_samr_close(hnd->cli, mem_ctx, &user_pol);
+       got_user_pol = False;
 
        user_info->group_rid = ctr->info.id21->group_rid;
        user_info->acct_name = unistr2_tdup(mem_ctx, 
index fd82325be7301cbef7f7a8142d15b94e6140e223..91b54b9c836ec8500c21d5ac4f532a9d95fdca76 100644 (file)
@@ -2094,4 +2094,10 @@ BOOL lsa_io_r_removeprivs(char *desc, LSA_R_REMOVEPRIVS *r_c, prs_struct *ps, in
        return True;
 }
 
+BOOL policy_handle_is_valid(const POLICY_HND *hnd)
+{
+       POLICY_HND zero_pol;
 
+       ZERO_STRUCT(zero_pol);
+       return ((memcmp(&zero_pol, hnd, sizeof(POLICY_HND)) == 0) ? False : True );
+}