Squid Web Cache v8/master
Loading...
Searching...
No Matches
negotiate_kerberos.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2026 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/*
10 * -----------------------------------------------------------------------------
11 *
12 * Author: Markus Moeller (markus_moeller at compuserve.com)
13 *
14 * Copyright (C) 2013 Markus Moeller. All rights reserved.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License along
27 * with this program; if not, see <https://www.gnu.org/licenses/>.
28 *
29 * As a special exemption, M Moeller gives permission to link this program
30 * with MIT, Heimdal or other GSS/Kerberos libraries, and distribute
31 * the resulting executable, without including the source code for
32 * the Libraries in the source distribution.
33 *
34 * -----------------------------------------------------------------------------
35 */
36
37#ifndef SQUID_SRC_AUTH_NEGOTIATE_KERBEROS_NEGOTIATE_KERBEROS_H
38#define SQUID_SRC_AUTH_NEGOTIATE_KERBEROS_NEGOTIATE_KERBEROS_H
39
40#include <cstring>
41#include <ctime>
42#if HAVE_NETDB_H
43#include <netdb.h>
44#endif
45#if HAVE_UNISTD_H
46#include <unistd.h>
47#endif
48
49#include "base64.h"
50#include "compat/krb5.h"
51#include "util.h"
52
53#if HAVE_GSS_H
54#include <gss.h>
55#endif
56
57#if USE_APPLE_KRB5
58#define GSSKRB_APPLE_DEPRECATED(x)
59#endif
60#if HAVE_GSSAPI_GSSAPI_H
61#include <gssapi/gssapi.h>
62#elif HAVE_GSSAPI_H
63#include <gssapi.h>
64#endif
65#if HAVE_GSSAPI_GSSAPI_KRB5_H
66#include <gssapi/gssapi_krb5.h>
67#endif
68#if HAVE_GSSAPI_GSSAPI_GENERIC_H
69#include <gssapi/gssapi_generic.h>
70#endif
71#if HAVE_GSSAPI_GSSAPI_EXT_H
72#include <gssapi/gssapi_ext.h>
73#endif
74
75#ifndef gss_nt_service_name
76#define gss_nt_service_name GSS_C_NT_HOSTBASED_SERVICE
77#endif
78
79#define PROGRAM "negotiate_kerberos_auth"
80
81#ifndef MAX_AUTHTOKEN_LEN
82#define MAX_AUTHTOKEN_LEN 65535
83#endif
84#ifndef SQUID_KERB_AUTH_VERSION
85#define SQUID_KERB_AUTH_VERSION "3.1.0sq"
86#endif
87
88char *gethost_name(void);
89
90static const unsigned char ntlmProtocol[] = {'N', 'T', 'L', 'M', 'S', 'S', 'P', 0};
91
92inline const char *
94{
95 struct timeval now;
96 static time_t last_t = 0;
97 static char buf[128];
98
99 gettimeofday(&now, nullptr);
100 if (now.tv_sec != last_t) {
101 struct tm *tm;
102 tm = localtime((time_t *) & now.tv_sec);
103 strftime(buf, 127, "%Y/%m/%d %H:%M:%S", tm);
104 last_t = now.tv_sec;
105 }
106 return buf;
107}
108
109int check_gss_err(OM_uint32 major_status, OM_uint32 minor_status,
110 const char *function, int log, int sout);
111
112char *gethost_name(void);
113
114#if HAVE_KRB5_PAC_SUPPORT
128#define MAX_PAC_GROUP_SIZE (1024*98)
129typedef struct {
130 uint16_t length;
131 uint16_t maxlength;
132 uint32_t pointer;
133} RPC_UNICODE_STRING;
134
135void align(int n);
136void getustr(RPC_UNICODE_STRING *string);
137char **getgids(char **Rids, uint32_t GroupIds, uint32_t GroupCount);
138char *getdomaingids(char *ad_groups, uint32_t DomainLogonId, char **Rids, uint32_t GroupCount);
139char *getextrasids(char *ad_groups, uint32_t ExtraSids, uint32_t SidCount);
140uint64_t get6byt_be(void);
141uint32_t get4byt(void);
142uint16_t get2byt(void);
143uint8_t get1byt(void);
144char *xstrcpy( char *src, const char*dst);
145char *xstrcat( char *src, const char*dst);
146int checkustr(RPC_UNICODE_STRING *string);
147char *get_ad_groups(char *ad_groups, krb5_context context, krb5_pac pac);
148#endif /* HAVE_KRB5_PAC_SUPPORT */
149
150int check_k5_err(krb5_context context, const char *msg, krb5_error_code code);
151
152#endif /* SQUID_SRC_AUTH_NEGOTIATE_KERBEROS_NEGOTIATE_KERBEROS_H */
153
void log(char *format,...)
char * gethost_name(void)
const char * LogTime()
int check_gss_err(OM_uint32 major_status, OM_uint32 minor_status, const char *function, int log, int sout)
int check_k5_err(krb5_context context, const char *msg, krb5_error_code code)
static const unsigned char ntlmProtocol[]