Remove useless layer of indirection, where every service called
[jelmer/samba4-debian.git] / source / rpc_server / service_rpc.c
index 04dd5a8ee9e4ae5d80ae6d59c6819d96bf4e044e..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;
 
        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)));
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("dcesrv_sock_accept: auth_anonymous_session_info failed: %s\n", 
                        nt_errstr(status)));
@@ -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;
                            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);
 
        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, 
                                     "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",
                                     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;
 }
 
        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;
 {
        struct dcesrv_socket_context *dcesrv_sock;
        uint16_t port = 1;
@@ -256,7 +262,7 @@ static NTSTATUS dcesrv_add_ep_ncalrpc(struct dcesrv_context *dce_ctx, struct dce
                e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT");
        }
 
                e->ep_description->endpoint = talloc_strdup(dce_ctx, "DEFAULT");
        }
 
-       full_path = talloc_asprintf(dce_ctx, "%s/%s", lp_ncalrpc_dir(global_loadparm), 
+       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);
                                    e->ep_description->endpoint);
 
        dcesrv_sock = talloc(event_ctx, struct dcesrv_socket_context);
@@ -266,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);
 
        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)));
        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)));
@@ -310,8 +319,10 @@ static NTSTATUS add_socket_rpc_pipe_iface(struct dcesrv_context *dce_ctx, struct
        return status;
 }
 
        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;
 
 {
        NTSTATUS status;
 
@@ -343,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);
 
        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)));
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) failed - %s\n", 
                         address, port, nt_errstr(status)));
@@ -357,23 +371,30 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx, struct
        return status;
 }
 
        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 */
 {
        NTSTATUS status;
 
        /* Add TCP/IP sockets */
-       if (lp_interfaces(global_loadparm) && lp_bind_interfaces_only(global_loadparm)) {
-               int num_interfaces = iface_count();
+       if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
+               int num_interfaces;
                int i;
                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++) {
                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, 
                        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(global_loadparm));
+                                                 lp_socket_address(lp_ctx));
                NT_STATUS_NOT_OK_RETURN(status);
        }
 
                NT_STATUS_NOT_OK_RETURN(status);
        }
 
@@ -381,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:
                          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:
 
        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:
 
        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:
 
        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;
 
        default:
                return NT_STATUS_NOT_SUPPORTED;
@@ -414,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,
        task_server_set_title(task, "task[dcesrv]");
 
        status = dcesrv_init_context(task->event_ctx,
-                                    lp_dcerpc_endpoint_servers(global_loadparm),
+                                    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 */
                                     &dce_ctx);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* Make sure the directory for NCALRPC exists */
-       if (!directory_exist(lp_ncalrpc_dir(global_loadparm))) {
-               mkdir(lp_ncalrpc_dir(global_loadparm), 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) {
        }
 
        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;
        }
 
                if (!NT_STATUS_IS_OK(status)) goto failed;
        }
 
@@ -433,19 +457,9 @@ failed:
        task_server_terminate(task, "Failed to startup dcerpc server task");    
 }
 
        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)
 {
 NTSTATUS server_service_rpc_init(void)
 {
-       init_module_fn static_init[] = STATIC_dcerpc_server_MODULES;
+       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);
        init_module_fn *shared_init = load_samba_modules(NULL, global_loadparm, "dcerpc_server");
 
        run_init_functions(static_init);
@@ -453,7 +467,5 @@ NTSTATUS server_service_rpc_init(void)
 
        talloc_free(shared_init);
        
 
        talloc_free(shared_init);
        
-       return register_server_service("rpc", dcesrv_init);
+       return register_server_service("rpc", dcesrv_task_init);
 }
 }
-
-