]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/external_acl/kerberos_ldap_group/support_group.cc
3 * -----------------------------------------------------------------------------
5 * Author: Markus Moeller (markus_moeller at compuserve.com)
7 * Copyright (C) 2007 Markus Moeller. All rights reserved.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23 * -----------------------------------------------------------------------------
33 struct gdstruct
*init_gd(void);
37 struct gdstruct
*gdsp
;
38 gdsp
= (struct gdstruct
*) xmalloc(sizeof(struct gdstruct
));
45 char *utf8dup(struct main_args
*margs
);
48 utf8dup(struct main_args
*margs
)
53 unsigned char *p
, *dupp
;
58 for (n
= 0; n
< strlen(src
); ++n
)
59 if ((unsigned char) src
[n
] > 127)
62 p
= (unsigned char *) xmalloc(strlen(src
) + c
);
64 for (n
= 0; n
< strlen(src
); ++n
) {
65 s
= (unsigned char) src
[n
];
66 if (s
> 127 && s
< 192) {
70 } else if (s
> 191 && s
< 256) {
79 debug((char *) "%s| %s: INFO: Group %s as UTF-8: %s\n", LogTime(), PROGRAM
, src
, dupp
);
85 char *hex_utf_char(struct main_args
*margs
, int flag
);
88 * UTFMB = UTF2 / UTF3 / UTF4
93 * UTF3 = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
94 * %xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
95 * UTF4 = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
96 * %xF4 %x80-8F 2(UTF0)
98 * http://www.utf8-chartable.de/unicode-utf8-table.pl
102 hex_utf_char(struct main_args
*margs
, int flag
)
107 int a
, n
, nl
, ival
, ichar
;
108 int iUTF2
, iUTF3
, iUTF4
;
119 upd
= strrchr(up
, '@');
125 ul
= (char *) xmalloc(strlen(up
));
132 while (n
< (int) strlen(up
)) {
142 if (ival
> 64 && ival
< 71)
143 ichar
= (ival
- 55) * 16;
144 else if (ival
> 96 && ival
< 103)
145 ichar
= (ival
- 87) * 16;
146 else if (ival
> 47 && ival
< 58)
147 ichar
= (ival
- 48) * 16;
149 debug((char *) "%s| %s: WARNING: Invalid Hex value %c\n", LogTime(), PROGRAM
, ival
);
157 debug((char *) "%s| %s: WARNING: Invalid Hex UTF-8 string %s\n", LogTime(), PROGRAM
, up
);
164 if (ival
> 64 && ival
< 71)
165 ichar
= ichar
+ ival
- 55;
166 else if (ival
> 96 && ival
< 103)
167 ichar
= ichar
+ ival
- 87;
168 else if (ival
> 47 && ival
< 58)
169 ichar
= ichar
+ ival
- 48;
171 debug((char *) "%s| %s: WARNING: Invalid Hex value %c\n", LogTime(), PROGRAM
, ival
);
178 if (iUTF2
== 0xC2 && ichar
> 0x7F && ichar
< 0xC0) {
181 } else if (iUTF2
== 0xC3 && ichar
> 0x7F && ichar
< 0xC0) {
183 ul
[nl
- 1] = ichar
+ 64;
184 } else if (iUTF2
> 0xC3 && iUTF2
< 0xE0 && ichar
> 0x7F && ichar
< 0xC0) {
192 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
198 if (iUTF3
== 0xE0 && ichar
> 0x9F && ichar
< 0xC0) {
202 } else if (iUTF3
> 0xE0 && iUTF3
< 0xED && ichar
> 0x7F && ichar
< 0xC0) {
206 } else if (iUTF3
== 0xED && ichar
> 0x7F && ichar
< 0xA0) {
210 } else if (iUTF3
> 0xED && iUTF3
< 0xF0 && ichar
> 0x7F && ichar
< 0xC0) {
214 } else if (iUTF3
> 0 && iUTF3
< 5 && ichar
> 0x7F && ichar
< 0xC0) {
222 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
228 if (iUTF4
== 0xF0 && ichar
> 0x8F && ichar
< 0xC0) {
232 } else if (iUTF4
> 0xF0 && iUTF3
< 0xF4 && ichar
> 0x7F && ichar
< 0xC0) {
236 } else if (iUTF4
== 0xF4 && ichar
> 0x7F && ichar
< 0x90) {
240 } else if (iUTF4
> 0 && iUTF4
< 5 && ichar
> 0x7F && ichar
< 0xC0) {
251 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
256 } else if (ichar
< 0x80) {
260 } else if (ichar
> 0xC1 && ichar
< 0xE0) {
265 } else if (ichar
> 0xDF && ichar
< 0xF0) {
270 } else if (ichar
> 0xEF && ichar
< 0xF5) {
278 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
287 if (iUTF2
|| iUTF3
|| iUTF4
) {
288 debug((char *) "%s| %s: INFO: iUTF2: %d iUTF3: %d iUTF4: %d\n", LogTime(), PROGRAM
, iUTF2
, iUTF3
, iUTF4
);
289 debug((char *) "%s| %s: WARNING: Invalid UTF-8 sequence for Unicode %s\n", LogTime(), PROGRAM
, ul
);
295 ul
= strcat(ul
, upd
);
301 create_gd(struct main_args
*margs
)
304 char *hp1
, *hp2
, *up
;
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 hp1
= hex_utf_char(margs
, 0);
327 hp2
= hex_utf_char(margs
, 1);
333 p
= (char *) xmalloc(strlen(up
) + strlen(hp1
) + strlen(hp2
) + 2);
340 p
= (char *) xmalloc(strlen(hp1
) + strlen(hp2
) + 1);
347 p
= (char *) xmalloc(strlen(up
) + strlen(hp1
) + 1);
357 p
= (char *) xmalloc(strlen(up
) + strlen(hp2
) + 1);
367 debug((char *) "%s| %s: INFO: Group list %s\n", LogTime(), PROGRAM
, p
? p
: "NULL");
371 debug((char *) "%s| %s: ERROR: No groups defined.\n", LogTime(), PROGRAM
);
374 while (*p
) { /* loop over group list */
375 if (*p
== '\n' || *p
== '\r') { /* Ignore CR and LF if exist */
379 if (*p
== '@') { /* end of group name - start of domain name */
380 if (p
== gp
) { /* empty group name not allowed */
381 debug((char *) "%s| %s: ERROR: No group defined for domain %s\n", LogTime(), PROGRAM
, p
);
388 if (gdspn
) /* Have already an existing structure */
390 dp
= p
; /* after @ starts new domain name */
391 } else if (*p
== ':') { /* end of group name or end of domain name */
392 if (p
== gp
) { /* empty group name not allowed */
393 debug((char *) "%s| %s: ERROR: No group defined for domain %s\n", LogTime(), PROGRAM
, p
);
398 if (dp
) { /* end of domain name */
399 gdsp
->domain
= xstrdup(dp
);
401 } else { /* end of group name and no domain name */
404 if (gdspn
) /* Have already an existing structure */
408 gp
= p
; /* after : starts new group name */
409 debug((char *) "%s| %s: INFO: Group %s Domain %s\n", LogTime(), PROGRAM
, gdsp
->group
, gdsp
->domain
? gdsp
->domain
: "NULL");
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
);
417 if (dp
) { /* end of domain name */
418 gdsp
->domain
= xstrdup(dp
);
419 } else { /* end of group name and no domain name */
422 if (gdspn
) /* Have already an existing structure */
425 debug((char *) "%s| %s: INFO: Group %s Domain %s\n", LogTime(), PROGRAM
, gdsp
->group
, gdsp
->domain
? gdsp
->domain
: "NULL");
427 margs
->groups
= gdsp
;