auth: Add SID_NT_NTLM_AUTHENTICATION / S-1-5-64-10 to the token during NTLM auth
[vlendec/samba-autobuild/.git] / auth / common_auth.h
1 /*
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett 2001-2010
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef AUTH_COMMON_AUTH_H
21 #define AUTH_COMMON_AUTH_H
22
23 #include "librpc/gen_ndr/auth.h"
24
25 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
26 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
27 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT   0x04 /* don't check unix account status */
28 #define USER_INFO_INTERACTIVE_LOGON         0x08 /* Interactive logon */
29 /*unused #define USER_INFO_LOCAL_SAM_ONLY   0x10    Only authenticate against the local SAM, do not map missing passwords to NO_SUCH_USER */
30 #define USER_INFO_INFO3_AND_NO_AUTHZ        0x20 /* Only fill in server_info->info3 and do not do any authorization steps */
31
32 enum auth_password_state {
33         AUTH_PASSWORD_PLAIN = 1,
34         AUTH_PASSWORD_HASH = 2,
35         AUTH_PASSWORD_RESPONSE = 3
36 };
37
38 #define AUTH_SESSION_INFO_DEFAULT_GROUPS     0x01 /* Add the user to the default world and network groups */
39 #define AUTH_SESSION_INFO_AUTHENTICATED      0x02 /* Add the user to the 'authenticated users' group */
40 #define AUTH_SESSION_INFO_SIMPLE_PRIVILEGES  0x04 /* Use a trivial map between users and privilages, rather than a DB */
41 #define AUTH_SESSION_INFO_UNIX_TOKEN         0x08 /* The returned token must have the unix_token and unix_info elements provided */
42 #define AUTH_SESSION_INFO_NTLM               0x10 /* The returned token must have authenticated-with-NTLM flag set */
43
44 struct auth_usersupplied_info
45 {
46         const char *workstation_name;
47         const struct tsocket_address *remote_host;
48
49         uint32_t logon_parameters;
50
51         bool mapped_state;
52         bool was_mapped;
53         /* the values the client gives us */
54         struct {
55                 const char *account_name;
56                 const char *domain_name;
57         } client, mapped;
58
59         enum auth_password_state password_state;
60
61         struct {
62                 struct {
63                         DATA_BLOB lanman;
64                         DATA_BLOB nt;
65                 } response;
66                 struct {
67                         struct samr_Password *lanman;
68                         struct samr_Password *nt;
69                 } hash;
70
71                 char *plaintext;
72         } password;
73         uint32_t flags;
74 };
75
76 struct auth_method_context;
77 struct tevent_context;
78 struct imessaging_context;
79 struct loadparm_context;
80 struct ldb_context;
81 struct smb_krb5_context;
82
83 struct auth4_context {
84         struct {
85                 /* Who set this up in the first place? */
86                 const char *set_by;
87
88                 DATA_BLOB data;
89         } challenge;
90
91         /* methods, in the order they should be called */
92         struct auth_method_context *methods;
93
94         /* the event context to use for calls that can block */
95         struct tevent_context *event_ctx;
96
97         /* the messaging context which can be used by backends */
98         struct imessaging_context *msg_ctx;
99
100         /* loadparm context */
101         struct loadparm_context *lp_ctx;
102
103         /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
104         struct ldb_context *sam_ctx;
105
106         /* Private data for the callbacks on this auth context */
107         void *private_data;
108
109         NTSTATUS (*check_ntlm_password)(struct auth4_context *auth_ctx,
110                                         TALLOC_CTX *mem_ctx,
111                                         const struct auth_usersupplied_info *user_info,
112                                         uint8_t *pauthoritative,
113                                         void **server_returned_info,
114                                         DATA_BLOB *nt_session_key, DATA_BLOB *lm_session_key);
115
116         NTSTATUS (*get_ntlm_challenge)(struct auth4_context *auth_ctx, uint8_t chal[8]);
117
118         NTSTATUS (*set_ntlm_challenge)(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
119
120         NTSTATUS (*generate_session_info)(struct auth4_context *auth_context,
121                                           TALLOC_CTX *mem_ctx,
122                                           void *server_returned_info,
123                                           const char *original_user_name,
124                                           uint32_t session_info_flags,
125                                           struct auth_session_info **session_info);
126
127         NTSTATUS (*generate_session_info_pac)(struct auth4_context *auth_ctx,
128                                               TALLOC_CTX *mem_ctx,
129                                               struct smb_krb5_context *smb_krb5_context,
130                                               DATA_BLOB *pac_blob,
131                                               const char *principal_name,
132                                               const struct tsocket_address *remote_address,
133                                               uint32_t session_info_flags,
134                                               struct auth_session_info **session_info);
135 };
136
137 #endif