X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Finspircd.cpp;h=87da59b5736edbc7b11387692932c217cd14df7d;hb=dada179fb63917ced15976da5e83c7c6ddc65f2f;hp=88b9e2042127af98768872a4f047ef1a3a101d8c;hpb=ba0e6d9c7b743e7c78593e0398e37b0210f18e3f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 88b9e2042..87da59b57 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -36,7 +36,7 @@ using namespace std; #ifdef USE_EPOLL #include -#define EP_DELAY 50 +#define EP_DELAY 5 #endif #include @@ -51,6 +51,9 @@ using namespace std; #include #include #include +#ifdef THREADED_DNS +#include +#endif #include "users.h" #include "ctables.h" #include "globals.h" @@ -67,6 +70,7 @@ using namespace std; #include "hashcomp.h" #include "socketengine.h" #include "socket.h" +#include "dns.h" int LogLevel = DEFAULT; char ServerName[MAXBUF]; @@ -140,7 +144,7 @@ userrec* fd_ref_table[65536]; int statsAccept = 0, statsRefused = 0, statsUnknown = 0, statsCollisions = 0, statsDns = 0, statsDnsGood = 0, statsDnsBad = 0, statsConnects = 0, statsSent= 0, statsRecv = 0; -serverrec* me[32]; +Server* MyServer = new Server; FILE *log_file; @@ -160,7 +164,7 @@ struct linger linger = { 0 }; char MyExecutable[1024]; int boundPortCount = 0; int portCount = 0, SERVERportCount = 0, ports[MAXSOCKS]; -int defaultRoute = 0; + char ModPath[MAXBUF]; /* prototypes */ @@ -172,7 +176,6 @@ char* Passwd(userrec *user); bool IsDenied(userrec *user); void AddWhoWas(userrec* u); -std::vector auth_cookies; std::stringstream config_f(stringstream::in | stringstream::out); std::vector all_opers; @@ -203,7 +206,8 @@ const char* FindServerNamePtr(std::string servername) if (*a == servername) return a->c_str(); } - return ""; + AddServerName(servername); + return FindServerNamePtr(servername); } void DeleteOper(userrec* user) @@ -293,7 +297,7 @@ void ReadConfig(bool bail, userrec* user) } else { - WriteOpers("There were errors in the configuration file:",user->nick); + WriteOpers("There were errors in the configuration file:"); while (!errstr.eof()) { errstr.getline(dataline,1024); @@ -567,10 +571,13 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri if (!FindChan(cname)) { - MOD_RESULT = 0; - FOREACH_RESULT(OnUserPreJoin(user,NULL,cname)); - if (MOD_RESULT == 1) { - return NULL; + if (!strcasecmp(ServerName,user->server)) + { + MOD_RESULT = 0; + FOREACH_RESULT(OnUserPreJoin(user,NULL,cname)); + if (MOD_RESULT == 1) { + return NULL; + } } /* create a new one */ @@ -600,9 +607,9 @@ chanrec* add_channel(userrec *user, const char* cn, const char* key, bool overri { log(DEBUG,"add_channel: joining to: %s",Ptr->name); - // the override flag allows us to bypass channel modes + // remote users are allowed us to bypass channel modes // and bans (used by servers) - if ((!override) || (!strcasecmp(user->server,ServerName))) + if (!strcasecmp(ServerName,user->server)) { log(DEBUG,"Not overriding..."); MOD_RESULT = 0; @@ -852,12 +859,12 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason) int MOD_RESULT = 0; FOREACH_RESULT(OnAccessCheck(src,user,Ptr,AC_KICK)); - if (MOD_RESULT == ACR_DENY) + if ((MOD_RESULT == ACR_DENY) && (!is_uline(src->server))) return; - if (MOD_RESULT == ACR_DEFAULT) + if ((MOD_RESULT == ACR_DEFAULT) || (!is_uline(src->server))) { - if (((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr))) && (!is_uline(src->server))) + if ((cstatus(src,Ptr) < STATUS_HOP) || (cstatus(src,Ptr) < cstatus(user,Ptr))) { if (cstatus(src,Ptr) == STATUS_HOP) { @@ -872,10 +879,13 @@ void kick_channel(userrec *src,userrec *user, chanrec *Ptr, char* reason) } } - MOD_RESULT = 0; - FOREACH_RESULT(OnUserPreKick(src,user,Ptr,reason)); - if (MOD_RESULT) - return; + if (!is_uline(src->server)) + { + MOD_RESULT = 0; + FOREACH_RESULT(OnUserPreKick(src,user,Ptr,reason)); + if (MOD_RESULT) + return; + } FOREACH_MOD OnUserKick(src,user,Ptr,reason); @@ -1097,7 +1107,7 @@ void kill_link(userrec *user,const char* r) log(DEBUG,"closing fd %lu",(unsigned long)user->fd); if (user->registered == 7) { - FOREACH_MOD OnUserQuit(user); + FOREACH_MOD OnUserQuit(user,reason); WriteCommonExcept(user,"QUIT :%s",reason); } @@ -1152,7 +1162,7 @@ void kill_link_silent(userrec *user,const char* r) user->FlushWriteBuf(); if (user->registered == 7) { - FOREACH_MOD OnUserQuit(user); + FOREACH_MOD OnUserQuit(user,reason); WriteCommonExcept(user,"QUIT :%s",reason); } @@ -1180,6 +1190,15 @@ void kill_link_silent(userrec *user,const char* r) } +/*void *task(void *arg) +{ + for (;;) { + cout << (char *)arg; + cout.flush(); + } + return NULL; +}*/ + int main(int argc, char** argv) { Start(); @@ -1206,6 +1225,7 @@ int main(int argc, char** argv) } } } + strlcpy(MyExecutable,argv[0],MAXBUF); // initialize the lowercase mapping table @@ -1318,6 +1338,51 @@ void AddWhoWas(userrec* u) } } +#ifdef THREADED_DNS +void* dns_task(void* arg) +{ + userrec* u = (userrec*)arg; + log(DEBUG,"DNS thread for user %s",u->nick); + DNS dns1; + DNS dns2; + std::string host; + std::string ip; + if (dns1.ReverseLookup(u->ip)) + { + log(DEBUG,"DNS Step 1"); + while (!dns1.HasResult()) + { + usleep(100); + } + host = dns1.GetResult(); + if (host != "") + { + log(DEBUG,"DNS Step 2: '%s'",host.c_str()); + if (dns2.ForwardLookup(host)) + { + while (!dns2.HasResult()) + { + usleep(100); + } + ip = dns2.GetResultIP(); + log(DEBUG,"DNS Step 3 '%s'(%d) '%s'(%d)",ip.c_str(),ip.length(),u->ip,strlen(u->ip)); + if (ip == std::string(u->ip)) + { + log(DEBUG,"DNS Step 4"); + if (host.length() < 160) + { + log(DEBUG,"DNS Step 5"); + strcpy(u->host,host.c_str()); + strcpy(u->dhost,host.c_str()); + } + } + } + } + } + u->dns_done = true; + return NULL; +} +#endif /* add a client connection to the sockets list */ void AddClient(int socket, char* host, int port, bool iscached, char* ip) @@ -1443,6 +1508,12 @@ void AddClient(int socket, char* host, int port, bool iscached, char* ip) } fd_ref_table[socket] = clientlist[tempnick]; engine_add_fd; + + // initialize their dns lookup thread + //if (pthread_create(&clientlist[tempnick]->dnsthread, NULL, dns_task, (void *)clientlist[tempnick]) != 0) + //{ + // log(DEBUG,"Failed to create DNS lookup thread for user %s",clientlist[tempnick]->nick); + //} } /* shows the message of the day, and any other on-logon stuff */ @@ -1486,8 +1557,6 @@ void FullConnectUser(userrec* user) } } - // fix by brain: move this below the xline checks to prevent spurious quits going onto the net that dont belong - user->registered = 7; WriteServ(user->fd,"NOTICE Auth :Welcome to \002%s\002!",Network); WriteServ(user->fd,"001 %s :Welcome to the %s IRC Network %s!%s@%s",user->nick,Network,user->nick,user->ident,user->host); @@ -1496,7 +1565,7 @@ void FullConnectUser(userrec* user) WriteServ(user->fd,"004 %s %s %s iowghraAsORVSxNCWqBzvdHtGI lvhopsmntikrRcaqOALQbSeKVfHGCuzN",user->nick,ServerName,VERSION); // the neatest way to construct the initial 005 numeric, considering the number of configure constants to go in it... std::stringstream v; - v << "MESHED WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS; + v << "WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS; v << " MAXBANS=60 NICKLEN=" << NICKMAX; v << " TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=20 AWAYLEN=" << MAXAWAY << " CHANMODES=ohvb,k,l,psmnti NETWORK="; v << Network; @@ -1522,9 +1591,11 @@ void FullConnectUser(userrec* user) } ShowMOTD(user); - // fix by brain: these should be AFTER the N token, so other servers know what the HELL we're on about... :) + // fix 3 by brain, move registered = 7 below these so that spurious modes and host changes dont go out + // onto the network and produce 'fake direction' FOREACH_MOD OnUserConnect(user); FOREACH_MOD OnGlobalConnect(user); + user->registered = 7; WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip); } @@ -1550,83 +1621,75 @@ std::string GetVersionString() v2 = strtok_r(s1," ",&savept); s1 = savept; char socketengine[] = engine_name; - snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s (O=%lu) [SE=%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,socketengine); +#ifdef THREADED_DNS + char dnsengine[] = "multithread"; +#else + char dnsengine[] = "singlethread"; +#endif + snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s [FLAGS=%lu,%s,%s]",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION,socketengine,dnsengine); return versiondata; } void handle_version(char **parameters, int pcnt, userrec *user) { - if (!pcnt) - { - WriteServ(user->fd,"351 %s :%s",user->nick,GetVersionString().c_str()); - } - else + WriteServ(user->fd,"351 %s :%s",user->nick,GetVersionString().c_str()); +} + + +bool is_valid_cmd(const char* commandname, int pcnt, userrec * user) +{ + for (unsigned int i = 0; i < cmdlist.size(); i++) { - if (!strcmp(parameters[0],"*")) + if (!strcasecmp(cmdlist[i].command,commandname)) { - for (int j = 0; j < 32; j++) + if (cmdlist[i].handler_function) { - if (me[j] != NULL) + if ((pcnt>=cmdlist[i].min_params) && (strcasecmp(cmdlist[i].source,""))) { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) + if ((strchr(user->modes,cmdlist[i].flags_needed)) || (!cmdlist[i].flags_needed)) { - WriteServ(user->fd,"351 %s :Server %d:%d (%s): %s",user->nick,j,x,me[j]->connectors[x].GetServerName().c_str(),me[j]->connectors[x].GetVersionString().c_str()); - } - } - } - return; - } - if (match(ServerName,parameters[0])) - { - WriteServ(user->fd,"351 %s :%s",user->nick,GetVersionString().c_str()); - return; - } - bool displayed = false, found = false; - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int x = 0; x < me[j]->connectors.size(); x++) - { - if (match(me[j]->connectors[x].GetServerName().c_str(),parameters[0])) - { - found = true; - if ((me[j]->connectors[x].GetVersionString() != "") && (!displayed)) + if (cmdlist[i].flags_needed) { - displayed = true; - WriteServ(user->fd,"351 %s :%s",user->nick,me[j]->connectors[x].GetVersionString().c_str()); + if ((user->HasPermission((char*)commandname)) || (is_uline(user->server))) + { + return true; + } + else + { + return false; + } } + return true; } } } } - if ((!displayed) && (found)) - { - WriteServ(user->fd,"402 %s %s :Server %s has no version information",user->nick,parameters[0],parameters[0]); - return; - } - if (!found) - { - WriteServ(user->fd,"402 %s %s :No such server",user->nick,parameters[0]); - } } - return; + return false; } - // calls a handler function for a command void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user) { - for (unsigned int i = 0; i < cmdlist.size(); i++) + for (unsigned int i = 0; i < cmdlist.size(); i++) + { + if (!strcasecmp(cmdlist[i].command,commandname)) { - if (!strcasecmp(cmdlist[i].command,commandname)) + if (cmdlist[i].handler_function) { - if (cmdlist[i].handler_function) + if (pcnt>=cmdlist[i].min_params) { - if (pcnt>=cmdlist[i].min_params) + if ((strchr(user->modes,cmdlist[i].flags_needed)) || (!cmdlist[i].flags_needed)) { - if (strchr(user->modes,cmdlist[i].flags_needed)) + if (cmdlist[i].flags_needed) + { + if ((user->HasPermission((char*)commandname)) || (is_uline(user->server))) + { + cmdlist[i].handler_function(parameters,pcnt,user); + } + } + else { cmdlist[i].handler_function(parameters,pcnt,user); } @@ -1634,6 +1697,7 @@ void call_handler(const char* commandname,char **parameters, int pcnt, userrec * } } } + } } @@ -2120,6 +2184,15 @@ bool UnloadModule(const char* filename) snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)"); return false; } + /* Give the module a chance to tidy out all its metadata */ + for (chan_hash::iterator c = chanlist.begin(); c != chanlist.end(); c++) + { + modules[j]->OnCleanup(TYPE_CHANNEL,c->second); + } + for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++) + { + modules[j]->OnCleanup(TYPE_USER,u->second); + } FOREACH_MOD OnUnloadModule(modules[j],module_names[j]); // found the module log(DEBUG,"Deleting module..."); @@ -2180,7 +2253,7 @@ bool LoadModule(const char* filename) } if (factory[MODCOUNT+1]->factory) { - Module* m = factory[MODCOUNT+1]->factory->CreateModule(); + Module* m = factory[MODCOUNT+1]->factory->CreateModule(MyServer); modules[MODCOUNT+1] = m; /* save the module and the module's classfactory, if * this isnt done, random crashes can occur :/ */ @@ -2207,25 +2280,6 @@ bool LoadModule(const char* filename) } -bool GotServer(std::string name) -{ - for (int j = 0; j < 32; j++) - { - if (me[j] != NULL) - { - for (unsigned int k = 0; k < me[j]->connectors.size(); k++) - { - if (name == me[j]->connectors[k].GetServerName()) - { - return true; - } - } - } - } - return false; -} - - int InspIRCd(char** argv, int argc) { struct sockaddr_in client,server; @@ -2409,17 +2463,24 @@ int InspIRCd(char** argv, int argc) OLDTIME = TIME; TIME = time(NULL); +#ifndef THREADED_DNS dns_poll(); +#endif + unsigned int numsockets = module_sockets.size(); for (std::vector::iterator a = module_sockets.begin(); a < module_sockets.end(); a++) { InspSocket* s = (InspSocket*)*a; - if (!s->Poll()) + if ((s) && (!s->Poll())) { - delete s; + log(DEBUG,"Socket poll returned false, close and bail"); + s->Close(); module_sockets.erase(a); + delete s; break; } + // we gained a socket, sarper + if (module_sockets.size() != numsockets) break; } // *FIX* Instead of closing sockets in kill_link when they receive the ERROR :blah line, we should queue