1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
21 #include <sys/types.h>
22 #include <sys/socket.h>
35 /* $ModDesc: An SQL test module */
39 class ModuleSQLAuth : public Module
42 std::string usertable;
49 Conf = new ConfigReader();
50 usertable = Conf->ReadValue("sqlauth","usertable",0);
51 dbid = Conf->ReadInteger("sqlauth","dbid",0,true);
53 SQLModule = Srv->FindModule("m_sql.so");
63 virtual void OnRehash()
68 bool CheckCredentials(std::string username, std::string password,std::string usertable)
72 // is the sql module loaded? If not, we don't attempt to do anything.
76 // Create a request containing the SQL query and send it to m_sql.so
77 SQLRequest* query = new SQLRequest(SQL_RESULT,1,"SELECT * FROM "+usertable+" WHERE user='"+username+"' AND pass=md5('"+password+"')");
78 Request queryrequest((char*)query, this, SQLModule);
79 SQLResult* result = (SQLResult*)queryrequest.Send();
81 // Did we get "OK" as a result?
82 if (result->GetType() == SQL_OK)
85 // if we did, this means we may now request a row... there should be only one row for each user, so,
86 // we don't need to loop to fetch multiple rows.
87 SQLRequest* rowrequest = new SQLRequest(SQL_ROW,1,"");
88 Request rowquery((char*)rowrequest, this, SQLModule);
89 SQLResult* rowresult = (SQLResult*)rowquery.Send();
91 // did we get a row? If we did, we can now do something with the fields
92 if (rowresult->GetType() == SQL_ROW)
94 Srv->Log(DEBUG,"*********** SQL TEST MODULE - RESULTS *************");
95 Srv->Log(DEBUG,"Result, field 'qcount': '" + rowrequest->GetField("qcount"));
96 Srv->Log(DEBUG,"Result, field 'asked': '" + rowrequest->GetField("asked"));
102 // we didn't have a row.
113 query->SetQueryType(SQL_DONE);
115 Request donerequest((char*)query, this, SQLModule);
121 virtual bool OnCheckReady(userrec* user)
125 virtual void OnUserDisconnect(userrec* user)
129 virtual ~ModuleSQLAuth()
134 virtual Version GetVersion()
136 return Version(1,0,0,1,VF_VENDOR);
141 class ModuleSQLAuthFactory : public ModuleFactory
144 ModuleSQLAuthFactory()
148 ~ModuleSQLAuthFactory()
152 virtual Module * CreateModule()
154 return new ModuleSQLAuth;
160 extern "C" void * init_module( void )
162 return new ModuleSQLAuthFactory;