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