| 1 |
/* Conversion routines for trircd Services program (version 4.26). |
| 2 |
* |
| 3 |
* IRC Services is copyright (c) 1996-2009 Andrew Church. |
| 4 |
* E-mail: <achurch@achurch.org> |
| 5 |
* Parts written by Andrew Kempe and others. |
| 6 |
* This program is free but copyrighted software; see the file GPL.txt for |
| 7 |
* details. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "convert-db.h" |
| 11 |
|
| 12 |
#if NICKMAX < 32 |
| 13 |
# error NICKMAX too small (must be >=32) |
| 14 |
#elif CHANMAX < 64 |
| 15 |
# error CHANMAX too small (must be >=64) |
| 16 |
#elif PASSMAX < 32 |
| 17 |
# error PASSMAX too small (must be >=32) |
| 18 |
#endif |
| 19 |
|
| 20 |
/*************************************************************************/ |
| 21 |
|
| 22 |
static void |
| 23 |
trircd_load_nick(const char *dir) |
| 24 |
{ |
| 25 |
dbFILE *f; |
| 26 |
int i, j, c; |
| 27 |
int16 tmp16; |
| 28 |
int32 tmp32; |
| 29 |
NickInfo *ni; |
| 30 |
NickGroupInfo *ngi; |
| 31 |
|
| 32 |
f = open_db_ver(dir, "nick.db", 22, 25, NULL); |
| 33 |
for (i = 0; i < 256; i++) |
| 34 |
{ |
| 35 |
while ((c = getc_db(f)) == 1) |
| 36 |
{ |
| 37 |
char nickbuf[32], passbuf[32]; |
| 38 |
SAFE(read_buffer(nickbuf, f)); |
| 39 |
ni = makenick(nickbuf, &ngi); |
| 40 |
SAFE(read_buffer(passbuf, f)); |
| 41 |
init_password(&ngi->pass); |
| 42 |
memcpy(ngi->pass.password, passbuf, sizeof(passbuf)); |
| 43 |
SAFE(read_string(&ngi->url, f)); |
| 44 |
SAFE(read_string(&ngi->email, f)); |
| 45 |
SAFE(read_string(&ni->last_usermask, f)); |
| 46 |
if (!ni->last_usermask) |
| 47 |
ni->last_usermask = (char *) "@"; |
| 48 |
SAFE(read_string(&ni->last_realname, f)); |
| 49 |
if (!ni->last_realname) |
| 50 |
ni->last_realname = (char *) ""; |
| 51 |
SAFE(read_string(&ni->last_quit, f)); |
| 52 |
SAFE(read_int32(&tmp32, f)); |
| 53 |
ni->time_registered = tmp32; |
| 54 |
SAFE(read_int32(&tmp32, f)); |
| 55 |
ni->last_seen = tmp32; |
| 56 |
SAFE(read_int16(&tmp16, f)); /* status */ |
| 57 |
if (tmp16 & 0x0001) |
| 58 |
ngi->pass.cipher = sstrdup("md5"); |
| 59 |
if (tmp16 & 0x0002) |
| 60 |
{ |
| 61 |
ni->status |= NS_VERBOTEN; |
| 62 |
del_nickgroupinfo(ngi); |
| 63 |
ni->nickgroup = 0; |
| 64 |
} |
| 65 |
if (tmp16 & 0x0004) |
| 66 |
ni->status |= NS_NOEXPIRE; |
| 67 |
SAFE(read_string(&ni->last_realmask, f)); /* link */ |
| 68 |
SAFE(read_int16(&tmp16, f)); /* linkcount */ |
| 69 |
if (ni->last_realmask) |
| 70 |
{ |
| 71 |
ni->nickgroup = 0; |
| 72 |
SAFE(read_int16(&tmp16, f)); /* channelcount */ |
| 73 |
} |
| 74 |
else |
| 75 |
{ |
| 76 |
void *tmpptr; |
| 77 |
SAFE(read_int32(&tmp32, f)); /* flags */ |
| 78 |
if (tmp32 & 0x00000001) |
| 79 |
ngi->flags |= NF_KILLPROTECT; |
| 80 |
if (tmp32 & 0x00000002) |
| 81 |
ngi->flags |= NF_SECURE; |
| 82 |
if (tmp32 & 0x00000008) |
| 83 |
ngi->flags |= NF_MEMO_HARDMAX; |
| 84 |
if (tmp32 & 0x00000010) |
| 85 |
ngi->flags |= NF_MEMO_SIGNON; |
| 86 |
if (tmp32 & 0x00000020) |
| 87 |
ngi->flags |= NF_MEMO_RECEIVE; |
| 88 |
if (tmp32 & 0x00000040) |
| 89 |
ngi->flags |= NF_PRIVATE; |
| 90 |
if (tmp32 & 0x00000080) |
| 91 |
ngi->flags |= NF_HIDE_EMAIL; |
| 92 |
if (tmp32 & 0x00000100) |
| 93 |
ngi->flags |= NF_HIDE_MASK; |
| 94 |
if (tmp32 & 0x00000200) |
| 95 |
ngi->flags |= NF_HIDE_QUIT; |
| 96 |
if (tmp32 & 0x00000400) |
| 97 |
ngi->flags |= NF_KILL_QUICK; |
| 98 |
if (tmp32 & 0x00000800) |
| 99 |
ngi->flags |= NF_KILL_IMMED; |
| 100 |
if (tmp32 & 0x80000000) |
| 101 |
ngi->flags |= NF_MEMO_FWD | NF_MEMO_FWDCOPY; |
| 102 |
SAFE(read_ptr(&tmpptr, f)); |
| 103 |
if (tmpptr) |
| 104 |
{ |
| 105 |
SAFE(read_buffer(nickbuf, f)); |
| 106 |
strbcpy(ngi->suspend_who, nickbuf); |
| 107 |
SAFE(read_string(&ngi->suspend_reason, f)); |
| 108 |
SAFE(read_int32(&tmp32, f)); |
| 109 |
ngi->suspend_time = tmp32; |
| 110 |
SAFE(read_int32(&tmp32, f)); |
| 111 |
ngi->suspend_expires = tmp32; |
| 112 |
ngi->flags |= NF_SUSPENDED; |
| 113 |
} |
| 114 |
SAFE(read_int16(&ngi->access_count, f)); |
| 115 |
if (ngi->access_count) |
| 116 |
{ |
| 117 |
char **access; |
| 118 |
access = scalloc(sizeof(char *), ngi->access_count); |
| 119 |
ngi->access = access; |
| 120 |
for (j = 0; j < ngi->access_count; j++, access++) |
| 121 |
SAFE(read_string(access, f)); |
| 122 |
} |
| 123 |
SAFE(read_int16(&ngi->memos.memos_count, f)); |
| 124 |
SAFE(read_int16(&ngi->memos.memomax, f)); |
| 125 |
if (ngi->memos.memos_count) |
| 126 |
{ |
| 127 |
Memo *memos; |
| 128 |
memos = scalloc(sizeof(Memo), ngi->memos.memos_count); |
| 129 |
ngi->memos.memos = memos; |
| 130 |
for (j = 0; j < ngi->memos.memos_count; j++, memos++) |
| 131 |
{ |
| 132 |
SAFE(read_uint32(&memos->number, f)); |
| 133 |
SAFE(read_int16(&tmp16, f)); |
| 134 |
if (tmp16 & 1) |
| 135 |
memos->flags |= MF_UNREAD; |
| 136 |
SAFE(read_int32(&tmp32, f)); |
| 137 |
memos->time = tmp32; |
| 138 |
SAFE(read_buffer(nickbuf, f)); |
| 139 |
strbcpy(memos->sender, nickbuf); |
| 140 |
SAFE(read_string(&memos->text, f)); |
| 141 |
} |
| 142 |
} |
| 143 |
SAFE(read_int16(&tmp16, f)); /* channelcount */ |
| 144 |
SAFE(read_int16(&tmp16, f)); /* channelmax */ |
| 145 |
SAFE(read_int16(&ngi->language, f)); |
| 146 |
} |
| 147 |
} /* while (getc_db(f) == 1) */ |
| 148 |
if (c != 0) |
| 149 |
{ |
| 150 |
fprintf(stderr, "%s is corrupt, aborting.\n", f->filename); |
| 151 |
exit(1); |
| 152 |
} |
| 153 |
} /* for (i) */ |
| 154 |
close_db(f); |
| 155 |
|
| 156 |
/* Resolve links */ |
| 157 |
for (ni = first_nickinfo(); ni; ni = next_nickinfo()) |
| 158 |
{ |
| 159 |
NickInfo *ni2; |
| 160 |
const char *last_nick; |
| 161 |
if (ni->last_realmask) |
| 162 |
{ |
| 163 |
ni2 = ni; |
| 164 |
/* Find root nick (this will actually stop at the first nick |
| 165 |
* in the path to the root that isn't marked as linked, but |
| 166 |
* that's okay because such a nick will already have its |
| 167 |
* nickgroup ID set correctly) */ |
| 168 |
do |
| 169 |
{ |
| 170 |
last_nick = ni2->last_realmask; |
| 171 |
ni2 = get_nickinfo(last_nick); |
| 172 |
} while (ni2 && ni2 != ni && ni2->last_realmask); |
| 173 |
ni->last_realmask = NULL; |
| 174 |
/* Set nickgroup, or delete nick if an error occurred */ |
| 175 |
if (ni2 == ni) |
| 176 |
{ |
| 177 |
fprintf(stderr, |
| 178 |
"Warning: dropping nick %s with circular link\n", ni->nick); |
| 179 |
del_nickinfo(ni); |
| 180 |
} |
| 181 |
else if (!ni2) |
| 182 |
{ |
| 183 |
fprintf(stderr, "Warning: dropping nick %s linked to" |
| 184 |
" nonexistent nick %s\n", ni->nick, last_nick); |
| 185 |
del_nickinfo(ni); |
| 186 |
} |
| 187 |
else |
| 188 |
{ |
| 189 |
ngi = get_nickgroupinfo(ni->nickgroup); |
| 190 |
if (ngi) |
| 191 |
del_nickgroupinfo(ngi); |
| 192 |
ni->nickgroup = ni2->nickgroup; |
| 193 |
ngi = get_nickgroupinfo(ni->nickgroup); |
| 194 |
if (ngi) |
| 195 |
{ |
| 196 |
ARRAY_EXTEND(ngi->nicks); |
| 197 |
strbcpy(ngi->nicks[ngi->nicks_count - 1], ni->nick); |
| 198 |
} |
| 199 |
else if (ni->nickgroup != 0) |
| 200 |
{ |
| 201 |
fprintf(stderr, "Warning: Nick group %d for nick %s not" |
| 202 |
" found -- program bug? Output may be corrupt.", |
| 203 |
ni->nickgroup, ni->nick); |
| 204 |
} |
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
/*************************************************************************/ |
| 211 |
|
| 212 |
static void |
| 213 |
trircd_load_ajoin(const char *dir) |
| 214 |
{ |
| 215 |
dbFILE *f; |
| 216 |
int c; |
| 217 |
int16 j, tmp16; |
| 218 |
int32 tmp32; |
| 219 |
void *tmpptr; |
| 220 |
char *s; |
| 221 |
NickGroupInfo *ngi; |
| 222 |
|
| 223 |
f = open_db_ver(dir, "ajoin.db", 25, 25, NULL); |
| 224 |
while ((c = getc_db(f)) == 1) |
| 225 |
{ |
| 226 |
int is_root; /* is this a root nick (should we store data)? */ |
| 227 |
char nickbuf[32]; |
| 228 |
|
| 229 |
SAFE(read_buffer(nickbuf, f)); |
| 230 |
ngi = get_nickgroupinfo_by_nick(nickbuf); |
| 231 |
is_root = ngi && stricmp(nickbuf, ngi_mainnick(ngi)) == 0; |
| 232 |
SAFE(read_int16(&tmp16, f)); /* ajoincount */ |
| 233 |
if (is_root) |
| 234 |
{ |
| 235 |
ngi->ajoin_count = tmp16; |
| 236 |
ngi->ajoin = scalloc(sizeof(char *), tmp16); |
| 237 |
for (j = 0; j < tmp16; j++) |
| 238 |
SAFE(read_string(&ngi->ajoin[j], f)); |
| 239 |
} |
| 240 |
else |
| 241 |
{ |
| 242 |
for (j = 0; j < tmp16; j++) |
| 243 |
SAFE(read_string(&s, f)); |
| 244 |
} |
| 245 |
SAFE(read_ptr((void *) &tmpptr, f)); /* forbidinfo */ |
| 246 |
if (tmpptr) |
| 247 |
{ |
| 248 |
SAFE(read_buffer(nickbuf, f)); /* forbidder */ |
| 249 |
SAFE(read_string(&s, f)); /* forbid_message */ |
| 250 |
} |
| 251 |
SAFE(read_int32(&tmp32, f)); /* authcode */ |
| 252 |
SAFE(read_int16(&tmp16, f)); /* authmode */ |
| 253 |
if (tmp16 & 3) /* NH_AUTHENTIC | NH_OLDAUTH */ |
| 254 |
tmp32 = 0; |
| 255 |
if (is_root) |
| 256 |
{ |
| 257 |
ngi->authcode = tmp32; |
| 258 |
ngi->authset = time(NULL); |
| 259 |
} |
| 260 |
SAFE(read_int16(&tmp16, f)); /* ignorecount */ |
| 261 |
if (is_root) |
| 262 |
{ |
| 263 |
ngi->ignore_count = tmp16; |
| 264 |
ngi->ignore = scalloc(sizeof(char *), tmp16); |
| 265 |
for (j = 0; j < ngi->ignore_count; j++) |
| 266 |
{ |
| 267 |
SAFE(read_int16(&tmp16, f)); |
| 268 |
if (tmp16) |
| 269 |
SAFE(read_string(&ngi->ignore[j], f)); |
| 270 |
} |
| 271 |
} |
| 272 |
else |
| 273 |
{ |
| 274 |
for (j = tmp16; j > 0; j--) |
| 275 |
{ |
| 276 |
SAFE(read_int16(&tmp16, f)); |
| 277 |
if (tmp16) |
| 278 |
SAFE(read_string(&s, f)); |
| 279 |
} |
| 280 |
} |
| 281 |
SAFE(read_string(&s, f)); /* infomsg */ |
| 282 |
if (is_root) |
| 283 |
ngi->info = s; |
| 284 |
SAFE(read_int32(&tmp32, f)); /* expiredelay */ |
| 285 |
SAFE(read_int16(&tmp16, f)); /* count for memo expire */ |
| 286 |
for (j = 0; j < tmp16; j++) |
| 287 |
SAFE(read_int32(&tmp32, f)); /* memo.expiration */ |
| 288 |
} /* while (getc_db(f) == 1) */ |
| 289 |
if (c != -1) |
| 290 |
fprintf(stderr, "Warning: %s may be corrupt.\n", f->filename); |
| 291 |
close_db(f); |
| 292 |
} |
| 293 |
|
| 294 |
/*************************************************************************/ |
| 295 |
|
| 296 |
static struct |
| 297 |
{ |
| 298 |
int32 flag; |
| 299 |
char mode; |
| 300 |
} cmodes[] = |
| 301 |
{ |
| 302 |
{ |
| 303 |
0x00000001, 'i'}, |
| 304 |
{ |
| 305 |
0x00000002, 'm'}, |
| 306 |
{ |
| 307 |
0x00000004, 'n'}, |
| 308 |
{ |
| 309 |
0x00000008, 'p'}, |
| 310 |
{ |
| 311 |
0x00000010, 's'}, |
| 312 |
{ |
| 313 |
0x00000020, 't'}, |
| 314 |
{ |
| 315 |
0x00000040, 'k'}, |
| 316 |
{ |
| 317 |
0x00000080, 'l'}, |
| 318 |
{ |
| 319 |
0x00000100, 'R'}, |
| 320 |
{ |
| 321 |
0x00000200, 0}, /* 'r', never set in mlock */ |
| 322 |
{ |
| 323 |
0x00000400, 'c'}, |
| 324 |
{ |
| 325 |
0x00000800, 'O'}, |
| 326 |
{ |
| 327 |
0x00001000, 'A'}, |
| 328 |
{ |
| 329 |
0x00002000, 'z'}, |
| 330 |
{ |
| 331 |
0x00004000, 'Q'}, |
| 332 |
{ |
| 333 |
0x00008000, 'K'}, |
| 334 |
{ |
| 335 |
0x00010000, 'V'}, |
| 336 |
{ |
| 337 |
0x00020000, 'H'}, |
| 338 |
{ |
| 339 |
0x00040000, 'C'}, |
| 340 |
{ |
| 341 |
0x00080000, 'N'}, |
| 342 |
{ |
| 343 |
0x00100000, 'S'}, |
| 344 |
{ |
| 345 |
0x00200000, 'G'}, |
| 346 |
{ |
| 347 |
0x00400000, 'u'}, |
| 348 |
{ |
| 349 |
0x00800000, 'f'}, |
| 350 |
{ |
| 351 |
0x01000000, 'M'}, |
| 352 |
{ |
| 353 |
0, 0} |
| 354 |
}; |
| 355 |
|
| 356 |
static void |
| 357 |
trircd_load_chan(const char *dir) |
| 358 |
{ |
| 359 |
dbFILE *f; |
| 360 |
int i, j, c; |
| 361 |
ChannelInfo *ci; |
| 362 |
NickInfo *ni; |
| 363 |
int32 tmp32, mlock_on, mlock_off; |
| 364 |
MemoInfo tmpmi; |
| 365 |
void *tmpptr; |
| 366 |
|
| 367 |
f = open_db_ver(dir, "chan.db", 22, 25, NULL); |
| 368 |
|
| 369 |
for (i = 0; i < 256; i++) |
| 370 |
{ |
| 371 |
int16 tmp16; |
| 372 |
char *s, *on, *off; |
| 373 |
char namebuf[64], passbuf[32], nickbuf[32]; |
| 374 |
|
| 375 |
while ((c = getc_db(f)) == 1) |
| 376 |
{ |
| 377 |
SAFE(read_buffer(namebuf, f)); |
| 378 |
ci = makechan(namebuf); |
| 379 |
SAFE(read_string(&s, f)); |
| 380 |
if (s) |
| 381 |
{ |
| 382 |
ni = get_nickinfo(s); |
| 383 |
if (!ni) |
| 384 |
{ |
| 385 |
fprintf(stderr, |
| 386 |
"Warning: Founder %s for channel %s not found\n", |
| 387 |
s, ci->name); |
| 388 |
} |
| 389 |
else if (!ni->nickgroup) |
| 390 |
{ |
| 391 |
fprintf(stderr, "Warning: Founder %s for channel %s is a" |
| 392 |
" forbidden nick\n", s, ci->name); |
| 393 |
} |
| 394 |
else |
| 395 |
{ |
| 396 |
ci->founder = ni->nickgroup; |
| 397 |
} |
| 398 |
} |
| 399 |
SAFE(read_string(&s, f)); |
| 400 |
if (s) |
| 401 |
{ |
| 402 |
ni = get_nickinfo(s); |
| 403 |
if (!ni) |
| 404 |
{ |
| 405 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
| 406 |
" not found\n", s, ci->name); |
| 407 |
} |
| 408 |
else if (!ni->nickgroup) |
| 409 |
{ |
| 410 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
| 411 |
" is a forbidden nick\n", s, ci->name); |
| 412 |
} |
| 413 |
else if (ni->nickgroup == ci->founder) |
| 414 |
{ |
| 415 |
fprintf(stderr, "Warning: Successor %s for channel %s" |
| 416 |
" is the same as the founder, clearing\n", s, ci->name); |
| 417 |
} |
| 418 |
else |
| 419 |
{ |
| 420 |
ci->successor = ni->nickgroup; |
| 421 |
} |
| 422 |
} |
| 423 |
SAFE(read_buffer(passbuf, f)); |
| 424 |
init_password(&ci->founderpass); |
| 425 |
memcpy(ci->founderpass.password, passbuf, sizeof(passbuf)); |
| 426 |
SAFE(read_string(&ci->desc, f)); |
| 427 |
if (!ci->desc) |
| 428 |
ci->desc = (char *) ""; |
| 429 |
SAFE(read_string(&ci->url, f)); |
| 430 |
SAFE(read_string(&ci->email, f)); |
| 431 |
SAFE(read_int32(&tmp32, f)); |
| 432 |
ci->time_registered = tmp32; |
| 433 |
SAFE(read_int32(&tmp32, f)); |
| 434 |
ci->last_used = tmp32; |
| 435 |
SAFE(read_string(&ci->last_topic, f)); |
| 436 |
SAFE(read_buffer(nickbuf, f)); |
| 437 |
strbcpy(ci->last_topic_setter, nickbuf); |
| 438 |
SAFE(read_int32(&tmp32, f)); |
| 439 |
ci->last_topic_time = tmp32; |
| 440 |
|
| 441 |
SAFE(read_int32(&tmp32, f)); /* flags */ |
| 442 |
if (tmp32 & 0x00000001) |
| 443 |
ci->flags |= CF_KEEPTOPIC; |
| 444 |
if (tmp32 & 0x00000002) |
| 445 |
ci->flags |= CF_SECUREOPS; |
| 446 |
if (tmp32 & 0x00000004) |
| 447 |
ci->flags |= CF_PRIVATE; |
| 448 |
if (tmp32 & 0x00000008) |
| 449 |
ci->flags |= CF_TOPICLOCK; |
| 450 |
if (tmp32 & 0x00000010) |
| 451 |
ci->flags |= CF_RESTRICTED; |
| 452 |
if (tmp32 & 0x00000020) |
| 453 |
ci->flags |= CF_LEAVEOPS; |
| 454 |
if (tmp32 & 0x00000040) |
| 455 |
ci->flags |= CF_SECURE; |
| 456 |
if (tmp32 & 0x00000080) |
| 457 |
ci->flags |= CF_VERBOTEN; |
| 458 |
if (tmp32 & 0x00000100) |
| 459 |
ci->founderpass.cipher = sstrdup("md5"); |
| 460 |
if (tmp32 & 0x00000200) |
| 461 |
ci->flags |= CF_NOEXPIRE; |
| 462 |
if (tmp32 & 0x01000000) |
| 463 |
ci->flags |= CF_HIDE_TOPIC; |
| 464 |
if (tmp32 & 0x04000000) |
| 465 |
ci->flags |= CF_HIDE_MLOCK; |
| 466 |
if (tmp32 & 0x80000000) |
| 467 |
ci->flags |= CF_HIDE_EMAIL; |
| 468 |
|
| 469 |
SAFE(read_ptr((void **) &tmpptr, f)); |
| 470 |
if (tmpptr) |
| 471 |
{ |
| 472 |
SAFE(read_buffer(nickbuf, f)); |
| 473 |
strbcpy(ci->suspend_who, nickbuf); |
| 474 |
SAFE(read_string(&ci->suspend_reason, f)); |
| 475 |
SAFE(read_int32(&tmp32, f)); |
| 476 |
ci->suspend_time = tmp32; |
| 477 |
SAFE(read_int32(&tmp32, f)); |
| 478 |
ci->suspend_expires = tmp32; |
| 479 |
ci->flags |= CF_SUSPENDED; |
| 480 |
} |
| 481 |
|
| 482 |
SAFE(read_int16(&tmp16, f)); /* n_levels */ |
| 483 |
for (j = tmp16; j > 0; j--) |
| 484 |
SAFE(read_int16(&tmp16, f)); /* levels */ |
| 485 |
|
| 486 |
SAFE(read_int16(&ci->access_count, f)); |
| 487 |
if (ci->access_count) |
| 488 |
{ |
| 489 |
ci->access = scalloc(ci->access_count, sizeof(ChanAccess)); |
| 490 |
for (j = 0; j < ci->access_count; j++) |
| 491 |
{ |
| 492 |
SAFE(read_int16(&tmp16, f)); /* in_use */ |
| 493 |
if (tmp16) |
| 494 |
{ |
| 495 |
SAFE(read_int16(&ci->access[j].level, f)); |
| 496 |
SAFE(read_string(&s, f)); |
| 497 |
ci->access[j].level = convert_acclev(ci->access[j].level); |
| 498 |
if (s) |
| 499 |
{ |
| 500 |
ni = get_nickinfo(s); |
| 501 |
if (ni) |
| 502 |
ci->access[j].nickgroup = ni->nickgroup; |
| 503 |
} |
| 504 |
} |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
SAFE(read_int16(&ci->akick_count, f)); |
| 509 |
if (ci->akick_count) |
| 510 |
{ |
| 511 |
ci->akick = scalloc(ci->akick_count, sizeof(AutoKick)); |
| 512 |
for (j = 0; j < ci->akick_count; j++) |
| 513 |
{ |
| 514 |
SAFE(read_int16(&tmp16, f)); /* in_use */ |
| 515 |
if (tmp16) |
| 516 |
{ |
| 517 |
SAFE(read_int16(&tmp16, f)); /* is_nick */ |
| 518 |
SAFE(read_string(&s, f)); |
| 519 |
if (tmp16 && s) |
| 520 |
{ |
| 521 |
ci->akick[j].mask = smalloc(strlen(s) + 5); |
| 522 |
sprintf(ci->akick[j].mask, "%s!*@*", s); |
| 523 |
} |
| 524 |
else |
| 525 |
{ |
| 526 |
ci->akick[j].mask = s; |
| 527 |
} |
| 528 |
SAFE(read_string(&s, f)); |
| 529 |
SAFE(read_buffer(nickbuf, f)); |
| 530 |
if (ci->akick[j].mask) |
| 531 |
{ |
| 532 |
ci->akick[j].reason = s; |
| 533 |
strbcpy(ci->akick[j].who, nickbuf); |
| 534 |
ci->akick[j].set = time(NULL); |
| 535 |
} |
| 536 |
} |
| 537 |
} |
| 538 |
} |
| 539 |
|
| 540 |
SAFE(read_int32(&mlock_on, f)); |
| 541 |
SAFE(read_int32(&mlock_off, f)); |
| 542 |
ci->mlock.on = on = scalloc(64, 1); |
| 543 |
ci->mlock.off = off = scalloc(64, 1); |
| 544 |
for (j = 0; cmodes[j].flag != 0; j++) |
| 545 |
{ |
| 546 |
if (mlock_on & cmodes[j].flag) |
| 547 |
*on++ = cmodes[j].mode; |
| 548 |
if (mlock_off & cmodes[j].flag) |
| 549 |
*off++ = cmodes[j].mode; |
| 550 |
} |
| 551 |
*on = 0; |
| 552 |
*off = 0; |
| 553 |
SAFE(read_int32(&ci->mlock.limit, f)); |
| 554 |
SAFE(read_string(&ci->mlock.key, f)); |
| 555 |
|
| 556 |
SAFE(read_int16(&tmpmi.memos_count, f)); |
| 557 |
SAFE(read_int16(&tmp16, f)); /* memomax */ |
| 558 |
if (tmpmi.memos_count) |
| 559 |
{ |
| 560 |
Memo *memos; |
| 561 |
memos = scalloc(sizeof(Memo), tmpmi.memos_count); |
| 562 |
tmpmi.memos = memos; |
| 563 |
for (j = 0; j < tmpmi.memos_count; j++, memos++) |
| 564 |
{ |
| 565 |
SAFE(read_uint32(&memos->number, f)); |
| 566 |
SAFE(read_int16(&memos->flags, f)); |
| 567 |
SAFE(read_int32(&tmp32, f)); |
| 568 |
memos->time = tmp32; |
| 569 |
SAFE(read_buffer(nickbuf, f)); |
| 570 |
strbcpy(memos->sender, nickbuf); |
| 571 |
SAFE(read_string(&memos->text, f)); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
SAFE(read_string(&ci->entry_message, f)); |
| 576 |
|
| 577 |
if (!(ci->flags & CF_VERBOTEN) && !ci->founder) |
| 578 |
{ |
| 579 |
fprintf(stderr, "Ignoring channel %s (missing founder)\n", ci->name); |
| 580 |
del_channelinfo(ci); |
| 581 |
} |
| 582 |
|
| 583 |
} /* while (getc_db(f) == 1) */ |
| 584 |
|
| 585 |
if (c != 0) |
| 586 |
{ |
| 587 |
fprintf(stderr, "%s is corrupt, aborting.\n", f->filename); |
| 588 |
exit(1); |
| 589 |
} |
| 590 |
} /* for (i) */ |
| 591 |
close_db(f); |
| 592 |
} |
| 593 |
|
| 594 |
/*************************************************************************/ |
| 595 |
|
| 596 |
static void |
| 597 |
trircd_load_cforbid(const char *dir) |
| 598 |
{ |
| 599 |
dbFILE *f; |
| 600 |
int c; |
| 601 |
|
| 602 |
f = open_db_ver(dir, "cforbid.db", 25, 25, NULL); |
| 603 |
while ((c = getc_db(f)) == 1) |
| 604 |
{ |
| 605 |
char chanbuf[64]; |
| 606 |
void *tmpptr; |
| 607 |
int8 tmp8; |
| 608 |
int16 i, tmp16; |
| 609 |
int32 tmp32; |
| 610 |
char *s; |
| 611 |
ChannelInfo *ci; |
| 612 |
|
| 613 |
SAFE(read_buffer(chanbuf, f)); |
| 614 |
ci = get_channelinfo(chanbuf); |
| 615 |
if (!ci) |
| 616 |
{ |
| 617 |
fprintf(stderr, "Warning: cforbid data for nonexistent channel" |
| 618 |
" %s, ignoring\n", chanbuf); |
| 619 |
} |
| 620 |
SAFE(read_ptr(&tmpptr, f)); /* forbidinfo */ |
| 621 |
if (tmpptr) |
| 622 |
{ |
| 623 |
char nickbuf[32]; |
| 624 |
SAFE(read_buffer(nickbuf, f)); /* forbidder */ |
| 625 |
SAFE(read_string(&s, f)); /* forbid_message */ |
| 626 |
} |
| 627 |
SAFE(read_int16(&tmp16, f)); /* akickcount */ |
| 628 |
if (ci && tmp16 != ci->akick_count) |
| 629 |
{ |
| 630 |
fprintf(stderr, "Warning: autokick count mismatch (chan.db: %d," |
| 631 |
" cforbid.db: %d); databases may be corrupt\n", |
| 632 |
ci->akick_count, tmp16); |
| 633 |
} |
| 634 |
for (i = 0; i < tmp16; i++) |
| 635 |
{ |
| 636 |
int16 in_use; |
| 637 |
SAFE(read_int16(&in_use, f)); |
| 638 |
if (in_use) |
| 639 |
{ |
| 640 |
if (ci && i < ci->akick_count) |
| 641 |
{ |
| 642 |
SAFE(read_int32(&tmp32, f)); |
| 643 |
ci->akick[i].set = tmp32; |
| 644 |
SAFE(read_int32(&tmp32, f)); |
| 645 |
ci->akick[i].lastused = tmp32; |
| 646 |
} |
| 647 |
else |
| 648 |
{ |
| 649 |
SAFE(read_int32(&tmp32, f)); |
| 650 |
SAFE(read_int32(&tmp32, f)); |
| 651 |
} |
| 652 |
SAFE(read_int32(&tmp32, f)); /* expires */ |
| 653 |
} |
| 654 |
} |
| 655 |
SAFE(read_int16(&tmp16, f)); /* accesscount */ |
| 656 |
for (i = tmp16; i > 0; i--) |
| 657 |
{ |
| 658 |
SAFE(read_int16(&tmp16, f)); /* in_use */ |
| 659 |
if (tmp16) |
| 660 |
SAFE(read_int32(&tmp32, f)); /* last_used */ |
| 661 |
} |
| 662 |
SAFE(read_int8(&tmp8, f)); |
| 663 |
if (tmp8 != 0) |
| 664 |
{ |
| 665 |
fprintf(stderr, "%s is corrupt, aborting.\n", f->filename); |
| 666 |
exit(1); |
| 667 |
} |
| 668 |
} /* while (getc_db(f) == 1) */ |
| 669 |
if (c != -1) |
| 670 |
fprintf(stderr, "Warning: %s may be corrupt.\n", f->filename); |
| 671 |
close_db(f); |
| 672 |
} |
| 673 |
|
| 674 |
/*************************************************************************/ |
| 675 |
|
| 676 |
static void |
| 677 |
trircd_load_oper(const char *dir) |
| 678 |
{ |
| 679 |
dbFILE *f; |
| 680 |
int16 i, n; |
| 681 |
int32 tmp32; |
| 682 |
int8 tmp8; |
| 683 |
char *s; |
| 684 |
|
| 685 |
f = open_db_ver(dir, "oper.db", 22, 25, NULL); |
| 686 |
/* servadmin */ |
| 687 |
SAFE(read_int16(&n, f)); |
| 688 |
for (i = 0; i < n; i++) |
| 689 |
{ |
| 690 |
SAFE(read_string(&s, f)); |
| 691 |
set_os_priv(s, NP_SERVADMIN); |
| 692 |
} |
| 693 |
/* servoper */ |
| 694 |
SAFE(read_int16(&n, f)); |
| 695 |
for (i = 0; i < n; i++) |
| 696 |
{ |
| 697 |
SAFE(read_string(&s, f)); |
| 698 |
set_os_priv(s, NP_SERVOPER); |
| 699 |
} |
| 700 |
SAFE(read_int32(&maxusercnt, f)); |
| 701 |
SAFE(read_int32(&tmp32, f)); |
| 702 |
maxusertime = tmp32; |
| 703 |
SAFE(read_int8(&tmp8, f)); |
| 704 |
no_supass = tmp8; |
| 705 |
if (!no_supass) |
| 706 |
{ |
| 707 |
char passbuf[32]; |
| 708 |
SAFE(read_buffer(passbuf, f)); |
| 709 |
memcpy(supass.password, passbuf, sizeof(passbuf)); |
| 710 |
} |
| 711 |
close_db(f); |
| 712 |
} |
| 713 |
|
| 714 |
/*************************************************************************/ |
| 715 |
|
| 716 |
static void |
| 717 |
trircd_load_akill(const char *dir) |
| 718 |
{ |
| 719 |
dbFILE *f; |
| 720 |
int16 i, n; |
| 721 |
MaskData *md; |
| 722 |
|
| 723 |
f = open_db_ver(dir, "akill.db", 22, 25, NULL); |
| 724 |
SAFE(read_int16(&n, f)); |
| 725 |
md = scalloc(sizeof(*md), n); |
| 726 |
for (i = 0; i < n; i++) |
| 727 |
{ |
| 728 |
char nick[32]; |
| 729 |
int32 tmp32; |
| 730 |
SAFE(read_string(&md[i].mask, f)); |
| 731 |
SAFE(read_string(&md[i].reason, f)); |
| 732 |
SAFE(read_buffer(nick, f)); |
| 733 |
strbcpy(md[i].who, nick); |
| 734 |
SAFE(read_int32(&tmp32, f)); |
| 735 |
md[i].time = tmp32; |
| 736 |
SAFE(read_int32(&tmp32, f)); |
| 737 |
md[i].expires = tmp32; |
| 738 |
if (md[i].mask) |
| 739 |
add_maskdata(MD_AKILL, &md[i]); |
| 740 |
} |
| 741 |
close_db(f); |
| 742 |
} |
| 743 |
|
| 744 |
/*************************************************************************/ |
| 745 |
|
| 746 |
static void |
| 747 |
trircd_load_exclude(const char *dir) |
| 748 |
{ |
| 749 |
dbFILE *f; |
| 750 |
int16 i, n; |
| 751 |
MaskData *md; |
| 752 |
|
| 753 |
f = open_db_ver(dir, "exclude.db", 22, 25, NULL); |
| 754 |
SAFE(read_int16(&n, f)); |
| 755 |
md = scalloc(sizeof(*md), n); |
| 756 |
for (i = 0; i < n; i++) |
| 757 |
{ |
| 758 |
char nick[32]; |
| 759 |
int32 tmp32; |
| 760 |
SAFE(read_string(&md[i].mask, f)); |
| 761 |
SAFE(read_string(&md[i].reason, f)); |
| 762 |
SAFE(read_buffer(nick, f)); |
| 763 |
strbcpy(md[i].who, nick); |
| 764 |
SAFE(read_int32(&tmp32, f)); |
| 765 |
md[i].time = tmp32; |
| 766 |
SAFE(read_int32(&tmp32, f)); |
| 767 |
md[i].expires = tmp32; |
| 768 |
if (md[i].mask) |
| 769 |
add_maskdata(MD_EXCLUDE, &md[i]); |
| 770 |
} |
| 771 |
close_db(f); |
| 772 |
} |
| 773 |
|
| 774 |
/*************************************************************************/ |
| 775 |
|
| 776 |
static void |
| 777 |
trircd_load_exception(const char *dir) |
| 778 |
{ |
| 779 |
dbFILE *f; |
| 780 |
int16 i, n; |
| 781 |
MaskData *md; |
| 782 |
|
| 783 |
f = open_db_ver(dir, "exception.db", 22, 25, NULL); |
| 784 |
SAFE(read_int16(&n, f)); |
| 785 |
md = scalloc(sizeof(*md), n); |
| 786 |
for (i = 0; i < n; i++) |
| 787 |
{ |
| 788 |
char nick[32]; |
| 789 |
int32 tmp32; |
| 790 |
SAFE(read_string(&md[i].mask, f)); |
| 791 |
SAFE(read_int16(&md[i].limit, f)); |
| 792 |
SAFE(read_buffer(nick, f)); |
| 793 |
strbcpy(md[i].who, nick); |
| 794 |
SAFE(read_string(&md[i].reason, f)); |
| 795 |
SAFE(read_int32(&tmp32, f)); |
| 796 |
md[i].time = tmp32; |
| 797 |
SAFE(read_int32(&tmp32, f)); |
| 798 |
md[i].expires = tmp32; |
| 799 |
if (md[i].mask) |
| 800 |
add_maskdata(MD_AKILL, &md[i]); |
| 801 |
} |
| 802 |
close_db(f); |
| 803 |
} |
| 804 |
|
| 805 |
/*************************************************************************/ |
| 806 |
|
| 807 |
static void |
| 808 |
trircd_load_news(const char *dir) |
| 809 |
{ |
| 810 |
dbFILE *f; |
| 811 |
int16 i, n; |
| 812 |
NewsItem *news; |
| 813 |
|
| 814 |
f = open_db_ver(dir, "news.db", 22, 25, NULL); |
| 815 |
SAFE(read_int16(&n, f)); |
| 816 |
news = scalloc(sizeof(*news), n); |
| 817 |
for (i = 0; i < n; i++) |
| 818 |
{ |
| 819 |
char nick[32]; |
| 820 |
int32 tmp32; |
| 821 |
SAFE(read_int16(&news[i].type, f)); |
| 822 |
SAFE(read_int32(&news[i].num, f)); |
| 823 |
SAFE(read_string(&news[i].text, f)); |
| 824 |
SAFE(read_buffer(nick, f)); |
| 825 |
strbcpy(news[i].who, nick); |
| 826 |
SAFE(read_int32(&tmp32, f)); |
| 827 |
news[i].time = tmp32; |
| 828 |
add_news(&news[i]); |
| 829 |
} |
| 830 |
close_db(f); |
| 831 |
} |
| 832 |
|
| 833 |
/*************************************************************************/ |
| 834 |
|
| 835 |
static void |
| 836 |
trircd_load_sline(const char *dir, const unsigned char type) |
| 837 |
{ |
| 838 |
char filenamebuf[16]; |
| 839 |
dbFILE *f; |
| 840 |
int32 ver; |
| 841 |
int16 i, n; |
| 842 |
MaskData *md; |
| 843 |
|
| 844 |
snprintf(filenamebuf, sizeof(filenamebuf), "s%cline.db", type); |
| 845 |
f = open_db_ver(dir, filenamebuf, 22, 25, &ver); |
| 846 |
read_int16(&n, f); |
| 847 |
md = scalloc(sizeof(*md), n); |
| 848 |
for (i = 0; i < n; i++) |
| 849 |
{ |
| 850 |
char nickbuf[32]; |
| 851 |
int32 tmp32; |
| 852 |
SAFE(read_string(&md[i].mask, f)); |
| 853 |
SAFE(read_string(&md[i].reason, f)); |
| 854 |
SAFE(read_buffer(nickbuf, f)); |
| 855 |
strbcpy(md[i].who, nickbuf); |
| 856 |
if (ver >= 23) |
| 857 |
{ |
| 858 |
SAFE(read_int32(&tmp32, f)); |
| 859 |
md[i].time = tmp32; |
| 860 |
SAFE(read_int32(&tmp32, f)); |
| 861 |
md[i].expires = tmp32; |
| 862 |
} |
| 863 |
else |
| 864 |
{ |
| 865 |
md[i].time = time(NULL); |
| 866 |
} |
| 867 |
if (md[i].mask) |
| 868 |
add_maskdata(type, &md[i]); |
| 869 |
} |
| 870 |
close_db(f); |
| 871 |
} |
| 872 |
|
| 873 |
/*************************************************************************/ |
| 874 |
/*************************************************************************/ |
| 875 |
|
| 876 |
static const char * |
| 877 |
check_trircd(const char *dir) |
| 878 |
{ |
| 879 |
char buf[PATH_MAX + 1]; |
| 880 |
FILE *f; |
| 881 |
|
| 882 |
snprintf(buf, sizeof(buf), "%s/cforbid.db", dir); |
| 883 |
if ((f = fopen(buf, "rb")) != NULL) |
| 884 |
{ |
| 885 |
int32 ver; |
| 886 |
ver = fgetc(f) << 24; |
| 887 |
ver |= fgetc(f) << 16; |
| 888 |
ver |= fgetc(f) << 8; |
| 889 |
ver |= fgetc(f); |
| 890 |
fclose(f); |
| 891 |
if (ver == 25) |
| 892 |
return "trircd-4.26"; |
| 893 |
} |
| 894 |
return NULL; |
| 895 |
} |
| 896 |
|
| 897 |
static void |
| 898 |
load_trircd(const char *dir, int verbose, int ac, char **av) |
| 899 |
{ |
| 900 |
if (ac > 1) |
| 901 |
{ |
| 902 |
fprintf(stderr, "Unrecognized option %s\n", av[1]); |
| 903 |
usage(av[0]); |
| 904 |
} |
| 905 |
if (verbose) |
| 906 |
fprintf(stderr, "Loading nick.db...\n"); |
| 907 |
trircd_load_nick(dir); |
| 908 |
if (verbose) |
| 909 |
fprintf(stderr, "Loading ajoin.db...\n"); |
| 910 |
trircd_load_ajoin(dir); |
| 911 |
if (verbose) |
| 912 |
fprintf(stderr, "Loading chan.db...\n"); |
| 913 |
trircd_load_chan(dir); |
| 914 |
if (verbose) |
| 915 |
fprintf(stderr, "Loading cforbid.db...\n"); |
| 916 |
trircd_load_cforbid(dir); |
| 917 |
if (verbose) |
| 918 |
fprintf(stderr, "Loading oper.db...\n"); |
| 919 |
trircd_load_oper(dir); |
| 920 |
if (verbose) |
| 921 |
fprintf(stderr, "Loading akill.db...\n"); |
| 922 |
trircd_load_akill(dir); |
| 923 |
if (verbose) |
| 924 |
fprintf(stderr, "Loading exclude.db...\n"); |
| 925 |
trircd_load_exclude(dir); |
| 926 |
if (verbose) |
| 927 |
fprintf(stderr, "Loading exception.db...\n"); |
| 928 |
trircd_load_exception(dir); |
| 929 |
if (verbose) |
| 930 |
fprintf(stderr, "Loading news.db...\n"); |
| 931 |
trircd_load_news(dir); |
| 932 |
if (verbose) |
| 933 |
fprintf(stderr, "Loading sgline.db...\n"); |
| 934 |
trircd_load_sline(dir, 'g'); |
| 935 |
if (verbose) |
| 936 |
fprintf(stderr, "Loading sqline.db...\n"); |
| 937 |
trircd_load_sline(dir, 'q'); |
| 938 |
if (verbose) |
| 939 |
fprintf(stderr, "Loading szline.db...\n"); |
| 940 |
trircd_load_sline(dir, 'z'); |
| 941 |
} |
| 942 |
|
| 943 |
/*************************************************************************/ |
| 944 |
/*************************************************************************/ |
| 945 |
|
| 946 |
DBTypeInfo dbtype_trircd_4_26 = { |
| 947 |
"trircd-4.26", |
| 948 |
check_trircd, |
| 949 |
load_trircd |
| 950 |
}; |
| 951 |
|
| 952 |
/*************************************************************************/ |
| 953 |
|
| 954 |
/* |
| 955 |
* Local variables: |
| 956 |
* c-file-style: "stroustrup" |
| 957 |
* c-file-offsets: ((case-label . *) (statement-case-intro . *)) |
| 958 |
* indent-tabs-mode: nil |
| 959 |
* End: |
| 960 |
* |
| 961 |
* vim: expandtab shiftwidth=4: |
| 962 |
*/ |