Remove useless layer of indirection, where every service called
[jelmer/samba4-debian.git] / source / smb_server / smb_server.c
index 923c1bdfe5e511e920af2151bf9bde8decd9b3c1..9a8a8cf5c4643d0b18041f001acc84fcf7880faa 100644 (file)
@@ -42,7 +42,7 @@ static NTSTATUS smbsrv_recv_generic_request(void *private, DATA_BLOB blob)
 
        /* see if its a special NBT packet */
        if (CVAL(blob.data,0) != 0) {
-               status = smbsrv_init_smb_connection(smb_conn, global_loadparm);
+               status = smbsrv_init_smb_connection(smb_conn, smb_conn->lp_ctx);
                NT_STATUS_NOT_OK_RETURN(status);
                packet_set_callback(smb_conn->packet, smbsrv_recv_smb_request);
                return smbsrv_recv_smb_request(smb_conn, blob);
@@ -58,12 +58,12 @@ static NTSTATUS smbsrv_recv_generic_request(void *private, DATA_BLOB blob)
 
        switch (protocol_version) {
        case SMB_MAGIC:
-               status = smbsrv_init_smb_connection(smb_conn, global_loadparm);
+               status = smbsrv_init_smb_connection(smb_conn, smb_conn->lp_ctx);
                NT_STATUS_NOT_OK_RETURN(status);
                packet_set_callback(smb_conn->packet, smbsrv_recv_smb_request);
                return smbsrv_recv_smb_request(smb_conn, blob);
        case SMB2_MAGIC:
-               if (lp_srv_maxprotocol(global_loadparm) < PROTOCOL_SMB2) break;
+               if (lp_srv_maxprotocol(smb_conn->lp_ctx) < PROTOCOL_SMB2) break;
                status = smbsrv_init_smb2_connection(smb_conn);
                NT_STATUS_NOT_OK_RETURN(status);
                packet_set_callback(smb_conn->packet, smbsrv_recv_smb2_request);
@@ -94,9 +94,6 @@ static void smbsrv_recv(struct stream_connection *conn, uint16_t flags)
        DEBUG(10,("smbsrv_recv\n"));
 
        packet_recv(smb_conn->packet);
-
-       /* free up temporary memory */
-       lp_talloc_free();
 }
 
 /*
@@ -149,6 +146,7 @@ static void smbsrv_accept(struct stream_connection *conn)
        packet_set_fde(smb_conn->packet, conn->event.fde);
        packet_set_serialise(smb_conn->packet);
 
+       smb_conn->lp_ctx = global_loadparm;
        smb_conn->connection = conn;
        conn->private = smb_conn;
 
@@ -158,7 +156,8 @@ static void smbsrv_accept(struct stream_connection *conn)
 
        smbsrv_management_init(smb_conn);
 
-       if (!NT_STATUS_IS_OK(share_get_context(smb_conn, &(smb_conn->share_context)))) {
+       if (!NT_STATUS_IS_OK(share_get_context_by_name(smb_conn, lp_share_backend(smb_conn->lp_ctx), 
+                                                      smb_conn->lp_ctx, &(smb_conn->share_context)))) {
                smbsrv_terminate_connection(smb_conn, "share_init failed!");
                return;
        }
@@ -175,18 +174,22 @@ static const struct stream_server_ops smb_stream_ops = {
   setup a listening socket on all the SMB ports for a particular address
 */
 _PUBLIC_ NTSTATUS smbsrv_add_socket(struct event_context *event_context,
+                                   struct loadparm_context *lp_ctx,
                               const struct model_ops *model_ops,
                               const char *address)
 {
-       const char **ports = lp_smb_ports(global_loadparm);
+       const char **ports = lp_smb_ports(lp_ctx);
        int i;
        NTSTATUS status;
 
        for (i=0;ports[i];i++) {
                uint16_t port = atoi(ports[i]);
                if (port == 0) continue;
-               status = stream_setup_socket(event_context, model_ops, &smb_stream_ops, 
-                                            "ipv4", address, &port, NULL);
+               status = stream_setup_socket(event_context, lp_ctx, 
+                                            model_ops, &smb_stream_ops, 
+                                            "ipv4", address, &port, 
+                                            lp_socket_options(lp_ctx), 
+                                            NULL);
                NT_STATUS_NOT_OK_RETURN(status);
        }
 
@@ -203,7 +206,7 @@ static void smbsrv_preopen_ldb(struct task_server *task)
        /* yes, this looks strange. It is a hack to preload the
           schema. I'd like to share most of the ldb context with the
           child too. That will come later */
-       talloc_free(samdb_connect(task, global_loadparm, NULL));
+       talloc_free(samdb_connect(task, task->lp_ctx, NULL));
 }
 
 /*
@@ -215,23 +218,28 @@ static void smbsrv_task_init(struct task_server *task)
 
        task_server_set_title(task, "task[smbsrv]");
 
-       if (lp_interfaces(global_loadparm) && lp_bind_interfaces_only(global_loadparm)) {
-               int num_interfaces = iface_count();
+       if (lp_interfaces(task->lp_ctx) && lp_bind_interfaces_only(task->lp_ctx)) {
+               int num_interfaces;
                int i;
+               struct interface *ifaces;
+
+               load_interfaces(task, lp_interfaces(task->lp_ctx), &ifaces);
+
+               num_interfaces = iface_count(ifaces);
 
                /* We have been given an interfaces line, and been 
                   told to only bind to those interfaces. Create a
                   socket per interface and bind to only these.
                */
                for(i = 0; i < num_interfaces; i++) {
-                       const char *address = iface_n_ip(i);
-                       status = smbsrv_add_socket(task->event_ctx, task->model_ops, address);
+                       const char *address = iface_n_ip(ifaces, i);
+                       status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops, address);
                        if (!NT_STATUS_IS_OK(status)) goto failed;
                }
        } else {
                /* Just bind to lp_socket_address() (usually 0.0.0.0) */
-               status = smbsrv_add_socket(task->event_ctx, task->model_ops, 
-                                          lp_socket_address(global_loadparm));
+               status = smbsrv_add_socket(task->event_ctx, task->lp_ctx, task->model_ops, 
+                                          lp_socket_address(task->lp_ctx));
                if (!NT_STATUS_IS_OK(status)) goto failed;
        }
 
@@ -242,18 +250,8 @@ failed:
        task_server_terminate(task, "Failed to startup smb server task");       
 }
 
-/*
-  called on startup of the smb server service It's job is to start
-  listening on all configured sockets
-*/
-static NTSTATUS smbsrv_init(struct event_context *event_context, 
-                           const struct model_ops *model_ops)
-{      
-       return task_server_startup(event_context, model_ops, smbsrv_task_init);
-}
-
 /* called at smbd startup - register ourselves as a server service */
 NTSTATUS server_service_smb_init(void)
 {
-       return register_server_service("smb", smbsrv_init);
+       return register_server_service("smb", smbsrv_task_init);
 }