]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/external/kerberos_ldap_group/support.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / external / kerberos_ldap_group / support.h
1 /*
2 * Copyright (C) 1996-2017 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 <cstring>
36
37 #if USE_APPLE_KRB5
38 #define KERBEROS_APPLE_DEPRECATED(x)
39 #endif
40
41 #if HAVE_KRB5_H
42 #if HAVE_BROKEN_SOLARIS_KRB5_H
43 #warn "Warning! You have a broken Solaris <krb5.h> system header"
44 #warn "http://bugs.opensolaris.org/bugdatabase/view_bug.do?bug_id=6837512"
45 #if defined(__cplusplus)
46 #define KRB5INT_BEGIN_DECLS extern "C" {
47 #define KRB5INT_END_DECLS
48 KRB5INT_BEGIN_DECLS
49 #endif
50 #endif /* HAVE_BROKEN_SOLARIS_KRB5_H */
51 #if HAVE_BROKEN_HEIMDAL_KRB5_H
52 extern "C" {
53 #include <krb5.h>
54 }
55 #else
56 #include <krb5.h>
57 #endif
58 #endif /* HAVE_KRB5_H */
59
60 #if HAVE_COM_ERR_H
61 #include <com_err.h>
62 #endif /* HAVE_COM_ERR_H */
63
64 #define LDAP_DEPRECATED 1
65 #if HAVE_LDAP_REBIND_FUNCTION
66 #define LDAP_REFERRALS
67 #endif
68 #if HAVE_LBER_H
69 #include <lber.h>
70 #endif
71 #if HAVE_LDAP_H
72 #include <ldap.h>
73 #endif
74 #if HAVE_MOZLDAP_LDAP_H
75 #include <mozldap/ldap.h>
76 #endif
77
78 struct gdstruct {
79 char *group;
80 char *domain;
81 struct gdstruct *next;
82 };
83 struct ndstruct {
84 char *netbios;
85 char *domain;
86 struct ndstruct *next;
87 };
88 struct lsstruct {
89 char *lserver;
90 char *domain;
91 struct lsstruct *next;
92 };
93
94 struct main_args {
95 char *glist;
96 char *ulist;
97 char *tlist;
98 char *nlist;
99 char *llist;
100 char *luser;
101 char *lpass;
102 char *lbind;
103 char *lurl;
104 char *ssl;
105 int rc_allow;
106 int AD;
107 int mdepth;
108 int nokerberos;
109 char *ddomain;
110 struct gdstruct *groups;
111 struct ndstruct *ndoms;
112 struct lsstruct *lservs;
113 };
114
115 SQUIDCEXTERN int log_enabled;
116
117 /* the macro overload style is really a gcc-ism */
118 #ifdef __GNUC__
119
120 #define log(X...) \
121 if (log_enabled) { \
122 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
123 fprintf(stderr,X); \
124 } else (void)0
125
126 #define error(X...) \
127 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
128 fprintf(stderr,X); \
129
130 #define warn(X...) \
131 fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
132 fprintf(stderr,X); \
133
134 #else /* __GNUC__ */
135
136 /* non-GCC compilers can't do the above macro define yet. */
137 void log(char *format,...);
138 void error(char *format,...);
139 void warn(char *format,...);
140 #endif
141
142 struct hstruct {
143 char *host;
144 int port;
145 int priority;
146 int weight;
147 };
148
149 struct ldap_creds {
150 char *dn;
151 char *pw;
152 };
153
154 void init_args(struct main_args *margs);
155 void clean_args(struct main_args *margs);
156 const char *LogTime(void);
157
158 int check_memberof(struct main_args *margs, char *user, char *domain);
159 int get_memberof(struct main_args *margs, char *user, char *domain, char *group);
160
161 char *get_netbios_name(struct main_args *margs, char *netbios);
162
163 int create_gd(struct main_args *margs);
164 int create_nd(struct main_args *margs);
165 int create_ls(struct main_args *margs);
166
167 size_t get_ldap_hostname_list(struct main_args *margs, struct hstruct **hlist, size_t nhosts, char *domain);
168 size_t get_hostname_list(struct hstruct **hlist, size_t nhosts, char *name);
169 size_t free_hostname_list(struct hstruct **hlist, size_t nhosts);
170
171 #if HAVE_SASL_H || HAVE_SASL_SASL_H || HAVE_SASL_DARWIN
172 int tool_sasl_bind(LDAP * ld, char *binddn, char *ssl);
173 #endif
174
175 #if HAVE_KRB5
176 #define MAX_DOMAINS 16
177 #define MAX_SKEW 300
178 struct kstruct {
179 krb5_context context;
180 krb5_ccache cc[MAX_DOMAINS];
181 char* mem_ccache[MAX_DOMAINS];
182 int ncache;
183 };
184 int krb5_create_cache(char *domain);
185 void krb5_cleanup(void);
186 #endif
187
188 #define PROGRAM "kerberos_ldap_group"
189