]> git.ipfire.org Git - thirdparty/squid.git/blob - helpers/external_acl/kerberos_ldap_group/support_lserver.cc
0c08275404381dc32a9759b0390b2742ff5136e2
[thirdparty/squid.git] / helpers / external_acl / kerberos_ldap_group / support_lserver.cc
1 /*
2 * -----------------------------------------------------------------------------
3 *
4 * Author: Markus Moeller (markus_moeller at compuserve.com)
5 *
6 * Copyright (C) 2007 Markus Moeller. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 *
22 * -----------------------------------------------------------------------------
23 */
24
25 #include "config.h"
26 #include "util.h"
27
28 #ifdef HAVE_LDAP
29
30 #include "support.h"
31 struct lsstruct *init_ls(void);
32
33 struct lsstruct *
34 init_ls(void) {
35 struct lsstruct *lssp;
36 lssp = (struct lsstruct *) xmalloc(sizeof(struct lsstruct));
37 lssp->lserver = NULL;
38 lssp->domain = NULL;
39 lssp->next = NULL;
40 return lssp;
41 }
42
43 int
44 create_ls(struct main_args *margs)
45 {
46 char *np, *dp;
47 char *p;
48 struct lsstruct *lssp = NULL, *lsspn = NULL;
49 /*
50 * netbios list format:
51 *
52 * nlist=Pattern1[:Pattern2]
53 *
54 * Pattern=ldap-server@Domain ldap server Name for a specific Kerberos domain
55 * lsstruct.domain=Domain, lsstruct.lserver=ldap server
56 *
57 *
58 */
59 p = margs->llist;
60 np = margs->llist;
61 debug((char *) "%s| %s: DEBUG: ldap server list %s\n", LogTime(), PROGRAM, margs->llist ? margs->llist : "NULL");
62 dp = NULL;
63
64 if (!p) {
65 debug((char *) "%s| %s: DEBUG: No ldap servers defined.\n", LogTime(), PROGRAM);
66 return (0);
67 }
68 while (*p) { /* loop over group list */
69 if (*p == '\n' || *p == '\r') { /* Ignore CR and LF if exist */
70 p++;
71 continue;
72 }
73 if (*p == '@') { /* end of group name - start of domain name */
74 if (p == np) { /* empty group name not allowed */
75 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
76 return (1);
77 }
78 *p = '\0';
79 p++;
80 lssp = init_ls();
81 lssp->lserver = xstrdup(np);
82 if (lsspn) /* Have already an existing structure */
83 lssp->next = lsspn;
84 dp = p; /* after @ starts new domain name */
85 } else if (*p == ':') { /* end of group name or end of domain name */
86 if (p == np) { /* empty group name not allowed */
87 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
88 return (1);
89 }
90 *p = '\0';
91 p++;
92 if (dp) { /* end of domain name */
93 lssp->domain = xstrdup(dp);
94 dp = NULL;
95 } else { /* end of group name and no domain name */
96 lssp = init_ls();
97 lssp->lserver = xstrdup(np);
98 if (lsspn) /* Have already an existing structure */
99 lssp->next = lsspn;
100 }
101 lsspn = lssp;
102 np = p; /* after : starts new group name */
103 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
104 } else
105 p++;
106 }
107 if (p == np) { /* empty group name not allowed */
108 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
109 return (1);
110 }
111 if (dp) { /* end of domain name */
112 lssp->domain = xstrdup(dp);
113 } else { /* end of group name and no domain name */
114 lssp = init_ls();
115 lssp->lserver = xstrdup(np);
116 if (lsspn) /* Have already an existing structure */
117 lssp->next = lsspn;
118 }
119 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
120
121 margs->lservs = lssp;
122 return (0);
123 }
124 #endif