std::string GetIpStr() const;
bool IsIPInIPS(uint32_t ip) const;
bool OnlyOneIP() const;
- int Count() const;
+ size_t Count() const;
void Add(const IP_MASK &im);
void Erase();
}
//-----------------------------------------------------------------------------
inline
-int USER_IPS::Count() const
+size_t USER_IPS::Count() const
{
-return static_cast<int>(ips.size());
+return ips.size();
}
//-----------------------------------------------------------------------------
inline
virtual int FindByIPIdx(uint32_t ip, USER_PTR * user) const = 0;
virtual bool IsIPInIndex(uint32_t ip) const = 0;
+ virtual bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const = 0;
virtual int OpenSearch() = 0;
virtual int SearchNext(int handle, USER_PTR * u) = 0;
{
USER_IPS ips;
ips = StrToIPS(xmlrpc_c::value_string(it->second));
+
+ for (size_t i = 0; i < ips.Count(); ++i)
+ {
+ CONST_USER_PTR user;
+ uint32_t ip = ips[i].ip;
+ if (users.IsIPInUse(ip, login, &user))
+ {
+ printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ return true;
+ }
+ }
+
if (!ptr->GetProperty().ips.Set(ips,
admin,
login,
class USER_HELPER
{
public:
- USER_HELPER(USER_PTR & p)
- : ptr(p)
+ USER_HELPER(USER_PTR & p, USERS & us)
+ : ptr(p),
+ users(us)
{
}
TARIFFS * tariffs);
private:
USER_PTR & ptr;
+ USERS & users;
};
#endif
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
xmlrpc_c::value info;
- USER_HELPER uhelper(u);
+ USER_HELPER uhelper(u, *users);
uhelper.GetUserInfo(&info, hidePassword);
return;
}
-USER_HELPER uhelper(u);
+USER_HELPER uhelper(u, *users);
if (!adminInfo.priviledges.userConf || !adminInfo.priviledges.userPasswd)
{
{
printfd(__FILE__, "Requested change leads to a forbidden state: AlwaysOnline with multiple IP's\n");
GetStgLogger()("%s Requested change leads to a forbidden state: AlwaysOnline with multiple IP's", currAdmin->GetLogStr().c_str());
+ res = -1;
return -1;
}
+for (size_t i = 0; i < ucr->ips.const_data().Count(); ++i)
+ {
+ CONST_USER_PTR user;
+ uint32_t ip = ucr->ips.const_data().operator[](i).ip;
+ if (users->IsIPInUse(ip, login, &user))
+ {
+ printfd(__FILE__, "Trying to assign an IP %s to '%s' that is already in use by '%s'\n", inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ GetStgLogger()("%s trying to assign an IP %s to '%s' that is currently in use by '%s'", currAdmin->GetLogStr().c_str(), inet_ntostring(ip).c_str(), login.c_str(), user->GetLogin().c_str());
+ res = -1;
+ return -1;
+ }
+ }
+
if (!ucr->ips.res_empty())
if (!u->GetProperty().ips.Set(ucr->ips.const_data(), currAdmin, login, store))
res = -1;
st->Execute();
st->Prepare("insert into tb_allowed_ip (fk_user, ip, mask) values (?, ?, ?)");
- for(i = 0; i < conf.ips.Count(); i++)
+ for(size_t i = 0; i < conf.ips.Count(); i++)
{
st->Set(1, uid);
st->Set(2, (int32_t)conf.ips[i].ip);
PQclear(result);
-for (int i = 0; i < ips.Count(); ++i)
+for (size_t i = 0; i < ips.Count(); ++i)
{
std::ostringstream query;
query << "INSERT INTO tb_allowed_ip "
return it != ipIndex.end();
}
//-----------------------------------------------------------------------------
+bool USERS_IMPL::IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const
+{
+STG_LOCKER lock(&mutex, __FILE__, __LINE__);
+std::list<USER_IMPL>::const_iterator iter;
+iter = users.begin();
+while (iter != users.end())
+ {
+ if (iter->GetLogin() != login && iter->GetProperty().ips.Get().IsIPInIPS(ip))
+ {
+ if (user != NULL)
+ *user = &(*iter);
+ return true;
+ }
+ ++iter;
+ }
+return false;
+}
+//-----------------------------------------------------------------------------
void USERS_IMPL::AddNotifierUserAdd(NOTIFIER_BASE<USER_PTR> * n)
{
STG_LOCKER lock(&mutex, __FILE__, __LINE__);
int FindByIPIdx(uint32_t ip, USER_PTR * user) const;
int FindByIPIdx(uint32_t ip, USER_IMPL ** user) const;
bool IsIPInIndex(uint32_t ip) const;
+ bool IsIPInUse(uint32_t ip, const std::string & login, CONST_USER_PTR * user) const;
int OpenSearch();
int SearchNext(int handler, USER_PTR * user);