]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fixed bug #85
[user/henk/code/inspircd.git] / src / users.cpp
index 5154b04cb1ab941da62a38e19cbfb1fd168c75cb..1920e8dcdf9c070a7700fdf3877f8fddff412721 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
 #include "inspircd_config.h" 
 #include "channels.h"
+#include "connection.h"
 #include "users.h"
 #include "inspircd.h"
 #include <stdio.h>
+#ifdef THREADED_DNS
+#include <pthread.h>
+#include <signal.h>
+#endif
 #include "inspstring.h"
+#include "commands.h"
+#include "helperfuncs.h"
 
 extern std::stringstream config_f;
+extern char ServerName[MAXBUF];
 
 extern time_t TIME;
 
@@ -36,8 +46,7 @@ userrec::userrec()
        strcpy(dhost,"");
        strcpy(fullname,"");
        strcpy(modes,"");
-       strcpy(inbuf,"");
-       strcpy(server,"");
+       server = (char*)FindServerNamePtr(ServerName);
        strcpy(awaymsg,"");
        strcpy(oper,"");
        reset_due = TIME;
@@ -48,7 +57,6 @@ userrec::userrec()
        dns_done = false;
        recvq = "";
        sendq = "";
-       strcpy(result,"");
        for (int i = 0; i < MAXCHANS; i++)
        {
                this->chans[i].channel = NULL;
@@ -57,19 +65,39 @@ userrec::userrec()
        invites.clear();
 }
 
+userrec::~userrec()
+{
+}
 
+void userrec::CloseSocket()
+{
+       shutdown(this->fd,2);
+       close(this->fd);
+}
  
 char* userrec::GetFullHost()
 {
+       static char result[MAXBUF];
        snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,dhost);
        return result;
 }
 
+int userrec::ReadData(void* buffer, size_t size)
+{
+       if (this->fd > -1)
+       {
+               log(DEBUG,"userrec::ReadData on fd %d",this->fd);
+               return read(this->fd, buffer, size);
+       }
+       else return 0;
+}
+
 
 char* userrec::GetFullRealHost()
 {
-       snprintf(result,MAXBUF,"%s!%s@%s",nick,ident,host);
-       return result;
+       static char fresult[MAXBUF];
+       snprintf(fresult,MAXBUF,"%s!%s@%s",nick,ident,host);
+       return fresult;
 }
 
 bool userrec::IsInvited(char* channel)
@@ -86,6 +114,11 @@ bool userrec::IsInvited(char* channel)
        return false;
 }
 
+InvitedList* userrec::GetInviteList()
+{
+       return &invites;
+}
+
 void userrec::InviteTo(char* channel)
 {
        Invited i;
@@ -122,36 +155,38 @@ bool userrec::HasPermission(char* command)
        char* savept;
        char* savept2;
        
+       // users on u-lined servers can completely bypass
+       // all permissions based checks.
+       //
+       // of course, if this is sent to a remote server and this
+       // server is not ulined there, then that other server
+       // silently drops the command.
+       if (is_uline(this->server))
+               return true;
+       
        // are they even an oper at all?
        if (strchr(this->modes,'o'))
        {
-               log(DEBUG,"*** HasPermission: %s is an oper",this->nick);
                for (int j =0; j < ConfValueEnum("type",&config_f); j++)
                {
                        ConfValue("type","name",j,TypeName,&config_f);
                        if (!strcmp(TypeName,this->oper))
                        {
-                               log(DEBUG,"*** HasPermission: %s is an oper of type '%s'",this->nick,this->oper);
                                ConfValue("type","classes",j,Classes,&config_f);
                                char* myclass = strtok_r(Classes," ",&savept);
                                while (myclass)
                                {
-                                       log(DEBUG,"*** HasPermission: checking classtype '%s'",myclass);
                                        for (int k =0; k < ConfValueEnum("class",&config_f); k++)
                                        {
                                                ConfValue("class","name",k,ClassName,&config_f);
                                                if (!strcmp(ClassName,myclass))
                                                {
                                                        ConfValue("class","commands",k,CommandList,&config_f);
-                                                       log(DEBUG,"*** HasPermission: found class named %s with commands: '%s'",ClassName,CommandList);
-                                                       
-                                                       
                                                        mycmd = strtok_r(CommandList," ",&savept2);
                                                        while (mycmd)
                                                        {
-                                                               if (!strcasecmp(mycmd,command))
+                                                               if ((!strcasecmp(mycmd,command)) || (*mycmd == '*'))
                                                                {
-                                                                       log(DEBUG,"*** Command %s found, returning true",command);
                                                                        return true;
                                                                }
                                                                mycmd = strtok_r(NULL," ",&savept2);
@@ -170,19 +205,24 @@ bool userrec::HasPermission(char* command)
 bool userrec::AddBuffer(std::string a)
 {
         std::string b = "";
-        for (int i = 0; i < a.length(); i++)
+        for (unsigned int i = 0; i < a.length(); i++)
                 if ((a[i] != '\r') && (a[i] != '\0') && (a[i] != 7))
                         b = b + a[i];
         std::stringstream stream(recvq);
         stream << b;
         recvq = stream.str();
-       int i = 0;
+       unsigned int i = 0;
        // count the size of the first line in the buffer.
        while (i < recvq.length())
        {
                if (recvq[i++] == '\n')
                        break;
        }
+       if (recvq.length() > (unsigned)this->recvqmax)
+       {
+               this->SetWriteError("RecvQ exceeded");
+               WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax);
+       }
        // return false if we've had more than 600 characters WITHOUT
        // a carriage return (this is BAD, drop the socket)
        return (i < 600);
@@ -190,7 +230,7 @@ bool userrec::AddBuffer(std::string a)
 
 bool userrec::BufferIsReady()
 {
-        for (int i = 0; i < recvq.length(); i++)
+        for (unsigned int i = 0; i < recvq.length(); i++)
                if (recvq[i] == '\n')
                        return true;
         return false;
@@ -222,9 +262,9 @@ void userrec::AddWriteBuf(std::string data)
 {
        if (this->GetWriteError() != "")
                return;
-       if (sendq.length() + data.length() > this->sendqmax)
+       if (sendq.length() + data.length() > (unsigned)this->sendqmax)
        {
-               WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),sendq.length());
+               WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax);
                this->SetWriteError("SendQ exceeded");
                return;
        }