03206c03c6a894822936f2fa5f7a177e9b814f7b
[tprouty/samba.git] / source / 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         int len;
26         char *str;
27 } AUTH_STR;
28
29 typedef struct auth_usersupplied_info {
30         DATA_BLOB lm_resp;
31         DATA_BLOB nt_resp;
32         DATA_BLOB lm_interactive_pwd;
33         DATA_BLOB nt_interactive_pwd;
34         DATA_BLOB plaintext_password;
35         
36         BOOL encrypted;
37         
38         AUTH_STR           client_domain;          /* domain name string */
39         AUTH_STR           domain;               /* domain name after mapping */
40         AUTH_STR           internal_username;    /* username after mapping */
41         AUTH_STR           smb_name;        /* username before mapping */
42         AUTH_STR           wksta_name;           /* workstation name (netbios calling name) unicode string */
43         
44         uint32 logon_parameters;
45
46 } auth_usersupplied_info;
47
48 #define SAM_FILL_NAME  0x01
49 #define SAM_FILL_INFO3 0x02
50 #define SAM_FILL_SAM   0x04
51 #define SAM_FILL_UNIX  0x08
52 #define SAM_FILL_ALL (SAM_FILL_NAME | SAM_FILL_INFO3 | SAM_FILL_SAM | SAM_FILL_UNIX)
53
54 typedef struct auth_serversupplied_info {
55         BOOL guest;
56
57         uid_t uid;
58         gid_t gid;
59         
60         /* This groups info is needed for when we become_user() for this uid */
61         size_t n_groups;
62         gid_t *groups;
63         
64         /* NT group information taken from the info3 structure */
65         
66         NT_USER_TOKEN *ptok;
67         
68         DATA_BLOB user_session_key;
69         DATA_BLOB lm_session_key;
70
71         char *login_server; /* which server authorized the login? */
72         
73         uint32 sam_fill_level;  /* How far is this structure filled? */
74         
75         SAM_ACCOUNT *sam_account;
76         
77         void *pam_handle;
78
79         char *unix_name;
80         
81 } auth_serversupplied_info;
82
83 struct auth_context {
84         DATA_BLOB challenge; 
85
86         /* Who set this up in the first place? */ 
87         const char *challenge_set_by; 
88
89         BOOL challenge_may_be_modified;
90
91         struct auth_methods *challenge_set_method; 
92         /* What order are the various methods in?   Try to stop it changing under us */ 
93         struct auth_methods *auth_method_list;  
94
95         TALLOC_CTX *mem_ctx;
96         const uint8 *(*get_ntlm_challenge)(struct auth_context *auth_context);
97         NTSTATUS (*check_ntlm_password)(const struct auth_context *auth_context,
98                                         const struct auth_usersupplied_info *user_info, 
99                                         struct auth_serversupplied_info **server_info);
100         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
101         void (*free)(struct auth_context **auth_context);
102 };
103
104 typedef struct auth_methods
105 {
106         struct auth_methods *prev, *next;
107         const char *name; /* What name got this module */
108
109         NTSTATUS (*auth)(const struct auth_context *auth_context,
110                          void *my_private_data, 
111                          TALLOC_CTX *mem_ctx,
112                          const struct auth_usersupplied_info *user_info, 
113                          auth_serversupplied_info **server_info);
114
115         /* If you are using this interface, then you are probably
116          * getting something wrong.  This interface is only for
117          * security=server, and makes a number of compromises to allow
118          * that.  It is not compatible with being a PDC.  */
119         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
120                               void **my_private_data, 
121                               TALLOC_CTX *mem_ctx);
122         
123         /* Used to keep tabs on things like the cli for SMB server authentication */
124         void *private_data;
125         
126         /* Function to clean up the above arbitary structure */
127         void (*free_private_data)(void **private_data);
128
129         /* Function to send a keepalive message on the above structure */
130         void (*send_keepalive)(void **private_data);
131
132 } auth_methods;
133
134 typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
135
136 struct auth_init_function_entry {
137         const char *name;
138         /* Function to create a member of the authmethods list */
139
140         auth_init_function init;
141
142         struct auth_init_function_entry *prev, *next;
143 };
144
145 typedef struct auth_ntlmssp_state {
146         TALLOC_CTX *mem_ctx;
147         struct auth_context *auth_context;
148         struct auth_serversupplied_info *server_info;
149         struct ntlmssp_state *ntlmssp_state;
150 } AUTH_NTLMSSP_STATE;
151
152 /* Changed from 1 -> 2 to add the logon_parameters field. */
153 #define AUTH_INTERFACE_VERSION 2
154
155 #endif /* _SMBAUTH_H_ */