]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fix potential for duplicate SID if the SID is auto generated.
[user/henk/code/inspircd.git] / src / users.cpp
index 476a4f1cd28179e5c69793a0c21222ef0986fe51..4856ebc388f6f2cd5d87b8b828a77d0abcae6ca5 100644 (file)
@@ -12,9 +12,6 @@
  */
 
 #include "inspircd.h"
-#include "configreader.h"
-#include "channels.h"
-#include "users.h"
 #include <stdarg.h>
 #include "socketengine.h"
 #include "wildcard.h"
@@ -345,8 +342,19 @@ userrec::userrec(InspIRCd* Instance, const std::string &uid) : ServerInstance(In
        memset(snomasks,0,sizeof(snomasks));
        /* Invalidate cache */
        operquit = cached_fullhost = cached_hostip = cached_makehost = cached_fullrealhost = NULL;
-       if (!uid.empty())
+
+       if (uid.empty())
+               strlcpy(uuid, Instance->GetUID().c_str(), UUID_LENGTH);
+       else
                strlcpy(uuid, uid.c_str(), UUID_LENGTH);
+
+       ServerInstance->Log(DEBUG,"New UUID for user: %s (%s)", uuid, uid.empty() ? "allocated new" : "used remote");
+
+       user_hash::iterator finduuid = Instance->uuidlist->find(uuid);
+       if (finduuid == Instance->uuidlist->end())
+               (*Instance->uuidlist)[uuid] = this;
+       else
+               throw CoreException("Duplicate UUID "+std::string(uuid)+" in userrec constructor");
 }
 
 void userrec::RemoveCloneCounts()
@@ -393,6 +401,8 @@ userrec::~userrec()
                }
 #endif
        }
+
+       ServerInstance->uuidlist->erase(uuid);
 }
 
 char* userrec::MakeHost()
@@ -863,7 +873,17 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
        /* NOTE: Calling this one parameter constructor for userrec automatically
         * allocates a new UUID and places it in the hash_map.
         */
-       userrec* New = new userrec(Instance);
+       userrec* New = NULL;
+       try
+       {
+               New = new userrec(Instance);
+       }
+       catch (CoreException &e)
+       {
+               Instance->Log(DEFAULT,"*** WTF *** Duplicated UUID! -- Crack smoking monkies have been unleashed.");
+               return;
+       }
+
        int j = 0;
 
        Instance->unregistered_count++;