mirror of
https://github.com/anope/anope.git
synced 2026-06-29 15:56:37 +02:00
Ripped out old databases
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2699 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
+1
-47
@@ -17,55 +17,9 @@
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/param.h>
|
||||
#define DeleteFile unlink
|
||||
#endif
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
typedef struct dbFILE_ dbFILE;
|
||||
struct dbFILE_ {
|
||||
int mode; /* 'r' for reading, 'w' for writing */
|
||||
FILE *fp; /* The normal file descriptor */
|
||||
FILE *backupfp; /* Open file pointer to a backup copy of
|
||||
* the database file (if non-NULL) */
|
||||
char filename[MAXPATHLEN]; /* Name of the database file */
|
||||
char backupname[MAXPATHLEN]; /* Name of the backup file */
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Prototypes and macros: */
|
||||
|
||||
E void check_file_version(dbFILE *f);
|
||||
E int get_file_version(dbFILE *f);
|
||||
E int write_file_version(dbFILE *f, uint32 version);
|
||||
|
||||
E dbFILE *open_db(const char *service, const char *filename, const char *mode, uint32 version);
|
||||
E void restore_db(dbFILE *f); /* Restore to state before open_db() */
|
||||
E void close_db(dbFILE *f);
|
||||
E void backup_databases();
|
||||
|
||||
#define read_db(f,buf,len) (fread((buf),1,(len),(f)->fp))
|
||||
#define write_db(f,buf,len) (fwrite((buf),1,(len),(f)->fp))
|
||||
#define getc_db(f) (fgetc((f)->fp))
|
||||
|
||||
E int read_int16(uint16 *ret, dbFILE *f);
|
||||
E int write_int16(uint16 val, dbFILE *f);
|
||||
E int read_int32(uint32 *ret, dbFILE *f);
|
||||
E int write_int32(uint32 val, dbFILE *f);
|
||||
E int read_ptr(void **ret, dbFILE *f);
|
||||
E int write_ptr(const void *ptr, dbFILE *f);
|
||||
E int read_string(char **ret, dbFILE *f);
|
||||
E int write_string(const char *s, dbFILE *f);
|
||||
|
||||
#define read_int8(ret,f) ((*(ret)=fgetc((f)->fp))==EOF ? -1 : 0)
|
||||
#define write_int8(val,f) (fputc((val),(f)->fp)==EOF ? -1 : 0)
|
||||
#define read_buffer(buf,f) (read_db((f),(buf),sizeof(buf)) == sizeof(buf))
|
||||
#define write_buffer(buf,f) (write_db((f),(buf),sizeof(buf)) == sizeof(buf))
|
||||
#define read_buflen(buf,len,f) (read_db((f),(buf),(len)) == (len))
|
||||
#define write_buflen(buf,len,f) (write_db((f),(buf),(len)) == (len))
|
||||
#define read_variable(var,f) (read_db((f),&(var),sizeof(var)) == sizeof(var))
|
||||
#define write_variable(var,f) (write_db((f),&(var),sizeof(var)) == sizeof(var))
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#endif /* DATAFILES_H */
|
||||
|
||||
@@ -49,8 +49,6 @@ E void bs_init();
|
||||
E void botserv(User *u, char *buf);
|
||||
E void botmsgs(User *u, BotInfo *bi, char *buf);
|
||||
E void botchanmsgs(User *u, ChannelInfo *ci, char *buf);
|
||||
E void load_bs_dbase();
|
||||
E void save_bs_dbase();
|
||||
E BotInfo *findbot(const char *nick);
|
||||
|
||||
/** Finds a pseudoclient, given a UID. Useful for TS6 protocol modules.
|
||||
@@ -132,8 +130,6 @@ E void alpha_insert_chan(ChannelInfo * ci);
|
||||
E void reset_levels(ChannelInfo * ci);
|
||||
E void cs_init();
|
||||
E void chanserv(User * u, char *buf);
|
||||
E void load_cs_dbase();
|
||||
E void save_cs_dbase();
|
||||
E void expire_chans();
|
||||
E void cs_remove_nick(const NickCore * nc);
|
||||
|
||||
@@ -178,8 +174,6 @@ char *sockstrerror(int error);
|
||||
|
||||
E ServerConfig Config;
|
||||
|
||||
E void load_hs_dbase();
|
||||
E void save_hs_dbase();
|
||||
E int do_on_id(User * u);
|
||||
E void delHostCore(const char *nick);
|
||||
E void hostserv(User * u, char *buf);
|
||||
@@ -424,10 +418,6 @@ E int should_mode_change(int16 status, int16 mode);
|
||||
|
||||
E void ns_init();
|
||||
E void nickserv(User * u, char *buf);
|
||||
E void load_ns_dbase();
|
||||
E void load_ns_req_db();
|
||||
E void save_ns_dbase();
|
||||
E void save_ns_req_dbase();
|
||||
E int validate_user(User * u);
|
||||
E void cancel_user(User * u);
|
||||
E int nick_identified(User * u);
|
||||
@@ -458,8 +448,6 @@ E void UnsetDefConParam(ChannelModeName);
|
||||
|
||||
E void operserv(User *u, char *buf);
|
||||
E void os_init();
|
||||
E void load_os_dbase();
|
||||
E void save_os_dbase();
|
||||
|
||||
E int add_akill(User *u, const char *mask, const char *by, const time_t expires, const char *reason);
|
||||
E int check_akill(const char *nick, const char *username, const char *host, const char *vhost, const char *ip);
|
||||
@@ -562,8 +550,6 @@ E int do_session(User *u);
|
||||
E int add_session(const char *nick, const char *host, char *hostip);
|
||||
E void del_session(const char *host);
|
||||
|
||||
E void load_exceptions();
|
||||
E void save_exceptions();
|
||||
E int do_exception(User *u);
|
||||
E void expire_exceptions();
|
||||
|
||||
|
||||
-120
@@ -461,126 +461,6 @@ void botchanmsgs(User * u, ChannelInfo * ci, char *buf)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Load/save data files. */
|
||||
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.BotDBName); \
|
||||
failed = 1; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_bs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
int c, ver;
|
||||
uint16 tmp16;
|
||||
uint32 tmp32;
|
||||
BotInfo *bi;
|
||||
int failed = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_BotServ, Config.BotDBName, "r", BOT_VERSION)))
|
||||
return;
|
||||
|
||||
ver = get_file_version(f);
|
||||
|
||||
while (!failed && (c = getc_db(f)) != 0) {
|
||||
char *s;
|
||||
|
||||
if (c != 1)
|
||||
fatal("Invalid format in %s %d", Config.BotDBName, c);
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
bi = new BotInfo(s);
|
||||
delete [] s;
|
||||
SAFE(read_string(&bi->user, f));
|
||||
SAFE(read_string(&bi->host, f));
|
||||
SAFE(read_string(&bi->real, f));
|
||||
if (ver >= 10) {
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
//bi->flags |= tmp16;
|
||||
}
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
bi->created = tmp32;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
bi->chancount = tmp16;
|
||||
|
||||
/* Fixes bug #1080, services bot names may have been
|
||||
* changed in the config and different from database
|
||||
* names
|
||||
*/
|
||||
if (Config.s_ChanServ && bi->HasFlag(BI_CHANSERV) && strcmp(bi->nick, Config.s_ChanServ))
|
||||
bi->ChangeNick(Config.s_ChanServ);
|
||||
else if (Config.s_BotServ && bi->HasFlag(BI_BOTSERV) && strcmp(bi->nick, Config.s_BotServ))
|
||||
bi->ChangeNick(Config.s_BotServ);
|
||||
else if (Config.s_HostServ && bi->HasFlag(BI_HOSTSERV) && strcmp(bi->nick, Config.s_HostServ))
|
||||
bi->ChangeNick(Config.s_HostServ);
|
||||
else if (Config.s_OperServ && bi->HasFlag(BI_OPERSERV) && strcmp(bi->nick, Config.s_OperServ))
|
||||
bi->ChangeNick(Config.s_OperServ);
|
||||
else if (Config.s_MemoServ && bi->HasFlag(BI_MEMOSERV) && strcmp(bi->nick, Config.s_MemoServ))
|
||||
bi->ChangeNick(Config.s_MemoServ);
|
||||
else if (Config.s_NickServ && bi->HasFlag(BI_NICKSERV) && strcmp(bi->nick, Config.s_NickServ))
|
||||
bi->ChangeNick(Config.s_NickServ);
|
||||
else if (Config.s_GlobalNoticer && bi->HasFlag(BI_GLOBAL) && strcmp(bi->nick, Config.s_GlobalNoticer))
|
||||
bi->ChangeNick(Config.s_GlobalNoticer);
|
||||
}
|
||||
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.BotDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.BotDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_bs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
BotInfo *bi;
|
||||
static time_t lastwarn = 0;
|
||||
int i;
|
||||
|
||||
if (!(f = open_db(Config.s_BotServ, Config.BotDBName, "w", BOT_VERSION)))
|
||||
return;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
for (bi = botlists[i]; bi; bi = bi->next) {
|
||||
SAFE(write_int8(1, f));
|
||||
SAFE(write_string(bi->nick, f));
|
||||
SAFE(write_string(bi->user, f));
|
||||
SAFE(write_string(bi->host, f));
|
||||
SAFE(write_string(bi->real, f));
|
||||
//SAFE(write_int16(bi->flags, f));
|
||||
SAFE(write_int16(0, f));
|
||||
SAFE(write_int32(bi->created, f));
|
||||
SAFE(write_int16(bi->chancount, f));
|
||||
}
|
||||
}
|
||||
SAFE(write_int8(0, f));
|
||||
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Inserts a bot in the bot list. I can't be much explicit mh? */
|
||||
|
||||
void insert_bot(BotInfo * bi)
|
||||
|
||||
-471
@@ -303,477 +303,6 @@ void chanserv(User * u, char *buf)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Load/save data files. */
|
||||
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.ChanDBName); \
|
||||
failed = 1; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_cs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
int ver, c;
|
||||
unsigned i, j;
|
||||
ChannelInfo *ci, **last, *prev;
|
||||
int failed = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "r", CHAN_VERSION)))
|
||||
return;
|
||||
|
||||
ver = get_file_version(f);
|
||||
|
||||
if (ver != 16)
|
||||
fatal("Invalid database version! (I only understand %d)", CHAN_VERSION);
|
||||
|
||||
for (i = 0; i < 256 && !failed; i++) {
|
||||
uint16 tmp16;
|
||||
uint32 tmp32;
|
||||
unsigned int read;
|
||||
int n_levels;
|
||||
char *s;
|
||||
NickAlias *na;
|
||||
|
||||
last = &chanlists[i];
|
||||
prev = NULL;
|
||||
while ((c = getc_db(f)) != 0) {
|
||||
if (c != 1)
|
||||
fatal("Invalid format in %s", Config.ChanDBName);
|
||||
char channame[CHANMAX];
|
||||
SAFE(read = read_buffer(channame, f));
|
||||
ci = new ChannelInfo(channame);
|
||||
*last = ci;
|
||||
last = &ci->next;
|
||||
ci->prev = prev;
|
||||
prev = ci;
|
||||
SAFE(read_string(&s, f));
|
||||
if (s) {
|
||||
ci->founder = findcore(s);
|
||||
delete [] s;
|
||||
} else
|
||||
ci->founder = NULL;
|
||||
if (ver >= 7) {
|
||||
SAFE(read_string(&s, f));
|
||||
if (s) {
|
||||
if (ver >= 13)
|
||||
ci->successor = findcore(s);
|
||||
else {
|
||||
na = findnick(s);
|
||||
if (na)
|
||||
ci->successor = na->nc;
|
||||
else
|
||||
ci->successor = NULL;
|
||||
}
|
||||
delete [] s;
|
||||
} else
|
||||
ci->successor = NULL;
|
||||
} else {
|
||||
ci->successor = NULL;
|
||||
}
|
||||
|
||||
char nothing[PASSMAX];
|
||||
SAFE(read = read_buffer(nothing, f)); // XXX founder pass was removed.. just here so it works
|
||||
|
||||
SAFE(read_string(&ci->desc, f));
|
||||
if (!ci->desc)
|
||||
ci->desc = sstrdup("");
|
||||
SAFE(read_string(&ci->url, f));
|
||||
SAFE(read_string(&ci->email, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ci->time_registered = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ci->last_used = tmp32;
|
||||
SAFE(read_string(&ci->last_topic, f));
|
||||
SAFE(read = read_buffer(ci->last_topic_setter, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ci->last_topic_time = tmp32;
|
||||
//SAFE(read_int32(&ci->flags, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
|
||||
/* Leaveops cleanup */
|
||||
// if (ver <= 13 && (ci->HasFlag()0x00000020))
|
||||
// ci->UnsetFlag()0x00000020;
|
||||
/* Temporary flags cleanup */
|
||||
ci->UnsetFlag(CI_INHABIT);
|
||||
|
||||
SAFE(read_string(&ci->forbidby, f));
|
||||
SAFE(read_string(&ci->forbidreason, f));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->bantype = tmp16;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
n_levels = tmp16;
|
||||
ci->levels = new int16[CA_SIZE];
|
||||
reset_levels(ci);
|
||||
for (j = 0; j < n_levels; j++) {
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
if (j < CA_SIZE)
|
||||
ci->levels[j] = static_cast<int16>(tmp16);
|
||||
}
|
||||
|
||||
uint16 accesscount = 0;
|
||||
SAFE(read_int16(&accesscount, f));
|
||||
if (accesscount) {
|
||||
for (j = 0; j < accesscount; j++) {
|
||||
uint16 in_use = 0;
|
||||
SAFE(read_int16(&in_use, f));
|
||||
if (in_use) {
|
||||
uint16 level;
|
||||
SAFE(read_int16(&level, f));
|
||||
NickCore *nc;
|
||||
SAFE(read_string(&s, f));
|
||||
if (s) {
|
||||
nc = findcore(s);
|
||||
delete [] s;
|
||||
}
|
||||
else
|
||||
nc = NULL;
|
||||
uint32 last_seen;
|
||||
SAFE(read_int32(&last_seen, f));
|
||||
//SAFE(read_string(&s, f));
|
||||
if (nc)
|
||||
{
|
||||
//std::string creator = s ? s : "";
|
||||
std::string creator = "";
|
||||
ci->AddAccess(nc, level, creator, last_seen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint16 akickcount = 0;
|
||||
NickCore *nc;
|
||||
SAFE(read_int16(&akickcount, f));
|
||||
if (akickcount) {
|
||||
for (j = 0; j < akickcount; ++j)
|
||||
{
|
||||
uint16 flags;
|
||||
SAFE(read_int16(&flags, f));
|
||||
SAFE(read_string(&s, f));
|
||||
char *akickreason;
|
||||
SAFE(read_string(&akickreason, f));
|
||||
char *akickcreator;
|
||||
SAFE(read_string(&akickcreator, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
|
||||
if (flags & AK_ISNICK)
|
||||
{
|
||||
nc = findcore(s);
|
||||
if (!nc)
|
||||
continue;
|
||||
ci->AddAkick(akickcreator, nc, akickreason ? akickreason : "", tmp32);
|
||||
}
|
||||
else
|
||||
ci->AddAkick(akickcreator, s, akickreason ? akickreason : "", tmp32);
|
||||
}
|
||||
}
|
||||
|
||||
//SAFE(read_int32(&ci->mlock_on, f));
|
||||
//SAFE(read_int32(&ci->mlock_off, f));
|
||||
// Clearly this doesn't work
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
if (tmp32)
|
||||
{
|
||||
std::ostringstream limit;
|
||||
limit << tmp32;
|
||||
ci->SetMLock(CMODE_LIMIT, true, limit.str());
|
||||
}
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
if (s)
|
||||
{
|
||||
ci->SetMLock(CMODE_KEY, true, std::string(s));
|
||||
delete [] s;
|
||||
}
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
if (s)
|
||||
{
|
||||
ci->SetMLock(CMODE_FLOOD, true, std::string(s));
|
||||
delete [] s;
|
||||
}
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
if (s)
|
||||
{
|
||||
ci->SetMLock(CMODE_REDIRECT, true, std::string(s));
|
||||
delete [] s;
|
||||
}
|
||||
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
if (tmp16) ci->memos.memos.resize(tmp16);
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->memos.memomax = static_cast<int16>(tmp16);
|
||||
if (!ci->memos.memos.empty()) {
|
||||
for (j = 0; j < ci->memos.memos.size(); j++) {
|
||||
ci->memos.memos[j] = new Memo;
|
||||
Memo *memo = ci->memos.memos[j];
|
||||
SAFE(read_int32(&memo->number, f));
|
||||
//SAFE(read_int16(&memo->flags, f));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
memo->time = tmp32;
|
||||
SAFE(read = read_buffer(memo->sender, f));
|
||||
SAFE(read_string(&memo->text, f));
|
||||
}
|
||||
}
|
||||
|
||||
SAFE(read_string(&ci->entry_message, f));
|
||||
|
||||
ci->c = NULL;
|
||||
|
||||
/* BotServ options */
|
||||
int n_ttb;
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
if (s) {
|
||||
ci->bi = findbot(s);
|
||||
delete [] s;
|
||||
} else
|
||||
ci->bi = NULL;
|
||||
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
//ci->botflags = tmp32;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
n_ttb = tmp16;
|
||||
ci->ttb = new int16[2 * TTB_SIZE];
|
||||
for (j = 0; j < n_ttb; j++) {
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
if (j < TTB_SIZE)
|
||||
ci->ttb[j] = static_cast<int16>(tmp16);
|
||||
}
|
||||
for (j = n_ttb; j < TTB_SIZE; j++)
|
||||
ci->ttb[j] = 0;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->capsmin = tmp16;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->capspercent = tmp16;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->floodlines = tmp16;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->floodsecs = tmp16;
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
ci->repeattimes = tmp16;
|
||||
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
if (tmp16) {
|
||||
for (j = 0; j < tmp16; j++) {
|
||||
uint16 inuse;
|
||||
SAFE(read_int16(&inuse, f));
|
||||
//if (ci->badwords[j].in_use) {
|
||||
char *badword;
|
||||
SAFE(read_string(&badword, f));
|
||||
//SAFE(read_int16(&ci->badwords[j].type, f));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
//ci->badwords[j].type = BW_ANY; // for now
|
||||
ci->AddBadWord(badword, BW_ANY);
|
||||
delete [] badword;
|
||||
// }
|
||||
}
|
||||
}
|
||||
} /* while (getc_db(f) != 0) */
|
||||
|
||||
*last = NULL;
|
||||
|
||||
} /* for (i) */
|
||||
|
||||
close_db(f);
|
||||
|
||||
/* Check for non-forbidden channels with no founder.
|
||||
Makes also other essential tasks. */
|
||||
for (i = 0; i < 256; i++) {
|
||||
ChannelInfo *next;
|
||||
for (ci = chanlists[i]; ci; ci = next) {
|
||||
next = ci->next;
|
||||
if (!(ci->HasFlag(CI_FORBIDDEN)) && !ci->founder) {
|
||||
alog("%s: database load: Deleting founderless channel %s",
|
||||
Config.s_ChanServ, ci->name);
|
||||
delete ci;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.ChanDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.ChanDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_cs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
unsigned i, j;
|
||||
ChannelInfo *ci;
|
||||
static time_t lastwarn = 0;
|
||||
std::string param;
|
||||
|
||||
if (!(f = open_db(Config.s_ChanServ, Config.ChanDBName, "w", CHAN_VERSION)))
|
||||
return;
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
int16 tmp16;
|
||||
unsigned int written;
|
||||
|
||||
for (ci = chanlists[i]; ci; ci = ci->next) {
|
||||
SAFE(write_int8(1, f));
|
||||
SAFE(written = write_buffer(ci->name, f));
|
||||
if (ci->founder)
|
||||
SAFE(write_string(ci->founder->display, f));
|
||||
else
|
||||
SAFE(write_string(NULL, f));
|
||||
if (ci->successor)
|
||||
SAFE(write_string(ci->successor->display, f));
|
||||
else
|
||||
SAFE(write_string(NULL, f));
|
||||
|
||||
char nothing[PASSMAX]; /* founder passwords were removed! */
|
||||
strcpy(nothing, "nothing\0");
|
||||
SAFE(written = write_buffer(nothing, f));
|
||||
|
||||
SAFE(write_string(ci->desc, f));
|
||||
SAFE(write_string(ci->url, f));
|
||||
SAFE(write_string(ci->email, f));
|
||||
SAFE(write_int32(ci->time_registered, f));
|
||||
SAFE(write_int32(ci->last_used, f));
|
||||
SAFE(write_string(ci->last_topic, f));
|
||||
SAFE(written = write_buffer(ci->last_topic_setter, f));
|
||||
SAFE(write_int32(ci->last_topic_time, f));
|
||||
//SAFE(write_int32(ci->flags, f));
|
||||
SAFE(write_int32(0, f));
|
||||
SAFE(write_string(ci->forbidby, f));
|
||||
SAFE(write_string(ci->forbidreason, f));
|
||||
SAFE(write_int16(ci->bantype, f));
|
||||
|
||||
tmp16 = CA_SIZE;
|
||||
SAFE(write_int16(tmp16, f));
|
||||
for (j = 0; j < CA_SIZE; j++)
|
||||
SAFE(write_int16(ci->levels[j], f));
|
||||
|
||||
SAFE(write_int16(ci->GetAccessCount(), f));
|
||||
for (j = 0; j < ci->GetAccessCount(); j++) {
|
||||
ChanAccess *access = ci->GetAccess(j);
|
||||
if (!access->in_use)
|
||||
continue;
|
||||
SAFE(write_int16(access->in_use, f));
|
||||
SAFE(write_int16(access->level, f));
|
||||
SAFE(write_string(access->nc->display, f));
|
||||
SAFE(write_int32(access->last_seen, f));
|
||||
//SAFE(write_string(access->creator.c_str(), f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(ci->GetAkickCount(), f));
|
||||
for (j = 0; j < ci->GetAkickCount(); ++j)
|
||||
{
|
||||
AutoKick *akick = ci->GetAkick(j);
|
||||
//SAFE(write_int16(akick->flags, f));
|
||||
SAFE(write_int16(0, f));
|
||||
if (akick->HasFlag(AK_ISNICK))
|
||||
SAFE(write_string(akick->nc->display, f));
|
||||
else
|
||||
SAFE(write_string(akick->mask.c_str(), f));
|
||||
SAFE(write_string(akick->reason.c_str(), f));
|
||||
SAFE(write_string(akick->creator.c_str(), f));
|
||||
SAFE(write_int32(akick->addtime, f));
|
||||
}
|
||||
|
||||
//SAFE(write_int32(ci->mlock_on, f));
|
||||
//SAFE(write_int32(ci->mlock_off, f));
|
||||
// Clearly this doesnt work
|
||||
SAFE(write_int32(NULL, f));
|
||||
SAFE(write_int32(NULL, f));
|
||||
|
||||
ci->GetParam(CMODE_LIMIT, ¶m);
|
||||
SAFE(write_int32(param.empty() ? NULL : atoi(param.c_str()), f));
|
||||
|
||||
ci->GetParam(CMODE_KEY, ¶m);
|
||||
SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
|
||||
|
||||
ci->GetParam(CMODE_FLOOD, ¶m);
|
||||
SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
|
||||
|
||||
ci->GetParam(CMODE_REDIRECT, ¶m);
|
||||
SAFE(write_string(param.empty() ? NULL : param.c_str(), f));
|
||||
|
||||
SAFE(write_int16(ci->memos.memos.size(), f));
|
||||
SAFE(write_int16(ci->memos.memomax, f));
|
||||
for (j = 0; j < ci->memos.memos.size(); j++) {
|
||||
Memo *memo = ci->memos.memos[j];
|
||||
SAFE(write_int32(memo->number, f));
|
||||
SAFE(write_int16(0, f));
|
||||
//SAFE(write_int16(memo->flags, f));
|
||||
SAFE(write_int32(memo->time, f));
|
||||
SAFE(written = write_buffer(memo->sender, f));
|
||||
SAFE(write_string(memo->text, f));
|
||||
}
|
||||
|
||||
SAFE(write_string(ci->entry_message, f));
|
||||
|
||||
if (ci->bi)
|
||||
SAFE(write_string(ci->bi->nick, f));
|
||||
else
|
||||
SAFE(write_string(NULL, f));
|
||||
|
||||
//SAFE(write_int32(ci->botflags, f));
|
||||
SAFE(write_int32(0, f));
|
||||
|
||||
tmp16 = TTB_SIZE;
|
||||
SAFE(write_int16(tmp16, f));
|
||||
for (j = 0; j < TTB_SIZE; j++)
|
||||
SAFE(write_int16(ci->ttb[j], f));
|
||||
|
||||
SAFE(write_int16(ci->capsmin, f));
|
||||
SAFE(write_int16(ci->capspercent, f));
|
||||
SAFE(write_int16(ci->floodlines, f));
|
||||
SAFE(write_int16(ci->floodsecs, f));
|
||||
SAFE(write_int16(ci->repeattimes, f));
|
||||
|
||||
//SAFE(write_int16(ci->bwcount, f));
|
||||
SAFE(write_int16(ci->GetBadWordCount(), f));
|
||||
for (j = 0; j < ci->GetBadWordCount(); j++) {
|
||||
BadWord *bw = ci->GetBadWord(j);
|
||||
/*SAFE(write_int16(ci->badwords[j].in_use, f));
|
||||
if (ci->badwords[j].in_use) {
|
||||
SAFE(write_string(ci->badwords[j].word, f));
|
||||
SAFE(write_int16(ci->badwords[j].type, f));
|
||||
}*/
|
||||
SAFE(write_int16(1, f));
|
||||
SAFE(write_string(bw->word.c_str(), f));
|
||||
SAFE(write_int16(0, f));
|
||||
}
|
||||
} /* for (chanlists[i]) */
|
||||
|
||||
SAFE(write_int8(0, f));
|
||||
|
||||
} /* for (i) */
|
||||
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Check the current modes on a channel; if they conflict with a mode lock,
|
||||
* fix them.
|
||||
*/
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "pseudo.h" // Remove once new dbs are added
|
||||
|
||||
/* List of messages for each news type. This simplifies message sending. */
|
||||
|
||||
@@ -77,93 +76,6 @@ struct newsmsgs msgarray[] = {
|
||||
}
|
||||
};
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.NewsDBName); \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_news()
|
||||
{
|
||||
dbFILE *f;
|
||||
int i;
|
||||
uint16 n, type;
|
||||
uint32 tmp32;
|
||||
NewsItem *news;
|
||||
char *text;
|
||||
|
||||
if (!(f = open_db(Config.s_OperServ, Config.NewsDBName, "r", NEWS_VERSION)))
|
||||
return;
|
||||
switch (i = get_file_version(f)) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
SAFE(read_int16(&n, f));
|
||||
if (!n) {
|
||||
close_db(f);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
news = new NewsItem;
|
||||
|
||||
SAFE(read_int16(&type, f));
|
||||
news->type = static_cast<NewsType>(type);
|
||||
SAFE(read_int32(&news->num, f));
|
||||
SAFE(read_string(&text, f));
|
||||
news->Text = text;
|
||||
delete [] text;
|
||||
SAFE(read_buffer(news->who, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
news->time = tmp32;
|
||||
|
||||
News.push_back(news);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Unsupported version (%d) on %s", i, Config.NewsDBName);
|
||||
} /* switch (ver) */
|
||||
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.NewsDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.NewsDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_news()
|
||||
{
|
||||
dbFILE *f;
|
||||
static time_t lastwarn = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_OperServ, Config.NewsDBName, "w", NEWS_VERSION)))
|
||||
return;
|
||||
SAFE(write_int16(News.size(), f));
|
||||
for (unsigned i = 0; i < News.size(); i++) {
|
||||
SAFE(write_int16(News[i]->type, f));
|
||||
SAFE(write_int32(News[i]->num, f));
|
||||
SAFE(write_string(News[i]->Text.c_str(), f));
|
||||
SAFE(write_buffer(News[i]->who, f));
|
||||
SAFE(write_int32(News[i]->time, f));
|
||||
}
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
static void DisplayNews(User *u, NewsType Type)
|
||||
{
|
||||
int msg;
|
||||
@@ -495,7 +407,6 @@ class OSNews : public Module
|
||||
|
||||
~OSNews()
|
||||
{
|
||||
save_news();
|
||||
}
|
||||
|
||||
void OnOperServHelp(User *u)
|
||||
@@ -521,14 +432,10 @@ class OSNews : public Module
|
||||
|
||||
void OnSaveDatabase()
|
||||
{
|
||||
/* This needs to be destroyed when new dbs are added... */
|
||||
save_news();
|
||||
}
|
||||
|
||||
void OnPostLoadDatabases()
|
||||
{
|
||||
/* This needs to be destroyed when new dbs are added... */
|
||||
load_news();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+4
-559
@@ -22,529 +22,6 @@ static time_t lastwarn = 0;
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Return the version number on the file. Return 0 if there is no version
|
||||
* number or the number doesn't make sense (i.e. less than 1 or greater
|
||||
* than FILE_VERSION).
|
||||
* @param f dbFile Struct Member
|
||||
* @return int 0 if failure, 1 > is the version number
|
||||
*/
|
||||
int get_file_version(dbFILE * f)
|
||||
{
|
||||
FILE *fp = f->fp;
|
||||
int version =
|
||||
fgetc(fp) << 24 | fgetc(fp) << 16 | fgetc(fp) << 8 | fgetc(fp);
|
||||
if (ferror(fp)) {
|
||||
log_perror("Error reading version number on %s", f->filename);
|
||||
return 0;
|
||||
} else if (feof(fp)) {
|
||||
alog("Error reading version number on %s: End of file detected",
|
||||
f->filename);
|
||||
return 0;
|
||||
} else if (version < 1) {
|
||||
alog("Invalid version number (%d) on %s", version, f->filename);
|
||||
return 0;
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Write the current version number to the file.
|
||||
* @param f dbFile Struct Member
|
||||
* @return 0 on error, 1 on success.
|
||||
*/
|
||||
int write_file_version(dbFILE * f, uint32 version)
|
||||
{
|
||||
FILE *fp = f->fp;
|
||||
if (fputc(version >> 24 & 0xFF, fp) < 0 ||
|
||||
fputc(version >> 16 & 0xFF, fp) < 0 ||
|
||||
fputc(version >> 8 & 0xFF, fp) < 0 ||
|
||||
fputc(version & 0xFF, fp) < 0) {
|
||||
log_perror("Error writing version number on %s", f->filename);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Open the database for reading
|
||||
* @param service If error whom to return the error as
|
||||
* @param filename File to open as the database
|
||||
* @return dbFile struct
|
||||
*/
|
||||
static dbFILE *open_db_read(const char *service, const char *filename)
|
||||
{
|
||||
dbFILE *f;
|
||||
FILE *fp;
|
||||
|
||||
f = new dbFILE;
|
||||
if (!f) {
|
||||
log_perror("Can't read %s database %s", service, filename);
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) {
|
||||
ircdproto->SendGlobops(NULL,
|
||||
"Write error on %s: Memory allocation failed",
|
||||
filename);
|
||||
lastwarn = time(NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
strscpy(f->filename, filename, sizeof(f->filename));
|
||||
f->mode = 'r';
|
||||
fp = fopen(f->filename, "rb");
|
||||
if (!fp) {
|
||||
int errno_save = errno;
|
||||
if (errno != ENOENT)
|
||||
log_perror("Can not read %s database %s", service,
|
||||
f->filename);
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) {
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", f->filename,
|
||||
strerror(errno));
|
||||
lastwarn = time(NULL);
|
||||
}
|
||||
delete f;
|
||||
errno = errno_save;
|
||||
return NULL;
|
||||
}
|
||||
f->fp = fp;
|
||||
f->backupfp = NULL;
|
||||
return f;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Open the database for writting
|
||||
* @param service If error whom to return the error as
|
||||
* @param filename File to open as the database
|
||||
* @param version Database Version
|
||||
* @return dbFile struct
|
||||
*/
|
||||
static dbFILE *open_db_write(const char *service, const char *filename,
|
||||
uint32 version)
|
||||
{
|
||||
dbFILE *f;
|
||||
int fd;
|
||||
#ifdef _WIN32
|
||||
char buffer[_MAX_PATH];
|
||||
char win32filename[MAXPATHLEN];
|
||||
|
||||
/* Get the current working directory: */
|
||||
if (_getcwd(buffer, _MAX_PATH) == NULL) {
|
||||
alog("Warning: Unable to set Current working directory");
|
||||
}
|
||||
#endif
|
||||
|
||||
f = new dbFILE;
|
||||
if (!f) {
|
||||
log_perror("Can not read %s database %s", service, filename);
|
||||
return NULL;
|
||||
}
|
||||
strscpy(f->filename, filename, sizeof(f->filename));
|
||||
#ifndef _WIN32
|
||||
filename = f->filename;
|
||||
#else
|
||||
snprintf(win32filename, sizeof(win32filename), "%s\\%s", buffer,
|
||||
f->filename);
|
||||
filename = win32filename;
|
||||
#endif
|
||||
f->mode = 'w';
|
||||
|
||||
*f->backupname = 0;
|
||||
snprintf(f->backupname, sizeof(f->backupname), "%s.save", filename);
|
||||
if (!*f->backupname || strcmp(f->backupname, filename) == 0) {
|
||||
int errno_save = errno;
|
||||
alog("Opening %s database %s for write: Filename too long",
|
||||
service, filename);
|
||||
delete f;
|
||||
errno = errno_save;
|
||||
return NULL;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
unlink(filename);
|
||||
#else
|
||||
DeleteFile(filename);
|
||||
#endif
|
||||
f->backupfp = fopen(filename, "rb");
|
||||
#ifdef _WIN32
|
||||
if (!MoveFileExA(filename, f->backupname, MOVEFILE_COPY_ALLOWED)
|
||||
&& GetLastError() != ENOENT) {
|
||||
int errno_save = GetLastError();
|
||||
#else
|
||||
if (rename(filename, f->backupname) < 0 && errno != ENOENT) {
|
||||
int errno_save = errno;
|
||||
#endif
|
||||
|
||||
static int walloped = 0;
|
||||
if (!walloped) {
|
||||
walloped++;
|
||||
ircdproto->SendGlobops(NULL, "Can not back up %s database %s",
|
||||
service, filename);
|
||||
}
|
||||
#ifdef _WIN32
|
||||
if (debug) {
|
||||
if (errno == ENOENT) {
|
||||
alog("debug: Error %d (ENOENT) : the file or directory does not exist", errno);
|
||||
} else if (errno == EACCES) {
|
||||
alog("debug: Error %d (EACCES) : error while attempting to access file", errno);
|
||||
} else {
|
||||
alog("debug: Error %d", errno);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (debug) {
|
||||
alog("debug: Error %d", errno);
|
||||
}
|
||||
#endif
|
||||
errno = errno_save;
|
||||
log_perror("Can not back up %s database %s", service, filename);
|
||||
if (!Config.NoBackupOkay) {
|
||||
if (f->backupfp)
|
||||
fclose(f->backupfp);
|
||||
delete f;
|
||||
errno = errno_save;
|
||||
return NULL;
|
||||
}
|
||||
*f->backupname = 0;
|
||||
}
|
||||
#ifndef _WIN32
|
||||
unlink(filename);
|
||||
#else
|
||||
DeleteFile(filename);
|
||||
#endif
|
||||
/* Use open() to avoid people sneaking a new file in under us */
|
||||
#ifndef _WIN32
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
||||
#else
|
||||
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL | _O_BINARY, 0666);
|
||||
#endif
|
||||
f->fp = fdopen(fd, "wb"); /* will fail and return NULL if fd < 0 */
|
||||
if (!f->fp || !write_file_version(f, version)) {
|
||||
int errno_save = errno;
|
||||
static int walloped = 0;
|
||||
if (!walloped) {
|
||||
walloped++;
|
||||
ircdproto->SendGlobops(NULL, "Can't write to %s database %s",
|
||||
service, filename);
|
||||
}
|
||||
errno = errno_save;
|
||||
log_perror("Can't write to %s database %s", service, filename);
|
||||
if (f->fp) {
|
||||
fclose(f->fp);
|
||||
#ifndef _WIN32
|
||||
unlink(filename);
|
||||
#else
|
||||
DeleteFile(filename);
|
||||
#endif
|
||||
}
|
||||
if (*f->backupname && rename(f->backupname, filename) < 0)
|
||||
log_perror("Cannot restore backup copy of %s", filename);
|
||||
|
||||
/* Then the Lord said unto Moses, thou shalt free what thou hast malloced
|
||||
* -- codemastr */
|
||||
delete f;
|
||||
errno = errno_save;
|
||||
return NULL;
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Open a database file for reading (*mode == 'r') or writing (*mode == 'w').
|
||||
* Return the stream pointer, or NULL on error. When opening for write, it
|
||||
* is an error for rename() to return an error (when backing up the original
|
||||
* file) other than ENOENT, if NO_BACKUP_OKAY is not defined; it is an error
|
||||
* if the version number cannot be written to the file; and it is a fatal
|
||||
* error if opening the file for write fails and the backup was successfully
|
||||
* made but cannot be restored.
|
||||
* @param service If error whom to return the error as
|
||||
* @param filename File to open as the database
|
||||
* @param mode Mode for writting or reading
|
||||
* @param version Database Version
|
||||
* @return dbFile struct
|
||||
*/
|
||||
dbFILE *open_db(const char *service, const char *filename,
|
||||
const char *mode, uint32 version)
|
||||
{
|
||||
if (*mode == 'r') {
|
||||
return open_db_read(service, filename);
|
||||
} else if (*mode == 'w') {
|
||||
return open_db_write(service, filename, version);
|
||||
} else {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Restore the database file to its condition before open_db(). This is
|
||||
* identical to close_db() for files open for reading; however, for files
|
||||
* open for writing, we first attempt to restore any backup file before
|
||||
* closing files.
|
||||
* @param dbFile struct
|
||||
* @return void
|
||||
*/
|
||||
void restore_db(dbFILE * f)
|
||||
{
|
||||
int errno_save = errno;
|
||||
|
||||
if (f->mode == 'w') {
|
||||
int ok = 0; /* Did we manage to restore the old file? */
|
||||
errno = errno_save = 0;
|
||||
if (*f->backupname && strcmp(f->backupname, f->filename) != 0) {
|
||||
if (rename(f->backupname, f->filename) == 0)
|
||||
ok = 1;
|
||||
}
|
||||
if (!ok && f->backupfp) {
|
||||
char buf[1024];
|
||||
unsigned int i;
|
||||
ok = 1;
|
||||
if (fseek(f->fp, 0, SEEK_SET) < 0)
|
||||
ok = 0;
|
||||
while (ok && (i = fread(buf, 1, sizeof(buf), f->backupfp)) > 0) {
|
||||
if (fwrite(buf, 1, i, f->fp) != i)
|
||||
ok = 0;
|
||||
}
|
||||
if (ok) {
|
||||
fflush(f->fp);
|
||||
ftruncate(fileno(f->fp), ftell(f->fp));
|
||||
}
|
||||
}
|
||||
if (!ok && errno > 0)
|
||||
log_perror("Unable to restore backup of %s", f->filename);
|
||||
errno_save = errno;
|
||||
if (f->backupfp)
|
||||
fclose(f->backupfp);
|
||||
if (*f->backupname)
|
||||
#ifndef _WIN32
|
||||
unlink(f->backupname);
|
||||
#else
|
||||
DeleteFile(f->backupname);
|
||||
#endif
|
||||
}
|
||||
fclose(f->fp);
|
||||
if (!errno_save)
|
||||
errno_save = errno;
|
||||
delete f;
|
||||
errno = errno_save;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Close a database file. If the file was opened for write, remove the
|
||||
* backup we (may have) created earlier.
|
||||
* @param dbFile struct
|
||||
* @return void
|
||||
*/
|
||||
void close_db(dbFILE * f)
|
||||
{
|
||||
if (f->mode == 'w' && *f->backupname
|
||||
&& strcmp(f->backupname, f->filename) != 0) {
|
||||
if (f->backupfp)
|
||||
fclose(f->backupfp);
|
||||
#ifndef _WIN32
|
||||
unlink(f->backupname);
|
||||
#else
|
||||
DeleteFile(f->backupname);
|
||||
#endif
|
||||
}
|
||||
fclose(f->fp);
|
||||
delete f;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Read and write 2- and 4-byte quantities, pointers, and strings. All
|
||||
* multibyte values are stored in big-endian order (most significant byte
|
||||
* first). A pointer is stored as a byte, either 0 if NULL or 1 if not,
|
||||
* and read pointers are returned as either (void *)0 or (void *)1. A
|
||||
* string is stored with a 2-byte unsigned length (including the trailing
|
||||
* \0) first; a length of 0 indicates that the string pointer is NULL.
|
||||
* Written strings are truncated silently at 65534 bytes, and are always
|
||||
* null-terminated.
|
||||
*
|
||||
* @param ret 16bit integer to write
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int read_int16(uint16 * ret, dbFILE * f)
|
||||
{
|
||||
int c1, c2;
|
||||
|
||||
c1 = fgetc(f->fp);
|
||||
c2 = fgetc(f->fp);
|
||||
if (c1 == EOF || c2 == EOF)
|
||||
return -1;
|
||||
*ret = c1 << 8 | c2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Write a 16bit integer
|
||||
*
|
||||
* @param ret 16bit integer to write
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int write_int16(uint16 val, dbFILE * f)
|
||||
{
|
||||
if (fputc((val >> 8) & 0xFF, f->fp) == EOF
|
||||
|| fputc(val & 0xFF, f->fp) == EOF) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Read a unsigned 32bit integer
|
||||
*
|
||||
* @param ret unsigned 32bit integer to read
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int read_int32(uint32 * ret, dbFILE * f)
|
||||
{
|
||||
int c1, c2, c3, c4;
|
||||
|
||||
c1 = fgetc(f->fp);
|
||||
c2 = fgetc(f->fp);
|
||||
c3 = fgetc(f->fp);
|
||||
c4 = fgetc(f->fp);
|
||||
if (c1 == EOF || c2 == EOF || c3 == EOF || c4 == EOF)
|
||||
return -1;
|
||||
*ret = c1 << 24 | c2 << 16 | c3 << 8 | c4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Write a unsigned 32bit integer
|
||||
*
|
||||
* @param ret unsigned 32bit integer to write
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int write_int32(uint32 val, dbFILE * f)
|
||||
{
|
||||
if (fputc((val >> 24) & 0xFF, f->fp) == EOF)
|
||||
return -1;
|
||||
if (fputc((val >> 16) & 0xFF, f->fp) == EOF)
|
||||
return -1;
|
||||
if (fputc((val >> 8) & 0xFF, f->fp) == EOF)
|
||||
return -1;
|
||||
if (fputc((val) & 0xFF, f->fp) == EOF)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Read Pointer
|
||||
*
|
||||
* @param ret pointer to read
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int read_ptr(void **ret, dbFILE * f)
|
||||
{
|
||||
int c;
|
||||
|
||||
c = fgetc(f->fp);
|
||||
if (c == EOF)
|
||||
return -1;
|
||||
*ret = (c ? reinterpret_cast<void *>(1) : reinterpret_cast<void *>(0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Write Pointer
|
||||
*
|
||||
* @param ret pointer to write
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int write_ptr(const void *ptr, dbFILE * f)
|
||||
{
|
||||
if (fputc(ptr ? 1 : 0, f->fp) == EOF)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Read String
|
||||
*
|
||||
* @param ret string
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int read_string(char **ret, dbFILE * f)
|
||||
{
|
||||
char *s;
|
||||
uint16 len;
|
||||
|
||||
if (read_int16(&len, f) < 0)
|
||||
return -1;
|
||||
if (len == 0) {
|
||||
*ret = NULL;
|
||||
return 0;
|
||||
}
|
||||
s = new char[len];
|
||||
if (len != fread(s, 1, len, f->fp)) {
|
||||
delete [] s;
|
||||
return -1;
|
||||
}
|
||||
*ret = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Write String
|
||||
*
|
||||
* @param ret string
|
||||
* @param dbFile struct
|
||||
* @return -1 on error, 0 otherwise.
|
||||
*/
|
||||
int write_string(const char *s, dbFILE * f)
|
||||
{
|
||||
uint32 len;
|
||||
|
||||
if (!s)
|
||||
return write_int16(0, f);
|
||||
len = strlen(s);
|
||||
if (len > 65534)
|
||||
len = 65534;
|
||||
if (write_int16(static_cast<uint16>(len + 1), f) < 0)
|
||||
return -1;
|
||||
if (len > 0 && fwrite(s, 1, len, f->fp) != len)
|
||||
return -1;
|
||||
if (fputc(0, f->fp) == EOF)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/**
|
||||
* Renames a database
|
||||
*
|
||||
@@ -587,59 +64,31 @@ static void remove_backups()
|
||||
strftime(ext, sizeof(ext), "%Y%m%d", &tm);
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.NickDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.ChanDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.OperDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.NewsDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.ExceptionDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
|
||||
if (Config.s_BotServ) {
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.BotDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
}
|
||||
if (Config.s_HostServ) {
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.HostDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
}
|
||||
if (Config.NSEmailReg) {
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", Config.PreNickDBName, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -749,11 +198,7 @@ void ModuleRemoveBackups(const char *dbname)
|
||||
strftime(ext, sizeof(ext), "%Y%m%d", &tm);
|
||||
|
||||
snprintf(path, sizeof(path), "backups/%s.%s", dbname, ext);
|
||||
#ifndef _WIN32
|
||||
unlink(path);
|
||||
#else
|
||||
DeleteFile(path);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
-117
@@ -18,8 +18,6 @@
|
||||
|
||||
#define HASH(nick) ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))
|
||||
|
||||
void load_hs_dbase(dbFILE * f);
|
||||
|
||||
HostCore *head = NULL; /* head of the HostCore list */
|
||||
|
||||
E int do_hs_sync(NickCore * nc, char *vIdent, char *hostmask,
|
||||
@@ -355,122 +353,7 @@ void delHostCore(const char *nick)
|
||||
/*************************************************************************/
|
||||
/* End of Linked List routines */
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/* Start of Load/Save routines */
|
||||
/*************************************************************************/
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.HostDBName); \
|
||||
failed = 1; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_hs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
int ver;
|
||||
|
||||
if (!(f = open_db(Config.s_HostServ, Config.HostDBName, "r", HOST_VERSION))) {
|
||||
return;
|
||||
}
|
||||
ver = get_file_version(f);
|
||||
|
||||
if (ver != 3) {
|
||||
close_db(f);
|
||||
fatal("DB %s is too old", Config.HostDBName);
|
||||
return;
|
||||
}
|
||||
|
||||
load_hs_dbase(f);
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
void load_hs_dbase(dbFILE * f)
|
||||
{
|
||||
int c;
|
||||
int failed = 0;
|
||||
|
||||
char *nick;
|
||||
char *vHost;
|
||||
char *creator;
|
||||
char *vIdent;
|
||||
uint32 time;
|
||||
|
||||
while (!failed && (c = getc_db(f)) == 1) {
|
||||
if (c == 1) {
|
||||
SAFE(read_string(&nick, f));
|
||||
SAFE(read_string(&vIdent, f));
|
||||
SAFE(read_string(&vHost, f));
|
||||
SAFE(read_string(&creator, f));
|
||||
SAFE(read_int32(&time, f));
|
||||
|
||||
// Older Anope could save an empty vident when importing from MySQL, so trap that here.
|
||||
if (vIdent && !strcmp(vIdent, ""))
|
||||
{
|
||||
delete [] vIdent;
|
||||
vIdent = NULL;
|
||||
}
|
||||
|
||||
addHostCore(nick, vIdent, vHost, creator, time); /* could get a speed increase by not searching the list */
|
||||
delete [] nick; /* as we know the db is in alphabetical order... */
|
||||
delete [] vHost;
|
||||
delete [] creator;
|
||||
if (vIdent)
|
||||
delete [] vIdent;
|
||||
}
|
||||
else
|
||||
{
|
||||
fatal("Invalid format in %s %d", Config.HostDBName, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
/*************************************************************************/
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.HostDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.HostDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_hs_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
static time_t lastwarn = 0;
|
||||
HostCore *current;
|
||||
|
||||
if (!(f = open_db(Config.s_HostServ, Config.HostDBName, "w", HOST_VERSION)))
|
||||
return;
|
||||
|
||||
current = head;
|
||||
while (current != NULL) {
|
||||
SAFE(write_int8(1, f));
|
||||
SAFE(write_string(current->nick, f));
|
||||
SAFE(write_string(current->vIdent, f));
|
||||
SAFE(write_string(current->vHost, f));
|
||||
SAFE(write_string(current->creator, f));
|
||||
SAFE(write_int32(current->time, f));
|
||||
current = current->next;
|
||||
}
|
||||
SAFE(write_int8(0, f));
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
/* End of Load/Save Functions */
|
||||
/*************************************************************************/
|
||||
/*************************************************************************/
|
||||
/* Start of Generic Functions */
|
||||
/*************************************************************************/
|
||||
|
||||
+1
-38
@@ -500,44 +500,7 @@ int init_secondary(int ac, char **av)
|
||||
add_entropy_userkeys();
|
||||
|
||||
/* Load up databases */
|
||||
load_ns_dbase();
|
||||
if (debug)
|
||||
alog("debug: Loaded %s database (1/%d)", Config.s_NickServ,
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
if (Config.s_HostServ) {
|
||||
load_hs_dbase();
|
||||
if (debug)
|
||||
alog("debug: Loaded %s database (2/%d)", Config.s_HostServ,
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
} else if (debug) {
|
||||
alog("debug: HostServ database (2/%d) not loaded because HostServ is disabled", (Config.PreNickDBName ? 7 : 6));
|
||||
}
|
||||
if (Config.s_BotServ) {
|
||||
load_bs_dbase();
|
||||
if (debug)
|
||||
alog("debug: Loaded %s database (3/%d)", Config.s_BotServ,
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
} else if (debug) {
|
||||
alog("debug: BotServ database (3/%d) not loaded because BotServ is disabled", (Config.PreNickDBName ? 7 : 6));
|
||||
}
|
||||
load_cs_dbase();
|
||||
if (debug)
|
||||
alog("debug: Loaded %s database (4/%d)", Config.s_ChanServ,
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
load_os_dbase();
|
||||
if (debug)
|
||||
alog("debug: Loaded %s database (5/%d)", Config.s_OperServ,
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
load_exceptions();
|
||||
if (debug)
|
||||
alog("debug: Loaded exception database (6/%d)",
|
||||
(Config.PreNickDBName ? 7 : 6));
|
||||
if (Config.PreNickDBName) {
|
||||
load_ns_req_db();
|
||||
if (debug)
|
||||
alog("debug: Loaded PreNick database (7/7)");
|
||||
}
|
||||
alog("Databases loaded");
|
||||
//alog("Databases loaded");
|
||||
|
||||
// XXX: this is duplicated in type loading.
|
||||
for (std::list<std::pair<std::string, std::string> >::iterator it = Config.Opers.begin(); it != Config.Opers.end(); it++)
|
||||
|
||||
-14
@@ -139,20 +139,6 @@ void save_databases()
|
||||
FOREACH_MOD(I_OnSaveDatabase, OnSaveDatabase())
|
||||
if (debug)
|
||||
alog("debug: Saving FFF databases");
|
||||
backup_databases();
|
||||
save_ns_dbase();
|
||||
if (Config.PreNickDBName) {
|
||||
save_ns_req_dbase();
|
||||
}
|
||||
save_cs_dbase();
|
||||
if (Config.s_BotServ) {
|
||||
save_bs_dbase();
|
||||
}
|
||||
if (Config.s_HostServ) {
|
||||
save_hs_dbase();
|
||||
}
|
||||
save_os_dbase();
|
||||
save_exceptions();
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
-362
@@ -260,368 +260,6 @@ void nickserv(User * u, char *buf)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Load/save data files. */
|
||||
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.NickDBName); \
|
||||
failed = 1; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_ns_req_db()
|
||||
{
|
||||
dbFILE *f;
|
||||
int i, c, ver;
|
||||
NickRequest *nr;
|
||||
uint32 tmp32;
|
||||
int failed = 0, len;
|
||||
char *pass;
|
||||
|
||||
if (!(f = open_db(Config.s_NickServ, Config.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", Config.PreNickDBName);
|
||||
|
||||
char *s;
|
||||
SAFE(read_string(&s, f));
|
||||
nr = new NickRequest(s);
|
||||
delete [] s;
|
||||
|
||||
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);
|
||||
delete [] 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()
|
||||
{
|
||||
dbFILE *f;
|
||||
int ver, c;
|
||||
unsigned i, j;
|
||||
NickAlias *na, **nalast, *naprev;
|
||||
NickCore *nc, **nclast, *ncprev;
|
||||
int failed = 0;
|
||||
uint16 tmp16;
|
||||
uint32 tmp32;
|
||||
char *s;
|
||||
|
||||
if (!(f = open_db(Config.s_NickServ, Config.NickDBName, "r", NICK_VERSION)))
|
||||
return;
|
||||
|
||||
ver = get_file_version(f);
|
||||
|
||||
if (ver != 14)
|
||||
{
|
||||
close_db(f);
|
||||
fatal("DB %s is too old", Config.NickDBName);
|
||||
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", Config.NickDBName);
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
nc = new NickCore(s);
|
||||
delete [] s;
|
||||
*nclast = nc;
|
||||
nclast = &nc->next;
|
||||
nc->prev = ncprev;
|
||||
ncprev = nc;
|
||||
|
||||
slist_init(&nc->aliases);
|
||||
|
||||
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));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
if (!Config.NSAllowKillImmed)
|
||||
nc->UnsetFlag(NI_KILL_IMMED);
|
||||
SAFE(read_int16(&nc->language, f));
|
||||
|
||||
uint16 accesscount;
|
||||
SAFE(read_int16(&accesscount, f));
|
||||
if (accesscount)
|
||||
{
|
||||
for (j = 0; j < accesscount; ++j)
|
||||
{
|
||||
char *access;
|
||||
SAFE(read_string(&access, f));
|
||||
if (access)
|
||||
{
|
||||
nc->AddAccess(access);
|
||||
delete [] access;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
if (tmp16) nc->memos.memos.resize(tmp16);
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
nc->memos.memomax = static_cast<int16>(tmp16);
|
||||
if (!nc->memos.memos.empty())
|
||||
{
|
||||
for (j = 0; j < nc->memos.memos.size(); j++)
|
||||
{
|
||||
nc->memos.memos[j] = new Memo;
|
||||
Memo *memo = nc->memos.memos[j];
|
||||
SAFE(read_int32(&memo->number, f));
|
||||
//SAFE(read_int16(&memo->flags, f));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
memo->time = tmp32;
|
||||
SAFE(read_buffer(memo->sender, f));
|
||||
SAFE(read_string(&memo->text, f));
|
||||
}
|
||||
}
|
||||
|
||||
SAFE(read_int16(&nc->channelcount, f));
|
||||
SAFE(read_int16(&tmp16, 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", Config.NickDBName);
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
na = new NickAlias(s, nclists[0]); // XXXXXXXX
|
||||
delete [] s;
|
||||
|
||||
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));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
//na->UnsetFlag(NS_TEMPORARY);
|
||||
|
||||
SAFE(read_string(&s, f));
|
||||
na->nc = findcore(s);
|
||||
delete [] s;
|
||||
|
||||
slist_add(&na->nc->aliases, na);
|
||||
|
||||
if (!na->HasFlag(NS_FORBIDDEN))
|
||||
{
|
||||
if (!na->last_usermask)
|
||||
na->last_usermask = sstrdup("");
|
||||
if (!na->last_realname)
|
||||
na->last_realname = sstrdup("");
|
||||
}
|
||||
|
||||
*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.", Config.s_NickServ, na->nick);
|
||||
delete na;
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.NickDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.NickDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
|
||||
void save_ns_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
unsigned i, j;
|
||||
NickAlias *na;
|
||||
NickCore *nc;
|
||||
static time_t lastwarn = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_NickServ, Config.NickDBName, "w", NICK_VERSION)))
|
||||
return;
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
for (nc = nclists[i]; nc; nc = nc->next)
|
||||
{
|
||||
SAFE(write_int8(1, f));
|
||||
|
||||
SAFE(write_string(nc->display, f));
|
||||
SAFE(write_buffer(nc->pass, f));
|
||||
|
||||
SAFE(write_string(nc->email, f));
|
||||
SAFE(write_string(nc->greet, f));
|
||||
SAFE(write_int32(nc->icq, f));
|
||||
SAFE(write_string(nc->url, f));
|
||||
|
||||
//SAFE(write_int32(nc->flags, f));
|
||||
SAFE(write_int32(0, f));
|
||||
SAFE(write_int16(nc->language, f));
|
||||
|
||||
SAFE(write_int16(nc->access.size(), f));
|
||||
for (j = 0; j < nc->access.size(); ++j)
|
||||
{
|
||||
std::string access = nc->GetAccess(j);
|
||||
SAFE(write_string(access.c_str(), f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(nc->memos.memos.size(), f));
|
||||
SAFE(write_int16(nc->memos.memomax, f));
|
||||
for (j = 0; j < nc->memos.memos.size(); j++)
|
||||
{
|
||||
Memo *memo = nc->memos.memos[j];
|
||||
SAFE(write_int32(memo->number, f));
|
||||
//SAFE(write_int16(memo->flags, f));
|
||||
SAFE(write_int16(0, f));
|
||||
SAFE(write_int32(memo->time, f));
|
||||
SAFE(write_buffer(memo->sender, f));
|
||||
SAFE(write_string(memo->text, f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(nc->channelcount, f));
|
||||
SAFE(write_int16(nc->channelcount, f)); // write this twice to avoid having to revbump the NickServ DB from anope 1.7, hack alert XXX
|
||||
|
||||
} /* for (nc) */
|
||||
|
||||
SAFE(write_int8(0, f));
|
||||
|
||||
} /* for (i) */
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
for (na = nalists[i]; na; na = na->next)
|
||||
{
|
||||
SAFE(write_int8(1, f));
|
||||
|
||||
SAFE(write_string(na->nick, f));
|
||||
|
||||
SAFE(write_string(na->last_usermask, f));
|
||||
SAFE(write_string(na->last_realname, f));
|
||||
SAFE(write_string(na->last_quit, f));
|
||||
|
||||
SAFE(write_int32(na->time_registered, f));
|
||||
SAFE(write_int32(na->last_seen, f));
|
||||
|
||||
//SAFE(write_int16(na->status, f));
|
||||
SAFE(write_int16(0, f));
|
||||
|
||||
SAFE(write_string(na->nc->display, f));
|
||||
|
||||
} /* for (na) */
|
||||
SAFE(write_int8(0, f));
|
||||
} /* for (i) */
|
||||
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
void save_ns_req_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
int i;
|
||||
NickRequest *nr;
|
||||
static time_t lastwarn = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_NickServ, Config.PreNickDBName, "w", PRE_NICK_VERSION)))
|
||||
return;
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
{
|
||||
for (nr = nrlists[i]; nr; nr = nr->next)
|
||||
{
|
||||
SAFE(write_int8(1, f));
|
||||
SAFE(write_string(nr->nick, f));
|
||||
SAFE(write_string(nr->passcode, f));
|
||||
SAFE(write_buffer(nr->password, f));
|
||||
SAFE(write_string(nr->email, f));
|
||||
SAFE(write_int32(nr->requested, f));
|
||||
SAFE(write_int8(0, f));
|
||||
}
|
||||
}
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Check whether a user is on the access list of the nick they're using If
|
||||
* not, send warnings as appropriate. If so (and not NI_SECURE), update
|
||||
* last seen info.
|
||||
|
||||
-199
@@ -143,205 +143,6 @@ void operserv(User * u, char *buf)
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/**************************** Privilege checks ***************************/
|
||||
/*************************************************************************/
|
||||
|
||||
/* Load OperServ data. */
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.OperDBName); \
|
||||
failed = 1; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_os_dbase()
|
||||
{
|
||||
dbFILE *f;
|
||||
int16 i, ver;
|
||||
uint16 tmp16;
|
||||
uint32 tmp32;
|
||||
int failed = 0;
|
||||
|
||||
if (!(f = open_db(Config.s_OperServ, Config.OperDBName, "r", OPER_VERSION)))
|
||||
return;
|
||||
|
||||
ver = get_file_version(f);
|
||||
if (ver != 13)
|
||||
{
|
||||
close_db(f);
|
||||
fatal("Read error on %s", Config.ChanDBName);
|
||||
return;
|
||||
}
|
||||
|
||||
SAFE(read_int32(&maxusercnt, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
maxusertime = tmp32;
|
||||
|
||||
Akill *ak;
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&akills, tmp16);
|
||||
|
||||
for (i = 0; i < akills.capacity; i++) {
|
||||
ak = new Akill;
|
||||
|
||||
SAFE(read_string(&ak->user, f));
|
||||
SAFE(read_string(&ak->host, f));
|
||||
SAFE(read_string(&ak->by, f));
|
||||
SAFE(read_string(&ak->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ak->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
ak->expires = tmp32;
|
||||
|
||||
slist_add(&akills, ak);
|
||||
}
|
||||
|
||||
SXLine *sx;
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&sglines, tmp16);
|
||||
|
||||
for (i = 0; i < sglines.capacity; i++) {
|
||||
sx = new SXLine;
|
||||
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
|
||||
slist_add(&sglines, sx);
|
||||
}
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&sqlines, tmp16);
|
||||
|
||||
for (i = 0; i < sqlines.capacity; i++) {
|
||||
sx = new SXLine;
|
||||
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
|
||||
slist_add(&sqlines, sx);
|
||||
}
|
||||
|
||||
read_int16(&tmp16, f);
|
||||
slist_setcapacity(&szlines, tmp16);
|
||||
|
||||
for (i = 0; i < szlines.capacity; i++) {
|
||||
sx = new SXLine;
|
||||
|
||||
SAFE(read_string(&sx->mask, f));
|
||||
SAFE(read_string(&sx->by, f));
|
||||
SAFE(read_string(&sx->reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->seton = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
sx->expires = tmp32;
|
||||
|
||||
slist_add(&szlines, sx);
|
||||
}
|
||||
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Save OperServ data. */
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.OperDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.OperDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_os_dbase()
|
||||
{
|
||||
int i;
|
||||
dbFILE *f;
|
||||
static time_t lastwarn = 0;
|
||||
Akill *ak;
|
||||
SXLine *sx;
|
||||
|
||||
if (!(f = open_db(Config.s_OperServ, Config.OperDBName, "w", OPER_VERSION)))
|
||||
return;
|
||||
SAFE(write_int32(maxusercnt, f));
|
||||
SAFE(write_int32(maxusertime, f));
|
||||
|
||||
SAFE(write_int16(akills.count, f));
|
||||
for (i = 0; i < akills.count; i++) {
|
||||
ak = static_cast<Akill *>(akills.list[i]);
|
||||
|
||||
SAFE(write_string(ak->user, f));
|
||||
SAFE(write_string(ak->host, f));
|
||||
SAFE(write_string(ak->by, f));
|
||||
SAFE(write_string(ak->reason, f));
|
||||
SAFE(write_int32(ak->seton, f));
|
||||
SAFE(write_int32(ak->expires, f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(sglines.count, f));
|
||||
for (i = 0; i < sglines.count; i++) {
|
||||
sx = static_cast<SXLine *>(sglines.list[i]);
|
||||
|
||||
SAFE(write_string(sx->mask, f));
|
||||
SAFE(write_string(sx->by, f));
|
||||
SAFE(write_string(sx->reason, f));
|
||||
SAFE(write_int32(sx->seton, f));
|
||||
SAFE(write_int32(sx->expires, f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(sqlines.count, f));
|
||||
for (i = 0; i < sqlines.count; i++) {
|
||||
sx = static_cast<SXLine *>(sqlines.list[i]);
|
||||
|
||||
SAFE(write_string(sx->mask, f));
|
||||
SAFE(write_string(sx->by, f));
|
||||
SAFE(write_string(sx->reason, f));
|
||||
SAFE(write_int32(sx->seton, f));
|
||||
SAFE(write_int32(sx->expires, f));
|
||||
}
|
||||
|
||||
SAFE(write_int16(szlines.count, f));
|
||||
for (i = 0; i < szlines.count; i++) {
|
||||
sx = static_cast<SXLine *>(szlines.list[i]);
|
||||
|
||||
SAFE(write_string(sx->mask, f));
|
||||
SAFE(write_string(sx->by, f));
|
||||
SAFE(write_string(sx->reason, f));
|
||||
SAFE(write_int32(sx->seton, f));
|
||||
SAFE(write_int32(sx->expires, f));
|
||||
}
|
||||
|
||||
close_db(f);
|
||||
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/*********************** OperServ command functions **********************/
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -305,100 +305,6 @@ Exception *find_hostip_exception(const char *host, const char *hostip)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
/*********************** Exception Load/Save *****************************/
|
||||
/*************************************************************************/
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
if (!forceload) \
|
||||
fatal("Read error on %s", Config.ExceptionDBName); \
|
||||
nexceptions = i; \
|
||||
break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void load_exceptions()
|
||||
{
|
||||
dbFILE *f;
|
||||
int i;
|
||||
uint16 n;
|
||||
uint16 tmp16;
|
||||
uint32 tmp32;
|
||||
|
||||
if (!
|
||||
(f = open_db(Config.s_OperServ, Config.ExceptionDBName, "r", EXCEPTION_VERSION)))
|
||||
return;
|
||||
switch (i = get_file_version(f)) {
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
SAFE(read_int16(&n, f));
|
||||
nexceptions = n;
|
||||
exceptions = static_cast<Exception *>(scalloc(sizeof(Exception) * nexceptions, 1));
|
||||
if (!nexceptions) {
|
||||
close_db(f);
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < nexceptions; i++) {
|
||||
SAFE(read_string(&exceptions[i].mask, f));
|
||||
SAFE(read_int16(&tmp16, f));
|
||||
exceptions[i].limit = tmp16;
|
||||
SAFE(read_buffer(exceptions[i].who, f));
|
||||
SAFE(read_string(&exceptions[i].reason, f));
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
exceptions[i].time = tmp32;
|
||||
SAFE(read_int32(&tmp32, f));
|
||||
exceptions[i].expires = tmp32;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fatal("Unsupported version (%d) on %s", i, Config.ExceptionDBName);
|
||||
} /* switch (ver) */
|
||||
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
#define SAFE(x) do { \
|
||||
if ((x) < 0) { \
|
||||
restore_db(f); \
|
||||
log_perror("Write error on %s", Config.ExceptionDBName); \
|
||||
if (time(NULL) - lastwarn > Config.WarningTimeout) { \
|
||||
ircdproto->SendGlobops(NULL, "Write error on %s: %s", Config.ExceptionDBName, \
|
||||
strerror(errno)); \
|
||||
lastwarn = time(NULL); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void save_exceptions()
|
||||
{
|
||||
dbFILE *f;
|
||||
int i;
|
||||
static time_t lastwarn = 0;
|
||||
|
||||
if (!
|
||||
(f = open_db(Config.s_OperServ, Config.ExceptionDBName, "w", EXCEPTION_VERSION)))
|
||||
return;
|
||||
SAFE(write_int16(nexceptions, f));
|
||||
for (i = 0; i < nexceptions; i++) {
|
||||
SAFE(write_string(exceptions[i].mask, f));
|
||||
SAFE(write_int16(static_cast<uint16>(exceptions[i].limit), f));
|
||||
SAFE(write_buffer(exceptions[i].who, f));
|
||||
SAFE(write_string(exceptions[i].reason, f));
|
||||
SAFE(write_int32(exceptions[i].time, f));
|
||||
SAFE(write_int32(exceptions[i].expires, f));
|
||||
}
|
||||
close_db(f);
|
||||
}
|
||||
|
||||
#undef SAFE
|
||||
|
||||
/*************************************************************************/
|
||||
/************************ Exception Manipulation *************************/
|
||||
|
||||
Reference in New Issue
Block a user