]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/extra/m_sqloper.cpp
Get rid of Server::GetUsers(chanrec) - a throwback to before chanrec could do this...
[user/henk/code/inspircd.git] / src / modules / extra / m_sqloper.cpp
index e103a1f4b7ee0511407e4280ce9ef8ad7a84c551..a67ec46e266b18531b7d10ef1383b2e572a03ca2 100644 (file)
@@ -46,7 +46,7 @@ public:
        {
                SQLutils = Srv->FindFeature("SQLutils");
                
-               if(SQLutils)
+               if (SQLutils)
                {
                        log(DEBUG, "Successfully got SQLutils pointer");
                }
@@ -75,7 +75,7 @@ public:
        {
                if (validated && (command == "OPER"))
                {
-                       if(LookupOper(user, parameters[0], parameters[1]))
+                       if (LookupOper(user, parameters[0], parameters[1]))
                        {       
                                /* Returning true here just means the query is in progress, or on it's way to being
                                 * in progress. Nothing about the /oper actually being successful..
@@ -93,11 +93,11 @@ public:
                
                target = Srv->FindFeature("SQL");
                
-               if(target)
+               if (target)
                {
                        SQLrequest req = SQLreq(this, target, databaseid, "SELECT username, password, hostname, type FROM ircd_opers WHERE username = '?' AND password=md5('?')", username, password);
                        
-                       if(req.Send())
+                       if (req.Send())
                        {
                                /* When we get the query response from the service provider we will be given an ID to play with,
                                 * just an ID number which is unique to this query. We need a way of associating that ID with a userrec
@@ -128,25 +128,25 @@ public:
        
        virtual char* OnRequest(Request* request)
        {
-               if(strcmp(SQLRESID, request->GetData()) == 0)
+               if (strcmp(SQLRESID, request->GetId()) == 0)
                {
                        SQLresult* res;
                
                        res = static_cast<SQLresult*>(request);
                        
-                       log(DEBUG, "Got SQL result (%s) with ID %lu", res->GetData(), res->id);
+                       log(DEBUG, "Got SQL result (%s) with ID %lu", res->GetId(), res->id);
                        
                        userrec* user = GetAssocUser(this, SQLutils, res->id).S().user;
                        UnAssociate(this, SQLutils, res->id).S();
                        
-                       if(user)
+                       if (user)
                        {
-                               if(res->error.Id() == NO_ERROR)
+                               if (res->error.Id() == NO_ERROR)
                                {                               
                                        log(DEBUG, "Associated query ID %lu with user %s", res->id, user->nick);                        
                                        log(DEBUG, "Got result with %d rows and %d columns", res->Rows(), res->Cols());
                        
-                                       if(res->Rows())
+                                       if (res->Rows())
                                        {
                                                /* We got a row in the result, this means there was a record for the oper..
                                                 * now we just need to check if their host matches, and if it does then
@@ -161,11 +161,11 @@ public:
                                                 * are no more rows to return.
                                                 */
                                                
-                                               for(SQLfieldMap& row = res->GetRowMap(); row.size(); row = res->GetRowMap())
+                                               for (SQLfieldMap& row = res->GetRowMap(); row.size(); row = res->GetRowMap())
                                                {
                                                        log(DEBUG, "Trying to oper user %s with username = '%s', passhash = '%s', hostname = '%s', type = '%s'", user->nick, row["username"].d.c_str(), row["password"].d.c_str(), row["hostname"].d.c_str(), row["type"].d.c_str());
                                                        
-                                                       if(OperUser(user, row["username"].d, row["password"].d, row["hostname"].d, row["type"].d))
+                                                       if (OperUser(user, row["username"].d, row["password"].d, row["hostname"].d, row["type"].d))
                                                        {
                                                                /* If/when one of the rows matches, stop checking and return */
                                                                return SQLSUCCESS;
@@ -179,7 +179,7 @@ public:
                                                 * "insufficient awesomeness" (invalid credentials) error
                                                 */
                                                
-                                               WriteServ(user->fd, "491 %s :Invalid oper credentials", user->nick);
+                                               user->WriteServ( "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);
                                        }
@@ -192,7 +192,7 @@ public:
                                         */
                                        log(DEBUG, "Query failed: %s", res->error.Str());
 
-                                       WriteServ(user->fd, "491 %s :Invalid oper credentials", user->nick);
+                                       user->WriteServ( "491 %s :Invalid oper credentials", user->nick);
                                        WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s! (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str());
                                        log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.", user->nick, user->ident, user->host);
                                }
@@ -205,47 +205,41 @@ public:
                        return SQLSUCCESS;
                }
                
-               log(DEBUG, "Got unsupported API version string: %s", request->GetData());
+               log(DEBUG, "Got unsupported API version string: %s", request->GetId());
                
                return NULL;
        }       
 
-       bool OperUser(userrec* user, const std::string &username, const std::string &password, const std::string &hostname, const std::string &type)
+       bool OperUser(userrec* user, const std::string &username, const std::string &password, const std::string &pattern, const std::string &type)
        {
                ConfigReader Conf;
                
                for (int j = 0; j < Conf.Enumerate("type"); j++)
                {
-                       std::string TypeName = Conf.ReadValue("type","name",j);
+                       std::string tname = Conf.ReadValue("type","name",j);
                        
-                       Srv->Log(DEBUG,"Scanning opertype: "+TypeName);
+                       log(DEBUG, "Scanning opertype: %s", tname.c_str());
                        
-                       std::string pattern = std::string(user->ident) + "@" + std::string(user->host);
+                       std::string hostname(user->ident);
+                       hostname.append("@").append(user->host);
                                                        
-                       if((TypeName == type) && OneOfMatches(pattern.c_str(), hostname.c_str()))
+                       if ((tname == type) && OneOfMatches(hostname.c_str(), user->GetIPString(), pattern.c_str()))
                        {
-                               /* found this oper's opertype */
-                               Srv->Log(DEBUG,"Host and type match: "+TypeName+" "+type);
+                               /* Opertype and host match, looks like this is it. */
+                               log(DEBUG, "Host (%s matched %s OR %s) and type (%s)", pattern.c_str(), hostname.c_str(), user->GetIPString(), type.c_str());
                                
-                               std::string HostName = Conf.ReadValue("type","host",j);
+                               std::string operhost = Conf.ReadValue("type", "host", j);
                                                        
-                               if(HostName.size())
-                                       Srv->ChangeHost(user, HostName);
+                               if (operhost.size())
+                                       user->ChangeDisplayedHost(operhost);
                                                                
                                strlcpy(user->oper, type.c_str(), NICKMAX-1);
                                
                                WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s", user->nick, user->ident, user->host, type.c_str());
-                               WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s", user->nick, type.c_str());
+                               user->WriteServ("381 %s :You are now an IRC operator of type %s", user->nick, type.c_str());
                                
-                               if(!user->modes[UM_OPERATOR])
-                               {
-                                       user->modes[UM_OPERATOR] = 1;
-                                       WriteServ(user->fd,"MODE %s :+o",user->nick);
-                                       FOREACH_MOD(I_OnOper,OnOper(user, type));
-                                       AddOper(user);
-                                       FOREACH_MOD(I_OnPostOper,OnPostOper(user, type));
-                                       log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", user->nick, user->ident, user->host, type.c_str());
-                               }
+                               if (!user->modes[UM_OPERATOR])
+                                       user->Oper();
                                                                
                                return true;
                        }