+bool USERS_IMPL::Authorize(const std::string & login, uint32_t ip,
+ uint32_t enabledDirs, const AUTH * auth)
+{
+user_iter iter;
+STG_LOCKER lock(&mutex);
+if (FindByNameNonLock(login, &iter))
+ {
+ WriteServLog("Attempt to authorize non-existant user '%s'", login.c_str());
+ return false;
+ }
+
+if (FindByIPIdx(ip, iter))
+ {
+ if (iter->GetLogin() != login)
+ {
+ WriteServLog("Attempt to authorize user '%s' from ip %s which already occupied by '%s'",
+ login.c_str(), inet_ntostring(ip).c_str(),
+ iter->GetLogin().c_str());
+ return false;
+ }
+ if (iter->Authorize(ip, enabledDirs, auth))
+ return false;
+ return true;
+ }
+
+if (iter->Authorize(ip, enabledDirs, auth))
+ return false;
+
+AddToIPIdx(iter);
+return true;
+}
+//-----------------------------------------------------------------------------
+bool USERS_IMPL::Unauthorize(const std::string & login,
+ const AUTH * auth,
+ const std::string & reason)
+{
+user_iter iter;
+STG_LOCKER lock(&mutex);
+if (FindByNameNonLock(login, &iter))
+ {
+ WriteServLog("Attempt to unauthorize non-existant user '%s'", login.c_str());
+ printfd(__FILE__, "Attempt to unauthorize non-existant user '%s'", login.c_str());
+ return false;
+ }
+
+uint32_t ip = iter->GetCurrIP();
+
+iter->Unauthorize(auth, reason);
+
+if (!iter->GetAuthorized())
+ DelFromIPIdx(ip);
+
+return true;
+}
+//-----------------------------------------------------------------------------