support_lserver.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
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
33#include "squid.h"
34#include "util.h"
35
36#if HAVE_LDAP
37
38#include "support.h"
39struct lsstruct *init_ls(void);
40void free_ls(struct lsstruct *lssp);
41
42struct lsstruct *
43init_ls(void) {
44 struct lsstruct *lssp;
45 lssp = (struct lsstruct *) xmalloc(sizeof(struct lsstruct));
46 lssp->lserver = nullptr;
47 lssp->domain = nullptr;
48 lssp->next = nullptr;
49 return lssp;
50}
51
52void
53free_ls(struct lsstruct *lssp)
54{
55 while (lssp) {
56 struct lsstruct *lsspn = lssp->next;
57 xfree(lssp->lserver);
58 xfree(lssp->domain);
59 xfree(lssp);
60 lssp = lsspn;
61 }
62}
63
64int
65create_ls(struct main_args *margs)
66{
67 char *np, *dp;
68 char *p;
69 struct lsstruct *lssp = nullptr, *lsspn = nullptr;
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 = nullptr;
84
85 if (!p) {
86 debug((char *) "%s| %s: DEBUG: No ldap servers defined.\n", LogTime(), PROGRAM);
87 return (0);
88 }
89 while (*p) { /* loop over group list */
90 if (*p == '\n' || *p == '\r') { /* Ignore CR and LF if exist */
91 ++p;
92 continue;
93 }
94 if (*p == '@') { /* end of group name - start of domain name */
95 if (p == np) { /* empty group name not allowed */
96 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
97 free_ls(lssp);
98 return (1);
99 }
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 }
105 *p = '\0';
106 ++p;
107 lssp = init_ls();
108 lssp->lserver = xstrdup(np);
109 lssp->next = lsspn;
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 */
113 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
114 free_ls(lssp);
115 return (1);
116 }
117 *p = '\0';
118 ++p;
119 if (dp) { /* end of domain name */
120 lssp->domain = xstrdup(dp);
121 dp = nullptr;
122 } else { /* end of group name and no domain name */
123 lssp = init_ls();
124 lssp->lserver = xstrdup(np);
125 lssp->next = lsspn;
126 }
127 lsspn = lssp;
128 np = p; /* after : starts new group name */
129 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
130 } else
131 ++p;
132 }
133 if (p == np) { /* empty group name not allowed */
134 debug((char *) "%s| %s: DEBUG: No ldap servers defined for domain %s\n", LogTime(), PROGRAM, p);
135 free_ls(lssp);
136 return (1);
137 }
138 if (dp) { /* end of domain name */
139 lssp->domain = xstrdup(dp);
140 } else { /* end of group name and no domain name */
141 lssp = init_ls();
142 lssp->lserver = xstrdup(np);
143 if (lsspn) /* Have already an existing structure */
144 lssp->next = lsspn;
145 }
146 debug((char *) "%s| %s: DEBUG: ldap server %s Domain %s\n", LogTime(), PROGRAM, lssp->lserver, lssp->domain?lssp->domain:"NULL");
147
148 margs->lservs = lssp;
149 return (0);
150}
151#endif
152
#define PROGRAM
Definition: support.h:166
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:68
char * domain
Definition: support.h:67
char * lserver
Definition: support.h:66
struct lsstruct * lservs
Definition: support.h:89
char * llist
Definition: support.h:76

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors