git.stg.codes
/
stg.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[NY Flight] Use common encryption/decryption functions.
[stg.git]
/
projects
/
stargazer
/
admins_impl.cpp
diff --git
a/projects/stargazer/admins_impl.cpp
b/projects/stargazer/admins_impl.cpp
index 20bd8ef8a59a5da4588e545ffba4bffb70fe6a29..7d73dde1834cde8481ddeee2fde6f3cc78d3de66 100644
(file)
--- a/
projects/stargazer/admins_impl.cpp
+++ b/
projects/stargazer/admins_impl.cpp
@@
-32,36
+32,37
@@
#include <cassert>
#include <algorithm>
#include <cassert>
#include <algorithm>
+#include "stg/common.h"
#include "admins_impl.h"
#include "admins_impl.h"
-#include "admins.h"
-#include "admin.h"
#include "admin_impl.h"
#include "admin_impl.h"
-#include "common.h"
using namespace std;
//-----------------------------------------------------------------------------
using namespace std;
//-----------------------------------------------------------------------------
-ADMINS_IMPL::ADMINS_IMPL(BASE_STORE * st)
- : stg(0xFFFF, "@stargazer", ""),
+ADMINS_IMPL::ADMINS_IMPL(STORE * st)
+ : ADMINS(),
+ stg(0xFFFF, "@stargazer", ""),
noAdmin(0xFFFF, "NO-ADMIN", ""),
data(),
store(st),
WriteServLog(GetStgLogger()),
searchDescriptors(),
noAdmin(0xFFFF, "NO-ADMIN", ""),
data(),
store(st),
WriteServLog(GetStgLogger()),
searchDescriptors(),
- handle(0)
+ handle(0),
+ mutex(),
+ strError()
{
pthread_mutex_init(&mutex, NULL);
{
pthread_mutex_init(&mutex, NULL);
-Read
Admins
();
+Read();
}
//-----------------------------------------------------------------------------
}
//-----------------------------------------------------------------------------
-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__);
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-const PRIV * priv = admin
.
GetPriv();
+const PRIV * priv = admin
->
GetPriv();
if (!priv->adminChg)
{
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;
strError = "Access denied.";
WriteServLog(s.c_str());
return -1;
@@
-72,8
+73,8
@@
admin_iter ai(find(data.begin(), data.end(), adm));
if (ai != data.end())
{
if (ai != data.end())
{
- strError = "Administrator \'" + login + "\' cannot not be added. Administrator alredy exist.";
- WriteServLog("%s %s", admin
.
GetLogStr().c_str(), strError.c_str());
+ strError = "Administrator \'" + login + "\' cannot not be added. Administrator alre
a
dy exist.";
+ WriteServLog("%s %s", admin
->
GetLogStr().c_str(), strError.c_str());
return -1;
}
return -1;
}
@@
-83,25
+84,25
@@
data.push_back(adm);
if (store->AddAdmin(login) == 0)
{
WriteServLog("%s Administrator \'%s\' added.",
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();
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;
}
//-----------------------------------------------------------------------------
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, "");
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
ADMIN_IMPL adm(0, login, "");
-const PRIV * priv = admin
.
GetPriv();
+const PRIV * priv = admin
->
GetPriv();
if (!priv->adminChg)
{
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;
strError = "Access denied.";
WriteServLog(s.c_str());
return -1;
@@
-112,7
+113,7
@@
admin_iter ai(find(data.begin(), data.end(), adm));
if (ai == data.end())
{
strError = "Administrator \'" + login + "\' cannot be deleted. Administrator does not exist.";
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;
}
return -1;
}
@@
-129,23
+130,23
@@
data.remove(*ai);
if (store->DelAdmin(login) < 0)
{
strError = "Administrator \'" + login + "\' was not deleted. Error: " + store->GetStrError();
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;
}
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;
}
//-----------------------------------------------------------------------------
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__);
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-const PRIV * priv = admin
.
GetPriv();
+const PRIV * priv = admin
->
GetPriv();
if (!priv->adminChg)
{
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;
strError = "Access denied.";
WriteServLog(s.c_str());
return -1;
@@
-157,7
+158,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.";
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;
}
return -1;
}
@@
-170,12
+171,12
@@
if (store->SaveAdmin(ac))
}
WriteServLog("%s Administrator \'%s\' changed.",
}
WriteServLog("%s Administrator \'%s\' changed.",
- admin
.
GetLogStr().c_str(), ac.login.c_str());
+ admin
->
GetLogStr().c_str(), ac.login.c_str());
return 0;
}
//-----------------------------------------------------------------------------
return 0;
}
//-----------------------------------------------------------------------------
-int ADMINS_IMPL::Read
Admins
()
+int ADMINS_IMPL::Read()
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
vector<string> adminsList;
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
vector<string> adminsList;
@@
-211,14
+212,14
@@
while (ai != data.end())
}
}
//-----------------------------------------------------------------------------
}
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::Find
Admin
(const string & l, ADMIN ** admin)
+bool ADMINS_IMPL::Find(const string & l, ADMIN ** admin)
{
assert(admin != NULL && "Pointer to admin is not null");
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
{
{
assert(admin != NULL && "Pointer to admin is not null");
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
{
- printfd(__FILE__, "
n
o admin in system!\n");
+ printfd(__FILE__, "
N
o admin in system!\n");
*admin = &noAdmin;
return false;
}
*admin = &noAdmin;
return false;
}
@@
-235,7
+236,7
@@
if (ai != data.end())
return true;
}
//-----------------------------------------------------------------------------
return true;
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::
Admin
Exists(const string & login) const
+bool ADMINS_IMPL::Exists(const string & login) const
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
@@
-253,7
+254,7
@@
if (ai != data.end())
return false;
}
//-----------------------------------------------------------------------------
return false;
}
//-----------------------------------------------------------------------------
-bool ADMINS_IMPL::
AdminCorrect(const string & login, const std::string & password, ADMIN * admin) const
+bool ADMINS_IMPL::
Correct(const string & login, const std::string & password, ADMIN ** admin)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
if (data.empty())
@@
-263,7
+264,7
@@
if (data.empty())
}
ADMIN_IMPL adm(0, login, "");
}
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())
{
if (ai == data.end())
{
@@
-275,7
+276,7
@@
if (ai->GetPassword() != password)
return false;
}
return false;
}
-*admin =
*ai
;
+*admin =
&(*ai)
;
return true;
}
return true;
}