]>
Commit | Line | Data |
---|---|---|
ca02e0ec | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
ca02e0ec AJ |
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 | ||
f602c423 MM |
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 | ||
f7f3304a | 33 | #include "squid.h" |
f602c423 MM |
34 | #include "util.h" |
35 | ||
1a22a39e | 36 | #if HAVE_LDAP |
f602c423 MM |
37 | |
38 | #include "support.h" | |
39 | struct lsstruct *init_ls(void); | |
4ebcf1ce | 40 | void free_ls(struct lsstruct *lssp); |
f602c423 MM |
41 | |
42 | struct lsstruct * | |
43 | init_ls(void) { | |
44 | struct lsstruct *lssp; | |
45 | lssp = (struct lsstruct *) xmalloc(sizeof(struct lsstruct)); | |
46 | lssp->lserver = NULL; | |
47 | lssp->domain = NULL; | |
48 | lssp->next = NULL; | |
49 | return lssp; | |
50 | } | |
51 | ||
4ad7aabf AJ |
52 | void |
53 | free_ls(struct lsstruct *lssp) | |
54 | { | |
4a07fc72 | 55 | while (lssp) { |
4ad7aabf AJ |
56 | struct lsstruct *lsspn = lssp->next; |
57 | xfree(lssp->lserver); | |
58 | xfree(lssp->domain); | |
59 | xfree(lssp); | |
60 | lssp = lsspn; | |
61 | } | |
62 | } | |
63 | ||
f602c423 MM |
64 | int |
65 | create_ls(struct main_args *margs) | |
66 | { | |
67 | char *np, *dp; | |
68 | char *p; | |
69 | struct lsstruct *lssp = NULL, *lsspn = NULL; | |
70 | /* | |
71 | * netbios list format: | |
72 | * | |
73 | * nlist=Pattern1[:Pattern2] | |
74 | * | |
75 | * Pattern=ldap-server@Domain ldap server Name for a specific Kerberos domain | |
76 | * lsstruct.domain=Domain, lsstruct.lserver=ldap server | |
77 | * | |
78 | * | |
79 | */ | |
80 | p = margs->llist; | |
81 | np = margs->llist; | |
82 | debug((char *) "%s| %s: DEBUG: ldap server list %s\n", LogTime(), PROGRAM, margs->llist ? margs->llist : "NULL"); | |
83 | dp = NULL; | |
84 | ||
85 | if (!p) { | |
86 | debug((char *) "%s| %s: DEBUG: No ldap servers defined.\n", LogTime(), PROGRAM); | |
87 | return (0); | |
88 | } | |
f53969cc SM |
89 | while (*p) { /* loop over group list */ |
90 | if (*p == '\n' || *p == '\r') { /* Ignore CR and LF if exist */ | |
755494da | 91 | ++p; |
f602c423 MM |
92 | continue; |
93 | } | |
f53969cc SM |
94 | if (*p == '@') { /* end of group name - start of domain name */ |
95 | if (p == np) { /* empty group name not allowed */ | |
f602c423 | 96 | debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p); |
4ad7aabf | 97 | free_ls(lssp); |
f602c423 MM |
98 | return (1); |
99 | } | |
96072b37 AJ |
100 | if (dp) { /* end of domain name - twice */ |
101 | debug((char *) "%s| %s: @ is not allowed in server name %s@%s\n",LogTime(), PROGRAM,np,dp); | |
102 | free_ls(lssp); | |
103 | return(1); | |
104 | } | |
f602c423 | 105 | *p = '\0'; |
755494da | 106 | ++p; |
f602c423 MM |
107 | lssp = init_ls(); |
108 | lssp->lserver = xstrdup(np); | |
4ad7aabf | 109 | lssp->next = lsspn; |
f53969cc SM |
110 | dp = p; /* after @ starts new domain name */ |
111 | } else if (*p == ':') { /* end of group name or end of domain name */ | |
112 | if (p == np) { /* empty group name not allowed */ | |
f602c423 | 113 | debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p); |
4ad7aabf | 114 | free_ls(lssp); |
f602c423 MM |
115 | return (1); |
116 | } | |
117 | *p = '\0'; | |
755494da | 118 | ++p; |
f53969cc | 119 | if (dp) { /* end of domain name */ |
f602c423 MM |
120 | lssp->domain = xstrdup(dp); |
121 | dp = NULL; | |
f53969cc | 122 | } else { /* end of group name and no domain name */ |
f602c423 MM |
123 | lssp = init_ls(); |
124 | lssp->lserver = xstrdup(np); | |
4ad7aabf | 125 | lssp->next = lsspn; |
f602c423 MM |
126 | } |
127 | lsspn = lssp; | |
f53969cc | 128 | np = p; /* after : starts new group name */ |
0b6cf317 | 129 | debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL"); |
f602c423 | 130 | } else |
755494da | 131 | ++p; |
f602c423 | 132 | } |
f53969cc | 133 | if (p == np) { /* empty group name not allowed */ |
f602c423 | 134 | debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p); |
4ad7aabf | 135 | free_ls(lssp); |
f602c423 MM |
136 | return (1); |
137 | } | |
f53969cc | 138 | if (dp) { /* end of domain name */ |
f602c423 | 139 | lssp->domain = xstrdup(dp); |
f53969cc | 140 | } else { /* end of group name and no domain name */ |
f602c423 MM |
141 | lssp = init_ls(); |
142 | lssp->lserver = xstrdup(np); | |
f53969cc | 143 | if (lsspn) /* Have already an existing structure */ |
f602c423 MM |
144 | lssp->next = lsspn; |
145 | } | |
0b6cf317 | 146 | debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL"); |
f602c423 MM |
147 | |
148 | margs->lservs = lssp; | |
149 | return (0); | |
150 | } | |
151 | #endif | |
f53969cc | 152 |