summaryrefslogtreecommitdiff
path: root/source4/rpc_server
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-09-20 12:31:07 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:58:54 -0500
commit7d06a06584e5163b69f712e38dc46afc2668389c (patch)
tree7b15e5c67ad99a2a576fac13ecf04287fdacbc61 /source4/rpc_server
parente8d244251732cd744c2c69e3e7bd7a875e704a60 (diff)
downloadsamba-7d06a06584e5163b69f712e38dc46afc2668389c.tar.gz
samba-7d06a06584e5163b69f712e38dc46afc2668389c.tar.bz2
samba-7d06a06584e5163b69f712e38dc46afc2668389c.zip
r2447: let the server code use the new lib/socket/ stuff
metze (This used to be commit 2fd577d2417e117a7e8c1a56feb147eae805df34)
Diffstat (limited to 'source4/rpc_server')
-rw-r--r--source4/rpc_server/dcerpc_server.c12
-rw-r--r--source4/rpc_server/dcerpc_tcp.c75
2 files changed, 40 insertions, 47 deletions
diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c
index e619053f6a..14b7c14d2a 100644
--- a/source4/rpc_server/dcerpc_server.c
+++ b/source4/rpc_server/dcerpc_server.c
@@ -929,7 +929,7 @@ NTSTATUS dcesrv_input(struct dcesrv_connection *dce_conn, const DATA_BLOB *data)
*/
NTSTATUS dcesrv_output(struct dcesrv_connection *dce_conn,
void *private,
- ssize_t (*write_fn)(void *, const void *, size_t))
+ ssize_t (*write_fn)(void *, DATA_BLOB *))
{
struct dcesrv_call_state *call;
struct dcesrv_call_reply *rep;
@@ -942,7 +942,7 @@ NTSTATUS dcesrv_output(struct dcesrv_connection *dce_conn,
}
rep = call->replies;
- nwritten = write_fn(private, rep->data.data, rep->data.length);
+ nwritten = write_fn(private, &rep->data);
if (nwritten == -1) {
/* TODO: hmm, how do we cope with this? destroy the
connection perhaps? */
@@ -972,13 +972,13 @@ NTSTATUS dcesrv_output(struct dcesrv_connection *dce_conn,
/*
write_fn() for dcesrv_output_blob()
*/
-static ssize_t dcesrv_output_blob_write_fn(void *private, const void *buf, size_t count)
+static ssize_t dcesrv_output_blob_write_fn(void *private, DATA_BLOB *out)
{
DATA_BLOB *blob = private;
- if (count < blob->length) {
- blob->length = count;
+ if (out->length < blob->length) {
+ blob->length = out->length;
}
- memcpy(blob->data, buf, blob->length);
+ memcpy(blob->data, out->data, blob->length);
return blob->length;
}
diff --git a/source4/rpc_server/dcerpc_tcp.c b/source4/rpc_server/dcerpc_tcp.c
index 26ced8c087..c5f88d467f 100644
--- a/source4/rpc_server/dcerpc_tcp.c
+++ b/source4/rpc_server/dcerpc_tcp.c
@@ -31,15 +31,18 @@ struct dcesrv_socket_context {
/*
write_fn callback for dcesrv_output()
*/
-static ssize_t dcerpc_write_fn(void *private, const void *buf, size_t count)
+static ssize_t dcerpc_write_fn(void *private, DATA_BLOB *out)
{
- struct fd_event *fde = private;
- ssize_t ret;
- ret = write(fde->fd, buf, count);
- if (ret == -1 && errno == EINTR) {
- return 0;
+ NTSTATUS status;
+ struct socket_context *sock = private;
+ size_t sendlen;
+
+ status = socket_send(sock, sock, out, &sendlen, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ return -1;
}
- return ret;
+
+ return sendlen;
}
void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, const char *reason)
@@ -52,24 +55,24 @@ void dcesrv_terminate_connection(struct dcesrv_connection *dce_conn, const char
*/
static void add_socket_rpc(struct server_service *service,
const struct model_ops *model_ops,
- struct socket_context *socket_ctx,
struct dcesrv_context *dce_ctx,
struct in_addr *ifip)
{
struct dcesrv_endpoint *e;
+ char *ip_str = talloc_strdup(service->mem_ctx, inet_ntoa(*ifip));
for (e=dce_ctx->endpoint_list;e;e=e->next) {
if (e->ep_description.type == ENDPOINT_TCP) {
struct server_socket *sock;
struct dcesrv_socket_context *dcesrv_sock;
- sock = service_setup_socket(service,model_ops,socket_ctx,ifip, &e->ep_description.info.tcp_port);
+ sock = service_setup_socket(service,model_ops, ip_str, &e->ep_description.info.tcp_port);
if (!sock) {
DEBUG(0,("service_setup_socket(port=%u) failed\n",e->ep_description.info.tcp_port));
continue;
}
- dcesrv_sock = talloc_p(sock->mem_ctx, struct dcesrv_socket_context);
+ dcesrv_sock = talloc_p(sock, struct dcesrv_socket_context);
if (!dcesrv_sock) {
DEBUG(0,("talloc_p(sock->mem_ctx, struct dcesrv_socket_context) failed\n"));
continue;
@@ -78,10 +81,12 @@ static void add_socket_rpc(struct server_service *service,
/* remeber the enpoint of this socket */
dcesrv_sock->endpoint = e;
dcesrv_sock->dcesrv_ctx = dce_ctx;
-
+
sock->private_data = dcesrv_sock;
}
}
+
+ talloc_free(ip_str);
}
/****************************************************************************
@@ -99,7 +104,7 @@ void dcesrv_tcp_init(struct server_service *service, const struct model_ops *mod
if (ifip == NULL) {
continue;
}
- add_socket_rpc(service, model_ops, NULL, dce_ctx, ifip);
+ add_socket_rpc(service, model_ops, dce_ctx, ifip);
}
} else {
struct in_addr *ifip;
@@ -109,7 +114,7 @@ void dcesrv_tcp_init(struct server_service *service, const struct model_ops *mod
}
ifip = interpret_addr2(mem_ctx, lp_socket_address());
- add_socket_rpc(service, model_ops, NULL, dce_ctx, ifip);
+ add_socket_rpc(service, model_ops, dce_ctx, ifip);
talloc_destroy(mem_ctx);
}
@@ -135,45 +140,32 @@ void dcesrv_tcp_accept(struct server_connection *conn)
conn->private_data = dcesrv_conn;
- /* TODO: this should to the generic code
- * but the smb server can't handle it yet
- * --metze
- */
- set_blocking(conn->event.fde->fd, False);
-
return;
}
void dcesrv_tcp_recv(struct server_connection *conn, time_t t, uint16_t flags)
{
+ NTSTATUS status;
struct dcesrv_connection *dce_conn = conn->private_data;
- DATA_BLOB blob;
- ssize_t ret;
+ DATA_BLOB tmp_blob;
DEBUG(10,("dcesrv_tcp_recv\n"));
- blob = data_blob(NULL, 0x4000);
- if (!blob.data) {
- dcesrv_terminate_connection(dce_conn, "eof on socket");
+ status = socket_recv(conn->socket, conn->socket, &tmp_blob, 0x4000, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ if (NT_STATUS_IS_ERR(status)) {
+ dcesrv_terminate_connection(dce_conn, "eof on socket");
+ return;
+ }
return;
}
- ret = read(conn->event.fde->fd, blob.data, blob.length);
- if (ret == 0 || (ret == -1 && errno != EINTR)) {
- data_blob_free(&blob);
+ status = dcesrv_input(dce_conn, &tmp_blob);
+ talloc_free(tmp_blob.data);
+ if (!NT_STATUS_IS_OK(status)) {
dcesrv_terminate_connection(dce_conn, "eof on socket");
return;
}
- if (ret == -1) {
- data_blob_free(&blob);
- return;
- }
-
- blob.length = ret;
-
- dcesrv_input(dce_conn, &blob);
-
- data_blob_free(&blob);
if (dce_conn->call_list && dce_conn->call_list->replies) {
conn->event.fde->flags |= EVENT_FD_WRITE;
@@ -189,16 +181,17 @@ void dcesrv_tcp_send(struct server_connection *conn, time_t t, uint16_t flags)
DEBUG(10,("dcesrv_tcp_send\n"));
- status = dcesrv_output(dce_conn, conn->event.fde, dcerpc_write_fn);
- if (NT_STATUS_IS_ERR(status)) {
- /* TODO: destroy fd_event? */
+ status = dcesrv_output(dce_conn, conn->socket, dcerpc_write_fn);
+ if (!NT_STATUS_IS_OK(status)) {
+ dcesrv_terminate_connection(dce_conn, "eof on socket");
+ return;
}
if (!dce_conn->call_list || !dce_conn->call_list->replies) {
conn->event.fde->flags &= ~EVENT_FD_WRITE;
}
- return;
+ return;
}
void dcesrv_tcp_idle(struct server_connection *conn, time_t t)