Remove useless layer of indirection, where every service called
[jelmer/samba4-debian.git] / source / rpc_server / service_rpc.c
index 6875ff88ff94cf8470ed0cfd68ed58a786db8a36..ddcf1c2a999166172aec47e42e207786a3c57c26 100644 (file)
@@ -107,7 +107,7 @@ static void dcesrv_sock_accept(struct stream_connection *srv_conn)
        struct dcesrv_connection *dcesrv_conn = NULL;
        struct auth_session_info *session_info = NULL;
 
-       status = auth_anonymous_session_info(srv_conn, &session_info);
+       status = auth_anonymous_session_info(srv_conn, dcesrv_sock->dcesrv_ctx->lp_ctx, &session_info);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("dcesrv_sock_accept: auth_anonymous_session_info failed: %s\n", 
                        nt_errstr(status)));
@@ -173,9 +173,9 @@ static void dcesrv_sock_recv(struct stream_connection *conn, uint16_t flags)
 
        tmp_blob.length = nread;
 
-       dce_conn->processing = True;
+       dce_conn->processing = true;
        status = dcesrv_input(dce_conn, &tmp_blob);
-       dce_conn->processing = False;
+       dce_conn->processing = false;
        talloc_free(tmp_blob.data);
 
        EVENT_FD_READABLE(conn->event.fde);
@@ -216,7 +216,9 @@ static const struct stream_server_ops dcesrv_stream_ops = {
 
 
 
-static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
+static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, 
+                                  struct loadparm_context *lp_ctx,
+                                  struct dcesrv_endpoint *e,
                            struct event_context *event_ctx, const struct model_ops *model_ops)
 {
        struct dcesrv_socket_context *dcesrv_sock;
@@ -230,8 +232,10 @@ static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, struct dcesrv
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, model_ops, &dcesrv_stream_ops, 
+       status = stream_setup_socket(event_ctx, lp_ctx,
+                                    model_ops, &dcesrv_stream_ops, 
                                     "unix", e->ep_description->endpoint, &port, 
+                                    lp_socket_options(lp_ctx), 
                                     dcesrv_sock);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("service_setup_stream_socket(path=%s) failed - %s\n",
@@ -241,8 +245,10 @@ static NTSTATUS dcesrv_add_ep_unix(struct dcesrv_context *dce_ctx, struct dcesrv
        return status;
 }
 
-static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
-                              struct event_context *event_ctx, const struct model_ops *model_ops)
+static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, 
+                                     struct loadparm_context *lp_ctx,
+                                     struct dcesrv_endpoint *e,
+                                     struct event_context *event_ctx, const struct model_ops *model_ops)
 {
        struct dcesrv_socket_context *dcesrv_sock;
        uint16_t port = 1;
@@ -256,7 +262,8 @@ static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, struct dce
                e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT");
        }
 
-       full_path = talloc_asprintf(dce_ctx, "%s/%s", lp_ncalrpc_dir(), e->ep_description->endpoint);
+       full_path = talloc_asprintf(dce_ctx, "%s/%s", lp_ncalrpc_dir(lp_ctx), 
+                                   e->ep_description->endpoint);
 
        dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
        NT_STATUS_HAVE_NO_MEMORY(dcesrv_sock);
@@ -265,8 +272,11 @@ static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, struct dce
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, model_ops, &dcesrv_stream_ops, 
-                                    "unix", full_path, &port, dcesrv_sock);
+       status = stream_setup_socket(event_ctx, lp_ctx,
+                                    model_ops, &dcesrv_stream_ops, 
+                                    "unix", full_path, &port, 
+                                    lp_socket_options(lp_ctx), 
+                                    dcesrv_sock);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("service_setup_stream_socket(identifier=%s,path=%s) failed - %s\n",
                         e->ep_description->endpoint, full_path, nt_errstr(status)));
@@ -309,8 +319,10 @@ static NTSTATUS add_socket_rpc_pipe_iface(struct dcesrv_context *dce_ctx, struct
        return status;
 }
 
-static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
-                                  struct event_context *event_ctx, const struct model_ops *model_ops)
+static NTSTATUS dcesrv_add_ep_np(struct dcesrv_context *dce_ctx, 
+                                struct loadparm_context *lp_ctx,
+                                struct dcesrv_endpoint *e,
+                                struct event_context *event_ctx, const struct model_ops *model_ops)
 {
        NTSTATUS status;
 
@@ -342,8 +354,11 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct
        dcesrv_sock->endpoint           = e;
        dcesrv_sock->dcesrv_ctx         = talloc_reference(dcesrv_sock, dce_ctx);
 
-       status = stream_setup_socket(event_ctx, model_ops, &dcesrv_stream_ops, 
-                                    "ipv4", address, &port, dcesrv_sock);
+       status = stream_setup_socket(event_ctx, dce_ctx->lp_ctx,
+                                    model_ops, &dcesrv_stream_ops, 
+                                    "ipv4", address, &port, 
+                                    lp_socket_options(dce_ctx->lp_ctx), 
+                                    dcesrv_sock);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) failed - %s\n", 
                         address, port, nt_errstr(status)));
@@ -356,22 +371,30 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct
        return status;
 }
 
