]> git.ipfire.org Git - thirdparty/squid.git/blame - helpers/ntlm_auth/fakeauth/ntlm.h
SourceFormat: enforcement
[thirdparty/squid.git] / helpers / ntlm_auth / fakeauth / ntlm.h
CommitLineData
94439e4e 1/*
262a0e14 2 * $Id$
94439e4e 3 *
5d146f7d 4 * AUTHOR: Andrew Doran <ad@interlude.eu.org>
94439e4e 5 *
2b6662ba 6 * SQUID Web Proxy Cache http://www.squid-cache.org/
7 * ----------------------------------------------------------
94439e4e 8 *
2b6662ba 9 * Squid is the result of efforts by numerous individuals from
10 * the Internet community; see the CONTRIBUTORS file for full
11 * details. Many organizations have provided support for Squid's
12 * development; see the SPONSORS file for full details. Squid is
13 * Copyrighted (C) 2001 by the Regents of the University of
14 * California; see the COPYRIGHT file for full details. Squid
15 * incorporates software developed and/or copyrighted by other
16 * sources; see the CREDITS file for full details.
94439e4e 17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
26ac0430 22 *
94439e4e 23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
26ac0430 27 *
94439e4e 28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26ac0430 31 *
94439e4e 32 */
33
34#ifndef _NTLM_H_
35#define _NTLM_H_
36
37/* undefine this to have strict protocol adherence. You don't really need
38 * that though */
39#define IGNORANCE_IS_BLISS
40
41#include <sys/types.h>
42
43/* All of this cruft is little endian */
f9576890 44#include "squid_endian.h"
94439e4e 45
46/* NTLM request types that we know about */
94439e4e 47#define NTLM_ANY 0
48
94439e4e 49/* Negotiation request sent by client */
50struct ntlm_negotiate {
51 ntlmhdr hdr; /* NTLM header */
52 int32_t flags; /* Request flags */
53 strhdr domain; /* Domain we wish to authenticate in */
54 strhdr workstation; /* Client workstation name */
55 char pad[256]; /* String data */
56};
57
58/* Challenge request sent by server. */
59struct ntlm_challenge {
60 ntlmhdr hdr; /* NTLM header */
61 strhdr target; /* Authentication target (domain/server ...) */
62 int32_t flags; /* Request flags */
63 u_char challenge[8]; /* Challenge string */
64 int16_t unknown[8]; /* Some sort of context data */
65 char pad[256]; /* String data */
66};
67
68/* Authentication request sent by client in response to challenge */
69struct ntlm_authenticate {
70 ntlmhdr hdr; /* NTLM header */
71 strhdr lmresponse; /* LANMAN challenge response */
72 strhdr ntresponse; /* NT challenge response */
73 strhdr domain; /* Domain to authenticate against */
74 strhdr user; /* Username */
75 strhdr workstation; /* Workstation name */
76 strhdr sessionkey; /* Session key for server's use */
77 int32_t flags; /* Request flags */
78 char pad[256 * 6]; /* String data */
79};
80
81char *ntlmGetString(ntlmhdr * hdr, strhdr * str, int flags);
0e6205b4 82void ntlmMakeChallenge(struct ntlm_challenge *chal, int32_t flags);
6437ac71 83int ntlmCheckHeader(ntlmhdr * hdr, int type);
94439e4e 84int ntlmCheckNegotiation(struct ntlm_negotiate *neg);
85int ntlmAuthenticate(struct ntlm_authenticate *neg);
86
0e6205b4 87#define safe_free(x) if (x) { free(x); x = NULL; }
88
89#undef debug
90
91/************* CONFIGURATION ***************/
92/*
93 * define this if you want debugging
94 */
95#ifndef DEBUG
96#define DEBUG
97#endif
98
99#define FAIL_DEBUG 0
100
101/************* END CONFIGURATION ***************/
102
103#include <sys/types.h>
104
105extern int debug_enabled;
106#if FAIL_DEBUG
107extern int fail_debug_enabled;
108#endif
109
110/* Debugging stuff */
111
112#ifdef __GNUC__ /* this is really a gcc-ism */
113#ifdef DEBUG
114#include <stdio.h>
115#include <unistd.h>
ccb8b57c 116static const char *__foo;
0e6205b4 117#define debug(X...) if (debug_enabled) { \
ccb8b57c 118 fprintf(stderr,"ntlm-auth[%ld](%s:%d): ", (long)getpid(), \
0e6205b4 119 ((__foo=strrchr(__FILE__,'/'))==NULL?__FILE__:__foo+1),\
120 __LINE__);\
121 fprintf(stderr,X); }
122#else /* DEBUG */
123#define debug(X...) /* */
124#endif /* DEBUG */
125#else /* __GNUC__ */
126static void
127debug(char *format,...)
128{
129#ifdef DEBUG
130#ifdef _SQUID_MSWIN_
131#if FAIL_DEBUG
132 if (debug_enabled || fail_debug_enabled) {
133#else
e1381638 134if (debug_enabled) {
0e6205b4 135#endif
e1381638 136 va_list args;
0e6205b4 137
e1381638
AJ
138 va_start(args, format);
139 fprintf(stderr, "ntlm-auth[%ld]: ", (long)getpid());
140 vfprintf(stderr, format, args);
141 va_end(args);
0e6205b4 142#if FAIL_DEBUG
e1381638 143 fail_debug_enabled = 0;
0e6205b4 144#endif
e1381638 145 }
0e6205b4 146#endif /* _SQUID_MSWIN_ */
147#endif /* DEBUG */
e1381638 148}
0e6205b4 149#endif /* __GNUC__ */
150
151
152/* A couple of harmless helper macros */
153#define SEND(X) debug("sending '%s' to squid\n",X); printf(X "\n");
154#ifdef __GNUC__
155#define SEND2(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
156#else
157/* no gcc, no debugging. varargs macros are a gcc extension */
158#define SEND2(X,Y) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
159#endif
160
94439e4e 161#endif /* _NTLM_H_ */