summaryrefslogtreecommitdiff
path: root/source3/auth
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2010-07-19 13:48:31 -0400
committerSimo Sorce <idra@samba.org>2010-07-19 13:48:31 -0400
commitf9f3358348229b14d368316e327cfd2a4cb48c7c (patch)
tree9fb61c2ed61dd1ff93a64fc4498a4ec8d3a0607d /source3/auth
parent7e4de49bfceed18c81abf93703a61d0a22617a24 (diff)
parent630a2eb68af0d523a1bb4451bbaa75d2ba47d252 (diff)
downloadsamba-f9f3358348229b14d368316e327cfd2a4cb48c7c.tar.gz
samba-f9f3358348229b14d368316e327cfd2a4cb48c7c.tar.bz2
samba-f9f3358348229b14d368316e327cfd2a4cb48c7c.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Diffstat (limited to 'source3/auth')
-rw-r--r--source3/auth/auth.c34
-rw-r--r--source3/auth/auth_compat.c2
-rw-r--r--source3/auth/auth_ntlmssp.c67
3 files changed, 48 insertions, 55 deletions
diff --git a/source3/auth/auth.c b/source3/auth/auth.c
index a52dab9f01..5dc1d970d6 100644
--- a/source3/auth/auth.c
+++ b/source3/auth/auth.c
@@ -322,38 +322,40 @@ static NTSTATUS check_ntlm_password(const struct auth_context *auth_context,
Clear out a auth_context, and destroy the attached TALLOC_CTX
***************************************************************************/
-static void free_auth_context(struct auth_context **auth_context)
+static int auth_context_destructor(void *ptr)
{
- auth_methods *auth_method;
+ struct auth_context *ctx = talloc_get_type(ptr, struct auth_context);
+ struct auth_methods *am;
- if (*auth_context) {
- /* Free private data of context's authentication methods */
- for (auth_method = (*auth_context)->auth_method_list; auth_method; auth_method = auth_method->next) {
- TALLOC_FREE(auth_method->private_data);
- }
- talloc_destroy(*auth_context);
- *auth_context = NULL;
+ /* Free private data of context's authentication methods */
+ for (am = ctx->auth_method_list; am; am = am->next) {
+ TALLOC_FREE(am->private_data);
}
+
+ return 0;
}
/***************************************************************************
Make a auth_info struct
***************************************************************************/
-static NTSTATUS make_auth_context(struct auth_context **auth_context)
+static NTSTATUS make_auth_context(struct auth_context **auth_context)
{
- *auth_context = TALLOC_ZERO_P(talloc_autofree_context(),
- struct auth_context);
- if (!*auth_context) {
+ struct auth_context *ctx;
+
+ ctx = talloc_zero(talloc_autofree_context(), struct auth_context);
+ if (!ctx) {
DEBUG(0,("make_auth_context: talloc failed!\n"));
return NT_STATUS_NO_MEMORY;
}
- (*auth_context)->check_ntlm_password = check_ntlm_password;
- (*auth_context)->get_ntlm_challenge = get_ntlm_challenge;
- (*auth_context)->free = free_auth_context;
+ ctx->check_ntlm_password = check_ntlm_password;
+ ctx->get_ntlm_challenge = get_ntlm_challenge;
+
+ talloc_set_destructor((TALLOC_CTX *)ctx, auth_context_destructor);
+ *auth_context = ctx;
return NT_STATUS_OK;
}
diff --git a/source3/auth/auth_compat.c b/source3/auth/auth_compat.c
index e90036f3ff..cdd4096654 100644
--- a/source3/auth/auth_compat.c
+++ b/source3/auth/auth_compat.c
@@ -59,7 +59,7 @@ NTSTATUS check_plaintext_password(const char *smb_name,
nt_status = plaintext_auth_context->check_ntlm_password(plaintext_auth_context,
user_info, server_info);
- (plaintext_auth_context->free)(&plaintext_auth_context);
+ TALLOC_FREE(plaintext_auth_context);
free_user_info(&user_info);
return nt_status;
}
diff --git a/source3/auth/auth_ntlmssp.c b/source3/auth/auth_ntlmssp.c
index ba7efbf48e..bebb86ee17 100644
--- a/source3/auth/auth_ntlmssp.c
+++ b/source3/auth/auth_ntlmssp.c
@@ -24,7 +24,6 @@
#include "../libcli/auth/ntlmssp.h"
struct auth_ntlmssp_state {
- TALLOC_CTX *mem_ctx;
struct auth_context *auth_context;
struct auth_serversupplied_info *server_info;
struct ntlmssp_state *ntlmssp_state;
@@ -241,29 +240,33 @@ static NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
if (auth_ntlmssp_state->server_info->user_session_key.length) {
DEBUG(10, ("Got NT session key of length %u\n",
(unsigned int)auth_ntlmssp_state->server_info->user_session_key.length));
- *user_session_key = data_blob_talloc(auth_ntlmssp_state->mem_ctx,
+ *user_session_key = data_blob_talloc(auth_ntlmssp_state,
auth_ntlmssp_state->server_info->user_session_key.data,
auth_ntlmssp_state->server_info->user_session_key.length);
}
if (auth_ntlmssp_state->server_info->lm_session_key.length) {
DEBUG(10, ("Got LM session key of length %u\n",
(unsigned int)auth_ntlmssp_state->server_info->lm_session_key.length));
- *lm_session_key = data_blob_talloc(auth_ntlmssp_state->mem_ctx,
+ *lm_session_key = data_blob_talloc(auth_ntlmssp_state,
auth_ntlmssp_state->server_info->lm_session_key.data,
auth_ntlmssp_state->server_info->lm_session_key.length);
}
return nt_status;
}
+static int auth_ntlmssp_state_destructor(void *ptr);
+
NTSTATUS auth_ntlmssp_start(struct auth_ntlmssp_state **auth_ntlmssp_state)
{
NTSTATUS nt_status;
- TALLOC_CTX *mem_ctx;
bool is_standalone;
const char *netbios_name;
const char *netbios_domain;
const char *dns_name;
char *dns_domain;
+ struct auth_ntlmssp_state *ans;
+ struct ntlmssp_state *ntlmssp_state;
+ struct auth_context *auth_context;
if ((enum server_types)lp_server_role() == ROLE_STANDALONE) {
is_standalone = true;
@@ -280,63 +283,51 @@ NTSTATUS auth_ntlmssp_start(struct auth_ntlmssp_state **auth_ntlmssp_state)
}
dns_name = get_mydnsfullname();
- mem_ctx = talloc_init("AUTH NTLMSSP context");
-
- *auth_ntlmssp_state = TALLOC_ZERO_P(mem_ctx, struct auth_ntlmssp_state);
- if (!*auth_ntlmssp_state) {
+ ans = talloc_zero(NULL, struct auth_ntlmssp_state);
+ if (!ans) {
DEBUG(0,("auth_ntlmssp_start: talloc failed!\n"));
- talloc_destroy(mem_ctx);
+ TALLOC_FREE(ntlmssp_state);
return NT_STATUS_NO_MEMORY;
}
- ZERO_STRUCTP(*auth_ntlmssp_state);
-
- (*auth_ntlmssp_state)->mem_ctx = mem_ctx;
-
- nt_status = ntlmssp_server_start(NULL,
+ nt_status = ntlmssp_server_start(ans,
is_standalone,
netbios_name,
netbios_domain,
dns_name,
dns_domain,
- &(*auth_ntlmssp_state)->ntlmssp_state);
+ &ans->ntlmssp_state);
if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
- if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(&(*auth_ntlmssp_state)->auth_context))) {
+ nt_status = make_auth_context_subsystem(&auth_context);
+ if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
+ ans->auth_context = talloc_steal(ans, auth_context);
- (*auth_ntlmssp_state)->ntlmssp_state->callback_private = (*auth_ntlmssp_state);
- (*auth_ntlmssp_state)->ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
- (*auth_ntlmssp_state)->ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
- (*auth_ntlmssp_state)->ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
- (*auth_ntlmssp_state)->ntlmssp_state->check_password = auth_ntlmssp_check_password;
+ ans->ntlmssp_state->callback_private = ans;
+ ans->ntlmssp_state->get_challenge = auth_ntlmssp_get_challenge;
+ ans->ntlmssp_state->may_set_challenge = auth_ntlmssp_may_set_challenge;
+ ans->ntlmssp_state->set_challenge = auth_ntlmssp_set_challenge;
+ ans->ntlmssp_state->check_password = auth_ntlmssp_check_password;
+ talloc_set_destructor((TALLOC_CTX *)ans, auth_ntlmssp_state_destructor);
+
+ *auth_ntlmssp_state = ans;
return NT_STATUS_OK;
}
-void auth_ntlmssp_end(struct auth_ntlmssp_state **auth_ntlmssp_state)
+static int auth_ntlmssp_state_destructor(void *ptr)
{
- TALLOC_CTX *mem_ctx;
+ struct auth_ntlmssp_state *ans;
- if (*auth_ntlmssp_state == NULL) {
- return;
- }
+ ans = talloc_get_type(ptr, struct auth_ntlmssp_state);
- mem_ctx = (*auth_ntlmssp_state)->mem_ctx;
- if ((*auth_ntlmssp_state)->ntlmssp_state) {
- ntlmssp_end(&(*auth_ntlmssp_state)->ntlmssp_state);
- }
- if ((*auth_ntlmssp_state)->auth_context) {
- ((*auth_ntlmssp_state)->auth_context->free)(&(*auth_ntlmssp_state)->auth_context);
- }
- if ((*auth_ntlmssp_state)->server_info) {
- TALLOC_FREE((*auth_ntlmssp_state)->server_info);
- }
- talloc_destroy(mem_ctx);
- *auth_ntlmssp_state = NULL;
+ TALLOC_FREE(ans->server_info);
+ TALLOC_FREE(ans->ntlmssp_state);
+ return 0;
}
NTSTATUS auth_ntlmssp_update(struct auth_ntlmssp_state *auth_ntlmssp_state,