Remove useless layer of indirection, where every service called
[jelmer/samba4-debian.git] / source / winbind / wb_server.c
index a08b0803342ff94079d7a7a178f71bdd3a7c33e9..9b303f36158f32507e69ef5d3bbad7b07cb588c1 100644 (file)
@@ -7,7 +7,7 @@
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "lib/socket/socket.h"
-#include "dlinklist.h"
+#include "lib/util/dlinklist.h"
 #include "lib/events/events.h"
 #include "smbd/service_task.h"
+#include "smbd/process_model.h"
 #include "smbd/service_stream.h"
 #include "nsswitch/winbind_nss_config.h"
 #include "winbind/wb_server.h"
 #include "lib/stream/packet.h"
+#include "smbd/service.h"
+#include "param/secrets.h"
+#include "param/param.h"
 
 void wbsrv_terminate_connection(struct wbsrv_connection *wbconn, const char *reason)
 {
@@ -57,6 +60,7 @@ static void wbsrv_accept(struct stream_connection *conn)
        }
        wbconn->conn          = conn;
        wbconn->listen_socket = listen_socket;
+       wbconn->lp_ctx        = listen_socket->service->task->lp_ctx;
        conn->private         = wbconn;
 
        wbconn->packet = packet_init(wbconn);
@@ -113,6 +117,8 @@ static void winbind_task_init(struct task_server *task)
        struct wbsrv_service *service;
        struct wbsrv_listen_socket *listen_socket;
 
+       task_server_set_title(task, "task[winbind]");
+
        /* within the winbind task we want to be a single process, so
           ask for the single process model ops and pass these to the
           stream_setup_socket() call. */
@@ -123,9 +129,11 @@ static void winbind_task_init(struct task_server *task)
                return;
        }
 
-       /* Make sure the directory for NCALRPC exists */
-       if (!directory_exist(WINBINDD_DIR)) {
-               mkdir(WINBINDD_DIR, 0755);
+       /* Make sure the directory for the Samba3 socket exists, and is of the correct permissions */
+       if (!directory_create_or_exist(lp_winbindd_socket_directory(task->lp_ctx), geteuid(), 0755)) {
+               task_server_terminate(task,
+                                     "Cannot create winbindd pipe directory");
+               return;
        }
 
        service = talloc_zero(task, struct wbsrv_service);
@@ -133,7 +141,8 @@ static void winbind_task_init(struct task_server *task)
        service->task   = task;
 
        service->primary_sid = secrets_get_domain_sid(service,
-                                                     lp_workgroup());
+                                                     task->lp_ctx,
+                                                     lp_workgroup(task->lp_ctx));
        if (service->primary_sid == NULL) {
                task_server_terminate(
                        task, nt_errstr(NT_STATUS_CANT_ACCESS_DOMAIN_INFO));
@@ -143,13 +152,16 @@ static void winbind_task_init(struct task_server *task)
        /* setup the unprivileged samba3 socket */
        listen_socket = talloc(service, struct wbsrv_listen_socket);
        if (!listen_socket) goto nomem;
-       listen_socket->socket_path      = WINBINDD_SAMBA3_SOCKET;
+       listen_socket->socket_path      = talloc_asprintf(listen_socket, "%s/%s", 
+                                                         lp_winbindd_socket_directory(task->lp_ctx), 
+                                                         WINBINDD_SAMBA3_SOCKET);
        if (!listen_socket->socket_path) goto nomem;
        listen_socket->service          = service;
-       listen_socket->privileged       = False;
-       status = stream_setup_socket(task->event_ctx, model_ops,
+       listen_socket->privileged       = false;
+       status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
                                     &wbsrv_ops, "unix",
                                     listen_socket->socket_path, &port,
+                                    lp_socket_options(task->lp_ctx), 
                                     listen_socket);
        if (!NT_STATUS_IS_OK(status)) goto listen_failed;
 
@@ -157,17 +169,21 @@ static void winbind_task_init(struct task_server *task)
        listen_socket = talloc(service, struct wbsrv_listen_socket);
        if (!listen_socket) goto nomem;
        listen_socket->socket_path      =
-               smbd_tmp_path(listen_socket,
+               smbd_tmp_path(listen_socket, task->lp_ctx, 
                              WINBINDD_SAMBA3_PRIVILEGED_SOCKET);
        if (!listen_socket->socket_path) goto nomem;
        listen_socket->service          = service;
-       listen_socket->privileged       = True;
-       status = stream_setup_socket(task->event_ctx, model_ops,
+       listen_socket->privileged       = true;
+       status = stream_setup_socket(task->event_ctx, task->lp_ctx, model_ops,
                                     &wbsrv_ops, "unix",
                                     listen_socket->socket_path, &port,
+                                    lp_socket_options(task->lp_ctx), 
                                     listen_socket);
        if (!NT_STATUS_IS_OK(status)) goto listen_failed;
 
+       status = wbsrv_init_irpc(service);
+       if (!NT_STATUS_IS_OK(status)) goto irpc_failed;
+
        return;
 
 listen_failed:
@@ -175,24 +191,20 @@ listen_failed:
                 listen_socket->socket_path, nt_errstr(status)));
        task_server_terminate(task, nt_errstr(status));
        return;
+irpc_failed:
+       DEBUG(0,("wbsrv_init_irpc() failed - %s\n",
+                nt_errstr(status)));
+       task_server_terminate(task, nt_errstr(status));
+       return;
 nomem:
        task_server_terminate(task, nt_errstr(NT_STATUS_NO_MEMORY));
        return;
 }
 
-/*
-  initialise the winbind server
- */
-static NTSTATUS winbind_init(struct event_context *event_ctx,
-                            const struct model_ops *model_ops)
-{
-       return task_server_startup(event_ctx, model_ops, winbind_task_init);
-}
-
 /*
   register ourselves as a available server
 */
 NTSTATUS server_service_winbind_init(void)
 {
-       return register_server_service("winbind", winbind_init);
+       return register_server_service("winbind", winbind_task_init);
 }