diff --git a/libretroshare/src/ft/Makefile b/libretroshare/src/ft/Makefile index 0626e02ed..a252472b5 100644 --- a/libretroshare/src/ft/Makefile +++ b/libretroshare/src/ft/Makefile @@ -9,7 +9,7 @@ include $(RS_TOP_DIR)/scripts/config.mk RSOBJ = ftdata.o ftfileprovider.o ftfilecreator.o ftextralist.o \ ftdatamultiplex.o ftfilesearch.o fttransfermodule.o ftdbase.o ftserver.o \ - ftcontroller.o pqitestor.o + ftcontroller.o pqitestor.o ftdwlqueue.o TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o ftserver1test.o ftserver2test.o fttransfermoduletest.o ftserver3test.o diff --git a/libretroshare/src/libretroshare.pro b/libretroshare/src/libretroshare.pro index 2f9e2879d..67f1475b1 100644 --- a/libretroshare/src/libretroshare.pro +++ b/libretroshare/src/libretroshare.pro @@ -1,5 +1,5 @@ TEMPLATE = lib -CONFIG += static xpgp +CONFIG += static pgp TARGET = retroshare CONFIG += release @@ -22,6 +22,7 @@ pgp { DEFINES -=PQI_USE_XPGP DEFINES *= RS_USE_PGPSSL } + xpgp { DEFINES *= PQI_USE_XPGP SSL_DIR=../../../../openssl-0.9.7g-xpgp-0.1c @@ -246,7 +247,7 @@ SOURCES = \ rsserver/p3face-msgs.cc \ rsserver/rsiface.cc \ rsserver/rstypes.cc \ - rsserver/p3face-startup.cc \ + rsserver/rsinit.cc \ rsserver/p3face-config.cc \ rsserver/p3face-server.cc \ rsserver/p3Blog.cc \ diff --git a/libretroshare/src/pqi/authgpg.cc b/libretroshare/src/pqi/authgpg.cc index 6f257db20..9ec2ac8ca 100644 --- a/libretroshare/src/pqi/authgpg.cc +++ b/libretroshare/src/pqi/authgpg.cc @@ -57,10 +57,13 @@ #include #include +#define AUTHGPG_DEBUG 1 + + /* Turn a set of parameters into a string */ static std::string setKeyPairParams(bool useRsa, unsigned int blen, std::string name, std::string comment, std::string email, - std::string passphrase); + std::string inPassphrase); static gpgme_key_t getKey(gpgme_ctx_t, std::string, std::string, std::string); @@ -132,6 +135,7 @@ bool GPGAuthMgr::setPGPPassword_locked(std::string pwd) memcpy(PgpPassword, pwd.c_str(), pwd.length()); PgpPassword[pwd.length()] = '\0'; + fprintf(stderr, "GPGAuthMgr::setPGPPassword_locked() called\n"); gpgme_set_passphrase_cb(CTX, pgp_pwd_callback, (void *) PgpPassword); return true; @@ -257,7 +261,7 @@ bool GPGAuthMgr::availablePGPCertificates(std::list &ids) * This function must be called successfully (return == 1) * before anything else can be done. (except above fn). */ -int GPGAuthMgr::GPGInit(std::string ownId, std::string name, std::string passphrase) +int GPGAuthMgr::GPGInit(std::string ownId) { RsStackMutex stack(pgpMtx); /******* LOCKED ******/ @@ -280,23 +284,24 @@ int GPGAuthMgr::GPGInit(std::string ownId, std::string name, std::string passphr return 0; } - mOwnGpgCert.user.name = name; + mOwnGpgCert.user.name = newKey->uids->name; mOwnGpgCert.user.email = newKey->uids->email; mOwnGpgCert.user.fpr = newKey->subkeys->fpr; mOwnGpgCert.user.id = ownId; mOwnGpgCert.key = newKey; - this->passphrase = passphrase; mOwnId = ownId; gpgmeKeySelected = true; - setPGPPassword_locked(passphrase); + // Password set in different fn. + //this->passphrase = passphrase; + //setPGPPassword_locked(passphrase); return true; } int GPGAuthMgr::GPGInit(std::string name, std::string comment, - std::string email, std::string passphrase) + std::string email, std::string inPassphrase) { RsStackMutex stack(pgpMtx); /******* LOCKED ******/ @@ -329,8 +334,8 @@ int GPGAuthMgr::GPGInit(std::string name, std::string comment, mOwnGpgCert.user.id = newKey->subkeys->keyid; mOwnGpgCert.key = newKey; - this->passphrase = passphrase; - setPGPPassword_locked(passphrase); + this->passphrase = inPassphrase; + setPGPPassword_locked(inPassphrase); mOwnId = mOwnGpgCert.user.id; gpgmeKeySelected = true; @@ -342,6 +347,21 @@ int GPGAuthMgr::GPGInit(std::string name, std::string comment, { } +int GPGAuthMgr::LoadGPGPassword(std::string pwd) +{ + RsStackMutex stack(pgpMtx); /******* LOCKED ******/ + + if (!gpgmeInit) { + return 0; + } + + this->passphrase = pwd; + setPGPPassword_locked(pwd); + + return 1; +} + + // store all keys in map mKeyList to avoid callin gpgme exe repeatedly bool GPGAuthMgr::storeAllKeys_locked() @@ -637,6 +657,12 @@ bool GPGAuthMgr::printOwnKeys_locked() return true; } +bool GPGAuthMgr::printKeys() +{ + RsStackMutex stack(pgpMtx); /******* LOCKED ******/ + printAllKeys_locked(); + return printOwnKeys_locked(); +} X509 *GPGAuthMgr::SignX509Req(X509_REQ *req, long days, std::string gpg_passwd) { @@ -820,7 +846,7 @@ X509 *GPGAuthMgr::SignX509Req(X509_REQ *req, long days, std::string gpg_passwd) goto err; } - passphrase = "NULL"; + //passphrase = "NULL"; std::cerr << "Signature done: len:" << sigoutl << std::endl; @@ -1258,6 +1284,10 @@ bool GPGAuthMgr::getDetails(std::string id, pqiAuthDetails &details) * Ids are the SSL id cert ids, so we have to get issuer id (pgpid) * before we can add any gpg details ****/ +#ifdef AUTHGPG_DEBUG + std::cerr << "GPGAuthMgr::getDetails() \"" << id << "\""; + std::cerr << std::endl; +#endif if (AuthSSL::getDetails(id, details)) { @@ -1906,7 +1936,7 @@ void GPGAuthMgr::createDummyFriends() static std::string setKeyPairParams(bool useRsa, unsigned int blen, std::string name, std::string comment, std::string email, - std::string passphrase) + std::string inPassphrase) { std::ostringstream params; params << ""<< std::endl; @@ -1932,7 +1962,7 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen, params << "Name-Comment: "<< comment << std::endl; params << "Name-Email: "<< email << std::endl; params << "Expire-Date: 0"<< std::endl; - params << "Passphrase: "<< passphrase << std::endl; + params << "Passphrase: "<< inPassphrase << std::endl; params << ""<< std::endl; return params.str(); diff --git a/libretroshare/src/pqi/authgpg.h b/libretroshare/src/pqi/authgpg.h index 0eef90d40..2ca4b499e 100644 --- a/libretroshare/src/pqi/authgpg.h +++ b/libretroshare/src/pqi/authgpg.h @@ -82,9 +82,12 @@ class GPGAuthMgr: public AuthSSL bool availablePGPCertificates(std::list &ids); - int GPGInit(std::string ownId, std::string name, std::string passwd); + int GPGInit(std::string ownId); int GPGInit(std::string name, std::string comment, - std::string email, std::string passwd); + std::string email, std::string passwd); /* create it */ + + int LoadGPGPassword(std::string pwd); + /* Sign/Trust stuff */ int signCertificate(std::string id); int revokeCertificate(std::string id); /* revoke the signature on Certificate */ @@ -94,6 +97,8 @@ class GPGAuthMgr: public AuthSSL void showData(gpgme_data_t dh); void createDummyFriends(void); //NYI + bool printKeys(); + /*********************************************************************************/ /************************* STAGE 1 ***********************************************/ /*********************************************************************************/ diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index dfe57b4ab..4419201a7 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -803,7 +803,7 @@ std::string AuthSSL::getIssuerName(std::string id) bool AuthSSL::getDetails(std::string id, pqiAuthDetails &details) { #ifdef AUTHSSL_DEBUG - std::cerr << "AuthSSL::getDetails() " << id; + std::cerr << "AuthSSL::getDetails() \"" << id << "\""; std::cerr << std::endl; #endif sslMtx.lock(); /***** LOCK *****/ @@ -1964,6 +1964,59 @@ int LoadCheckX509andGetName(const char *cert_file, std::string &userName, std::s } } + +// Not dependent on sslroot. load, and detroys the X509 memory. + +int LoadCheckX509andGetIssuerName(const char *cert_file, std::string &issuerName, std::string &userId) +{ + /* This function loads the X509 certificate from the file, + * and checks the certificate + */ + + FILE *tmpfp = fopen(cert_file, "r"); + if (tmpfp == NULL) + { +#ifdef AUTHSSL_DEBUG + std::cerr << "sslroot::LoadCheckAndGetX509Name()"; + std::cerr << " Failed to open Certificate File:" << cert_file; + std::cerr << std::endl; +#endif + return 0; + } + + // get xPGP certificate. + X509 *x509 = PEM_read_X509(tmpfp, NULL, NULL, NULL); + fclose(tmpfp); + + // check the certificate. + bool valid = false; + if (x509) + { + valid = ((AuthSSL *) getAuthMgr())->ValidateCertificate(x509, userId); + } + + if (valid) + { + // extract the name. + issuerName = getX509CNString(x509->cert_info->issuer); + } + + std::cout << getX509Info(x509) << std::endl ; + // clean up. + X509_free(x509); + + if (valid) + { + // happy! + return 1; + } + else + { + // something went wrong! + return 0; + } +} + std::string getX509NameString(X509_NAME *name) { std::string namestr; diff --git a/libretroshare/src/pqi/authssl.h b/libretroshare/src/pqi/authssl.h index 993b1fcc1..ec442bcac 100644 --- a/libretroshare/src/pqi/authssl.h +++ b/libretroshare/src/pqi/authssl.h @@ -236,6 +236,8 @@ std::string getXPGPAuthCode(XPGP *xpgp); std::string getX509Info(X509 *cert); bool getX509id(X509 *x509, std::string &xid); +int LoadCheckX509andGetIssuerName(const char *cert_file, + std::string &issuerName, std::string &userId); int LoadCheckX509andGetName(const char *cert_file, std::string &userName, std::string &userId); diff --git a/libretroshare/src/pqi/gpgme_tst.c b/libretroshare/src/pqi/gpgme_tst.c index fac0ce15e..ec88a8439 100644 --- a/libretroshare/src/pqi/gpgme_tst.c +++ b/libretroshare/src/pqi/gpgme_tst.c @@ -21,8 +21,7 @@ int main() /* Select which GPG Keys we use */ /* print all keys */ - mgr.printAllKeys(); - mgr.printOwnKeys(); + mgr.printKeys(); std::list idList; mgr.availablePGPCertificates(idList); @@ -36,7 +35,8 @@ int main() fprintf(stderr, "Using GPG Certificate:%s \n", id.c_str()); std::string noname; - mgr.GPGInit(id, "noname", gpg_passwd); + mgr.GPGInit(id); + mgr.LoadGPGPassword(gpg_passwd); /* Init SSL library */ mgr.InitAuth(NULL, NULL, NULL); diff --git a/libretroshare/src/rsiface/rsinit.h b/libretroshare/src/rsiface/rsinit.h index 8a5e5b357..729d384eb 100644 --- a/libretroshare/src/rsiface/rsinit.h +++ b/libretroshare/src/rsiface/rsinit.h @@ -1,78 +1,104 @@ +#ifndef RETROSHARE_INIT_INTERFACE_H +#define RETROSHARE_INIT_INTERFACE_H + +/* + * "$Id: rsiface.h,v 1.9 2007-04-21 19:08:51 rmf24 Exp $" + * + * RetroShare C++ Interface. + * + * Copyright 2004-2006 by Robert Fernie. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License Version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + * USA. + * + * Please report all bugs and problems to "retroshare@lunamutt.com". + * + */ + + /* Initialisation Class (not publicly disclosed to RsIFace) */ /**** * #define RS_USE_PGPSSL 1 ***/ +#define RS_USE_PGPSSL 1 + class RsInit { public: - /* Commandline/Directory options */ + /* reorganised RsInit system */ - static const char *RsConfigDirectory() ; + /* PreLogin */ + static void InitRsConfig() ; + static int InitRetroShare(int argc, char **argv); - static bool setStartMinimised() ; - static int InitRetroShare(int argcIgnored, char **argvIgnored) ; - static int LoadCertificates(bool autoLoginNT) ; + /* Account Details (Combined GPG+SSL Setup) */ + static bool getPreferedAccountId(std::string &id); + static bool getAccountIds(std::list &ids); + static bool getAccountDetails(std::string id, + std::string &gpgId, std::string &gpgName, + std::string &gpgEmail, std::string &sslName); + static bool ValidateCertificate(std::string &userName) ; - static bool ValidateTrustedUser(std::string fname, std::string &userName) ; - static bool LoadPassword(std::string passwd) ; - static bool RsGenerateCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &errString); - static void load_check_basedir() ; - static int create_configinit() ; + + + /* Generating GPGme Account */ + static int GetPGPLogins(std::list &pgpIds); + static int GetPGPLoginDetails(std::string id, std::string &name, std::string &email); + static bool GeneratePGPCertificate(std::string name, std::string comment, std::string email, std::string passwd, std::string &pgpId, std::string &errString); + + /* Login PGP */ + static bool SelectGPGAccount(std::string id); + static bool LoadGPGPassword(std::string passwd); + + /* Create SSL Certificates */ + static bool GenerateSSLCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString); + + /* Login SSL */ + static bool LoadPassword(std::string id, std::string passwd) ; + + /* Final Certificate load. This can be called if: + * a) InitRetroshare() returns true -> autoLoad/password Set. + * b) SelectGPGAccount() && LoadPassword() + */ + static int LoadCertificates(bool autoLoginNT) ; + + + /* Post Login Options */ + static std::string RsConfigDirectory(); + static bool setStartMinimised() ; + + + private: + /* PreLogin */ + static std::string getHomePath() ; + static void setupBaseDir(); + + /* Account Details */ + static bool get_configinit(std::string dir, std::string &id); + static bool create_configinit(std::string dir, std::string id); + + static bool setupAccount(std::string accountdir); + + /* Auto Login */ static bool RsStoreAutoLogin() ; static bool RsTryAutoLogin() ; - static bool RsClearAutoLogin(std::string basedir) ; - static void InitRsConfig() ; + static bool RsClearAutoLogin() ; - static std::string getHomePath() ; - - /* PGPSSL init functions */ - -#ifdef RS_USE_PGPSSL - static bool LoadGPGPassword(std::string id, std::string passwd); - static int GetLogins(std::list &pgpIds); - static int GetLoginDetails(std::string id, std::string &name, std::string &email); - - static std::string gpgPasswd; -#endif - - /* Key Parameters that must be set before - * RetroShare will start up: - */ - static std::string load_cert; - static std::string load_key; - static std::string passwd; - - static bool havePasswd; /* for Commandline password */ - static bool autoLogin; /* autoLogin allowed */ - static bool startMinimised; /* Icon or Full Window */ - - /* Win/Unix Differences */ - static char dirSeperator; - - /* Directories */ - static std::string basedir; - static std::string homePath; - - /* Listening Port */ - static bool forceExtPort; - static bool forceLocalAddr; - static unsigned short port; - static char inet[256]; - - /* Logging */ - static bool haveLogFile; - static bool outStderr; - static bool haveDebugLevel; - static int debugLevel; - static char logfname[1024]; - - static bool firsttime_run; - static bool load_trustedpeer; - static std::string load_trustedpeer_file; - - static bool udpListenerOnly; }; + +#endif diff --git a/libretroshare/src/rsserver/Makefile b/libretroshare/src/rsserver/Makefile index 11706be5a..ed20c5e8b 100644 --- a/libretroshare/src/rsserver/Makefile +++ b/libretroshare/src/rsserver/Makefile @@ -7,7 +7,8 @@ RS_TOP_DIR = .. include $(RS_TOP_DIR)/scripts/config.mk ############################################################### -RSOBJ = p3peers.o \ +RSOBJ = rsinit.o \ + p3peers.o \ p3rank.o \ p3photo.o \ p3msgs.o \ @@ -15,7 +16,6 @@ RSOBJ = p3peers.o \ p3discovery.o \ p3face-server.o \ p3face-config.o \ - p3face-startup.o \ p3face-msgs.o \ rsiface.o \ rstypes.o diff --git a/libretroshare/src/rsserver/p3face.h b/libretroshare/src/rsserver/p3face.h index d17665a42..87692463a 100644 --- a/libretroshare/src/rsserver/p3face.h +++ b/libretroshare/src/rsserver/p3face.h @@ -105,8 +105,6 @@ class RsServer: public RsControl, public RsThread /* p3face-msg Operations */ public: - virtual const std::string& certificateFileName() ; - /* Flagging Persons / Channels / Files in or out of a set (CheckLists) */ virtual int SetInChat(std::string id, bool in); /* friend : chat msgs */ virtual int SetInMsg(std::string id, bool in); /* friend : msg receipients */ diff --git a/libretroshare/src/rsserver/rsiface.cc b/libretroshare/src/rsserver/rsiface.cc index 4a5b0d8d5..a7f34a71e 100644 --- a/libretroshare/src/rsserver/rsiface.cc +++ b/libretroshare/src/rsserver/rsiface.cc @@ -28,7 +28,11 @@ #include "rsiface/rsiface.h" #include "util/rsdir.h" - + +/* global variable */ +RsIface *rsiface = NULL; + + /* set to true */ bool RsIface::setChanged(DataFlags set) { @@ -97,7 +101,8 @@ private: RsIface *createRsIface(NotifyBase &cb) { - return new RsIfaceReal(cb); + rsiface = new RsIfaceReal(cb); + return rsiface; } diff --git a/libretroshare/src/rsserver/p3face-startup.cc b/libretroshare/src/rsserver/rsinit.cc similarity index 68% rename from libretroshare/src/rsserver/p3face-startup.cc rename to libretroshare/src/rsserver/rsinit.cc index 895300d5c..fce1cab4c 100644 --- a/libretroshare/src/rsserver/p3face-startup.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -1,6 +1,5 @@ - /* - * "$Id: p3face-startup.cc,v 1.9 2007-05-05 16:10:06 rmf24 Exp $" + * libretroshare/src/reserver rsinit.cc * * RetroShare C++ Interface. * @@ -24,74 +23,29 @@ * */ +/* This is an updated startup class. Class variables are hidden from + * the GUI / External via a hidden class */ + + + + #include -//#include - -#include "dbase/cachestrapper.h" -#include "ft/ftserver.h" -#include "ft/ftcontroller.h" -#include "rsiface/rsturtle.h" - -/* global variable now points straight to - * ft/ code so variable defined here. - */ - -RsFiles *rsFiles = NULL; -RsTurtle *rsTurtle = NULL ; - -#include "pqi/pqipersongrp.h" -#include "pqi/pqisslpersongrp.h" -#include "pqi/pqiloopback.h" -#include "pqi/p3cfgmgr.h" - #include "util/rsdebug.h" #include "util/rsdir.h" - #include "rsiface/rsinit.h" -#include "upnp/upnphandler.h" -#include "dht/opendhtmgr.h" - -#include "services/p3disc.h" -#include "services/p3msgservice.h" -#include "services/p3chatservice.h" -#include "services/p3gamelauncher.h" -#include "services/p3ranking.h" -#include "services/p3photoservice.h" -#include "services/p3forums.h" -#include "services/p3channels.h" -#include "services/p3status.h" -#include "services/p3Qblog.h" -#include "turtle/p3turtle.h" #include #include #include +#include +#include +#include +#include + // for blocking signals #include -/* Implemented Rs Interfaces */ -#include "rsserver/p3face.h" -#include "rsserver/p3peers.h" -#include "rsserver/p3rank.h" -#include "rsserver/p3msgs.h" -#include "rsserver/p3discovery.h" -#include "rsserver/p3photo.h" -#include "rsserver/p3Blog.h" -#include "rsiface/rsgame.h" - -#include "rsserver/p3files.h" - -#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order. - - -// COMMENT THIS FOR UNFINISHED SERVICES -/**** -#define RS_RELEASE 1 -****/ - -#define RS_RELEASE 1 - /**************** PQI_USE_XPGP ******************/ #if defined(PQI_USE_XPGP) #include "pqi/authxpgp.h" @@ -110,6 +64,70 @@ RsTurtle *rsTurtle = NULL ; #endif /* X509 Certificates */ /**************** PQI_USE_XPGP ******************/ +class accountId +{ + public: + std::string pgpId; + std::string pgpName; + std::string pgpEmail; + + std::string sslId; + std::string sslName; +}; + + +class RsInitConfig +{ + public: + /* OS Specifics */ + static char dirSeperator; + + /* Directories (SetupBaseDir) */ + static std::string basedir; + static std::string homePath; + + static std::list accountIds; + static std::string preferedId; + + /* for certificate creation */ + //static std::string gpgPasswd; + + /* These fields are needed for login */ + static std::string loginId; + static std::string configDir; + static std::string load_cert; + static std::string load_key; + static std::string passwd; + + static bool havePasswd; /* for Commandline password */ + static bool autoLogin; /* autoLogin allowed */ + static bool startMinimised; /* Icon or Full Window */ + + /* Key Parameters that must be set before + * RetroShare will start up: + */ + + /* Listening Port */ + static bool forceExtPort; + static bool forceLocalAddr; + static unsigned short port; + static char inet[256]; + + /* Logging */ + static bool haveLogFile; + static bool outStderr; + static bool haveDebugLevel; + static int debugLevel; + static char logfname[1024]; + + static bool firsttime_run; + static bool load_trustedpeer; + static std::string load_trustedpeer_file; + + static bool udpListenerOnly; +}; + + const int p3facestartupzone = 47238; // initial configuration bootstrapping... @@ -121,86 +139,83 @@ static const std::string configCaFile = "cacerts.pem"; static const std::string configLogFileName = "retro.log"; static const std::string configHelpName = "retro.htm"; -std::string RsInit::load_cert; -std::string RsInit::load_key; -std::string RsInit::passwd; +std::list RsInitConfig::accountIds; +std::string RsInitConfig::preferedId; -bool RsInit::havePasswd; /* for Commandline password */ -bool RsInit::autoLogin; /* autoLogin allowed */ -bool RsInit::startMinimised; /* Icon or Full Window */ +std::string RsInitConfig::configDir; +std::string RsInitConfig::load_cert; +std::string RsInitConfig::load_key; +std::string RsInitConfig::passwd; +//std::string RsInitConfig::gpgPasswd; + +bool RsInitConfig::havePasswd; /* for Commandline password */ +bool RsInitConfig::autoLogin; /* autoLogin allowed */ +bool RsInitConfig::startMinimised; /* Icon or Full Window */ /* Win/Unix Differences */ -char RsInit::dirSeperator; +char RsInitConfig::dirSeperator; /* Directories */ -std::string RsInit::basedir; -std::string RsInit::homePath; +std::string RsInitConfig::basedir; +std::string RsInitConfig::homePath; /* Listening Port */ -bool RsInit::forceExtPort; -bool RsInit::forceLocalAddr; -unsigned short RsInit::port; -char RsInit::inet[256]; +bool RsInitConfig::forceExtPort; +bool RsInitConfig::forceLocalAddr; +unsigned short RsInitConfig::port; +char RsInitConfig::inet[256]; /* Logging */ -bool RsInit::haveLogFile; -bool RsInit::outStderr; -bool RsInit::haveDebugLevel; -int RsInit::debugLevel; -char RsInit::logfname[1024]; +bool RsInitConfig::haveLogFile; +bool RsInitConfig::outStderr; +bool RsInitConfig::haveDebugLevel; +int RsInitConfig::debugLevel; +char RsInitConfig::logfname[1024]; -bool RsInit::firsttime_run; -bool RsInit::load_trustedpeer; -std::string RsInit::load_trustedpeer_file; +bool RsInitConfig::firsttime_run; +bool RsInitConfig::load_trustedpeer; +std::string RsInitConfig::load_trustedpeer_file; -bool RsInit::udpListenerOnly; +bool RsInitConfig::udpListenerOnly; -/* Helper Functions */ -//void load_check_basedir(RsInit *config); -//int create_configinit(RsInit *config); +/* Uses private class - so must be hidden */ +static bool getAvailableAccounts(std::list &ids); +static bool checkAccount(std::string accountdir, accountId &id); -RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify) -{ - RsServer *srv = new RsServer(iface, notify); - return srv; -} - -//void CleanupRsConfig(RsInit *config) -//{ -// delete config; -//} void RsInit::InitRsConfig() { - load_trustedpeer = false; - firsttime_run = false; - port = 7812; // default port. - forceLocalAddr = false; - haveLogFile = false; - outStderr = false; - forceExtPort = false; - - strcpy(inet, "127.0.0.1"); - strcpy(logfname, ""); - - autoLogin = true; // Always on now. - startMinimised = false; - passwd = ""; - havePasswd = false; - haveDebugLevel = false; - debugLevel = PQL_WARNING; - udpListenerOnly = false; - #ifndef WINDOWS_SYS - dirSeperator = '/'; // For unix. + RsInitConfig::dirSeperator = '/'; // For unix. #else - dirSeperator = '\\'; // For windows. + RsInitConfig::dirSeperator = '\\'; // For windows. #endif - /* setup the homePath (default save location) */ - homePath = getHomePath(); + RsInitConfig::load_trustedpeer = false; + RsInitConfig::firsttime_run = false; + RsInitConfig::port = 7812; // default port. + RsInitConfig::forceLocalAddr = false; + RsInitConfig::haveLogFile = false; + RsInitConfig::outStderr = false; + RsInitConfig::forceExtPort = false; + + strcpy(RsInitConfig::inet, "127.0.0.1"); + strcpy(RsInitConfig::logfname, ""); + + RsInitConfig::autoLogin = true; // Always on now. + RsInitConfig::startMinimised = false; + RsInitConfig::passwd = ""; + RsInitConfig::havePasswd = false; + RsInitConfig::haveDebugLevel = false; + RsInitConfig::debugLevel = PQL_WARNING; + RsInitConfig::udpListenerOnly = false; + + RsInitConfig::/* setup the homePath (default save location) */ + + RsInitConfig::homePath = getHomePath(); + /* Setup the Debugging */ // setup debugging for desired zones. @@ -231,15 +246,6 @@ void RsInit::InitRsConfig() //setZoneLevel(PQL_DEBUG_BASIC, 49787); // pqissllistener } -const char *RsInit::RsConfigDirectory() -{ - return basedir.c_str(); -} - -bool RsInit::setStartMinimised() -{ - return startMinimised; -} /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS @@ -309,64 +315,64 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored) switch (c) { case 'a': - autoLogin = true; - startMinimised = true; + RsInitConfig::autoLogin = true; + RsInitConfig::startMinimised = true; std::cerr << "AutoLogin Allowed / Start Minimised On"; std::cerr << std::endl; break; case 'm': - startMinimised = true; + RsInitConfig::startMinimised = true; std::cerr << "Start Minimised On"; std::cerr << std::endl; break; case 'l': - strncpy(logfname, optarg, 1024); - std::cerr << "LogFile (" << logfname; + strncpy(RsInitConfig::logfname, optarg, 1024); + std::cerr << "LogFile (" << RsInitConfig::logfname; std::cerr << ") Selected" << std::endl; - haveLogFile = true; + RsInitConfig::haveLogFile = true; break; case 'w': - passwd = optarg; - std::cerr << "Password Specified(" << passwd; + RsInitConfig::passwd = optarg; + std::cerr << "Password Specified(" << RsInitConfig::passwd; std::cerr << ") Selected" << std::endl; - havePasswd = true; + RsInitConfig::havePasswd = true; break; case 'i': - strncpy(inet, optarg, 256); - std::cerr << "New Inet Addr(" << inet; + strncpy(RsInitConfig::inet, optarg, 256); + std::cerr << "New Inet Addr(" << RsInitConfig::inet; std::cerr << ") Selected" << std::endl; - forceLocalAddr = true; + RsInitConfig::forceLocalAddr = true; break; case 'p': - port = atoi(optarg); - std::cerr << "New Listening Port(" << port; + RsInitConfig::port = atoi(optarg); + std::cerr << "New Listening Port(" << RsInitConfig::port; std::cerr << ") Selected" << std::endl; break; case 'c': - basedir = optarg; + RsInitConfig::basedir = optarg; std::cerr << "New Base Config Dir("; - std::cerr << basedir; + std::cerr << RsInitConfig::basedir; std::cerr << ") Selected" << std::endl; break; case 's': - outStderr = true; - haveLogFile = false; + RsInitConfig::outStderr = true; + RsInitConfig::haveLogFile = false; std::cerr << "Output to Stderr"; std::cerr << std::endl; break; case 'd': - haveDebugLevel = true; - debugLevel = atoi(optarg); + RsInitConfig::haveDebugLevel = true; + RsInitConfig::debugLevel = atoi(optarg); std::cerr << "Opt for new Debug Level"; std::cerr << std::endl; break; case 'u': - udpListenerOnly = true; + RsInitConfig::udpListenerOnly = true; std::cerr << "Opt for only udpListener"; std::cerr << std::endl; break; case 'e': - forceExtPort = true; + RsInitConfig::forceExtPort = true; std::cerr << "Opt for External Port Mode"; std::cerr << std::endl; break; @@ -397,28 +403,28 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored) // set the default Debug Level... - if (haveDebugLevel) + if (RsInitConfig::haveDebugLevel) { - if ((debugLevel > 0) && - (debugLevel <= PQL_DEBUG_ALL)) + if ((RsInitConfig::debugLevel > 0) && + (RsInitConfig::debugLevel <= PQL_DEBUG_ALL)) { std::cerr << "Setting Debug Level to: "; - std::cerr << debugLevel; + std::cerr << RsInitConfig::debugLevel; std::cerr << std::endl; - setOutputLevel(debugLevel); + setOutputLevel(RsInitConfig::debugLevel); } else { std::cerr << "Ignoring Invalid Debug Level: "; - std::cerr << debugLevel; + std::cerr << RsInitConfig::debugLevel; std::cerr << std::endl; } } // set the debug file. - if (haveLogFile) + if (RsInitConfig::haveLogFile) { - setDebugFile(logfname); + setDebugFile(RsInitConfig::logfname); } /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ @@ -442,10 +448,6 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored) #endif /********************************** WINDOWS/UNIX SPECIFIC PART ******************/ - - // first check config directories, and set bootstrap values. - load_check_basedir(); - // SWITCH off the SIGPIPE - kills process on Linux. /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ #ifndef WINDOWS_SYS @@ -466,50 +468,49 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored) #endif /******************************** WINDOWS/UNIX SPECIFIC PART ******************/ + + /* At this point we want to. + * 1) Load up Dase Directory. + * 3) Get Prefered Id. + * 2) Get List of Available Accounts. + * 4) Get List of GPG Accounts. + */ + + getAuthMgr() -> InitAuth(NULL, NULL, NULL); + + // first check config directories, and set bootstrap values. + setupBaseDir(); + get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId); + //std::list ids; + std::list::iterator it; + getAvailableAccounts(RsInitConfig::accountIds); + + /* check that preferedId */ std::string userName; std::string userId; bool existingUser = false; - - /* do a null init to allow the SSL libray to startup! */ -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) - if (LoadCheckXPGPandGetName(load_cert.c_str(), userName, userId)) + for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++) { - std::cerr << "Existing Name: " << userName << std::endl; - std::cerr << "Existing Id: " << userId << std::endl; - existingUser = true; + std::cerr << "Checking Account Id: " << it->sslId << std::endl; + if (RsInitConfig::preferedId == it->sslId) + { + std::cerr << " * Preferred * " << std::endl; + userId = it->sslId; + userName = it->sslName; + existingUser = true; + } } - else - { - std::cerr << "No Existing User" << std::endl; - } -#else /* X509 Certificates */ -/**************** PQI_USE_SSLONLY ***************/ - /* Initial Certificate load will be X509 for SSL cases. - * in the OpenPGP case, this needs to be checked too. - */ - - if (LoadCheckX509andGetName(load_cert.c_str(), userName, userId)) - { - std::cerr << "X509 Existing Name: " << userName << std::endl; - std::cerr << "Existing Id: " << userId << std::endl; - existingUser = true; - } - else + if (!existingUser) { std::cerr << "No Existing User" << std::endl; + RsInitConfig::preferedId == ""; } -/**************** SSL + OPENPGP *****************/ -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - - getAuthMgr() -> InitAuth(NULL, NULL, NULL); /* if existing user, and havePasswd .... we can skip the login prompt */ if (existingUser) { - if (havePasswd) + if (RsInitConfig::havePasswd) { return 1; } @@ -521,8 +522,267 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored) return 0; } -#ifdef RS_USE_PGPSSL -int RsInit::GetLogins(std::list &pgpIds) +/**************************** Access Functions for Init Data **************************/ + +bool RsInit::getPreferedAccountId(std::string &id) +{ + id = RsInitConfig::preferedId; + return (RsInitConfig::preferedId != ""); +} + +bool RsInit::getAccountIds(std::list &ids) +{ + std::list::iterator it; + std::cerr << "getAccountIds:" << std::endl; + + for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++) + { + std::cerr << "SSL Id: " << it->sslId << " PGP Id " << it->pgpId << + std::cerr << " PGP Name: " << it->pgpName; + std::cerr << " PGP Email: " << it->pgpEmail; + std::cerr << " SSL Name: " << it->sslName; + std::cerr << std::endl; + + ids.push_back(it->sslId); + } + return true; +} + + +bool RsInit::getAccountDetails(std::string id, + std::string &gpgId, std::string &gpgName, + std::string &gpgEmail, std::string &sslName) +{ + std::list::iterator it; + for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++) + { + if (id == it->sslId) + { + gpgId = it->pgpId; + gpgName = it->pgpName; + gpgEmail = it->pgpEmail; + sslName = it->sslName; + return true; + } + } + return false; +} + +/**************************** Access Functions for Init Data **************************/ +/**************************** Private Functions for InitRetroshare ********************/ +/**************************** Private Functions for InitRetroshare ********************/ + + +void RsInit::setupBaseDir() +{ + // get the default configuration location. + + if (RsInitConfig::basedir == "") + { + // v0.4.x if unix. homedir + /.pqiPGPrc + // v0.5.x if unix. homedir + /.retroshare + +/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ +#ifndef WINDOWS_SYS + char *h = getenv("HOME"); + std::cerr << "retroShare::basedir() -> $HOME = "; + std::cerr << h << std::endl; + if (h == NULL) + { + std::cerr << "load_check_basedir() Fatal Error --"; + std::cerr << std::endl; + std::cerr << "\tcannot determine $HOME dir" < $APPDATA = "; + std::cerr << h << std::endl; + char *h2 = getenv("HOMEDRIVE"); + std::cerr << "retroShare::basedir() -> $HOMEDRIVE = "; + std::cerr << h2 << std::endl; + char *h3 = getenv("HOMEPATH"); + std::cerr << "retroShare::basedir() -> $HOMEPATH = "; + std::cerr << h3 << std::endl; + if (h == NULL) + { + // generating default + std::cerr << "load_check_basedir() getEnv Error --Win95/98?"; + std::cerr << std::endl; + + RsInitConfig::basedir="C:\\Retro"; + + } + else + { + RsInitConfig::basedir = h; + } + + if (!RsDirUtil::checkCreateDirectory(RsInitConfig::basedir)) + { + std::cerr << "Cannot Create BaseConfig Dir" << std::endl; + exit(1); + } + basedir += "\\RetroShare"; +#endif +/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ + } + + // fatal if cannot find/create. + std::cerr << "Creating Root Retroshare Config Directories" << std::endl; + if (!RsDirUtil::checkCreateDirectory(RsInitConfig::basedir)) + { + std::cerr << "Cannot Create BaseConfig Dir:" << RsInitConfig::basedir << std::endl; + exit(1); + } +} + + +/* directories with valid certificates in the expected location */ +bool getAvailableAccounts(std::list &ids) +{ + /* get the directories */ + std::list directories; + std::list::iterator it; + + std::cerr << "getAvailableAccounts()"; + std::cerr << std::endl; + + /* now iterate through the directory... + * directories - flags as old, + * files checked to see if they have changed. (rehashed) + */ + + struct dirent *dent; + struct stat buf; + + /* check for the dir existance */ + DIR *dir = opendir(RsInitConfig::basedir.c_str()); + if (!dir) + { + std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl; + exit(1); + } + + while(NULL != (dent = readdir(dir))) + { + /* check entry type */ + std::string fname = dent -> d_name; + std::string fullname = RsInitConfig::basedir + "/" + fname; + + if (-1 != stat(fullname.c_str(), &buf)) + { + #ifdef FIM_DEBUG + std::cerr << "buf.st_mode: " << buf.st_mode < &pgpIds) { #ifdef PQI_USE_XPGP return 0; @@ -538,8 +798,11 @@ int RsInit::GetLogins(std::list &pgpIds) #endif } -int RsInit::GetLoginDetails(std::string id, std::string &name, std::string &email) +int RsInit::GetPGPLoginDetails(std::string id, std::string &name, std::string &email) { + std::cerr << "RsInit::GetPGPLoginDetails for \"" << id << "\""; + std::cerr << std::endl; + #ifdef PQI_USE_XPGP return 0; #else @@ -562,19 +825,17 @@ int RsInit::GetLoginDetails(std::string id, std::string &name, std::string &emai #endif } +/* Before any SSL stuff can be loaded, the correct PGP must be selected / generated: + **/ -std::string RsInit::gpgPasswd; - -bool RsInit::LoadGPGPassword(std::string id, std::string _passwd) +bool RsInit::SelectGPGAccount(std::string id) { bool ok = false; std::string gpgId = id; std::string name = id; - gpgPasswd = _passwd; - GPGAuthMgr *gpgAuthMgr = (GPGAuthMgr *) getAuthMgr(); - if (0 < gpgAuthMgr -> GPGInit(gpgId, name, gpgPasswd.c_str())) + if (0 < gpgAuthMgr -> GPGInit(gpgId)) { ok = true; std::cerr << "PGP Auth Success!"; @@ -590,554 +851,35 @@ bool RsInit::LoadGPGPassword(std::string id, std::string _passwd) return ok; } -#endif // RS_USE_PGPSSL - - - - -const std::string& RsServer::certificateFileName() { return RsInit::load_cert ; } -/* - * The Real RetroShare Startup Function. - */ - -int RsServer::StartupRetroShare() +bool RsInit::LoadGPGPassword(std::string inPGPpasswd) { - /**************************************************************************/ - /* STARTUP procedure */ - /**************************************************************************/ - /**************************************************************************/ - /* (1) Load up own certificate (DONE ALREADY) - just CHECK */ - /**************************************************************************/ - - mAuthMgr = getAuthMgr(); - -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) - if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL)) -#else /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL)) -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - { - std::cerr << "main() - Fatal Error....." << std::endl; - std::cerr << "Invalid Certificate configuration!" << std::endl; - std::cerr << std::endl; - exit(1); - } - - std::string ownId = mAuthMgr->OwnId(); - - /**************************************************************************/ - /* Any Initial Configuration (Commandline Options) */ - /**************************************************************************/ - - /* set the debugging to crashMode */ - if ((!RsInit::haveLogFile) && (!RsInit::outStderr)) - { - std::string crashfile = RsInit::basedir + RsInit::dirSeperator; - crashfile += configLogFileName; - setDebugCrashMode(crashfile.c_str()); - } - - unsigned long flags = 0; - if (RsInit::udpListenerOnly) - { - flags |= PQIPERSON_NO_LISTENER; - } - - /**************************************************************************/ - - // Load up Certificates, and Old Configuration (if present) - - std::string certConfigFile = RsInit::basedir.c_str(); - std::string certNeighDir = RsInit::basedir.c_str(); - std::string emergencySaveDir = RsInit::basedir.c_str(); - std::string emergencyPartialsDir = RsInit::basedir.c_str(); - if (certConfigFile != "") - { - certConfigFile += "/"; - certNeighDir += "/"; - emergencySaveDir += "/"; - emergencyPartialsDir += "/"; - } - certConfigFile += configConfFile; - certNeighDir += configCertDir; - emergencySaveDir += "Incoming"; - emergencyPartialsDir += "Partials"; - - /* if we've loaded an old format file! */ - bool oldFormat = false; - std::map oldConfigMap; - - mAuthMgr -> setConfigDirectories(certConfigFile, certNeighDir); - - mAuthMgr -> loadCertificates(); - - /**************************************************************************/ - /* setup classes / structures */ - /**************************************************************************/ - - /* Setup Notify Early - So we can use it. */ - rsNotify = new p3Notify(); - - mConnMgr = new p3ConnectMgr(mAuthMgr); - pqiNetAssistFirewall *mUpnpMgr = new upnphandler(); - p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInit::basedir); - - SecurityPolicy *none = secpolicy_create(); - pqih = new pqisslpersongrp(none, flags); - //pqih = new pqipersongrpDummy(none, flags); - - /****** New Ft Server **** !!! */ - ftserver = new ftServer(mAuthMgr, mConnMgr); - ftserver->setP3Interface(pqih); - ftserver->setConfigDirectory(RsInit::basedir); - - ftserver->SetupFtServer(&(getNotify())); - CacheStrapper *mCacheStrapper = ftserver->getCacheStrapper(); - CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer(); - - /* setup any extra bits (Default Paths) */ - ftserver->setPartialsDirectory(emergencyPartialsDir); - ftserver->setDownloadDirectory(emergencySaveDir); - - /* This should be set by config ... there is no default */ - //ftserver->setSharedDirectories(fileList); - rsFiles = ftserver; - - - mConfigMgr = new p3ConfigMgr(mAuthMgr, RsInit::basedir, "rs-v0.4.cfg", "rs-v0.4.sgn"); - mGeneralConfig = new p3GeneralConfig(); - - /* create Services */ - ad = new p3disc(mAuthMgr, mConnMgr); - msgSrv = new p3MsgService(mConnMgr); - chatSrv = new p3ChatService(mConnMgr); - - p3turtle *tr = new p3turtle(mConnMgr,ftserver) ; - rsTurtle = tr ; - pqih -> addService(tr); - ftserver->connectToTurtleRouter(tr) ; - - pqih -> addService(ad); - pqih -> addService(msgSrv); - pqih -> addService(chatSrv); - - /* create Cache Services */ - std::string config_dir = RsInit::basedir; - std::string localcachedir = config_dir + "/cache/local"; - std::string remotecachedir = config_dir + "/cache/remote"; - std::string channelsdir = config_dir + "/channels"; - - - //mRanking = NULL; - mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */ - mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months - - CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0)); - mCacheStrapper -> addCachePair(cp); /* end of declaration */ - - p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM, - mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir, mAuthMgr); - - CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0)); - mCacheStrapper -> addCachePair(cp4); - pqih -> addService(mForums); /* This must be also ticked as a service */ - - p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL, - mCacheStrapper, mCacheTransfer, rsFiles, - localcachedir, remotecachedir, channelsdir, mAuthMgr); - - CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0)); - mCacheStrapper -> addCachePair(cp5); - pqih -> addService(mChannels); /* This must be also ticked as a service */ - - -#ifndef RS_RELEASE - - p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr); - pqih -> addService(gameLauncher); - - p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */ - mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir); - - CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0)); - mCacheStrapper -> addCachePair(cp2); - - mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */ - mCacheStrapper, mCacheTransfer, - localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months - - CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0)); - mCacheStrapper -> addCachePair(cp3); - - -#else - mQblog = NULL; -#endif - - /**************************************************************************/ - - mConnMgr->addNetAssistConnect(1, mDhtMgr); - mConnMgr->addNetAssistFirewall(1, mUpnpMgr); - - /**************************************************************************/ - /* need to Monitor too! */ - - mConnMgr->addMonitor(pqih); - mConnMgr->addMonitor(mCacheStrapper); - mConnMgr->addMonitor(ad); - mConnMgr->addMonitor(msgSrv); - - /* must also add the controller as a Monitor... - * a little hack to get it to work. - */ - mConnMgr->addMonitor(((ftController *) mCacheTransfer)); - - - /**************************************************************************/ - - //mConfigMgr->addConfiguration("ftserver.cfg", ftserver); - // - mConfigMgr->addConfiguration("peers.cfg", mConnMgr); - mConfigMgr->addConfiguration("general.cfg", mGeneralConfig); - mConfigMgr->addConfiguration("msgs.cfg", msgSrv); - mConfigMgr->addConfiguration("chat.cfg", chatSrv); - mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper); - - mConfigMgr->addConfiguration("ranklink.cfg", mRanking); - mConfigMgr->addConfiguration("forums.cfg", mForums); - mConfigMgr->addConfiguration("channels.cfg", mChannels); - mConfigMgr->addConfiguration("turtle.cfg", tr); - -#ifndef RS_RELEASE -#else -#endif - - ftserver->addConfiguration(mConfigMgr); - - - /**************************************************************************/ - - - /**************************************************************************/ - /* (2) Load configuration files */ - /**************************************************************************/ - - mConfigMgr->loadConfiguration(); - - /* NOTE: CacheStrapper's load causes Cache Files to be - * loaded into all the CacheStores/Sources. This happens - * after all the other configurations have happened. - */ - - /**************************************************************************/ - /* Hack Old Configuration into new System (first load only) */ - /**************************************************************************/ - -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) -#else /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - - /**************************************************************************/ - /* trigger generalConfig loading for classes that require it */ - /**************************************************************************/ - - pqih->setConfig(mGeneralConfig); - - pqih->load_config(); - - /**************************************************************************/ - /* Force Any Configuration before Startup (After Load) */ - /**************************************************************************/ - - if (RsInit::forceLocalAddr) - { - struct sockaddr_in laddr; - - /* clean sockaddr before setting values (MaxOSX) */ - sockaddr_clear(&laddr); - - laddr.sin_family = AF_INET; - laddr.sin_port = htons(RsInit::port); - - // universal - laddr.sin_addr.s_addr = inet_addr(RsInit::inet); - - mConnMgr->setLocalAddress(ownId, laddr); - } - - if (RsInit::forceExtPort) - { - mConnMgr->setOwnNetConfig(RS_NET_MODE_EXT, RS_VIS_STATE_STD); - } - -#if 0 - /* must load the trusted_peer before setting up the pqipersongrp */ - if (firsttime_run) - { - /* at this point we want to load and start the trusted peer -> if selected */ - if (load_trustedpeer) - { - /* sslroot does further checks */ - sslr -> loadInitialTrustedPeer(load_trustedpeer_file); - } - } -#endif - - mConnMgr -> checkNetAddress(); - - /**************************************************************************/ - /* startup (stuff dependent on Ids/peers is after this point) */ - /**************************************************************************/ - - pqih->init_listener(); - - - - - /**************************************************************************/ - /* load caches and secondary data */ - /**************************************************************************/ - - - /**************************************************************************/ - /* Force Any Last Configuration Options */ - /**************************************************************************/ - - /**************************************************************************/ - /* Start up Threads */ - /**************************************************************************/ - - ftserver->StartupThreads(); - ftserver->ResumeTransfers(); - - mDhtMgr->start(); - - // create loopback device, and add to pqisslgrp. - - SearchModule *mod = new SearchModule(); - pqiloopback *ploop = new pqiloopback(ownId); - - mod -> peerid = ownId; - mod -> pqi = ploop; - mod -> sp = secpolicy_create(); - - pqih->AddSearchModule(mod); - - /* Setup GUI Interfaces. */ - - rsPeers = new p3Peers(mConnMgr, mAuthMgr); - rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv); - rsDisc = new p3Discovery(ad); - - rsForums = mForums; - rsChannels = mChannels; - rsRanks = new p3Rank(mRanking); - -#ifndef RS_RELEASE - rsGameLauncher = gameLauncher; - rsPhoto = new p3Photo(photoService); - rsStatus = new p3Status(); - rsQblog = new p3Blog(mQblog); - -#else - rsGameLauncher = NULL; - rsPhoto = NULL; - rsStatus = NULL; - rsQblog = NULL; -#endif - - - /* put a welcome message in! */ - if (RsInit::firsttime_run) - { - msgSrv->loadWelcomeMsg(); - } - - // load up the help page - std::string helppage = RsInit::basedir + RsInit::dirSeperator; - helppage += configHelpName; - - /* for DHT/UPnP stuff */ - //InitNetworking(basedir + "/kadc.ini"); - - /* Startup this thread! */ - createThread(*this); - - - return 1; -} - - - -int RsInit::LoadCertificates(bool autoLoginNT) -{ - if (load_cert == "") - { - std::cerr << "RetroShare needs a certificate" << std::endl; - return 0; - } - - if (load_key == "") - { - std::cerr << "RetroShare needs a key" << std::endl; - return 0; - } - - if ((!havePasswd) || (passwd == "")) - { - std::cerr << "RetroShare needs a Password" << std::endl; - return 0; - } - - std::string ca_loc = basedir + dirSeperator; - ca_loc += configCaFile; - - p3AuthMgr *authMgr = getAuthMgr(); + GPGAuthMgr *gpgAuthMgr = (GPGAuthMgr *) getAuthMgr(); bool ok = false; - -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) - if (0 < authMgr -> InitAuth(load_cert.c_str(), load_key.c_str(),passwd.c_str())) + if (0 < gpgAuthMgr -> LoadGPGPassword(inPGPpasswd)) { ok = true; - } -#else /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - /* The SSL / SSL + PGP version requires, SSL init + PGP init. */ - /**************** PQI_USE_XPGP ******************/ - #if defined(PQI_USE_SSLONLY) - if (0 < authMgr -> InitAuth(load_cert.c_str(), load_key.c_str(),passwd.c_str())) - { - ok = true; - } - else - { - std::cerr << "AuthSSL::InitAuth Failed" << std::endl; - } - - #else /* X509 Certificates */ - /**************** PQI_USE_XPGP ******************/ - /* The SSL / SSL + PGP version requires, SSL init + PGP init. */ - if (0 < authMgr -> InitAuth(load_cert.c_str(), load_key.c_str(),passwd.c_str())) - { - ok = true; - } - else - { - std::cerr << "SSL Auth Failed!"; + std::cerr << "PGP LoadPwd Success!"; std::cerr << std::endl; } - #endif /* X509 Certificates */ - /**************** PQI_USE_XPGP ******************/ -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - - if (ok) - { - if (autoLoginNT) - { - std::cerr << "RetroShare will AutoLogin next time"; - std::cerr << std::endl; - - RsStoreAutoLogin(); - } - /* wipe password */ - passwd = ""; - create_configinit(); - return 1; - } - - std::cerr << "RetroShare Failed To Start!" << std::endl; - std::cerr << "Please Check File Names/Password" << std::endl; - - return 0; -} - -/* To Enter RetroShare.... must call either: - * LoadPassword, or - * RsGenerateCertificate. - * - * Then call LoadCertificate .... if it returns true.... - * its all okay. - */ - -/* Assistance for Login */ -bool RsInit::ValidateCertificate(std::string &userName) -{ - std::string fname = load_cert; - std::string userId; - if (fname != "") - { -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) - return LoadCheckXPGPandGetName(fname.c_str(), userName, userId); -#else /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - /* check against authmanagers private keys */ - return LoadCheckX509andGetName(fname.c_str(), userName, userId); -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - - } - return false; -} - -bool RsInit::ValidateTrustedUser(std::string fname, std::string &userName) -{ - std::string userId; - bool valid = false; -/**************** PQI_USE_XPGP ******************/ -#if defined(PQI_USE_XPGP) - valid = LoadCheckXPGPandGetName(fname.c_str(), userName, userId); -#else /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - valid = LoadCheckX509andGetName(fname.c_str(), userName, userId); -#endif /* X509 Certificates */ -/**************** PQI_USE_XPGP ******************/ - - if (valid) - { - load_trustedpeer = true; - load_trustedpeer_file = fname; - } else { - load_trustedpeer = false; + std::cerr << "PGP LoadPwd Failed!"; + std::cerr << std::endl; } - return valid; + return ok; } -bool RsInit::LoadPassword(std::string _passwd) + +bool GeneratePGPCertificate(std::string name, std::string comment, std::string email, std::string passwd, std::string &pgpId, std::string &errString) { - passwd = _passwd; - havePasswd = true; return true; } -/* A little nasty fn.... - * (1) returns true, if successful, and updates config. - * (2) returns false if fails, with error msg to errString. - */ - -bool RsInit::RsGenerateCertificate( - std::string name, - std::string org, - std::string loc, - std::string country, - std::string password, - std::string &errString) + /* Create SSL Certificates */ +bool RsInit::GenerateSSLCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString) { // In the XPGP world this is easy... // generate the private_key / certificate. @@ -1146,7 +888,7 @@ bool RsInit::RsGenerateCertificate( // then load as if they had entered a passwd. // check password. - if (password.length() < 4) + if (passwd.length() < 4) { errString = "Password is Unsatisfactory (must be 4+ chars)"; return false; @@ -1160,9 +902,16 @@ bool RsInit::RsGenerateCertificate( int nbits = 2048; - // Create the filename. - std::string basename = basedir + dirSeperator; - basename += configKeyDir + dirSeperator; + // Create the filename ..... + // Temporary Directory for creating files.... + std::string tmpdir = "TMPCFG"; + + std::string tmpbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + tmpdir + RsInitConfig::dirSeperator; + RsInit::setupAccount(tmpbase); + + /* create directory structure */ + + std::string basename = tmpbase + configKeyDir + RsInitConfig::dirSeperator; basename += "user"; std::string key_name = basename + "_pk.pem"; @@ -1172,8 +921,8 @@ bool RsInit::RsGenerateCertificate( /**************** PQI_USE_XPGP ******************/ #if defined(PQI_USE_XPGP) - if (generate_xpgp(cert_name.c_str(), key_name.c_str(), - password.c_str(), + if (!generate_xpgp(cert_name.c_str(), key_name.c_str(), + passwd.c_str(), name.c_str(), "", //ui -> gen_email -> value(), org.c_str(), @@ -1223,11 +972,11 @@ bool RsInit::RsGenerateCertificate( gen_ok = false; } - + X509 *cert = NULL; if (gen_ok) { - cert = SignX509Certificate(X509_REQ_get_subject_name(req), + cert = SignX509Certificate(X509_REQ_get_subject_name(req), privkey,req,days); /* Print the signed Certificate! */ @@ -1269,7 +1018,7 @@ bool RsInit::RsGenerateCertificate( } if (cert) - { + { gen_ok = true; } @@ -1290,7 +1039,7 @@ bool RsInit::RsGenerateCertificate( X509_REQ *req = GenerateX509Req( key_name.c_str(), - password.c_str(), + passwd.c_str(), name.c_str(), "", //ui -> gen_email -> value(), org.c_str(), @@ -1307,7 +1056,7 @@ bool RsInit::RsGenerateCertificate( /* save to file */ if (x509) - { + { gen_ok = true; /* Print the signed Certificate! */ @@ -1341,14 +1090,14 @@ bool RsInit::RsGenerateCertificate( fprintf(stderr," : %s\n", cert_name.c_str()); gen_ok = false; } - + if (!PEM_write_X509(out,x509)) { fprintf(stderr,"RsGenerateCert() Couldn't Save Cert"); fprintf(stderr," : %s\n", cert_name.c_str()); gen_ok = false; } - + fclose(out); X509_free(x509); } @@ -1365,16 +1114,36 @@ bool RsInit::RsGenerateCertificate( return false; } - /* set the load passwd to the gen version - * and try to load it! - */ + /* try to load it, and get Id */ - /* if we get here .... then save details to the configuration class */ - load_cert = cert_name; - load_key = key_name; - passwd = password; - havePasswd = true; - firsttime_run = true; + std::string sslName; + int ret = 0; + +/**************** PQI_USE_XPGP ******************/ +#if defined(PQI_USE_XPGP) + ret = LoadCheckXPGPandGetName(cert_name.c_str(), sslName, sslId); +#else /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + ret = LoadCheckX509andGetName(cert_name.c_str(), sslName, sslId); +#endif /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + + + /* Move directory to correct id */ + std::string finalbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + sslId + RsInitConfig::dirSeperator; + /* Rename Directory */ + + std::cerr << "Mv Config Dir from: " << tmpbase << " to: " << finalbase; + std::cerr << std::endl; + + if (0 > rename(tmpbase.c_str(), finalbase.c_str())) + { + std::cerr << "rename FAILED" << std::endl; + } + + + /* Flag as first time run */ + RsInitConfig::firsttime_run = true; { std::ostringstream out; @@ -1388,79 +1157,27 @@ bool RsInit::RsGenerateCertificate( } - -void RsInit::load_check_basedir() +/******************* PRIVATE FNS TO HELP with GEN **************/ +bool RsInit::setupAccount(std::string accountdir) { - // get the default configuration location. + /* actual config directory isd */ - if (basedir == "") - { - // if unix. homedir + /.pqiPGPrc -/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS - char *h = getenv("HOME"); - std::cerr << "retroShare::basedir() -> $HOME = "; - std::cerr << h << std::endl; - if (h == NULL) - { - std::cerr << "load_check_basedir() Fatal Error --"; - std::cerr << std::endl; - std::cerr << "\tcannot determine $HOME dir" < $APPDATA = "; - std::cerr << h << std::endl; - char *h2 = getenv("HOMEDRIVE"); - std::cerr << "retroShare::basedir() -> $HOMEDRIVE = "; - std::cerr << h2 << std::endl; - char *h3 = getenv("HOMEPATH"); - std::cerr << "retroShare::basedir() -> $HOMEPATH = "; - std::cerr << h3 << std::endl; - if (h == NULL) - { - // generating default - std::cerr << "load_check_basedir() getEnv Error --Win95/98?"; - std::cerr << std::endl; - - basedir="C:\\Retro"; - - } - else - { - basedir = h; - } - - if (!RsDirUtil::checkCreateDirectory(basedir)) - { - std::cerr << "Cannot Create BaseConfig Dir" << std::endl; - exit(1); - } - basedir += "\\RetroShare"; -#endif -/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ - } - - - std::string subdir1 = basedir + dirSeperator; + std::string subdir1 = accountdir + RsInitConfig::dirSeperator; std::string subdir2 = subdir1; subdir1 += configKeyDir; subdir2 += configCertDir; - std::string subdir3 = basedir + dirSeperator; + std::string subdir3 = accountdir + RsInitConfig::dirSeperator; subdir3 += "cache"; - std::string subdir4 = subdir3 + dirSeperator; - std::string subdir5 = subdir3 + dirSeperator; + std::string subdir4 = subdir3 + RsInitConfig::dirSeperator; + std::string subdir5 = subdir3 + RsInitConfig::dirSeperator; subdir4 += "local"; subdir5 += "remote"; // fatal if cannot find/create. std::cerr << "Checking For Directories" << std::endl; - if (!RsDirUtil::checkCreateDirectory(basedir)) + if (!RsDirUtil::checkCreateDirectory(accountdir)) { std::cerr << "Cannot Create BaseConfig Dir" << std::endl; exit(1); @@ -1491,10 +1208,135 @@ void RsInit::load_check_basedir() exit(1); } + return true; +} + + + + + + +/***************************** FINAL LOADING OF SETUP *************************/ + /* Login SSL */ +bool RsInit::LoadPassword(std::string id, std::string inPwd) +{ + /* select configDir */ + + RsInitConfig::preferedId = id; + RsInitConfig::configDir = RsInitConfig::basedir + RsInitConfig::dirSeperator + id; + RsInitConfig::passwd = inPwd; + RsInitConfig::havePasswd = true; + + // Create the filename. + std::string basename = RsInitConfig::configDir + RsInitConfig::dirSeperator; + basename += configKeyDir + RsInitConfig::dirSeperator; + basename += "user"; + + RsInitConfig::load_key = basename + "_pk.pem"; + RsInitConfig::load_cert = basename + "_cert.pem"; + + return true; +} + + + +/***************************** FINAL LOADING OF SETUP ************************* + * Requires: + * PGPid to be selected (Password not required). + * CertId to be selected (Password Required). + */ + +int RsInit::LoadCertificates(bool autoLoginNT) +{ + if (RsInitConfig::load_cert == "") + { + std::cerr << "RetroShare needs a certificate" << std::endl; + return 0; + } + + if (RsInitConfig::load_key == "") + { + std::cerr << "RetroShare needs a key" << std::endl; + return 0; + } + + if ((!RsInitConfig::havePasswd) || (RsInitConfig::passwd == "")) + { + std::cerr << "RetroShare needs a Password" << std::endl; + return 0; + } + + //std::string ca_loc = RsInitConfig::basedir + RsInitConfig::dirSeperator; + //ca_loc += configCaFile; + + p3AuthMgr *authMgr = getAuthMgr(); + + bool ok = false; + +/**************** PQI_USE_XPGP ******************/ +#if defined(PQI_USE_XPGP) + if (0 < authMgr -> InitAuth(RsInitConfig::load_cert.c_str(), RsInitConfig::load_key.c_str(),RsInitConfig::passwd.c_str())) + { + ok = true; + } +#else /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + /* The SSL / SSL + PGP version requires, SSL init + PGP init. */ + /**************** PQI_USE_XPGP ******************/ + #if defined(PQI_USE_SSLONLY) + if (0 < authMgr -> InitAuth(RsInitConfig::load_cert.c_str(), RsInitConfig::load_key.c_str(),RsInitConfig::passwd.c_str())) + { + ok = true; + } + else + { + std::cerr << "AuthSSL::InitAuth Failed" << std::endl; + } + + #else /* X509 Certificates */ + /**************** PQI_USE_XPGP ******************/ + /* The SSL / SSL + PGP version requires, SSL init + PGP init. */ + if (0 < authMgr -> InitAuth(RsInitConfig::load_cert.c_str(), RsInitConfig::load_key.c_str(),RsInitConfig::passwd.c_str())) + { + ok = true; + } + else + { + std::cerr << "SSL Auth Failed!"; + std::cerr << std::endl; + } + #endif /* X509 Certificates */ + /**************** PQI_USE_XPGP ******************/ +#endif /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + + if (ok) + { + if (autoLoginNT) + { + std::cerr << "RetroShare will AutoLogin next time"; + std::cerr << std::endl; + + RsStoreAutoLogin(); + } + /* wipe password */ + RsInitConfig::passwd = ""; + create_configinit(RsInitConfig::basedir, RsInitConfig::preferedId); + return 1; + } + + std::cerr << "RetroShare Failed To Start!" << std::endl; + std::cerr << "Please Check File Names/Password" << std::endl; + + return 0; +} + +bool RsInit::get_configinit(std::string dir, std::string &id) +{ // have a config directories. // Check for config file. - std::string initfile = basedir + dirSeperator; + std::string initfile = dir + RsInitConfig::dirSeperator; initfile += configInitFile; // open and read in the lines. @@ -1508,27 +1350,23 @@ void RsInit::load_check_basedir() { for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++) {} path[i] = '\0'; - load_cert = path; - } - if (NULL != fgets(path, 1024, ifd)) - { - for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++) {} - path[i] = '\0'; - load_key = path; + id = path; } fclose(ifd); + return true; } // we have now // 1) checked or created the config dirs. // 2) loaded the config_init file - if possible. - return; + return false; } -int RsInit::create_configinit() + +bool RsInit::create_configinit(std::string dir, std::string id) { // Check for config file. - std::string initfile = basedir + dirSeperator; + std::string initfile = dir + RsInitConfig::dirSeperator; initfile += configInitFile; // open and read in the lines. @@ -1536,61 +1374,18 @@ int RsInit::create_configinit() if (ifd != NULL) { - fprintf(ifd, "%s\n", load_cert.c_str()); - fprintf(ifd, "%s\n", load_key.c_str()); + fprintf(ifd, "%s\n", id.c_str()); fclose(ifd); std::cerr << "Creating Init File: " << initfile << std::endl; - std::cerr << "\tLoad Cert: " << load_cert << std::endl; - std::cerr << "\tLoad Key: " << load_key << std::endl; + std::cerr << "\tId: " << id << std::endl; - return 1; + return true; } std::cerr << "Failed To Create Init File: " << initfile << std::endl; - return -1; + return false; } -#if 0 - -int check_create_directory(std::string dir) -{ - struct stat buf; - int val = stat(dir.c_str(), &buf); - if (val == -1) - { - // directory don't exist. create. -/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ -#ifndef WINDOWS_SYS // UNIX - if (-1 == mkdir(dir.c_str(), 0777)) -#else // WIN - if (-1 == mkdir(dir.c_str())) -#endif -/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ - - { - std::cerr << "check_create_directory() Fatal Error --"; - std::cerr < +//#include + +#include "dbase/cachestrapper.h" +#include "ft/ftserver.h" +#include "ft/ftcontroller.h" + +#include "rsiface/rsiface.h" +#include "rsiface/rsturtle.h" + +/* global variable now points straight to + * ft/ code so variable defined here. + */ + +RsControl *rsicontrol = NULL; +RsFiles *rsFiles = NULL; +RsTurtle *rsTurtle = NULL ; + +#include "pqi/pqipersongrp.h" +#include "pqi/pqisslpersongrp.h" +#include "pqi/pqiloopback.h" +#include "pqi/p3cfgmgr.h" + +#include "util/rsdebug.h" +#include "util/rsdir.h" + +#include "upnp/upnphandler.h" +#include "dht/opendhtmgr.h" + +#include "services/p3disc.h" +#include "services/p3msgservice.h" +#include "services/p3chatservice.h" +#include "services/p3gamelauncher.h" +#include "services/p3ranking.h" +#include "services/p3photoservice.h" +#include "services/p3forums.h" +#include "services/p3channels.h" +#include "services/p3status.h" +#include "services/p3Qblog.h" +#include "turtle/p3turtle.h" + +#include +#include +#include + +// for blocking signals +#include + +/* Implemented Rs Interfaces */ +#include "rsserver/p3face.h" +#include "rsserver/p3peers.h" +#include "rsserver/p3rank.h" +#include "rsserver/p3msgs.h" +#include "rsserver/p3discovery.h" +#include "rsserver/p3photo.h" +#include "rsserver/p3Blog.h" +#include "rsiface/rsgame.h" + +#include "rsserver/p3files.h" + +#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order. + + +/**** +#define RS_RELEASE 1 +****/ + +#define RS_RELEASE 1 + + +RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify) +{ + RsServer *srv = new RsServer(iface, notify); + rsicontrol = srv; + return srv; +} + +/* + * The Real RetroShare Startup Function. + */ + +int RsServer::StartupRetroShare() +{ + /**************************************************************************/ + /* STARTUP procedure */ + /**************************************************************************/ + /**************************************************************************/ + /* (1) Load up own certificate (DONE ALREADY) - just CHECK */ + /**************************************************************************/ + + mAuthMgr = getAuthMgr(); + +/**************** PQI_USE_XPGP ******************/ +#if defined(PQI_USE_XPGP) + if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL)) +#else /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL)) +#endif /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + { + std::cerr << "main() - Fatal Error....." << std::endl; + std::cerr << "Invalid Certificate configuration!" << std::endl; + std::cerr << std::endl; + exit(1); + } + + std::string ownId = mAuthMgr->OwnId(); + + /**************************************************************************/ + /* Any Initial Configuration (Commandline Options) */ + /**************************************************************************/ + + /* set the debugging to crashMode */ + if ((!RsInitConfig::haveLogFile) && (!RsInitConfig::outStderr)) + { + std::string crashfile = RsInitConfig::basedir + RsInitConfig::dirSeperator; + crashfile += configLogFileName; + setDebugCrashMode(crashfile.c_str()); + } + + unsigned long flags = 0; + if (RsInitConfig::udpListenerOnly) + { + flags |= PQIPERSON_NO_LISTENER; + } + + /**************************************************************************/ + + // Load up Certificates, and Old Configuration (if present) + + std::string certConfigFile = RsInitConfig::configDir.c_str(); + std::string certNeighDir = RsInitConfig::configDir.c_str(); + std::string emergencySaveDir = RsInitConfig::configDir.c_str(); + std::string emergencyPartialsDir = RsInitConfig::configDir.c_str(); + if (certConfigFile != "") + { + certConfigFile += "/"; + certNeighDir += "/"; + emergencySaveDir += "/"; + emergencyPartialsDir += "/"; + } + certConfigFile += configConfFile; + certNeighDir += configCertDir; + emergencySaveDir += "Downloads"; + emergencyPartialsDir += "Partials"; + + /* if we've loaded an old format file! */ + bool oldFormat = false; + std::map oldConfigMap; + + mAuthMgr -> setConfigDirectories(certConfigFile, certNeighDir); + + mAuthMgr -> loadCertificates(); + + /**************************************************************************/ + /* setup classes / structures */ + /**************************************************************************/ + + /* Setup Notify Early - So we can use it. */ + rsNotify = new p3Notify(); + + mConnMgr = new p3ConnectMgr(mAuthMgr); + pqiNetAssistFirewall *mUpnpMgr = new upnphandler(); + p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInitConfig::configDir); + + SecurityPolicy *none = secpolicy_create(); + pqih = new pqisslpersongrp(none, flags); + //pqih = new pqipersongrpDummy(none, flags); + + /****** New Ft Server **** !!! */ + ftserver = new ftServer(mAuthMgr, mConnMgr); + ftserver->setP3Interface(pqih); + ftserver->setConfigDirectory(RsInitConfig::configDir); + + ftserver->SetupFtServer(&(getNotify())); + CacheStrapper *mCacheStrapper = ftserver->getCacheStrapper(); + CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer(); + + /* setup any extra bits (Default Paths) */ + ftserver->setPartialsDirectory(emergencyPartialsDir); + ftserver->setDownloadDirectory(emergencySaveDir); + + /* This should be set by config ... there is no default */ + //ftserver->setSharedDirectories(fileList); + rsFiles = ftserver; + + + mConfigMgr = new p3ConfigMgr(mAuthMgr, RsInitConfig::configDir, "rs-v0.4.cfg", "rs-v0.4.sgn"); + mGeneralConfig = new p3GeneralConfig(); + + /* create Services */ + ad = new p3disc(mAuthMgr, mConnMgr); + msgSrv = new p3MsgService(mConnMgr); + chatSrv = new p3ChatService(mConnMgr); + + p3turtle *tr = new p3turtle(mConnMgr,ftserver) ; + rsTurtle = tr ; + pqih -> addService(tr); + ftserver->connectToTurtleRouter(tr) ; + + pqih -> addService(ad); + pqih -> addService(msgSrv); + pqih -> addService(chatSrv); + + /* create Cache Services */ + std::string config_dir = RsInitConfig::configDir; + std::string localcachedir = config_dir + "/cache/local"; + std::string remotecachedir = config_dir + "/cache/remote"; + std::string channelsdir = config_dir + "/channels"; + + + //mRanking = NULL; + mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */ + mCacheStrapper, mCacheTransfer, + localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months + + CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0)); + mCacheStrapper -> addCachePair(cp); /* end of declaration */ + + p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM, + mCacheStrapper, mCacheTransfer, + localcachedir, remotecachedir, mAuthMgr); + + CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0)); + mCacheStrapper -> addCachePair(cp4); + pqih -> addService(mForums); /* This must be also ticked as a service */ + + p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL, + mCacheStrapper, mCacheTransfer, rsFiles, + localcachedir, remotecachedir, channelsdir, mAuthMgr); + + CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0)); + mCacheStrapper -> addCachePair(cp5); + pqih -> addService(mChannels); /* This must be also ticked as a service */ + + +#ifndef RS_RELEASE + + p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr); + pqih -> addService(gameLauncher); + + p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */ + mCacheStrapper, mCacheTransfer, + localcachedir, remotecachedir); + + CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0)); + mCacheStrapper -> addCachePair(cp2); + + mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */ + mCacheStrapper, mCacheTransfer, + localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months + + CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0)); + mCacheStrapper -> addCachePair(cp3); + + +#else + mQblog = NULL; +#endif + + /**************************************************************************/ + + mConnMgr->addNetAssistConnect(1, mDhtMgr); + mConnMgr->addNetAssistFirewall(1, mUpnpMgr); + + /**************************************************************************/ + /* need to Monitor too! */ + + mConnMgr->addMonitor(pqih); + mConnMgr->addMonitor(mCacheStrapper); + mConnMgr->addMonitor(ad); + mConnMgr->addMonitor(msgSrv); + + /* must also add the controller as a Monitor... + * a little hack to get it to work. + */ + mConnMgr->addMonitor(((ftController *) mCacheTransfer)); + + + /**************************************************************************/ + + //mConfigMgr->addConfiguration("ftserver.cfg", ftserver); + // + mConfigMgr->addConfiguration("peers.cfg", mConnMgr); + mConfigMgr->addConfiguration("general.cfg", mGeneralConfig); + mConfigMgr->addConfiguration("msgs.cfg", msgSrv); + mConfigMgr->addConfiguration("chat.cfg", chatSrv); + mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper); + + mConfigMgr->addConfiguration("ranklink.cfg", mRanking); + mConfigMgr->addConfiguration("forums.cfg", mForums); + mConfigMgr->addConfiguration("channels.cfg", mChannels); + mConfigMgr->addConfiguration("turtle.cfg", tr); + +#ifndef RS_RELEASE +#else +#endif + + ftserver->addConfiguration(mConfigMgr); + + + /**************************************************************************/ + + + /**************************************************************************/ + /* (2) Load configuration files */ + /**************************************************************************/ + + mConfigMgr->loadConfiguration(); + + /* NOTE: CacheStrapper's load causes Cache Files to be + * loaded into all the CacheStores/Sources. This happens + * after all the other configurations have happened. + */ + + /**************************************************************************/ + /* Hack Old Configuration into new System (first load only) */ + /**************************************************************************/ + +/**************** PQI_USE_XPGP ******************/ +#if defined(PQI_USE_XPGP) +#else /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ +#endif /* X509 Certificates */ +/**************** PQI_USE_XPGP ******************/ + + /**************************************************************************/ + /* trigger generalConfig loading for classes that require it */ + /**************************************************************************/ + + pqih->setConfig(mGeneralConfig); + + pqih->load_config(); + + /**************************************************************************/ + /* Force Any Configuration before Startup (After Load) */ + /**************************************************************************/ + + if (RsInitConfig::forceLocalAddr) + { + struct sockaddr_in laddr; + + /* clean sockaddr before setting values (MaxOSX) */ + sockaddr_clear(&laddr); + + laddr.sin_family = AF_INET; + laddr.sin_port = htons(RsInitConfig::port); + + // universal + laddr.sin_addr.s_addr = inet_addr(RsInitConfig::inet); + + mConnMgr->setLocalAddress(ownId, laddr); + } + + if (RsInitConfig::forceExtPort) + { + mConnMgr->setOwnNetConfig(RS_NET_MODE_EXT, RS_VIS_STATE_STD); + } + +#if 0 + /* must load the trusted_peer before setting up the pqipersongrp */ + if (firsttime_run) + { + /* at this point we want to load and start the trusted peer -> if selected */ + if (load_trustedpeer) + { + /* sslroot does further checks */ + sslr -> loadInitialTrustedPeer(load_trustedpeer_file); + } + } +#endif + + mConnMgr -> checkNetAddress(); + + /**************************************************************************/ + /* startup (stuff dependent on Ids/peers is after this point) */ + /**************************************************************************/ + + pqih->init_listener(); + + + + + /**************************************************************************/ + /* load caches and secondary data */ + /**************************************************************************/ + + + /**************************************************************************/ + /* Force Any Last Configuration Options */ + /**************************************************************************/ + + /**************************************************************************/ + /* Start up Threads */ + /**************************************************************************/ + + ftserver->StartupThreads(); + ftserver->ResumeTransfers(); + + mDhtMgr->start(); + + // create loopback device, and add to pqisslgrp. + + SearchModule *mod = new SearchModule(); + pqiloopback *ploop = new pqiloopback(ownId); + + mod -> peerid = ownId; + mod -> pqi = ploop; + mod -> sp = secpolicy_create(); + + pqih->AddSearchModule(mod); + + /* Setup GUI Interfaces. */ + + rsPeers = new p3Peers(mConnMgr, mAuthMgr); + rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv); + rsDisc = new p3Discovery(ad); + + rsForums = mForums; + rsChannels = mChannels; + rsRanks = new p3Rank(mRanking); + +#ifndef RS_RELEASE + rsGameLauncher = gameLauncher; + rsPhoto = new p3Photo(photoService); + rsStatus = new p3Status(); + rsQblog = new p3Blog(mQblog); + +#else + rsGameLauncher = NULL; + rsPhoto = NULL; + rsStatus = NULL; + rsQblog = NULL; +#endif + + + /* put a welcome message in! */ + if (RsInitConfig::firsttime_run) + { + msgSrv->loadWelcomeMsg(); + } + + // load up the help page + std::string helppage = RsInitConfig::basedir + RsInitConfig::dirSeperator; + helppage += configHelpName; + + /* Startup this thread! */ + createThread(*this); + + + return 1; +} + + + + diff --git a/libretroshare/src/scripts/config-linux.mk b/libretroshare/src/scripts/config-linux.mk index fd2889979..e82e903c2 100644 --- a/libretroshare/src/scripts/config-linux.mk +++ b/libretroshare/src/scripts/config-linux.mk @@ -9,7 +9,7 @@ endif # flags for components.... #PQI_USE_SSLONLY = 1 -PQI_USE_XPGP = 1 +#PQI_USE_XPGP = 1 #PQI_USE_PROXY = 1 diff --git a/libretroshare/src/tcponudp/Makefile b/libretroshare/src/tcponudp/Makefile index 881ecad03..ce9fea3de 100644 --- a/libretroshare/src/tcponudp/Makefile +++ b/libretroshare/src/tcponudp/Makefile @@ -15,12 +15,12 @@ RSOBJ += tcppacket.o tcpstream.o tou.o $(BIOOBJ) EXECS = librs udpsock_test udpsort_test udp_server #test_tou pair_tou reset_tou internal_tou largefile_tou -#TESTOBJ = udpsock_test.o udpsort_test.o udp_server.o test_tou.o -#TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o +TESTOBJ = udpsock_test.o udpsort_test.o udp_server.o test_tou.o +TESTOBJ += pair_tou.o reset_tou.o largefile_tou.o #internal_tou.o -#TESTS = udpsock_test udpsort_test udp_server test_tou -#TESTS += pair_tou reset_tou largefile_tou +TESTS = udpsock_test udpsort_test udp_server test_tou +TESTS += pair_tou reset_tou largefile_tou #internal_tou all: librs tests