r26268: Avoid more use of global_loadparm - put lp_ctx in smb_server and wbsrv_connec...
[kai/samba-autobuild/.git] / source4 / smb_server / smb / sesssetup.c
index 25655fc14f05c0afa33e6094091d8a575bd2f0e0..de2141b8086d2595f42f9c8a8826939e3cf4837e 100644 (file)
@@ -10,7 +10,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 "version.h"
+#include "auth/credentials/credentials.h"
+#include "auth/gensec/gensec.h"
 #include "auth/auth.h"
 #include "smb_server/smb_server.h"
 #include "smbd/service_stream.h"
 #include "librpc/gen_ndr/nbt.h"
+#include "param/param.h"
 
 /*
   setup the OS, Lanman and domain portions of a session setup reply
@@ -38,7 +40,8 @@ static void sesssetup_common_strings(struct smbsrv_request *req,
 {
        (*os) = talloc_asprintf(req, "Unix");
        (*lanman) = talloc_asprintf(req, "Samba %s", SAMBA_VERSION_STRING);
-       (*domain) = talloc_asprintf(req, "%s", lp_workgroup());
+       (*domain) = talloc_asprintf(req, "%s", 
+                                   lp_workgroup(req->smb_conn->lp_ctx));
 }
 
 static void smbsrv_sesssetup_backend_send(struct smbsrv_request *req,
@@ -46,7 +49,9 @@ static void smbsrv_sesssetup_backend_send(struct smbsrv_request *req,
                                          NTSTATUS status)
 {
        if (NT_STATUS_IS_OK(status)) {
-               req->smb_conn->negotiate.done_sesssetup = True;
+               req->smb_conn->negotiate.done_sesssetup = true;
+               /* we need to keep the session long term */
+               req->session = talloc_steal(req->smb_conn, req->session);
        }
        smbsrv_reply_sesssetup_send(req, sess, status);
 }
@@ -65,11 +70,12 @@ static void sesssetup_old_send(struct auth_check_password_request *areq,
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* This references server_info into session_info */
-       status = auth_generate_session_info(req, server_info, &session_info);
+       status = auth_generate_session_info(req, req->smb_conn->lp_ctx, 
+                                           server_info, &session_info);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* allocate a new session */
-       smb_sess = smbsrv_session_new(req->smb_conn, NULL);
+       smb_sess = smbsrv_session_new(req->smb_conn, req, NULL);
        if (!smb_sess) {
                status = NT_STATUS_INSUFFICIENT_RESOURCES;
                goto failed;
@@ -125,7 +131,7 @@ static void sesssetup_old(struct smbsrv_request *req, union smb_sesssetup *sess)
        user_info = talloc(req, struct auth_usersupplied_info);
        if (!user_info) goto nomem;
        
-       user_info->mapped_state = False;
+       user_info->mapped_state = false;
        user_info->logon_parameters = 0;
        user_info->flags = 0;
        user_info->client.account_name = sess->old.in.user;
@@ -160,11 +166,12 @@ static void sesssetup_nt1_send(struct auth_check_password_request *areq,
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* This references server_info into session_info */
-       status = auth_generate_session_info(req, server_info, &session_info);
+       status = auth_generate_session_info(req, req->smb_conn->lp_ctx, 
+                                           server_info, &session_info);
        if (!NT_STATUS_IS_OK(status)) goto failed;
 
        /* allocate a new session */
-       smb_sess = smbsrv_session_new(req->smb_conn, NULL);
+       smb_sess = smbsrv_session_new(req->smb_conn, req, NULL);
        if (!smb_sess) {
                status = NT_STATUS_INSUFFICIENT_RESOURCES;
                goto failed;
@@ -239,9 +246,10 @@ static void sesssetup_nt1(struct smbsrv_request *req, union smb_sesssetup *sess)
                }
 
                /* TODO: should we use just "anonymous" here? */
-               status = auth_context_create(req, lp_auth_methods(), 
+               status = auth_context_create(req, 
                                             req->smb_conn->connection->event.ctx,
                                             req->smb_conn->connection->msg_ctx,
+                                            req->smb_conn->lp_ctx,
                                             &auth_context);
                if (!NT_STATUS_IS_OK(status)) goto failed;
        } else {
@@ -262,7 +270,7 @@ static void sesssetup_nt1(struct smbsrv_request *req, union smb_sesssetup *sess)
        user_info = talloc(req, struct auth_usersupplied_info);
        if (!user_info) goto nomem;
 
-       user_info->mapped_state = False;
+       user_info->mapped_state = false;
        user_info->logon_parameters = 0;
        user_info->flags = 0;
        user_info->client.account_name = sess->nt1.in.user;
@@ -337,6 +345,10 @@ done:
 failed:
        status = auth_nt_status_squash(status);
        smbsrv_sesssetup_backend_send(req, sess, status);
+       if (!NT_STATUS_IS_OK(status) && 
+           !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+               talloc_free(smb_sess);
+       }
 }
 
 /*
@@ -371,6 +383,7 @@ static void sesssetup_spnego(struct smbsrv_request *req, union smb_sesssetup *se
 
                status = gensec_server_start(req,
                                             req->smb_conn->connection->event.ctx,
+                                            req->smb_conn->lp_ctx,
                                             req->smb_conn->connection->msg_ctx,
                                             &gensec_ctx);
                if (!NT_STATUS_IS_OK(status)) {
@@ -392,7 +405,7 @@ static void sesssetup_spnego(struct smbsrv_request *req, union smb_sesssetup *se
                }
 
                /* allocate a new session */
-               smb_sess = smbsrv_session_new(req->smb_conn, gensec_ctx);
+               smb_sess = smbsrv_session_new(req->smb_conn, req->smb_conn, gensec_ctx);
                if (!smb_sess) {
                        status = NT_STATUS_INSUFFICIENT_RESOURCES;
                        goto failed;