r4394: Use 'raw' protocol towers in the lists in the endpoint rather then
[samba.git] / source4 / rpc_server / dcerpc_sock.c
index 4b892aed64af11d071e6da2757ec4f1db9b7ba8b..f8d0bbfc6dde71d59e94550d640da33e717bb842 100644 (file)
@@ -23,6 +23,8 @@
 */
 
 #include "includes.h"
+#include "events.h"
+#include "rpc_server/dcerpc_server.h"
 
 struct dcesrv_socket_context {
        const struct dcesrv_endpoint *endpoint;
@@ -38,8 +40,8 @@ static ssize_t dcerpc_write_fn(void *private, DATA_BLOB *out)
        struct socket_context *sock = private;
        size_t sendlen;
 
-       status = socket_send(sock, sock, out, &sendlen, 0);
-       if (!NT_STATUS_IS_OK(status)) {
+       status = socket_send(sock, out, &sendlen, 0);
+       if (NT_STATUS_IS_ERR(status)) {
                return -1;
        }
 
@@ -90,8 +92,10 @@ static void add_socket_rpc_ncalrpc(struct server_service *service,
        char *full_path;
 
        if (!e->ep_description.endpoint) {
-               /* No identifier specified: generate one */
-               e->ep_description.endpoint = generate_random_str(dce_ctx, 10);
+               /* No identifier specified: use DEFAULT. 
+                * DO NOT hardcode this value anywhere else. Rather, specify 
+                * no endpoint and let the epmapper worry about it. */
+               e->ep_description.endpoint = talloc_strdup(dce_ctx, "DEFAULT");
        }
 
        full_path = talloc_asprintf(dce_ctx, "%s/%s", lp_ncalrpc_dir(), e->ep_description.endpoint);
@@ -121,15 +125,15 @@ static void add_socket_rpc_ncalrpc(struct server_service *service,
   add a socket address to the list of events, one event per dcerpc endpoint
 */
 static void add_socket_rpc_tcp_iface(struct server_service *service, 
-                      const struct model_ops *model_ops,
-                      struct dcesrv_context *dce_ctx, 
-                          struct dcesrv_endpoint *e,
-                      struct in_addr *ifip)
+                                    const struct model_ops *model_ops,
+                                    struct dcesrv_context *dce_ctx, 
+                                    struct dcesrv_endpoint *e,
+                                    struct ipv4_addr *ifip)
 {
        struct server_socket *sock;
        struct dcesrv_socket_context *dcesrv_sock;
        uint16_t port = 0;
-       const char *ip_str = talloc_strdup(service, inet_ntoa(*ifip));
+       char *ip_str = talloc_strdup(service, sys_inet_ntoa(*ifip));
                        
        if (e->ep_description.endpoint) 
                port = atoi(e->ep_description.endpoint);
@@ -171,17 +175,16 @@ static void add_socket_rpc_tcp(struct server_service *service,
                int num_interfaces = iface_count();
                int i;
                for(i = 0; i < num_interfaces; i++) {
-                       struct in_addr *ifip = iface_n_ip(i);
+                       struct ipv4_addr *ifip = iface_n_ip(i);
                        if (ifip == NULL) {
                                continue;
                        }
                        add_socket_rpc_tcp_iface(service, model_ops, dce_ctx, e, ifip);
                }
        } else {
-               struct in_addr *ifip;
-               ifip = interpret_addr2(dce_ctx, lp_socket_address());
-               add_socket_rpc_tcp_iface(service, model_ops, dce_ctx, e, ifip);
-               talloc_free(ifip);
+               struct ipv4_addr ifip;
+               ifip = interpret_addr2(lp_socket_address());
+               add_socket_rpc_tcp_iface(service, model_ops, dce_ctx, e, &ifip);
        }
 
        return;
@@ -198,7 +201,7 @@ void dcesrv_sock_init(struct server_service *service, const struct model_ops *mo
 
        /* Make sure the directory for NCALRPC exists */
        if (!directory_exist(lp_ncalrpc_dir(), NULL)) {
-               mkdir(lp_ncalrpc_dir(), 700);
+               mkdir(lp_ncalrpc_dir(), S_IWUSR | S_IRUSR | S_IXUSR);
        }
 
        for (e=dce_ctx->endpoint_list;e;e=e->next) {
@@ -245,27 +248,36 @@ void dcesrv_sock_accept(struct server_connection *conn)
        return; 
 }
 
-void dcesrv_sock_recv(struct server_connection *conn, time_t t, uint16_t flags)
+void dcesrv_sock_recv(struct server_connection *conn, struct timeval t, uint16_t flags)
 {
        NTSTATUS status;
        struct dcesrv_connection *dce_conn = conn->private_data;
        DATA_BLOB tmp_blob;
+       size_t nread;
 
-       DEBUG(10,("dcesrv_sock_recv\n"));
+       tmp_blob = data_blob_talloc(conn->socket, NULL, 0x1000);
+       if (tmp_blob.data == NULL) {
+               dcesrv_terminate_connection(dce_conn, "out of memory");
+               return;
+       }
 
-       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;
-               }
+       status = socket_recv(conn->socket, tmp_blob.data, tmp_blob.length, &nread, 0);
+       if (NT_STATUS_IS_ERR(status)) {
+               dcesrv_terminate_connection(dce_conn, nt_errstr(status));
+               return;
+       }
+       if (nread == 0) {
+               talloc_free(tmp_blob.data);
                return;
        }
 
+       tmp_blob.length = nread;
+
        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");
+               dcesrv_terminate_connection(dce_conn, nt_errstr(status));
                return;
        }
 
@@ -276,7 +288,7 @@ void dcesrv_sock_recv(struct server_connection *conn, time_t t, uint16_t flags)
        return; 
 }
 
-void dcesrv_sock_send(struct server_connection *conn, time_t t, uint16_t flags)
+void dcesrv_sock_send(struct server_connection *conn, struct timeval t, uint16_t flags)
 {
        struct dcesrv_connection *dce_conn = conn->private_data;
        NTSTATUS status;
@@ -296,14 +308,6 @@ void dcesrv_sock_send(struct server_connection *conn, time_t t, uint16_t flags)
        return;
 }
 
-void dcesrv_sock_idle(struct server_connection *conn, time_t t)
-{
-       DEBUG(10,("dcesrv_sock_idle\n"));
-       conn->event.idle->next_event = t + 5;
-
-       return; 
-}
-
 void dcesrv_sock_close(struct server_connection *conn, const char *reason)
 {
        struct dcesrv_connection *dce_conn = conn->private_data;