]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/external/kerberos_ldap_group/support.h
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / acl / external / kerberos_ldap_group / support.h
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 /*
10 * -----------------------------------------------------------------------------
11 *
12 * Author: Markus Moeller (markus_moeller at compuserve.com)
13 *
14 * Copyright (C) 2007 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
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
29 *
30 * -----------------------------------------------------------------------------
31 */
32
33 #define KERBEROS_LDAP_GROUP_VERSION "1.4.0sq"
34
35 #include "compat/krb5.h"
36
37 #include <cstring>
38 #if HAVE_COM_ERR_H
39 #include <com_err.h>
40 #endif /* HAVE_COM_ERR_H */
41 #define LDAP_DEPRECATED 1
42 #if HAVE_LDAP_REBIND_FUNCTION
43 #define LDAP_REFERRALS
44 #endif
45 #if HAVE_LBER_H
46 #include <lber.h>
47 #endif
48 #if HAVE_LDAP_H
49 #include <ldap.h>
50 #endif
51 #if HAVE_MOZLDAP_LDAP_H
52 #include <mozldap/ldap.h>
53 #endif
54
55 struct gdstruct {
56 char *group;
57 char *domain;
58 struct gdstruct *next;
59 };
60 struct ndstruct {
61 char *netbios;
62 char *domain;
63 struct ndstruct *next;
64 };
65 struct lsstruct {
66 char *lserver;
67 char *domain;
68 struct lsstruct *next;
69 };
70
71 struct main_args {
72 char *glist;
73 char *ulist;
74 char *tlist;
75 char *nlist;
76 char *llist;
77 char *luser;
78 char *lpass;
79 char *lbind;
80 char *lurl;
81 char *ssl;
82 int rc_allow;
83 int AD;
84 int mdepth;
85 int nokerberos;
86 char *ddomain;
87 struct gdstruct *groups;
88 struct ndstruct *ndoms;
89 struct lsstruct *lservs;
90 char *principal;
91 };
92
93 SQUIDCEXTERN int log_enabled;
94
95 /* the macro overload style is really a gcc-ism */
96 #ifdef __GNUC__
97
98 #define log(X...) \
99 if (log_enabled) { \
100 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
101 fprintf(stderr,X); \
102 } else (void)0
103
104 #define error(X...) \
105 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
106 fprintf(stderr,X); \
107
108 #define warn(X...) \
109 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
110 fprintf(stderr,X); \
111
112 #else /* __GNUC__ */
113
114 /* non-GCC compilers can't do the above macro define yet. */
115 void log(char *format,...);
116 void error(char *format,...);
117 void warn(char *format,...);
118 #endif
119
120 struct hstruct {
121 char *host;
122 int port;
123 int priority;
124 int weight;
125 };
126
127 struct ldap_creds {
128 char *dn;
129 char *pw;
130 };
131
132 void init_args(struct main_args *margs);
133 void clean_args(struct main_args *margs);
134 const char *LogTime(void);
135
136 int check_memberof(struct main_args *margs, char *user, char *domain);
137 int get_memberof(struct main_args *margs, char *user, char *domain, char *group);
138
139 char *get_netbios_name(struct main_args *margs, char *netbios);
140
141 int create_gd(struct main_args *margs);
142 int create_nd(struct main_args *margs);
143 int create_ls(struct main_args *margs);
144
145 size_t get_ldap_hostname_list(struct main_args *margs, struct hstruct **hlist, size_t nhosts, char *domain);
146 size_t get_hostname_list(struct hstruct **hlist, size_t nhosts, char *name);
147 size_t free_hostname_list(struct hstruct **hlist, size_t nhosts);
148
149 #if HAVE_SASL_H || HAVE_SASL_SASL_H || HAVE_SASL_DARWIN
150 int tool_sasl_bind(LDAP * ld, char *binddn, char *ssl);
151 #endif
152
153 #if HAVE_KRB5
154 #define MAX_DOMAINS 16
155 #define MAX_SKEW 300
156 struct kstruct {
157 krb5_context context;
158 krb5_ccache cc[MAX_DOMAINS];
159 char* mem_ccache[MAX_DOMAINS];
160 int ncache;
161 };
162 int krb5_create_cache(char *domain, char* princ);
163 void krb5_cleanup(void);
164 #endif
165
166 #define PROGRAM "kerberos_ldap_group"
167