ntlmauth.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_LIB_NTLMAUTH_NTLMAUTH_H
10 #define SQUID_LIB_NTLMAUTH_NTLMAUTH_H
11 
12 /* NP: All of this cruft is little endian */
13 /* Endian functions are usually handled by the OS but not always. */
15 
16 /* Used internally. Microsoft seems to think this is right, I believe them.
17  * Right. */
18 #define NTLM_MAX_FIELD_LENGTH 300 /* max length of an NTLMSSP field */
19 
20 /* max length of the BLOB data. (and helper input/output buffer) */
21 #define NTLM_BLOB_BUFFER_SIZE 10240
22 
23 /* Here start the NTLMSSP definitions */
24 
25 /* these are marked as "extra" fields */
26 #define NTLM_REQUEST_INIT_RESPONSE 0x100000
27 #define NTLM_REQUEST_ACCEPT_RESPONSE 0x200000
28 #define NTLM_REQUEST_NON_NT_SESSION_KEY 0x400000
29 
30 /* NTLM error codes */
31 enum class NtlmError
32 {
33  None = 0,
36  LoginEror,
39  SspiError,
40  BadNtGroup,
41  BadRequest,
43  BlobError,
45 };
46 
48 typedef struct _strhdr {
49  int16_t len;
50  int16_t maxlen;
51  int32_t offset;
52 } strhdr;
53 
55 typedef struct _lstring {
56  int32_t l;
57  char *str;
58 } lstring;
59 
61 void ntlm_dump_ntlmssp_flags(const uint32_t flags);
62 
63 /* ************************************************************************* */
64 /* Packet and Payload structures and handling functions */
65 /* ************************************************************************* */
66 
67 /* NTLM request types that we know about */
68 #define NTLM_ANY 0
69 #define NTLM_NEGOTIATE 1
70 #define NTLM_CHALLENGE 2
71 #define NTLM_AUTHENTICATE 3
72 
76 typedef struct _ntlmhdr {
77  char signature[8];
78  int32_t type;
79 } ntlmhdr;
80 
82 NtlmError ntlm_validate_packet(const ntlmhdr *packet, const int32_t type);
83 
85 lstring ntlm_fetch_string(const ntlmhdr *packet,
86  const int32_t packet_length,
87  const strhdr *str,
88  const uint32_t flags);
89 
91 void ntlm_add_to_payload(const ntlmhdr *packet_hdr,
92  char *payload,
93  int *payload_length,
94  strhdr * hdr,
95  const char *toadd,
96  const uint16_t toadd_length);
97 
98 /* ************************************************************************* */
99 /* Negotiate Packet structures and functions */
100 /* ************************************************************************* */
101 
102 /* negotiate request flags */
103 #define NTLM_NEGOTIATE_UNICODE 0x0001
104 #define NTLM_NEGOTIATE_ASCII 0x0002
105 #define NTLM_NEGOTIATE_REQUEST_TARGET 0x0004
106 #define NTLM_NEGOTIATE_REQUEST_SIGN 0x0010
107 #define NTLM_NEGOTIATE_REQUEST_SEAL 0x0020
108 #define NTLM_NEGOTIATE_DATAGRAM_STYLE 0x0040
109 #define NTLM_NEGOTIATE_USE_LM 0x0080
110 #define NTLM_NEGOTIATE_USE_NETWARE 0x0100
111 #define NTLM_NEGOTIATE_USE_NTLM 0x0200
112 #define NTLM_NEGOTIATE_DOMAIN_SUPPLIED 0x1000
113 #define NTLM_NEGOTIATE_WORKSTATION_SUPPLIED 0x2000
114 #define NTLM_NEGOTIATE_THIS_IS_LOCAL_CALL 0x4000
115 #define NTLM_NEGOTIATE_ALWAYS_SIGN 0x8000
116 
118 typedef struct _ntlm_negotiate {
120  uint32_t flags;
123  char payload[256];
125 
126 /* ************************************************************************* */
127 /* Challenge Packet structures and functions */
128 /* ************************************************************************* */
129 
130 #define NTLM_NONCE_LEN 8
131 
132 /* challenge request flags */
133 #define NTLM_CHALLENGE_TARGET_IS_DOMAIN 0x10000
134 #define NTLM_CHALLENGE_TARGET_IS_SERVER 0x20000
135 #define NTLM_CHALLENGE_TARGET_IS_SHARE 0x40000
136 
138 typedef struct _ntlm_challenge {
141  uint32_t flags;
143  uint32_t context_low;
144  uint32_t context_high;
145  char payload[256];
147 
148 /* Size of the ntlm_challenge structures formatted fields (excluding payload) */
149 #define NTLM_CHALLENGE_HEADER_OFFSET (sizeof(ntlm_challenge)-256)
150 
152 void ntlm_make_nonce(char *nonce);
153 
158  const char *domain,
159  const char *domain_controller,
160  const char *challenge_nonce,
161  const int challenge_nonce_len,
162  const uint32_t flags);
163 
164 /* ************************************************************************* */
165 /* Authenticate Packet structures and functions */
166 /* ************************************************************************* */
167 
169 typedef struct _ntlm_authenticate {
177  uint32_t flags;
178  char payload[256 * 6];
180 
183  char *user,
184  char *domain,
185  const int32_t size);
186 
187 #endif /* SQUID_LIB_NTLMAUTH_NTLMAUTH_H */
188 
char * str
Definition: ntlmauth.h:57
char payload[256 *6]
Definition: ntlmauth.h:178
char payload[256]
Definition: ntlmauth.h:145
lstring ntlm_fetch_string(const ntlmhdr *packet, const int32_t packet_length, const strhdr *str, const uint32_t flags)
Definition: ntlmauth.cc:98
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:209
uint32_t context_high
Definition: ntlmauth.h:144
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:164
NtlmError
Definition: ntlmauth.h:31
struct _lstring lstring
uint32_t flags
Definition: ntlmauth.h:141
uint32_t context_low
Definition: ntlmauth.h:143
int size
Definition: ModDevPoll.cc:69
NtlmError ntlm_unpack_auth(const ntlm_authenticate *auth, char *user, char *domain, const int32_t size)
Definition: ntlmauth.cc:246
u_char challenge[NTLM_NONCE_LEN]
Definition: ntlmauth.h:142
int16_t len
Definition: ntlmauth.h:49
int32_t l
Definition: ntlmauth.h:56
ntlmhdr hdr
Definition: ntlmauth.h:119
uint32_t flags
Definition: ntlmauth.h:177
strhdr workstation
Definition: ntlmauth.h:175
void ntlm_dump_ntlmssp_flags(const uint32_t flags)
Definition: ntlmauth.cc:30
ntlmhdr hdr
Definition: ntlmauth.h:139
struct _ntlm_negotiate ntlm_negotiate
strhdr target
Definition: ntlmauth.h:140
char signature[8]
Definition: ntlmauth.h:77
int32_t type
Definition: ntlmauth.h:78
strhdr domain
Definition: ntlmauth.h:121
struct _strhdr strhdr
struct _ntlmhdr ntlmhdr
struct _ntlm_challenge ntlm_challenge
strhdr workstation
Definition: ntlmauth.h:122
NtlmError ntlm_validate_packet(const ntlmhdr *packet, const int32_t type)
Definition: ntlmauth.cc:67
int32_t offset
Definition: ntlmauth.h:51
uint32_t flags
Definition: ntlmauth.h:120
int16_t maxlen
Definition: ntlmauth.h:50
struct _ntlm_authenticate ntlm_authenticate
#define NTLM_NONCE_LEN
Definition: ntlmauth.h:130
char payload[256]
Definition: ntlmauth.h:123
void ntlm_make_nonce(char *nonce)
Definition: ntlmauth.cc:195

 

Introduction

Documentation

Support

Miscellaneous