1
0
mirror of https://github.com/anope/anope.git synced 2026-07-05 00:53:12 +02:00

Removed db-upgrade, its no longer needed

This commit is contained in:
Adam
2011-01-20 19:42:27 -05:00
parent ab2e34d817
commit 05933e9f21
4 changed files with 69 additions and 498 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_EN
throw CoreException("Empty display passed to NickCore constructor");
this->ot = NULL;
this->language = this->channelcount = 0;
this->channelcount = 0;
this->lastmail = 0;
this->display = coredisplay;
+15 -10
View File
@@ -159,7 +159,7 @@ int main(int argc, char *argv[])
std::ofstream fs;
std::string hashm, ircd;
printf("\n"C_LBLUE"Anope 1.8.x -> 1.9.2+ database converter"C_NONE"\n\n");
printf("\n"C_LBLUE"Anope 1.8.x -> 1.9.3+ database converter"C_NONE"\n\n");
while (hashm != "md5" && hashm != "sha1" && hashm != "oldmd5" && hashm != "plain")
{
@@ -189,8 +189,7 @@ int main(int argc, char *argv[])
exit(1);
}
// VERSHUN ONE
fs << "VER 1" << std::endl;
fs << "VER 2" << std::endl;
/* Section I: Nicks */
/* Ia: First database */
@@ -355,7 +354,7 @@ int main(int argc, char *argv[])
char **access;
Memo *memos;
int j, len;
char cpass[5000]; // if it's ever this long, I will commit suicide
std::string cpass;
for (nc = nclists[i]; nc; nc = nc->next)
{
if (nc->aliascount < 1)
@@ -382,12 +381,17 @@ int main(int argc, char *argv[])
else
len = 32;
b64_encode(nc->pass, len, cpass, 5000);
if (hashm == "plain")
b64_encode(nc->pass, cpass);
else
cpass = Hex(nc->pass);
fs << "NC " << nc->display << " " << hashm << ":" << cpass;
fs << " " << GetLanguageID(nc->language) << " " << nc->memos.memomax << " " << nc->channelcount << std::endl;
fs << "NC " << nc->display << " " << hashm << ":" << cpass << std::endl;
fs << "MD LANGUAGE " << GetLanguageID(nc->language) << std::endl;
fs << "MD MEMOMAX " << nc->memos.memomax << std::endl;
fs << "MD CHANCOUNT " << nc->channelcount << std::endl;
std::cout << "Wrote account for " << nc->display << " passlen " << strlen(cpass) << std::endl;
std::cout << "Wrote account for " << nc->display << " passlen " << cpass.length() << std::endl;
if (nc->email)
fs << "MD EMAIL " << nc->email << std::endl;
if (nc->greet)
@@ -784,12 +788,13 @@ int main(int argc, char *argv[])
{
int j;
fs << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used;
fs << " " << ci->bantype << " " << ci->memos.memomax << std::endl;
fs << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used << std::endl;
if (ci->founder)
fs << "MD FOUNDER " << ci->founder << std::endl;
if (ci->successor)
fs << "MD SUCCESSOR " << ci->successor << std::endl;
fs << "MD BANTYPE " << ci->bantype << std::endl;
fs << "MD MEMOMAX " << ci->memos.memomax << std::endl;
fs << "MD LEVELS";
for (j = 0; j < 36; ++j)
{
+53 -188
View File
@@ -239,7 +239,7 @@ NickAlias *nalists[1024];
NickCore *nclists[1024];
HostCore *head = NULL;
int b64_encode(char *src, size_t srclength, char *target, size_t targsize);
void b64_encode(const std::string &src, std::string &target);
/* Memo Flags */
#define MF_UNREAD 0x0001 /* Memo has not yet been read */
@@ -380,48 +380,48 @@ const std::string GetLanguageID(int id)
switch (id)
{
case LANG_EN_US:
return "en";
return "en_US";
break;
case LANG_JA_JIS:
case LANG_JA_EUC:
case LANG_JA_SJIS: // these seem to be unused
return "en";
return "en_US";
break;
case LANG_ES:
return "es";
return "es_ES";
break;
case LANG_PT:
return "pt";
return "pt_PT";
break;
case LANG_FR:
return "fr";
return "fr_FR";
break;
case LANG_TR:
return "tr";
return "tr_TR";
break;
case LANG_IT:
return "it";
return "it_IT";
break;
case LANG_DE:
return "de";
return "de_DE";
break;
case LANG_CAT:
return "ca"; // yes, iso639 defines catalan as CA
return "ca_ES"; // yes, iso639 defines catalan as CA
break;
case LANG_GR:
return "gr";
return "el_GR";
break;
case LANG_NL:
return "nl";
return "nl_NL";
break;
case LANG_RU:
return "ru";
return "ru_RU";
break;
case LANG_HUN:
return "hu";
return "hu_HU";
break;
case LANG_PL:
return "pl";
return "pl_PL";
break;
default:
abort();
@@ -779,6 +779,21 @@ long base64dec(char *b64)
return 0;
}
std::string Hex(const std::string &data)
{
const char hextable[] = "0123456789abcdef";
size_t l = data.length();
std::string rv;
for (size_t i = 0; i < l; ++i)
{
unsigned char c = data[i];
rv += hextable[c >> 4];
rv += hextable[c & 0xF];
}
return rv;
}
static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
@@ -845,192 +860,42 @@ static const char Pad64 = '=';
characters followed by one "=" padding character.
*/
int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
void b64_encode(const std::string &src, std::string &target)
{
size_t datalength = 0;
size_t src_pos = 0, src_len = src.length();
unsigned char input[3];
unsigned char output[4];
size_t i;
while (srclength > 2)
target.clear();
while (src_len - src_pos > 2)
{
input[0] = *src++;
input[1] = *src++;
input[2] = *src++;
srclength -= 3;
input[0] = src[src_pos++];
input[1] = src[src_pos++];
input[2] = src[src_pos++];
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
output[3] = input[2] & 0x3f;
if (datalength + 4 > targsize)
return -1;
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
target[datalength++] = Base64[output[2]];
target[datalength++] = Base64[output[3]];
target += Base64[input[0] >> 2];
target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
target += Base64[input[2] & 0x3f];
}
/* Now we worry about padding. */
if (srclength)
/* Now we worry about padding */
if (src_pos != src_len)
{
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
for (i = 0; i < srclength; ++i)
input[i] = *src++;
input[0] = input[1] = input[2] = 0;
for (size_t i = 0; i < src_len - src_pos; ++i)
input[i] = src[src_pos + i];
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
if (datalength + 4 > targsize)
return -1;
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
if (srclength == 1)
target[datalength++] = Pad64;
target += Base64[input[0] >> 2];
target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
if (src_pos == src_len - 1)
target += Pad64;
else
target[datalength++] = Base64[output[2]];
target[datalength++] = Pad64;
target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
target += Pad64;
}
if (datalength >= targsize)
return -1;
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return datalength;
}
/* skips all whitespace anywhere.
converts characters, four at a time, starting at (or after)
src from base - 64 numbers into three 8 bit bytes in the target area.
it returns the number of data bytes stored at the target, or -1 on error.
*/
int b64_decode(const char *src, char *target, size_t targsize)
{
int tarindex, state, ch;
const char *pos;
state = 0;
tarindex = 0;
while ((ch = *src++))
{
if (isspace(ch)) /* Skip whitespace anywhere. */
continue;
if (ch == Pad64)
break;
pos = strchr(Base64, ch);
if (!pos) /* A non-base64 character. */
return -1;
switch (state)
{
case 0:
if (target)
{
if (static_cast<size_t>(tarindex) >= targsize)
return -1;
target[tarindex] = (pos - Base64) << 2;
}
state = 1;
break;
case 1:
if (target)
{
if (static_cast<size_t>(tarindex) + 1 >= targsize)
return -1;
target[tarindex] |= (pos - Base64) >> 4;
target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
}
++tarindex;
state = 2;
break;
case 2:
if (target)
{
if (static_cast<size_t>(tarindex) + 1 >= targsize)
return -1;
target[tarindex] |= (pos - Base64) >> 2;
target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
}
++tarindex;
state = 3;
break;
case 3:
if (target)
{
if (static_cast<size_t>(tarindex) >= targsize)
return (-1);
target[tarindex] |= pos - Base64;
}
++tarindex;
state = 0;
break;
default:
abort();
}
}
/*
* We are done decoding Base-64 chars. Let's see if we ended
* on a byte boundary, and/or with erroneous trailing characters.
*/
if (ch == Pad64) /* We got a pad char. */
{
ch = *src++; /* Skip it, get next. */
switch (state)
{
case 0: /* Invalid = in first position */
case 1: /* Invalid = in second position */
return (-1);
case 2: /* Valid, means one byte of info */
/* Skip any number of spaces. */
for (; ch != '\0'; ch = *src++)
if (!isspace(ch))
break;
/* Make sure there is another trailing = sign. */
if (ch != Pad64)
return -1;
ch = *src++; /* Skip the = */
/* Fall through to "single trailing =" case. */
/* FALLTHROUGH */
case 3: /* Valid, means two bytes of info */
/*
* We know this char is an =. Is there anything but
* whitespace after it?
*/
for (; ch != '\0'; ch = *src++)
if (!isspace(ch))
return (-1);
/*
* Now make sure for cases 2 and 3 that the "extra"
* bits that slopped past the last full byte were
* zeros. If we don't check them, they become a
* subliminal channel.
*/
if (target && target[tarindex])
return -1;
}
}
else
{
/*
* We ended by seeing the end of the string. Make sure we
* have no partial bytes lying around.
*/
if (state)
return -1;
}
return tarindex;
}
/* ':' and '#' and '&' and '+' and '@' must never be in this table. */
/* these tables must NEVER CHANGE! >) */
-299
View File
@@ -1,299 +0,0 @@
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <cstring>
#ifndef _WIN32
static const std::string C_LBLUE = "\033[1;34m";
static const std::string C_NONE = "\033[m";
#else
static const std::string C_LBLUE = "";
static const std::string C_NONE = "";
#endif
/** sepstream allows for splitting token seperated lists.
* Each successive call to sepstream::GetToken() returns
* the next token, until none remain, at which point the method returns
* an empty string.
*/
class sepstream
{
private:
/** Original string.
*/
std::string tokens;
/** Last position of a seperator token
*/
std::string::iterator last_starting_position;
/** Current string position
*/
std::string::iterator n;
/** Seperator value
*/
char sep;
public:
/** Create a sepstream and fill it with the provided data
*/
sepstream(const std::string &source, char seperator);
virtual ~sepstream() { }
/** Fetch the next token from the stream
* @param token The next token from the stream is placed here
* @return True if tokens still remain, false if there are none left
*/
virtual bool GetToken(std::string &token);
/** Fetch the entire remaining stream, without tokenizing
* @return The remaining part of the stream
*/
virtual const std::string GetRemaining();
/** Returns true if the end of the stream has been reached
* @return True if the end of the stream has been reached, otherwise false
*/
virtual bool StreamEnd();
};
sepstream::sepstream(const std::string &source, char seperator) : tokens(source), sep(seperator)
{
last_starting_position = n = tokens.begin();
}
bool sepstream::GetToken(std::string &token)
{
std::string::iterator lsp = last_starting_position;
while (n != tokens.end())
{
if (*n == sep || n + 1 == tokens.end())
{
last_starting_position = n + 1;
token = std::string(lsp, n + 1 == tokens.end() ? n + 1 : n);
while (token.length() && token.rfind(sep) == token.length() - 1)
token.erase(token.end() - 1);
++n;
return true;
}
++n;
}
token.clear();
return false;
}
const std::string sepstream::GetRemaining()
{
return std::string(n, tokens.end());
}
bool sepstream::StreamEnd()
{
return n == tokens.end();
}
std::vector<std::string> BuildStringVector(const std::string &src, char delim = ' ')
{
sepstream tokens(src, delim);
std::string token;
std::vector<std::string> Ret;
while (tokens.GetToken(token))
Ret.push_back(token);
return Ret;
}
std::string Hex(const char *data, size_t len)
{
const char hextable[] = "0123456789abcdef";
std::string rv;
for (size_t i = 0; i < len; ++i)
{
unsigned char c = data[i];
rv += hextable[c >> 4];
rv += hextable[c & 0xF];
}
return rv;
}
static const std::string Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
unsigned b64_decode(const std::string &src, char *target)
{
unsigned state = 0, tarindex = 0;
std::string::const_iterator ch = src.begin(), end = src.end();
for (; ch != end; ++ch)
{
if (isspace(*ch)) /* Skip whitespace anywhere */
continue;
if (*ch == Pad64)
break;
size_t pos = Base64.find(*ch);
if (pos == std::string::npos) /* A non-base64 character */
return 0;
switch (state)
{
case 0:
target[tarindex] = pos << 2;
state = 1;
break;
case 1:
target[tarindex++] |= pos >> 4;
target[tarindex] = (pos & 0x0f) << 4;
state = 2;
break;
case 2:
target[tarindex++] |= pos >> 2;
target[tarindex] = (pos & 0x03) << 6;
state = 3;
break;
case 3:
target[tarindex++] |= pos;
state = 0;
}
}
return tarindex;
}
int main(int argc, char *argv[])
{
std::cout << C_LBLUE << "Anope 1.9.2 -> 1.9.3 database upgrader" << C_NONE << std::endl << std::endl;
std::ifstream in("anope.db.old");
if (!in.is_open())
{
std::cout << C_LBLUE << "Could not open anope.db.old for reading" << C_NONE << std::endl << std::endl;
return 1;
}
std::ofstream out("anope.db");
if (!out.is_open())
{
std::cout << C_LBLUE << "Could not open anope.db for writing" << C_NONE << std::endl << std::endl;
in.close();
return 1;
}
std::string line;
while (getline(in, line))
{
std::string lang, memomax, chancount, bantype;
if (line.substr(0, 2) == "NC")
{
std::vector<std::string> parts = BuildStringVector(line);
std::string password = parts[2];
size_t colon = password.find(':');
if (colon != std::string::npos && password.substr(0, colon) != "plain")
{
std::string hash = password.substr(colon + 1), iv, hashm = password.substr(0, colon);
unsigned len;
if (hashm == "sha256")
{
colon = hash.find(':');
iv = hash.substr(colon + 1);
hash = hash.substr(0, colon);
char *iv_decoded = new char[iv.length() * 3 / 4 + 1];
memset(iv_decoded, 0, iv.length() * 3 / 4 + 1);
len = b64_decode(iv, iv_decoded);
if (len)
iv = Hex(iv_decoded, len);
else
iv.clear();
delete [] iv_decoded;
}
char *hash_decoded = new char[hash.length() * 3 / 4 + 1];
memset(hash_decoded, 0, hash.length() * 3 / 4 + 1);
len = b64_decode(hash, hash_decoded);
if (len)
hash = Hex(hash_decoded, len);
else
hash.clear();
delete [] hash_decoded;
password = hashm + ":";
if (!hash.empty())
password += hash;
if (!iv.empty())
password += ":" + iv;
parts[2] = password;
}
if (parts.size() == 6)
{
chancount = parts[5];
memomax = parts[4];
lang = parts[3];
parts.erase(parts.end());
parts.erase(parts.end());
parts.erase(parts.end());
}
line.clear();
for (unsigned part = 0, end = parts.size(); part < end; ++part)
{
if (part)
line += ' ';
line += parts[part];
}
}
else if (line.substr(0, 2) == "CH")
{
std::vector<std::string> parts = BuildStringVector(line);
memomax = parts[parts.size() - 1];
bantype = parts[parts.size() - 2];
parts.erase(parts.end());
parts.erase(parts.end());
line.clear();
for (unsigned part = 0, end = parts.size(); part < end; ++part)
{
if (part)
line += ' ';
line += parts[part];
}
}
else if (line.substr(0, 5) == "MD MI")
{
while (isdigit(line[6]))
line.erase(line.begin() + 6);
line.erase(line.begin() + 6);
}
out << line << std::endl;
if (!lang.empty())
{
out << "MD LANGUAGE " << lang << std::endl;
lang.clear();
}
if (!memomax.empty())
{
out << "MD MEMOMAX " << memomax << std::endl;
memomax.clear();
}
if (!chancount.empty())
{
out << "MD CHANCOUNT " << chancount << std::endl;
chancount.clear();
}
if (!bantype.empty())
{
out << "MD BANTYPE " << bantype << std::endl;
bantype.clear();
}
}
std::cout << "Upgrade complete!" << std::endl;
in.close();
out.close();
return 0;
}