lib: modules: Change XXX_init interface from XXX_init(void) to XXX_init(TALLOC_CTX *)
[samba.git] / source3 / auth / proto.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Password and authentication handling
4  *
5  *  Copyright (C) Andrew Tridgell               1992-2001
6  *  Copyright (C) Luke Kenneth Casson Leighton  1996-2000
7  *  Copyright (C) Jeremy Allison                1997-2001
8  *  Copyright (C) John H Terpsta                1999-2001
9  *  Copyright (C) Tim Potter                    2000
10  *  Copyright (C) Andrew Bartlett               2001-2003
11  *  Copyright (C) Jelmer Vernooij               2002
12  *  Copyright (C) Rafal Szczesniak              2002
13  *  Copyright (C) Gerald Carter                 2003
14  *  Copyright (C) Volker Lendecke               2006,2010
15  *  Copyright (C) Michael Adam                  2007
16  *  Copyright (C) Dan Sledz                     2009
17  *  Copyright (C) Simo Sorce                    2010
18  *
19  *  This program is free software; you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License as published by
21  *  the Free Software Foundation; either version 3 of the License, or
22  *  (at your option) any later version.
23  *
24  *  This program is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  *  You should have received a copy of the GNU General Public License
30  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
31  */
32
33 #ifndef _AUTH_PROTO_H_
34 #define _AUTH_PROTO_H_
35
36 /* The following definitions come from auth/auth.c  */
37
38 NTSTATUS smb_register_auth(int version, const char *name, auth_init_function init);
39 bool load_auth_module(struct auth_context *auth_context,
40                       const char *module, auth_methods **ret) ;
41 NTSTATUS make_auth3_context_for_ntlm(TALLOC_CTX *mem_ctx,
42                                      struct auth_context **auth_context);
43 NTSTATUS make_auth3_context_for_netlogon(TALLOC_CTX *mem_ctx,
44                                          struct auth_context **auth_context);
45 NTSTATUS make_auth3_context_for_winbind(TALLOC_CTX *mem_ctx,
46                                         struct auth_context **auth_context);
47 bool auth3_context_set_challenge(struct auth_context *ctx, uint8_t chal[8],
48                                  const char *challenge_set_by);
49
50 /****************************************************************************
51  Try to get a challenge out of the various authentication modules.
52  Returns a const char of length 8 bytes.
53 ****************************************************************************/
54
55 NTSTATUS auth_get_ntlm_challenge(struct auth_context *auth_context,
56                                  uint8_t chal[8]);
57
58 /**
59  * Check a user's Plaintext, LM or NTLM password.
60  *
61  * Check a user's password, as given in the user_info struct and return various
62  * interesting details in the server_info struct.
63  *
64  * This function does NOT need to be in a become_root()/unbecome_root() pair
65  * as it makes the calls itself when needed.
66  *
67  * The return value takes precedence over the contents of the server_info 
68  * struct.  When the return is other than NT_STATUS_OK the contents 
69  * of that structure is undefined.
70  *
71  * @param mem_ctx   The memory context to use to allocate server_info
72  *
73  * @param user_info Contains the user supplied components, including the passwords.
74  *                  Must be created with make_user_info() or one of its wrappers.
75  *
76  * @param auth_context Supplies the challenges and some other data. 
77  *                  Must be created with make_auth_context(), and the challenges should be 
78  *                  filled in, either at creation or by calling the challenge geneation 
79  *                  function auth_get_challenge().  
80  *
81  * @param pserver_info If successful, contains information about the authentication,
82  *                     including a struct samu struct describing the user.
83  *
84  * @param pauthoritative Indicates if the result should be treated as final
85  *                       result.
86  *
87  * @return An NTSTATUS with NT_STATUS_OK or an appropriate error.
88  *
89  **/
90 NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
91                                   const struct auth_context *auth_context,
92                                   const struct auth_usersupplied_info *user_info,
93                                   struct auth_serversupplied_info **pserver_info,
94                                   uint8_t *pauthoritative);
95
96 /* The following definitions come from auth/auth_builtin.c  */
97
98 NTSTATUS auth_builtin_init(TALLOC_CTX *mem_ctx);
99
100 /* The following definitions come from auth/auth_domain.c  */
101
102 void attempt_machine_password_change(void);
103 NTSTATUS auth_domain_init(TALLOC_CTX *mem_ctx);
104
105 /* The following definitions come from auth/auth_generic.c  */
106
107 NTSTATUS make_auth4_context(TALLOC_CTX *mem_ctx, struct auth4_context **auth4_context_out);
108 NTSTATUS auth_generic_prepare(TALLOC_CTX *mem_ctx,
109                               const struct tsocket_address *remote_address,
110                               const struct tsocket_address *local_address,
111                               const char *service_description,
112                               struct gensec_security **gensec_security_out);
113
114 NTSTATUS auth_check_password_session_info(struct auth4_context *auth_context,
115                                           TALLOC_CTX *mem_ctx,
116                                           struct auth_usersupplied_info *user_info,
117                                           struct auth_session_info **session_info);
118
119 /* The following definitions come from auth/auth_ntlmssp.c  */
120
121 NTSTATUS auth3_generate_session_info(struct auth4_context *auth_context,
122                                      TALLOC_CTX *mem_ctx,
123                                      void *server_returned_info,
124                                      const char *original_user_name,
125                                      uint32_t session_info_flags,
126                                      struct auth_session_info **session_info);
127
128 NTSTATUS auth3_get_challenge(struct auth4_context *auth4_context,
129                              uint8_t chal[8]);
130
131 bool auth3_may_set_challenge(struct auth4_context *auth4_context);
132 NTSTATUS auth3_set_challenge(struct auth4_context *auth4_context, const uint8_t *chal,
133                              const char *challenge_set_by);
134
135 NTSTATUS auth3_check_password(struct auth4_context *auth4_context,
136                               TALLOC_CTX *mem_ctx,
137                               const struct auth_usersupplied_info *user_info,
138                               uint8_t *pauthoritative,
139                               void **server_returned_info,
140                               DATA_BLOB *session_key, DATA_BLOB *lm_session_key);
141
142 /* The following definitions come from auth/auth_sam.c  */
143
144 NTSTATUS check_sam_security(const DATA_BLOB *challenge,
145                             TALLOC_CTX *mem_ctx,
146                             const struct auth_usersupplied_info *user_info,
147                             struct auth_serversupplied_info **server_info);
148 NTSTATUS check_sam_security_info3(const DATA_BLOB *challenge,
149                                   TALLOC_CTX *mem_ctx,
150                                   const struct auth_usersupplied_info *user_info,
151                                   struct netr_SamInfo3 **pinfo3);
152 NTSTATUS auth_sam_init(TALLOC_CTX *mem_ctx);
153
154 /* The following definitions come from auth/auth_unix.c  */
155
156 NTSTATUS auth_unix_init(TALLOC_CTX *mem_ctx);
157
158 /* The following definitions come from auth/auth_util.c  */
159 struct tsocket_address;
160
161 NTSTATUS make_user_info_map(TALLOC_CTX *mem_ctx,
162                             struct auth_usersupplied_info **user_info,
163                             const char *smb_name,
164                             const char *client_domain,
165                             const char *workstation_name,
166                             const struct tsocket_address *remote_address,
167                             const struct tsocket_address *local_address,
168                             const char *service_description,
169                             const DATA_BLOB *lm_pwd,
170                             const DATA_BLOB *nt_pwd,
171                             const struct samr_Password *lm_interactive_pwd,
172                             const struct samr_Password *nt_interactive_pwd,
173                             const char *plaintext,
174                             enum auth_password_state password_state);
175 bool make_user_info_netlogon_network(TALLOC_CTX *mem_ctx,
176                                      struct auth_usersupplied_info **user_info,
177                                      const char *smb_name,
178                                      const char *client_domain,
179                                      const char *workstation_name,
180                                      const struct tsocket_address *remote_address,
181                                      const struct tsocket_address *local_address,
182                                      uint32_t logon_parameters,
183                                      const uchar *lm_network_pwd,
184                                      int lm_pwd_len,
185                                      const uchar *nt_network_pwd,
186                                      int nt_pwd_len);
187 bool make_user_info_netlogon_interactive(TALLOC_CTX *mem_ctx,
188                                          struct auth_usersupplied_info **user_info,
189                                          const char *smb_name,
190                                          const char *client_domain,
191                                          const char *workstation_name,
192                                          const struct tsocket_address *remote_address,
193                                          const struct tsocket_address *local_address,
194                                          uint32_t logon_parameters,
195                                          const uchar chal[8],
196                                          const uchar lm_interactive_pwd[16],
197                                          const uchar nt_interactive_pwd[16]);
198 bool make_user_info_for_reply(TALLOC_CTX *mem_ctx,
199                               struct auth_usersupplied_info **user_info,
200                               const char *smb_name,
201                               const char *client_domain,
202                               const struct tsocket_address *remote_address,
203                               const struct tsocket_address *local_address,
204                               const char *service_description,
205                               const uint8_t chal[8],
206                               DATA_BLOB plaintext_password);
207 NTSTATUS make_user_info_for_reply_enc(TALLOC_CTX *mem_ctx,
208                                       struct auth_usersupplied_info **user_info,
209                                       const char *smb_name,
210                                       const char *client_domain,
211                                       const struct tsocket_address *remote_address,
212                                       const struct tsocket_address *local_address,
213                                       const char *service_description,
214                                       DATA_BLOB lm_resp, DATA_BLOB nt_resp);
215 bool make_user_info_guest(TALLOC_CTX *mem_ctx,
216                           const struct tsocket_address *remote_address,
217                           const struct tsocket_address *local_address,
218                           const char *service_description,
219                           struct auth_usersupplied_info **user_info);
220
221 struct samu;
222 NTSTATUS make_server_info_sam(TALLOC_CTX *mem_ctx,
223                               struct samu *sampass,
224                               struct auth_serversupplied_info **pserver_info);
225 NTSTATUS create_local_token(TALLOC_CTX *mem_ctx,
226                             const struct auth_serversupplied_info *server_info,
227                             DATA_BLOB *session_key,
228                             const char *smb_name,
229                             struct auth_session_info **session_info_out);
230 NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
231                                     bool is_guest,
232                                     uid_t *uid, gid_t *gid,
233                                     char **found_username,
234                                     struct security_token **token);
235 bool user_in_group_sid(const char *username, const struct dom_sid *group_sid);
236 bool user_sid_in_group_sid(const struct dom_sid *sid, const struct dom_sid *group_sid);
237 bool user_in_group(const char *username, const char *groupname);
238 struct passwd;
239 NTSTATUS make_server_info_pw(TALLOC_CTX *mem_ctx,
240                              const char *unix_username,
241                              const struct passwd *pwd,
242                              struct auth_serversupplied_info **server_info);
243 NTSTATUS make_session_info_from_username(TALLOC_CTX *mem_ctx,
244                                          const char *username,
245                                          bool is_guest,
246                                          struct auth_session_info **session_info);
247 struct auth_session_info *copy_session_info(TALLOC_CTX *mem_ctx,
248                                              const struct auth_session_info *src);
249 bool init_guest_info(void);
250 NTSTATUS init_system_session_info(void);
251 bool session_info_set_session_key(struct auth_session_info *info,
252                                  DATA_BLOB session_key);
253 NTSTATUS make_server_info_guest(TALLOC_CTX *mem_ctx,
254                                 struct auth_serversupplied_info **server_info);
255 NTSTATUS make_session_info_guest(TALLOC_CTX *mem_ctx,
256                                 struct auth_session_info **server_info);
257 NTSTATUS make_session_info_system(TALLOC_CTX *mem_ctx,
258                                  struct auth_session_info **session_info);
259 const struct auth_session_info *get_session_info_system(void);
260 struct passwd *smb_getpwnam( TALLOC_CTX *mem_ctx, const char *domuser,
261                              char **p_save_username, bool create );
262 NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
263                                 const char *sent_nt_username,
264                                 const char *domain,
265                                 struct auth_serversupplied_info **server_info,
266                                 const struct netr_SamInfo3 *info3);
267 struct wbcAuthUserInfo;
268 NTSTATUS make_server_info_wbcAuthUserInfo(TALLOC_CTX *mem_ctx,
269                                           const char *sent_nt_username,
270                                           const char *domain,
271                                           const struct wbcAuthUserInfo *info,
272                                           struct auth_serversupplied_info **server_info);
273 void free_user_info(struct auth_usersupplied_info **user_info);
274 bool is_trusted_domain(const char* dom_name);
275 NTSTATUS session_extract_session_key(const struct auth_session_info *session_info, DATA_BLOB *session_key, enum session_key_use_intent intent);
276
277 /* The following definitions come from auth/user_info.c  */
278
279 NTSTATUS make_user_info(TALLOC_CTX *mem_ctx,
280                         struct auth_usersupplied_info **ret_user_info,
281                         const char *smb_name,
282                         const char *internal_username,
283                         const char *client_domain,
284                         const char *domain,
285                         const char *workstation_name,
286                         const struct tsocket_address *remote_address,
287                         const struct tsocket_address *local_address,
288                         const char *service_description,
289                         const DATA_BLOB *lm_pwd,
290                         const DATA_BLOB *nt_pwd,
291                         const struct samr_Password *lm_interactive_pwd,
292                         const struct samr_Password *nt_interactive_pwd,
293                         const char *plaintext_password,
294                         enum auth_password_state password_state);
295 void free_user_info(struct auth_usersupplied_info **user_info);
296
297 NTSTATUS do_map_to_guest_server_info(TALLOC_CTX *mem_ctx,
298                                      NTSTATUS status,
299                                      const char *user,
300                                      const char *domain,
301                                      struct auth_serversupplied_info **server_info);
302
303 /* The following definitions come from auth/auth_winbind.c  */
304
305 NTSTATUS auth_winbind_init(TALLOC_CTX *mem_ctx);
306
307 /* The following definitions come from auth/server_info.c  */
308
309 struct netr_SamInfo2;
310 struct netr_SamInfo3;
311 struct netr_SamInfo6;
312
313 struct auth_serversupplied_info *make_server_info(TALLOC_CTX *mem_ctx);
314 NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
315                                 struct netr_SamInfo2 *sam2);
316 NTSTATUS serverinfo_to_SamInfo3(const struct auth_serversupplied_info *server_info,
317                                 struct netr_SamInfo3 *sam3);
318 NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
319                                 struct netr_SamInfo6 *sam6);
320 NTSTATUS create_info3_from_pac_logon_info(TALLOC_CTX *mem_ctx,
321                                         const struct PAC_LOGON_INFO *logon_info,
322                                         struct netr_SamInfo3 **pp_info3);
323 NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
324                           struct samu *samu,
325                           const char *login_server,
326                           struct netr_SamInfo3 **_info3,
327                           struct extra_auth_info *extra);
328 NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx,
329                             const char *unix_username,
330                             const struct passwd *pwd,
331                             struct netr_SamInfo3 **pinfo3,
332                             struct extra_auth_info *extra);
333 struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
334                                          const struct netr_SamInfo3 *orig);
335
336 /* The following definitions come from auth/auth_wbc.c  */
337
338 NTSTATUS auth_wbc_init(void);
339
340 /* The following definitions come from auth/pampass.c  */
341
342 bool smb_pam_claim_session(const char *user, const char *tty, const char *rhost);
343 bool smb_pam_close_session(const char *user, const char *tty, const char *rhost);
344 NTSTATUS smb_pam_accountcheck(const char *user, const char *rhost);
345 NTSTATUS smb_pam_passcheck(const char * user, const char * rhost,
346                            const char * password);
347 bool smb_pam_passchange(const char *user, const char *rhost,
348                         const char *oldpassword, const char *newpassword);
349
350 /* The following definitions come from auth/pass_check.c  */
351
352 void dfs_unlogin(void);
353 NTSTATUS pass_check(const struct passwd *pass,
354                     const char *user,
355                     const char *rhost,
356                     const char *password,
357                     bool run_cracker);
358
359 /* The following definitions come from auth/token_util.c  */
360
361 bool nt_token_check_sid ( const struct dom_sid *sid, const struct security_token *token );
362 bool nt_token_check_domain_rid( struct security_token *token, uint32_t rid );
363 struct security_token *get_root_nt_token( void );
364 NTSTATUS add_aliases(const struct dom_sid *domain_sid,
365                      struct security_token *token);
366 struct security_token *create_local_nt_token(TALLOC_CTX *mem_ctx,
367                                             const struct dom_sid *user_sid,
368                                             bool is_guest,
369                                             int num_groupsids,
370                                             const struct dom_sid *groupsids);
371 NTSTATUS get_user_sid_info3_and_extra(const struct netr_SamInfo3 *info3,
372                                       const struct extra_auth_info *extra,
373                                       struct dom_sid *sid);
374 NTSTATUS create_local_nt_token_from_info3(TALLOC_CTX *mem_ctx,
375                                           bool is_guest,
376                                           const struct netr_SamInfo3 *info3,
377                                           const struct extra_auth_info *extra,
378                                           struct security_token **ntok);
379 void debug_unix_user_token(int dbg_class, int dbg_lev, uid_t uid, gid_t gid,
380                            int n_groups, gid_t *groups);
381
382 /* The following definitions come from auth/user_util.c  */
383
384 bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out);
385 bool user_in_netgroup(TALLOC_CTX *ctx, const char *user, const char *ngname);
386 bool user_in_list(TALLOC_CTX *ctx, const char *user, const char * const *list);
387
388 /* The following definitions come from auth/user_krb5.c  */
389 struct PAC_LOGON_INFO;
390 NTSTATUS get_user_from_kerberos_info(TALLOC_CTX *mem_ctx,
391                                      const char *cli_name,
392                                      const char *princ_name,
393                                      struct PAC_LOGON_INFO *logon_info,
394                                      bool *is_mapped,
395                                      bool *mapped_to_guest,
396                                      char **ntuser,
397                                      char **ntdomain,
398                                      char **username,
399                                      struct passwd **_pw);
400 NTSTATUS make_session_info_krb5(TALLOC_CTX *mem_ctx,
401                                 char *ntuser,
402                                 char *ntdomain,
403                                 char *username,
404                                 struct passwd *pw,
405                                 const struct netr_SamInfo3 *info3,
406                                 bool mapped_to_guest, bool username_was_mapped,
407                                 DATA_BLOB *session_key,
408                                 struct auth_session_info **session_info);
409
410 /* The following definitions come from auth/auth_samba4.c  */
411
412 NTSTATUS auth_samba4_init(TALLOC_CTX *mem_ctx);
413
414 #endif /* _AUTH_PROTO_H_ */