uint8_t chal[8];
generate_random_buffer(chal, sizeof(chal));
- auth_context->challenge = data_blob_talloc(auth_context->mem_ctx,
+ auth_context->challenge = data_blob_talloc(auth_context,
chal, sizeof(chal));
challenge_set_by = "random";
}
}
- talloc_destroy((*auth_context)->mem_ctx);
+ talloc_free(*auth_context);
*auth_context = NULL;
}
}
Make a auth_info struct
***************************************************************************/
-static NTSTATUS make_auth_context(struct auth_context **auth_context)
+static NTSTATUS make_auth_context(TALLOC_CTX *mem_ctx, struct auth_context **auth_context)
{
- TALLOC_CTX *mem_ctx;
-
- mem_ctx = talloc_init("authentication context");
-
- *auth_context = talloc(mem_ctx, sizeof(**auth_context));
+ *auth_context = talloc_p(mem_ctx, struct auth_context);
if (!*auth_context) {
DEBUG(0,("make_auth_context: talloc failed!\n"));
- talloc_destroy(mem_ctx);
return NT_STATUS_NO_MEMORY;
}
ZERO_STRUCTP(*auth_context);
- (*auth_context)->mem_ctx = mem_ctx;
(*auth_context)->check_ntlm_password = check_ntlm_password;
(*auth_context)->get_ntlm_challenge = get_ntlm_challenge;
Make a auth_info struct for the auth subsystem
***************************************************************************/
-static NTSTATUS make_auth_context_text_list(struct auth_context **auth_context, char **text_list)
+static NTSTATUS make_auth_context_text_list(TALLOC_CTX *mem_ctx,
+ struct auth_context **auth_context, char **text_list)
{
struct auth_methods *list = NULL;
struct auth_methods *t = NULL;
return NT_STATUS_UNSUCCESSFUL;
}
- if (!NT_STATUS_IS_OK(nt_status = make_auth_context(auth_context)))
+ if (!NT_STATUS_IS_OK(nt_status = make_auth_context(mem_ctx, auth_context)))
return nt_status;
for (;*text_list; text_list++) {
Make a auth_context struct for the auth subsystem
***************************************************************************/
-NTSTATUS make_auth_context_subsystem(struct auth_context **auth_context)
+NTSTATUS make_auth_context_subsystem(TALLOC_CTX *mem_ctx, struct auth_context **auth_context)
{
char **auth_method_list = NULL;
NTSTATUS nt_status;
return NT_STATUS_NO_MEMORY;
}
- if (!NT_STATUS_IS_OK(nt_status = make_auth_context_text_list(auth_context, auth_method_list))) {
+ nt_status = make_auth_context_text_list(mem_ctx, auth_context, auth_method_list);
+ if (!NT_STATUS_IS_OK(nt_status)) {
str_list_free(&auth_method_list);
return nt_status;
}
Make a auth_info struct with a fixed challenge
***************************************************************************/
-NTSTATUS make_auth_context_fixed(struct auth_context **auth_context, uint8_t chal[8])
+NTSTATUS make_auth_context_fixed(TALLOC_CTX *mem_ctx,
+ struct auth_context **auth_context, uint8_t chal[8])
{
NTSTATUS nt_status;
- if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(auth_context))) {
+ if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(mem_ctx, auth_context))) {
return nt_status;
}
- (*auth_context)->challenge = data_blob_talloc((*auth_context)->mem_ctx, chal, 8);
+ (*auth_context)->challenge = data_blob_talloc(*auth_context, chal, 8);
(*auth_context)->challenge_set_by = "fixed";
return nt_status;
}
/* methods, in the order they should be called */
struct auth_methods *auth_method_list;
- TALLOC_CTX *mem_ctx;
const uint8_t *(*get_ntlm_challenge)(struct auth_context *auth_context);
NTSTATUS (*check_ntlm_password)(struct auth_context *auth_context,
const struct auth_usersupplied_info *user_info,
smb_panic("make_auth_methods: pointer to auth_method pointer is NULL!\n");
}
- *auth_method = talloc(auth_context->mem_ctx, sizeof(**auth_method));
+ *auth_method = talloc_p(auth_context, struct auth_methods);
if (!*auth_method) {
DEBUG(0,("make_auth_method: malloc failed!\n"));
return False;
SMB_ASSERT(challenge->length == 8);
- auth_context->challenge = data_blob_talloc(auth_context->mem_ctx,
+ auth_context->challenge = data_blob_talloc(auth_context,
challenge->data, challenge->length);
auth_context->challenge_set_by = "NTLMSSP callback (NTLM2)";
}
ntlmssp_state = gensec_ntlmssp_state->ntlmssp_state;
- if (!NT_STATUS_IS_OK(nt_status = make_auth_context_subsystem(&gensec_ntlmssp_state->auth_context))) {
+ nt_status = make_auth_context_subsystem(gensec_security, &gensec_ntlmssp_state->auth_context);
+ if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
r->in.logon.password->ntpassword.hash,
sizeof(r->in.logon.password->ntpassword.hash));
- nt_status = make_auth_context_subsystem(&auth_context);
+ nt_status = make_auth_context_subsystem(pipe_state, &auth_context);
if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
case 2:
case 6:
- nt_status = make_auth_context_fixed(&auth_context, r->in.logon.network->challenge);
+ nt_status = make_auth_context_fixed(pipe_state,
+ &auth_context, r->in.logon.network->challenge);
if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
DEBUG(10, ("get challenge: creating negprot_global_auth_context\n"));
- nt_status = make_auth_context_subsystem(&smb_conn->negotiate.auth_context);
+ nt_status = make_auth_context_subsystem(smb_conn, &smb_conn->negotiate.auth_context);
if (!NT_STATUS_IS_OK(nt_status)) {
DEBUG(0, ("make_auth_context_subsystem returned %s", nt_errstr(nt_status)));
make_user_info_guest(&user_info);
}
- status = make_auth_context_subsystem(&auth_context);
+ status = make_auth_context_subsystem(req->smb_conn, &auth_context);
if (!NT_STATUS_IS_OK(status)) {
return status;
DEBUG(2,("single_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn);
}
}
DEBUG(2,("single_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn->service->srv_ctx);
}
/* terminate this process */
DEBUG(0,("thread_terminate_connection: reason[%s]\n",reason));
if (conn) {
- if (conn->service) {
- conn->service->ops->close_connection(conn,reason);
- }
-
- if (conn->server_socket) {
- MUTEX_LOCK_BY_ID(MUTEX_SMBD);
- DLIST_REMOVE(conn->server_socket->connection_list,conn);
- MUTEX_UNLOCK_BY_ID(MUTEX_SMBD);
- }
-
- server_destroy_connection(conn);
+ talloc_free(conn);
}
/* terminate this thread */
return srv_sock;
}
+/*
+ destructor that handles necessary event context changes
+ */
+static int server_destructor(void *ptr)
+{
+ struct server_connection *conn = ptr;
+
+ if (conn->service) {
+ conn->service->ops->close_connection(conn, "shutdown");
+ }
+
+ socket_destroy(conn->socket);
+
+ event_remove_fd(conn->event.ctx, conn->event.fde);
+ conn->event.fde = NULL;
+ event_remove_timed(conn->event.ctx, conn->event.idle);
+ conn->event.idle = NULL;
+
+ DLIST_REMOVE(conn->server_socket->connection_list, conn);
+
+ return 0;
+}
+
struct server_connection *server_setup_connection(struct event_context *ev,
struct server_socket *server_socket,
struct socket_context *sock,
srv_conn->event.fde = event_add_fd(ev,&fde);
srv_conn->event.idle = event_add_timed(ev,&idle);
+ talloc_set_destructor(srv_conn, server_destructor);
+
if (!socket_check_access(sock, "smbd", lp_hostsallow(-1), lp_hostsdeny(-1))) {
server_terminate_connection(srv_conn, "denied by access rules");
return NULL;
srv_conn->service->model_ops->terminate_connection(srv_conn, reason);
}
-void server_destroy_connection(struct server_connection *srv_conn)
-{
- socket_destroy(srv_conn->socket);
-
- event_remove_fd(srv_conn->event.ctx, srv_conn->event.fde);
- srv_conn->event.fde = NULL;
- event_remove_timed(srv_conn->event.ctx, srv_conn->event.idle);
- srv_conn->event.idle = NULL;
-
- talloc_free(srv_conn);
-}
-
void server_io_handler(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags)
{
struct server_connection *conn = fde->private;