]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
fixes to /STATS P
[user/henk/code/inspircd.git] / src / inspircd.cpp
index 064259c06c1a60f8e949a40d84b1319130f30a34..4250bdc75e9147a8bb1e40a0cca079fa1d4f2550 100644 (file)
@@ -85,6 +85,10 @@ int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read
 extern int MaxWhoResults;
 time_t nb_start = 0;
 
+bool AllowHalfop = true;
+bool AllowProtect = true;
+bool AllowFounder = true;
+
 extern vector<Module*> modules;
 std::vector<std::string> module_names;
 extern vector<ircd_module*> factory;
@@ -301,6 +305,7 @@ void readfile(file_cache &F, const char* fname)
 void ReadConfig(void)
 {
        char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF];
+       char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF];
        ConnectClass c;
        
        LoadConf(CONFIG_FILE,&config_f);
@@ -321,8 +326,14 @@ void ReadConfig(void)
        ConfValue("options","loglevel",0,dbg,&config_f);
        ConfValue("options","netbuffersize",0,NB,&config_f);
        ConfValue("options","maxwho",0,MW,&config_f);
+       ConfValue("options","allowhalfop",0,AH,&config_f);
+       ConfValue("options","allowprotect",0,AP,&config_f);
+       ConfValue("options","allowfounder",0,AF,&config_f);
        NetBufferSize = atoi(NB);
        MaxWhoResults = atoi(MW);
+       AllowHalfop = ((!strcasecmp(AH,"true")) || (!strcasecmp(AH,"1")) || (!strcasecmp(AH,"yes")));
+       AllowProtect = ((!strcasecmp(AP,"true")) || (!strcasecmp(AP,"1")) || (!strcasecmp(AP,"yes")));
+       AllowFounder = ((!strcasecmp(AF,"true")) || (!strcasecmp(AF,"1")) || (!strcasecmp(AF,"yes")));
        if ((!NetBufferSize) || (NetBufferSize > 65535) || (NetBufferSize < 1024))
        {
                log(DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
@@ -1122,6 +1133,7 @@ char* chanmodes(chanrec *chan)
        }
        if (strcmp(chan->key,""))
        {
+               strncat(sparam," ",MAXBUF);
                strncat(sparam,chan->key,MAXBUF);
        }
        if (chan->limit)
@@ -1298,8 +1310,9 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
 
        if (!FindChan(cname))
        {
+               int MOD_RESULT = 0;
                FOREACH_RESULT(OnUserPreJoin(user,NULL,cname));
-               if (MOD_RESULT) {
+               if (MOD_RESULT == 1) {
                        return NULL;
                }
 
@@ -1335,77 +1348,83 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                        // and bans (used by servers)
                        if (!override)
                        {
+                               int MOD_RESULT = 0;
                                FOREACH_RESULT(OnUserPreJoin(user,Ptr,cname));
-                               if (MOD_RESULT) {
+                               if (MOD_RESULT == 1) {
                                        return NULL;
                                }
                                
-                               if (strcmp(Ptr->key,""))
+                               if (MOD_RESULT == 0) 
                                {
-                                       log(DEBUG,"add_channel: %s has key %s",Ptr->name,Ptr->key);
-                                       if (!key)
-                                       {
-                                               log(DEBUG,"add_channel: no key given in JOIN");
-                                               WriteServ(user->fd,"475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
-                                               return NULL;
-                                       }
-                                       else
+                                       
+                                       if (strcmp(Ptr->key,""))
                                        {
-                                               log(DEBUG,"key at %p is %s",key,key);
-                                               if (strcasecmp(key,Ptr->key))
+                                               log(DEBUG,"add_channel: %s has key %s",Ptr->name,Ptr->key);
+                                               if (!key)
                                                {
-                                                       log(DEBUG,"add_channel: bad key given in JOIN");
-                                                       WriteServ(user->fd,"475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
+                                                       log(DEBUG,"add_channel: no key given in JOIN");
+                                                       WriteServ(user->fd,"475 %s %s :Cannot join channel (Requires key)",user->nick, Ptr->name);
                                                        return NULL;
                                                }
+                                               else
+                                               {
+                                                       log(DEBUG,"key at %p is %s",key,key);
+                                                       if (strcasecmp(key,Ptr->key))
+                                                       {
+                                                               log(DEBUG,"add_channel: bad key given in JOIN");
+                                                               WriteServ(user->fd,"475 %s %s :Cannot join channel (Incorrect key)",user->nick, Ptr->name);
+                                                               return NULL;
+                                                       }
+                                               }
                                        }
-                               }
-                               log(DEBUG,"add_channel: no key");
-       
-                               if (Ptr->inviteonly)
-                               {
-                                       log(DEBUG,"add_channel: channel is +i");
-                                       if (user->IsInvited(Ptr->name))
-                                       {
-                                               /* user was invited to channel */
-                                               /* there may be an optional channel NOTICE here */
-                                       }
-                                       else
+                                       log(DEBUG,"add_channel: no key");
+               
+                                       if (Ptr->inviteonly)
                                        {
-                                               WriteServ(user->fd,"473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
-                                               return NULL;
+                                               log(DEBUG,"add_channel: channel is +i");
+                                               if (user->IsInvited(Ptr->name))
+                                               {
+                                                       /* user was invited to channel */
+                                                       /* there may be an optional channel NOTICE here */
+                                               }
+                                               else
+                                               {
+                                                       WriteServ(user->fd,"473 %s %s :Cannot join channel (Invite only)",user->nick, Ptr->name);
+                                                       return NULL;
+                                               }
                                        }
-                               }
-                               log(DEBUG,"add_channel: channel is not +i");
-       
-                               if (Ptr->limit)
-                               {
-                                       if (usercount(Ptr) == Ptr->limit)
+                                       log(DEBUG,"add_channel: channel is not +i");
+               
+                                       if (Ptr->limit)
                                        {
-                                               WriteServ(user->fd,"471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
-                                               return NULL;
+                                               if (usercount(Ptr) == Ptr->limit)
+                                               {
+                                                       WriteServ(user->fd,"471 %s %s :Cannot join channel (Channel is full)",user->nick, Ptr->name);
+                                                       return NULL;
+                                               }
                                        }
-                               }
-                               
-                               log(DEBUG,"add_channel: about to walk banlist");
-       
-                               /* check user against the channel banlist */
-                               if (Ptr)
-                               {
-                                       if (Ptr->bans.size())
+                                       
+                                       log(DEBUG,"add_channel: about to walk banlist");
+               
+                                       /* check user against the channel banlist */
+                                       if (Ptr)
                                        {
-                                               for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
+                                               if (Ptr->bans.size())
                                                {
-                                                       if (match(user->GetFullHost(),i->data))
+                                                       for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
                                                        {
-                                                               WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
-                                                               return NULL;
+                                                               if (match(user->GetFullHost(),i->data))
+                                                               {
+                                                                       WriteServ(user->fd,"474 %s %s :Cannot join channel (You're banned)",user->nick, Ptr->name);
+                                                                       return NULL;
+                                                               }
                                                        }
                                                }
                                        }
-                               }
+                                       
+                                       log(DEBUG,"add_channel: bans checked");
                                
-                               log(DEBUG,"add_channel: bans checked");
+                               }
                                
 
                                if ((Ptr) && (user))
@@ -1451,7 +1470,14 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri
                        {
                                // use the stamdard J token with no privilages.
                                char buffer[MAXBUF];
-                               snprintf(buffer,MAXBUF,"J %s %s",user->nick,Ptr->name);
+                               if (created == 2)
+                               {
+                                       snprintf(buffer,MAXBUF,"J %s @%s",user->nick,Ptr->name);
+                               }
+                               else
+                               {
+                                       snprintf(buffer,MAXBUF,"J %s %s",user->nick,Ptr->name);
+                               }
                                NetSendToAll(buffer);
                        }
 
@@ -1581,18 +1607,28 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason)
                WriteServ(src->fd,"441 %s %s %s :They are not on that channel",src->nick, user->nick, Ptr->name);
                return;
        }
-       if (((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr))) && (!is_uline(src->server)))
+
+       int MOD_RESULT = 0;
+       FOREACH_RESULT(OnAccessCheck(src,user,Ptr,AC_KICK));
+       
+       if (MOD_RESULT == ACR_DENY)
+               return;
+
+       if (MOD_RESULT == ACR_DEFAULT)
        {
-               if (cstatus(src,Ptr) == STATUS_HOP)
-               {
-                       WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
-               }
-               else
+               if (((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr))) && (!is_uline(src->server)))
                {
-                       WriteServ(src->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",src->nick, Ptr->name);
+                       if (cstatus(src,Ptr) == STATUS_HOP)
+                       {
+                               WriteServ(src->fd,"482 %s %s :You must be a channel operator",src->nick, Ptr->name);
+                       }
+                       else
+                       {
+                               WriteServ(src->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",src->nick, Ptr->name);
+                       }
+                       
+                       return;
                }
-               
-               return;
        }
        
        for (int i =0; i != MAXCHANS; i++)
@@ -2323,7 +2359,7 @@ void ConnectUser(userrec *user)
        WriteOpers("*** Client connecting on port %d: %s!%s@%s",user->port,user->nick,user->ident,user->host);
        
        char buffer[MAXBUF];
-       snprintf(buffer,MAXBUF,"N %d %s %s %s %s +%s %s :%s",user->age,user->nick,user->host,user->dhost,user->ident,user->modes,ServerName,user->fullname);
+       snprintf(buffer,MAXBUF,"N %d %s %s %s %s +%s %s %s :%s",user->age,user->nick,user->host,user->dhost,user->ident,user->modes,user->ip,ServerName,user->fullname);
        NetSendToAll(buffer);
 }
 
@@ -2573,7 +2609,8 @@ void process_command(userrec *user, char* cmd)
        // another phidjit bug...
        if (total_params > 126)
        {
-               kill_link(user,"Protocol violation (1)");
+               //kill_link(user,"Protocol violation (1)");
+               WriteServ(user->fd,"421 %s * :Unknown command",user->nick);
                return;
        }
        
@@ -2583,7 +2620,7 @@ void process_command(userrec *user, char* cmd)
        for (int i = 0; i <= MODCOUNT; i++)
        {
                std::string oldtmp = tmp;
-               modules[i]->OnServerRaw(tmp,true);
+               modules[i]->OnServerRaw(tmp,true,user);
                if (oldtmp != tmp)
                {
                        log(DEBUG,"A Module changed the input string!");
@@ -2656,7 +2693,8 @@ void process_command(userrec *user, char* cmd)
        
        if (strlen(command)>MAXCOMMAND)
        {
-               kill_link(user,"Protocol violation (2)");
+               //kill_link(user,"Protocol violation (2)");
+               WriteServ(user->fd,"421 %s * :Unknown command",user->nick);
                return;
        }
        
@@ -2666,9 +2704,10 @@ void process_command(userrec *user, char* cmd)
                {
                        if (((command[x] < '0') || (command[x]> '9')) && (command[x] != '-'))
                        {
-                               if (!strchr("@!\"$%^&*(){}[]_-=+;:'#~,.<>/?\\|`",command[x]))
+                               if (strchr("@!\"$%^&*(){}[]_=+;:'#~,<>/?\\|`",command[x]))
                                {
-                                       kill_link(user,"Protocol violation (3)");
+                                       //kill_link(user,"Protocol violation (3)");
+                                       WriteServ(user->fd,"421 %s * :Unknown command",user->nick);
                                        return;
                                }
                        }
@@ -2720,6 +2759,13 @@ void process_command(userrec *user, char* cmd)
                                                cmd_found = 1;
                                                return;
                                        }
+                                       if ((cmdlist[i].flags_needed) && (!user->HasPermission(command)))
+                                       {
+                                               log(DEBUG,"process_command: permission denied: %s %s",user->nick,command);
+                                               WriteServ(user->fd,"481 %s :Permission Denied- Oper type %s does not have access to command %s",user->nick,user->oper,command);
+                                               cmd_found = 1;
+                                               return;
+                                       }
                                        /* if the command isnt USER, PASS, or NICK, and nick is empty,
                                         * deny command! */
                                        if ((strncmp(command,"USER",4)) && (strncmp(command,"NICK",4)) && (strncmp(command,"PASS",4)))
@@ -2839,6 +2885,7 @@ void SetupCommandTable(void)
        createcommand("GLINE",handle_gline,'o',1);
        createcommand("ZLINE",handle_zline,'o',1);
        createcommand("QLINE",handle_qline,'o',1);
+       createcommand("SERVER",handle_server,0,0);
 }
 
 void process_buffer(const char* cmdbuf,userrec *user)
@@ -2904,8 +2951,17 @@ void DoSync(serverrec* serv, char* tcp_host)
        // send users and channels
        for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
        {
-               snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->server,u->second->fullname);
+               snprintf(data,MAXBUF,"N %d %s %s %s %s +%s %s %s :%s",u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->server,u->second->fullname);
                serv->SendPacket(data,tcp_host);
+               for (int i = 0; i <= MODCOUNT; i++)
+               {
+                       string_list l = modules[i]->OnUserSync(u->second);
+                       for (int j = 0; j < l.size(); j++)
+                       {
+                               strncpy(data,l[j].c_str(),MAXBUF);
+                               serv->SendPacket(data,tcp_host);
+                       }
+               }
                if (strcmp(chlist(u->second),""))
                {
                        snprintf(data,MAXBUF,"J %s %s",u->second->nick,chlist(u->second));
@@ -2917,6 +2973,15 @@ void DoSync(serverrec* serv, char* tcp_host)
        {
                snprintf(data,MAXBUF,"M %s +%s",c->second->name,chanmodes(c->second));
                serv->SendPacket(data,tcp_host);
+               for (int i = 0; i <= MODCOUNT; i++)
+               {
+                       string_list l = modules[i]->OnChannelSync(c->second);
+                       for (int j = 0; j < l.size(); j++)
+                       {
+                               strncpy(data,l[j].c_str(),MAXBUF);
+                               serv->SendPacket(data,tcp_host);
+                       }
+               }
                if (strcmp(c->second->topic,""))
                {
                        snprintf(data,MAXBUF,"T %d %s %s :%s",c->second->topicset,c->second->setby,c->second->name,c->second->topic);