diff options
author | DukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-06-29 04:47:00 +0000 |
---|---|---|
committer | DukePyrolator <DukePyrolator@5417fbe8-f217-4b02-8779-1006273d7864> | 2009-06-29 04:47:00 +0000 |
commit | 15687a7c9eb882edc151870a4f27ac1e8dfd61ce (patch) | |
tree | a1180b8d0426a2f9471527efcca3bdd55340f433 | |
parent | 712cbb540c41e56115061be296f419e21111bedd (diff) |
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
-rw-r--r-- | include/encrypt.h | 22 | ||||
-rw-r--r-- | include/modules.h | 22 | ||||
-rw-r--r-- | include/pseudo.h | 1 | ||||
-rw-r--r-- | src/core/cs_set.c | 1 | ||||
-rw-r--r-- | src/core/enc_md5.c | 137 | ||||
-rw-r--r-- | src/core/enc_none.c | 84 | ||||
-rw-r--r-- | src/core/enc_old.c | 140 | ||||
-rw-r--r-- | src/core/enc_sha1.c | 151 | ||||
-rw-r--r-- | src/core/ns_register.c | 1 | ||||
-rw-r--r-- | src/core/ns_saset.c | 1 | ||||
-rw-r--r-- | src/core/ns_set.c | 1 | ||||
-rw-r--r-- | src/encrypt.c | 90 |
12 files changed, 299 insertions, 352 deletions
diff --git a/include/encrypt.h b/include/encrypt.h deleted file mode 100644 index 3ed93b6de..000000000 --- a/include/encrypt.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Include file for high-level encryption routines. - * - * (C) 2003-2009 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for furhter details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - * $Id$ - * - */ - -typedef struct encryption_ { - int (*encrypt)(const char *src, int len, char *dest, int size); - int (*encrypt_in_place)(char *buf, int size); - int (*encrypt_check_len)(int passlen, int bufsize); - int (*decrypt)(const char *src, char *dest, int size); - int (*check_password)(const char *plaintext, const char *password); -} Encryption; - diff --git a/include/modules.h b/include/modules.h index 7a1edf716..a75edac56 100644 --- a/include/modules.h +++ b/include/modules.h @@ -47,7 +47,8 @@ enum EventReturn { EVENT_STOP, EVENT_CONTINUE, - EVENT_ALLOW + EVENT_ALLOW, + EVENT_ERROR }; @@ -539,6 +540,15 @@ class CoreExport Module */ virtual void OnBackupDatabase() MARK_DEPRECATED { } + /** Called when anope needs to check passwords against encryption + * see src/encrypt.c for detailed informations + */ + virtual EventReturn OnEncrypt(const char *src,int len,char *dest,int size) { return EVENT_CONTINUE; } + virtual EventReturn OnEncryptInPlace(char *buf, int size) { return EVENT_CONTINUE; } + virtual EventReturn OnEncryptCheckLen(int passlen, int bufsize) { return EVENT_CONTINUE; } + virtual EventReturn OnDecrypt(const char *src, char *dest, int size) { return EVENT_CONTINUE; } + virtual EventReturn OnCheckPassword(const char *plaintext, const char *password) { return EVENT_CONTINUE; } + /** Called on fantasy command * @param command The command * @param u The user using the command @@ -805,17 +815,17 @@ enum Implementation I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, /* Users */ - I_OnUserConnect, I_OnUserNickChange, I_OnUserLogoff, I_OnPreJoinChannel, I_OnJoinChannel, I_OnPrePartChannel, I_OnPartChannel, + I_OnUserConnect, I_OnUserNickChange, I_OnUserLogoff, I_OnPreJoinChannel, I_OnJoinChannel, + I_OnPrePartChannel, I_OnPartChannel, /* OperServ */ I_OnDefconLevel, /* Other */ - I_OnReload, I_OnPreServerConnect, I_OnServerConnect, I_OnPreCommand, I_OnPostCommand, I_OnSaveDatabase, I_OnBackupDatabase, I_OnPreDatabaseExpire, I_OnDatabaseExpire, I_OnPreRestart, I_OnRestart, I_OnPreShutdown, I_OnShutdown, I_OnSignal, I_OnServerQuit, I_OnTopicUpdated, - + I_OnEncrypt, I_OnEncryptInPlace, I_OnEncryptCheckLen, I_OnDecrypt, I_OnCheckPassword, I_END }; @@ -943,9 +953,9 @@ struct MessageHash_ { /*************************************************************************/ /* Module Managment Functions */ -MDE Module *findModule(const char *name); /* Find a module */ +MDE Module *findModule(const char *name); /* Find a module */ -int encryption_module_init(); /* Load the encryption module */ +int encryption_module_init(); /* Load the encryption module */ int protocol_module_init(); /* Load the IRCD Protocol Module up*/ MDE void moduleDisplayHelp(const char *service, User *u); diff --git a/include/pseudo.h b/include/pseudo.h index f63a5b645..65e5e81e7 100644 --- a/include/pseudo.h +++ b/include/pseudo.h @@ -15,6 +15,5 @@ #include "commands.h" #include "language.h" #include "timers.h" -#include "encrypt.h" #include "datafiles.h" #include "slist.h" diff --git a/src/core/cs_set.c b/src/core/cs_set.c index 1f6bdd765..0c7fade4f 100644 --- a/src/core/cs_set.c +++ b/src/core/cs_set.c @@ -14,7 +14,6 @@ /*************************************************************************/ #include "module.h" -#include "encrypt.h" #include "hashcomp.h" class CommandCSSet : public Command diff --git a/src/core/enc_md5.c b/src/core/enc_md5.c index 85bf4445f..d24a0bbad 100644 --- a/src/core/enc_md5.c +++ b/src/core/enc_md5.c @@ -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,24 +335,78 @@ 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); + + } + + + EventReturn OnEncrypt(const char *src, int len, char *dest, int size) + { + 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; } - ~EMD5() + + EventReturn OnEncryptInPlace(char *buf, int size) { - encmodule_encrypt(NULL); - encmodule_encrypt_in_place(NULL); - encmodule_encrypt_check_len(NULL); - encmodule_decrypt(NULL); - encmodule_check_password(NULL); + 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; + } +}; /*************************************************************************/ diff --git a/src/core/enc_none.c b/src/core/enc_none.c index 3c5e4fcdf..faebe3641 100644 --- a/src/core/enc_none.c +++ b/src/core/enc_none.c @@ -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) { - memset(dest,0,size); - strncpy(dest,src,len); - dest[len] = '\0'; - return 0; + EventReturn OnEncryptInPlace(char *buf, int size) + { + return EVENT_STOP; } - 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 OnEncryptCheckLen(int passlen, int bufsize) + { + if(bufsize>=passlen) { + return EVENT_STOP; + } + return EVENT_ALLOW; // return 1 } - 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; -} + EventReturn OnDecrypt(const char *src, char *dest, int size) { + memset(dest,0,size); + strncpy(dest,src,size); + dest[size] = '\0'; + return EVENT_ALLOW; + } -int plain_check_password(const char *plaintext, const char *password) { - if(strcmp(plaintext,password)==0) { - return 1; + EventReturn OnCheckPassword(const char *plaintext, const char *password) { + if(strcmp(plaintext,password)==0) + { + return EVENT_ALLOW; + } + return EVENT_CONTINUE; } - return 0; -} +}; /* EOF */ diff --git a/src/core/enc_old.c b/src/core/enc_old.c index 772b4e1ca..e2169faac 100644 --- a/src/core/enc_old.c +++ b/src/core/enc_old.c @@ -324,99 +324,95 @@ 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) + +class EOld : public Module { + public: + EOld(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetVersion("$Id$"); + this->SetType(ENCRYPTION); - MD5_CTX context; - char digest[33]; - char tmp[33]; - int i; + 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); - 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]); + /* 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) + { - if(debug) { - memset(tmp,0,33); - binary_to_hex((unsigned char *)dest,tmp,16); - alog("enc_old: Converted [%s] to [%s]",src,tmp); - } + MD5_CTX context; + char digest[33]; + char tmp[33]; + int i; - return 0; + 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]); -/* 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); -} + if(debug) + { + memset(tmp,0,33); + binary_to_hex((unsigned char *)dest,tmp,16); + alog("enc_old: Converted [%s] to [%s]",src,tmp); + } -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; -} + 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. */ + /* Shortcut for encrypting a null-terminated string in place. */ + EventReturn OnEncryptInPlace(char *buf, int size) + { + return OnEncrypt(buf, strlen(buf), buf, size); + } -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; -} + EventReturn OnEncryptCheckLen(int passlen, int bufsize) + { + if (bufsize < 16) + fatal("enc_old: old_check_len(): buffer too small (%d)", bufsize); + return EVENT_STOP; + } -int old_decrypt(const char *src, char *dest, int size) -{ - return 0; -} -class EOld : public Module -{ - public: - EOld(const std::string &modname, const std::string &creator) : Module(modname, creator) - { - this->SetAuthor("Anope"); - this->SetVersion("$Id$"); - this->SetType(ENCRYPTION); + /* Compare a plaintext string against an encrypted password. Return 1 if + * they match, 0 if not, and -1 if something went wrong. */ - 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); + 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; } - ~EOld() + EventReturn OnDecrypt(const char *src, char *dest, int size) { - encmodule_encrypt(NULL); - encmodule_encrypt_in_place(NULL); - encmodule_encrypt_check_len(NULL); - encmodule_decrypt(NULL); - encmodule_check_password(NULL); + return EVENT_CONTINUE; // 0 } + }; /*************************************************************************/ diff --git a/src/core/enc_sha1.c b/src/core/enc_sha1.c index 675a3f1b6..143f14aa0 100644 --- a/src/core/enc_sha1.c +++ b/src/core/enc_sha1.c @@ -175,103 +175,100 @@ 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; -} +/*************************************************************************/ +/* Module stuff. */ -int sha1_encrypt_in_place(char *buf, int size) +class ESHA1 : public Module { - 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; -} + public: + ESHA1(const std::string &modname, const std::string &creator) : Module(modname, creator) + { + this->SetAuthor("Anope"); + this->SetVersion("$Id$"); + this->SetType(ENCRYPTION); + 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); -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; -} + EventReturn OnEncrypt(const char *src, int len, char *dest, int size) + { + 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; + } -int sha1_check_password(const char *plaintext, const char *password) -{ - char buf[BUFSIZE]; + EventReturn OnEncryptInPlace(char *buf, int size) + { + char tmp[41]; - if (sha1_encrypt(plaintext, strlen(plaintext), buf, sizeof(buf)) < 0) - return -1; - if (memcmp(buf, password, 20) == 0) - return 1; + memset(tmp,0,41); + if(OnEncrypt(buf, strlen(buf), tmp, size)==EVENT_STOP) + { + memcpy(buf, tmp, size); + } else { + return EVENT_STOP; + } + return EVENT_STOP; + } - return 0; -} -/*************************************************************************/ + EventReturn OnEncryptCheckLen(int passlen, int bufsize) + { + if (bufsize < 20) + fatal("enc_sha1: sha1_check_len(): buffer too small (%d)", bufsize); + return EVENT_STOP; + } -/* Module stuff. */ -class ESHA1 : public Module -{ - public: - ESHA1(const std::string &modname, const std::string &creator) : Module(modname, creator) + EventReturn OnDecrypt(const char *src, char *dest, int size) { - this->SetAuthor("Anope"); - 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); + return EVENT_STOP; } - ~ESHA1() + + EventReturn OnCheckPassword(const char *plaintext, const char *password) { - encmodule_encrypt(NULL); - encmodule_encrypt_in_place(NULL); - encmodule_encrypt_check_len(NULL); - encmodule_decrypt(NULL); - encmodule_check_password(NULL); + 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; } + }; diff --git a/src/core/ns_register.c b/src/core/ns_register.c index a75520cdb..b036a19b8 100644 --- a/src/core/ns_register.c +++ b/src/core/ns_register.c @@ -14,7 +14,6 @@ /*************************************************************************/ #include "module.h" -#include "encrypt.h" NickRequest *makerequest(const char *nick); NickAlias *makenick(const char *nick); diff --git a/src/core/ns_saset.c b/src/core/ns_saset.c index a2b28606c..ac7dac5cc 100644 --- a/src/core/ns_saset.c +++ b/src/core/ns_saset.c @@ -14,7 +14,6 @@ /*************************************************************************/ #include "module.h" -#include "encrypt.h" class CommandNSSASet : public Command { diff --git a/src/core/ns_set.c b/src/core/ns_set.c index c35667f5c..ac48c7bb6 100644 --- a/src/core/ns_set.c +++ b/src/core/ns_set.c @@ -14,7 +14,6 @@ /*************************************************************************/ #include "module.h" -#include "encrypt.h" class CommandNSSet : public Command { diff --git a/src/encrypt.c b/src/encrypt.c index 25d1fe246..8650963e1 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -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 */ |