static void load_old_ns_dbase(dbFILE *f, int ver) { struct nickinfo_ { NickInfo *next, *prev; char nick[NICKMAX]; char pass[PASSMAX]; char *last_usermask; char *last_realname; time_t time_registered; time_t last_seen; long accesscount; char **access; long flags; time_t id_stamp; unsigned short memomax; unsigned short channelcount; char *url; char *email; } old_nickinfo; int i, j, c; NickInfo *ni, **last, *prev; int failed = 0; for (i = 33; i < 256 && !failed; i++) { last = &nicklists[i]; prev = NULL; while ((c = getc_db(f)) != 0) { if (c != 1) fatal("Invalid format in %s", NickDBName); SAFE(read_variable(old_nickinfo, f)); if (debug >= 3) log("debug: load_old_ns_dbase read nick %s", old_nickinfo.nick); ni = scalloc(sizeof(NickInfo), 1); *last = ni; last = &ni->next; ni->prev = prev; prev = ni; strscpy(ni->nick, old_nickinfo.nick, NICKMAX); strscpy(ni->pass, old_nickinfo.pass, PASSMAX); ni->time_registered = old_nickinfo.time_registered; ni->last_seen = old_nickinfo.last_seen; ni->accesscount = old_nickinfo.accesscount; ni->flags = old_nickinfo.flags; ni->channelcount = 0; ni->channelmax = CSMaxReg; ni->language = DEF_LANGUAGE; /* ENCRYPTEDPW and VERBOTEN moved from ni->flags to ni->status */ if (ni->flags & 4) ni->status |= NS_VERBOTEN; if (ni->flags & 8) ni->status |= NS_ENCRYPTEDPW; ni->flags &= ~0xE000000C; #ifdef USE_ENCRYPTION if (!(ni->status & (NS_ENCRYPTEDPW | NS_VERBOTEN))) { if (debug) log("debug: %s: encrypting password for `%s' on load", s_NickServ, ni->nick); if (encrypt_in_place(ni->pass, PASSMAX) < 0) fatal("%s: Can't encrypt `%s' nickname password!", s_NickServ, ni->nick); ni->status |= NS_ENCRYPTEDPW; } #else if (ni->status & NS_ENCRYPTEDPW) { /* Bail: it makes no sense to continue with encrypted * passwords, since we won't be able to verify them */ fatal("%s: load database: password for %s encrypted " "but encryption disabled, aborting", s_NickServ, ni->nick); } #endif if (old_nickinfo.url) SAFE(read_string(&ni->url, f)); if (old_nickinfo.email) SAFE(read_string(&ni->email, f)); SAFE(read_string(&ni->last_usermask, f)); if (!ni->last_usermask) ni->last_usermask = sstrdup("@"); SAFE(read_string(&ni->last_realname, f)); if (!ni->last_realname) ni->last_realname = sstrdup(""); if (ni->accesscount) { char **access, *s; if (ni->accesscount > NSAccessMax) ni->accesscount = NSAccessMax; access = smalloc(sizeof(char *) * ni->accesscount); ni->access = access; for (j = 0; j < ni->accesscount; j++, access++) SAFE(read_string(access, f)); while (j < old_nickinfo.accesscount) { SAFE(read_string(&s, f)); if (s) free(s); j++; } } ni->id_stamp = 0; if (ver < 3) { ni->flags |= NI_MEMO_SIGNON | NI_MEMO_RECEIVE; } else if (ver == 3) { if (!(ni->flags & (NI_MEMO_SIGNON | NI_MEMO_RECEIVE))) ni->flags |= NI_MEMO_SIGNON | NI_MEMO_RECEIVE; } } /* while (getc_db(f) != 0) */ *last = NULL; } /* for (i) */ }
void load_ns_dbase(void) { dbFILE *f; int ver, i, j, c; NickAlias *na, **nalast, *naprev; NickCore *nc, **nclast, *ncprev; int failed = 0; uint16 tmp16; uint32 tmp32; char *s, *pass; if (!(f = open_db(s_NickServ, NickDBName, NICK_VERSION))) return; ver = get_file_version(f); if (ver <= 11) { // close_db(f); // load_old_ns_dbase(); printf("old database gtfo !\n"); return; } /* First we load nick cores */ for (i = 0; i < 1024 && !failed; i++) { nclast = &nclists[i]; ncprev = NULL; while ((c = getc_db(f)) == 1) { if (c != 1) printf("Invalid format in %s", NickDBName); nc = scalloc(1, sizeof(NickCore)); *nclast = nc; nclast = &nc->next; nc->prev = ncprev; ncprev = nc; slist_init(&nc->aliases); SAFE(read_string(&nc->display, f)); printf("%s", nc->display); if (ver < 14) { SAFE(read_string(&pass, f)); if (pass) { memset(nc->pass, 0, PASSMAX); memcpy(nc->pass, pass, strlen(pass)); } else memset(nc->pass, 0, PASSMAX); } else SAFE(read_buffer(nc->pass, f)); // printf(" %s", nc->pass); SAFE(read_string(&nc->email, f)); // printf(" %s", nc->email); SAFE(read_string(&nc->greet, f)); // printf(" %s", nc->greet); SAFE(read_int32(&nc->icq, f)); // printf(" %d", nc->icq); SAFE(read_string(&nc->url, f)); // printf(" %s\n", nc->url); SAFE(read_int32(&nc->flags, f)); if (!NSAllowKillImmed) nc->flags &= ~NI_KILL_IMMED; SAFE(read_int16(&nc->language, f)); /* Add services opers and admins to the appropriate list, but only if the database version is more than 10. */ /* if (nc->flags & NI_SERVICES_ADMIN) slist_add(&servadmins, nc); if (nc->flags & NI_SERVICES_OPER) slist_add(&servopers, nc); */ // OSEF des axx Sop et Sadmin ! SAFE(read_int16(&nc->accesscount, f)); if (nc->accesscount) { char **access; access = scalloc(sizeof(char *) * nc->accesscount, 1); nc->access = access; for (j = 0; j < nc->accesscount; j++, access++) SAFE(read_string(access, f)); } SAFE(read_int16(&tmp16, f)); nc->memos.memocount = (int16) tmp16; SAFE(read_int16(&tmp16, f)); nc->memos.memomax = (int16) tmp16; if (nc->memos.memocount) { Memo *memos; memos = scalloc(sizeof(Memo) * nc->memos.memocount, 1); nc->memos.memos = memos; for (j = 0; j < nc->memos.memocount; j++, memos++) { SAFE(read_int32(&memos->number, f)); SAFE(read_int16(&memos->flags, f)); SAFE(read_int32(&tmp32, f)); memos->time = tmp32; SAFE(read_buffer(memos->sender, f)); SAFE(read_string(&memos->text, f)); memos->moduleData = NULL; } } SAFE(read_int16(&nc->channelcount, f)); SAFE(read_int16(&tmp16, f)); nc->channelmax = CSMaxReg; if (ver < 13) { /* Used to be dead authentication system */ SAFE(read_int16(&tmp16, f)); SAFE(read_int32(&tmp32, f)); SAFE(read_int16(&tmp16, f)); SAFE(read_string(&s, f)); } } /* while (getc_db(f) != 0) */ *nclast = NULL; } /* for (i) */ for (i = 0; i < 1024 && !failed; i++) { nalast = &nalists[i]; naprev = NULL; while ((c = getc_db(f)) == 1) { if (c != 1) printf("Invalid format in %s", NickDBName); na = scalloc(1, sizeof(NickAlias)); SAFE(read_string(&na->nick, f)); SAFE(read_string(&na->last_usermask, f)); SAFE(read_string(&na->last_realname, f)); SAFE(read_string(&na->last_quit, f)); SAFE(read_int32(&tmp32, f)); na->time_registered = tmp32; SAFE(read_int32(&tmp32, f)); na->last_seen = tmp32; SAFE(read_int16(&na->status, f)); na->status &= ~NS_TEMPORARY; SAFE(read_string(&s, f)); na->nc = findcore(s); free(s); slist_add(&na->nc->aliases, na); if (!(na->status & NS_VERBOTEN)) { if (!na->last_usermask) na->last_usermask = sstrdup(""); if (!na->last_realname) na->last_realname = sstrdup(""); } na->nc->flags &= ~NI_SERVICES_ROOT; *nalast = na; nalast = &na->next; na->prev = naprev; naprev = na; } /* while (getc_db(f) != 0) */ *nalast = NULL; } /* for (i) */ // close_db(f); // nevermind wasting memory for (i = 0; i < 1024; i++) { NickAlias *next; for (na = nalists[i]; na; na = next) { next = na->next; /* We check for coreless nicks (although it should never happen) */ if (!na->nc) { printf("%s: while loading database: %s has no core! We delete it (here just ignore it !).", s_NickServ, na->nick); // delnick(na); continue; } /* Add the Services root flag if needed. */ /* for (j = 0; j < RootNumber; j++) if (!stricmp(ServicesRoots[j], na->nick)) na->nc->flags |= NI_SERVICES_ROOT; */ // OSEF de savoir si Paul Pierre ou Jacques est Services Root ! } } }
void load_ns_dbase(void) { dbFILE *f; int ver, i, c; NickInfo *ni; int failed = 0; if (!(f = open_db(s_NickServ, NickDBName, "r"))) return; switch (ver = get_file_version(f)) { case 13: case 12: case 11: case 10: case 9: case 8: case 7: case 6: case 5: for (i = 0; i < 256 && !failed; i++) { while ((c = getc_db(f)) != 0) { if (c != 1) fatal("Invalid format in %s", NickDBName); ni = load_nick(f, ver); if (ni) { alpha_insert_nick(ni); } else { failed = 1; break; } } } /* Now resolve links */ for (ni = firstnick(); ni; ni = nextnick()) { if (ni->link) { char *s = (char *)ni->link; ni->link = findnick(s); free(s); if (ni->link) ni->link->linkcount++; } } break; case 4: case 3: case 2: case 1: load_old_ns_dbase(f, ver); break; case -1: fatal("Unable to read version number from %s", NickDBName); default: fatal("Unsupported version number (%d) on %s", ver, NickDBName); } /* switch (version) */ close_db(f); }