]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/external/kerberos_ldap_group/support_netbios.cc
Source Format Enforcement (#532)
[thirdparty/squid.git] / src / acl / external / kerberos_ldap_group / support_netbios.cc
CommitLineData
ca02e0ec 1/*
77b1029d 2 * Copyright (C) 1996-2020 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
b1218840
AJ
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"
b1218840
AJ
34#include "util.h"
35
1a22a39e 36#if HAVE_LDAP
b1218840
AJ
37
38#include "support.h"
39
40struct ndstruct *init_nd(void);
4ebcf1ce 41void free_nd(struct ndstruct *ndsp);
b1218840
AJ
42
43struct ndstruct *
2e881a6f 44init_nd(void) {
b1218840
AJ
45 struct ndstruct *ndsp;
46 ndsp = (struct ndstruct *) xmalloc(sizeof(struct ndstruct));
47 ndsp->netbios = NULL;
48 ndsp->domain = NULL;
49 ndsp->next = NULL;
50 return ndsp;
51}
52
4ad7aabf
AJ
53void
54free_nd(struct ndstruct *ndsp)
55{
56 while (ndsp) {
57 struct ndstruct *ndspn = ndsp->next;
58 xfree(ndsp->netbios);
59 xfree(ndsp->domain);
60 xfree(ndsp);
61 ndsp = ndspn;
62 }
63}
64
b1218840
AJ
65int
66create_nd(struct main_args *margs)
67{
68 char *np, *dp;
69 char *p;
70 struct ndstruct *ndsp = NULL, *ndspn = NULL;
71 /*
72 * netbios list format:
73 *
74 * nlist=Pattern1[:Pattern2]
75 *
76 * Pattern=NetbiosName@Domain Netbios Name for a specific Kerberos domain
77 * ndstruct.domain=Domain, ndstruct.netbios=NetbiosName
78 *
79 *
80 */
81 p = margs->nlist;
82 np = margs->nlist;
83 debug((char *) "%s| %s: DEBUG: Netbios list %s\n", LogTime(), PROGRAM, margs->nlist ? margs->nlist : "NULL");
84 dp = NULL;
85
86 if (!p) {
2e881a6f
A
87 debug((char *) "%s| %s: DEBUG: No netbios names defined.\n", LogTime(), PROGRAM);
88 return (0);
b1218840 89 }
f53969cc
SM
90 while (*p) { /* loop over group list */
91 if (*p == '\n' || *p == '\r') { /* Ignore CR and LF if exist */
755494da 92 ++p;
2e881a6f
A
93 continue;
94 }
f53969cc
SM
95 if (*p == '@') { /* end of group name - start of domain name */
96 if (p == np) { /* empty group name not allowed */
2e881a6f 97 debug((char *) "%s| %s: DEBUG: No netbios name defined for domain %s\n", LogTime(), PROGRAM, p);
4ad7aabf 98 free_nd(ndsp);
2e881a6f
A
99 return (1);
100 }
4f10fd9b
MM
101 if (dp) { /* end of domain name - twice */
102 debug((char *) "%s| %s: @ is not allowed in netbios name %s@%s\n",LogTime(), PROGRAM,np,dp);
103 free_nd(ndsp);
104 return(1);
105 }
2e881a6f 106 *p = '\0';
755494da 107 ++p;
2e881a6f
A
108 ndsp = init_nd();
109 ndsp->netbios = xstrdup(np);
4ad7aabf 110 ndsp->next = ndspn;
f53969cc
SM
111 dp = p; /* after @ starts new domain name */
112 } else if (*p == ':') { /* end of group name or end of domain name */
113 if (p == np) { /* empty group name not allowed */
2e881a6f 114 debug((char *) "%s| %s: DEBUG: No netbios name defined for domain %s\n", LogTime(), PROGRAM, p);
4ad7aabf 115 free_nd(ndsp);
2e881a6f
A
116 return (1);
117 }
118 *p = '\0';
755494da 119 ++p;
f53969cc 120 if (dp) { /* end of domain name */
2e881a6f
A
121 ndsp->domain = xstrdup(dp);
122 dp = NULL;
f53969cc 123 } else { /* end of group name and no domain name */
2e881a6f
A
124 ndsp = init_nd();
125 ndsp->netbios = xstrdup(np);
4ad7aabf 126 ndsp->next = ndspn;
2e881a6f
A
127 }
128 ndspn = ndsp;
f53969cc 129 np = p; /* after : starts new group name */
2e881a6f
A
130 if (!ndsp->domain || !strcmp(ndsp->domain, "")) {
131 debug((char *) "%s| %s: DEBUG: No domain defined for netbios name %s\n", LogTime(), PROGRAM, ndsp->netbios);
4ad7aabf 132 free_nd(ndsp);
2e881a6f
A
133 return (1);
134 }
135 debug((char *) "%s| %s: DEBUG: Netbios name %s Domain %s\n", LogTime(), PROGRAM, ndsp->netbios, ndsp->domain);
136 } else
755494da 137 ++p;
b1218840 138 }
f53969cc 139 if (p == np) { /* empty group name not allowed */
2e881a6f 140 debug((char *) "%s| %s: DEBUG: No netbios name defined for domain %s\n", LogTime(), PROGRAM, p);
4ad7aabf 141 free_nd(ndsp);
2e881a6f 142 return (1);
b1218840 143 }
f53969cc 144 if (dp) { /* end of domain name */
2e881a6f 145 ndsp->domain = xstrdup(dp);
f53969cc 146 } else { /* end of group name and no domain name */
2e881a6f
A
147 ndsp = init_nd();
148 ndsp->netbios = xstrdup(np);
4ad7aabf 149 ndsp->next = ndspn;
b1218840
AJ
150 }
151 if (!ndsp->domain || !strcmp(ndsp->domain, "")) {
2e881a6f 152 debug((char *) "%s| %s: DEBUG: No domain defined for netbios name %s\n", LogTime(), PROGRAM, ndsp->netbios);
4ad7aabf 153 free_nd(ndsp);
2e881a6f 154 return (1);
b1218840
AJ
155 }
156 debug((char *) "%s| %s: DEBUG: Netbios name %s Domain %s\n", LogTime(), PROGRAM, ndsp->netbios, ndsp->domain);
157
158 margs->ndoms = ndsp;
159 return (0);
160}
161
162char *
163get_netbios_name(struct main_args *margs, char *netbios)
164{
165 struct ndstruct *nd;
166
167 nd = margs->ndoms;
168 while (nd && netbios) {
2e881a6f
A
169 debug((char *) "%s| %s: DEBUG: Netbios domain loop: netbios@domain %s@%s\n", LogTime(), PROGRAM, nd->netbios, nd->domain);
170 if (nd->netbios && !strcasecmp(nd->netbios, netbios)) {
171 debug((char *) "%s| %s: DEBUG: Found netbios@domain %s@%s\n", LogTime(), PROGRAM, nd->netbios, nd->domain);
172 return (nd->domain);
173 }
174 nd = nd->next;
b1218840
AJ
175 }
176
177 return NULL;
178}
179#endif
f53969cc 180