void HubInfo::onFlagsUpdated(const UserPtr& aUser) noexcept { auto ou = ClientManager::getInstance()->findOnlineUser(aUser->getCID(), client->getHubUrl(), false); if (ou) { onUserUpdated(ou, { PROP_FLAGS }); } }
void LogManager::removePmCache(const UserPtr& aUser) noexcept { pmPaths.erase(aUser->getCID()); }
BOOST_FOREACH (const UserPtr& user, users) { t_task(USER, user.id()); }
/* * Creates new (or update existing) node which is NOT added to our routing table */ Node::Ptr KBucket::createNode(const UserPtr& u, const string& ip, uint16_t port, bool update, bool isUdpKeyValid) { if(u->isSet(User::DHT)) // is this user already known in DHT? { Node::Ptr node = NULL; // no online node found, try get from routing table for(NodeList::iterator it = nodes.begin(); it != nodes.end(); ++it) { if(u->getCID() == (*it)->getUser()->getCID()) { node = *it; // put node at the end of the list nodes.erase(it); nodes.push_back(node); break; } } if(node == NULL && u->isOnline()) { // try to get node from ClientManager (user can be online but not in our routing table) // this fixes the bug with DHT node online twice node = (Node*)ClientManager::getInstance()->findDHTNode(u->getCID()); node = node.get(); } if(node != NULL) { // fine, node found, update it and return it if(update) { string oldIp = node->getIdentity().getIp(); string oldPort = node->getIdentity().getUdpPort(); if(ip != oldIp || static_cast<uint16_t>(Util::toInt(oldPort)) != port) { node->setIpVerified(false); // TODO: don't allow update when new IP already exists for different node // erase old IP and remember new one ipMap.erase(oldIp + ":" + oldPort); ipMap.insert(ip + ":" + Util::toString(port)); } if(!node->isIpVerified()) node->setIpVerified(isUdpKeyValid); node->setAlive(); node->getIdentity().setIp(ip); node->getIdentity().setUdpPort(Util::toString(port)); DHT::getInstance()->setDirty(); } return node; } } u->setFlag(User::DHT); Node::Ptr node(new Node(u)); node->getIdentity().setIp(ip); node->getIdentity().setUdpPort(Util::toString(port)); node->setIpVerified(isUdpKeyValid); return node; }
void SearchManager::onData(const uint8_t* buf, size_t aLen, const string& remoteIp) { string x((char*)buf, aLen); if(x.compare(0, 4, "$SR ") == 0) { string::size_type i, j; // Directories: $SR <nick><0x20><directory><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>) // Files: $SR <nick><0x20><filename><0x05><filesize><0x20><free slots>/<total slots><0x05><Hubname><0x20>(<Hubip:port>) i = 4; if( (j = x.find(' ', i)) == string::npos) { return; } string nick = x.substr(i, j-i); i = j + 1; // A file has 2 0x05, a directory only one size_t cnt = count(x.begin() + j, x.end(), 0x05); SearchResult::Types type = SearchResult::TYPE_FILE; string file; int64_t size = 0; if(cnt == 1) { // We have a directory...find the first space beyond the first 0x05 from the back // (dirs might contain spaces as well...clever protocol, eh?) type = SearchResult::TYPE_DIRECTORY; // Get past the hubname that might contain spaces if((j = x.rfind(0x05)) == string::npos) { return; } // Find the end of the directory info if((j = x.rfind(' ', j-1)) == string::npos) { return; } if(j < i + 1) { return; } file = x.substr(i, j-i) + '\\'; } else if(cnt == 2) { if( (j = x.find((char)5, i)) == string::npos) { return; } file = x.substr(i, j-i); i = j + 1; if( (j = x.find(' ', i)) == string::npos) { return; } size = Util::toInt64(x.substr(i, j-i)); } i = j + 1; if( (j = x.find('/', i)) == string::npos) { return; } int freeSlots = Util::toInt(x.substr(i, j-i)); i = j + 1; if( (j = x.find((char)5, i)) == string::npos) { return; } int slots = Util::toInt(x.substr(i, j-i)); i = j + 1; if( (j = x.rfind(" (")) == string::npos) { return; } string hubName = x.substr(i, j-i); i = j + 2; if( (j = x.rfind(')')) == string::npos) { return; } string hubIpPort = x.substr(i, j-i); string url = ClientManager::getInstance()->findHub(hubIpPort); string encoding = ClientManager::getInstance()->findHubEncoding(url); nick = Text::toUtf8(nick, encoding); file = Text::toUtf8(file, encoding); hubName = Text::toUtf8(hubName, encoding); UserPtr user = ClientManager::getInstance()->findUser(nick, url); if(!user) { // Could happen if hub has multiple URLs / IPs user = ClientManager::getInstance()->findLegacyUser(nick); if(!user) return; } string tth; if(hubName.compare(0, 4, "TTH:") == 0) { tth = hubName.substr(4); StringList names = ClientManager::getInstance()->getHubNames(user->getCID()); hubName = names.empty() ? _("Offline") : Util::toString(names); } if(tth.empty() && type == SearchResult::TYPE_FILE) { return; } SearchResultPtr sr(new SearchResult(user, type, slots, freeSlots, size, file, hubName, url, remoteIp, TTHValue(tth), Util::emptyString)); fire(SearchManagerListener::SR(), sr); } else if(x.compare(1, 4, "RES ") == 0 && x[x.length() - 1] == 0x0a) { AdcCommand c(x.substr(0, x.length()-1)); if(c.getParameters().empty()) return; string cid = c.getParam(0); if(cid.size() != 39) return; UserPtr user = ClientManager::getInstance()->findUser(CID(cid)); if(!user) return; // This should be handled by AdcCommand really... c.getParameters().erase(c.getParameters().begin()); onRES(c, user, remoteIp); } /*else if(x.compare(1, 4, "SCH ") == 0 && x[x.length() - 1] == 0x0a) { try { respond(AdcCommand(x.substr(0, x.length()-1))); } catch(ParseException& ) { } }*/ // Needs further DoS investigation }
bool UserPropertiesHandler::handleURI(URI& uri) { bool addUser = uri.action == "add_user"; bool editUser = uri.action == "edit_user"; if (!addUser && !editUser) return false; wxWindow* w = getParentWindow(uri); ServerPtr server; UserPtr user; wxString title(_("Modify User")); if (addUser) { server = extractMetadataItemPtrFromURI<Server>(uri); if (!server) return true; title = _("Create New User"); user.reset(new User(server)); } else { user = extractMetadataItemPtrFromURI<User>(uri); if (!user) return true; #ifdef __WXGTK__ if (user->getUsername() == "SYSDBA") { showWarningDialog(w, _("The password for the SYSDBA user should not be changed here."), _("The appropriate way to change the password of the SYSDBA user is to run the changeDBAPassword.sh script in Firebird's bin directory.\n\nOtherwise the scripts will not be updated."), AdvancedMessageDialogButtonsOk(), config(), "DIALOG_warn_sysdba_change", _("Do not show this information again")); } #endif server = user->getServer(); if (!server) return true; } UserDialog d(w, title, addUser); d.setUser(user); if (d.ShowModal() == wxID_OK) { ProgressDialog pd(w, _("Connecting to Server..."), 1); pd.doShow(); IBPP::Service svc; if (!getService(server.get(), svc, &pd, true)) // true = need SYSDBA password return true; try { IBPP::User u; user->assignTo(u); if (addUser) svc->AddUser(u); else svc->ModifyUser(u); server->notifyObservers(); } catch(IBPP::Exception& e) { wxMessageBox(e.what(), _("Error"), wxOK | wxICON_WARNING); } } return true; }