s4:auth/unix_token: remove unused tevent_context from auth_session_info_fill_unix()
[sfrench/samba-autobuild/.git] / source4 / auth / auth.h
1 /*
2    Unix SMB/CIFS implementation.
3    Standardised Authentication types
4    Copyright (C) Andrew Bartlett   2001
5    Copyright (C) Stefan Metzmacher 2005
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 3 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef _SAMBA_AUTH_H
22 #define _SAMBA_AUTH_H
23
24 #include "librpc/gen_ndr/ndr_krb5pac.h"
25 #include "librpc/gen_ndr/auth.h"
26 #include "../auth/common_auth.h"
27
28 extern const char *krbtgt_attrs[];
29 extern const char *server_attrs[];
30 extern const char *user_attrs[];
31
32 union netr_Validation;
33 struct netr_SamBaseInfo;
34 struct netr_SamInfo3;
35 struct loadparm_context;
36
37 /* modules can use the following to determine if the interface has changed
38  * please increment the version number after each interface change
39  * with a comment and maybe update struct auth_critical_sizes.
40  */
41 /* version 1 - version from samba 3.0 - metze */
42 /* version 2 - initial samba4 version - metze */
43 /* version 3 - subsequent samba4 version - abartlet */
44 /* version 4 - subsequent samba4 version - metze */
45 /* version 0 - till samba4 is stable - metze */
46 #define AUTH4_INTERFACE_VERSION 0
47
48 struct auth_method_context;
49 struct auth4_context;
50 struct auth_session_info;
51 struct ldb_dn;
52 struct smb_krb5_context;
53
54 struct auth_operations {
55         const char *name;
56
57         /* Given the user supplied info, check if this backend want to handle the password checking */
58
59         NTSTATUS (*want_check)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
60                                const struct auth_usersupplied_info *user_info);
61
62         /* Given the user supplied info, check a password */
63
64         NTSTATUS (*check_password)(struct auth_method_context *ctx, TALLOC_CTX *mem_ctx,
65                                    const struct auth_usersupplied_info *user_info,
66                                    struct auth_user_info_dc **interim_info,
67                                    bool *authoritative);
68
69
70         /* Lookup a 'session info interim' return based only on the principal or DN */
71         NTSTATUS (*get_user_info_dc_principal)(TALLOC_CTX *mem_ctx,
72                                                        struct auth4_context *auth_context,
73                                                        const char *principal,
74                                                        struct ldb_dn *user_dn,
75                                                        struct auth_user_info_dc **interim_info);
76         uint32_t flags;
77 };
78
79 struct auth_method_context {
80         struct auth_method_context *prev, *next;
81         struct auth4_context *auth_ctx;
82         const struct auth_operations *ops;
83         int depth;
84         void *private_data;
85 };
86
87 /* this structure is used by backends to determine the size of some critical types */
88 struct auth_critical_sizes {
89         int interface_version;
90         int sizeof_auth_operations;
91         int sizeof_auth_methods;
92         int sizeof_auth_context;
93         int sizeof_auth_usersupplied_info;
94         int sizeof_auth_user_info_dc;
95 };
96
97  NTSTATUS encrypt_user_info(TALLOC_CTX *mem_ctx, struct auth4_context *auth_context,
98                            enum auth_password_state to_state,
99                            const struct auth_usersupplied_info *user_info_in,
100                            const struct auth_usersupplied_info **user_info_encrypted);
101
102 #include "auth/session.h"
103 #include "auth/unix_token_proto.h"
104 #include "auth/system_session_proto.h"
105 #include "libcli/security/security.h"
106
107 struct ldb_message;
108 struct ldb_context;
109 struct gensec_security;
110 struct cli_credentials;
111
112 NTSTATUS auth_get_challenge(struct auth4_context *auth_ctx, uint8_t chal[8]);
113 NTSTATUS authsam_account_ok(TALLOC_CTX *mem_ctx,
114                             struct ldb_context *sam_ctx,
115                             uint32_t logon_parameters,
116                             struct ldb_dn *domain_dn,
117                             struct ldb_message *msg,
118                             const char *logon_workstation,
119                             const char *name_for_logs,
120                             bool allow_domain_trust,
121                             bool password_change);
122
123 struct auth_session_info *system_session(struct loadparm_context *lp_ctx);
124 NTSTATUS authsam_make_user_info_dc(TALLOC_CTX *mem_ctx, struct ldb_context *sam_ctx,
125                                            const char *netbios_name,
126                                            const char *domain_name,
127                                            const char *dns_domain_name,
128                                            struct ldb_dn *domain_dn,
129                                            struct ldb_message *msg,
130                                            DATA_BLOB user_sess_key, DATA_BLOB lm_sess_key,
131                                   struct auth_user_info_dc **_user_info_dc);
132 NTSTATUS auth_system_session_info(TALLOC_CTX *parent_ctx,
133                                            struct loadparm_context *lp_ctx,
134                                            struct auth_session_info **_session_info) ;
135
136 NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char * const *methods,
137                                      struct tevent_context *ev,
138                                      struct imessaging_context *msg,
139                                      struct loadparm_context *lp_ctx,
140                                      struct ldb_context *sam_ctx,
141                                      struct auth4_context **auth_ctx);
142 const char **auth_methods_from_lp(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx);
143
144 NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx,
145                              struct tevent_context *ev,
146                              struct imessaging_context *msg,
147                              struct loadparm_context *lp_ctx,
148                              struct auth4_context **auth_ctx);
149 NTSTATUS auth_context_create_for_netlogon(TALLOC_CTX *mem_ctx,
150                                           struct tevent_context *ev,
151                                           struct imessaging_context *msg,
152                                           struct loadparm_context *lp_ctx,
153                                           struct auth4_context **auth_ctx);
154
155 NTSTATUS auth_check_password(struct auth4_context *auth_ctx,
156                              TALLOC_CTX *mem_ctx,
157                              const struct auth_usersupplied_info *user_info, 
158                              struct auth_user_info_dc **user_info_dc,
159                              uint8_t *pauthoritative);
160 NTSTATUS auth4_init(void);
161 NTSTATUS auth_register(TALLOC_CTX *mem_ctx, const struct auth_operations *ops);
162 NTSTATUS server_service_auth_init(TALLOC_CTX *ctx);
163 struct tevent_req *authenticate_ldap_simple_bind_send(TALLOC_CTX *mem_ctx,
164                                         struct tevent_context *ev,
165                                         struct imessaging_context *msg,
166                                         struct loadparm_context *lp_ctx,
167                                         struct tsocket_address *remote_address,
168                                         struct tsocket_address *local_address,
169                                         bool using_tls,
170                                         const char *dn,
171                                         const char *password);
172 NTSTATUS authenticate_ldap_simple_bind_recv(struct tevent_req *req,
173                                         TALLOC_CTX *mem_ctx,
174                                         struct auth_session_info **session_info);
175 NTSTATUS authenticate_ldap_simple_bind(TALLOC_CTX *mem_ctx,
176                                        struct tevent_context *ev,
177                                        struct imessaging_context *msg,
178                                        struct loadparm_context *lp_ctx,
179                                        struct tsocket_address *remote_address,
180                                        struct tsocket_address *local_address,
181                                        bool using_tls,
182                                        const char *dn,
183                                        const char *password,
184                                        struct auth_session_info **session_info);
185
186 struct tevent_req *auth_check_password_send(TALLOC_CTX *mem_ctx,
187                                             struct tevent_context *ev,
188                                             struct auth4_context *auth_ctx,
189                                             const struct auth_usersupplied_info *user_info);
190 NTSTATUS auth_check_password_recv(struct tevent_req *req,
191                                   TALLOC_CTX *mem_ctx,
192                                   struct auth_user_info_dc **user_info_dc,
193                                   uint8_t *pauthoritative);
194
195 NTSTATUS auth_context_set_challenge(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
196
197 NTSTATUS samba_server_gensec_start(TALLOC_CTX *mem_ctx,
198                                    struct tevent_context *event_ctx,
199                                    struct imessaging_context *msg_ctx,
200                                    struct loadparm_context *lp_ctx,
201                                    struct cli_credentials *server_credentials,
202                                    const char *target_service,
203                                    struct gensec_security **gensec_context);
204 NTSTATUS samba_server_gensec_krb5_start(TALLOC_CTX *mem_ctx,
205                                         struct tevent_context *event_ctx,
206                                         struct imessaging_context *msg_ctx,
207                                         struct loadparm_context *lp_ctx,
208                                         struct cli_credentials *server_credentials,
209                                         const char *target_service,
210                                         struct gensec_security **gensec_context);
211
212 #endif /* _SMBAUTH_H_ */