Squid Web Cache v8/master
Loading...
Searching...
No Matches
support_lserver.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2026 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 along
27 * with this program; if not, see <https://www.gnu.org/licenses/>.
28 *
29 * -----------------------------------------------------------------------------
30 */
31
32#include "squid.h"
33#include "util.h"
34
35#if HAVE_LDAP
36
37#include "support.h"
38struct lsstruct *init_ls(void);
39void free_ls(struct lsstruct *lssp);
40
41struct lsstruct *
42init_ls(void) {
43 struct lsstruct *lssp;
44 lssp = (struct lsstruct *) xmalloc(sizeof(struct lsstruct));
45 lssp->lserver = nullptr;
46 lssp->domain = nullptr;
47 lssp->next = nullptr;
48 return lssp;
49}
50
51void
52free_ls(struct lsstruct *lssp)
53{
54 while (lssp) {
55 struct lsstruct *lsspn = lssp->next;
56 xfree(lssp->lserver);
57 xfree(lssp->domain);
58 xfree(lssp);
59 lssp = lsspn;
60 }
61}
62
63int
64create_ls(struct main_args *margs)
65{
66 char *np, *dp;
67 char *p;
68 struct lsstruct *lssp = nullptr, *lsspn = nullptr;
69 /*
70 * netbios list format:
71 *
72 * nlist=Pattern1[:Pattern2]
73 *
74 * Pattern=ldap-server@Domain ldap server Name for a specific Kerberos domain
75 * lsstruct.domain=Domain, lsstruct.lserver=ldap server
76 *
77 *
78 */
79 p = margs->llist;
80 np = margs->llist;
81 debug((char *) "%s| %s: DEBUG: ldap server list %s\n", LogTime(), PROGRAM, margs->llist ? margs->llist : "NULL");
82 dp = nullptr;
83
84 if (!p) {
85 debug((char *) "%s| %s: DEBUG: No ldap servers defined.\n", LogTime(), PROGRAM);
86 return (0);
87 }
88 while (*p) { /* loop over group list */
89 if (*p == '\n' || *p == '\r') { /* Ignore CR and LF if exist */
90 ++p;
91 continue;
92 }
93 if (*p == '@') { /* end of group name - start of domain name */
94 if (p == np) { /* empty group name not allowed */
95 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
96 free_ls(lssp);
97 return (1);
98 }
99 if (dp) { /* end of domain name - twice */
100 debug((char *) "%s| %s: @ is not allowed in server name %s@%s\n",LogTime(), PROGRAM,np,dp);
101 free_ls(lssp);
102 return(1);
103 }
104 *p = '\0';
105 ++p;
106 lssp = init_ls();
107 lssp->lserver = xstrdup(np);
108 lssp->next = lsspn;
109 dp = p; /* after @ starts new domain name */
110 } else if (*p == ':') { /* end of group name or end of domain name */
111 if (p == np) { /* empty group name not allowed */
112 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
113 free_ls(lssp);
114 return (1);
115 }
116 *p = '\0';
117 ++p;
118 if (dp) { /* end of domain name */
119 lssp->domain = xstrdup(dp);
120 dp = nullptr;
121 } else { /* end of group name and no domain name */
122 lssp = init_ls();
123 lssp->lserver = xstrdup(np);
124 lssp->next = lsspn;
125 }
126 lsspn = lssp;
127 np = p; /* after : starts new group name */
128 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
129 } else
130 ++p;
131 }
132 if (p == np) { /* empty group name not allowed */
133 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
134 free_ls(lssp);
135 return (1);
136 }
137 if (dp) { /* end of domain name */
138 lssp->domain = xstrdup(dp);
139 } else { /* end of group name and no domain name */
140 lssp = init_ls();
141 lssp->lserver = xstrdup(np);
142 if (lsspn) /* Have already an existing structure */
143 lssp->next = lsspn;
144 }
145 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
146
147 margs->lservs = lssp;
148 return (0);
149}
150#endif
151
#define PROGRAM
Definition support.h:168
const char * LogTime(void)
int create_ls(struct main_args *margs)
void debug(const char *format,...)
Definition debug.cc:19
#define xfree
#define xstrdup
#define xmalloc
struct lsstruct * next
Definition support.h:70
char * domain
Definition support.h:69
char * lserver
Definition support.h:68
struct lsstruct * lservs
Definition support.h:91
char * llist
Definition support.h:78