summaryrefslogtreecommitdiff
path: root/source3/nsswitch
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2001-10-19 08:22:52 +0000
committerTim Potter <tpot@samba.org>2001-10-19 08:22:52 +0000
commite3e9c52b7a5d653d1a6ec4a741c8335829fd6a87 (patch)
tree974fc8621239e8175853e8c463c3ea7b5070939e /source3/nsswitch
parent52995a5f7d48d41b07ee9fab20903a685c0dd33b (diff)
downloadsamba-e3e9c52b7a5d653d1a6ec4a741c8335829fd6a87.tar.gz
samba-e3e9c52b7a5d653d1a6ec4a741c8335829fd6a87.tar.bz2
samba-e3e9c52b7a5d653d1a6ec4a741c8335829fd6a87.zip
Fixed some memory leaks introduced by connection handling rewrite, as well
as one memory leak that has been there for ages! Changed the way talloc is used in get{pw,gr}nam routines. (This used to be commit d52cd1854fdff18c223d6dd1eca0e26f1f0bf01b)
Diffstat (limited to 'source3/nsswitch')
-rw-r--r--source3/nsswitch/winbindd.h1
-rw-r--r--source3/nsswitch/winbindd_group.c23
-rw-r--r--source3/nsswitch/winbindd_user.c23
-rw-r--r--source3/nsswitch/winbindd_util.c2
4 files changed, 29 insertions, 20 deletions
diff --git a/source3/nsswitch/winbindd.h b/source3/nsswitch/winbindd.h
index 659789a920..a9035ca200 100644
--- a/source3/nsswitch/winbindd.h
+++ b/source3/nsswitch/winbindd.h
@@ -55,7 +55,6 @@ struct getent_state {
uint32 grp_query_start_ndx;
BOOL got_all_sam_entries, got_sam_entries;
struct winbindd_domain *domain;
- TALLOC_CTX *mem_ctx;
};
/* Storage for cached getpwent() user entries */
diff --git a/source3/nsswitch/winbindd_group.c b/source3/nsswitch/winbindd_group.c
index b526feb780..2dbc5ded49 100644
--- a/source3/nsswitch/winbindd_group.c
+++ b/source3/nsswitch/winbindd_group.c
@@ -410,7 +410,6 @@ enum winbindd_result winbindd_setgrent(struct winbindd_cli_state *state)
ZERO_STRUCTP(domain_state);
domain_state->domain = tmp;
- domain_state->mem_ctx = talloc_init();
/* Add to list of open domains */
@@ -444,6 +443,8 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
NTSTATUS status;
uint32 num_entries;
struct acct_info *name_list = NULL, *tnl;
+ TALLOC_CTX *mem_ctx;
+ BOOL result = False;
if (ent->got_all_sam_entries)
return False;
@@ -454,6 +455,9 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
&ent->num_sam_entries))
return True;
#endif
+
+ if (!(mem_ctx = talloc_init()))
+ return False;
/* Free any existing group info */
@@ -473,7 +477,7 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
break;
status = cli_samr_enum_dom_groups(
- hnd->cli, ent->mem_ctx, &hnd->pol,
+ hnd->cli, mem_ctx, &hnd->pol,
&ent->grp_query_start_ndx,
0x8000, /* buffer size? */
(struct acct_info **) &sam_grp_entries, &num_entries);
@@ -492,15 +496,13 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
"realloc a structure!\n"));
SAFE_FREE(name_list);
- return False;
+ goto done;
} else
name_list = tnl;
memcpy(&name_list[ent->num_sam_entries],
sam_grp_entries,
num_entries * sizeof(struct acct_info));
-
- SAFE_FREE(sam_grp_entries);
}
ent->num_sam_entries += num_entries;
@@ -524,7 +526,12 @@ static BOOL get_sam_group_entries(struct getent_state *ent)
ent->got_all_sam_entries = (NT_STATUS_V(status) !=
NT_STATUS_V(STATUS_MORE_ENTRIES));
- return ent->num_sam_entries > 0;
+ result = (ent->num_sam_entries > 0);
+
+ done:
+ talloc_destroy(mem_ctx);
+
+ return result;
}
/* Fetch next group entry from ntdom database */
@@ -585,7 +592,6 @@ enum winbindd_result winbindd_getgrent(struct winbindd_cli_state *state)
/* Free state information for this domain */
SAFE_FREE(ent->sam_entries);
- ent->sam_entries = NULL;
next_ent = ent->next;
DLIST_REMOVE(state->getgrent_state, ent);
@@ -762,7 +768,6 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
ZERO_STRUCT(groups);
groups.domain = domain;
- groups.mem_ctx = talloc_init();
/*
* iterate through all groups
@@ -819,7 +824,6 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
DEBUG(0,("winbindd_list_groups: failed to enlarge "
"buffer!\n"));
SAFE_FREE(extra_data);
- talloc_destroy(groups.mem_ctx);
return WINBINDD_ERROR;
} else
extra_data = ted;
@@ -847,7 +851,6 @@ enum winbindd_result winbindd_list_groups(struct winbindd_cli_state *state)
}
next_group:
- talloc_destroy(groups.mem_ctx);
}
/* Assign extra_data fields in response structure */
diff --git a/source3/nsswitch/winbindd_user.c b/source3/nsswitch/winbindd_user.c
index 08a8973e94..6e64922cc0 100644
--- a/source3/nsswitch/winbindd_user.c
+++ b/source3/nsswitch/winbindd_user.c
@@ -302,7 +302,6 @@ enum winbindd_result winbindd_setpwent(struct winbindd_cli_state *state)
ZERO_STRUCTP(domain_state);
domain_state->domain = tmp;
- domain_state->mem_ctx = talloc_init();
/* Add to list of open domains */
@@ -339,10 +338,15 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
SAM_DISPINFO_CTR ctr;
struct getpwent_user *name_list = NULL;
uint32 group_rid;
+ BOOL result = False;
+ TALLOC_CTX *mem_ctx;
if (ent->got_all_sam_entries)
return False;
+ if (!(mem_ctx = talloc_init()))
+ return False;
+
ZERO_STRUCT(info1);
ZERO_STRUCT(ctr);
@@ -379,7 +383,7 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
num_entries = 0;
- status = winbindd_query_dispinfo(ent->domain, ent->mem_ctx,
+ status = winbindd_query_dispinfo(ent->domain, mem_ctx,
&ent->dispinfo_ndx, 1,
&num_entries, &ctr);
@@ -394,7 +398,7 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
if (!tnl) {
DEBUG(0,("get_sam_user_entries: Realloc failed.\n"));
SAFE_FREE(name_list);
- return WINBINDD_ERROR;
+ goto done;
} else
name_list = tnl;
}
@@ -424,9 +428,8 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
ent->num_sam_entries += num_entries;
- if (NT_STATUS_V(status) != NT_STATUS_V(STATUS_MORE_ENTRIES)) {
+ if (NT_STATUS_V(status) != NT_STATUS_V(STATUS_MORE_ENTRIES))
break;
- }
} while (ent->num_sam_entries < MAX_FETCH_SAM_ENTRIES);
@@ -441,9 +444,15 @@ static BOOL get_sam_user_entries(struct getent_state *ent)
ent->sam_entries = name_list;
ent->sam_entry_index = 0;
- ent->got_all_sam_entries = (NT_STATUS_V(status) != NT_STATUS_V(STATUS_MORE_ENTRIES));
+ ent->got_all_sam_entries = (NT_STATUS_V(status) !=
+ NT_STATUS_V(STATUS_MORE_ENTRIES));
+
+ result = ent->num_sam_entries > 0;
+
+ done:
+ talloc_destroy(mem_ctx);
- return ent->num_sam_entries > 0;
+ return result;
}
/* Fetch next passwd entry from ntdom database */
diff --git a/source3/nsswitch/winbindd_util.c b/source3/nsswitch/winbindd_util.c
index 0e0493e57f..cf0e6b8e93 100644
--- a/source3/nsswitch/winbindd_util.c
+++ b/source3/nsswitch/winbindd_util.c
@@ -470,8 +470,6 @@ void free_getent_state(struct getent_state *state)
DLIST_REMOVE(state, state);
next = temp->next;
- talloc_destroy(temp->mem_ctx);
-
SAFE_FREE(temp);
temp = next;
}