SPDX: Mass-update to GPL-2.0-or-later
[exim.git] / src / src / auths / auth-spa.h
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /*
6  * This file provides the necessary methods for authenticating with
7  * Microsoft's Secure Password Authentication.
8
9  * All the code used here was torn by Marc Prud'hommeaux out of the
10  * Samba project (by Andrew Tridgell, Jeremy Allison, and others).
11  */
12 /* SPDX-License-Identifier: GPL-2.0-or-later */
13
14 /* December 2004: The spa_base64_to_bits() function has no length checking in
15 it. I have added a check. PH */
16
17 /* It seems that some systems have existing but different definitions of some
18 of the following types. I received a complaint about "int16" causing
19 compilation problems. So I (PH) have renamed them all, to be on the safe side.
20
21 typedef signed short int16;
22 typedef unsigned short uint16;
23 typedef unsigned uint32;
24 typedef unsigned char  uint8;
25 */
26
27 typedef signed short int16x;
28 typedef unsigned short uint16x;
29 typedef unsigned uint32x;
30 typedef unsigned char  uint8x;
31
32 typedef struct
33 {
34        uint16x         len;
35        uint16x         maxlen;
36        uint32x         offset;
37 } SPAStrHeader;
38
39 typedef struct
40 {
41        char         ident[8];
42        uint32x         msgType;
43        SPAStrHeader    uDomain;
44        uint32x         flags;
45        uint8x         challengeData[8];
46        uint8x         reserved[8];
47        SPAStrHeader    emptyString;
48        uint8x         buffer[1024];
49        uint32x         bufIndex;
50 } SPAAuthChallenge;
51
52
53 typedef struct
54 {
55        char         ident[8];
56        uint32x         msgType;
57        uint32x         flags;
58        SPAStrHeader    user;
59        SPAStrHeader    domain;
60        uint8x         buffer[1024];
61        uint32x         bufIndex;
62 } SPAAuthRequest;
63
64 typedef struct
65 {
66        char         ident[8];
67        uint32x         msgType;
68        SPAStrHeader    lmResponse;
69        SPAStrHeader    ntResponse;
70        SPAStrHeader    uDomain;
71        SPAStrHeader    uUser;
72        SPAStrHeader    uWks;
73        SPAStrHeader    sessionKey;
74        uint32x         flags;
75        uint8x         buffer[1024];
76        uint32x         bufIndex;
77 } SPAAuthResponse;
78
79 #define spa_request_length(ptr) (((ptr)->buffer - (uint8x*)(ptr)) + (ptr)->bufIndex)
80
81 void spa_bits_to_base64 (unsigned char *, const unsigned char *, int);
82 int spa_base64_to_bits(char *, int, const char *);
83 void spa_build_auth_response (SPAAuthChallenge *challenge,
84        SPAAuthResponse *response, char *user, char *password);
85 void spa_build_auth_request (SPAAuthRequest *request, char *user,
86        char *domain);
87 extern void spa_smb_encrypt (unsigned char * passwd, unsigned char * c8,
88                              unsigned char * p24);
89 extern void spa_smb_nt_encrypt (unsigned char * passwd, unsigned char * c8,
90                                 unsigned char * p24);
91 extern char *unicodeToString(char *p, size_t len);
92 extern void spa_build_auth_challenge(SPAAuthRequest *, SPAAuthChallenge *);
93