summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-09-26 01:43:05 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:59:15 -0500
commit6bea5bea4ccd4eb45b9cd4dd1e16538b14e2180e (patch)
treebd8c95a07360dcf1363cbf49a46db6304893fc63
parent9cafc0d07ed339b511abf0f6fd41c289d2815974 (diff)
downloadsamba-6bea5bea4ccd4eb45b9cd4dd1e16538b14e2180e.tar.gz
samba-6bea5bea4ccd4eb45b9cd4dd1e16538b14e2180e.tar.bz2
samba-6bea5bea4ccd4eb45b9cd4dd1e16538b14e2180e.zip
r2643: convert more of the auth subsyystem to the new talloc methods. This
also fixes a memory leak found with --leak-check. (This used to be commit f19201ea274f0a542314c61c4af676197bf154ad)
-rw-r--r--source4/auth/auth.h4
-rw-r--r--source4/auth/auth_sam.c24
-rw-r--r--source4/auth/auth_util.c22
-rw-r--r--source4/libcli/auth/gensec_krb5.c18
-rw-r--r--source4/libcli/auth/gensec_ntlmssp.c4
-rw-r--r--source4/librpc/rpc/dcerpc_schannel.c13
-rw-r--r--source4/utils/ntlm_auth.c2
7 files changed, 35 insertions, 52 deletions
diff --git a/source4/auth/auth.h b/source4/auth/auth.h
index 74df97a2ed..6f2c7134e7 100644
--- a/source4/auth/auth.h
+++ b/source4/auth/auth.h
@@ -58,8 +58,6 @@ struct auth_usersupplied_info
struct auth_serversupplied_info
{
- TALLOC_CTX *mem_ctx;
-
BOOL guest;
struct dom_sid *user_sid;
@@ -95,8 +93,6 @@ struct auth_serversupplied_info
struct auth_session_info
{
- TALLOC_CTX *mem_ctx;
-
int refcount;
/* NT group information taken from the info3 structure */
diff --git a/source4/auth/auth_sam.c b/source4/auth/auth_sam.c
index 5239d6f413..74c8edcb82 100644
--- a/source4/auth/auth_sam.c
+++ b/source4/auth/auth_sam.c
@@ -332,19 +332,19 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
if (group_ret > 0 &&
!(groupSIDs = talloc_realloc_p(groupSIDs,
struct dom_sid *, group_ret))) {
- talloc_destroy((*server_info)->mem_ctx);
+ talloc_free(*server_info);
return NT_STATUS_NO_MEMORY;
}
/* Need to unroll some nested groups, but not aliases */
for (i = 0; i < group_ret; i++) {
sidstr = ldb_msg_find_string(group_msgs[i], "objectSid", NULL);
- groupSIDs[i] = dom_sid_parse_talloc((*server_info)->mem_ctx, sidstr);
+ groupSIDs[i] = dom_sid_parse_talloc(*server_info, sidstr);
}
sidstr = ldb_msg_find_string(msgs[0], "objectSid", NULL);
- user_sid = dom_sid_parse_talloc((*server_info)->mem_ctx, sidstr);
- primary_group_sid = dom_sid_parse_talloc((*server_info)->mem_ctx, sidstr);
+ user_sid = dom_sid_parse_talloc(*server_info, sidstr);
+ primary_group_sid = dom_sid_parse_talloc(*server_info, sidstr);
primary_group_sid->sub_auths[primary_group_sid->num_auths-1]
= samdb_result_uint(msgs[0], "primaryGroupID", 0);
@@ -356,29 +356,29 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
}
(*server_info)->account_name
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "sAMAccountName", ""));
(*server_info)->domain
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs_domain[0], "name", ""));
(*server_info)->full_name
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "displayName", ""));
(*server_info)->logon_script
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "scriptPath", ""));
(*server_info)->profile_path
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "profilePath", ""));
(*server_info)->home_directory
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "homeDirectory", ""));
(*server_info)->home_drive
- = talloc_strdup((*server_info)->mem_ctx,
+ = talloc_strdup(*server_info,
samdb_result_string(msgs[0], "homeDrive", ""));
(*server_info)->last_logon = samdb_result_nttime(msgs[0], "lastLogon", 0);
@@ -408,7 +408,7 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
|| !(*server_info)->profile_path
|| !(*server_info)->home_directory
|| !(*server_info)->home_drive) {
- talloc_destroy((*server_info)->mem_ctx);
+ talloc_destroy(*server_info);
return NT_STATUS_NO_MEMORY;
}
diff --git a/source4/auth/auth_util.c b/source4/auth/auth_util.c
index 3c77faefe1..ab725249c7 100644
--- a/source4/auth/auth_util.c
+++ b/source4/auth/auth_util.c
@@ -402,15 +402,12 @@ NTSTATUS create_nt_user_token(TALLOC_CTX *mem_ctx,
NTSTATUS make_server_info(struct auth_serversupplied_info **server_info,
const char *username)
{
- TALLOC_CTX *mem_ctx = talloc_init("auth subsystem: server_info for %s", username);
- *server_info = talloc_p(mem_ctx, struct auth_serversupplied_info);
+ *server_info = talloc_p(NULL, struct auth_serversupplied_info);
if (!*server_info) {
DEBUG(0,("make_server_info: malloc failed!\n"));
- talloc_destroy(mem_ctx);
return NT_STATUS_NO_MEMORY;
}
ZERO_STRUCTP(*server_info);
- (*server_info)->mem_ctx = mem_ctx;
return NT_STATUS_OK;
}
@@ -431,8 +428,8 @@ NTSTATUS make_server_info_guest(struct auth_serversupplied_info **server_info)
(*server_info)->guest = True;
- (*server_info)->user_sid = dom_sid_parse_talloc((*server_info)->mem_ctx, SID_ANONYMOUS);
- (*server_info)->primary_group_sid = dom_sid_parse_talloc((*server_info)->mem_ctx, SID_BUILTIN_GUESTS);
+ (*server_info)->user_sid = dom_sid_parse_talloc((*server_info), SID_ANONYMOUS);
+ (*server_info)->primary_group_sid = dom_sid_parse_talloc((*server_info), SID_BUILTIN_GUESTS);
(*server_info)->n_domain_groups = 0;
(*server_info)->domain_groups = NULL;
@@ -495,8 +492,8 @@ void free_user_info(struct auth_usersupplied_info **user_info)
void free_server_info(struct auth_serversupplied_info **server_info)
{
DEBUG(5,("attempting to free a server_info structure\n"));
- if (!*server_info) {
- talloc_destroy((*server_info)->mem_ctx);
+ if (*server_info) {
+ talloc_free(*server_info);
}
*server_info = NULL;
}
@@ -530,15 +527,12 @@ NTSTATUS make_session_info(struct auth_serversupplied_info *server_info,
{
NTSTATUS nt_status;
- *session_info = talloc_p(server_info->mem_ctx, struct auth_session_info);
+ *session_info = talloc_p(server_info, struct auth_session_info);
if (!*session_info) {
return NT_STATUS_NO_MEMORY;
}
(*session_info)->refcount = 1;
- (*session_info)->mem_ctx = server_info->mem_ctx;
- server_info->mem_ctx = NULL; /* make sure not to accidentily destory it,
- and this information is now constant */
(*session_info)->server_info = server_info;
/* unless set otherwise, the session key is the user session
@@ -546,7 +540,7 @@ NTSTATUS make_session_info(struct auth_serversupplied_info *server_info,
(*session_info)->session_key = server_info->user_session_key;
- nt_status = create_nt_user_token((*session_info)->mem_ctx,
+ nt_status = create_nt_user_token((*session_info),
server_info->user_sid,
server_info->primary_group_sid,
server_info->n_domain_groups,
@@ -567,7 +561,7 @@ void free_session_info(struct auth_session_info **session_info)
if (*session_info) {
(*session_info)->refcount--;
if ((*session_info)->refcount <= 0) {
- talloc_destroy((*session_info)->mem_ctx);
+ talloc_free((*session_info));
}
}
*session_info = NULL;
diff --git a/source4/libcli/auth/gensec_krb5.c b/source4/libcli/auth/gensec_krb5.c
index 37fa95bac4..06630455ce 100644
--- a/source4/libcli/auth/gensec_krb5.c
+++ b/source4/libcli/auth/gensec_krb5.c
@@ -627,13 +627,13 @@ static NTSTATUS gensec_krb5_session_info(struct gensec_security *gensec_security
server_info->guest = False;
- principal = talloc_strdup(server_info->mem_ctx, gensec_krb5_state->peer_principal);
+ principal = talloc_strdup(server_info, gensec_krb5_state->peer_principal);
p = strchr(principal, '@');
if (p) {
*p = '\0';
}
server_info->account_name = principal;
- server_info->domain = talloc_strdup(server_info->mem_ctx, p++);
+ server_info->domain = talloc_strdup(server_info, p++);
if (!server_info->domain) {
free_server_info(&server_info);
return NT_STATUS_NO_MEMORY;
@@ -650,7 +650,7 @@ static NTSTATUS gensec_krb5_session_info(struct gensec_security *gensec_security
* kind... */
if (logon_info) {
- ptoken = talloc_p(session_info->mem_ctx, struct nt_user_token);
+ ptoken = talloc_p(session_info, struct nt_user_token);
if (!ptoken) {
return NT_STATUS_NO_MEMORY;
}
@@ -663,16 +663,16 @@ static NTSTATUS gensec_krb5_session_info(struct gensec_security *gensec_security
}
- sid = dom_sid_dup(session_info->mem_ctx, logon_info->dom_sid);
- ptoken->user_sids[0] = dom_sid_add_rid(session_info->mem_ctx, sid, logon_info->user_rid);
+ sid = dom_sid_dup(session_info, logon_info->dom_sid);
+ ptoken->user_sids[0] = dom_sid_add_rid(session_info, sid, logon_info->user_rid);
ptoken->num_sids++;
- sid = dom_sid_dup(session_info->mem_ctx, logon_info->dom_sid);
- ptoken->user_sids[1] = dom_sid_add_rid(session_info->mem_ctx, sid, logon_info->group_rid);
+ sid = dom_sid_dup(session_info, logon_info->dom_sid);
+ ptoken->user_sids[1] = dom_sid_add_rid(session_info, sid, logon_info->group_rid);
ptoken->num_sids++;
for (;ptoken->num_sids < logon_info->groups_count; ptoken->num_sids++) {
- sid = dom_sid_dup(session_info->mem_ctx, logon_info->dom_sid);
- ptoken->user_sids[ptoken->num_sids] = dom_sid_add_rid(session_info->mem_ctx, sid, logon_info->groups[ptoken->num_sids - 2].rid);
+ sid = dom_sid_dup(session_info, logon_info->dom_sid);
+ ptoken->user_sids[ptoken->num_sids] = dom_sid_add_rid(session_info, sid, logon_info->groups[ptoken->num_sids - 2].rid);
}
debug_nt_user_token(DBGC_AUTH, 0, ptoken);
diff --git a/source4/libcli/auth/gensec_ntlmssp.c b/source4/libcli/auth/gensec_ntlmssp.c
index 0c96a783f1..8b760bcd45 100644
--- a/source4/libcli/auth/gensec_ntlmssp.c
+++ b/source4/libcli/auth/gensec_ntlmssp.c
@@ -386,11 +386,11 @@ static NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_secur
/* the session_info owns this now */
gensec_ntlmssp_state->server_info = NULL;
- (*session_info)->session_key = data_blob_talloc((*session_info)->mem_ctx,
+ (*session_info)->session_key = data_blob_talloc(*session_info,
gensec_ntlmssp_state->ntlmssp_state->session_key.data,
gensec_ntlmssp_state->ntlmssp_state->session_key.length);
- (*session_info)->workstation = talloc_strdup((*session_info)->mem_ctx,
+ (*session_info)->workstation = talloc_strdup(*session_info,
gensec_ntlmssp_state->ntlmssp_state->workstation);
return NT_STATUS_OK;
diff --git a/source4/librpc/rpc/dcerpc_schannel.c b/source4/librpc/rpc/dcerpc_schannel.c
index 057e20f497..7bb871811a 100644
--- a/source4/librpc/rpc/dcerpc_schannel.c
+++ b/source4/librpc/rpc/dcerpc_schannel.c
@@ -212,25 +212,18 @@ NTSTATUS dcerpc_schannel_session_info(struct gensec_security *gensec_security,
struct auth_session_info **session_info)
{
struct dcerpc_schannel_state *dce_schan_state = gensec_security->private_data;
- TALLOC_CTX *mem_ctx;
- mem_ctx = talloc_init("dcerpc_schannel_start");
- if (!mem_ctx) {
- return NT_STATUS_NO_MEMORY;
- }
- (*session_info) = talloc_p(mem_ctx, struct auth_session_info);
+ (*session_info) = talloc_p(gensec_security, struct auth_session_info);
if (*session_info == NULL) {
- talloc_destroy(mem_ctx);
return NT_STATUS_NO_MEMORY;
}
ZERO_STRUCTP(*session_info);
- (*session_info)->mem_ctx = mem_ctx;
(*session_info)->refcount = 1;
- (*session_info)->workstation = talloc_strdup(mem_ctx, dce_schan_state->account_name);
+ (*session_info)->workstation = talloc_strdup(*session_info, dce_schan_state->account_name);
if ((*session_info)->workstation == NULL) {
- talloc_destroy(mem_ctx);
+ talloc_free(*session_info);
return NT_STATUS_NO_MEMORY;
}
return NT_STATUS_OK;
diff --git a/source4/utils/ntlm_auth.c b/source4/utils/ntlm_auth.c
index 576996502d..e83aa76cf4 100644
--- a/source4/utils/ntlm_auth.c
+++ b/source4/utils/ntlm_auth.c
@@ -433,7 +433,7 @@ static void manage_gensec_request(enum stdio_helper_mode stdio_helper_mode,
reply_arg = talloc_asprintf(*gensec_state,
"%s%s%s", session_info->server_info->domain,
lp_winbind_separator(), session_info->server_info->account_name);
- talloc_destroy(session_info->mem_ctx);
+ talloc_free(session_info);
}
} else if ((*gensec_state)->gensec_role == GENSEC_CLIENT) {
reply_code = "AF";