*/
/*
- * Author : Maxim Mamontov <faust@stargazer.dp.ua>
+ * Author : Maksym Mamontov <stg@madf.info>
*/
/*
* Administrators manipulation methods
*
- * $Revision: 1.2 $
- * $Date: 2009/06/09 12:32:39 $
+ * $Revision: 1.3 $
+ * $Date: 2010/11/08 10:10:24 $
*
*/
#include <libpq-fe.h>
+#include "stg/locker.h"
+#include "stg/admin_conf.h"
+#include "stg/blowfish.h"
#include "postgresql_store.h"
-#include "stg_locker.h"
-#include "admin_conf.h"
-#include "blowfish.h"
#define adm_enc_passwd "cjeifY8m3"
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::GetAdminsList(std::vector<std::string> * adminsList) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (PQstatus(connection) != CONNECTION_OK)
{
//-----------------------------------------------------------------------------
int POSTGRESQL_STORE::SaveAdmin(const ADMIN_CONF & ac) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (PQstatus(connection) != CONNECTION_OK)
{
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);
-std::string password = encodedPass;
+std::string pass = encodedPass;
std::string login = ac.login;
-if (EscapeString(password))
+if (EscapeString(pass))
{
printfd(__FILE__, "POSTGRESQL_STORE::SaveAdmin(): 'Failed to escape password'\n");
if (RollbackTransaction())
std::stringstream query;
query << "UPDATE tb_admins SET "
- << "passwd = '" << password << "', "
+ << "passwd = '" << pass << "', "
<< "chg_conf = " << ac.priv.userConf << ", "
<< "chg_password = " << ac.priv.userPasswd << ", "
<< "chg_stat = " << ac.priv.userStat << ", "
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const string & login) const
+int POSTGRESQL_STORE::RestoreAdmin(ADMIN_CONF * ac, const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (PQstatus(connection) != CONNECTION_OK)
{
return -1;
}
-std::stringstream query;
+std::ostringstream query;
query << "SELECT login, passwd, \
chg_conf, chg_password, chg_stat, \
chg_cash, usr_add_del, chg_tariff, \
}
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;
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::AddAdmin(const string & login) const
+int POSTGRESQL_STORE::AddAdmin(const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (PQstatus(connection) != CONNECTION_OK)
{
return -1;
}
-std::stringstream query;
+std::ostringstream query;
query << "INSERT INTO tb_admins \
(login, passwd, \
chg_conf, chg_password, chg_stat, \
return 0;
}
//-----------------------------------------------------------------------------
-int POSTGRESQL_STORE::DelAdmin(const string & login) const
+int POSTGRESQL_STORE::DelAdmin(const std::string & login) const
{
-STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+STG_LOCKER lock(&mutex);
if (PQstatus(connection) != CONNECTION_OK)
{
return -1;
}
-std::stringstream query;
+std::ostringstream query;
query << "DELETE FROM tb_admins WHERE login = '" << elogin << "'";
result = PQexec(connection, query.str().c_str());