[SithNet-Patches] [CVS] Module gnuworld-sithnet: Change committed
Brought to you by:
darthsidious_
From: Tim I. <dar...@us...> - 2003-08-22 10:25:49
|
Committer : Tim Ireland <dar...@us...> CVSROOT : /cvsroot/sithnet-dev Module : gnuworld-sithnet Commit time: 2003-08-21 17:38:07 UTC Modified files: mod.cservice/Makefile.am mod.cservice/cservice.cc mod.cservice/cserviceCommands.h mod.cservice/levels.h Added files: mod.cservice/ADDUSERIDCommand.cc Log message: Implemented OUTsider's ADDUSERIDCommand dont forget to run autoconf etc on these.. ---------------------- diff included ---------------------- Index: gnuworld-sithnet/mod.cservice/ADDUSERIDCommand.cc diff -u /dev/null gnuworld-sithnet/mod.cservice/ADDUSERIDCommand.cc:1.1 --- /dev/null Thu Aug 21 10:38:07 2003 +++ gnuworld-sithnet/mod.cservice/ADDUSERIDCommand.cc Thu Aug 21 10:37:57 2003 @@ -0,0 +1,175 @@ +/* ADDUSERIDCommand.cc + * Adds a user to the database, usefull should pages not be available or obsolete + */ + +#include <string> +#include <iomanip.h> + +#include "md5hash.h" +#include "StringTokenizer.h" +#include "ELog.h" +#include "cservice.h" +#include "responses.h" +#include "networkData.h" +#include "levels.h" +#include "libpq++.h" +#include "responses.h" +#include "Network.h" + + +const char ADDUSERIDCommand_cc_rcsId[] = "$Id: ADDUSERIDCommand.cc,v 1.1 2003/08/21 17:37:57 darthsidious_ Exp $" ; + +namespace gnuworld +{ + +using namespace gnuworld; + +bool ADDUSERIDCommand::Exec( iClient* theClient, const string& Message ) +{ + + const char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.$*_"; + + StringTokenizer st( Message ) ; + if( st.size() < 4 ) + { + Usage(theClient); + return true; + } + + + /* + * Fetch the sqlUser record attached to this client. If there isn't one, + * they aren't logged in - tell them they should be. + */ + + sqlUser* theUser = bot->isAuthed(theClient, true); + if (!theUser) return false; + + + /* + * Check Command access + */ + int level = bot->getAdminAccessLevel(theUser); + if (level < level::adduserid) + { + bot->Notice(theClient, + bot->getResponse(theUser, + language::insuf_access, + string("You have insufficient access to perform that command."))); + return false; + } + + /* + * User exists?! Bail out, we don't want clones! + */ + sqlUser* Target = bot->getUserRecord(st[1]); + if(Target) + { + bot->Notice(theClient, "Sorry, %s is already present in the database" ,st[1].c_str()); + return false; + } + + /* Try and stop people using an invalid syntax.. */ + if (string_lower(st[1]) == string_lower(st[2]) ) + { + bot->Notice(theClient, "The passphrase cannot be the same as the username"); + return false; + } + + /* Work out some salt. */ + string salt; + + // TODO: Why calling srand() here? + srand(clock() * 1000000); + + // TODO: What is the significance of '8' here? + // Schema states a fixed 8 bytes of random salt are used in generating the + // password. + for ( unsigned short int i = 0 ; i < 8; i++) + { + int randNo = 1+(int) (64.0*rand()/(RAND_MAX+1.0)); + salt += validChars[randNo]; + } + + /* Work out a MD5 hash of our salt + password */ + + md5 hash; // MD5 hash algorithm object. + md5Digest digest; // MD5Digest algorithm object. + + // Prepend the salt to the password + string newPass = salt + st[2]; + + // Take the md5 hash of this newPass string + hash.update( (const unsigned char *)newPass.c_str(), newPass.size() ); + hash.report( digest ); + + /* Convert to Hex */ + + int data[ MD5_DIGEST_LENGTH ] = { 0 } ; + for( size_t i = 0 ; i < MD5_DIGEST_LENGTH ; ++i ) + { + data[ i ] = digest[ i ] ; + } + + strstream output; + output << hex; + output.fill('0'); + for( size_t ii = 0; ii < MD5_DIGEST_LENGTH; ii++ ) + { + output << setw(2) << data[ii]; + } + output << ends; + + // Prepend the md5 hash to the salt + string finalPassword = salt + output.str(); + + /* + * Check if the email is a correct one + */ + StringTokenizer st2( st[ 3 ], '@' ) ; + + if( (st2.size() != 2) || (st2[ 1 ].size() > 128 ) ) + { + bot->Notice(theClient, "Sorry, this email address is not valid."); + return false ; + } + + /* + * Finally done, let's rock and roll.... + */ + + strstream theQuery ; + theQuery << "INSERT INTO users (user_name, password, email, language_id, last_updated_by, last_updated ) " + << "VALUES (" + << "'" << st[1] << "'," + << "'" << finalPassword.c_str() << "'," + << "'" << st[3] << "',1," + << "'(" << theUser->getUserName() << ") " + << theClient->getNickUserHost() << "'," + << bot->currentTime() + << ");" + << ends; + +#ifdef LOG_SQL + elog << "ADDUSERID::sqlQuery> " + << theQuery.str() + << endl; +#endif + + ExecStatusType status = bot->SQLDb->Exec(theQuery.str()) ; + delete[] theQuery.str() ; + + if( PGRES_COMMAND_OK != status ) + { + bot->dbErrorMessage(theClient); + return false ; + } + + bot->Notice(theClient, "%s has been added to the database with email address %s and password %s" ,st[1].c_str(), st[3].c_str(), st[2].c_str()); + + delete[] output.str() ; + return true; + } + + +} // namespace gnuworld Index: gnuworld-sithnet/mod.cservice/Makefile.am diff -u gnuworld-sithnet/mod.cservice/Makefile.am:1.1.1.1 gnuworld-sithnet/mod.cservice/Makefile.am:1.2 --- gnuworld-sithnet/mod.cservice/Makefile.am:1.1.1.1 Mon Aug 18 13:30:45 2003 +++ gnuworld-sithnet/mod.cservice/Makefile.am Thu Aug 21 10:37:57 2003 @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in -# "$Id: Makefile.am,v 1.1.1.1 2003/08/18 20:30:45 darthsidious_ Exp $" +# "$Id: Makefile.am,v 1.2 2003/08/21 17:37:57 darthsidious_ Exp $" lib_LTLIBRARIES = libcservice.la libcservice_la_LDFLAGS = -module -export-dynamic -L@PGSQL_LIB@ \ @@ -66,7 +66,8 @@ UNFORCECommand.cc \ UNSUSPENDCommand.cc \ VERIFYCommand.cc \ - VOICECommand.cc + VOICECommand.cc \ + ADDUSERIDCommand.cc EXTRA_DIST = constants.h \ cserviceCommands.h \ Index: gnuworld-sithnet/mod.cservice/cservice.cc diff -u gnuworld-sithnet/mod.cservice/cservice.cc:1.2 gnuworld-sithnet/mod.cservice/cservice.cc:1.3 --- gnuworld-sithnet/mod.cservice/cservice.cc:1.2 Wed Aug 20 08:33:03 2003 +++ gnuworld-sithnet/mod.cservice/cservice.cc Thu Aug 21 10:37:57 2003 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * - * $Id: cservice.cc,v 1.2 2003/08/20 15:33:03 darthsidious_ Exp $ + * $Id: cservice.cc,v 1.3 2003/08/21 17:37:57 darthsidious_ Exp $ */ #include <new> @@ -223,6 +223,7 @@ RegisterCommand(new UNFORCECommand(this, "UNFORCE", "<#channel>", 8)); RegisterCommand(new SERVNOTICECommand(this, "SERVNOTICE", "<#channel> <text>", 5)); RegisterCommand(new SAYCommand(this, "SAY", "<#channel> <text>", 5)); +RegisterCommand(new ADDUSERIDCommand(this, "ADDUSERID", "<userid> <password> <email>", 5)); RegisterCommand(new QUOTECommand(this, "QUOTE", "<text>", 5)); RegisterCommand(new REHASHCommand(this, "REHASH", "[translations | help]]", 5)); RegisterCommand(new STATSCommand(this, "STATS", "", 8)); Index: gnuworld-sithnet/mod.cservice/cserviceCommands.h diff -u gnuworld-sithnet/mod.cservice/cserviceCommands.h:1.1.1.1 gnuworld-sithnet/mod.cservice/cserviceCommands.h:1.2 --- gnuworld-sithnet/mod.cservice/cserviceCommands.h:1.1.1.1 Mon Aug 18 13:30:44 2003 +++ gnuworld-sithnet/mod.cservice/cserviceCommands.h Thu Aug 21 10:37:57 2003 @@ -16,11 +16,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * - * $Id: cserviceCommands.h,v 1.1.1.1 2003/08/18 20:30:44 darthsidious_ Exp $ + * $Id: cserviceCommands.h,v 1.2 2003/08/21 17:37:57 darthsidious_ Exp $ */ #ifndef __CSERVICECOMMANDS_H -#define __CSERVICECOMMANDS_H "$Id: cserviceCommands.h,v 1.1.1.1 2003/08/18 20:30:44 darthsidious_ Exp $" +#define __CSERVICECOMMANDS_H "$Id: cserviceCommands.h,v 1.2 2003/08/21 17:37:57 darthsidious_ Exp $" #include <string> @@ -148,6 +148,7 @@ DECLARE_COMMAND( SERVNOTICE ) DECLARE_COMMAND( SAY ) DECLARE_COMMAND( QUOTE ) +DECLARE_COMMAND( ADDUSERID ) DECLARE_COMMAND( REHASH ) DECLARE_COMMAND( STATS ) DECLARE_COMMAND( ADDCOMMENT ) Index: gnuworld-sithnet/mod.cservice/levels.h diff -u gnuworld-sithnet/mod.cservice/levels.h:1.2 gnuworld-sithnet/mod.cservice/levels.h:1.3 --- gnuworld-sithnet/mod.cservice/levels.h:1.2 Wed Aug 20 08:33:03 2003 +++ gnuworld-sithnet/mod.cservice/levels.h Thu Aug 21 10:37:57 2003 @@ -21,11 +21,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. * - * $Id: levels.h,v 1.2 2003/08/20 15:33:03 darthsidious_ Exp $ + * $Id: levels.h,v 1.3 2003/08/21 17:37:57 darthsidious_ Exp $ */ #ifndef __LEVELS_H -#define __LEVELS_H "$Id: levels.h,v 1.2 2003/08/20 15:33:03 darthsidious_ Exp $" +#define __LEVELS_H "$Id: levels.h,v 1.3 2003/08/21 17:37:57 darthsidious_ Exp $" namespace gnuworld { @@ -85,6 +85,7 @@ const int servnotice = 800; const int say = 800; + const int adduserid = 900; // Debug Commands const int shutdown = 900; ----------------------- End of diff ----------------------- |