mirror of
https://github.com/anope/anope.git
synced 2026-07-04 17:33:12 +02:00
changed encryption modules to use the new module API
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2342 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "encrypt.h"
|
||||
#include "hashcomp.h"
|
||||
|
||||
class CommandCSSet : public Command
|
||||
|
||||
+68
-71
@@ -317,67 +317,10 @@ void Decode (UINT4 *output, unsigned char *input, unsigned int len)
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
/* Our own high-level routines. See encrypt.h for documentation. */
|
||||
/* Our own high-level routines. */
|
||||
|
||||
#define XTOI(c) ((c)>9 ? (c)-'A'+10 : (c)-'0')
|
||||
|
||||
int md5_encrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
MD5_CTX context;
|
||||
char tmp[33];
|
||||
|
||||
if (size < 16)
|
||||
return -1;
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, (unsigned char *)src, len);
|
||||
MD5Final((unsigned char *)dest, &context);
|
||||
|
||||
if(debug) {
|
||||
memset(tmp,0,33);
|
||||
binary_to_hex((unsigned char *)dest,tmp,16);
|
||||
/* Dont log source if we were encrypting in place :) */
|
||||
if (memcmp(src, dest, 16) != 0) {
|
||||
alog("enc_md5: hashed from [%s] to [%s]",src,tmp);
|
||||
} else {
|
||||
alog("enc_md5: hashed password to [%s]",tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int md5_encrypt_in_place(char *buf, int size)
|
||||
{
|
||||
return md5_encrypt(buf, strlen(buf), buf, size);
|
||||
}
|
||||
|
||||
|
||||
int md5_encrypt_check_len(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 16)
|
||||
fatal("enc_md5: md5_check_len(): buffer too small (%d)", bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int md5_decrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int md5_check_password(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if (md5_encrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) < 0)
|
||||
return -1;
|
||||
if (memcmp(buf, password, 16) == 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -392,25 +335,79 @@ class EMD5 : public Module
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(ENCRYPTION);
|
||||
|
||||
encmodule_encrypt(md5_encrypt);
|
||||
encmodule_encrypt_in_place(md5_encrypt_in_place);
|
||||
encmodule_encrypt_check_len(md5_encrypt_check_len);
|
||||
encmodule_decrypt(md5_decrypt);
|
||||
encmodule_check_password(md5_check_password);
|
||||
|
||||
ModuleManager::Attach(I_OnEncrypt, this);
|
||||
ModuleManager::Attach(I_OnEncryptInPlace, this);
|
||||
ModuleManager::Attach(I_OnEncryptCheckLen, this);
|
||||
ModuleManager::Attach(I_OnDecrypt, this);
|
||||
ModuleManager::Attach(I_OnCheckPassword, this);
|
||||
|
||||
}
|
||||
|
||||
~EMD5()
|
||||
|
||||
EventReturn OnEncrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
encmodule_encrypt(NULL);
|
||||
encmodule_encrypt_in_place(NULL);
|
||||
encmodule_encrypt_check_len(NULL);
|
||||
encmodule_decrypt(NULL);
|
||||
encmodule_check_password(NULL);
|
||||
MD5_CTX context;
|
||||
char tmp[33];
|
||||
|
||||
if (size < 16)
|
||||
return EVENT_ERROR;
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, (unsigned char *)src, len);
|
||||
MD5Final((unsigned char *)dest, &context);
|
||||
|
||||
if(debug)
|
||||
{
|
||||
memset(tmp,0,33);
|
||||
binary_to_hex((unsigned char *)dest,tmp,16);
|
||||
/* Dont log source if we were encrypting in place :) */
|
||||
if (memcmp(src, dest, 16) != 0)
|
||||
{
|
||||
alog("enc_md5: hashed from [%s] to [%s]",src,tmp);
|
||||
} else {
|
||||
alog("enc_md5: hashed password to [%s]",tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnEncryptInPlace(char *buf, int size)
|
||||
{
|
||||
return OnEncrypt(buf, strlen(buf), buf, size);
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnEncryptCheckLen(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 16)
|
||||
fatal("enc_md5: md5_check_len(): buffer too small (%d)", bufsize);
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnDecrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnCheckPassword(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if (OnEncrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) == EVENT_ERROR)
|
||||
return EVENT_ERROR;
|
||||
if (memcmp(buf, password, 16) == 0)
|
||||
{
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
||||
+39
-49
@@ -1,4 +1,4 @@
|
||||
/* Module for encryption using MD5.
|
||||
/* Module for plain text encryption.
|
||||
*
|
||||
* (C) 2003-2009 Anope Team
|
||||
* Contact us at team@anope.org
|
||||
@@ -9,12 +9,6 @@
|
||||
|
||||
#include "module.h"
|
||||
|
||||
int plain_encrypt(const char *src,int len,char *dest,int size);
|
||||
int plain_encrypt_in_place(char *buf, int size);
|
||||
int plain_encrypt_check_len(int passlen, int bufsize);
|
||||
int plain_decrypt(const char *src, char *dest, int size);
|
||||
int plain_check_password(const char *plaintext, const char *password);
|
||||
|
||||
class ENone : public Module
|
||||
{
|
||||
public:
|
||||
@@ -24,58 +18,54 @@ class ENone : public Module
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(ENCRYPTION);
|
||||
|
||||
encmodule_encrypt(plain_encrypt);
|
||||
encmodule_encrypt_in_place(plain_encrypt_in_place);
|
||||
encmodule_encrypt_check_len(plain_encrypt_check_len);
|
||||
encmodule_decrypt(plain_decrypt);
|
||||
encmodule_check_password(plain_check_password);
|
||||
ModuleManager::Attach(I_OnEncrypt, this);
|
||||
ModuleManager::Attach(I_OnEncryptInPlace, this);
|
||||
ModuleManager::Attach(I_OnEncryptCheckLen, this);
|
||||
ModuleManager::Attach(I_OnDecrypt, this);
|
||||
ModuleManager::Attach(I_OnCheckPassword, this);
|
||||
}
|
||||
|
||||
~ENone()
|
||||
EventReturn OnEncrypt(const char *src,int len,char *dest,int size)
|
||||
{
|
||||
encmodule_encrypt(NULL);
|
||||
encmodule_encrypt_in_place(NULL);
|
||||
encmodule_encrypt_check_len(NULL);
|
||||
encmodule_decrypt(NULL);
|
||||
encmodule_check_password(NULL);
|
||||
if(size>=len)
|
||||
{
|
||||
memset(dest,0,size);
|
||||
strncpy(dest,src,len);
|
||||
dest[len] = '\0';
|
||||
return EVENT_STOP;
|
||||
}
|
||||
return EVENT_ERROR;
|
||||
}
|
||||
};
|
||||
|
||||
int plain_encrypt(const char *src,int len,char *dest,int size) {
|
||||
if(size>=len) {
|
||||
EventReturn OnEncryptInPlace(char *buf, int size)
|
||||
{
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
EventReturn OnEncryptCheckLen(int passlen, int bufsize)
|
||||
{
|
||||
if(bufsize>=passlen) {
|
||||
return EVENT_STOP;
|
||||
}
|
||||
return EVENT_ALLOW; // return 1
|
||||
}
|
||||
|
||||
EventReturn OnDecrypt(const char *src, char *dest, int size) {
|
||||
memset(dest,0,size);
|
||||
strncpy(dest,src,len);
|
||||
dest[len] = '\0';
|
||||
return 0;
|
||||
strncpy(dest,src,size);
|
||||
dest[size] = '\0';
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int plain_encrypt_in_place(char *buf, int size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int plain_encrypt_check_len(int passlen, int bufsize) {
|
||||
if(bufsize>=passlen) {
|
||||
return 0;
|
||||
EventReturn OnCheckPassword(const char *plaintext, const char *password) {
|
||||
if(strcmp(plaintext,password)==0)
|
||||
{
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
int plain_decrypt(const char *src, char *dest, int size) {
|
||||
memset(dest,0,size);
|
||||
strncpy(dest,src,size);
|
||||
dest[size] = '\0';
|
||||
return 1;
|
||||
}
|
||||
|
||||
int plain_check_password(const char *plaintext, const char *password) {
|
||||
if(strcmp(plaintext,password)==0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
};
|
||||
/* EOF */
|
||||
|
||||
|
||||
|
||||
+75
-79
@@ -324,74 +324,6 @@ static void Decode(UINT4 *output, unsigned char *input, unsigned int len)
|
||||
#define XTOI(c) ((c)>9 ? (c)-'A'+10 : (c)-'0')
|
||||
|
||||
|
||||
/* Encrypt `src' of length `len' and store the result in `dest'. If the
|
||||
* resulting string would be longer than `size', return -1 and leave `dest'
|
||||
* unchanged; else return 0.
|
||||
*/
|
||||
int old_encrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
|
||||
MD5_CTX context;
|
||||
char digest[33];
|
||||
char tmp[33];
|
||||
int i;
|
||||
|
||||
if (size < 16)
|
||||
return -1;
|
||||
|
||||
memset(&context, 0, sizeof(context));
|
||||
memset(&digest, 0, sizeof(digest));
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, (unsigned char *)src, len);
|
||||
MD5Final((unsigned char *)digest, &context);
|
||||
for (i = 0; i < 32; i += 2)
|
||||
dest[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);
|
||||
|
||||
if(debug) {
|
||||
memset(tmp,0,33);
|
||||
binary_to_hex((unsigned char *)dest,tmp,16);
|
||||
alog("enc_old: Converted [%s] to [%s]",src,tmp);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Shortcut for encrypting a null-terminated string in place. */
|
||||
int old_encrypt_in_place(char *buf, int size)
|
||||
{
|
||||
return old_encrypt(buf, strlen(buf), buf, size);
|
||||
}
|
||||
|
||||
int old_encrypt_check_len(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 16)
|
||||
fatal("enc_old: old_check_len(): buffer too small (%d)", bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Compare a plaintext string against an encrypted password. Return 1 if
|
||||
* they match, 0 if not, and -1 if something went wrong. */
|
||||
|
||||
int old_check_password(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if (old_encrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) < 0)
|
||||
return -1;
|
||||
if (memcmp(buf, password, 16) == 0)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int old_decrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
class EOld : public Module
|
||||
{
|
||||
@@ -402,21 +334,85 @@ class EOld : public Module
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(ENCRYPTION);
|
||||
|
||||
encmodule_encrypt(old_encrypt);
|
||||
encmodule_encrypt_in_place(old_encrypt_in_place);
|
||||
encmodule_encrypt_check_len(old_encrypt_check_len);
|
||||
encmodule_decrypt(old_decrypt);
|
||||
encmodule_check_password(old_check_password);
|
||||
ModuleManager::Attach(I_OnEncrypt, this);
|
||||
ModuleManager::Attach(I_OnEncryptInPlace, this);
|
||||
ModuleManager::Attach(I_OnEncryptCheckLen, this);
|
||||
ModuleManager::Attach(I_OnDecrypt, this);
|
||||
ModuleManager::Attach(I_OnCheckPassword, this);
|
||||
|
||||
}
|
||||
|
||||
~EOld()
|
||||
|
||||
/* Encrypt `src' of length `len' and store the result in `dest'. If the
|
||||
* resulting string would be longer than `size', return -1 and leave `dest'
|
||||
* unchanged; else return 0.
|
||||
*/
|
||||
EventReturn OnEncrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
encmodule_encrypt(NULL);
|
||||
encmodule_encrypt_in_place(NULL);
|
||||
encmodule_encrypt_check_len(NULL);
|
||||
encmodule_decrypt(NULL);
|
||||
encmodule_check_password(NULL);
|
||||
|
||||
MD5_CTX context;
|
||||
char digest[33];
|
||||
char tmp[33];
|
||||
int i;
|
||||
|
||||
if (size < 16)
|
||||
return EVENT_ERROR;
|
||||
|
||||
memset(&context, 0, sizeof(context));
|
||||
memset(&digest, 0, sizeof(digest));
|
||||
|
||||
MD5Init(&context);
|
||||
MD5Update(&context, (unsigned char *)src, len);
|
||||
MD5Final((unsigned char *)digest, &context);
|
||||
for (i = 0; i < 32; i += 2)
|
||||
dest[i / 2] = XTOI(digest[i]) << 4 | XTOI(digest[i + 1]);
|
||||
|
||||
if(debug)
|
||||
{
|
||||
memset(tmp,0,33);
|
||||
binary_to_hex((unsigned char *)dest,tmp,16);
|
||||
alog("enc_old: Converted [%s] to [%s]",src,tmp);
|
||||
}
|
||||
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
/* Shortcut for encrypting a null-terminated string in place. */
|
||||
EventReturn OnEncryptInPlace(char *buf, int size)
|
||||
{
|
||||
return OnEncrypt(buf, strlen(buf), buf, size);
|
||||
}
|
||||
|
||||
EventReturn OnEncryptCheckLen(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 16)
|
||||
fatal("enc_old: old_check_len(): buffer too small (%d)", bufsize);
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
/* Compare a plaintext string against an encrypted password. Return 1 if
|
||||
* they match, 0 if not, and -1 if something went wrong. */
|
||||
|
||||
EventReturn OnCheckPassword(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if (OnEncrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) == EVENT_ERROR)
|
||||
return EVENT_ERROR;
|
||||
if (memcmp(buf, password, 16) == 0)
|
||||
{
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
EventReturn OnDecrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return EVENT_CONTINUE; // 0
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
+76
-79
@@ -175,74 +175,6 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
int sha1_encrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
SHA1_CTX context;
|
||||
unsigned char tmp[41];
|
||||
|
||||
if (size < 20)
|
||||
return -1;
|
||||
|
||||
memset(dest,0,size);
|
||||
|
||||
SHA1Init(&context);
|
||||
SHA1Update(&context, (unsigned char *)src, len);
|
||||
SHA1Final((unsigned char *)dest, &context);
|
||||
|
||||
if(debug) {
|
||||
memset(tmp,0,41);
|
||||
binary_to_hex((unsigned char *)dest,(char *)tmp,20);
|
||||
/* Dont log source if we were encrypting in place :) */
|
||||
if (memcmp(src, dest, 20) != 0) {
|
||||
alog("enc_sha1: hashed from [%s] to [%s]",src,tmp);
|
||||
} else {
|
||||
alog("enc_sha1: hashed password to [%s]",tmp);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sha1_encrypt_in_place(char *buf, int size)
|
||||
{
|
||||
char tmp[41];
|
||||
|
||||
memset(tmp,0,41);
|
||||
if(sha1_encrypt(buf, strlen(buf), tmp, size)==0) {
|
||||
memcpy(buf, tmp, size);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sha1_encrypt_check_len(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 20)
|
||||
fatal("enc_sha1: sha1_check_len(): buffer too small (%d)", bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sha1_decrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int sha1_check_password(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
|
||||
if (sha1_encrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) < 0)
|
||||
return -1;
|
||||
if (memcmp(buf, password, 20) == 0)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
@@ -257,21 +189,86 @@ class ESHA1 : public Module
|
||||
this->SetVersion("$Id$");
|
||||
this->SetType(ENCRYPTION);
|
||||
|
||||
encmodule_encrypt(sha1_encrypt);
|
||||
encmodule_encrypt_in_place(sha1_encrypt_in_place);
|
||||
encmodule_encrypt_check_len(sha1_encrypt_check_len);
|
||||
encmodule_decrypt(sha1_decrypt);
|
||||
encmodule_check_password(sha1_check_password);
|
||||
ModuleManager::Attach(I_OnEncrypt, this);
|
||||
ModuleManager::Attach(I_OnEncryptInPlace, this);
|
||||
ModuleManager::Attach(I_OnEncryptCheckLen, this);
|
||||
ModuleManager::Attach(I_OnDecrypt, this);
|
||||
ModuleManager::Attach(I_OnCheckPassword, this);
|
||||
|
||||
}
|
||||
|
||||
~ESHA1()
|
||||
|
||||
EventReturn OnEncrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
encmodule_encrypt(NULL);
|
||||
encmodule_encrypt_in_place(NULL);
|
||||
encmodule_encrypt_check_len(NULL);
|
||||
encmodule_decrypt(NULL);
|
||||
encmodule_check_password(NULL);
|
||||
SHA1_CTX context;
|
||||
unsigned char tmp[41];
|
||||
|
||||
if (size < 20)
|
||||
return EVENT_ALLOW;
|
||||
|
||||
memset(dest,0,size);
|
||||
|
||||
SHA1Init(&context);
|
||||
SHA1Update(&context, (unsigned char *)src, len);
|
||||
SHA1Final((unsigned char *)dest, &context);
|
||||
|
||||
if(debug)
|
||||
{
|
||||
memset(tmp,0,41);
|
||||
binary_to_hex((unsigned char *)dest,(char *)tmp,20);
|
||||
/* Dont log source if we were encrypting in place :) */
|
||||
if (memcmp(src, dest, 20) != 0)
|
||||
{
|
||||
alog("enc_sha1: hashed from [%s] to [%s]",src,tmp);
|
||||
} else {
|
||||
alog("enc_sha1: hashed password to [%s]",tmp);
|
||||
}
|
||||
}
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnEncryptInPlace(char *buf, int size)
|
||||
{
|
||||
char tmp[41];
|
||||
|
||||
memset(tmp,0,41);
|
||||
if(OnEncrypt(buf, strlen(buf), tmp, size)==EVENT_STOP)
|
||||
{
|
||||
memcpy(buf, tmp, size);
|
||||
} else {
|
||||
return EVENT_STOP;
|
||||
}
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnEncryptCheckLen(int passlen, int bufsize)
|
||||
{
|
||||
if (bufsize < 20)
|
||||
fatal("enc_sha1: sha1_check_len(): buffer too small (%d)", bufsize);
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnDecrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
return EVENT_STOP;
|
||||
}
|
||||
|
||||
|
||||
EventReturn OnCheckPassword(const char *plaintext, const char *password)
|
||||
{
|
||||
char buf[BUFSIZE];
|
||||
if (OnEncrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) == EVENT_ALLOW)
|
||||
return EVENT_STOP;
|
||||
if (memcmp(buf, password, 20) == 0)
|
||||
{
|
||||
return EVENT_ALLOW;
|
||||
}
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "encrypt.h"
|
||||
|
||||
NickRequest *makerequest(const char *nick);
|
||||
NickAlias *makenick(const char *nick);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "encrypt.h"
|
||||
|
||||
class CommandNSSASet : public Command
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "encrypt.h"
|
||||
|
||||
class CommandNSSet : public Command
|
||||
{
|
||||
|
||||
+37
-53
@@ -13,41 +13,9 @@
|
||||
*/
|
||||
|
||||
#include "services.h"
|
||||
#include "encrypt.h"
|
||||
|
||||
Encryption encryption;
|
||||
#include "modules.h"
|
||||
|
||||
/******************************************************************************/
|
||||
void encmodule_encrypt(int (*func)
|
||||
(const char *src, int len, char *dest, int size))
|
||||
{
|
||||
encryption.encrypt = func;
|
||||
}
|
||||
|
||||
void encmodule_encrypt_in_place(int (*func) (char *buf, int size))
|
||||
{
|
||||
encryption.encrypt_in_place = func;
|
||||
}
|
||||
|
||||
void encmodule_encrypt_check_len(int (*func) (int passlen, int bufsize))
|
||||
{
|
||||
encryption.encrypt_check_len = func;
|
||||
}
|
||||
|
||||
void encmodule_decrypt(int (*func) (const char *src, char *dest, int size))
|
||||
{
|
||||
encryption.decrypt = func;
|
||||
}
|
||||
|
||||
void encmodule_check_password(int (*func)
|
||||
(const char *plaintext,
|
||||
const char *password))
|
||||
{
|
||||
encryption.check_password = func;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Encrypt string `src' of length `len', placing the result in buffer
|
||||
@@ -55,10 +23,13 @@ void encmodule_check_password(int (*func)
|
||||
**/
|
||||
int enc_encrypt(const char *src, int len, char *dest, int size)
|
||||
{
|
||||
if (encryption.encrypt) {
|
||||
return encryption.encrypt(src, len, dest, size);
|
||||
}
|
||||
return -1;
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, len, dest, size));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
return 1;
|
||||
if (MOD_RESULT == EVENT_ERROR)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,10 +39,14 @@ int enc_encrypt(const char *src, int len, char *dest, int size)
|
||||
**/
|
||||
int enc_encrypt_in_place(char *buf, int size)
|
||||
{
|
||||
if (encryption.encrypt_in_place) {
|
||||
return encryption.encrypt_in_place(buf, size);
|
||||
}
|
||||
return -1;
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnEncryptInPlace, OnEncryptInPlace(buf, size));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
return 1;
|
||||
if (MOD_RESULT == EVENT_ERROR)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,10 +59,13 @@ int enc_encrypt_in_place(char *buf, int size)
|
||||
**/
|
||||
int enc_encrypt_check_len(int passlen, int bufsize)
|
||||
{
|
||||
if (encryption.encrypt_check_len) {
|
||||
return encryption.encrypt_check_len(passlen, bufsize);
|
||||
}
|
||||
return -1;
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnEncryptCheckLen, OnEncryptCheckLen(passlen, bufsize));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
return 1;
|
||||
if (MOD_RESULT == EVENT_ERROR)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,10 +76,13 @@ int enc_encrypt_check_len(int passlen, int bufsize)
|
||||
**/
|
||||
int enc_decrypt(const char *src, char *dest, int size)
|
||||
{
|
||||
if (encryption.decrypt) {
|
||||
return encryption.decrypt(src, dest, size);
|
||||
}
|
||||
return -1;
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnDecrypt, OnDecrypt(src, dest, size));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
return 1;
|
||||
if (MOD_RESULT == EVENT_ERROR)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,10 +94,13 @@ int enc_decrypt(const char *src, char *dest, int size)
|
||||
**/
|
||||
int enc_check_password(const char *plaintext, const char *password)
|
||||
{
|
||||
if (encryption.check_password) {
|
||||
return encryption.check_password(plaintext, password);
|
||||
}
|
||||
return -1;
|
||||
EventReturn MOD_RESULT;
|
||||
FOREACH_RESULT(I_OnCheckPassword, OnCheckPassword(plaintext, password));
|
||||
if (MOD_RESULT == EVENT_ALLOW)
|
||||
return 1;
|
||||
if (MOD_RESULT == EVENT_ERROR)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
||||
Reference in New Issue
Block a user