]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * kdparse.c: Parses K and D lines. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
23 | * | |
24 | * $Id: kdparse.c 254 2005-09-21 23:35:12Z nenolod $ | |
25 | */ | |
26 | ||
27 | #include "stdinc.h" | |
28 | #include "tools.h" | |
29 | #include "s_log.h" | |
30 | #include "s_conf.h" | |
31 | #include "s_newconf.h" | |
32 | #include "hostmask.h" | |
33 | #include "client.h" | |
34 | #include "irc_string.h" | |
35 | #include "memory.h" | |
36 | #include "hash.h" | |
37 | ||
38 | /* conf_add_fields() | |
39 | * | |
40 | * inputs - pointer to config item, host/pass/user/operreason fields | |
41 | * output - NONE | |
42 | * side effects - update respective fields with pointers | |
43 | */ | |
44 | static void | |
45 | conf_add_fields(struct ConfItem *aconf, const char *host_field, | |
46 | const char *pass_field, const char *user_field, | |
47 | const char *operreason_field) | |
48 | { | |
49 | if(host_field != NULL) | |
50 | DupString(aconf->host, host_field); | |
51 | if(pass_field != NULL) | |
52 | DupString(aconf->passwd, pass_field); | |
53 | if(user_field != NULL) | |
54 | DupString(aconf->user, user_field); | |
55 | if(operreason_field != NULL) | |
56 | DupString(aconf->spasswd, operreason_field); | |
57 | } | |
58 | ||
59 | /* | |
60 | * parse_k_file | |
61 | * Inputs - pointer to line to parse | |
62 | * Output - NONE | |
63 | * Side Effects - Parse one new style K line | |
64 | */ | |
65 | ||
66 | void | |
67 | parse_k_file(FILE * file) | |
68 | { | |
69 | struct ConfItem *aconf; | |
70 | char *user_field = NULL; | |
71 | char *reason_field = NULL; | |
72 | char *operreason_field = NULL; | |
73 | char *host_field = NULL; | |
74 | char line[BUFSIZE]; | |
75 | char *p; | |
76 | ||
77 | while (fgets(line, sizeof(line), file)) | |
78 | { | |
79 | if((p = strchr(line, '\n')) != NULL) | |
80 | *p = '\0'; | |
81 | ||
82 | if((*line == '\0') || (*line == '#')) | |
83 | continue; | |
84 | ||
85 | user_field = getfield(line); | |
86 | if(EmptyString(user_field)) | |
87 | continue; | |
88 | ||
89 | host_field = getfield(NULL); | |
90 | if(EmptyString(host_field)) | |
91 | continue; | |
92 | ||
93 | reason_field = getfield(NULL); | |
94 | if(EmptyString(reason_field)) | |
95 | continue; | |
96 | ||
97 | operreason_field = getfield(NULL); | |
98 | ||
99 | aconf = make_conf(); | |
100 | aconf->status = CONF_KILL; | |
101 | conf_add_fields(aconf, host_field, reason_field, | |
102 | user_field, operreason_field); | |
103 | ||
104 | if(aconf->host != NULL) | |
105 | add_conf_by_address(aconf->host, CONF_KILL, aconf->user, aconf); | |
106 | } | |
107 | } | |
108 | ||
109 | /* | |
110 | * parse_d_file | |
111 | * Inputs - pointer to line to parse | |
112 | * Output - NONE | |
113 | * Side Effects - Parse one new style D line | |
114 | */ | |
115 | ||
116 | void | |
117 | parse_d_file(FILE * file) | |
118 | { | |
119 | struct ConfItem *aconf; | |
120 | char *reason_field = NULL; | |
121 | char *host_field = NULL; | |
122 | char *operreason_field = NULL; | |
123 | char line[BUFSIZE]; | |
124 | char *p; | |
125 | ||
126 | while (fgets(line, sizeof(line), file)) | |
127 | { | |
128 | if((p = strchr(line, '\n'))) | |
129 | *p = '\0'; | |
130 | ||
131 | if((*line == '\0') || (line[0] == '#')) | |
132 | continue; | |
133 | ||
134 | host_field = getfield(line); | |
135 | if(EmptyString(host_field)) | |
136 | continue; | |
137 | ||
138 | reason_field = getfield(NULL); | |
139 | if(EmptyString(reason_field)) | |
140 | continue; | |
141 | ||
142 | operreason_field = getfield(NULL); | |
143 | ||
144 | aconf = make_conf(); | |
145 | aconf->status = CONF_DLINE; | |
146 | conf_add_fields(aconf, host_field, reason_field, "", operreason_field); | |
147 | conf_add_d_conf(aconf); | |
148 | } | |
149 | } | |
150 | ||
151 | void | |
152 | parse_x_file(FILE * file) | |
153 | { | |
154 | struct ConfItem *aconf; | |
155 | char *gecos_field = NULL; | |
156 | char *reason_field = NULL; | |
157 | char line[BUFSIZE]; | |
158 | char *p; | |
159 | ||
160 | while (fgets(line, sizeof(line), file)) | |
161 | { | |
162 | if((p = strchr(line, '\n'))) | |
163 | *p = '\0'; | |
164 | ||
165 | if((*line == '\0') || (line[0] == '#')) | |
166 | continue; | |
167 | ||
168 | gecos_field = getfield(line); | |
169 | if(EmptyString(gecos_field)) | |
170 | continue; | |
171 | ||
172 | /* field for xline types, which no longer exist */ | |
173 | getfield(NULL); | |
174 | ||
175 | reason_field = getfield(NULL); | |
176 | if(EmptyString(reason_field)) | |
177 | continue; | |
178 | ||
179 | /* sanity checking */ | |
180 | if((find_xline(gecos_field, 0) != NULL) || | |
181 | (strchr(reason_field, ':') != NULL)) | |
182 | continue; | |
183 | ||
184 | aconf = make_conf(); | |
185 | aconf->status = CONF_XLINE; | |
186 | ||
187 | DupString(aconf->name, gecos_field); | |
188 | DupString(aconf->passwd, reason_field); | |
189 | ||
190 | dlinkAddAlloc(aconf, &xline_conf_list); | |
191 | } | |
192 | } | |
193 | ||
194 | void | |
195 | parse_resv_file(FILE * file) | |
196 | { | |
197 | struct ConfItem *aconf; | |
198 | char *reason_field; | |
199 | char *host_field; | |
200 | char line[BUFSIZE]; | |
201 | char *p; | |
202 | ||
203 | while (fgets(line, sizeof(line), file)) | |
204 | { | |
205 | if((p = strchr(line, '\n'))) | |
206 | *p = '\0'; | |
207 | ||
208 | if((*line == '\0') || (line[0] == '#')) | |
209 | continue; | |
210 | ||
211 | host_field = getfield(line); | |
212 | if(EmptyString(host_field)) | |
213 | continue; | |
214 | ||
215 | reason_field = getfield(NULL); | |
216 | if(EmptyString(reason_field)) | |
217 | continue; | |
218 | ||
219 | if(IsChannelName(host_field)) | |
220 | { | |
221 | if(hash_find_resv(host_field)) | |
222 | continue; | |
223 | ||
224 | aconf = make_conf(); | |
225 | aconf->status = CONF_RESV_CHANNEL; | |
226 | aconf->port = 0; | |
227 | ||
228 | DupString(aconf->name, host_field); | |
229 | DupString(aconf->passwd, reason_field); | |
230 | add_to_resv_hash(aconf->name, aconf); | |
231 | } | |
232 | else if(clean_resv_nick(host_field)) | |
233 | { | |
234 | if(find_nick_resv(host_field)) | |
235 | continue; | |
236 | ||
237 | aconf = make_conf(); | |
238 | aconf->status = CONF_RESV_NICK; | |
239 | aconf->port = 0; | |
240 | ||
241 | DupString(aconf->name, host_field); | |
242 | DupString(aconf->passwd, reason_field); | |
243 | dlinkAddAlloc(aconf, &resv_conf_list); | |
244 | } | |
245 | } | |
246 | } | |
247 | ||
248 | /* | |
249 | * getfield | |
250 | * | |
251 | * inputs - input buffer | |
252 | * output - next field | |
253 | * side effects - field breakup for ircd.conf file. | |
254 | */ | |
255 | char * | |
256 | getfield(char *newline) | |
257 | { | |
258 | static char *line = NULL; | |
259 | char *end, *field; | |
260 | ||
261 | if(newline != NULL) | |
262 | line = newline; | |
263 | ||
264 | if(line == NULL) | |
265 | return (NULL); | |
266 | ||
267 | field = line; | |
268 | ||
269 | /* XXX make this skip to first " if present */ | |
270 | if(*field == '"') | |
271 | field++; | |
272 | else | |
273 | return (NULL); /* mal-formed field */ | |
274 | ||
275 | end = strchr(line, ','); | |
276 | ||
277 | while(1) | |
278 | { | |
279 | /* no trailing , - last field */ | |
280 | if(end == NULL) | |
281 | { | |
282 | end = line + strlen(line); | |
283 | line = NULL; | |
284 | ||
285 | if(*end == '"') | |
286 | { | |
287 | *end = '\0'; | |
288 | return field; | |
289 | } | |
290 | else | |
291 | return NULL; | |
292 | } | |
293 | else | |
294 | { | |
295 | /* look for a ", to mark the end of a field.. */ | |
296 | if(*(end - 1) == '"') | |
297 | { | |
298 | line = end + 1; | |
299 | end--; | |
300 | *end = '\0'; | |
301 | return field; | |
302 | } | |
303 | ||
304 | /* search for the next ',' */ | |
305 | end++; | |
306 | end = strchr(end, ','); | |
307 | } | |
308 | } | |
309 | ||
310 | return NULL; | |
311 | } |