1 |
/* Conversion routines for datafile version 8 based databases (Daylight and |
2 |
* IRCS 1.2). |
3 |
* |
4 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
5 |
* E-mail: <achurch@achurch.org> |
6 |
* Parts written by Andrew Kempe and others. |
7 |
* This program is free but copyrighted software; see the file GPL.txt for |
8 |
* details. |
9 |
*/ |
10 |
|
11 |
#include "convert-db.h" |
12 |
|
13 |
#if NICKMAX < 32 |
14 |
# error NICKMAX too small (must be >=32) |
15 |
#elif CHANMAX < 204 |
16 |
# error CHANMAX too small (must be >=204) |
17 |
#elif PASSMAX < 32 |
18 |
# error PASSMAX too small (must be >=32) |
19 |
#endif |
20 |
|
21 |
#define TYPE_DAYLIGHT 0 |
22 |
#define TYPE_IRCS 1 |
23 |
|
24 |
/*************************************************************************/ |
25 |
|
26 |
static void ver8_load_nick(const char *dir, int type) |
27 |
{ |
28 |
dbFILE *f; |
29 |
int i, j, c; |
30 |
int16 tmp16; |
31 |
int32 tmp32; |
32 |
NickInfo *ni; |
33 |
NickGroupInfo *ngi; |
34 |
|
35 |
f = open_db_ver(dir, "nick.db", 8, 8, NULL); |
36 |
for (i = 0; i < 256; i++) { |
37 |
while ((c = getc_db(f)) == 1) { |
38 |
char nickbuf[32]; |
39 |
SAFE(read_buffer(nickbuf, f)); |
40 |
ni = makenick(nickbuf, &ngi); |
41 |
init_password(&ngi->pass); |
42 |
if (type == TYPE_IRCS) { |
43 |
char passbuf[16]; |
44 |
SAFE(read_buffer(passbuf, f)); |
45 |
memcpy(ngi->pass.password, passbuf, sizeof(passbuf)); |
46 |
} else { |
47 |
char passbuf[32]; |
48 |
SAFE(read_buffer(passbuf, f)); |
49 |
memcpy(ngi->pass.password, passbuf, sizeof(passbuf)); |
50 |
} |
51 |
SAFE(read_string(&ngi->url, f)); |
52 |
SAFE(read_string(&ngi->email, f)); |
53 |
SAFE(read_string(&ni->last_usermask, f)); |
54 |
if (!ni->last_usermask) |
55 |
ni->last_usermask = (char *)"@"; |
56 |
SAFE(read_string(&ni->last_realname, f)); |
57 |
if (!ni->last_realname) |
58 |
ni->last_realname = (char *)""; |
59 |
SAFE(read_string(&ni->last_quit, f)); |
60 |
SAFE(read_int32(&tmp32, f)); |
61 |
ni->time_registered = tmp32; |
62 |
SAFE(read_int32(&tmp32, f)); |
63 |
ni->last_seen = tmp32; |
64 |
SAFE(read_int16(&tmp16, f)); /* status */ |
65 |
if (tmp16 & 0x0001) |
66 |
ngi->pass.cipher = sstrdup("md5"); |
67 |
if (tmp16 & 0x0002) { |
68 |
ni->status |= NS_VERBOTEN; |
69 |
del_nickgroupinfo(ngi); |
70 |
ni->nickgroup = 0; |
71 |
} |
72 |
if (tmp16 & 0x0004) |
73 |
ni->status |= NS_NOEXPIRE; |
74 |
SAFE(read_string(&ni->last_realmask, f)); /* link */ |
75 |
SAFE(read_int16(&tmp16, f)); /* linkcount */ |
76 |
if (ni->last_realmask) { |
77 |
ni->nickgroup = 0; |
78 |
SAFE(read_int16(&tmp16, f)); /* channelcount */ |
79 |
} else { |
80 |
SAFE(read_int32(&tmp32, f)); /* flags */ |
81 |
if (tmp32 & 0x00000001) |
82 |
ngi->flags |= NF_KILLPROTECT; |
83 |
if (tmp32 & 0x00000002) |
84 |
ngi->flags |= NF_SECURE; |
85 |
if (tmp32 & 0x00000008) |
86 |
ngi->flags |= NF_MEMO_HARDMAX; |
87 |
if (tmp32 & 0x00000010) |
88 |
ngi->flags |= NF_MEMO_SIGNON; |
89 |
if (tmp32 & 0x00000020) |
90 |
ngi->flags |= NF_MEMO_RECEIVE; |
91 |
if (tmp32 & 0x00000040) |
92 |
ngi->flags |= NF_PRIVATE; |
93 |
if (tmp32 & 0x00000080) |
94 |
ngi->flags |= NF_HIDE_EMAIL; |
95 |
if (tmp32 & 0x00000100) |
96 |
ngi->flags |= NF_HIDE_MASK; |
97 |
if (tmp32 & 0x00000200) |
98 |
ngi->flags |= NF_HIDE_QUIT; |
99 |
if (tmp32 & 0x00000400) |
100 |
ngi->flags |= NF_KILL_QUICK; |
101 |
if (tmp32 & 0x00000800) |
102 |
ngi->flags |= NF_KILL_IMMED; |
103 |
SAFE(read_int16(&ngi->access_count, f)); |
104 |
if (ngi->access_count) { |
105 |
char **access; |
106 |
access = scalloc(sizeof(char *), ngi->access_count); |
107 |
ngi->access = access; |
108 |
for (j = 0; j < ngi->access_count; j++, access++) |
109 |
SAFE(read_string(access, f)); |
110 |
} |
111 |
SAFE(read_int16(&ngi->memos.memos_count, f)); |
112 |
SAFE(read_int16(&ngi->memos.memomax, f)); |
113 |
if (ngi->memos.memos_count) { |
114 |
Memo *memos; |
115 |
memos = scalloc(sizeof(Memo), ngi->memos.memos_count); |
116 |
ngi->memos.memos = memos; |
117 |
for (j = 0; j < ngi->memos.memos_count; j++, memos++) { |
118 |
SAFE(read_uint32(&memos->number, f)); |
119 |
SAFE(read_int16(&tmp16, f)); |
120 |
if (tmp16 & 1) |
121 |
memos->flags |= MF_UNREAD; |
122 |
SAFE(read_int32(&tmp32, f)); |
123 |
memos->time = tmp32; |
124 |
SAFE(read_buffer(nickbuf, f)); |
125 |
strbcpy(memos->sender, nickbuf); |
126 |
SAFE(read_string(&memos->text, f)); |
127 |
} |
128 |
} |
129 |
SAFE(read_int16(&tmp16, f)); /* channelcount */ |
130 |
SAFE(read_int16(&tmp16, f)); /* channelmax */ |
131 |
SAFE(read_int16(&tmp16, f)); |
132 |
switch (tmp16) { |
133 |
case 0: ngi->language = LANG_EN_US; break; |
134 |
case 2: ngi->language = LANG_JA_EUC; break; |
135 |
case 3: ngi->language = LANG_JA_SJIS; break; |
136 |
case 4: ngi->language = LANG_ES; break; |
137 |
case 5: ngi->language = LANG_PT; break; |
138 |
case 6: ngi->language = LANG_FR; break; |
139 |
case 7: ngi->language = LANG_TR; break; |
140 |
case 8: ngi->language = LANG_IT; break; |
141 |
} |
142 |
} |
143 |
} /* while (getc_db(f) == 1) */ |
144 |
if (c != 0) { |
145 |
fprintf(stderr, "%s is corrupt, aborting.\n", f->filename); |
146 |
exit(1); |
147 |
} |
148 |
} /* for (i) */ |
149 |
close_db(f); |
150 |
|
151 |
/* Resolve links */ |
152 |
for (ni = first_nickinfo(); ni; ni = next_nickinfo()) { |
153 |
NickInfo *ni2; |
154 |
const char *last_nick; |
155 |
if (ni->last_realmask) { |
156 |
ni2 = ni; |
157 |
/* Find root nick (this will actually stop at the first nick |
158 |
* in the path to the root that isn't marked as linked, but |
159 |
* that's okay because such a nick will already have its |
160 |
* nickgroup ID set correctly) */ |
161 |
do { |
162 |
last_nick = ni2->last_realmask; |
163 |
ni2 = get_nickinfo(last_nick); |
164 |
} while (ni2 && ni2 != ni && ni2->last_realmask); |
165 |
ni->last_realmask = NULL; |
166 |
/* Set nickgroup, or delete nick if an error occurred */ |
167 |
if (ni2 == ni) { |
168 |
fprintf(stderr, |
169 |
"Warning: dropping nick %s with circular link\n", |
170 |
ni->nick); |
171 |
del_nickinfo(ni); |
172 |
} else if (!ni2) { |
173 |
fprintf(stderr, "Warning: dropping nick %s linked to" |
174 |
" nonexistent nick %s\n", ni->nick, last_nick); |
175 |
del_nickinfo(ni); |
176 |
} else { |
177 |
ngi = get_nickgroupinfo(ni->nickgroup); |
178 |
if (ngi) |
179 |
del_nickgroupinfo(ngi); |
180 |
ni->nickgroup = ni2->nickgroup; |
181 |
ngi = get_nickgroupinfo(ni->nickgroup); |
182 |
if (ngi) { |
183 |
ARRAY_EXTEND(ngi->nicks); |
184 |
strbcpy(ngi->nicks[ngi->nicks_count-1], ni->nick); |
185 |
} else if (ni->nickgroup != 0) { |
186 |
fprintf(stderr, "Warning: Nick group %d for nick %s not" |
187 |
" found -- program bug? Output may be corrupt.", |
188 |
ni->nickgroup, ni->nick); |
189 |
} |
190 |
} |
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
/*************************************************************************/ |
196 |
|
197 |
static struct { |
198 |
int32 flag; |
199 |
char mode; |
200 |
} cmodes[] = { |
201 |
{ 0x00000001, 'i' }, |
202 |
{ 0x00000002, 'm' }, |
203 |
{ 0x00000004, 'n' }, |
204 |
{ 0x00000008, 'p' }, |
205 |
{ 0x00000010, 's' }, |
206 |
{ 0x00000020, 't' }, |
207 |
{ 0x00000040, 'k' }, |
208 |
{ 0x00000080, 'l' }, |
209 |
{ 0x00000100, 'R' }, |
210 |
{ 0x00000200, 0 }, /* 'r', never set in mlock */ |
211 |
{ 0x00000400, 'K' }, |
212 |
{ 0x00000800, 'V' }, |
213 |
{ 0x00001000, 'Q' }, |
214 |
{ 0x00002000, 'c' }, |
215 |
{ 0x00004000, 'O' }, |
216 |
{ 0x00008000, 'A' }, |
217 |
{ 0x00010000, 'S' }, |
218 |
{ 0x00020000, 'H' }, |
219 |
{ 0x00040000, 'C' }, |
220 |
{ 0x00080000, 'u' }, |
221 |
{ 0x00100000, 'N' }, |
222 |
{ 0x00200000, 'f' }, |
223 |
{ 0x00400000, 'z' }, |
224 |
{ 0, 0 } |
225 |
}; |
226 |
|
227 |
static void ver8_load_chan(const char *dir, int type) |
228 |
{ |
229 |
dbFILE *f; |
230 |
int i, j, c; |
231 |
ChannelInfo *ci, dummy_ci; |
232 |
NickInfo *ni; |
233 |
int32 tmp32, mlock_on, mlock_off; |
234 |
MemoInfo tmpmi; |
235 |
|
236 |
f = open_db_ver(dir, "chan.db", 8, type==TYPE_DAYLIGHT?9:8, NULL); |
237 |
|
238 |
for (i = 0; i < 256; i++) { |
239 |
int16 tmp16; |
240 |
char *s, *on, *off; |
241 |
|
242 |
while ((c = getc_db(f)) == 1) { |
243 |
char nickbuf[32]; |
244 |
if (type == TYPE_IRCS) { |
245 |
char namebuf[204]; |
246 |
SAFE(read_buffer(namebuf, f)); |
247 |
#if CHANMAX < 204 |
248 |
if (CHANMAX-1 < strlen(namebuf)) { |
249 |
fprintf(stderr, "Warning: Channel %s name truncated\n", |
250 |
namebuf); |
251 |
namebuf[CHANMAX-1] = 0; |
252 |
} |
253 |
#endif |
254 |
if (get_channelinfo(namebuf)) { |
255 |
fprintf(stderr, "Channel %s conflicts with existing" |
256 |
" channel, ignoring\n", namebuf); |
257 |
ci = &dummy_ci; |
258 |
} else { |
259 |
ci = makechan(namebuf); |
260 |
} |
261 |
} else { |
262 |
char namebuf[64]; |
263 |
SAFE(read_buffer(namebuf, f)); |
264 |
if (get_channelinfo(namebuf)) { |
265 |
fprintf(stderr, "Channel %s conflicts with existing" |
266 |
" channel, ignoring\n", namebuf); |
267 |
ci = &dummy_ci; |
268 |
} else { |
269 |
ci = makechan(namebuf); |
270 |
} |
271 |
} |
272 |
SAFE(read_string(&s, f)); |
273 |
if (s) { |
274 |
ni = get_nickinfo(s); |
275 |
if (!ni) { |
276 |
fprintf(stderr, |
277 |
"Warning: Founder %s for channel %s not found\n", |
278 |
s, ci->name); |
279 |
} else if (!ni->nickgroup) { |
280 |
fprintf(stderr, "Warning: Founder %s for channel %s is a" |
281 |
" forbidden nick\n", s, ci->name); |
282 |
} else { |
283 |
ci->founder = ni->nickgroup; |
284 |
} |
285 |
} |
286 |
if (type != TYPE_IRCS) { |
287 |
SAFE(read_string(&s, f)); |
288 |
if (s) { |
289 |
ni = get_nickinfo(s); |
290 |
if (!ni) { |
291 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
292 |
" not found\n", s, ci->name); |
293 |
} else if (!ni->nickgroup) { |
294 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
295 |
" is a forbidden nick\n", s, ci->name); |
296 |
} else if (ni->nickgroup == ci->founder) { |
297 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
298 |
" is the same as the founder, clearing\n", |
299 |
s, ci->name); |
300 |
} else { |
301 |
ci->successor = ni->nickgroup; |
302 |
} |
303 |
} |
304 |
} |
305 |
init_password(&ci->founderpass); |
306 |
if (type == TYPE_IRCS) { |
307 |
char passbuf[16]; |
308 |
SAFE(read_buffer(passbuf, f)); |
309 |
memcpy(ci->founderpass.password, passbuf, sizeof(passbuf)); |
310 |
} else { |
311 |
char passbuf[32]; |
312 |
SAFE(read_buffer(passbuf, f)); |
313 |
memcpy(ci->founderpass.password, passbuf, sizeof(passbuf)); |
314 |
} |
315 |
SAFE(read_string(&ci->desc, f)); |
316 |
if (!ci->desc) |
317 |
ci->desc = (char *)""; |
318 |
SAFE(read_string(&ci->url, f)); |
319 |
SAFE(read_string(&ci->email, f)); |
320 |
if (type == TYPE_IRCS) |
321 |
SAFE(read_int16(&tmp16, f)); /* autoop */ |
322 |
SAFE(read_int32(&tmp32, f)); |
323 |
ci->time_registered = tmp32; |
324 |
SAFE(read_int32(&tmp32, f)); |
325 |
ci->last_used = tmp32; |
326 |
SAFE(read_string(&ci->last_topic, f)); |
327 |
SAFE(read_buffer(nickbuf, f)); |
328 |
strbcpy(ci->last_topic_setter, nickbuf); |
329 |
SAFE(read_int32(&tmp32, f)); |
330 |
ci->last_topic_time = tmp32; |
331 |
|
332 |
SAFE(read_int32(&tmp32, f)); /* flags */ |
333 |
if (tmp32 & 0x00000001) |
334 |
ci->flags |= CF_KEEPTOPIC; |
335 |
if (tmp32 & 0x00000002) |
336 |
ci->flags |= CF_SECUREOPS; |
337 |
if (tmp32 & 0x00000004) |
338 |
ci->flags |= CF_PRIVATE; |
339 |
if (tmp32 & 0x00000008) |
340 |
ci->flags |= CF_TOPICLOCK; |
341 |
if (tmp32 & 0x00000010) |
342 |
ci->flags |= CF_RESTRICTED; |
343 |
if (tmp32 & 0x00000020) |
344 |
ci->flags |= CF_LEAVEOPS; |
345 |
if (tmp32 & 0x00000040) |
346 |
ci->flags |= CF_SECURE; |
347 |
if (tmp32 & 0x00000080) |
348 |
ci->flags |= CF_VERBOTEN; |
349 |
if (tmp32 & 0x00000100) |
350 |
ci->founderpass.cipher = sstrdup("md5"); |
351 |
if (tmp32 & 0x00000200) |
352 |
ci->flags |= CF_NOEXPIRE; |
353 |
|
354 |
/* Levels data is ignored */ |
355 |
SAFE(read_int16(&tmp16, f)); |
356 |
for (j = tmp16; j > 0; j--) |
357 |
SAFE(read_int16(&tmp16, f)); |
358 |
|
359 |
SAFE(read_int16(&ci->access_count, f)); |
360 |
if (ci->access_count) { |
361 |
ci->access = scalloc(ci->access_count, sizeof(ChanAccess)); |
362 |
for (j = 0; j < ci->access_count; j++) { |
363 |
SAFE(read_int16(&tmp16, f)); /* in_use */ |
364 |
if (tmp16) { |
365 |
SAFE(read_int16(&ci->access[j].level, f)); |
366 |
if (type == TYPE_IRCS) { |
367 |
if (ci->access[j].level >= 10) |
368 |
ci->access[j].level = 15; |
369 |
else if (ci->access[j].level >= 7) |
370 |
ci->access[j].level += 3; |
371 |
ci->access[j].level = |
372 |
convert_acclev(ci->access[j].level); |
373 |
SAFE(read_int16(&tmp16, f)); /* autoop */ |
374 |
} |
375 |
SAFE(read_string(&s, f)); |
376 |
if (s) { |
377 |
ni = get_nickinfo(s); |
378 |
if (ni) |
379 |
ci->access[j].nickgroup = ni->nickgroup; |
380 |
} |
381 |
} |
382 |
} |
383 |
} |
384 |
|
385 |
SAFE(read_int16(&ci->akick_count, f)); |
386 |
if (ci->akick_count) { |
387 |
ci->akick = scalloc(ci->akick_count, sizeof(AutoKick)); |
388 |
for (j = 0; j < ci->akick_count; j++) { |
389 |
SAFE(read_int16(&tmp16, f)); /* in_use */ |
390 |
if (tmp16) { |
391 |
SAFE(read_int16(&tmp16, f)); /* is_nick */ |
392 |
SAFE(read_string(&s, f)); |
393 |
if (tmp16 && s) { |
394 |
ci->akick[j].mask = smalloc(strlen(s)+5); |
395 |
sprintf(ci->akick[j].mask, "%s!*@*", s); |
396 |
} else { |
397 |
ci->akick[j].mask = s; |
398 |
} |
399 |
SAFE(read_string(&s, f)); |
400 |
if (ci->akick[j].mask) { |
401 |
ci->akick[j].reason = s; |
402 |
strbcpy(ci->akick[j].who, "<unknown>"); |
403 |
ci->akick[j].set = time(NULL); |
404 |
} |
405 |
} |
406 |
} |
407 |
} |
408 |
|
409 |
if (type == TYPE_DAYLIGHT) { |
410 |
SAFE(read_int32(&mlock_on, f)); |
411 |
SAFE(read_int32(&mlock_off, f)); |
412 |
} else { |
413 |
SAFE(read_int16(&tmp16, f)); |
414 |
mlock_on = tmp16 & 0x00FF; |
415 |
SAFE(read_int16(&tmp16, f)); |
416 |
mlock_off = tmp16 & 0x00FF; |
417 |
} |
418 |
ci->mlock.on = on = scalloc(64, 1); |
419 |
ci->mlock.off = off = scalloc(64, 1); |
420 |
for (j = 0; cmodes[j].flag != 0; j++) { |
421 |
if (mlock_on & cmodes[j].flag) |
422 |
*on++ = cmodes[j].mode; |
423 |
if (mlock_off & cmodes[j].flag) |
424 |
*off++ = cmodes[j].mode; |
425 |
} |
426 |
*on = 0; |
427 |
*off = 0; |
428 |
SAFE(read_int32(&ci->mlock.limit, f)); |
429 |
SAFE(read_string(&ci->mlock.key, f)); |
430 |
|
431 |
SAFE(read_int16(&tmpmi.memos_count, f)); |
432 |
SAFE(read_int16(&tmp16, f)); /* memomax */ |
433 |
if (tmpmi.memos_count) { |
434 |
Memo *memos; |
435 |
memos = scalloc(sizeof(Memo), tmpmi.memos_count); |
436 |
tmpmi.memos = memos; |
437 |
for (j = 0; j < tmpmi.memos_count; j++, memos++) { |
438 |
SAFE(read_uint32(&memos->number, f)); |
439 |
SAFE(read_int16(&memos->flags, f)); |
440 |
SAFE(read_int32(&tmp32, f)); |
441 |
memos->time = tmp32; |
442 |
SAFE(read_buffer(nickbuf, f)); |
443 |
strbcpy(memos->sender, nickbuf); |
444 |
SAFE(read_string(&memos->text, f)); |
445 |
} |
446 |
} |
447 |
|
448 |
SAFE(read_string(&ci->entry_message, f)); |
449 |
|
450 |
if (!(ci->flags & CF_VERBOTEN) && !ci->founder) { |
451 |
fprintf(stderr, "Ignoring channel %s (missing founder)\n", |
452 |
ci->name); |
453 |
del_channelinfo(ci); |
454 |
} |
455 |
|
456 |
} /* while (getc_db(f) == 1) */ |
457 |
|
458 |
if (c != 0) { |
459 |
fprintf(stderr, "%s is corrupt, aborting.\n", f->filename); |
460 |
exit(1); |
461 |
} |
462 |
} /* for (i) */ |
463 |
close_db(f); |
464 |
} |
465 |
|
466 |
/*************************************************************************/ |
467 |
|
468 |
static void ver8_load_oper(const char *dir, int type) |
469 |
{ |
470 |
dbFILE *f; |
471 |
int16 i, n; |
472 |
int32 tmp32; |
473 |
char *s; |
474 |
|
475 |
f = open_db_ver(dir, "oper.db", 8, 8, NULL); |
476 |
/* servadmin */ |
477 |
SAFE(read_int16(&n, f)); |
478 |
for (i = 0; i < n; i++) { |
479 |
SAFE(read_string(&s, f)); |
480 |
set_os_priv(s, NP_SERVADMIN); |
481 |
} |
482 |
if (type == TYPE_IRCS) { |
483 |
/* senior */ |
484 |
SAFE(read_int16(&n, f)); |
485 |
for (i = 0; i < n; i++) { |
486 |
SAFE(read_string(&s, f)); |
487 |
set_os_priv(s, NP_SERVADMIN); |
488 |
} |
489 |
/* junior */ |
490 |
SAFE(read_int16(&n, f)); |
491 |
for (i = 0; i < n; i++) { |
492 |
SAFE(read_string(&s, f)); |
493 |
set_os_priv(s, NP_SERVOPER); |
494 |
} |
495 |
/* helper */ |
496 |
SAFE(read_int16(&n, f)); |
497 |
for (i = 0; i < n; i++) { |
498 |
SAFE(read_string(&s, f)); |
499 |
set_os_priv(s, NP_SERVOPER); |
500 |
} |
501 |
} |
502 |
/* servoper */ |
503 |
SAFE(read_int16(&n, f)); |
504 |
for (i = 0; i < n; i++) { |
505 |
SAFE(read_string(&s, f)); |
506 |
set_os_priv(s, NP_SERVOPER); |
507 |
} |
508 |
SAFE(read_int32(&maxusercnt, f)); |
509 |
if (type != TYPE_IRCS) { |
510 |
SAFE(read_int32(&tmp32, f)); |
511 |
maxusertime = tmp32; |
512 |
} |
513 |
close_db(f); |
514 |
} |
515 |
|
516 |
/*************************************************************************/ |
517 |
|
518 |
static void ver8_load_akill(const char *dir, int type) |
519 |
{ |
520 |
dbFILE *f; |
521 |
int16 i, n; |
522 |
MaskData *md; |
523 |
|
524 |
f = open_db_ver(dir, "akill.db", 8, 8, NULL); |
525 |
SAFE(read_int16(&n, f)); |
526 |
md = scalloc(sizeof(*md), n); |
527 |
for (i = 0; i < n; i++) { |
528 |
char nick[32]; |
529 |
int32 tmp32; |
530 |
SAFE(read_string(&md[i].mask, f)); |
531 |
SAFE(read_string(&md[i].reason, f)); |
532 |
SAFE(read_buffer(nick, f)); |
533 |
strbcpy(md[i].who, nick); |
534 |
SAFE(read_int32(&tmp32, f)); |
535 |
md[i].time = tmp32; |
536 |
SAFE(read_int32(&tmp32, f)); |
537 |
md[i].expires = tmp32; |
538 |
if (md[i].mask) |
539 |
add_maskdata(MD_AKILL, &md[i]); |
540 |
} |
541 |
close_db(f); |
542 |
} |
543 |
|
544 |
/*************************************************************************/ |
545 |
|
546 |
static void ver8_load_exception(const char *dir, int type) |
547 |
{ |
548 |
dbFILE *f; |
549 |
int16 i, n; |
550 |
MaskData *md; |
551 |
|
552 |
f = open_db_ver(dir, "exception.db", 8, 8, NULL); |
553 |
SAFE(read_int16(&n, f)); |
554 |
md = scalloc(sizeof(*md), n); |
555 |
for (i = 0; i < n; i++) { |
556 |
char nick[32]; |
557 |
int32 tmp32; |
558 |
SAFE(read_string(&md[i].mask, f)); |
559 |
SAFE(read_int16(&md[i].limit, f)); |
560 |
SAFE(read_buffer(nick, f)); |
561 |
strbcpy(md[i].who, nick); |
562 |
SAFE(read_string(&md[i].reason, f)); |
563 |
SAFE(read_int32(&tmp32, f)); |
564 |
md[i].time = tmp32; |
565 |
SAFE(read_int32(&tmp32, f)); |
566 |
md[i].expires = tmp32; |
567 |
if (md[i].mask) |
568 |
add_maskdata(MD_AKILL, &md[i]); |
569 |
} |
570 |
close_db(f); |
571 |
} |
572 |
|
573 |
/*************************************************************************/ |
574 |
|
575 |
static void ver8_load_news(const char *dir, int type) |
576 |
{ |
577 |
dbFILE *f; |
578 |
int16 i, n; |
579 |
NewsItem *news; |
580 |
|
581 |
f = open_db_ver(dir, "news.db", 8, 8, NULL); |
582 |
SAFE(read_int16(&n, f)); |
583 |
news = scalloc(sizeof(*news), n); |
584 |
for (i = 0; i < n; i++) { |
585 |
char nick[32]; |
586 |
int32 tmp32; |
587 |
SAFE(read_int16(&news[i].type, f)); |
588 |
SAFE(read_int32(&news[i].num, f)); |
589 |
SAFE(read_string(&news[i].text, f)); |
590 |
SAFE(read_buffer(nick, f)); |
591 |
strbcpy(news[i].who, nick); |
592 |
SAFE(read_int32(&tmp32, f)); |
593 |
news[i].time = tmp32; |
594 |
add_news(&news[i]); |
595 |
} |
596 |
close_db(f); |
597 |
} |
598 |
|
599 |
/*************************************************************************/ |
600 |
|
601 |
static void ircs_load_gline(const char *dir) |
602 |
{ |
603 |
dbFILE *f; |
604 |
int16 i, n; |
605 |
MaskData *md; |
606 |
|
607 |
f = open_db_ver(dir, "gline.db", 8, 8, NULL); |
608 |
read_int16(&n, f); |
609 |
md = scalloc(sizeof(*md), n); |
610 |
for (i = 0; i < n; i++) { |
611 |
char *user, *host; |
612 |
char nick[32]; |
613 |
int32 tmp32; |
614 |
SAFE(read_string(&user, f)); |
615 |
SAFE(read_string(&host, f)); |
616 |
if (user && host) { |
617 |
md[i].mask = smalloc(strlen(user)+strlen(host)+2); |
618 |
sprintf(md[i].mask, "%s@%s", user, host); |
619 |
} else { |
620 |
md[i].mask = NULL; |
621 |
} |
622 |
SAFE(read_string(&md[i].reason, f)); |
623 |
SAFE(read_buffer(nick, f)); |
624 |
strbcpy(md[i].who, nick); |
625 |
SAFE(read_int32(&tmp32, f)); |
626 |
md[i].time = tmp32; |
627 |
SAFE(read_int32(&tmp32, f)); |
628 |
md[i].expires = tmp32; |
629 |
if (md[i].mask) |
630 |
add_maskdata(MD_AKILL, &md[i]); |
631 |
} |
632 |
close_db(f); |
633 |
} |
634 |
|
635 |
/*************************************************************************/ |
636 |
/*************************************************************************/ |
637 |
|
638 |
static const char *check_daylight(const char *dir) |
639 |
{ |
640 |
char buf[PATH_MAX+1]; |
641 |
|
642 |
snprintf(buf, sizeof(buf), "%s/services.conn", dir); |
643 |
if (access(buf, R_OK) == 0) |
644 |
return "Daylight"; |
645 |
return NULL; |
646 |
} |
647 |
|
648 |
static void load_daylight(const char *dir, int verbose, int ac, |
649 |
char **av) |
650 |
{ |
651 |
if (ac > 1) { |
652 |
fprintf(stderr, "Unrecognized option %s\n", av[1]); |
653 |
usage(av[0]); |
654 |
} |
655 |
if (verbose) |
656 |
fprintf(stderr, "Loading nick.db...\n"); |
657 |
ver8_load_nick(dir, TYPE_DAYLIGHT); |
658 |
if (verbose) |
659 |
fprintf(stderr, "Loading chan.db...\n"); |
660 |
ver8_load_chan(dir, TYPE_DAYLIGHT); |
661 |
if (verbose) |
662 |
fprintf(stderr, "Loading oper.db...\n"); |
663 |
ver8_load_oper(dir, TYPE_DAYLIGHT); |
664 |
if (verbose) |
665 |
fprintf(stderr, "Loading akill.db...\n"); |
666 |
ver8_load_akill(dir, TYPE_DAYLIGHT); |
667 |
if (verbose) |
668 |
fprintf(stderr, "Loading exception.db...\n"); |
669 |
ver8_load_exception(dir, TYPE_DAYLIGHT); |
670 |
if (verbose) |
671 |
fprintf(stderr, "Loading news.db...\n"); |
672 |
ver8_load_news(dir, TYPE_DAYLIGHT); |
673 |
} |
674 |
|
675 |
/*************************************************************************/ |
676 |
/*************************************************************************/ |
677 |
|
678 |
static const char *check_ircs_1_2(const char *dir) |
679 |
{ |
680 |
char buf[PATH_MAX+1]; |
681 |
|
682 |
snprintf(buf, sizeof(buf), "%s/gline.db", dir); |
683 |
if (access(buf, R_OK) == 0) |
684 |
return "IRCS 1.2"; |
685 |
return NULL; |
686 |
} |
687 |
|
688 |
static void load_ircs_1_2(const char *dir, int verbose, int ac, |
689 |
char **av) |
690 |
{ |
691 |
if (ac > 1) { |
692 |
fprintf(stderr, "Unrecognized option %s\n", av[1]); |
693 |
usage(av[0]); |
694 |
} |
695 |
if (verbose) |
696 |
fprintf(stderr, "Loading nick.db...\n"); |
697 |
ver8_load_nick(dir, TYPE_IRCS); |
698 |
if (verbose) |
699 |
fprintf(stderr, "Loading chan.db...\n"); |
700 |
ver8_load_chan(dir, TYPE_IRCS); |
701 |
if (verbose) |
702 |
fprintf(stderr, "Loading oper.db...\n"); |
703 |
ver8_load_oper(dir, TYPE_IRCS); |
704 |
if (verbose) |
705 |
fprintf(stderr, "Loading gline.db...\n"); |
706 |
ircs_load_gline(dir); |
707 |
} |
708 |
|
709 |
/*************************************************************************/ |
710 |
/*************************************************************************/ |
711 |
|
712 |
DBTypeInfo dbtype_daylight = { |
713 |
"daylight", |
714 |
check_daylight, |
715 |
load_daylight |
716 |
}; |
717 |
|
718 |
DBTypeInfo dbtype_ircs_1_2 = { |
719 |
"ircs-1.2", |
720 |
check_ircs_1_2, |
721 |
load_ircs_1_2 |
722 |
}; |
723 |
|
724 |
/*************************************************************************/ |
725 |
|
726 |
/* |
727 |
* Local variables: |
728 |
* c-file-style: "stroustrup" |
729 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
730 |
* indent-tabs-mode: nil |
731 |
* End: |
732 |
* |
733 |
* vim: expandtab shiftwidth=4: |
734 |
*/ |