ntlmauth.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_NTLMAUTH_H
10 #define SQUID_NTLMAUTH_H
11 
12 /* NP: All of this cruft is little endian */
13 /* Endian functions are usualy handled by the OS but not always. */
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* Used internally. Microsoft seems to think this is right, I believe them.
21  * Right. */
22 #define NTLM_MAX_FIELD_LENGTH 300 /* max length of an NTLMSSP field */
23 
24 /* max length of the BLOB data. (and helper input/output buffer) */
25 #define NTLM_BLOB_BUFFER_SIZE 10240
26 
27 /* Here start the NTLMSSP definitions */
28 
29 /* these are marked as "extra" fields */
30 #define NTLM_REQUEST_INIT_RESPONSE 0x100000
31 #define NTLM_REQUEST_ACCEPT_RESPONSE 0x200000
32 #define NTLM_REQUEST_NON_NT_SESSION_KEY 0x400000
33 
34 /* NTLM error codes */
35 #define NTLM_ERR_INTERNAL -3
36 #define NTLM_ERR_BLOB -2
37 #define NTLM_ERR_BAD_PROTOCOL -1
38 #define NTLM_ERR_NONE 0 /* aka. SMBLM_ERR_NONE */
39 /* codes used by smb_lm helper */
40 #define NTLM_ERR_SERVER 1 /* aka. SMBLM_ERR_SERVER */
41 #define NTLM_ERR_PROTOCOL 2 /* aka. SMBLM_ERR_PROTOCOL */
42 #define NTLM_ERR_LOGON 3 /* aka. SMBLM_ERR_LOGON */
43 #define NTLM_ERR_UNTRUSTED_DOMAIN 4
44 #define NTLM_ERR_NOT_CONNECTED 10
45 /* codes used by mswin_ntlmsspi helper */
46 #define NTLM_SSPI_ERROR 1
47 #define NTLM_BAD_NTGROUP 2
48 #define NTLM_BAD_REQUEST 3
49 /* TODO: reduce the above codes down to one set non-overlapping. */
50 
52 typedef struct _strhdr {
53  int16_t len;
54  int16_t maxlen;
55  int32_t offset;
56 } strhdr;
57 
59 typedef struct _lstring {
60  int32_t l;
61  char *str;
62 } lstring;
63 
65 void ntlm_dump_ntlmssp_flags(const uint32_t flags);
66 
67 /* ************************************************************************* */
68 /* Packet and Payload structures and handling functions */
69 /* ************************************************************************* */
70 
71 /* NTLM request types that we know about */
72 #define NTLM_ANY 0
73 #define NTLM_NEGOTIATE 1
74 #define NTLM_CHALLENGE 2
75 #define NTLM_AUTHENTICATE 3
76 
80 typedef struct _ntlmhdr {
81  char signature[8];
82  int32_t type;
83 } ntlmhdr;
84 
86 int ntlm_validate_packet(const ntlmhdr *packet, const int32_t type);
87 
89 lstring ntlm_fetch_string(const ntlmhdr *packet,
90  const int32_t packet_length,
91  const strhdr *str,
92  const uint32_t flags);
93 
95 void ntlm_add_to_payload(const ntlmhdr *packet_hdr,
96  char *payload,
97  int *payload_length,
98  strhdr * hdr,
99  const char *toadd,
100  const uint16_t toadd_length);
101 
102 /* ************************************************************************* */
103 /* Negotiate Packet structures and functions */
104 /* ************************************************************************* */
105 
106 /* negotiate request flags */
107 #define NTLM_NEGOTIATE_UNICODE 0x0001
108 #define NTLM_NEGOTIATE_ASCII 0x0002
109 #define NTLM_NEGOTIATE_REQUEST_TARGET 0x0004
110 #define NTLM_NEGOTIATE_REQUEST_SIGN 0x0010
111 #define NTLM_NEGOTIATE_REQUEST_SEAL 0x0020
112 #define NTLM_NEGOTIATE_DATAGRAM_STYLE 0x0040
113 #define NTLM_NEGOTIATE_USE_LM 0x0080
114 #define NTLM_NEGOTIATE_USE_NETWARE 0x0100
115 #define NTLM_NEGOTIATE_USE_NTLM 0x0200
116 #define NTLM_NEGOTIATE_DOMAIN_SUPPLIED 0x1000
117 #define NTLM_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
118 #define NTLM_NEGOTIATE_THIS_IS_LOCAL_CALL 0x4000
119 #define NTLM_NEGOTIATE_ALWAYS_SIGN 0x8000
120 
122 typedef struct _ntlm_negotiate {
124  uint32_t flags;
127  char payload[256];
129 
130 /* ************************************************************************* */
131 /* Challenge Packet structures and functions */
132 /* ************************************************************************* */
133 
134 #define NTLM_NONCE_LEN 8
135 
136 /* challenge request flags */
137 #define NTLM_CHALLENGE_TARGET_IS_DOMAIN 0x10000
138 #define NTLM_CHALLENGE_TARGET_IS_SERVER 0x20000
139 #define NTLM_CHALLENGE_TARGET_IS_SHARE 0x40000
140 
142 typedef struct _ntlm_challenge {
145  uint32_t flags;
147  uint32_t context_low;
148  uint32_t context_high;
149  char payload[256];
151 
152 /* Size of the ntlm_challenge structures formatted fields (excluding payload) */
153 #define NTLM_CHALLENGE_HEADER_OFFSET (sizeof(ntlm_challenge)-256)
154 
156 void ntlm_make_nonce(char *nonce);
157 
162  const char *domain,
163  const char *domain_controller,
164  const char *challenge_nonce,
165  const int challenge_nonce_len,
166  const uint32_t flags);
167 
168 /* ************************************************************************* */
169 /* Authenticate Packet structures and functions */
170 /* ************************************************************************* */
171 
173 typedef struct _ntlm_authenticate {
181  uint32_t flags;
182  char payload[256 * 6];
184 
186 int ntlm_unpack_auth(const ntlm_authenticate *auth,
187  char *user,
188  char *domain,
189  const int32_t size);
190 
191 #if __cplusplus
192 }
193 #endif
194 
195 #endif /* SQUID_NTLMAUTH_H */
196 
strhdr workstation
Definition: ntlmauth.h:126
uint32_t flags
Definition: ntlmauth.h:124
char payload[256]
Definition: ntlmauth.h:127
struct _ntlmhdr ntlmhdr
char payload[256]
Definition: ntlmauth.h:149
int type
Definition: errorpage.cc:79
strhdr workstation
Definition: ntlmauth.h:179
void ntlm_make_challenge(ntlm_challenge *ch, const char *domain, const char *domain_controller, const char *challenge_nonce, const int challenge_nonce_len, const uint32_t flags)
Definition: ntlmauth.cc:199
int32_t offset
Definition: ntlmauth.h:55
int ntlm_unpack_auth(const ntlm_authenticate *auth, char *user, char *domain, const int32_t size)
Definition: ntlmauth.cc:236
int16_t len
Definition: ntlmauth.h:53
char signature[8]
Definition: ntlmauth.h:81
lstring ntlm_fetch_string(const ntlmhdr *packet, const int32_t packet_length, const strhdr *str, const uint32_t flags)
Definition: ntlmauth.cc:97
uint32_t flags
Definition: ntlmauth.h:145
void ntlm_add_to_payload(const ntlmhdr *packet_hdr, char *payload, int *payload_length, strhdr *hdr, const char *toadd, const uint16_t toadd_length)
Definition: ntlmauth.cc:154
uint32_t context_high
Definition: ntlmauth.h:148
uint32_t context_low
Definition: ntlmauth.h:147
int32_t type
Definition: ntlmauth.h:82
ntlmhdr hdr
Definition: ntlmauth.h:123
struct _strhdr strhdr
u_char challenge[NTLM_NONCE_LEN]
Definition: ntlmauth.h:146
struct _ntlm_authenticate ntlm_authenticate
struct _ntlm_negotiate ntlm_negotiate
strhdr domain
Definition: ntlmauth.h:125
char payload[256 *6]
Definition: ntlmauth.h:182
int32_t l
Definition: ntlmauth.h:60
void ntlm_dump_ntlmssp_flags(const uint32_t flags)
Definition: ntlmauth.cc:29
int ntlm_validate_packet(const ntlmhdr *packet, const int32_t type)
Definition: ntlmauth.cc:66
ntlmhdr hdr
Definition: ntlmauth.h:143
strhdr target
Definition: ntlmauth.h:144
int16_t maxlen
Definition: ntlmauth.h:54
struct _ntlm_challenge ntlm_challenge
char * str
Definition: ntlmauth.h:61
#define NTLM_NONCE_LEN
Definition: ntlmauth.h:134
void ntlm_make_nonce(char *nonce)
Definition: ntlmauth.cc:185
struct _lstring lstring
uint32_t flags
Definition: ntlmauth.h:181
int size
Definition: ModDevPoll.cc:77

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors