872e2cd56d2371542d7e73b253bb8dd0b5a8b901
[abartlet/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 void debug_ntlmssp_flags(uint32_t neg_flags);
47 void ntlmssp_handle_neg_flags(struct ntlmssp_state *ntlmssp_state,
48                               uint32_t neg_flags, bool allow_lm);
49
50 /* The following definitions come from auth/ntlmssp_server.c  */
51
52 const char *ntlmssp_target_name(struct ntlmssp_state *ntlmssp_state,
53                                 uint32_t neg_flags, uint32_t *chal_flags);
54 NTSTATUS ntlmssp_server_negotiate(struct ntlmssp_state *ntlmssp_state,
55                                   TALLOC_CTX *out_mem_ctx,
56                                   const DATA_BLOB in, DATA_BLOB *out);
57 NTSTATUS ntlmssp_server_auth(struct ntlmssp_state *ntlmssp_state,
58                              TALLOC_CTX *out_mem_ctx,
59                              const DATA_BLOB request, DATA_BLOB *reply);
60 /* The following definitions come from auth/ntlmssp/ntlmssp_client.c  */
61
62
63 /**
64  * Next state function for the Initial packet
65  * 
66  * @param ntlmssp_state NTLMSSP State
67  * @param out_mem_ctx The DATA_BLOB *out will be allocated on this context
68  * @param in A NULL data blob (input ignored)
69  * @param out The initial negotiate request to the server, as an talloc()ed DATA_BLOB, on out_mem_ctx
70  * @return Errors or NT_STATUS_OK. 
71  */
72 NTSTATUS ntlmssp_client_initial(struct gensec_security *gensec_security, 
73                                 TALLOC_CTX *out_mem_ctx, 
74                                 DATA_BLOB in, DATA_BLOB *out) ;
75
76 /**
77  * Next state function for the Challenge Packet.  Generate an auth packet.
78  * 
79  * @param gensec_security GENSEC state
80  * @param out_mem_ctx Memory context for *out
81  * @param in The server challnege, as a DATA_BLOB.  reply.data must be NULL
82  * @param out The next request (auth packet) to the server, as an allocated DATA_BLOB, on the out_mem_ctx context
83  * @return Errors or NT_STATUS_OK. 
84  */
85 NTSTATUS ntlmssp_client_challenge(struct gensec_security *gensec_security, 
86                                   TALLOC_CTX *out_mem_ctx,
87                                   const DATA_BLOB in, DATA_BLOB *out) ;
88 NTSTATUS gensec_ntlmssp_client_start(struct gensec_security *gensec_security);
89
90 /* The following definitions come from auth/ntlmssp/ntlmssp_server.c  */
91
92
93 /**
94  * Next state function for the Negotiate packet (GENSEC wrapper)
95  *
96  * @param gensec_security GENSEC state
97  * @param out_mem_ctx Memory context for *out
98  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
99  * @param out The reply, as an allocated DATA_BLOB, caller to free.
100  * @return Errors or MORE_PROCESSING_REQUIRED if (normal) a reply is required.
101  */
102 NTSTATUS gensec_ntlmssp_server_negotiate(struct gensec_security *gensec_security,
103                                          TALLOC_CTX *out_mem_ctx,
104                                          const DATA_BLOB request, DATA_BLOB *reply);
105
106 /**
107  * Next state function for the Authenticate packet (GENSEC wrapper)
108  *
109  * @param gensec_security GENSEC state
110  * @param out_mem_ctx Memory context for *out
111  * @param in The request, as a DATA_BLOB.  reply.data must be NULL
112  * @param out The reply, as an allocated DATA_BLOB, caller to free.
113  * @return Errors or NT_STATUS_OK if authentication sucessful
114  */
115 NTSTATUS gensec_ntlmssp_server_auth(struct gensec_security *gensec_security,
116                                     TALLOC_CTX *out_mem_ctx,
117                                     const DATA_BLOB in, DATA_BLOB *out);
118
119 /** 
120  * Return the credentials of a logged on user, including session keys
121  * etc.
122  *
123  * Only valid after a successful authentication
124  *
125  * May only be called once per authentication.
126  *
127  */
128 NTSTATUS gensec_ntlmssp_session_info(struct gensec_security *gensec_security,
129                                      TALLOC_CTX *mem_ctx,
130                                      struct auth_session_info **session_info) ;
131
132 /**
133  * Start NTLMSSP on the server side 
134  *
135  */
136 NTSTATUS gensec_ntlmssp_server_start(struct gensec_security *gensec_security);
137
138 /**
139  * Return the challenge as determined by the authentication subsystem 
140  * @return an 8 byte random challenge
141  */
142
143 NTSTATUS auth_ntlmssp_get_challenge(const struct ntlmssp_state *ntlmssp_state,
144                                     uint8_t chal[8]);
145
146 /**
147  * Some authentication methods 'fix' the challenge, so we may not be able to set it
148  *
149  * @return If the effective challenge used by the auth subsystem may be modified
150  */
151 bool auth_ntlmssp_may_set_challenge(const struct ntlmssp_state *ntlmssp_state);
152
153 /**
154  * NTLM2 authentication modifies the effective challenge, 
155  * @param challenge The new challenge value
156  */
157 NTSTATUS auth_ntlmssp_set_challenge(struct ntlmssp_state *ntlmssp_state, DATA_BLOB *challenge);
158
159 /**
160  * Check the password on an NTLMSSP login.  
161  *
162  * Return the session keys used on the connection.
163  */
164
165 NTSTATUS auth_ntlmssp_check_password(struct ntlmssp_state *ntlmssp_state,
166                                      TALLOC_CTX *mem_ctx,
167                                      DATA_BLOB *user_session_key, DATA_BLOB *lm_session_key);
168