s3-libads: allow ads_try_connect() to re-use a resolved ip address.
[nivanova/samba-autobuild/.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_auth_context_subsystem(TALLOC_CTX *mem_ctx,
42                                      struct auth_context **auth_context);
43 NTSTATUS make_auth_context_fixed(TALLOC_CTX *mem_ctx,
44                                  struct auth_context **auth_context,
45                                  uchar chal[8]) ;
46
47 /****************************************************************************
48  Try to get a challenge out of the various authentication modules.
49  Returns a const char of length 8 bytes.
50 ****************************************************************************/
51
52 NTSTATUS auth_get_ntlm_challenge(struct auth_context *auth_context,
53                                  uint8_t chal[8]);
54
55 /**
56  * Check a user's Plaintext, LM or NTLM password.
57  *
58  * Check a user's password, as given in the user_info struct and return various
59  * interesting details in the server_info struct.
60  *
61  * This function does NOT need to be in a become_root()/unbecome_root() pair
62  * as it makes the calls itself when needed.
63  *
64  * The return value takes precedence over the contents of the server_info 
65  * struct.  When the return is other than NT_STATUS_OK the contents 
66  * of that structure is undefined.
67  *
68  * @param mem_ctx   The memory context to use to allocate server_info
69  *
70  * @param user_info Contains the user supplied components, including the passwords.
71  *                  Must be created with make_user_info() or one of its wrappers.
72  *
73  * @param auth_context Supplies the challenges and some other data. 
74  *                  Must be created with make_auth_context(), and the challenges should be 
75  *                  filled in, either at creation or by calling the challenge geneation 
76  *                  function auth_get_challenge().  
77  *
78  * @param server_info If successful, contains information about the authentication, 
79  *                    including a struct samu struct describing the user.
80  *
81  * @return An NTSTATUS with NT_STATUS_OK or an appropriate error.
82  *
83  **/
84 NTSTATUS auth_check_ntlm_password(TALLOC_CTX *mem_ctx,
85                                   const struct auth_context *auth_context,
86                                   const struct auth_usersupplied_info *user_info,
87                                   struct auth_serversupplied_info **server_info);
88
89 /* The following definitions come from auth/auth_builtin.c  */
90
91 NTSTATUS auth_builtin_init(void);
92
93 /* The following definitions come from auth/auth_domain.c  */
94
95 void attempt_machine_password_change(void);
96 NTSTATUS auth_domain_init(void);
97
98 /* The following definitions come from auth/auth_generic.c  */
99
100 NTSTATUS make_auth4_context(TALLOC_CTX *mem_ctx, struct auth4_context **auth4_context_out);
101 NTSTATUS auth_generic_prepare(TALLOC_CTX *mem_ctx, const struct tsocket_address *remote_address,
102                               struct gensec_security **gensec_security_out);
103
104 NTSTATUS auth_check_password_session_info(struct auth4_context *auth_context,
105                                           TALLOC_CTX *mem_ctx,
106                                           struct auth_usersupplied_info *user_info,
107                                           struct auth_session_info **session_info);
108
109 /* The following definitions come from auth/auth_ntlmssp.c  */
110
111 NTSTATUS auth3_generate_session_info(struct auth4_context *auth_context,
112                                      TALLOC_CTX *mem_ctx,
113                                      void *server_returned_info,
114                                      const char *original_user_name,
115                                      uint32_t session_info_flags,
116                                      struct auth_session_info **session_info);
117
118 NTSTATUS auth3_get_challenge(struct auth4_context *auth4_context,
119                              uint8_t chal[8]);
120
121 bool auth3_may_set_challenge(struct auth4_context *auth4_context);
122 NTSTATUS auth3_set_challenge(struct auth4_context *auth4_context, const uint8_t *chal,
123                              const char *challenge_set_by);
124
125 NTSTATUS auth3_check_password(struct auth4_context *auth4_context,
126                               TALLOC_CTX *mem_ctx,
127                               const struct auth_usersupplied_info *user_info,
128                               void **server_returned_info,
129                               DATA_BLOB *session_key, DATA_BLOB *lm_session_key);
130
131 /* The following definitions come from auth/auth_sam.c  */
132
133 NTSTATUS check_sam_security(const DATA_BLOB *challenge,
134                             TALLOC_CTX *mem_ctx,
135                             const struct auth_usersupplied_info *user_info,
136                             struct auth_serversupplied_info **server_info);
137 NTSTATUS check_sam_security_info3(const DATA_BLOB *challenge,
138                                   TALLOC_CTX *mem_ctx,
139                                   const struct auth_usersupplied_info *user_info,
140                                   struct netr_SamInfo3 **pinfo3);
141 NTSTATUS auth_sam_init(void);
142
143 /* The following definitions come from auth/auth_unix.c  */
144
145 NTSTATUS auth_unix_init(void);
146
147 /* The following definitions come from auth/auth_util.c  */
148 struct tsocket_address;
149
150 NTSTATUS make_user_info_map(TALLOC_CTX *mem_ctx,
151                             struct auth_usersupplied_info **user_info,
152                             const char *smb_name,
153                             const char *client_domain,
154                             const char *workstation_name,
155                             const struct tsocket_address *remote_address,
156                             const DATA_BLOB *lm_pwd,
157                             const DATA_BLOB *nt_pwd,
158                             const struct samr_Password *lm_interactive_pwd,
159                             const struct samr_Password *nt_interactive_pwd,
160                             const char *plaintext,
161                             enum auth_password_state password_state);
162 bool make_user_info_netlogon_network(TALLOC_CTX *mem_ctx,
163                                      struct auth_usersupplied_info **user_info,
164                                      const char *smb_name,
165                                      const char *client_domain,
166                                      const char *workstation_name,
167                                      const struct tsocket_address *remote_address,
168                                      uint32 logon_parameters,
169                                      const uchar *lm_network_pwd,
170                                      int lm_pwd_len,
171                                      const uchar *nt_network_pwd,
172                                      int nt_pwd_len);
173 bool make_user_info_netlogon_interactive(TALLOC_CTX *mem_ctx,
174                                          struct auth_usersupplied_info **user_info,
175                                          const char *smb_name,
176                                          const char *client_domain,
177                                          const char *workstation_name,
178                                          const struct tsocket_address *remote_address,
179                                          uint32 logon_parameters,
180                                          const uchar chal[8],
181                                          const uchar lm_interactive_pwd[16],
182                                          const uchar nt_interactive_pwd[16]);
183 bool make_user_info_for_reply(TALLOC_CTX *mem_ctx,
184                               struct auth_usersupplied_info **user_info,
185                               const char *smb_name,
186                               const char *client_domain,
187                               const struct tsocket_address *remote_address,
188                               const uint8 chal[8],
189                               DATA_BLOB plaintext_password);
190 NTSTATUS make_user_info_for_reply_enc(TALLOC_CTX *mem_ctx,
191                                       struct auth_usersupplied_info **user_info,
192                                       const char *smb_name,
193                                       const char *client_domain,
194                                       const struct tsocket_address *remote_address,
195                                       DATA_BLOB lm_resp, DATA_BLOB nt_resp);
196 bool make_user_info_guest(TALLOC_CTX *mem_ctx,
197                           const struct tsocket_address *remote_address,
198                           struct auth_usersupplied_info **user_info);
199
200 struct samu;
201 NTSTATUS make_server_info_sam(TALLOC_CTX *mem_ctx,
202                               struct samu *sampass,
203                               struct auth_serversupplied_info **pserver_info);
204 NTSTATUS create_local_token(TALLOC_CTX *mem_ctx,
205                             const struct auth_serversupplied_info *server_info,
206                             DATA_BLOB *session_key,
207                             const char *smb_name,
208                             struct auth_session_info **session_info_out);
209 NTSTATUS create_token_from_username(TALLOC_CTX *mem_ctx, const char *username,
210                                     bool is_guest,
211                                     uid_t *uid, gid_t *gid,
212                                     char **found_username,
213                                     struct security_token **token);
214 bool user_in_group_sid(const char *username, const struct dom_sid *group_sid);
215 bool user_sid_in_group_sid(const struct dom_sid *sid, const struct dom_sid *group_sid);
216 bool user_in_group(const char *username, const char *groupname);
217 struct passwd;
218 NTSTATUS make_server_info_pw(TALLOC_CTX *mem_ctx,
219                              const char *unix_username,
220                              const struct passwd *pwd,
221                              struct auth_serversupplied_info **server_info);
222 NTSTATUS make_session_info_from_username(TALLOC_CTX *mem_ctx,
223                                          const char *username,
224                                          bool is_guest,
225                                          struct auth_session_info **session_info);
226 struct auth_session_info *copy_session_info(TALLOC_CTX *mem_ctx,
227                                              const struct auth_session_info *src);
228 bool init_guest_info(void);
229 NTSTATUS init_system_session_info(void);
230 bool session_info_set_session_key(struct auth_session_info *info,
231                                  DATA_BLOB session_key);
232 NTSTATUS make_server_info_guest(TALLOC_CTX *mem_ctx,
233                                 struct auth_serversupplied_info **server_info);
234 NTSTATUS make_session_info_guest(TALLOC_CTX *mem_ctx,
235                                 struct auth_session_info **server_info);
236 NTSTATUS make_session_info_system(TALLOC_CTX *mem_ctx,
237                                  struct auth_session_info **session_info);
238 const struct auth_session_info *get_session_info_system(void);
239 struct passwd *smb_getpwnam( TALLOC_CTX *mem_ctx, const char *domuser,
240                              char **p_save_username, bool create );
241 NTSTATUS make_server_info_info3(TALLOC_CTX *mem_ctx,
242                                 const char *sent_nt_username,
243                                 const char *domain,
244                                 struct auth_serversupplied_info **server_info,
245                                 struct netr_SamInfo3 *info3);
246 struct wbcAuthUserInfo;
247 NTSTATUS make_server_info_wbcAuthUserInfo(TALLOC_CTX *mem_ctx,
248                                           const char *sent_nt_username,
249                                           const char *domain,
250                                           const struct wbcAuthUserInfo *info,
251                                           struct auth_serversupplied_info **server_info);
252 void free_user_info(struct auth_usersupplied_info **user_info);
253 bool is_trusted_domain(const char* dom_name);
254 NTSTATUS session_extract_session_key(const struct auth_session_info *session_info, DATA_BLOB *session_key, enum session_key_use_intent intent);
255
256 /* The following definitions come from auth/user_info.c  */
257
258 NTSTATUS make_user_info(TALLOC_CTX *mem_ctx,
259                         struct auth_usersupplied_info **ret_user_info,
260                         const char *smb_name,
261                         const char *internal_username,
262                         const char *client_domain,
263                         const char *domain,
264                         const char *workstation_name,
265                         const struct tsocket_address *remote_address,
266                         const DATA_BLOB *lm_pwd,
267                         const DATA_BLOB *nt_pwd,
268                         const struct samr_Password *lm_interactive_pwd,
269                         const struct samr_Password *nt_interactive_pwd,
270                         const char *plaintext_password,
271                         enum auth_password_state password_state);
272 void free_user_info(struct auth_usersupplied_info **user_info);
273
274 NTSTATUS do_map_to_guest_server_info(TALLOC_CTX *mem_ctx,
275                                      NTSTATUS status,
276                                      const char *user,
277                                      const char *domain,
278                                      struct auth_serversupplied_info **server_info);
279
280 /* The following definitions come from auth/auth_winbind.c  */
281
282 NTSTATUS auth_winbind_init(void);
283
284 /* The following definitions come from auth/server_info.c  */
285
286 struct netr_SamInfo2;
287 struct netr_SamInfo3;
288 struct netr_SamInfo6;
289
290 struct auth_serversupplied_info *make_server_info(TALLOC_CTX *mem_ctx);
291 NTSTATUS serverinfo_to_SamInfo2(struct auth_serversupplied_info *server_info,
292                                 struct netr_SamInfo2 *sam2);
293 NTSTATUS serverinfo_to_SamInfo3(const struct auth_serversupplied_info *server_info,
294                                 struct netr_SamInfo3 *sam3);
295 NTSTATUS serverinfo_to_SamInfo6(struct auth_serversupplied_info *server_info,
296                                 struct netr_SamInfo6 *sam6);
297 NTSTATUS samu_to_SamInfo3(TALLOC_CTX *mem_ctx,
298                           struct samu *samu,
299                           const char *login_server,
300                           struct netr_SamInfo3 **_info3,
301                           struct extra_auth_info *extra);
302 NTSTATUS passwd_to_SamInfo3(TALLOC_CTX *mem_ctx,
303                             const char *unix_username,
304                             const struct passwd *pwd,
305                             struct netr_SamInfo3 **pinfo3);
306 struct netr_SamInfo3 *copy_netr_SamInfo3(TALLOC_CTX *mem_ctx,
307                                          struct netr_SamInfo3 *orig);
308 struct netr_SamInfo3 *wbcAuthUserInfo_to_netr_SamInfo3(TALLOC_CTX *mem_ctx,
309                                         const struct wbcAuthUserInfo *info);
310
311 /* The following definitions come from auth/auth_wbc.c  */
312
313 NTSTATUS auth_wbc_init(void);
314
315 /* The following definitions come from auth/pampass.c  */
316
317 bool smb_pam_claim_session(const char *user, const char *tty, const char *rhost);
318 bool smb_pam_close_session(const char *user, const char *tty, const char *rhost);
319 NTSTATUS smb_pam_accountcheck(const char *user, const char *rhost);
320 NTSTATUS smb_pam_passcheck(const char * user, const char * rhost,
321                            const char * password);
322 bool smb_pam_passchange(const char *user, const char *rhost,
323                         const char *oldpassword, const char *newpassword);
324
325 /* The following definitions come from auth/pass_check.c  */
326
327 void dfs_unlogin(void);
328 NTSTATUS pass_check(const struct passwd *pass,
329                     const char *user,
330                     const char *rhost,
331                     const char *password,
332                     bool run_cracker);
333
334 /* The following definitions come from auth/token_util.c  */
335
336 bool nt_token_check_sid ( const struct dom_sid *sid, const struct security_token *token );
337 bool nt_token_check_domain_rid( struct security_token *token, uint32 rid );
338 struct security_token *get_root_nt_token( void );
339 NTSTATUS add_aliases(const struct dom_sid *domain_sid,
340                      struct security_token *token);
341 struct security_token *create_local_nt_token(TALLOC_CTX *mem_ctx,
342                                             const struct dom_sid *user_sid,
343                                             bool is_guest,
344                                             int num_groupsids,
345                                             const struct dom_sid *groupsids);
346 NTSTATUS create_local_nt_token_from_info3(TALLOC_CTX *mem_ctx,
347                                           bool is_guest,
348                                           const struct netr_SamInfo3 *info3,
349                                           const struct extra_auth_info *extra,
350                                           struct security_token **ntok);
351 void debug_unix_user_token(int dbg_class, int dbg_lev, uid_t uid, gid_t gid,
352                            int n_groups, gid_t *groups);
353
354 /* The following definitions come from auth/user_util.c  */
355
356 bool map_username(TALLOC_CTX *ctx, const char *user_in, char **p_user_out);
357 bool user_in_netgroup(TALLOC_CTX *ctx, const char *user, const char *ngname);
358 bool user_in_list(TALLOC_CTX *ctx, const char *user,const char **list);
359
360 /* The following definitions come from auth/user_krb5.c  */
361 struct PAC_LOGON_INFO;
362 NTSTATUS get_user_from_kerberos_info(TALLOC_CTX *mem_ctx,
363                                      const char *cli_name,
364                                      const char *princ_name,
365                                      struct PAC_LOGON_INFO *logon_info,
366                                      bool *is_mapped,
367                                      bool *mapped_to_guest,
368                                      char **ntuser,
369                                      char **ntdomain,
370                                      char **username,
371                                      struct passwd **_pw);
372 NTSTATUS make_session_info_krb5(TALLOC_CTX *mem_ctx,
373                                 char *ntuser,
374                                 char *ntdomain,
375                                 char *username,
376                                 struct passwd *pw,
377                                 struct PAC_LOGON_INFO *logon_info,
378                                 bool mapped_to_guest, bool username_was_mapped,
379                                 DATA_BLOB *session_key,
380                                 struct auth_session_info **session_info);
381
382
383 #endif /* _AUTH_PROTO_H_ */