From adc57a79d99cfb6e0f5a1ba94275bb40eeb95bb7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 4 Apr 2002 02:39:57 +0000 Subject: Fixed the handle leak in the connection management code (this code is crap and should be rewritten, just not now... :-). Jeremy. (This used to be commit 5de792e7e9c2ad1422ac146caba632baa3f4e5c5) --- source3/nsswitch/winbindd_cm.c | 13 +++++++++++++ source3/nsswitch/winbindd_rpc.c | 13 +++++++++++-- source3/rpc_parse/parse_lsa.c | 6 ++++++ 3 files changed, 30 insertions(+), 2 deletions(-) (limited to 'source3') diff --git a/source3/nsswitch/winbindd_cm.c b/source3/nsswitch/winbindd_cm.c index f4abf86c47..ce484795f8 100644 --- a/source3/nsswitch/winbindd_cm.c +++ b/source3/nsswitch/winbindd_cm.c @@ -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); diff --git a/source3/nsswitch/winbindd_rpc.c b/source3/nsswitch/winbindd_rpc.c index c56b553bdc..53c39b2f57 100644 --- a/source3/nsswitch/winbindd_rpc.c +++ b/source3/nsswitch/winbindd_rpc.c @@ -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;jcli, 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, diff --git a/source3/rpc_parse/parse_lsa.c b/source3/rpc_parse/parse_lsa.c index fd82325be7..91b54b9c83 100644 --- a/source3/rpc_parse/parse_lsa.c +++ b/source3/rpc_parse/parse_lsa.c @@ -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 ); +} -- cgit