s3-auth Use the common gensec_ntlmssp_update in gensec_ntlmssp3_server
[ab/samba.git/.git] / auth / ntlmssp / ntlmssp_private.h
1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Version 3.0
4  *  NTLMSSP Signing routines
5  *  Copyright (C) Andrew Bartlett 2003-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 /* For structures internal to the NTLMSSP implementation that should not be exposed */
22
23 #include "../lib/crypto/arcfour.h"
24
25 struct auth_session_info;
26
27 struct ntlmssp_crypt_direction {
28         uint32_t seq_num;
29         uint8_t sign_key[16];
30         struct arcfour_state seal_state;
31 };
32
33 union ntlmssp_crypt_state {
34         /* NTLM */
35         struct ntlmssp_crypt_direction ntlm;
36
37         /* NTLM2 */
38         struct {
39                 struct ntlmssp_crypt_direction sending;
40                 struct ntlmssp_crypt_direction receiving;
41         } ntlm2;
42 };
43
44 /* The following definitions come from auth/ntlmssp.c  */
45
46 NTSTATUS gensec_ntlmssp_update(struct gensec_security *gensec_security,
47                                TALLOC_CTX *out_mem_ctx,
48                                struct tevent_context *ev,
49                                const DATA_BLOB input, DATA_BLOB *out);
50
51 /* The following definitions come from auth/ntlmssp_util.c  */
52
53 void debug_ntlmssp_flags(uint32_t neg_flags);
54 void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
55                               uint32_t neg_flags, bool allow_lm);
56
57 /* The following definitions come from auth/ntlmssp_server.c  */
58
59 const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
60                                 uint32_t neg_flags, uint32_t *chal_flags);
61 NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
62                                   TALLOC_CTX *out_mem_ctx,
63                                   const DATA_BLOB in, DATA_BLOB *out);
64 NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
65                              TALLOC_CTX *out_mem_ctx,
66                              const DATA_BLOB request, DATA_BLOB *reply);
67 /* The following definitions come from auth/ntlmssp/ntlmssp_client.c  */
68
69
70 /**
71  * Next state function for the Initial packet
72  *
73  * @param ntlmssp_state NTLMSSP State
74  * @param out_mem_ctx The DATA_BLOB *out will be allocated on this context
75  * @param in A NULL data blob (input ignored)
76  * @param out The initial negotiate request to the server, as an talloc()ed DATA_BLOB, on out_mem_ctx
77  * @return Errors or NT_STATUS_OK.
78  */
79 NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security,
80                                 TALLOC_CTX *out_mem_ctx,
81                                 DATA_BLOB in, DATA_BLOB *out) ;
82
83 /**
84  * Next state function for the Challenge Packet.  Generate an auth packet.
85  *
86  * @param gensec_security GENSEC state
87  * @param out_mem_ctx Memory context for *out
88  * @param in The server challnege, as a DATA_BLOB.  reply.data must be NULL
89  * @param out The next request (auth packet) to the server, as an allocated DATA_BLOB, on the out_mem_ctx context
90  * @return Errors or NT_STATUS_OK.
91  */
92 NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security,
93                                   TALLOC_CTX *out_mem_ctx,
94                                   const DATA_BLOB in, DATA_BLOB *out) ;
95 NTSTATUS gensec_ntlmssp_client_start(struct gensec_security *gensec_security);
96
97 /* The following definitions come from auth/ntlmssp/ntlmssp_server.c  */
98
99
100 /**
101  * Next state function for the Negotiate packet (GENSEC wrapper)
102  *
103  * @param gensec_security GENSEC state
104  * @param out_mem_ctx Memory context for *out
105  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
106  * @param out The reply, as an allocated DATA_BLOB, caller to free.
107  * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
108  */
109 NTSTATUS gensec_ntlmssp_server_negotiate(struct gensec_security *gensec_security,
110                                          TALLOC_CTX *out_mem_ctx,
111                                          const DATA_BLOB request, DATA_BLOB *reply);
112
113 /**
114  * Next state function for the Authenticate packet (GENSEC wrapper)
115  *
116  * @param gensec_security GENSEC state
117  * @param out_mem_ctx Memory context for *out
118  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
119  * @param out The reply, as an allocated DATA_BLOB, caller to free.
120  * @return Errors or NT_STATUS_OK if authentication sucessful
121  */
122 NTSTATUS gensec_ntlmssp_server_auth(struct gensec_security *gensec_security,
123                                     TALLOC_CTX *out_mem_ctx,
124                                     const DATA_BLOB in, DATA_BLOB *out);
125
126 /**
127  * Return the credentials of a logged on user, including session keys
128  * etc.
129  *
130  * Only valid after a successful authentication
131  *
132  * May only be called once per authentication.
133  *
134  */
135 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
136                                      TALLOC_CTX *mem_ctx,
137                                      struct auth_session_info **session_info) ;
138
139 /**
140  * Start NTLMSSP on the server side
141  *
142  */
143 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security);
144
145 /**
146  * Return the challenge as determined by the authentication subsystem
147  * @return an 8 byte random challenge
148  */
149
150 NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
151                                     uint8_t chal[8]);
152
153 /**
154  * Some authentication methods 'fix' the challenge, so we may not be able to set it
155  *
156  * @return If the effective challenge used by the auth subsystem may be modified
157  */
158 bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state);
159
160 /**
161  * NTLM2 authentication modifies the effective challenge,
162  * @param challenge The new challenge value
163  */
164 NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge);
165
166 /**
167  * Check the password on an NTLMSSP login.
168  *
169  * Return the session keys used on the connection.
170  */
171
172 NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
173                                      TALLOC_CTX *mem_ctx,
174                                      DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key);