From: Maxim Mamontov Date: Sat, 19 Mar 2011 15:52:01 +0000 (+0200) Subject: Fix work with admins X-Git-Tag: 2.407-rc3~145 X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/e767204dbf56ac466489c142f0acdaebd5d0b935 Fix work with admins --- diff --git a/include/admins.h b/include/admins.h index 48c02252..169f1a26 100644 --- a/include/admins.h +++ b/include/admins.h @@ -28,16 +28,16 @@ class ADMINS { public: - virtual int Add(const std::string & login, const ADMIN & admin) = 0; - virtual int Del(const std::string & login, const ADMIN & admin) = 0; - virtual int Change(const ADMIN_CONF & ac, const ADMIN & admin) = 0; + virtual int Add(const std::string & login, const ADMIN * admin) = 0; + virtual int Del(const std::string & login, const ADMIN * admin) = 0; + virtual int Change(const ADMIN_CONF & ac, const ADMIN * admin) = 0; virtual const ADMIN * GetSysAdmin() const = 0; virtual const ADMIN * GetNoAdmin() const = 0; virtual bool FindAdmin(const std::string & l, ADMIN ** admin) = 0; virtual bool AdminExists(const std::string & login) const = 0; virtual bool AdminCorrect(const std::string & login, const std::string & password, - ADMIN * admin) const = 0; + ADMIN ** admin) = 0; virtual const std::string & GetStrError() const = 0; virtual int OpenSearch() const = 0; diff --git a/include/tariffs.h b/include/tariffs.h index dfc47b48..1f91948f 100644 --- a/include/tariffs.h +++ b/include/tariffs.h @@ -34,9 +34,9 @@ public: virtual const TARIFF * FindByName(const std::string & name) const = 0; virtual const TARIFF * GetNoTariff() const = 0; virtual int GetTariffsNum() const = 0; - virtual int Del(const std::string & name, const ADMIN & admin) = 0; - virtual int Add(const std::string & name, const ADMIN & admin) = 0; - virtual int Chg(const TARIFF_DATA & td, const ADMIN & admin) = 0; + virtual int Del(const std::string & name, const ADMIN * admin) = 0; + virtual int Add(const std::string & name, const ADMIN * admin) = 0; + virtual int Chg(const TARIFF_DATA & td, const ADMIN * admin) = 0; virtual void GetTariffsData(std::list * tdl) = 0; diff --git a/include/users.h b/include/users.h index b9454ce4..50f5ffe2 100644 --- a/include/users.h +++ b/include/users.h @@ -40,8 +40,8 @@ public: virtual void AddNotifierUserDel(NOTIFIER_BASE * notifier) = 0; virtual void DelNotifierUserDel(NOTIFIER_BASE * notifier) = 0; - virtual int Add(const std::string & login, const ADMIN & admin) = 0; - virtual void Del(const std::string & login, const ADMIN & admin) = 0; + virtual int Add(const std::string & login, const ADMIN * admin) = 0; + virtual void Del(const std::string & login, const ADMIN * admin) = 0; virtual int ReadUsers() = 0; virtual int GetUserNum() const = 0; diff --git a/projects/stargazer/admins_impl.cpp b/projects/stargazer/admins_impl.cpp index 99a8ff48..38d2cec0 100644 --- a/projects/stargazer/admins_impl.cpp +++ b/projects/stargazer/admins_impl.cpp @@ -54,14 +54,14 @@ pthread_mutex_init(&mutex, NULL); ReadAdmins(); } //----------------------------------------------------------------------------- -int ADMINS_IMPL::Add(const string & login, const ADMIN & admin) +int ADMINS_IMPL::Add(const string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin.GetLogStr() + " Add administrator \'" + login + "\'. Access denied."; + string s = admin->GetLogStr() + " Add administrator \'" + login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -73,7 +73,7 @@ admin_iter ai(find(data.begin(), data.end(), adm)); if (ai != data.end()) { strError = "Administrator \'" + login + "\' cannot not be added. Administrator alredy exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -83,25 +83,25 @@ data.push_back(adm); if (store->AddAdmin(login) == 0) { WriteServLog("%s Administrator \'%s\' added.", - admin.GetLogStr().c_str(), login.c_str()); + admin->GetLogStr().c_str(), login.c_str()); return 0; } strError = "Administrator \'" + login + "\' was not added. Error: " + store->GetStrError(); -WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); +WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } //----------------------------------------------------------------------------- -int ADMINS_IMPL::Del(const string & login, const ADMIN & admin) +int ADMINS_IMPL::Del(const string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); ADMIN_IMPL adm(0, login, ""); -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin.GetLogStr() + " Delete administrator \'" + login + "\'. Access denied."; + string s = admin->GetLogStr() + " Delete administrator \'" + login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -112,7 +112,7 @@ admin_iter ai(find(data.begin(), data.end(), adm)); if (ai == data.end()) { strError = "Administrator \'" + login + "\' cannot be deleted. Administrator does not exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -129,23 +129,23 @@ data.remove(*ai); if (store->DelAdmin(login) < 0) { strError = "Administrator \'" + login + "\' was not deleted. Error: " + store->GetStrError(); - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } -WriteServLog("%s Administrator \'%s\' deleted.", admin.GetLogStr().c_str(), login.c_str()); +WriteServLog("%s Administrator \'%s\' deleted.", admin->GetLogStr().c_str(), login.c_str()); return 0; } //----------------------------------------------------------------------------- -int ADMINS_IMPL::Change(const ADMIN_CONF & ac, const ADMIN & admin) +int ADMINS_IMPL::Change(const ADMIN_CONF & ac, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->adminChg) { - string s = admin.GetLogStr() + " Change administrator \'" + ac.login + "\'. Access denied."; + string s = admin->GetLogStr() + " Change administrator \'" + ac.login + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); return -1; @@ -157,7 +157,7 @@ admin_iter ai(find(data.begin(), data.end(), adm)); if (ai == data.end()) { strError = "Administrator \'" + ac.login + "\' cannot be changed " + ". Administrator does not exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -170,7 +170,7 @@ if (store->SaveAdmin(ac)) } WriteServLog("%s Administrator \'%s\' changed.", - admin.GetLogStr().c_str(), ac.login.c_str()); + admin->GetLogStr().c_str(), ac.login.c_str()); return 0; } @@ -253,7 +253,7 @@ if (ai != data.end()) return false; } //----------------------------------------------------------------------------- -bool ADMINS_IMPL::AdminCorrect(const string & login, const std::string & password, ADMIN * admin) const +bool ADMINS_IMPL::AdminCorrect(const string & login, const std::string & password, ADMIN ** admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); if (data.empty()) @@ -263,7 +263,7 @@ if (data.empty()) } ADMIN_IMPL adm(0, login, ""); -const_admin_iter ai(find(data.begin(), data.end(), adm)); +admin_iter ai(find(data.begin(), data.end(), adm)); if (ai == data.end()) { @@ -275,7 +275,7 @@ if (ai->GetPassword() != password) return false; } -*admin = *ai; +*admin = &(*ai); return true; } diff --git a/projects/stargazer/admins_impl.h b/projects/stargazer/admins_impl.h index c40f2659..b481e25f 100644 --- a/projects/stargazer/admins_impl.h +++ b/projects/stargazer/admins_impl.h @@ -48,9 +48,9 @@ public: ADMINS_IMPL(STORE * st); virtual ~ADMINS_IMPL() {} - int Add(const string & login, const ADMIN & admin); - int Del(const string & login, const ADMIN & admin); - int Change(const ADMIN_CONF & ac, const ADMIN & admin); + int Add(const string & login, const ADMIN * admin); + int Del(const string & login, const ADMIN * admin); + int Change(const ADMIN_CONF & ac, const ADMIN * admin); void PrintAdmins() const; const ADMIN * GetSysAdmin() const { return &stg; } const ADMIN * GetNoAdmin() const { return &noAdmin; } @@ -58,7 +58,7 @@ public: bool AdminExists(const std::string & login) const; bool AdminCorrect(const std::string & login, const std::string & password, - ADMIN * admin) const; + ADMIN ** admin); const std::string & GetStrError() const { return strError; } int OpenSearch() const; diff --git a/projects/stargazer/main.cpp b/projects/stargazer/main.cpp index 8eacc9ac..6a8c61f5 100644 --- a/projects/stargazer/main.cpp +++ b/projects/stargazer/main.cpp @@ -552,7 +552,7 @@ WriteServLog("Storage plugin: %s. Loading successfull.", dataStore->GetVersion() tariffs = new TARIFFS_IMPL(dataStore); admins = new ADMINS_IMPL(dataStore); -users = new USERS_IMPL(settings, dataStore, tariffs, *admins->GetSysAdmin()); +users = new USERS_IMPL(settings, dataStore, tariffs, admins->GetSysAdmin()); traffCnt = new TRAFFCOUNTER(users, tariffs, settings->GetRulesFileName()); traffCnt->SetMonitorDir(settings->GetMonitorDir()); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp index 05c16b10..b90cb2b6 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser.cpp @@ -712,7 +712,7 @@ int PARSER_ADD_USER::CheckUserData() USER_PTR u; if (users->FindByName(login, &u)) { - return users->Add(login, *currAdmin); + return users->Add(login, currAdmin); } return -1; } @@ -1019,49 +1019,49 @@ if (users->FindByName(login, &u)) } if (!ucr->ips.res_empty()) - if (!u->GetProperty().ips.Set(ucr->ips.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store)) res = -1; if (!ucr->address.res_empty()) - if (!u->GetProperty().address.Set(ucr->address.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().address.Set(ucr->address.const_data(), currAdmin, login, store)) res = -1; if (!ucr->alwaysOnline.res_empty()) if (!u->GetProperty().alwaysOnline.Set(ucr->alwaysOnline.const_data(), - *currAdmin, login, store)) + currAdmin, login, store)) res = -1; if (!ucr->creditExpire.res_empty()) if (!u->GetProperty().creditExpire.Set(ucr->creditExpire.const_data(), - *currAdmin, login, store)) + currAdmin, login, store)) res = -1; if (!ucr->credit.res_empty()) - if (!u->GetProperty().credit.Set(ucr->credit.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().credit.Set(ucr->credit.const_data(), currAdmin, login, store)) res = -1; if (!usr->freeMb.res_empty()) - if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().freeMb.Set(usr->freeMb.const_data(), currAdmin, login, store)) res = -1; if (!ucr->disabled.res_empty()) - if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().disabled.Set(ucr->disabled.const_data(), currAdmin, login, store)) res = -1; if (!ucr->disabledDetailStat.res_empty()) - if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().disabledDetailStat.Set(ucr->disabledDetailStat.const_data(), currAdmin, login, store)) res = -1; if (!ucr->email.res_empty()) - if (!u->GetProperty().email.Set(ucr->email.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().email.Set(ucr->email.const_data(), currAdmin, login, store)) res = -1; if (!ucr->group.res_empty()) - if (!u->GetProperty().group.Set(ucr->group.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().group.Set(ucr->group.const_data(), currAdmin, login, store)) res = -1; if (!ucr->note.res_empty()) - if (!u->GetProperty().note.Set(ucr->note.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().note.Set(ucr->note.const_data(), currAdmin, login, store)) res = -1; vector *> userdata; @@ -1080,25 +1080,25 @@ for (int i = 0; i < (int)userdata.size(); i++) { if (!ucr->userdata[i].res_empty()) { - if(!userdata[i]->Set(ucr->userdata[i].const_data(), *currAdmin, login, store)) + if(!userdata[i]->Set(ucr->userdata[i].const_data(), currAdmin, login, store)) res = -1; } } if (!ucr->passive.res_empty()) - if (!u->GetProperty().passive.Set(ucr->passive.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().passive.Set(ucr->passive.const_data(), currAdmin, login, store)) res = -1; if (!ucr->password.res_empty()) - if (!u->GetProperty().password.Set(ucr->password.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().password.Set(ucr->password.const_data(), currAdmin, login, store)) res = -1; if (!ucr->phone.res_empty()) - if (!u->GetProperty().phone.Set(ucr->phone.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().phone.Set(ucr->phone.const_data(), currAdmin, login, store)) res = -1; if (!ucr->realName.res_empty()) - if (!u->GetProperty().realName.Set(ucr->realName.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().realName.Set(ucr->realName.const_data(), currAdmin, login, store)) res = -1; @@ -1109,15 +1109,15 @@ if (!usr->cash.res_empty()) if (cashMustBeAdded) { if (!u->GetProperty().cash.Set(usr->cash.const_data() + u->GetProperty().cash, - *currAdmin, - login, - store, - cashMsg)) + currAdmin, + login, + store, + cashMsg)) res = -1; } else { - if (!u->GetProperty().cash.Set(usr->cash.const_data(), *currAdmin, login, store, cashMsg)) + if (!u->GetProperty().cash.Set(usr->cash.const_data(), currAdmin, login, store, cashMsg)) res = -1; } } @@ -1128,7 +1128,7 @@ if (!ucr->tariffName.res_empty()) { if (tariffs->FindByName(ucr->tariffName.const_data())) { - if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().tariffName.Set(ucr->tariffName.const_data(), currAdmin, login, store)) res = -1; u->ResetNextTariff(); } @@ -1143,7 +1143,7 @@ if (!ucr->nextTariff.res_empty()) { if (tariffs->FindByName(ucr->nextTariff.const_data())) { - if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), *currAdmin, login, store)) + if (!u->GetProperty().nextTariff.Set(ucr->nextTariff.const_data(), currAdmin, login, store)) res = -1; } else @@ -1172,20 +1172,20 @@ for (int i = 0; i < DIR_NUM; i++) } if (upCount) - if (!u->GetProperty().up.Set(up, *currAdmin, login, store)) + if (!u->GetProperty().up.Set(up, currAdmin, login, store)) res = -1; if (downCount) - if (!u->GetProperty().down.Set(down, *currAdmin, login, store)) + if (!u->GetProperty().down.Set(down, currAdmin, login, store)) res = -1; /*if (!usr->down.res_empty()) { - u->GetProperty().down.Set(usr->down.const_data(), *currAdmin, login, store); + u->GetProperty().down.Set(usr->down.const_data(), currAdmin, login, store); } if (!usr->up.res_empty()) { - u->GetProperty().up.Set(usr->up.const_data(), *currAdmin, login, store); + u->GetProperty().up.Set(usr->up.const_data(), currAdmin, login, store); }*/ u->WriteConf(); @@ -1375,7 +1375,7 @@ int PARSER_DEL_USER::ParseEnd(void *, const char *el) if (strcasecmp(el, "DelUser") == 0) { if (!res) - users->Del(u->GetLogin(), *currAdmin); + users->Del(u->GetLogin(), currAdmin); return 0; } diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp index f232fb23..a87c1dbf 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_admin.cpp @@ -93,7 +93,7 @@ void PARSER_DEL_ADMIN::CreateAnswer() //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); -if (admins->Del(adminToDel, *currAdmin) == 0) +if (admins->Del(adminToDel, currAdmin) == 0) { answerList->push_back(""); } @@ -149,7 +149,7 @@ void PARSER_ADD_ADMIN::CreateAnswer() //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); -if (admins->Add(adminToAdd, *currAdmin) == 0) +if (admins->Add(adminToAdd, currAdmin) == 0) { answerList->push_back(""); } @@ -241,7 +241,7 @@ if (!login.res_empty()) conf.priv.tariffChg = (p & 0x3000) >> 0x0C; // 1000+2000 } - if (admins->Change(conf, *currAdmin) != 0) + if (admins->Change(conf, currAdmin) != 0) { strprintf(&s, "", admins->GetStrError().c_str()); answerList->push_back(s); diff --git a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp index e2daa336..c17a7713 100644 --- a/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp +++ b/projects/stargazer/plugins/configuration/sgconfig/parser_tariff.cpp @@ -180,7 +180,7 @@ void PARSER_ADD_TARIFF::CreateAnswer() //answerList->clear(); answerList->erase(answerList->begin(), answerList->end()); -if (tariffs->Add(tariffToAdd, *currAdmin) == 0) +if (tariffs->Add(tariffToAdd, currAdmin) == 0) { answerList->push_back(""); } @@ -228,7 +228,7 @@ if (users->TariffInUse(tariffToDel)) return; } -if (tariffs->Del(tariffToDel, *currAdmin) == 0) +if (tariffs->Del(tariffToDel, currAdmin) == 0) { answerList->push_back(""); } @@ -475,7 +475,7 @@ answerList->erase(answerList->begin(), answerList->end()); if (!td.tariffConf.name.data().empty()) { TARIFF_DATA tariffData = td.GetData(); - if (tariffs->Chg(tariffData, *currAdmin) == 0) + if (tariffs->Chg(tariffData, currAdmin) == 0) { answerList->push_back(""); return; diff --git a/projects/stargazer/tariffs_impl.cpp b/projects/stargazer/tariffs_impl.cpp index 32de4971..e0ef68e1 100644 --- a/projects/stargazer/tariffs_impl.cpp +++ b/projects/stargazer/tariffs_impl.cpp @@ -106,13 +106,13 @@ if (ti != tariffs.end()) return NULL; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Chg(const TARIFF_DATA & td, const ADMIN & admin) +int TARIFFS_IMPL::Chg(const TARIFF_DATA & td, const ADMIN * admin) { -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin.GetLogStr() + " Change tariff \'" + string s = admin->GetLogStr() + " Change tariff \'" + td.tariffConf.name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -127,7 +127,7 @@ ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(td.tariffConf.name)); if (ti == tariffs.end()) { strError = "Tariff \'" + td.tariffConf.name + "\' cannot be changed. Tariff does not exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -141,18 +141,18 @@ if (store->SaveTariff(td, td.tariffConf.name)) } WriteServLog("%s Tariff \'%s\' changed.", - admin.GetLogStr().c_str(), td.tariffConf.name.c_str()); + admin->GetLogStr().c_str(), td.tariffConf.name.c_str()); return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Del(const string & name, const ADMIN & admin) +int TARIFFS_IMPL::Del(const string & name, const ADMIN * admin) { -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin.GetLogStr() + " Delete tariff \'" + string s = admin->GetLogStr() + " Delete tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -167,7 +167,7 @@ ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti == tariffs.end()) { strError = "Tariff \'" + name + "\' cannot be deleted. Tariff does not exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -181,18 +181,18 @@ if (store->DelTariff(name)) tariffs.erase(ti); WriteServLog("%s Tariff \'%s\' deleted.", - admin.GetLogStr().c_str(), + admin->GetLogStr().c_str(), name.c_str()); return 0; } //----------------------------------------------------------------------------- -int TARIFFS_IMPL::Add(const string & name, const ADMIN & admin) +int TARIFFS_IMPL::Add(const string & name, const ADMIN * admin) { -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->tariffChg) { - string s = admin.GetLogStr() + " Add tariff \'" + string s = admin->GetLogStr() + " Add tariff \'" + name + "\'. Access denied."; strError = "Access denied."; WriteServLog(s.c_str()); @@ -207,7 +207,7 @@ ti = find(tariffs.begin(), tariffs.end(), TARIFF_IMPL(name)); if (ti != tariffs.end()) { strError = "Tariff \'" + name + "\' cannot be added. Tariff alredy exist."; - WriteServLog("%s %s", admin.GetLogStr().c_str(), strError.c_str()); + WriteServLog("%s %s", admin->GetLogStr().c_str(), strError.c_str()); return -1; } @@ -221,7 +221,7 @@ if (store->AddTariff(name) < 0) } WriteServLog("%s Tariff \'%s\' added.", - admin.GetLogStr().c_str(), name.c_str()); + admin->GetLogStr().c_str(), name.c_str()); return 0; } diff --git a/projects/stargazer/tariffs_impl.h b/projects/stargazer/tariffs_impl.h index 0b1c23b9..5778945d 100644 --- a/projects/stargazer/tariffs_impl.h +++ b/projects/stargazer/tariffs_impl.h @@ -61,9 +61,9 @@ public: const TARIFF * FindByName(const std::string & name) const; const TARIFF * GetNoTariff() const { return &noTariff; }; int GetTariffsNum() const; - int Del(const std::string & name, const ADMIN & admin); - int Add(const std::string & name, const ADMIN & admin); - int Chg(const TARIFF_DATA & td, const ADMIN & admin); + int Del(const std::string & name, const ADMIN * admin); + int Add(const std::string & name, const ADMIN * admin); + int Chg(const TARIFF_DATA & td, const ADMIN * admin); void GetTariffsData(std::list * tdl); diff --git a/projects/stargazer/user_impl.cpp b/projects/stargazer/user_impl.cpp index 0d6cfa84..6ef806f2 100644 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@ -49,7 +49,7 @@ USER_IMPL::USER_IMPL(const SETTINGS * s, const STORE * st, const TARIFFS * t, - const ADMIN & a, + const ADMIN * a, const USERS * u) : users(u), property(s), diff --git a/projects/stargazer/user_impl.h b/projects/stargazer/user_impl.h index ad5b4516..ba69ced1 100644 --- a/projects/stargazer/user_impl.h +++ b/projects/stargazer/user_impl.h @@ -105,7 +105,7 @@ public: USER_IMPL(const SETTINGS * settings, const STORE * store, const TARIFFS * tariffs, - const ADMIN & sysAdmin, + const ADMIN * sysAdmin, const USERS * u); USER_IMPL(const USER_IMPL & u); virtual ~USER_IMPL(); @@ -221,7 +221,7 @@ private: time_t pingTime; - const ADMIN & sysAdmin; + const ADMIN * sysAdmin; const STORE * store; const TARIFFS * tariffs; diff --git a/projects/stargazer/user_property.h b/projects/stargazer/user_property.h index 704f371e..c7019216 100644 --- a/projects/stargazer/user_property.h +++ b/projects/stargazer/user_property.h @@ -77,17 +77,17 @@ public: const varT & Get() const; const string & GetName() const; bool Set(const varT & val, - const ADMIN & admin, + const ADMIN * admin, const string & login, const STORE * store, const string & msg = ""); private: void WriteAccessDenied(const string & login, - const ADMIN & admin, + const ADMIN * admin, const string & parameter); void WriteSuccessChange(const string & login, - const ADMIN & admin, + const ADMIN * admin, const string & parameter, const string & oldValue, const string & newValue, @@ -98,7 +98,7 @@ private: const string & paramName, const string & oldValue, const string & newValue, - const ADMIN & admin); + const ADMIN * admin); string name; // parameter name. needed for logging bool isPassword; // is parameter password. when true, it will be logged as ******* @@ -321,20 +321,16 @@ return name; //------------------------------------------------------------------------- template bool USER_PROPERTY_LOGGED::Set(const varT & val, - const ADMIN & admin, + const ADMIN * admin, const string & login, const STORE * store, const string & msg) { STG_LOCKER locker(&mutex, __FILE__, __LINE__); -//cout << "USER_PROPERTY_LOGGED " << val << endl; -//value = val; -//modificationTime = stgTime; - -const PRIV * priv = admin.GetPriv(); -string adm_login = admin.GetLogin(); -string adm_ip = admin.GetIPStr(); +const PRIV * priv = admin->GetPriv(); +string adm_login = admin->GetLogin(); +string adm_ip = admin->GetIPStr(); if ((priv->userConf && !isStat) || (priv->userStat && isStat) || (priv->userPasswd && isPassword) || (priv->userCash && name == "cash")) { @@ -370,16 +366,16 @@ return true; //------------------------------------------------------------------------- template void USER_PROPERTY_LOGGED::WriteAccessDenied(const string & login, - const ADMIN & admin, + const ADMIN * admin, const string & parameter) { stgLogger("%s Change user \'%s.\' Parameter \'%s\'. Access denied.", - admin.GetLogStr().c_str(), login.c_str(), parameter.c_str()); + admin->GetLogStr().c_str(), login.c_str(), parameter.c_str()); } //------------------------------------------------------------------------- template void USER_PROPERTY_LOGGED::WriteSuccessChange(const string & login, - const ADMIN & admin, + const ADMIN * admin, const string & parameter, const string & oldValue, const string & newValue, @@ -387,14 +383,14 @@ void USER_PROPERTY_LOGGED::WriteSuccessChange(const string & login, const STORE * store) { stgLogger("%s User \'%s\': \'%s\' parameter changed from \'%s\' to \'%s\'. %s", - admin.GetLogStr().c_str(), + admin->GetLogStr().c_str(), login.c_str(), parameter.c_str(), oldValue.c_str(), newValue.c_str(), msg.c_str()); -store->WriteUserChgLog(login, admin.GetLogin(), admin.GetIP(), parameter, oldValue, newValue, msg); +store->WriteUserChgLog(login, admin->GetLogin(), admin->GetIP(), parameter, oldValue, newValue, msg); } //------------------------------------------------------------------------- template @@ -402,7 +398,7 @@ void USER_PROPERTY_LOGGED::OnChange(const string & login, const string & paramName, const string & oldValue, const string & newValue, - const ADMIN & admin) + const ADMIN * admin) { string str1; @@ -410,7 +406,7 @@ str1 = settings->GetConfDir() + "/OnChange"; if (access(str1.c_str(), X_OK) == 0) { - string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin.GetLogin() + "\" \"" + admin.GetIPStr() + "\""); + string str2("\"" + str1 + "\" \"" + login + "\" \"" + paramName + "\" \"" + oldValue + "\" \"" + newValue + "\" \"" + admin->GetLogin() + "\" \"" + admin->GetIPStr() + "\""); ScriptExec(str2); } else diff --git a/projects/stargazer/users_impl.cpp b/projects/stargazer/users_impl.cpp index 9faadeb3..3384c660 100644 --- a/projects/stargazer/users_impl.cpp +++ b/projects/stargazer/users_impl.cpp @@ -52,7 +52,7 @@ extern const volatile time_t stgTime; //#define USERS_DEBUG 1 //----------------------------------------------------------------------------- -USERS_IMPL::USERS_IMPL(SETTINGS * s, STORE * st, TARIFFS * t, const ADMIN & sa) +USERS_IMPL::USERS_IMPL(SETTINGS * s, STORE * st, TARIFFS * t, const ADMIN * sa) : users(), usersToDelete(), userIPNotifiersBefore(), @@ -122,16 +122,16 @@ while (iter != users.end()) return false; } //----------------------------------------------------------------------------- -int USERS_IMPL::Add(const string & login, const ADMIN & admin) +int USERS_IMPL::Add(const string & login, const ADMIN * admin) { STG_LOCKER lock(&mutex, __FILE__, __LINE__); -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); if (!priv->userAddDel) { WriteServLog("%s tried to add user \'%s\'. Access denied.", - admin.GetLogStr().c_str(), login.c_str()); - /*errorStr = "Admin \'" + admin.GetLogin() + + admin->GetLogStr().c_str(), login.c_str()); + /*errorStr = "Admin \'" + admin->GetLogin() + "\': tried to add user \'" + ud->login + "\'. Access denied.";*/ return -1; } @@ -141,7 +141,7 @@ if (store->AddUser(login)) { //TODO //WriteServLog("Admin \'%s\': tried to add user \'%s\'. Access denied.", - // admin.GetLogin().c_str(), ud->login.c_str()); + // admin->GetLogin().c_str(), ud->login.c_str()); return -1; } ////// @@ -170,7 +170,7 @@ u.WriteConf(); u.WriteStat(); WriteServLog("%s User \'%s\' added.", - admin.GetLogStr().c_str(), login.c_str()); + admin->GetLogStr().c_str(), login.c_str()); u.OnAdd(); @@ -190,15 +190,15 @@ while (ni != onAddNotifiers.end()) return 0; } //----------------------------------------------------------------------------- -void USERS_IMPL::Del(const string & login, const ADMIN & admin) +void USERS_IMPL::Del(const string & login, const ADMIN * admin) { -const PRIV * priv = admin.GetPriv(); +const PRIV * priv = admin->GetPriv(); user_iter u; if (!priv->userAddDel) { WriteServLog("%s tried to remove user \'%s\'. Access denied.", - admin.GetLogStr().c_str(), login.c_str()); + admin->GetLogStr().c_str(), login.c_str()); return; } @@ -209,7 +209,7 @@ if (!priv->userAddDel) if (FindByNameNonLock(login, &u)) { WriteServLog("%s tried to delete user \'%s\': not found.", - admin.GetLogStr().c_str(), + admin->GetLogStr().c_str(), login.c_str()); return; } @@ -237,7 +237,7 @@ while (ni != onDelNotifiers.end()) DelUserFromIndexes(u); WriteServLog("%s User \'%s\' deleted.", - admin.GetLogStr().c_str(), login.c_str()); + admin->GetLogStr().c_str(), login.c_str()); } } diff --git a/projects/stargazer/users_impl.h b/projects/stargazer/users_impl.h index 966487df..b9df5981 100644 --- a/projects/stargazer/users_impl.h +++ b/projects/stargazer/users_impl.h @@ -92,7 +92,7 @@ class USERS_IMPL : private NONCOPYABLE, public USERS { friend class PROPERTY_NOTIFER_IP_AFTER; public: - USERS_IMPL(SETTINGS * s, STORE * store, TARIFFS * tariffs, const ADMIN & sysAdmin); + USERS_IMPL(SETTINGS * s, STORE * store, TARIFFS * tariffs, const ADMIN * sysAdmin); virtual ~USERS_IMPL(); int FindByName(const std::string & login, USER_PTR * user); @@ -105,8 +105,8 @@ public: void AddNotifierUserDel(NOTIFIER_BASE *); void DelNotifierUserDel(NOTIFIER_BASE *); - int Add(const std::string & login, const ADMIN & admin); - void Del(const std::string & login, const ADMIN & admin); + int Add(const std::string & login, const ADMIN * admin); + void Del(const std::string & login, const ADMIN * admin); int ReadUsers(); int GetUserNum() const; @@ -154,7 +154,7 @@ private: SETTINGS * settings; TARIFFS * tariffs; STORE * store; - const ADMIN & sysAdmin; + const ADMIN * sysAdmin; STG_LOGGER & WriteServLog; bool nonstop;