]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/external/kerberos_ldap_group/support_group.cc
a45cc00be5745b34c393289c3d20d78593abbe58
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
10 * -----------------------------------------------------------------------------
12 * Author: Markus Moeller (markus_moeller at compuserve.com)
14 * Copyright (C) 2007 Markus Moeller. All rights reserved.
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.
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.
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.
30 * -----------------------------------------------------------------------------
40 struct gdstruct
*init_gd(void);
41 void free_gd(struct gdstruct
*gdsp
);
45 struct gdstruct
*gdsp
;
46 gdsp
= (struct gdstruct
*) xmalloc(sizeof(struct gdstruct
));
54 free_gd(struct gdstruct
*gdsp
)
57 struct gdstruct
*gdspn
= gdsp
->next
;
65 char *utf8dup(struct main_args
*margs
);
68 utf8dup(struct main_args
*margs
)
78 for (n
= 0; n
< strlen(src
); ++n
)
79 if ((unsigned char) src
[n
] > 127)
83 p
= (unsigned char *) xmalloc(strlen(src
) + c
);
85 for (n
= 0; n
< strlen(src
); ++n
) {
87 s
= (unsigned char) src
[n
];
88 if (s
> 127 && s
< 192) {
101 debug((char *) "%s| %s: INFO: Group %s as UTF-8: %s\n", LogTime(), PROGRAM
, src
, dupp
);
102 return (char *) dupp
;
107 char *hex_utf_char(struct main_args
*margs
, int flag
);
109 * UTF8 = UTF1 / UTFMB
110 * UTFMB = UTF2 / UTF3 / UTF4
114 * UTF2 = %xC2-DF UTF0
115 * UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
116 * %xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
117 * UTF4 = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
118 * %xF4 %x80-8F 2(UTF0)
120 * http://www.utf8-chartable.de/unicode-utf8-table.pl
124 hex_utf_char(struct main_args
*margs
, int flag
)
127 int iUTF2
, iUTF3
, iUTF4
;
129 char *up
= (flag
? margs
->ulist
: margs
->tlist
);
133 char *upd
= strrchr(up
, '@');
134 size_t a
= (upd
? (size_t)(upd
- up
) : strlen(up
) );
136 char *ul
= (char *) xmalloc(strlen(up
)+1);
143 while (n
< strlen(up
)) {
153 if (ival
> 64 && ival
< 71)
154 ichar
= (ival
- 55) * 16;
155 else if (ival
> 96 && ival
< 103)
156 ichar
= (ival
- 87) * 16;
157 else if (ival
> 47 && ival
< 58)
158 ichar
= (ival
- 48) * 16;
160 debug((char *) "%s| %s: WARNING: Invalid Hex value %c\n", LogTime(), PROGRAM
, ival
);
166 debug((char *) "%s| %s: WARNING: Invalid Hex UTF-8 string %s\n", LogTime(), PROGRAM
, up
);
172 if (ival
> 64 && ival
< 71)
173 ichar
= ichar
+ ival
- 55;
174 else if (ival
> 96 && ival
< 103)
175 ichar
= ichar
+ ival
- 87;
176 else if (ival
> 47 && ival
< 58)
177 ichar
= ichar
+ ival
- 48;
179 debug((char *) "%s| %s: WARNING: Invalid Hex value %c\n", LogTime(), PROGRAM
, ival
);
185 if (iUTF2
== 0xC2 && ichar
> 0x7F && ichar
< 0xC0) {
187 ul
[nl
- 1] = (char)ichar
;
188 } else if (iUTF2
== 0xC3 && ichar
> 0x7F && ichar
< 0xC0) {
190 ul
[nl
- 1] = (char)(ichar
+ 64);
191 } else if (iUTF2
> 0xC3 && iUTF2
< 0xE0 && ichar
> 0x7F && ichar
< 0xC0) {
193 ul
[nl
] = (char)ichar
;
197 ul
[nl
] = (char)ichar
;
199 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
204 if (iUTF3
== 0xE0 && ichar
> 0x9F && ichar
< 0xC0) {
206 ul
[nl
] = (char)ichar
;
208 } else if (iUTF3
> 0xE0 && iUTF3
< 0xED && ichar
> 0x7F && ichar
< 0xC0) {
210 ul
[nl
] = (char)ichar
;
212 } else if (iUTF3
== 0xED && ichar
> 0x7F && ichar
< 0xA0) {
214 ul
[nl
] = (char)ichar
;
216 } else if (iUTF3
> 0xED && iUTF3
< 0xF0 && ichar
> 0x7F && ichar
< 0xC0) {
218 ul
[nl
] = (char)ichar
;
220 } else if (iUTF3
> 0 && iUTF3
< 5 && ichar
> 0x7F && ichar
< 0xC0) {
222 ul
[nl
] = (char)ichar
;
226 ul
[nl
] = (char)ichar
;
228 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
233 if (iUTF4
== 0xF0 && ichar
> 0x8F && ichar
< 0xC0) {
235 ul
[nl
] = (char)ichar
;
237 } else if (iUTF4
> 0xF0 && iUTF3
< 0xF4 && ichar
> 0x7F && ichar
< 0xC0) {
239 ul
[nl
] = (char)ichar
;
241 } else if (iUTF4
== 0xF4 && ichar
> 0x7F && ichar
< 0x90) {
243 ul
[nl
] = (char)ichar
;
245 } else if (iUTF4
> 0 && iUTF4
< 5 && ichar
> 0x7F && ichar
< 0xC0) {
250 ul
[nl
] = (char)ichar
;
254 ul
[nl
] = (char)ichar
;
256 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
260 } else if (ichar
< 0x80) {
262 ul
[nl
] = (char)ichar
;
264 } else if (ichar
> 0xC1 && ichar
< 0xE0) {
267 ul
[nl
] = (char)ichar
;
269 } else if (ichar
> 0xDF && ichar
< 0xF0) {
272 ul
[nl
] = (char)ichar
;
274 } else if (ichar
> 0xEF && ichar
< 0xF5) {
277 ul
[nl
] = (char)ichar
;
280 ul
[nl
] = (char)ichar
;
282 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
290 if (iUTF2
|| iUTF3
|| iUTF4
) {
291 debug((char *) "%s| %s: INFO: iUTF2: %d iUTF3: %d iUTF4: %d\n", LogTime(), PROGRAM
, iUTF2
, iUTF3
, iUTF4
);
292 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
297 ul
= strcat(ul
, upd
);
302 create_gd(struct main_args
*margs
)
306 struct gdstruct
*gdsp
= NULL
, *gdspn
= NULL
;
310 * glist=Pattern1[:Pattern2]
312 * Pattern=Group Group for all domains(including non Kerberos domains using ldap url options) if no
313 * other group definition for domain exists or users without
314 * domain information.
315 * gdstruct.domain=NULL, gdstruct.group=Group
317 * or Pattern=Group@ Group for all Kerberos domains if no other group definition
319 * gdstruct.domain="", gdstruct.group=Group
321 * or Pattern=Group@Domain Group for a specific Kerberos domain
322 * gdstruct.domain=Domain, gdstruct.group=Group
326 char *hp1
= hex_utf_char(margs
, 0);
327 char *hp2
= hex_utf_char(margs
, 1);
328 char *up
= utf8dup(margs
);
330 // NP: will point to the start of a temporary assembly buffer used by 'p' and 'gp'
331 // for catenation of the hp1, hp2, and up buffer contents from above.
332 // necessary for xfree() because both p and gp move over the assembly area
335 // release the allocated UTF decoding buffers
336 #define cleanup() { \
348 gpbuf
= p
= (char *) xmalloc(strlen(up
) + strlen(hp1
) + strlen(hp2
) + 2);
355 gpbuf
= p
= (char *) xmalloc(strlen(hp1
) + strlen(hp2
) + 1);
362 gpbuf
= p
= (char *) xmalloc(strlen(up
) + strlen(hp1
) + 1);
372 gpbuf
= p
= (char *) xmalloc(strlen(up
) + strlen(hp2
) + 1);
382 debug((char *) "%s| %s: INFO: Group list %s\n", LogTime(), PROGRAM
, p
? p
: "NULL");
386 debug((char *) "%s| %s: ERROR: No groups defined.\n", LogTime(), PROGRAM
);
390 while (*p
) { /* loop over group list */
391 if (*p
== '\n' || *p
== '\r') { /* Ignore CR and LF if exist */
395 if (*p
== '@') { /* end of group name - start of domain name */
396 if (p
== gp
) { /* empty group name not allowed */
397 debug((char *) "%s| %s: ERROR: No group defined for domain %s\n", LogTime(), PROGRAM
, p
);
401 if (dp
) { /* end of domain name - twice */
402 debug((char *) "%s| %s: @ is not allowed in group name %s@%s\n",LogTime(), PROGRAM
,gp
,dp
);
409 gdsp
->group
= xstrdup(gp
);
411 dp
= p
; /* after @ starts new domain name */
412 } else if (*p
== ':') { /* end of group name or end of domain name */
413 if (p
== gp
) { /* empty group name not allowed */
414 debug((char *) "%s| %s: ERROR: No group defined for domain %s\n", LogTime(), PROGRAM
, p
);
420 if (dp
) { /* end of domain name */
421 gdsp
->domain
= xstrdup(dp
);
423 } else { /* end of group name and no domain name */
425 gdsp
->group
= xstrdup(gp
);
429 gp
= p
; /* after : starts new group name */
430 debug((char *) "%s| %s: INFO: Group %s Domain %s\n", LogTime(), PROGRAM
, gdsp
->group
, gdsp
->domain
? gdsp
->domain
: "NULL");
434 if (p
== gp
) { /* empty group name not allowed */
435 debug((char *) "%s| %s: ERROR: No group defined for domain %s\n", LogTime(), PROGRAM
, p
);
439 if (dp
) { /* end of domain name */
440 gdsp
->domain
= xstrdup(dp
);
441 } else { /* end of group name and no domain name */
443 gdsp
->group
= xstrdup(gp
);
444 if (gdspn
) /* Have already an existing structure */
447 debug((char *) "%s| %s: INFO: Group %s Domain %s\n", LogTime(), PROGRAM
, gdsp
->group
, gdsp
->domain
? gdsp
->domain
: "NULL");
449 margs
->groups
= gdsp
;
450 gdsp
= NULL
; // prevent the cleanup() deallocating it.