X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/1347f3d1e04bedd1508589173f577673ee2c5554..a500fb72810060e52d87ad2c2e4691531f0bcc5a:/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp diff --git a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp index 1e9db12d..b1c1203e 100644 --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_admins.cpp @@ -26,23 +26,25 @@ * */ +#include "postgresql_store.h" + +#include "stg/locker.h" +#include "stg/common.h" +#include "stg/admin_conf.h" +#include "stg/blowfish.h" + #include #include #include #include -#include "stg/locker.h" -#include "stg/admin_conf.h" -#include "stg/blowfish.h" -#include "postgresql_store.h" - #define adm_enc_passwd "cjeifY8m3" //----------------------------------------------------------------------------- int POSTGRESQL_STORE::GetAdminsList(std::vector * adminsList) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -71,9 +73,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) PQclear(result); printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): '%s'\n", strError.c_str()); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::GetAdminsList(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -96,9 +98,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::SaveAdmin(const ADMIN_CONF & ac) const +int POSTGRESQL_STORE::SaveAdmin(const STG::AdminConf & ac) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -126,10 +128,10 @@ BLOWFISH_CTX ctx; memset(cryptedPass, 0, ADM_PASSWD_LEN + 1); strncpy(adminPass, ac.password.c_str(), ADM_PASSWD_LEN); -EnDecodeInit(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx); +InitContext(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx); for (int i = 0; i < ADM_PASSWD_LEN / 8; i++) - EncodeString(cryptedPass + 8 * i, adminPass + 8 * i, &ctx); + EncryptBlock(cryptedPass + 8 * i, adminPass + 8 * i, &ctx); cryptedPass[ADM_PASSWD_LEN] = 0; Encode12(encodedPass, cryptedPass, ADM_PASSWD_LEN); @@ -141,9 +143,9 @@ if (EscapeString(pass)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape password'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -151,9 +153,9 @@ if (EscapeString(login)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -177,9 +179,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) PQclear(result); printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): '%s'\n", strError.c_str()); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -195,9 +197,9 @@ return 0; } //----------------------------------------------------------------------------- -int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const +int POSTGRESQL_STORE::RestoreAdmin(STG::AdminConf * ac, const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -228,9 +230,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -250,9 +252,9 @@ if (PQresultStatus(result) != PGRES_TUPLES_OK) printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): '%s'\n", strError.c_str()); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -264,9 +266,9 @@ if (tuples != 1) printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Invalid number of tuples. Wanted 1, actulally %d'\n", tuples); PQclear(result); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::RestoreAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -306,10 +308,10 @@ if (ac->password == "") } Decode21(cryptedPass, ac->password.c_str()); -EnDecodeInit(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx); +InitContext(adm_enc_passwd, sizeof(adm_enc_passwd), &ctx); for (int i = 0; i < ADM_PASSWD_LEN / 8; i++) { - DecodeString(adminPass + 8 * i, cryptedPass + 8 * i, &ctx); + DecryptBlock(adminPass + 8 * i, cryptedPass + 8 * i, &ctx); } ac->password = adminPass; @@ -318,7 +320,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::AddAdmin(const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -345,9 +347,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -369,9 +371,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) PQclear(result); printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): '%s'\n", strError.c_str()); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::AddAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -388,7 +390,7 @@ return 0; //----------------------------------------------------------------------------- int POSTGRESQL_STORE::DelAdmin(const std::string & login) const { -STG_LOCKER lock(&mutex, __FILE__, __LINE__); +STG_LOCKER lock(&mutex); if (PQstatus(connection) != CONNECTION_OK) { @@ -415,9 +417,9 @@ if (EscapeString(elogin)) { printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to escape login'\n"); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n"); + } return -1; } @@ -432,9 +434,9 @@ if (PQresultStatus(result) != PGRES_COMMAND_OK) PQclear(result); printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): '%s'\n", strError.c_str()); if (RollbackTransaction()) - { - printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n"); - } + { + printfd(__FILE__, "POSTGRESQL_STORE::DelAdmin(): 'Failed to rollback transaction'\n"); + } return -1; }