-static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
-                                  struct event_context *event_ctx, const struct model_ops *model_ops)
+static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, 
+                                 struct loadparm_context *lp_ctx,
+                                 struct dcesrv_endpoint *e,
+                                 struct event_context *event_ctx, const struct model_ops *model_ops)
 {
        NTSTATUS status;
 
        /* Add TCP/IP sockets */
-       if (lp_interfaces() && lp_bind_interfaces_only()) {
-               int num_interfaces = iface_count();
+       if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
+               int num_interfaces;
                int i;
+               struct interface *ifaces;
+
+               load_interfaces(dce_ctx, lp_interfaces(lp_ctx), &ifaces);
+
+               num_interfaces = iface_count(ifaces);
                for(i = 0; i < num_interfaces; i++) {
-                       const char *address = iface_n_ip(i);
+                       const char *address = iface_n_ip(ifaces, i);
                        status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, address);
                        NT_STATUS_NOT_OK_RETURN(status);
                }
        } else {
-               status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, lp_socket_address());
+               status = add_socket_rpc_tcp_iface(dce_ctx, e, event_ctx, model_ops, 
+                                                 lp_socket_address(lp_ctx));
                NT_STATUS_NOT_OK_RETURN(status);
        }
 
@@ -379,21 +402,23 @@ static NTSTATUS dcesrv_add_ep_tcp(struct dcesrv_context *dce_ctx, struct dcesrv_
 }
 
 
-static NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx, struct dcesrv_endpoint *e,
+static NTSTATUS dcesrv_add_ep(struct dcesrv_context *dce_ctx, 
+                             struct loadparm_context *lp_ctx,
+                             struct dcesrv_endpoint *e,
                          struct event_context *event_ctx, const struct model_ops *model_ops)
 {
        switch (e->ep_description->transport) {
        case NCACN_UNIX_STREAM:
-               return dcesrv_add_ep_unix(dce_ctx, e, event_ctx, model_ops);
+               return dcesrv_add_ep_unix(dce_ctx, lp_ctx, e, event_ctx, model_ops);
 
        case NCALRPC:
-               return dcesrv_add_ep_ncalrpc(dce_ctx, e, event_ctx, model_ops);
+               return dcesrv_add_ep_ncalrpc(dce_ctx, lp_ctx, e, event_ctx, model_ops);
 
        case NCACN_IP_TCP:
-               return dcesrv_add_ep_tcp(dce_ctx, e, event_ctx, model_ops);
+               return dcesrv_add_ep_tcp(dce_ctx, lp_ctx, e, event_ctx, model_ops);
 
        case NCACN_NP:
-               return dcesrv_add_ep_np(dce_ctx, e, event_ctx, model_ops);
+               return dcesrv_add_ep_np(dce_ctx, lp_ctx, e, event_ctx, model_ops);
 
        default:
                return NT_STATUS_NOT_SUPPORTED;
@@ -412,17 +437,18 @@ static void dcesrv_task_init(struct task_server *task)
        task_server_set_title(task, "task[dcesrv]");
 
        status = dcesrv_init_context(task->event_ctx,
-                                    lp_dcerpc_endpoint_servers(),
+                                    task->lp_ctx,
+                                    lp_dcerpc_endpoint_servers(task->lp_ctx),
                                     &dce_ctx);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* Make sure the directory for NCALRPC exists */
-       if (!directory_exist(lp_ncalrpc_dir())) {
-               mkdir(lp_ncalrpc_dir(), 0755);
+       if (!directory_exist(lp_ncalrpc_dir(task->lp_ctx))) {
+               mkdir(lp_ncalrpc_dir(task->lp_ctx), 0755);
        }
 
        for (e=dce_ctx->endpoint_list;e;e=e->next) {
-               status = dcesrv_add_ep(dce_ctx, e, task->event_ctx, task->model_ops);
+               status = dcesrv_add_ep(dce_ctx, task->lp_ctx, e, task->event_ctx, task->model_ops);
                if (!NT_STATUS_IS_OK(status)) goto failed;
        }
 
@@ -431,27 +457,15 @@ failed:
        task_server_terminate(task, "Failed to startup dcerpc server task");    
 }
 
-/*
-  called on startup of the smb server service It's job is to start
-  listening on all configured sockets
-*/
-static NTSTATUS dcesrv_init(struct event_context *event_context, 
-                           const struct model_ops *model_ops)
-{      
-       return task_server_startup(event_context, model_ops, dcesrv_task_init);
-}
-
 NTSTATUS server_service_rpc_init(void)
 {
-       init_module_fn static_init[] = STATIC_dcerpc_server_MODULES;
-       init_module_fn *shared_init = load_samba_modules(NULL, "dcerpc_server");
+       init_module_fn static_init[] = { STATIC_dcerpc_server_MODULES };
+       init_module_fn *shared_init = load_samba_modules(NULL, global_loadparm, "dcerpc_server");
 
        run_init_functions(static_init);
        run_init_functions(shared_init);
 
        talloc_free(shared_init);
        
-       return register_server_service("rpc", dcesrv_init);
+       return register_server_service("rpc", dcesrv_task_init);
 }
-
-