summaryrefslogtreecommitdiff
path: root/source3/winbindd
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2009-05-12 17:47:22 +0200
committerVolker Lendecke <vl@samba.org>2009-05-12 18:02:00 +0200
commit3fa69438b9fafc13d522720e188e82455856fc1d (patch)
tree785824d4d86e70053899ebc0bdda16cfab7befad /source3/winbindd
parentc9efd454c5ffe0126bb21fdaadd421d71c38e2f7 (diff)
downloadsamba-3fa69438b9fafc13d522720e188e82455856fc1d.tar.gz
samba-3fa69438b9fafc13d522720e188e82455856fc1d.tar.bz2
samba-3fa69438b9fafc13d522720e188e82455856fc1d.zip
Convert response.extra_data.data from malloc to talloc
Diffstat (limited to 'source3/winbindd')
-rw-r--r--source3/winbindd/winbindd.c12
-rw-r--r--source3/winbindd/winbindd_async.c18
-rw-r--r--source3/winbindd/winbindd_ccache_access.c3
-rw-r--r--source3/winbindd/winbindd_dual.c2
-rw-r--r--source3/winbindd/winbindd_group.c36
-rw-r--r--source3/winbindd/winbindd_misc.c22
-rw-r--r--source3/winbindd/winbindd_pam.c46
-rw-r--r--source3/winbindd/winbindd_user.c6
8 files changed, 47 insertions, 98 deletions
diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c
index bcfe52891a..fb7eda92c4 100644
--- a/source3/winbindd/winbindd.c
+++ b/source3/winbindd/winbindd.c
@@ -508,11 +508,6 @@ static void process_request(struct winbindd_cli_state *state)
{
struct winbindd_dispatch_table *table = dispatch_table;
- /* Free response data - we may be interrupted and receive another
- command before being able to send this data off. */
-
- SAFE_FREE(state->response.extra_data.data);
-
ZERO_STRUCT(state->response);
state->response.result = WINBINDD_PENDING;
@@ -680,8 +675,6 @@ static void response_extra_sent(void *private_data, bool success)
return;
}
- SAFE_FREE(state->response.extra_data.data);
-
setup_async_read(&state->fd_event, &state->request, sizeof(uint32),
request_len_recv, state);
}
@@ -886,11 +879,6 @@ static void remove_client(struct winbindd_cli_state *state)
free_getent_state(state->getpwent_state);
free_getent_state(state->getgrent_state);
- /* We may have some extra data that was not freed if the client was
- killed unexpectedly */
-
- SAFE_FREE(state->response.extra_data.data);
-
TALLOC_FREE(state->mem_ctx);
remove_fd_event(&state->fd_event);
diff --git a/source3/winbindd/winbindd_async.c b/source3/winbindd/winbindd_async.c
index b5c432ff90..3905b13073 100644
--- a/source3/winbindd/winbindd_async.c
+++ b/source3/winbindd/winbindd_async.c
@@ -469,8 +469,6 @@ static void listent_recv(TALLOC_CTX *mem_ctx, bool success,
cont(private_data, True, response->data.name.dom_name,
(char *)response->extra_data.data);
-
- SAFE_FREE(response->extra_data.data);
}
/* Request the name of all users/groups in a single domain */
@@ -499,7 +497,7 @@ enum winbindd_result winbindd_dual_list_users(struct winbindd_domain *domain,
NTSTATUS status;
struct winbindd_methods *methods;
uint32 num_entries = 0;
- char *extra_data = NULL;
+ char *extra_data;
uint32_t extra_data_len = 0, i;
/* Must copy domain into response first for debugging in parent */
@@ -519,8 +517,8 @@ enum winbindd_result winbindd_dual_list_users(struct winbindd_domain *domain,
/* Allocate some memory for extra data. Note that we limit
account names to sizeof(fstring) = 256 characters.
+1 for the ',' between group names */
- extra_data = (char *)SMB_REALLOC(extra_data,
- (sizeof(fstring) + 1) * num_entries);
+ extra_data = talloc_array(state->mem_ctx, char,
+ (sizeof(fstring) + 1) * num_entries);
if (!extra_data) {
DEBUG(0,("failed to enlarge buffer!\n"));
@@ -558,7 +556,7 @@ enum winbindd_result winbindd_dual_list_groups(struct winbindd_domain *domain,
struct winbindd_cli_state *state)
{
struct getent_state groups;
- char *extra_data = NULL;
+ char *extra_data;
uint32_t extra_data_len = 0, i;
ZERO_STRUCT(groups);
@@ -576,7 +574,8 @@ enum winbindd_result winbindd_dual_list_groups(struct winbindd_domain *domain,
/* Allocate some memory for extra data. Note that we limit
account names to sizeof(fstring) = 256 characters.
+1 for the ',' between group names */
- extra_data = (char *)SMB_REALLOC(extra_data,
+ extra_data = talloc_array(
+ state->mem_ctx, char,
(sizeof(fstring) + 1) * groups.num_sam_entries);
if (!extra_data) {
@@ -738,10 +737,7 @@ enum winbindd_result winbindd_dual_lookuprids(struct winbindd_domain *domain,
fstrcpy(state->response.data.domain_name, domain_name);
if (result != NULL) {
- state->response.extra_data.data = SMB_STRDUP(result);
- if (!state->response.extra_data.data) {
- return WINBINDD_ERROR;
- }
+ state->response.extra_data.data = result;
state->response.length += len+1;
}
diff --git a/source3/winbindd/winbindd_ccache_access.c b/source3/winbindd/winbindd_ccache_access.c
index dd6d352960..36680409a1 100644
--- a/source3/winbindd/winbindd_ccache_access.c
+++ b/source3/winbindd/winbindd_ccache_access.c
@@ -269,7 +269,8 @@ enum winbindd_result winbindd_dual_ccache_ntlm_auth(struct winbindd_domain *doma
goto process_result;
}
- state->response.extra_data.data = smb_xmemdup(auth.data, auth.length);
+ state->response.extra_data.data = talloc_memdup(
+ state->mem_ctx, auth.data, auth.length);
if (!state->response.extra_data.data) {
result = NT_STATUS_NO_MEMORY;
goto process_result;
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index d045678666..893303e7f4 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -1457,8 +1457,6 @@ static bool fork_domain_child(struct winbindd_child *child)
cache_store_response(sys_getpid(), &state.response);
- SAFE_FREE(state.response.extra_data.data);
-
/* We just send the result code back, the result
* structure needs to be fetched via the
* winbindd_cache. Hmm. That needs fixing... */
diff --git a/source3/winbindd/winbindd_group.c b/source3/winbindd/winbindd_group.c
index 6ad93adf4a..3273a288e2 100644
--- a/source3/winbindd/winbindd_group.c
+++ b/source3/winbindd/winbindd_group.c
@@ -879,7 +879,12 @@ static void getgrsid_sid2gid_recv(void *private_data, bool success, gid_t gid)
s->state->response.data.gr.gr_mem_ofs = 0;
s->state->response.length += gr_mem_len;
- s->state->response.extra_data.data = gr_mem;
+ s->state->response.extra_data.data = talloc_memdup(
+ s->state->mem_ctx, gr_mem, gr_mem_len);
+ if (s->state->response.extra_data.data == NULL) {
+ request_error(s->state);
+ return;
+ }
request_ok(s->state);
}
@@ -1272,17 +1277,14 @@ void winbindd_getgrent(struct winbindd_cli_state *state)
return;
}
- group_list = SMB_MALLOC_ARRAY(struct winbindd_gr, num_groups);
+ group_list = talloc_zero_array(state->mem_ctx, struct winbindd_gr,
+ num_groups);
if (!group_list) {
request_error(state);
return;
}
- /* will be freed by process_request() */
state->response.extra_data.data = group_list;
- memset(state->response.extra_data.data, '\0',
- num_groups * sizeof(struct winbindd_gr) );
-
state->response.data.num_entries = 0;
if (!state->getgrent_initialized)
@@ -1473,8 +1475,8 @@ void winbindd_getgrent(struct winbindd_cli_state *state)
if (group_list_ndx == 0)
goto done;
- state->response.extra_data.data = SMB_REALLOC(
- state->response.extra_data.data,
+ state->response.extra_data.data = talloc_realloc_size(
+ state->mem_ctx, state->response.extra_data.data,
group_list_ndx * sizeof(struct winbindd_gr) + gr_mem_list_len);
if (!state->response.extra_data.data) {
@@ -1699,10 +1701,7 @@ static void getgroups_sid2gid_recv(void *private_data, bool success, gid_t gid)
s->state->response.data.num_entries = s->num_token_gids;
if (s->num_token_gids) {
- /* s->token_gids are talloced */
- s->state->response.extra_data.data =
- smb_xmemdup(s->token_gids,
- s->num_token_gids * sizeof(gid_t));
+ s->state->response.extra_data.data = s->token_gids;
s->state->response.length += s->num_token_gids * sizeof(gid_t);
}
request_ok(s->state);
@@ -1770,7 +1769,7 @@ static void getusersids_recv(void *private_data, bool success, DOM_SID *sids,
}
/* build the reply */
- ret = (char *)SMB_MALLOC(ret_size);
+ ret = talloc_array(state->mem_ctx, char, ret_size);
if (!ret) {
DEBUG(0, ("malloc failed\n"));
request_error(state);
@@ -1856,10 +1855,7 @@ enum winbindd_result winbindd_dual_getuserdomgroups(struct winbindd_domain *doma
return WINBINDD_ERROR;
}
- state->response.extra_data.data = SMB_STRDUP(sidstring);
- if (!state->response.extra_data.data) {
- return WINBINDD_ERROR;
- }
+ state->response.extra_data.data = sidstring;
state->response.length += len+1;
state->response.data.num_entries = num_groups;
@@ -1965,11 +1961,7 @@ enum winbindd_result winbindd_dual_getsidaliases(struct winbindd_domain *domain,
state->response.extra_data.data = NULL;
if (sidstr) {
- state->response.extra_data.data = SMB_STRDUP(sidstr);
- if (!state->response.extra_data.data) {
- DEBUG(0, ("Out of memory\n"));
- return WINBINDD_ERROR;
- }
+ state->response.extra_data.data = sidstr;
DEBUG(10, ("aliases_list: %s\n",
(char *)state->response.extra_data.data));
state->response.length += len+1;
diff --git a/source3/winbindd/winbindd_misc.c b/source3/winbindd/winbindd_misc.c
index 737fd08d2a..4109adb14b 100644
--- a/source3/winbindd/winbindd_misc.c
+++ b/source3/winbindd/winbindd_misc.c
@@ -209,8 +209,7 @@ static void listent_recv(void *private_data, bool success, fstring dom_name,
/* Return list of all users/groups to the client */
if (state->extra_data) {
- state->cli_state->response.extra_data.data =
- SMB_STRDUP(state->extra_data);
+ state->cli_state->response.extra_data.data = state->extra_data;
state->cli_state->response.length += state->extra_data_len;
}
@@ -334,14 +333,13 @@ void winbindd_list_trusted_domains(struct winbindd_cli_state *state)
}
if (extra_data_len > 0) {
- state->response.extra_data.data = SMB_STRDUP(extra_data);
+ state->response.extra_data.data = extra_data;
state->response.length += extra_data_len+1;
}
request_ok(state);
done:
TALLOC_FREE( dom_list );
- TALLOC_FREE( extra_data );
}
enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *domain,
@@ -409,7 +407,7 @@ enum winbindd_result winbindd_dual_list_trusted_domains(struct winbindd_domain *
}
if (extra_data_len > 0) {
- state->response.extra_data.data = SMB_STRDUP(extra_data);
+ state->response.extra_data.data = extra_data;
state->response.length += extra_data_len+1;
}
@@ -607,8 +605,7 @@ static void sequence_recv(void *private_data, bool success)
cli_state->response.length =
sizeof(cli_state->response) +
strlen(state->extra_data) + 1;
- cli_state->response.extra_data.data =
- SMB_STRDUP(state->extra_data);
+ cli_state->response.extra_data.data = state->extra_data;
request_ok(cli_state);
return;
}
@@ -782,16 +779,13 @@ void winbindd_netbios_name(struct winbindd_cli_state *state)
void winbindd_priv_pipe_dir(struct winbindd_cli_state *state)
{
-
+ char *priv_dir;
DEBUG(3, ("[%5lu]: request location of privileged pipe\n",
(unsigned long)state->pid));
- state->response.extra_data.data = SMB_STRDUP(get_winbind_priv_pipe_dir());
- if (!state->response.extra_data.data) {
- DEBUG(0, ("malloc failed\n"));
- request_error(state);
- return;
- }
+ priv_dir = get_winbind_priv_pipe_dir();
+ state->response.extra_data.data = talloc_move(state->mem_ctx,
+ &priv_dir);
/* must add one to length to copy the 0 for string termination */
state->response.length +=
diff --git a/source3/winbindd/winbindd_pam.c b/source3/winbindd/winbindd_pam.c
index bbf3526fd0..a85cf0e6fc 100644
--- a/source3/winbindd/winbindd_pam.c
+++ b/source3/winbindd/winbindd_pam.c
@@ -35,7 +35,6 @@ static NTSTATUS append_info3_as_txt(TALLOC_CTX *mem_ctx,
struct netr_SamInfo3 *info3)
{
char *ex;
- size_t size;
uint32_t i;
state->response.data.auth.info3.logon_time =
@@ -82,7 +81,7 @@ static NTSTATUS append_info3_as_txt(TALLOC_CTX *mem_ctx,
fstrcpy(state->response.data.auth.info3.logon_dom,
info3->base.domain.string);
- ex = talloc_strdup(mem_ctx, "");
+ ex = talloc_strdup(state->mem_ctx, "");
NT_STATUS_HAVE_NO_MEMORY(ex);
for (i=0; i < info3->base.groups.count; i++) {
@@ -106,17 +105,8 @@ static NTSTATUS append_info3_as_txt(TALLOC_CTX *mem_ctx,
talloc_free(sid);
}
- size = talloc_get_size(ex);
-
- SAFE_FREE(state->response.extra_data.data);
- state->response.extra_data.data = SMB_MALLOC(size);
- if (!state->response.extra_data.data) {
- return NT_STATUS_NO_MEMORY;
- }
- memcpy(state->response.extra_data.data, ex, size);
- talloc_free(ex);
-
- state->response.length += size;
+ state->response.extra_data.data = ex;
+ state->response.length += talloc_get_size(ex);
return NT_STATUS_OK;
}
@@ -135,19 +125,9 @@ static NTSTATUS append_info3_as_ndr(TALLOC_CTX *mem_ctx,
return ndr_map_error2ntstatus(ndr_err);
}
- SAFE_FREE(state->response.extra_data.data);
- state->response.extra_data.data = SMB_MALLOC(blob.length);
- if (!state->response.extra_data.data) {
- data_blob_free(&blob);
- return NT_STATUS_NO_MEMORY;
- }
-
- memset(state->response.extra_data.data, '\0', blob.length);
- memcpy(state->response.extra_data.data, blob.data, blob.length);
+ state->response.extra_data.data = blob.data;
state->response.length += blob.length;
- data_blob_free(&blob);
-
return NT_STATUS_OK;
}
@@ -193,6 +173,7 @@ static NTSTATUS append_afs_token(TALLOC_CTX *mem_ctx,
{
char *afsname = NULL;
char *cell;
+ char *token;
afsname = talloc_strdup(mem_ctx, lp_afs_username_map());
if (afsname == NULL) {
@@ -235,15 +216,16 @@ static NTSTATUS append_afs_token(TALLOC_CTX *mem_ctx,
*cell = '\0';
cell += 1;
- /* Append an AFS token string */
- SAFE_FREE(state->response.extra_data.data);
- state->response.extra_data.data =
- afs_createtoken_str(afsname, cell);
-
- if (state->response.extra_data.data != NULL) {
- state->response.length +=
- strlen((const char *)state->response.extra_data.data)+1;
+ token = afs_createtoken_str(afsname, cell);
+ if (token == NULL) {
+ return NT_STATUS_OK;
+ }
+ state->response.extra_data.data = talloc_strdup(state->mem_ctx, token);
+ if (state->response.extra_data.data == NULL) {
+ return NT_STATUS_NO_MEMORY;
}
+ state->response.length +=
+ strlen((const char *)state->response.extra_data.data)+1;
return NT_STATUS_OK;
}
diff --git a/source3/winbindd/winbindd_user.c b/source3/winbindd/winbindd_user.c
index 50aea4e0cb..f990ca88e7 100644
--- a/source3/winbindd/winbindd_user.c
+++ b/source3/winbindd/winbindd_user.c
@@ -779,16 +779,14 @@ void winbindd_getpwent(struct winbindd_cli_state *state)
return;
}
- user_list = SMB_MALLOC_ARRAY(struct winbindd_pw, num_users);
+ user_list = talloc_zero_array(state->mem_ctx, struct winbindd_pw,
+ num_users);
if (!user_list) {
request_error(state);
return;
}
- /* will be freed by process_request() */
state->response.extra_data.data = user_list;
- memset(user_list, 0, num_users * sizeof(struct winbindd_pw));
-
if (!state->getpwent_initialized)
winbindd_setpwent_internal(state);