Use "unix netbios name" type unstring - 64 bytes long to manipulate netbios
[jra/samba/.git] / source3 / include / auth.h
1 #ifndef _SMBAUTH_H_
2 #define _SMBAUTH_H_
3 /* 
4    Unix SMB/CIFS implementation.
5    Standardised Authentication types
6    Copyright (C) Andrew Bartlett 2001
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /* AUTH_STR - string */
24 typedef struct normal_string
25 {
26         int len;
27         char *str;
28 } AUTH_STR;
29
30 /* AUTH_UNISTR - unicode string or buffer */
31 typedef struct unicode_string
32 {
33         int len;
34         uchar *unistr;
35 } AUTH_UNISTR;
36
37 typedef struct interactive_password
38 {
39         OWF_INFO          lm_owf;              /* LM OWF Password */
40         OWF_INFO          nt_owf;              /* NT OWF Password */
41 } auth_interactive_password;
42
43 #define AUTH_FLAG_NONE        0x000000
44 #define AUTH_FLAG_PLAINTEXT   0x000001
45 #define AUTH_FLAG_LM_RESP     0x000002
46 #define AUTH_FLAG_NTLM_RESP   0x000004
47 #define AUTH_FLAG_NTLMv2_RESP 0x000008
48
49 typedef struct auth_usersupplied_info
50 {
51         
52         DATA_BLOB lm_resp;
53         DATA_BLOB nt_resp;
54         auth_interactive_password * interactive_password;
55         DATA_BLOB plaintext_password;
56         
57         BOOL encrypted;
58         
59         uint32 auth_flags;
60
61         AUTH_STR           client_domain;          /* domain name string */
62         AUTH_STR           domain;               /* domain name after mapping */
63         AUTH_STR           internal_username;    /* username after mapping */
64         AUTH_STR           smb_name;        /* username before mapping */
65         AUTH_STR           wksta_name;           /* workstation name (netbios calling name) unicode string */
66         
67 } auth_usersupplied_info;
68
69 #define SAM_FILL_NAME  0x01
70 #define SAM_FILL_INFO3 0x02
71 #define SAM_FILL_SAM   0x04
72 #define SAM_FILL_UNIX  0x08
73 #define SAM_FILL_ALL (SAM_FILL_NAME | SAM_FILL_INFO3 | SAM_FILL_SAM | SAM_FILL_UNIX)
74
75 typedef struct auth_serversupplied_info 
76 {
77         BOOL guest;
78
79         uid_t uid;
80         gid_t gid;
81         
82         /* This groups info is needed for when we become_user() for this uid */
83         int n_groups;
84         gid_t *groups;
85         
86         /* NT group information taken from the info3 structure */
87         
88         NT_USER_TOKEN *ptok;
89         PRIVILEGE_SET *privs;
90         
91         DATA_BLOB nt_session_key;
92         DATA_BLOB lm_session_key;
93         
94         uint32 sam_fill_level;  /* How far is this structure filled? */
95         
96         SAM_ACCOUNT *sam_account;
97         
98         void *pam_handle;
99
100         char *unix_name;
101         
102 } auth_serversupplied_info;
103
104 struct auth_context {
105         DATA_BLOB challenge; 
106
107         /* Who set this up in the first place? */ 
108         const char *challenge_set_by; 
109
110         BOOL challenge_may_be_modified;
111
112         struct auth_methods *challenge_set_method; 
113         /* What order are the various methods in?   Try to stop it changing under us */ 
114         struct auth_methods *auth_method_list;  
115
116         TALLOC_CTX *mem_ctx;
117         const uint8 *(*get_ntlm_challenge)(struct auth_context *auth_context);
118         NTSTATUS (*check_ntlm_password)(const struct auth_context *auth_context,
119                                         const struct auth_usersupplied_info *user_info, 
120                                         struct auth_serversupplied_info **server_info);
121         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
122         void (*free)(struct auth_context **auth_context);
123 };
124
125 typedef struct auth_methods
126 {
127         struct auth_methods *prev, *next;
128         const char *name; /* What name got this module */
129
130         NTSTATUS (*auth)(const struct auth_context *auth_context,
131                          void *my_private_data, 
132                          TALLOC_CTX *mem_ctx,
133                          const struct auth_usersupplied_info *user_info, 
134                          auth_serversupplied_info **server_info);
135
136         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
137                               void **my_private_data, 
138                               TALLOC_CTX *mem_ctx);
139         
140         /* Used to keep tabs on things like the cli for SMB server authentication */
141         void *private_data;
142         
143         /* Function to clean up the above arbitary structure */
144         void (*free_private_data)(void **private_data);
145
146         /* Function to send a keepalive message on the above structure */
147         void (*send_keepalive)(void **private_data);
148
149 } auth_methods;
150
151 typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
152
153 struct auth_init_function_entry {
154         const char *name;
155         /* Function to create a member of the authmethods list */
156
157         auth_init_function init;
158
159         struct auth_init_function_entry *prev, *next;
160 };
161
162 typedef struct auth_ntlmssp_state
163 {
164         TALLOC_CTX *mem_ctx;
165         struct auth_context *auth_context;
166         struct auth_serversupplied_info *server_info;
167         struct ntlmssp_state *ntlmssp_state;
168 } AUTH_NTLMSSP_STATE;
169
170 #define AUTH_INTERFACE_VERSION 1
171
172 #endif /* _SMBAUTH_H_ */