Kill off another ugly wart from the side of the passdb subsystem.
[bbaumbach/samba-autobuild/.git] / source / include / auth.h
1 #ifndef _SMBAUTH_H_
2 #define _SMBAUTH_H_
3 /* 
4    Unix SMB/Netbios implementation.
5    Version 2.2
6    Standardised Authentication types
7    Copyright (C) Andrew Bartlett 2001
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 /* AUTH_STR - string */
25 typedef struct normal_string
26 {
27         int len;
28         char *str;
29 } AUTH_STR;
30
31 /* AUTH_UNISTR - unicode string or buffer */
32 typedef struct unicode_string
33 {
34         int len;
35         uchar *unistr;
36 } AUTH_UNISTR;
37
38 typedef struct interactive_password
39 {
40         OWF_INFO          lm_owf;              /* LM OWF Password */
41         OWF_INFO          nt_owf;              /* NT OWF Password */
42 } auth_interactive_password;
43
44 #define AUTH_FLAG_NONE        0x000000
45 #define AUTH_FLAG_PLAINTEXT   0x000001
46 #define AUTH_FLAG_LM_RESP     0x000002
47 #define AUTH_FLAG_NTLM_RESP   0x000004
48 #define AUTH_FLAG_NTLMv2_RESP 0x000008
49
50 typedef struct auth_usersupplied_info
51 {
52         
53         DATA_BLOB lm_resp;
54         DATA_BLOB nt_resp;
55         auth_interactive_password * interactive_password;
56         DATA_BLOB plaintext_password;
57         
58         BOOL encrypted;
59         
60         uint32 auth_flags;
61
62         AUTH_STR           client_domain;          /* domain name string */
63         AUTH_STR           domain;               /* domain name after mapping */
64         AUTH_STR           internal_username;    /* username after mapping */
65         AUTH_STR           smb_name;        /* username before mapping */
66         AUTH_STR           wksta_name;           /* workstation name (netbios calling name) unicode string */
67         
68 } auth_usersupplied_info;
69
70 #define SAM_FILL_NAME  0x01
71 #define SAM_FILL_INFO3 0x02
72 #define SAM_FILL_SAM   0x04
73 #define SAM_FILL_UNIX  0x08
74 #define SAM_FILL_ALL (SAM_FILL_NAME | SAM_FILL_INFO3 | SAM_FILL_SAM | SAM_FILL_UNIX)
75
76 typedef struct auth_serversupplied_info 
77 {
78         BOOL guest;
79         
80         /* This groups info is needed for when we become_user() for this uid */
81         int n_groups;
82         gid_t *groups;
83         
84         /* NT group information taken from the info3 structure */
85         
86         NT_USER_TOKEN *ptok;
87         
88         uint8 session_key[16];
89         
90         uint8 first_8_lm_hash[8];
91
92         uint32 sam_fill_level;  /* How far is this structure filled? */
93         
94         SAM_ACCOUNT *sam_account;
95         
96         void *pam_handle;
97         
98 } auth_serversupplied_info;
99
100 struct auth_context {
101         DATA_BLOB challenge; 
102
103         /* Who set this up in the first place? */ 
104         char *challenge_set_by; 
105
106         struct auth_methods *challenge_set_method; 
107         /* What order are the various methods in?   Try to stop it changing under us */ 
108         struct auth_methods *auth_method_list;  
109
110         TALLOC_CTX *mem_ctx;
111         const uint8 *(*get_ntlm_challenge)(struct auth_context *auth_context);
112         NTSTATUS (*check_ntlm_password)(const struct auth_context *auth_context,
113                                         const struct auth_usersupplied_info *user_info, 
114                                         struct auth_serversupplied_info **server_info);
115         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
116         void (*free)(struct auth_context **auth_context);
117 };
118
119 typedef struct auth_methods
120 {
121         struct auth_methods *prev, *next;
122         char *name; /* What name got this module */
123
124         NTSTATUS (*auth)(const struct auth_context *auth_context,
125                          void *my_private_data, 
126                          TALLOC_CTX *mem_ctx,
127                          const struct auth_usersupplied_info *user_info, 
128                          auth_serversupplied_info **server_info);
129
130         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
131                               void **my_private_data, 
132                               TALLOC_CTX *mem_ctx);
133         
134         /* Used to keep tabs on things like the cli for SMB server authentication */
135         void *private_data;
136         
137         /* Function to clean up the above arbitary structure */
138         void (*free_private_data)(void **private_data);
139
140         /* Function to send a keepalive message on the above structure */
141         void (*send_keepalive)(void **private_data);
142
143 } auth_methods;
144
145 struct auth_init_function {
146         char *name;
147         /* Function to create a member of the authmethods list */
148         BOOL (*init)(struct auth_context *auth_context, struct auth_methods **auth_method);
149 };
150
151
152 #endif /* _SMBAUTH_H_ */