summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/channels.cpp42
-rw-r--r--src/cmd_oper.cpp120
-rw-r--r--src/helperfuncs.cpp83
-rw-r--r--src/userprocess.cpp78
4 files changed, 171 insertions, 152 deletions
diff --git a/src/channels.cpp b/src/channels.cpp
index 3f2eca3f5..5918a4568 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -589,21 +589,21 @@ void server_kick_channel(userrec* user, chanrec* Ptr, char* reason, bool trigger
}
}
-void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
+void kick_channel(userrec *src,userrec *user, chanrec *chan, char* reason)
{
- if ((!src) || (!user) || (!Ptr) || (!reason))
+ if ((!src) || (!user) || (!chan) || (!reason))
{
log(DEFAULT,"*** BUG *** kick_channel was given an invalid parameter");
return;
}
- log(DEBUG,"kick_channel: removing: %s %s %s",user->nick,Ptr->name,src->nick);
+ log(DEBUG,"kick_channel: removing: %s %s %s",user->nick,chan->name,src->nick);
if (IS_LOCAL(src))
{
- if (!Ptr->HasUser(user))
+ if (!chan->HasUser(user))
{
- WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
+ WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, chan->name);
return;
}
int MOD_RESULT = 0;
@@ -611,28 +611,28 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
if (!is_uline(src->server))
{
MOD_RESULT = 0;
- FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,Ptr,reason));
+ FOREACH_RESULT(I_OnUserPreKick,OnUserPreKick(src,user,chan,reason));
if (MOD_RESULT == 1)
return;
}
/* Set to -1 by OnUserPreKick if explicit allow was set */
if (MOD_RESULT != -1)
{
- FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,Ptr,AC_KICK));
+ FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(src,user,chan,AC_KICK));
if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server)))
return;
if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server)))
{
- if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr)))
+ if ((cstatus(src,chan) < STATUS_HOP) || (cstatus(src,chan) < cstatus(user,chan)))
{
- if (cstatus(src,Ptr) == STATUS_HOP)
+ if (cstatus(src,chan) == STATUS_HOP)
{
- WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
+ WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, chan->name);
}
else
{
- WriteServ(src->fd,"482 %s %s :You must be at least a half-operator",src->nick, Ptr->name);
+ WriteServ(src->fd,"482 %s %s :You must be at least a half-operator",src->nick, chan->name);
}
return;
@@ -641,34 +641,34 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
}
}
- FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,Ptr,reason));
+ FOREACH_MOD(I_OnUserKick,OnUserKick(src,user,chan,reason));
for (std::vector<ucrec*>::const_iterator i = user->chans.begin(); i != user->chans.end(); i++)
{
/* zap it from the channel list of the user */
- if ((((ucrec*)(*i))->channel) && (((ucrec*)(*i))->channel == Ptr))
+ if ((((ucrec*)(*i))->channel) && (((ucrec*)(*i))->channel == chan))
{
- WriteChannel(Ptr,src,"KICK %s %s :%s",Ptr->name, user->nick, reason);
+ WriteChannel(chan,src,"KICK %s %s :%s",chan->name, user->nick, reason);
((ucrec*)(*i))->uc_modes = 0;
((ucrec*)(*i))->channel = NULL;
- log(DEBUG,"del_channel: unlinked: %s %s",user->nick,Ptr->name);
+ log(DEBUG,"del_channel: unlinked: %s %s",user->nick,chan->name);
break;
}
}
- if (!Ptr->DelUser(user))
+ if (!chan->DelUser(user))
/* if there are no users left on the channel */
{
- chan_hash::iterator iter = chanlist.find(Ptr->name);
+ chan_hash::iterator iter = chanlist.find(chan->name);
- log(DEBUG,"del_channel: destroying channel: %s",Ptr->name);
+ log(DEBUG,"del_channel: destroying channel: %s",chan->name);
/* kill the record */
if (iter != chanlist.end())
{
- log(DEBUG,"del_channel: destroyed: %s",Ptr->name);
- FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(Ptr));
- delete Ptr;
+ log(DEBUG,"del_channel: destroyed: %s",chan->name);
+ FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(chan));
+ delete chan;
chanlist.erase(iter);
}
}
diff --git a/src/cmd_oper.cpp b/src/cmd_oper.cpp
index 0c0026121..2e9a0b457 100644
--- a/src/cmd_oper.cpp
+++ b/src/cmd_oper.cpp
@@ -85,8 +85,6 @@ void cmd_oper::Handle (char **parameters, int pcnt, userrec *user)
char HostName[MAXBUF];
char TheHost[MAXBUF];
int j;
- bool found = false;
- bool fail2 = false;
snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
@@ -96,66 +94,82 @@ void cmd_oper::Handle (char **parameters, int pcnt, userrec *user)
Config->ConfValue("oper","password",i,Password,&Config->config_f);
Config->ConfValue("oper","type",i,OperType,&Config->config_f);
Config->ConfValue("oper","host",i,HostName,&Config->config_f);
- if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (OneOfMatches(TheHost,HostName)))
+
+ if (!strcmp(LoginName, parameters[0]))
{
- fail2 = true;
- for (j =0; j < Config->ConfValueEnum("type",&Config->config_f); j++)
+ /* login name matches */
+ if (!operstrcmp(Password, parameters[1]))
{
- Config->ConfValue("type","name",j,TypeName,&Config->config_f);
-
- if (!strcmp(TypeName,OperType))
+ /* password matches */
+ if (OneOfMatches(TheHost, HostName))
{
- /* found this oper's opertype */
- Config->ConfValue("type","host",j,HostName,&Config->config_f);
- if (*HostName)
- ChangeDisplayedHost(user,HostName);
- if (!isnick(TypeName))
+ for (j =0; j < Config->ConfValueEnum("type",&Config->config_f); j++)
{
- WriteServ(user->fd,"491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
- WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
- log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
- return;
+ Config->ConfValue("type","name",j,TypeName,&Config->config_f);
+
+ if (!strcmp(TypeName,OperType))
+ {
+ /* found this oper's opertype */
+ Config->ConfValue("type","host",j,HostName,&Config->config_f);
+ if (*HostName)
+ ChangeDisplayedHost(user,HostName);
+ if (!isnick(TypeName))
+ {
+ WriteServ(user->fd,"491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
+ WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
+ log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
+ return;
+ }
+
+ /* correct oper credentials */
+ WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
+ WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
+
+ if (!strchr(user->modes,'o'))
+ {
+ strcat(user->modes,"o");
+ WriteServ(user->fd,"MODE %s :+o",user->nick);
+ FOREACH_MOD(I_OnOper,OnOper(user,OperType));
+ log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
+ AddOper(user);
+ FOREACH_MOD(I_OnPostOper,OnPostOper(user,OperType));
+ }
+
+ strlcpy(user->oper,TypeName,NICKMAX-1);
+ return;
+ }
}
- strlcpy(user->oper,TypeName,NICKMAX-1);
- found = true;
- fail2 = false;
- break;
+
+ /* if we get to here, we have NOT found their opertype. */
+ WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
+ WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
+ log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
+ return;
+ }
+ else
+ {
+ /* no host matches */
+ WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
+ WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect hostname)!", user->nick, user->ident, user->host);
+ log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: host did not match.", user->nick, user->ident, user->host);
+ return;
}
}
- }
- if (found)
- break;
- }
- if (found)
- {
- /* correct oper credentials */
- WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
- WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
- if (!strchr(user->modes,'o'))
- {
- strcat(user->modes,"o");
- WriteServ(user->fd,"MODE %s :+o",user->nick);
- FOREACH_MOD(I_OnOper,OnOper(user,OperType));
- log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
- AddOper(user);
- FOREACH_MOD(I_OnPostOper,OnPostOper(user,OperType));
- }
- }
- else
- {
- if (!fail2)
- {
- WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
- WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
- log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
- }
- else
- {
- WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
- WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
- log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
+ else
+ {
+ /* password WRONG */
+ WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
+ WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect password)!", user->nick, user->ident, user->host);
+ log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: password did not match.", user->nick, user->ident, user->host);
+ return;
+ }
}
}
+
+ /* if we get here, invalid oper login */
+ WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
+ WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect oper (%s))!", user->nick, user->ident, user->host, parameters[0]);
+ log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: incorrect oper (%s)", user->nick, user->ident, user->host, parameters[0]);
return;
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index 4905cfabd..073b5b37c 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -61,6 +61,8 @@ extern std::vector<userrec*> all_opers;
extern user_hash clientlist;
extern chan_hash chanlist;
+char LOG_FILE[MAXBUF];
+
extern std::vector<userrec*> local_users;
static char TIMESTR[26];
@@ -1791,3 +1793,84 @@ bool charremove(char* mp, char remove)
return shift_down;
}
+
+void OpenLog(char** argv, int argc)
+{
+ if (!*LOG_FILE)
+ {
+ if (Config->logpath == "")
+ {
+ Config->logpath = GetFullProgDir(argv,argc) + "/ircd.log";
+ }
+ }
+ else
+ {
+ Config->log_file = fopen(LOG_FILE,"a+");
+
+ if (!Config->log_file)
+ {
+ printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
+ Exit(ERROR);
+ }
+
+ return;
+ }
+
+ Config->log_file = fopen(Config->logpath.c_str(),"a+");
+
+ if (!Config->log_file)
+ {
+ printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
+ Exit(ERROR);
+ }
+}
+
+void CheckRoot()
+{
+ if (geteuid() == 0)
+ {
+ printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
+ log(DEFAULT,"InspIRCd: startup: not starting with UID 0!");
+ Exit(ERROR);
+ }
+}
+
+void CheckDie()
+{
+ if (*Config->DieValue)
+ {
+ printf("WARNING: %s\n\n",Config->DieValue);
+ log(DEFAULT,"Uh-Oh, somebody didn't read their config file: '%s'",Config->DieValue);
+ Exit(ERROR);
+ }
+}
+
+/* We must load the modules AFTER initializing the socket engine, now */
+void LoadAllModules(InspIRCd* ServerInstance)
+{
+ char configToken[MAXBUF];
+ Config->module_names.clear();
+ MODCOUNT = -1;
+
+ for (int count = 0; count < Config->ConfValueEnum("module",&Config->config_f); count++)
+ {
+ Config->ConfValue("module","name",count,configToken,&Config->config_f);
+ printf("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
+
+ if (!ServerInstance->LoadModule(configToken))
+ {
+ log(DEFAULT,"Exiting due to a module loader error.");
+ printf("\nThere was an error loading a module: %s\n\n",ServerInstance->ModuleError());
+ Exit(0);
+ }
+
+ if (!ServerInstance->LoadModule(configToken))
+ {
+ log(DEFAULT,"Exiting due to a module loader error.");
+ printf("\nThere was an error loading a module: %s\n\n",ServerInstance->ModuleError());
+ Exit(0);
+ }
+ }
+
+ log(DEFAULT,"Total loaded modules: %lu",(unsigned long)MODCOUNT+1);
+}
diff --git a/src/userprocess.cpp b/src/userprocess.cpp
index 67cd3cca9..956ddb61b 100644
--- a/src/userprocess.cpp
+++ b/src/userprocess.cpp
@@ -61,7 +61,6 @@ using namespace std;
#include "command_parse.h"
#include "cull_list.h"
-extern int MODCOUNT;
extern struct sockaddr_in client,server;
extern socklen_t length;
extern std::vector<Module*> modules;
@@ -71,7 +70,6 @@ extern time_t TIME;
extern time_t OLDTIME;
extern std::vector<userrec*> local_users;
extern InspSocket* socket_ref[MAX_DESCRIPTORS];
-char LOG_FILE[MAXBUF];
extern InspIRCd* ServerInstance;
extern ServerConfig *Config;
@@ -420,79 +418,3 @@ void DoBackgroundUserStuff(time_t TIME)
GlobalGoners.Apply();
}
-void OpenLog(char** argv, int argc)
-{
- if (!*LOG_FILE)
- {
- if (Config->logpath == "")
- {
- Config->logpath = GetFullProgDir(argv,argc) + "/ircd.log";
- }
- }
- else
- {
- Config->log_file = fopen(LOG_FILE,"a+");
-
- if (!Config->log_file)
- {
- printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
- Exit(ERROR);
- }
-
- return;
- }
-
- Config->log_file = fopen(Config->logpath.c_str(),"a+");
-
- if (!Config->log_file)
- {
- printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
- Exit(ERROR);
- }
-}
-
-
-void CheckRoot()
-{
- if (geteuid() == 0)
- {
- printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
- log(DEFAULT,"InspIRCd: startup: not starting with UID 0!");
- Exit(ERROR);
- }
-}
-
-
-void CheckDie()
-{
- if (*Config->DieValue)
- {
- printf("WARNING: %s\n\n",Config->DieValue);
- log(DEFAULT,"Uh-Oh, somebody didn't read their config file: '%s'",Config->DieValue);
- Exit(ERROR);
- }
-}
-
-/* We must load the modules AFTER initializing the socket engine, now */
-void LoadAllModules(InspIRCd* ServerInstance)
-{
- char configToken[MAXBUF];
- Config->module_names.clear();
-
- MODCOUNT = -1;
-
- for (int count = 0; count < Config->ConfValueEnum("module",&Config->config_f); count++)
- {
- Config->ConfValue("module","name",count,configToken,&Config->config_f);
- printf("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
-
- if (!ServerInstance->LoadModule(configToken))
- {
- log(DEFAULT,"Exiting due to a module loader error.");
- printf("\nThere was an error loading a module: %s\n\n",ServerInstance->ModuleError());
- Exit(0);
- }
- }
-
- log(DEFAULT,"Total loaded modules: %lu",(unsigned long)MODCOUNT+1);
-}