X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=43ebfe0a3a2df1d6ac71b648d6afb0d498f7537f;hb=20680f9c4964a5e10e3649a1e479078ff85c5c85;hp=2e0e0d3cce99e2f4f0f0fcde2a85d94c279fcbf5;hpb=2bd34b7037095f5007cf0acc36a32916ff0ea74e;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index 2e0e0d3cc..43ebfe0a3 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -73,6 +73,9 @@ std::string User::ProcessNoticeMasks(const char *sm) output += *c; } } + else + this->WriteNumeric(501, "%s %c :is unknown snomask char to me", this->nick, *c); + oldadding = adding; break; } @@ -88,13 +91,13 @@ void User::StartDNSLookup() try { bool cached; - const char* ip = this->GetIPString(); + const char* sip = this->GetIPString(); /* Special case for 4in6 (Have i mentioned i HATE 4in6?) */ - if (!strncmp(ip, "0::ffff:", 8)) - res_reverse = new UserResolver(this->ServerInstance, this, ip + 8, DNS_QUERY_PTR4, cached); + if (!strncmp(sip, "0::ffff:", 8)) + res_reverse = new UserResolver(this->ServerInstance, this, sip + 8, DNS_QUERY_PTR4, cached); else - res_reverse = new UserResolver(this->ServerInstance, this, ip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached); + res_reverse = new UserResolver(this->ServerInstance, this, sip, this->GetProtocolFamily() == AF_INET ? DNS_QUERY_PTR4 : DNS_QUERY_PTR6, cached); this->ServerInstance->AddResolver(res_reverse, cached); } @@ -177,11 +180,11 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = *uuid = 0; server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName); reset_due = ServerInstance->Time(); - age = ServerInstance->Time(true); + age = ServerInstance->Time(); Penalty = 0; lines_in = lastping = signon = idle_lastmsg = nping = registered = 0; ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0; - OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false; + quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false; fd = -1; recvq.clear(); sendq.clear(); @@ -190,7 +193,11 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance Visibility = NULL; ip = NULL; MyClass = NULL; + AllowedUserModes = NULL; + AllowedChanModes = NULL; AllowedOperCommands = NULL; + memset(AllowedUserModes, 0, sizeof(AllowedUserModes)); + memset(AllowedChanModes, 0, sizeof(AllowedChanModes)); chans.clear(); invites.clear(); memset(modes,0,sizeof(modes)); @@ -226,6 +233,18 @@ User::~User() AllowedOperCommands = NULL; } + if (this->AllowedUserModes) + { + delete AllowedUserModes; + AllowedUserModes = NULL; + } + + if (this->AllowedChanModes) + { + delete AllowedChanModes; + AllowedChanModes = NULL; + } + this->InvalidateCache(); this->DecrementModes(); @@ -405,21 +424,21 @@ InvitedList* User::GetInviteList() return &invites; } -void User::InviteTo(const irc::string &channel, time_t timeout) +void User::InviteTo(const irc::string &channel, time_t invtimeout) { time_t now = time(NULL); - if (timeout != 0 && now > timeout) return; /* Don't add invites that are expired from the get-go. */ + if (invtimeout != 0 && now > invtimeout) return; /* Don't add invites that are expired from the get-go. */ for (InvitedList::iterator i = invites.begin(); i != invites.end(); ++i) { if (channel == i->first) { - if (i->second != 0 && timeout > i->second) + if (i->second != 0 && invtimeout > i->second) { - i->second = timeout; + i->second = invtimeout; } } } - invites.push_back(std::make_pair(channel, timeout)); + invites.push_back(std::make_pair(channel, invtimeout)); } void User::RemoveInvite(const irc::string &channel) @@ -434,6 +453,21 @@ void User::RemoveInvite(const irc::string &channel) } } +bool User::HasModePermission(unsigned char mode, ModeType type) +{ + if (!IS_LOCAL(this)) + return true; + + if (!IS_OPER(this)) + return false; + + if (!AllowedUserModes || !AllowedChanModes) + return false; + + return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')]; + +} + bool User::HasPermission(const std::string &command) { /* @@ -666,6 +700,15 @@ void User::Oper(const std::string &opertype, const std::string &opername) else AllowedOperCommands = new std::map; + if (!AllowedChanModes) + AllowedChanModes = new bool[64]; + + if (!AllowedUserModes) + AllowedUserModes = new bool[64]; + + memset(AllowedUserModes, 0, 64); + memset(AllowedChanModes, 0, 64); + char* Classes = strdup(iter_opertype->second); char* myclass = strtok_r(Classes," ",&savept); while (myclass) @@ -673,7 +716,7 @@ void User::Oper(const std::string &opertype, const std::string &opername) operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass); if (iter_operclass != ServerInstance->Config->operclass.end()) { - char* CommandList = strdup(iter_operclass->second); + char* CommandList = strdup(iter_operclass->second.commandlist); mycmd = strtok_r(CommandList," ",&savept2); while (mycmd) { @@ -681,6 +724,29 @@ void User::Oper(const std::string &opertype, const std::string &opername) mycmd = strtok_r(NULL," ",&savept2); } free(CommandList); + this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want. + for (unsigned char* c = (unsigned char*)iter_operclass->second.umodelist; *c; ++c) + { + if (*c == '*') + { + memset(this->AllowedUserModes, (int)(true), sizeof(this->AllowedUserModes)); + } + else + { + this->AllowedUserModes[*c - 'A'] = true; + } + } + for (unsigned char* c = (unsigned char*)iter_operclass->second.cmodelist; *c; ++c) + { + if (*c == '*') + { + memset(this->AllowedChanModes, (int)(true), sizeof(this->AllowedChanModes)); + } + else + { + this->AllowedChanModes[*c - 'A'] = true; + } + } } myclass = strtok_r(NULL," ",&savept); } @@ -692,7 +758,7 @@ void User::Oper(const std::string &opertype, const std::string &opername) catch (...) { - ServerInstance->Log(DEBUG,"Exception in User::Oper()"); + ServerInstance->Logs->Log("OPER", DEBUG,"Exception in User::Oper()"); } } @@ -700,11 +766,27 @@ void User::UnOper() { if (IS_OPER(this)) { - // unset their oper type (what IS_OPER checks), and remove +o + /* Remove all oper only modes from the user when the deoper - Bug #466*/ + std::string moderemove("-"); + + for (unsigned char letter = 'A'; letter <= 'z'; letter++) + { + if (letter != 'o') + { + ModeHandler* mh = ServerInstance->Modes->FindMode(letter, MODETYPE_USER); + if (mh && mh->NeedsOper()) + moderemove += letter; + } + } + + const char* parameters[] = { this->nick, moderemove.c_str() }; + ServerInstance->Parser->CallHandler("MODE", parameters, 2, this); + + /* unset their oper type (what IS_OPER checks), and remove +o */ *this->oper = 0; this->modes[UM_OPERATOR] = 0; - // remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 + /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */ ServerInstance->Users->all_opers.remove(this); if (AllowedOperCommands) @@ -721,7 +803,12 @@ void User::QuitUser(InspIRCd* Instance, User *user, const std::string &quitreaso user->Write("ERROR :Closing link (%s@%s) [%s]", user->ident, user->host, *operreason ? operreason : quitreason.c_str()); user->quietquit = false; user->quitmsg = quitreason; - user->operquitmsg = operreason; + + if (!*operreason) + user->operquitmsg = quitreason; + else + user->operquitmsg = operreason; + Instance->GlobalCulls.AddItem(user); } @@ -809,14 +896,14 @@ void User::FullConnect() } this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network); - this->WriteServ("001 %s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host); - this->WriteServ("002 %s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION); - this->WriteServ("003 %s :This server was created %s %s", this->nick, __TIME__, __DATE__); - this->WriteServ("004 %s %s %s %s %s %s", this->nick, ServerInstance->Config->ServerName, VERSION, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); + this->WriteNumeric(001, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host); + this->WriteNumeric(002, "%s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION); + this->WriteNumeric(003, "%s :This server was created %s %s", this->nick, __TIME__, __DATE__); + this->WriteNumeric(004, "%s %s %s %s %s %s", this->nick, ServerInstance->Config->ServerName, VERSION, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); ServerInstance->Config->Send005(this); - this->WriteServ("042 %s %s :your unique ID", this->nick, this->uuid); + this->WriteNumeric(42, "%s %s :your unique ID", this->nick, this->uuid); this->ShowMOTD(); @@ -926,7 +1013,7 @@ bool User::ForceNickChange(const char* newnick) return false; } -void User::SetSockAddr(int protocol_family, const char* ip, int port) +void User::SetSockAddr(int protocol_family, const char* sip, int port) { this->cachedip = ""; @@ -938,7 +1025,7 @@ void User::SetSockAddr(int protocol_family, const char* ip, int port) sockaddr_in6* sin = new sockaddr_in6; sin->sin6_family = AF_INET6; sin->sin6_port = port; - inet_pton(AF_INET6, ip, &sin->sin6_addr); + inet_pton(AF_INET6, sip, &sin->sin6_addr); this->ip = (sockaddr*)sin; } break; @@ -948,12 +1035,12 @@ void User::SetSockAddr(int protocol_family, const char* ip, int port) sockaddr_in* sin = new sockaddr_in; sin->sin_family = AF_INET; sin->sin_port = port; - inet_pton(AF_INET, ip, &sin->sin_addr); + inet_pton(AF_INET, sip, &sin->sin_addr); this->ip = (sockaddr*)sin; } break; default: - ServerInstance->Log(DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick); + ServerInstance->Logs->Log("USERS",DEBUG,"Uh oh, I dont know protocol %d to be set on '%s'!", protocol_family, this->nick); break; } } @@ -1060,12 +1147,12 @@ void User::Write(std::string text) try { - ServerInstance->Logs->Log("USERIO", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str()); + ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"C[%d] O %s", this->GetFd(), text.c_str()); text.append("\r\n"); } catch (...) { - ServerInstance->Log(DEBUG,"Exception in User::Write() std::string::append"); + ServerInstance->Logs->Log("USEROUTPUT", DEBUG,"Exception in User::Write() std::string::append"); return; } @@ -1080,7 +1167,7 @@ void User::Write(std::string text) } catch (CoreException& modexcept) { - ServerInstance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); + ServerInstance->Logs->Log("USEROUTPUT", DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason()); } } else @@ -1129,6 +1216,32 @@ void User::WriteServ(const char* text, ...) } +void User::WriteNumeric(unsigned int numeric, const char* text, ...) +{ + va_list argsPtr; + char textbuffer[MAXBUF]; + + va_start(argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + this->WriteNumeric(numeric, std::string(textbuffer)); +} + +void User::WriteNumeric(unsigned int numeric, const std::string &text) +{ + char textbuffer[MAXBUF]; + int MOD_RESULT = 0; + + FOREACH_RESULT(I_OnNumeric, OnNumeric(this, numeric, text)); + + if (MOD_RESULT) + return; + + snprintf(textbuffer,MAXBUF,":%s %03u %s",ServerInstance->Config->ServerName, numeric, text.c_str()); + this->Write(std::string(textbuffer)); +} + void User::WriteFrom(User *user, const std::string &text) { char tb[MAXBUF]; @@ -1380,25 +1493,25 @@ bool User::ChangeName(const char* gecos) return true; } -bool User::ChangeDisplayedHost(const char* host) +bool User::ChangeDisplayedHost(const char* shost) { - if (!strcmp(host, this->dhost)) + if (!strcmp(shost, this->dhost)) return true; if (IS_LOCAL(this)) { int MOD_RESULT = 0; - FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,host)); + FOREACH_RESULT(I_OnChangeLocalUserHost,OnChangeLocalUserHost(this,shost)); if (MOD_RESULT) return false; - FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host)); + FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,shost)); } if (this->ServerInstance->Config->CycleHosts) this->WriteCommonExcept("QUIT :Changing hosts"); /* Fix by Om: User::dhost is 65 long, this was truncating some long hosts */ - strlcpy(this->dhost,host,64); + strlcpy(this->dhost,shost,64); this->InvalidateCache(); @@ -1414,7 +1527,7 @@ bool User::ChangeDisplayedHost(const char* host) } if (IS_LOCAL(this)) - this->WriteServ("396 %s %s :is now your displayed host",this->nick,this->dhost); + this->WriteNumeric(396, "%s %s :is now your displayed host",this->nick,this->dhost); return true; } @@ -1445,7 +1558,7 @@ bool User::ChangeIdent(const char* newident) return true; } -void User::SendAll(const char* command, char* text, ...) +void User::SendAll(const char* command, const char* text, ...) { char textbuffer[MAXBUF]; char formatbuffer[MAXBUF]; @@ -1585,7 +1698,7 @@ ConnectClass* User::SetClass(const std::string &explicit_name) /* deny change if change will take class over the limit */ if (found->limit && (found->RefCount + 1 >= found->limit)) { - ServerInstance->Log(DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit); + ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit); return this->MyClass; } @@ -1595,12 +1708,12 @@ ConnectClass* User::SetClass(const std::string &explicit_name) if (found == this->MyClass) // no point changing this shit :P return this->MyClass; this->MyClass->RefCount--; - ServerInstance->Log(DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount); + ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount); } this->MyClass = found; this->MyClass->RefCount++; - ServerInstance->Log(DEBUG, "User tied to new class -- connect refcount now: %u", this->MyClass->RefCount); + ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %u", this->MyClass->RefCount); } return this->MyClass; @@ -1633,7 +1746,7 @@ void User::PurgeEmptyChannels() } catch (...) { - ServerInstance->Log(DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()"); + ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::PurgeEmptyChannels to_delete.push_back()"); } } } @@ -1658,31 +1771,31 @@ void User::ShowMOTD() { if (!ServerInstance->Config->MOTD.size()) { - this->WriteServ("422 %s :Message of the day file is missing.",this->nick); + this->WriteNumeric(422, "%s :Message of the day file is missing.",this->nick); return; } - this->WriteServ("375 %s :%s message of the day", this->nick, ServerInstance->Config->ServerName); + this->WriteNumeric(375, "%s :%s message of the day", this->nick, ServerInstance->Config->ServerName); for (file_cache::iterator i = ServerInstance->Config->MOTD.begin(); i != ServerInstance->Config->MOTD.end(); i++) - this->WriteServ("372 %s :- %s",this->nick,i->c_str()); + this->WriteNumeric(372, "%s :- %s",this->nick,i->c_str()); - this->WriteServ("376 %s :End of message of the day.", this->nick); + this->WriteNumeric(376, "%s :End of message of the day.", this->nick); } void User::ShowRULES() { if (!ServerInstance->Config->RULES.size()) { - this->WriteServ("434 %s :RULES File is missing",this->nick); + this->WriteNumeric(434, "%s :RULES File is missing",this->nick); return; } - this->WriteServ("308 %s :- %s Server Rules -",this->nick,ServerInstance->Config->ServerName); + this->WriteNumeric(308, "%s :- %s Server Rules -",this->nick,ServerInstance->Config->ServerName); for (file_cache::iterator i = ServerInstance->Config->RULES.begin(); i != ServerInstance->Config->RULES.end(); i++) - this->WriteServ("232 %s :- %s",this->nick,i->c_str()); + this->WriteNumeric(232, "%s :- %s",this->nick,i->c_str()); - this->WriteServ("309 %s :End of RULES command.",this->nick); + this->WriteNumeric(309, "%s :End of RULES command.",this->nick); } void User::HandleEvent(EventType et, int errornum) @@ -1711,7 +1824,7 @@ void User::HandleEvent(EventType et, int errornum) } catch (...) { - ServerInstance->Log(DEBUG,"Exception in User::HandleEvent intercepted"); + ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::HandleEvent intercepted"); } /* If the user has raised an error whilst being processed, quit them now we're safe to */