mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
libsocket: Add "mem_ctx" to socket_create()
Every caller did a talloc_steal() after socket_create(). Just pass in the correct memory context. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
This commit is contained in:
parent
350826868d
commit
d88f826c7b
@ -339,13 +339,12 @@ _PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
|
||||
nbtsock->event_ctx = event_ctx;
|
||||
if (nbtsock->event_ctx == NULL) goto failed;
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_DGRAM, &nbtsock->sock, 0);
|
||||
status = socket_create(nbtsock, "ip", SOCKET_TYPE_DGRAM,
|
||||
&nbtsock->sock, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) goto failed;
|
||||
|
||||
socket_set_option(nbtsock->sock, "SO_BROADCAST", "1");
|
||||
|
||||
talloc_steal(nbtsock, nbtsock->sock);
|
||||
|
||||
nbtsock->idr = idr_init(nbtsock);
|
||||
if (nbtsock->idr == NULL) goto failed;
|
||||
|
||||
|
@ -261,10 +261,14 @@ static krb5_error_code smb_krb5_send_and_recv_func_int(krb5_context context,
|
||||
status = NT_STATUS_INVALID_PARAMETER;
|
||||
switch (hi->proto) {
|
||||
case KRB5_KRBHST_UDP:
|
||||
status = socket_create(name, SOCKET_TYPE_DGRAM, &smb_krb5->sock, 0);
|
||||
status = socket_create(smb_krb5, name,
|
||||
SOCKET_TYPE_DGRAM,
|
||||
&smb_krb5->sock, 0);
|
||||
break;
|
||||
case KRB5_KRBHST_TCP:
|
||||
status = socket_create(name, SOCKET_TYPE_STREAM, &smb_krb5->sock, 0);
|
||||
status = socket_create(smb_krb5, name,
|
||||
SOCKET_TYPE_STREAM,
|
||||
&smb_krb5->sock, 0);
|
||||
break;
|
||||
case KRB5_KRBHST_HTTP:
|
||||
TALLOC_FREE(frame);
|
||||
@ -275,8 +279,6 @@ static krb5_error_code smb_krb5_send_and_recv_func_int(krb5_context context,
|
||||
continue;
|
||||
}
|
||||
|
||||
talloc_steal(smb_krb5, smb_krb5->sock);
|
||||
|
||||
remote_addr = socket_address_from_sockaddr(smb_krb5, a->ai_addr, a->ai_addrlen);
|
||||
if (!remote_addr) {
|
||||
talloc_free(smb_krb5);
|
||||
|
@ -152,8 +152,9 @@ static void connect_multi_next_socket(struct composite_context *result)
|
||||
if (composite_nomem(state, result)) return;
|
||||
|
||||
state->result = result;
|
||||
result->status = socket_create(multi->server_address[multi->current_address]->family,
|
||||
SOCKET_TYPE_STREAM, &state->sock, 0);
|
||||
result->status = socket_create(
|
||||
state, multi->server_address[multi->current_address]->family,
|
||||
SOCKET_TYPE_STREAM, &state->sock, 0);
|
||||
if (!composite_is_ok(result)) return;
|
||||
|
||||
state->addr = socket_address_copy(state, multi->server_address[multi->current_address]);
|
||||
@ -161,8 +162,6 @@ static void connect_multi_next_socket(struct composite_context *result)
|
||||
|
||||
socket_address_set_port(state->addr, multi->ports[multi->current_port]);
|
||||
|
||||
talloc_steal(state, state->sock);
|
||||
|
||||
creq = socket_connect_send(state->sock, NULL,
|
||||
state->addr, 0,
|
||||
result->event_ctx);
|
||||
|
@ -96,7 +96,8 @@ _PUBLIC_ NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socke
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
_PUBLIC_ NTSTATUS socket_create(const char *name, enum socket_type type,
|
||||
_PUBLIC_ NTSTATUS socket_create(TALLOC_CTX *mem_ctx,
|
||||
const char *name, enum socket_type type,
|
||||
struct socket_context **new_sock, uint32_t flags)
|
||||
{
|
||||
const struct socket_ops *ops;
|
||||
@ -106,7 +107,7 @@ _PUBLIC_ NTSTATUS socket_create(const char *name, enum socket_type type,
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
return socket_create_with_ops(NULL, ops, new_sock, type, flags);
|
||||
return socket_create_with_ops(mem_ctx, ops, new_sock, type, flags);
|
||||
}
|
||||
|
||||
_PUBLIC_ NTSTATUS socket_connect(struct socket_context *sock,
|
||||
|
@ -133,7 +133,8 @@ struct tsocket_address;
|
||||
NTSTATUS socket_create_with_ops(TALLOC_CTX *mem_ctx, const struct socket_ops *ops,
|
||||
struct socket_context **new_sock,
|
||||
enum socket_type type, uint32_t flags);
|
||||
NTSTATUS socket_create(const char *name, enum socket_type type,
|
||||
NTSTATUS socket_create(TALLOC_CTX *mem_ctx,
|
||||
const char *name, enum socket_type type,
|
||||
struct socket_context **new_sock, uint32_t flags);
|
||||
NTSTATUS socket_connect(struct socket_context *sock,
|
||||
const struct socket_address *my_address,
|
||||
|
@ -45,13 +45,11 @@ static bool test_udp(struct torture_context *tctx)
|
||||
|
||||
load_interface_list(tctx, tctx->lp_ctx, &ifaces);
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock1, 0);
|
||||
status = socket_create(mem_ctx, "ip", SOCKET_TYPE_DGRAM, &sock1, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
|
||||
talloc_steal(mem_ctx, sock1);
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_DGRAM, &sock2, 0);
|
||||
status = socket_create(mem_ctx, "ip", SOCKET_TYPE_DGRAM, &sock2, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status, "creating DGRAM IP socket 1");
|
||||
talloc_steal(mem_ctx, sock2);
|
||||
|
||||
localhost = socket_address_from_strings(sock1, sock1->backend_name,
|
||||
iface_list_best_ip(ifaces, "127.0.0.1"), 0);
|
||||
@ -128,13 +126,11 @@ static bool test_tcp(struct torture_context *tctx)
|
||||
struct tevent_context *ev = tctx->ev;
|
||||
struct interface *ifaces;
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock1, 0);
|
||||
status = socket_create(mem_ctx, "ip", SOCKET_TYPE_STREAM, &sock1, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
|
||||
talloc_steal(mem_ctx, sock1);
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_STREAM, &sock2, 0);
|
||||
status = socket_create(mem_ctx, "ip", SOCKET_TYPE_STREAM, &sock2, 0);
|
||||
torture_assert_ntstatus_ok(tctx, status, "creating IP stream socket 1");
|
||||
talloc_steal(mem_ctx, sock2);
|
||||
|
||||
load_interface_list(tctx, tctx->lp_ctx, &ifaces);
|
||||
localhost = socket_address_from_strings(sock1, sock1->backend_name,
|
||||
|
@ -168,13 +168,12 @@ struct nbt_dgram_socket *nbt_dgram_socket_init(TALLOC_CTX *mem_ctx,
|
||||
dgmsock->event_ctx = event_ctx;
|
||||
if (dgmsock->event_ctx == NULL) goto failed;
|
||||
|
||||
status = socket_create("ip", SOCKET_TYPE_DGRAM, &dgmsock->sock, 0);
|
||||
status = socket_create(dgmsock, "ip", SOCKET_TYPE_DGRAM,
|
||||
&dgmsock->sock, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) goto failed;
|
||||
|
||||
socket_set_option(dgmsock->sock, "SO_BROADCAST", "1");
|
||||
|
||||
talloc_steal(dgmsock, dgmsock->sock);
|
||||
|
||||
dgmsock->fde = tevent_add_fd(dgmsock->event_ctx, dgmsock,
|
||||
socket_get_fd(dgmsock->sock), 0,
|
||||
dgm_socket_handler, dgmsock);
|
||||
|
@ -413,11 +413,12 @@ _PUBLIC_ struct composite_context *ldap_connect_send(struct ldap_connection *con
|
||||
struct socket_address *unix_addr;
|
||||
char path[1025];
|
||||
char *end = NULL;
|
||||
NTSTATUS status = socket_create("unix", SOCKET_TYPE_STREAM, &state->sock, 0);
|
||||
NTSTATUS status = socket_create(state, "unix",
|
||||
SOCKET_TYPE_STREAM,
|
||||
&state->sock, 0);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
return NULL;
|
||||
}
|
||||
talloc_steal(state, state->sock);
|
||||
SMB_ASSERT(sizeof(protocol)>10);
|
||||
SMB_ASSERT(sizeof(path)>1024);
|
||||
|
||||
|
@ -151,11 +151,10 @@ static struct composite_context *dcerpc_pipe_open_socket_send(TALLOC_CTX *mem_ct
|
||||
if (composite_nomem(s->target_hostname, c)) return c;
|
||||
}
|
||||
|
||||
c->status = socket_create(server->family, SOCKET_TYPE_STREAM, &s->socket_ctx, 0);
|
||||
c->status = socket_create(s, server->family, SOCKET_TYPE_STREAM,
|
||||
&s->socket_ctx, 0);
|
||||
if (!composite_is_ok(c)) return c;
|
||||
|
||||
talloc_steal(s, s->socket_ctx);
|
||||
|
||||
conn_req = socket_connect_send(s->socket_ctx, s->localaddr, s->server, 0,
|
||||
c->event_ctx);
|
||||
composite_continue(c, conn_req, continue_socket_connect, c);
|
||||
|
@ -315,10 +315,14 @@ NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = socket_create(socket_address->family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
|
||||
status = socket_create(stream_socket, socket_address->family,
|
||||
SOCKET_TYPE_STREAM,
|
||||
&stream_socket->sock, 0);
|
||||
NT_STATUS_NOT_OK_RETURN(status);
|
||||
} else {
|
||||
status = socket_create(family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
|
||||
status = socket_create(stream_socket, family,
|
||||
SOCKET_TYPE_STREAM,
|
||||
&stream_socket->sock, 0);
|
||||
NT_STATUS_NOT_OK_RETURN(status);
|
||||
|
||||
/* this is for non-IP sockets, eg. unix domain sockets */
|
||||
@ -329,8 +333,6 @@ NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
|
||||
}
|
||||
|
||||
|
||||
talloc_steal(stream_socket, stream_socket->sock);
|
||||
|
||||
stream_socket->lp_ctx = talloc_reference(stream_socket, lp_ctx);
|
||||
|
||||
/* ready to listen */
|
||||
|
Loading…
Reference in New Issue
Block a user