diff options
| author | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
|---|---|---|
| committer | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
| commit | 6c55e0a529c7f1216ff6f63a4fc77ea06a2a3a38 (patch) | |
| tree | 91b0841faf23087ebe0c74dd4269d181a383f1e7 /src/nickserv.c | |
| parent | 069409cd99cf78ab8bf87a1fe69a833576414fd3 (diff) | |
Insane commit of doom: s/ \t/g
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1681 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/nickserv.c')
| -rw-r--r-- | src/nickserv.c | 2542 |
1 files changed, 1271 insertions, 1271 deletions
diff --git a/src/nickserv.c b/src/nickserv.c index 2940538b2..42a417cae 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -24,10 +24,10 @@ NickAlias *nalists[1024]; NickCore *nclists[1024]; NickRequest *nrlists[1024]; -unsigned int guestnum; /* Current guest number */ +unsigned int guestnum; /* Current guest number */ -#define TO_COLLIDE 0 /* Collide the user with this nick */ -#define TO_RELEASE 1 /* Release a collided nick */ +#define TO_COLLIDE 0 /* Collide the user with this nick */ +#define TO_RELEASE 1 /* Release a collided nick */ /*************************************************************************/ @@ -45,26 +45,26 @@ void moduleAddNickServCmds(void) { void get_aliases_stats(long *nrec, long *memuse) { - long count = 0, mem = 0; - int i; - NickAlias *na; - - for (i = 0; i < 1024; i++) { - for (na = nalists[i]; na; na = na->next) { - count++; - mem += sizeof(*na); - if (na->nick) - mem += strlen(na->nick) + 1; - if (na->last_usermask) - mem += strlen(na->last_usermask) + 1; - if (na->last_realname) - mem += strlen(na->last_realname) + 1; - if (na->last_quit) - mem += strlen(na->last_quit) + 1; - } - } - *nrec = count; - *memuse = mem; + long count = 0, mem = 0; + int i; + NickAlias *na; + + for (i = 0; i < 1024; i++) { + for (na = nalists[i]; na; na = na->next) { + count++; + mem += sizeof(*na); + if (na->nick) + mem += strlen(na->nick) + 1; + if (na->last_usermask) + mem += strlen(na->last_usermask) + 1; + if (na->last_realname) + mem += strlen(na->last_realname) + 1; + if (na->last_quit) + mem += strlen(na->last_quit) + 1; + } + } + *nrec = count; + *memuse = mem; } /*************************************************************************/ @@ -73,46 +73,46 @@ void get_aliases_stats(long *nrec, long *memuse) void get_core_stats(long *nrec, long *memuse) { - long count = 0, mem = 0; - int i, j; - NickCore *nc; - char **accptr; - - for (i = 0; i < 1024; i++) { - for (nc = nclists[i]; nc; nc = nc->next) { - count++; - mem += sizeof(*nc); - - if (nc->display) - mem += strlen(nc->display) + 1; - if (nc->pass) - mem += strlen(nc->pass) + 1; - - if (nc->url) - mem += strlen(nc->url) + 1; - if (nc->email) - mem += strlen(nc->email) + 1; - if (nc->greet) - mem += strlen(nc->greet) + 1; - - mem += sizeof(char *) * nc->accesscount; - for (accptr = nc->access, j = 0; j < nc->accesscount; - accptr++, j++) { - if (*accptr) - mem += strlen(*accptr) + 1; - } - - mem += nc->memos.memocount * sizeof(Memo); - for (j = 0; j < nc->memos.memocount; j++) { - if (nc->memos.memos[j].text) - mem += strlen(nc->memos.memos[j].text) + 1; - } - - mem += sizeof(void *) * nc->aliases.count; - } - } - *nrec = count; - *memuse = mem; + long count = 0, mem = 0; + int i, j; + NickCore *nc; + char **accptr; + + for (i = 0; i < 1024; i++) { + for (nc = nclists[i]; nc; nc = nc->next) { + count++; + mem += sizeof(*nc); + + if (nc->display) + mem += strlen(nc->display) + 1; + if (nc->pass) + mem += strlen(nc->pass) + 1; + + if (nc->url) + mem += strlen(nc->url) + 1; + if (nc->email) + mem += strlen(nc->email) + 1; + if (nc->greet) + mem += strlen(nc->greet) + 1; + + mem += sizeof(char *) * nc->accesscount; + for (accptr = nc->access, j = 0; j < nc->accesscount; + accptr++, j++) { + if (*accptr) + mem += strlen(*accptr) + 1; + } + + mem += nc->memos.memocount * sizeof(Memo); + for (j = 0; j < nc->memos.memocount; j++) { + if (nc->memos.memos[j].text) + mem += strlen(nc->memos.memos[j].text) + 1; + } + + mem += sizeof(void *) * nc->aliases.count; + } + } + *nrec = count; + *memuse = mem; } /*************************************************************************/ @@ -122,10 +122,10 @@ void get_core_stats(long *nrec, long *memuse) void ns_init(void) { - moduleAddNickServCmds(); - guestnum = time(NULL); - while (guestnum > 9999999) - guestnum -= 10000000; + moduleAddNickServCmds(); + guestnum = time(NULL); + while (guestnum > 9999999) + guestnum -= 10000000; } /*************************************************************************/ @@ -134,20 +134,20 @@ void ns_init(void) void nickserv(User * u, char *buf) { - const char *cmd, *s; + const char *cmd, *s; - cmd = strtok(buf, " "); + cmd = strtok(buf, " "); - if (!cmd) { - return; - } else if (stricmp(cmd, "\1PING") == 0) { - if (!(s = strtok(NULL, ""))) { - s = ""; - } - ircdproto->SendCTCP(findbot(s_NickServ), u->nick, "PING %s", s); - } else { - mod_run_cmd(s_NickServ, u, NICKSERV, cmd); - } + if (!cmd) { + return; + } else if (stricmp(cmd, "\1PING") == 0) { + if (!(s = strtok(NULL, ""))) { + s = ""; + } + ircdproto->SendCTCP(findbot(s_NickServ), u->nick, "PING %s", s); + } else { + mod_run_cmd(s_NickServ, u, NICKSERV, cmd); + } } @@ -157,474 +157,474 @@ void nickserv(User * u, char *buf) #define SAFE(x) do { \ - if ((x) < 0) { \ + if ((x) < 0) { \ if (!forceload) \ - fatal("Read error on %s", NickDBName); \ + fatal("Read error on %s", NickDBName); \ failed = 1; \ break; \ - } \ + } \ } while (0) /* Loads NickServ database versions 5 to 11 (<= 4 is not supported) */ void load_old_ns_dbase(void) { - dbFILE *f; - int ver, i, j, c; - NickAlias *na, *na2, *next; - NickCore *nc; - int failed = 0; - - uint16 tmp16; - uint32 tmp32; - - char bufn[NICKMAX], bufp[PASSMAX]; - char *email, *greet, *url, *forbidby, *forbidreason; - uint32 icq; - - if (!(f = open_db(s_NickServ, NickDBName, "r", NICK_VERSION))) - return; - - ver = get_file_version(f); - if (ver <= 4) { - fatal("Unsupported version number (%d) on %s", ver, NickDBName); - close_db(f); - return; - } - - for (i = 0; i < 256 && !failed; i++) { - while ((c = getc_db(f)) == 1) { - if (c != 1) - fatal("Invalid format in %s", NickDBName); - - na = (NickAlias *)scalloc(sizeof(NickAlias), 1); - - SAFE(read_buffer(bufn, f)); - na->nick = sstrdup(bufn); - SAFE(read_buffer(bufp, f)); /* Will be used later if needed */ - - SAFE(read_string(&url, f)); - SAFE(read_string(&email, f)); - if (ver >= 10) - SAFE(read_int32(&icq, f)); - else - icq = 0; - if (ver >= 9) - SAFE(read_string(&greet, f)); - else - greet = NULL; - - 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; - - if (ver >= 9) { - SAFE(read_string(&forbidby, f)); - SAFE(read_string(&forbidreason, f)); - /* Cleanup */ - if (forbidby && *forbidby == '@') { - free(forbidby); - forbidby = NULL; - } - if (forbidreason && *forbidreason == 0) { - free(forbidreason); - forbidreason = NULL; - } - } else { - forbidby = NULL; - forbidreason = NULL; - } - - if (na->status & NS_VERBOTEN) { - if (na->last_usermask) - free(na->last_usermask); - if (na->last_realname) - free(na->last_realname); - - na->last_usermask = forbidby; - na->last_realname = forbidreason; - } else { - if (!na->last_usermask) - na->last_usermask = sstrdup(""); - if (!na->last_realname) - na->last_realname = sstrdup(""); - } - - /* Store the reference for later resolving */ - SAFE(read_string((char **) &na->nc, f)); - SAFE(read_int16(&tmp16, f)); /* Was linkcount */ - - if (na->nc) { - SAFE(read_int16(&tmp16, f)); /* Was channelcount */ - } else { - /* This nick was a master nick, so it also has all the - * core info! =) - */ - nc = (NickCore *)scalloc(1, sizeof(NickCore)); - slist_init(&nc->aliases); - - /* The initial display is what used to be the master nick */ - nc->display = sstrdup(na->nick); - - /* We grabbed info before; fill the appropriate fields now */ - if (*bufp) - memcpy(nc->pass, bufp, PASSMAX); - else - memset(nc->pass, 0, PASSMAX); /* Which may be the case for forbidden nicks .. */ - - nc->email = email; - nc->greet = greet; - nc->icq = icq; - nc->url = url; - - /* We check whether the e-mail is valid because it was not tested - * in older versions. - */ - if (ver <= 10 && nc->email && !MailValidate(nc->email)) { - free(nc->email); - nc->email = NULL; - } - - SAFE(read_int32(&nc->flags, f)); - if (!NSAllowKillImmed) - nc->flags &= ~NI_KILL_IMMED; - - /* Status flags cleanup */ - if (na->status & NS_OLD_ENCRYPTEDPW) { - nc->flags |= NI_ENCRYPTEDPW; - na->status &= ~NS_OLD_ENCRYPTEDPW; - } - - /* Add services opers and admins to the appropriate list, but - only if the database version is equal to or more than 10. */ - if (ver >= 10) { - if (nc->flags & NI_SERVICES_ADMIN) - slist_add(&servadmins, nc); - if (nc->flags & NI_SERVICES_OPER) - slist_add(&servopers, nc); - } - - /* Add the Services root flag if needed. */ - if (nc) - for (j = 0; j < RootNumber; j++) - if (!stricmp(ServicesRoots[j], na->nick)) - nc->flags |= NI_SERVICES_ROOT; - - SAFE(read_int16(&nc->accesscount, f)); - if (nc->accesscount) { - char **access; - access = (char **)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 = (Memo *)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; - } - } - - /* We read the channel count, but don't take care of it. - load_cs_dbase will regenerate it correctly. */ - SAFE(read_int16(&tmp16, f)); + dbFILE *f; + int ver, i, j, c; + NickAlias *na, *na2, *next; + NickCore *nc; + int failed = 0; + + uint16 tmp16; + uint32 tmp32; + + char bufn[NICKMAX], bufp[PASSMAX]; + char *email, *greet, *url, *forbidby, *forbidreason; + uint32 icq; + + if (!(f = open_db(s_NickServ, NickDBName, "r", NICK_VERSION))) + return; + + ver = get_file_version(f); + if (ver <= 4) { + fatal("Unsupported version number (%d) on %s", ver, NickDBName); + close_db(f); + return; + } + + for (i = 0; i < 256 && !failed; i++) { + while ((c = getc_db(f)) == 1) { + if (c != 1) + fatal("Invalid format in %s", NickDBName); + + na = (NickAlias *)scalloc(sizeof(NickAlias), 1); + + SAFE(read_buffer(bufn, f)); + na->nick = sstrdup(bufn); + SAFE(read_buffer(bufp, f)); /* Will be used later if needed */ + + SAFE(read_string(&url, f)); + SAFE(read_string(&email, f)); + if (ver >= 10) + SAFE(read_int32(&icq, f)); + else + icq = 0; + if (ver >= 9) + SAFE(read_string(&greet, f)); + else + greet = NULL; + + 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; + + if (ver >= 9) { + SAFE(read_string(&forbidby, f)); + SAFE(read_string(&forbidreason, f)); + /* Cleanup */ + if (forbidby && *forbidby == '@') { + free(forbidby); + forbidby = NULL; + } + if (forbidreason && *forbidreason == 0) { + free(forbidreason); + forbidreason = NULL; + } + } else { + forbidby = NULL; + forbidreason = NULL; + } + + if (na->status & NS_VERBOTEN) { + if (na->last_usermask) + free(na->last_usermask); + if (na->last_realname) + free(na->last_realname); + + na->last_usermask = forbidby; + na->last_realname = forbidreason; + } else { + if (!na->last_usermask) + na->last_usermask = sstrdup(""); + if (!na->last_realname) + na->last_realname = sstrdup(""); + } + + /* Store the reference for later resolving */ + SAFE(read_string((char **) &na->nc, f)); + SAFE(read_int16(&tmp16, f)); /* Was linkcount */ + + if (na->nc) { + SAFE(read_int16(&tmp16, f)); /* Was channelcount */ + } else { + /* This nick was a master nick, so it also has all the + * core info! =) + */ + nc = (NickCore *)scalloc(1, sizeof(NickCore)); + slist_init(&nc->aliases); + + /* The initial display is what used to be the master nick */ + nc->display = sstrdup(na->nick); + + /* We grabbed info before; fill the appropriate fields now */ + if (*bufp) + memcpy(nc->pass, bufp, PASSMAX); + else + memset(nc->pass, 0, PASSMAX); /* Which may be the case for forbidden nicks .. */ + + nc->email = email; + nc->greet = greet; + nc->icq = icq; + nc->url = url; + + /* We check whether the e-mail is valid because it was not tested + * in older versions. + */ + if (ver <= 10 && nc->email && !MailValidate(nc->email)) { + free(nc->email); + nc->email = NULL; + } + + SAFE(read_int32(&nc->flags, f)); + if (!NSAllowKillImmed) + nc->flags &= ~NI_KILL_IMMED; + + /* Status flags cleanup */ + if (na->status & NS_OLD_ENCRYPTEDPW) { + nc->flags |= NI_ENCRYPTEDPW; + na->status &= ~NS_OLD_ENCRYPTEDPW; + } + + /* Add services opers and admins to the appropriate list, but + only if the database version is equal to or more than 10. */ + if (ver >= 10) { + if (nc->flags & NI_SERVICES_ADMIN) + slist_add(&servadmins, nc); + if (nc->flags & NI_SERVICES_OPER) + slist_add(&servopers, nc); + } + + /* Add the Services root flag if needed. */ + if (nc) + for (j = 0; j < RootNumber; j++) + if (!stricmp(ServicesRoots[j], na->nick)) + nc->flags |= NI_SERVICES_ROOT; + + SAFE(read_int16(&nc->accesscount, f)); + if (nc->accesscount) { + char **access; + access = (char **)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 = (Memo *)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; + } + } + + /* We read the channel count, but don't take care of it. + load_cs_dbase will regenerate it correctly. */ + SAFE(read_int16(&tmp16, f)); /* formerly nc->channelmax, RIP */ - SAFE(read_int16(&tmp16, f)); - SAFE(read_int16(&nc->language, f)); - - if (ver >= 11 && ver < 13) { - char *s; - - SAFE(read_int16(&tmp16, f)); - SAFE(read_int32(&tmp32, f)); - SAFE(read_int16(&tmp16, f)); - SAFE(read_string(&s, f)); - } - - /* Set us as being a master nick; fill the nc field also. - The NS_MASTER flag will not be cleared in this function. */ - na->status |= NS_MASTER; - na->nc = nc; - slist_add(&nc->aliases, na); - - /* Insert our new core in the core list */ - insert_core(nc); - } - - alpha_insert_alias(na); - - } /* while (getc_db(f) != 0) */ - } /* for (i) */ - - /* Now resolve what were called links */ - for (i = 0; i < 1024; i++) { - for (na = nalists[i]; na; na = next) { - next = na->next; - - /* Master nicks are already resolved */ - if (na->status & NS_MASTER) - continue; - - na2 = na; - /* While the reference resolves and it's not a master nick */ - while ((na2 = findnick((char *) na2->nc)) - && !(na2->status & NS_MASTER)); - - /* It didn't resolve. This is problematic since there is no core. :/ - We delete the nick. */ - if (!na2) { - alog("%s: while loading database: %s was linked to inexistant %s", s_NickServ, na->nick, (char *) na->nc); - delnick(na); - continue; - } - - /* OK we have information on the core. We mark the current alias - as a master nick because it now contains a valid core. */ - na->nc = na2->nc; - na->status |= NS_MASTER; - slist_add(&na->nc->aliases, na); - } - } - - close_db(f); + SAFE(read_int16(&tmp16, f)); + SAFE(read_int16(&nc->language, f)); + + if (ver >= 11 && ver < 13) { + char *s; + + SAFE(read_int16(&tmp16, f)); + SAFE(read_int32(&tmp32, f)); + SAFE(read_int16(&tmp16, f)); + SAFE(read_string(&s, f)); + } + + /* Set us as being a master nick; fill the nc field also. + The NS_MASTER flag will not be cleared in this function. */ + na->status |= NS_MASTER; + na->nc = nc; + slist_add(&nc->aliases, na); + + /* Insert our new core in the core list */ + insert_core(nc); + } + + alpha_insert_alias(na); + + } /* while (getc_db(f) != 0) */ + } /* for (i) */ + + /* Now resolve what were called links */ + for (i = 0; i < 1024; i++) { + for (na = nalists[i]; na; na = next) { + next = na->next; + + /* Master nicks are already resolved */ + if (na->status & NS_MASTER) + continue; + + na2 = na; + /* While the reference resolves and it's not a master nick */ + while ((na2 = findnick((char *) na2->nc)) + && !(na2->status & NS_MASTER)); + + /* It didn't resolve. This is problematic since there is no core. :/ + We delete the nick. */ + if (!na2) { + alog("%s: while loading database: %s was linked to inexistant %s", s_NickServ, na->nick, (char *) na->nc); + delnick(na); + continue; + } + + /* OK we have information on the core. We mark the current alias + as a master nick because it now contains a valid core. */ + na->nc = na2->nc; + na->status |= NS_MASTER; + slist_add(&na->nc->aliases, na); + } + } + + close_db(f); } void load_ns_req_db(void) { - dbFILE *f; - int i, c, ver; - NickRequest *nr; - uint32 tmp32; - int failed = 0, len; - char *pass; - - if (!(f = open_db(s_NickServ, PreNickDBName, "r", PRE_NICK_VERSION))) - return; - ver = get_file_version(f); - for (i = 0; i < 1024 && !failed; i++) { - while ((c = getc_db(f)) == 1) { - if (c != 1) - fatal("Invalid format in %s", PreNickDBName); - nr = (NickRequest *)scalloc(1, sizeof(NickRequest)); - SAFE(read_string(&nr->nick, f)); - SAFE(read_string(&nr->passcode, f)); - if (ver < 2) { - SAFE(read_string(&pass, f)); - len = strlen(pass); - enc_encrypt(pass, len, nr->password, PASSMAX); - memset(pass, 0, len); - free(pass); - } else - SAFE(read_buffer(nr->password, f)); - SAFE(read_string(&nr->email, f)); - SAFE(read_int32(&tmp32, f)); - nr->requested = tmp32; - insert_requestnick(nr); - } - } - close_db(f); + dbFILE *f; + int i, c, ver; + NickRequest *nr; + uint32 tmp32; + int failed = 0, len; + char *pass; + + if (!(f = open_db(s_NickServ, PreNickDBName, "r", PRE_NICK_VERSION))) + return; + ver = get_file_version(f); + for (i = 0; i < 1024 && !failed; i++) { + while ((c = getc_db(f)) == 1) { + if (c != 1) + fatal("Invalid format in %s", PreNickDBName); + nr = (NickRequest *)scalloc(1, sizeof(NickRequest)); + SAFE(read_string(&nr->nick, f)); + SAFE(read_string(&nr->passcode, f)); + if (ver < 2) { + SAFE(read_string(&pass, f)); + len = strlen(pass); + enc_encrypt(pass, len, nr->password, PASSMAX); + memset(pass, 0, len); + free(pass); + } else + SAFE(read_buffer(nr->password, f)); + SAFE(read_string(&nr->email, f)); + SAFE(read_int32(&tmp32, f)); + nr->requested = tmp32; + insert_requestnick(nr); + } + } + close_db(f); } 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, "r", NICK_VERSION))) - return; - - ver = get_file_version(f); - - if (ver <= 11) { - close_db(f); - load_old_ns_dbase(); - 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) - fatal("Invalid format in %s", NickDBName); - - nc = (NickCore *)scalloc(1, sizeof(NickCore)); - *nclast = nc; - nclast = &nc->next; - nc->prev = ncprev; - ncprev = nc; - - slist_init(&nc->aliases); - - SAFE(read_string(&nc->display, f)); - 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)); - - SAFE(read_string(&nc->email, f)); - SAFE(read_string(&nc->greet, f)); - SAFE(read_int32(&nc->icq, f)); - SAFE(read_string(&nc->url, f)); - - 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); - - SAFE(read_int16(&nc->accesscount, f)); - if (nc->accesscount) { - char **access; - access = (char **)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 = (Memo *)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)); - - 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) - fatal("Invalid format in %s", NickDBName); - - na = (NickAlias *)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); - - 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) { - alog("%s: while loading database: %s has no core! We delete 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; - } - } + 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, "r", NICK_VERSION))) + return; + + ver = get_file_version(f); + + if (ver <= 11) { + close_db(f); + load_old_ns_dbase(); + 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) + fatal("Invalid format in %s", NickDBName); + + nc = (NickCore *)scalloc(1, sizeof(NickCore)); + *nclast = nc; + nclast = &nc->next; + nc->prev = ncprev; + ncprev = nc; + + slist_init(&nc->aliases); + + SAFE(read_string(&nc->display, f)); + 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)); + + SAFE(read_string(&nc->email, f)); + SAFE(read_string(&nc->greet, f)); + SAFE(read_int32(&nc->icq, f)); + SAFE(read_string(&nc->url, f)); + + 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); + + SAFE(read_int16(&nc->accesscount, f)); + if (nc->accesscount) { + char **access; + access = (char **)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 = (Memo *)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)); + + 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) + fatal("Invalid format in %s", NickDBName); + + na = (NickAlias *)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; + |
