- move all SMB server stuff to smb_server/*
[gd/samba-autobuild/.git] / source4 / smb_server / sesssetup.c
1 /* 
2    Unix SMB/CIFS implementation.
3    handle SMBsessionsetup
4    Copyright (C) Andrew Tridgell 1998-2001
5    Copyright (C) Andrew Bartlett      2001
6    Copyright (C) Jim McDonough        2002
7    Copyright (C) Luke Howard          2003
8
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25
26 /*
27   setup the OS, Lanman and domain portions of a session setup reply
28 */
29 static void sesssetup_common_strings(struct request_context *req,
30                                      char **os, char **lanman, char **domain)
31 {
32         (*os) = talloc_asprintf(req->mem_ctx, "Unix");
33         (*lanman) = talloc_asprintf(req->mem_ctx, "Samba %s", SAMBA_VERSION_STRING);
34         (*domain) = talloc_asprintf(req->mem_ctx, "%s", lp_workgroup());
35 }
36
37
38 /*
39   handler for old style session setup
40 */
41 static NTSTATUS sesssetup_old(struct request_context *req, union smb_sesssetup *sess)
42 {
43         NTSTATUS status;
44         auth_usersupplied_info *user_info = NULL;
45         auth_serversupplied_info *server_info = NULL;
46         DATA_BLOB null_blob;
47
48         if (!req->smb->negotiate.done_sesssetup) {
49                 req->smb->negotiate.max_send = sess->old.in.bufsize;
50         }
51
52         null_blob.length = 0;
53
54         status = make_user_info_for_reply_enc(&user_info, 
55                                               sess->old.in.user, sess->old.in.domain,
56                                               sess->old.in.password,
57                                               null_blob);
58         if (!NT_STATUS_IS_OK(status)) {
59                 return NT_STATUS_ACCESS_DENIED;
60         }
61
62         status = req->smb->negotiate.auth_context->check_ntlm_password(req->smb->negotiate.auth_context, 
63                                                                        user_info, 
64                                                                        &server_info);
65         if (!NT_STATUS_IS_OK(status)) {
66                 return NT_STATUS_ACCESS_DENIED;
67         }
68
69         sess->old.out.action = 0;
70         sess->old.out.vuid = register_vuid(req->smb, server_info, sess->old.in.user);
71         sesssetup_common_strings(req, 
72                                  &sess->old.out.os,
73                                  &sess->old.out.lanman,
74                                  &sess->old.out.domain);
75
76         return NT_STATUS_OK;
77 }
78
79
80 /*
81   handler for NT1 style session setup
82 */
83 static NTSTATUS sesssetup_nt1(struct request_context *req, union smb_sesssetup *sess)
84 {
85         NTSTATUS status;
86         auth_usersupplied_info *user_info = NULL;
87         auth_serversupplied_info *server_info = NULL;
88
89         if (!req->smb->negotiate.done_sesssetup) {
90                 req->smb->negotiate.max_send = sess->nt1.in.bufsize;
91                 req->smb->negotiate.client_caps = sess->nt1.in.capabilities;
92         }
93
94         status = make_user_info_for_reply_enc(&user_info, 
95                                               sess->nt1.in.user, sess->nt1.in.domain,
96                                               sess->nt1.in.password1,
97                                               sess->nt1.in.password2);
98         if (!NT_STATUS_IS_OK(status)) {
99                 return NT_STATUS_ACCESS_DENIED;
100         }
101
102         status = req->smb->negotiate.auth_context->check_ntlm_password(req->smb->negotiate.auth_context, 
103                                                                        user_info, 
104                                                                        &server_info);
105         if (!NT_STATUS_IS_OK(status)) {
106                 return NT_STATUS_ACCESS_DENIED;
107         }
108
109         sess->nt1.out.action = 0;
110         sess->nt1.out.vuid = register_vuid(req->smb, server_info, sess->old.in.user);
111         sesssetup_common_strings(req, 
112                                  &sess->nt1.out.os,
113                                  &sess->nt1.out.lanman,
114                                  &sess->nt1.out.domain);
115
116         return NT_STATUS_OK;
117 }
118
119
120 /*
121   handler for SPNEGO style session setup
122 */
123 static NTSTATUS sesssetup_spnego(struct request_context *req, union smb_sesssetup *sess)
124 {
125         /* defer this one for now */
126         return NT_STATUS_INVALID_LEVEL;
127 }
128
129 /*
130   backend for sessionsetup call - this takes all 3 varients of the call
131 */
132 NTSTATUS sesssetup_backend(struct request_context *req, 
133                            union smb_sesssetup *sess)
134 {
135         switch (sess->generic.level) {
136                 case RAW_SESSSETUP_OLD:
137                         return sesssetup_old(req, sess);
138                 case RAW_SESSSETUP_NT1:
139                         return sesssetup_nt1(req, sess);
140                 case RAW_SESSSETUP_SPNEGO:
141                         return sesssetup_spnego(req, sess);
142         }
143
144         req->smb->negotiate.done_sesssetup = True;
145
146         return NT_STATUS_INVALID_LEVEL;
147 }
148
149