mirror of
https://github.com/samba-team/samba.git
synced 2025-12-23 00:23:53 +03:00
r2439: - function that return just an int don't need a TALLOC_CTX
- fix some return and state bugs
metze
(This used to be commit 2757c593ab)
This commit is contained in:
committed by
Gerald (Jerry) Carter
parent
635f5fa942
commit
be61c9d877
@@ -39,7 +39,7 @@ NTSTATUS socket_create(const char *name, enum socket_type type, struct socket_co
|
||||
(*new_sock)->ops = socket_getops_byname(name, type);
|
||||
if (!(*new_sock)->ops) {
|
||||
talloc_free((*new_sock));
|
||||
return status;
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
status = (*new_sock)->ops->init((*new_sock));
|
||||
@@ -120,7 +120,7 @@ NTSTATUS socket_recv(struct socket_context *sock, TALLOC_CTX *mem_ctx,
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (sock->state != SOCKET_STATE_CLIENT_CONNECTED ||
|
||||
if (sock->state != SOCKET_STATE_CLIENT_CONNECTED &&
|
||||
sock->state != SOCKET_STATE_SERVER_CONNECTED) {
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ NTSTATUS socket_send(struct socket_context *sock, TALLOC_CTX *mem_ctx,
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (sock->state != SOCKET_STATE_CLIENT_CONNECTED ||
|
||||
if (sock->state != SOCKET_STATE_CLIENT_CONNECTED &&
|
||||
sock->state != SOCKET_STATE_SERVER_CONNECTED) {
|
||||
return NT_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -169,13 +169,13 @@ char *socket_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
return sock->ops->get_peer_addr(sock, mem_ctx);
|
||||
}
|
||||
|
||||
int socket_get_peer_port(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
int socket_get_peer_port(struct socket_context *sock)
|
||||
{
|
||||
if (!sock->ops->get_peer_port) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock->ops->get_peer_port(sock, mem_ctx);
|
||||
return sock->ops->get_peer_port(sock);
|
||||
}
|
||||
|
||||
char *socket_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
@@ -187,22 +187,22 @@ char *socket_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
return sock->ops->get_my_addr(sock, mem_ctx);
|
||||
}
|
||||
|
||||
int socket_get_my_port(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
int socket_get_my_port(struct socket_context *sock)
|
||||
{
|
||||
if (!sock->ops->get_my_port) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock->ops->get_my_port(sock, mem_ctx);
|
||||
return sock->ops->get_my_port(sock);
|
||||
}
|
||||
|
||||
int socket_get_fd(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
int socket_get_fd(struct socket_context *sock)
|
||||
{
|
||||
if (!sock->ops->get_fd) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sock->ops->get_fd(sock, mem_ctx);
|
||||
return sock->ops->get_fd(sock);
|
||||
}
|
||||
|
||||
const struct socket_ops *socket_getops_byname(const char *name, enum socket_type type)
|
||||
|
||||
@@ -56,11 +56,11 @@ struct socket_ops {
|
||||
NTSTATUS (*set_option)(struct socket_context *sock, const char *option, const char *val);
|
||||
|
||||
char *(*get_peer_addr)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
|
||||
int (*get_peer_port)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
|
||||
int (*get_peer_port)(struct socket_context *sock);
|
||||
char *(*get_my_addr)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
|
||||
int (*get_my_port)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
|
||||
int (*get_my_port)(struct socket_context *sock);
|
||||
|
||||
int (*get_fd)(struct socket_context *sock, TALLOC_CTX *mem_ctx);
|
||||
int (*get_fd)(struct socket_context *sock);
|
||||
};
|
||||
|
||||
enum socket_state {
|
||||
|
||||
@@ -67,7 +67,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock,
|
||||
return NT_STATUS_FOOBAR;
|
||||
}
|
||||
|
||||
ret = bind(sock->fd, &my_addr, sizeof(my_addr));
|
||||
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
|
||||
if (ret == -1) {
|
||||
/* TODO: we need to map from errno to NTSTATUS here! */
|
||||
return NT_STATUS_FOOBAR;
|
||||
@@ -90,7 +90,7 @@ static NTSTATUS ipv4_tcp_connect(struct socket_context *sock,
|
||||
}
|
||||
|
||||
|
||||
ret = connect(sock->fd, &srv_addr, sizeof(srv_addr));
|
||||
ret = connect(sock->fd, (const struct sockaddr *)&srv_addr, sizeof(srv_addr));
|
||||
if (ret == -1) {
|
||||
/* TODO: we need to map from errno to NTSTATUS here! */
|
||||
return NT_STATUS_FOOBAR;
|
||||
@@ -109,14 +109,13 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock,
|
||||
struct in_addr ip_addr;
|
||||
int ret;
|
||||
|
||||
ZERO_STRUCT(my_addr);
|
||||
|
||||
ret = inet_aton(my_address, &ip_addr);
|
||||
if (ret == 0) {
|
||||
/* not a valid ipv4 address */
|
||||
return NT_STATUS_FOOBAR;
|
||||
}
|
||||
|
||||
ZERO_STRUCT(my_addr);
|
||||
#ifdef HAVE_SOCK_SIN_LEN
|
||||
my_addr.sin_len = sizeof(my_addr);
|
||||
#endif
|
||||
@@ -124,7 +123,7 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock,
|
||||
my_addr.sin_port = htons(port);
|
||||
my_addr.sin_family = PF_INET;
|
||||
|
||||
ret = bind(sock->fd, &my_addr, sizeof(my_addr));
|
||||
ret = bind(sock->fd, (struct sockaddr *)&my_addr, sizeof(my_addr));
|
||||
if (ret == -1) {
|
||||
/* TODO: we need to map from errno to NTSTATUS here! */
|
||||
return NT_STATUS_FOOBAR;
|
||||
@@ -144,7 +143,9 @@ static NTSTATUS ipv4_tcp_listen(struct socket_context *sock,
|
||||
}
|
||||
}
|
||||
|
||||
return NT_STATUS_NOT_IMPLEMENTED;
|
||||
sock->state= SOCKET_STATE_SERVER_LISTEN;
|
||||
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
static NTSTATUS ipv4_tcp_accept(struct socket_context *sock, struct socket_context **new_sock, uint32_t flags)
|
||||
@@ -298,7 +299,7 @@ static char *ipv4_tcp_get_peer_addr(struct socket_context *sock, TALLOC_CTX *mem
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ipv4_tcp_get_peer_port(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
static int ipv4_tcp_get_peer_port(struct socket_context *sock)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@@ -308,12 +309,12 @@ static char *ipv4_tcp_get_my_addr(struct socket_context *sock, TALLOC_CTX *mem_c
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int ipv4_tcp_get_my_port(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
static int ipv4_tcp_get_my_port(struct socket_context *sock)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int ipv4_tcp_get_fd(struct socket_context *sock, TALLOC_CTX *mem_ctx)
|
||||
static int ipv4_tcp_get_fd(struct socket_context *sock)
|
||||
{
|
||||
return sock->fd;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user