2 Unix SMB/CIFS implementation.
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
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.
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.
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.
27 setup the OS, Lanman and domain portions of a session setup reply
29 static void sesssetup_common_strings(struct request_context *req,
30 char **os, char **lanman, char **domain)
32 (*os) = talloc_asprintf(req->mem_ctx, "Unix");
33 (*lanman) = talloc_asprintf(req->mem_ctx, "Samba %s", SAMBA_VERSION);
34 (*domain) = talloc_asprintf(req->mem_ctx, "%s", lp_workgroup());
39 handler for old style session setup
41 static NTSTATUS sesssetup_old(struct request_context *req, union smb_sesssetup *sess)
44 auth_usersupplied_info *user_info = NULL;
45 auth_serversupplied_info *server_info = NULL;
48 if (!req->smb->negotiate.done_sesssetup) {
49 req->smb->negotiate.max_send = sess->old.in.bufsize;
54 status = make_user_info_for_reply_enc(&user_info,
55 sess->old.in.user, sess->old.in.domain,
56 sess->old.in.password,
58 if (!NT_STATUS_IS_OK(status)) {
59 return NT_STATUS_ACCESS_DENIED;
62 status = req->smb->negotiate.auth_context->check_ntlm_password(req->smb->negotiate.auth_context,
65 if (!NT_STATUS_IS_OK(status)) {
66 return NT_STATUS_ACCESS_DENIED;
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,
73 &sess->old.out.lanman,
74 &sess->old.out.domain);
81 handler for NT1 style session setup
83 static NTSTATUS sesssetup_nt1(struct request_context *req, union smb_sesssetup *sess)
86 auth_usersupplied_info *user_info = NULL;
87 auth_serversupplied_info *server_info = NULL;
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;
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;
102 status = req->smb->negotiate.auth_context->check_ntlm_password(req->smb->negotiate.auth_context,
105 if (!NT_STATUS_IS_OK(status)) {
106 return NT_STATUS_ACCESS_DENIED;
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,
113 &sess->nt1.out.lanman,
114 &sess->nt1.out.domain);
121 handler for SPNEGO style session setup
123 static NTSTATUS sesssetup_spnego(struct request_context *req, union smb_sesssetup *sess)
125 /* defer this one for now */
126 return NT_STATUS_INVALID_LEVEL;
130 backend for sessionsetup call - this takes all 3 varients of the call
132 NTSTATUS sesssetup_backend(struct request_context *req,
133 union smb_sesssetup *sess)
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);
144 req->smb->negotiate.done_sesssetup = True;
146 return NT_STATUS_INVALID_LEVEL;