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