2007-11-14 22:18:48 -05:00
|
|
|
/*
|
2009-07-30 17:27:47 -04:00
|
|
|
* libretroshare/src/reserver rsinit.cc
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* This is an updated startup class. Class variables are hidden from
|
|
|
|
* the GUI / External via a hidden class */
|
2008-11-02 06:38:11 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include <unistd.h>
|
2010-07-01 16:30:36 -04:00
|
|
|
|
|
|
|
// for locking instances
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "util/rsdir.h"
|
2011-02-01 18:27:53 -05:00
|
|
|
#include "util/rsrandom.h"
|
2011-04-03 19:11:38 -04:00
|
|
|
#include "util/folderiterator.h"
|
2011-10-01 09:12:28 -04:00
|
|
|
#include "util/rsstring.h"
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsinit.h"
|
2011-06-16 17:59:26 -04:00
|
|
|
#include "plugins/pluginmanager.h"
|
2011-02-01 18:27:53 -05:00
|
|
|
#include "rsserver/rsloginhandler.h"
|
2009-03-13 17:14:30 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
2012-02-19 15:05:41 -05:00
|
|
|
#if (defined(__unix__) || defined(unix)) && !defined(USG)
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
// for blocking signals
|
|
|
|
#include <signal.h>
|
|
|
|
|
2010-01-13 15:52:31 -05:00
|
|
|
#include "pqi/authssl.h"
|
2010-06-26 08:31:24 -04:00
|
|
|
#include "pqi/sslfns.h"
|
2010-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-06-29 14:02:44 -04:00
|
|
|
#include "tcponudp/udpstunner.h"
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
class accountId
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string pgpId;
|
|
|
|
std::string pgpName;
|
|
|
|
std::string pgpEmail;
|
|
|
|
|
|
|
|
std::string sslId;
|
2010-01-18 17:44:09 -05:00
|
|
|
std::string location;
|
2009-07-30 17:27:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class RsInitConfig
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/* Directories (SetupBaseDir) */
|
|
|
|
static std::string basedir;
|
|
|
|
static std::string homePath;
|
2010-04-30 10:34:48 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
static bool portable;
|
2010-10-07 07:17:42 -04:00
|
|
|
static bool isWindowsXP;
|
2010-04-30 10:34:48 -04:00
|
|
|
#endif
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
static std::list<accountId> accountIds;
|
|
|
|
static std::string preferedId;
|
|
|
|
|
|
|
|
/* for certificate creation */
|
|
|
|
//static std::string gpgPasswd;
|
|
|
|
|
2012-06-14 18:53:02 -04:00
|
|
|
static rs_lock_handle_t lockHandle;
|
2010-07-01 16:30:36 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* These fields are needed for login */
|
|
|
|
static std::string loginId;
|
|
|
|
static std::string configDir;
|
|
|
|
static std::string load_cert;
|
|
|
|
static std::string load_key;
|
2009-08-18 08:43:19 -04:00
|
|
|
|
|
|
|
static std::string passwd;
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
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;
|
2011-03-21 18:16:03 -04:00
|
|
|
static std::string logfname;
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
static bool firsttime_run;
|
|
|
|
static bool load_trustedpeer;
|
|
|
|
static std::string load_trustedpeer_file;
|
|
|
|
|
|
|
|
static bool udpListenerOnly;
|
2011-04-14 17:59:51 -04:00
|
|
|
|
|
|
|
static std::string RetroShareLink;
|
2009-07-30 17:27:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
const int p3facestartupzone = 47238;
|
|
|
|
|
|
|
|
// initial configuration bootstrapping...
|
|
|
|
static const std::string configInitFile = "default_cert.txt";
|
|
|
|
static const std::string configConfFile = "config.rs";
|
|
|
|
static const std::string configCertDir = "friends";
|
|
|
|
static const std::string configKeyDir = "keys";
|
|
|
|
static const std::string configCaFile = "cacerts.pem";
|
|
|
|
static const std::string configLogFileName = "retro.log";
|
|
|
|
static const std::string configHelpName = "retro.htm";
|
2011-01-29 09:27:16 -05:00
|
|
|
static const int SSLPWD_LEN = 64;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::list<accountId> RsInitConfig::accountIds;
|
|
|
|
std::string RsInitConfig::preferedId;
|
|
|
|
|
2012-06-14 18:53:02 -04:00
|
|
|
rs_lock_handle_t RsInitConfig::lockHandle;
|
2010-07-01 16:30:36 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string RsInitConfig::configDir;
|
|
|
|
std::string RsInitConfig::load_cert;
|
|
|
|
std::string RsInitConfig::load_key;
|
2009-08-18 08:43:19 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string RsInitConfig::passwd;
|
|
|
|
//std::string RsInitConfig::gpgPasswd;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInitConfig::autoLogin; /* autoLogin allowed */
|
|
|
|
bool RsInitConfig::startMinimised; /* Icon or Full Window */
|
2011-04-14 17:59:51 -04:00
|
|
|
std::string RsInitConfig::RetroShareLink;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
|
|
|
/* Directories */
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string RsInitConfig::basedir;
|
|
|
|
std::string RsInitConfig::homePath;
|
2010-04-30 10:34:48 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
bool RsInitConfig::portable = false;
|
2010-10-07 07:17:42 -04:00
|
|
|
bool RsInitConfig::isWindowsXP = false;
|
2010-04-30 10:34:48 -04:00
|
|
|
#endif
|
2009-02-08 09:30:28 -05:00
|
|
|
|
|
|
|
/* Listening Port */
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInitConfig::forceExtPort;
|
|
|
|
bool RsInitConfig::forceLocalAddr;
|
|
|
|
unsigned short RsInitConfig::port;
|
|
|
|
char RsInitConfig::inet[256];
|
2009-02-08 09:30:28 -05:00
|
|
|
|
|
|
|
/* Logging */
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInitConfig::haveLogFile;
|
|
|
|
bool RsInitConfig::outStderr;
|
|
|
|
bool RsInitConfig::haveDebugLevel;
|
|
|
|
int RsInitConfig::debugLevel;
|
2011-03-21 18:16:03 -04:00
|
|
|
std::string RsInitConfig::logfname;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInitConfig::firsttime_run;
|
|
|
|
bool RsInitConfig::load_trustedpeer;
|
|
|
|
std::string RsInitConfig::load_trustedpeer_file;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInitConfig::udpListenerOnly;
|
2009-02-08 09:30:28 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Uses private class - so must be hidden */
|
2012-06-09 17:01:22 -04:00
|
|
|
static bool getAvailableAccounts(std::list<accountId> &ids,int& failing_accounts);
|
2009-07-30 17:27:47 -04:00
|
|
|
static bool checkAccount(std::string accountdir, accountId &id);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-27 12:28:44 -04:00
|
|
|
static std::string toUpperCase(const std::string& s)
|
|
|
|
{
|
|
|
|
std::string res(s) ;
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<res.size();++i)
|
|
|
|
if(res[i] > 96 && res[i] < 123)
|
|
|
|
res[i] -= 97-65 ;
|
|
|
|
|
|
|
|
return res ;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string toLowerCase(const std::string& s)
|
|
|
|
{
|
|
|
|
std::string res(s) ;
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<res.size();++i)
|
|
|
|
if(res[i] > 64 && res[i] < 91)
|
|
|
|
res[i] += 97-65 ;
|
|
|
|
|
|
|
|
return res ;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
void RsInit::InitRsConfig()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
#ifndef WINDOWS_SYS
|
2010-07-01 16:30:36 -04:00
|
|
|
RsInitConfig::lockHandle = -1;
|
2007-11-14 22:18:48 -05:00
|
|
|
#else
|
2010-09-29 20:27:23 -04:00
|
|
|
RsInitConfig::lockHandle = NULL;
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::load_trustedpeer = false;
|
|
|
|
RsInitConfig::firsttime_run = false;
|
2011-02-09 15:21:28 -05:00
|
|
|
RsInitConfig::port = 0 ;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::forceLocalAddr = false;
|
|
|
|
RsInitConfig::haveLogFile = false;
|
|
|
|
RsInitConfig::outStderr = false;
|
|
|
|
RsInitConfig::forceExtPort = false;
|
|
|
|
|
|
|
|
strcpy(RsInitConfig::inet, "127.0.0.1");
|
|
|
|
|
2010-04-08 08:02:46 -04:00
|
|
|
RsInitConfig::autoLogin = false; // .
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::startMinimised = false;
|
|
|
|
RsInitConfig::passwd = "";
|
|
|
|
RsInitConfig::haveDebugLevel = false;
|
|
|
|
RsInitConfig::debugLevel = PQL_WARNING;
|
|
|
|
RsInitConfig::udpListenerOnly = false;
|
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
/* setup the homePath (default save location) */
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::homePath = getHomePath();
|
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
// test for portable version
|
2012-06-09 20:29:46 -04:00
|
|
|
if (GetFileAttributes(L"portable") != (DWORD) -1) {
|
2010-04-30 10:34:48 -04:00
|
|
|
// use portable version
|
|
|
|
RsInitConfig::portable = true;
|
|
|
|
}
|
2010-10-07 07:17:42 -04:00
|
|
|
|
|
|
|
// test for Windows XP
|
|
|
|
OSVERSIONINFOEX osvi;
|
|
|
|
memset(&osvi, 0, sizeof(osvi));
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
|
|
|
|
if (GetVersionEx((OSVERSIONINFO*) &osvi)) {
|
|
|
|
if (osvi.dwMajorVersion == 5) {
|
|
|
|
if (osvi.dwMinorVersion == 1) {
|
|
|
|
/* Windows XP */
|
|
|
|
RsInitConfig::isWindowsXP = true;
|
|
|
|
} else if (osvi.dwMinorVersion == 2) {
|
|
|
|
SYSTEM_INFO si;
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
GetSystemInfo(&si);
|
|
|
|
if (osvi.wProductType == VER_NT_WORKSTATION && si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64) {
|
|
|
|
/* Windows XP Professional x64 Edition */
|
|
|
|
RsInitConfig::isWindowsXP = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RsInitConfig::isWindowsXP) {
|
|
|
|
std::cerr << "Running Windows XP" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cerr << "Not running Windows XP" << std::endl;
|
|
|
|
}
|
2010-04-30 10:34:48 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Setup the Debugging */
|
|
|
|
// setup debugging for desired zones.
|
|
|
|
setOutputLevel(PQL_WARNING); // default to Warnings.
|
|
|
|
|
|
|
|
// For Testing purposes.
|
|
|
|
// We can adjust everything under Linux.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 38422); // pqipacket.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 96184); // pqinetwork;
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 82371); // pqiperson.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 60478); // pqitunnel.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 34283); // pqihandler.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 44863); // discItems.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 2482); // p3disc
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 1728); // pqi/p3proxy
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 1211); // sslroot.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 37714); // pqissl.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 8221); // pqistreamer.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 9326); // pqiarchive
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 3334); // p3channel.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 354); // pqipersongrp.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 6846); // pqiudpproxy
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 3144); // pqissludp;
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 86539); // pqifiler.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 91393); // Funky_Browser.
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 25915); // fltkserver
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 47659); // fldxsrvr
|
|
|
|
//setZoneLevel(PQL_DEBUG_BASIC, 49787); // pqissllistener
|
|
|
|
}
|
|
|
|
|
2012-01-07 06:28:00 -05:00
|
|
|
/********
|
|
|
|
* LOCALNET_TESTING - allows port restrictions
|
2012-01-11 05:24:37 -05:00
|
|
|
*
|
|
|
|
* #define LOCALNET_TESTING 1
|
|
|
|
*
|
2012-01-07 06:28:00 -05:00
|
|
|
********/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
|
|
|
|
std::string portRestrictions;
|
|
|
|
bool doPortRestrictions = false;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-06-14 09:22:39 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
2010-05-08 17:44:08 -04:00
|
|
|
int RsInit::InitRetroShare(int argc, char **argv, bool strictCheck)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* for static PThreads under windows... we need to init the library...
|
|
|
|
*/
|
|
|
|
#ifdef PTW32_STATIC_LIB
|
|
|
|
#include <pthread.h>
|
2008-09-21 16:30:34 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-05-08 17:44:08 -04:00
|
|
|
int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
/* THIS IS A HACK TO ALLOW WINDOWS TO ACCEPT COMMANDLINE ARGUMENTS */
|
|
|
|
|
2010-09-01 17:08:08 -04:00
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
int argc;
|
2010-09-01 17:08:08 -04:00
|
|
|
int i;
|
|
|
|
#ifdef USE_CMD_ARGS
|
|
|
|
char** argv = argvIgnored;
|
|
|
|
argc = argcIgnored;
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
const int MAX_ARGS = 32;
|
|
|
|
int j;
|
2007-11-14 22:18:48 -05:00
|
|
|
char *argv[MAX_ARGS];
|
2009-02-08 09:30:28 -05:00
|
|
|
char *wholeline = (char*)GetCommandLine();
|
2007-11-14 22:18:48 -05:00
|
|
|
int cmdlen = strlen(wholeline);
|
|
|
|
// duplicate line, so we can put in spaces..
|
|
|
|
char dupline[cmdlen+1];
|
|
|
|
strcpy(dupline, wholeline);
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
/* break wholeline down ....
|
|
|
|
* NB. This is very simplistic, and will not
|
2007-11-14 22:18:48 -05:00
|
|
|
* handle multiple spaces, or quotations etc, only for debugging purposes
|
|
|
|
*/
|
|
|
|
argv[0] = dupline;
|
|
|
|
for(i = 1, j = 0; (j + 1 < cmdlen) && (i < MAX_ARGS);)
|
|
|
|
{
|
2010-09-01 17:08:08 -04:00
|
|
|
/* find next space. */
|
|
|
|
for(;(j + 1 < cmdlen) && (dupline[j] != ' ');j++);
|
|
|
|
if (j + 1 < cmdlen)
|
|
|
|
{
|
|
|
|
dupline[j] = '\0';
|
|
|
|
argv[i++] = &(dupline[j+1]);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
argc = i;
|
2010-09-01 17:08:08 -04:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
for( i=0; i<argc; i++)
|
|
|
|
{
|
|
|
|
printf("%d: %s\n", i, argv[i]);
|
|
|
|
}
|
|
|
|
|
2010-09-01 17:08:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* for static PThreads under windows... we need to init the library...
|
|
|
|
*/
|
|
|
|
#ifdef PTW32_STATIC_LIB
|
|
|
|
pthread_win32_process_attach_np();
|
2008-09-21 16:30:34 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
2010-04-10 18:06:11 -04:00
|
|
|
int c;
|
2010-06-27 12:28:44 -04:00
|
|
|
std::string prefUserString = "";
|
2010-04-10 18:06:11 -04:00
|
|
|
/* getopt info: every availiable option is listed here. if it is followed by a ':' it
|
|
|
|
needs an argument. If it is followed by a '::' the argument is optional.
|
|
|
|
*/
|
2012-01-07 06:28:00 -05:00
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:R:")) != -1)
|
|
|
|
#else
|
2011-04-14 17:59:51 -04:00
|
|
|
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:")) != -1)
|
2012-01-07 06:28:00 -05:00
|
|
|
#endif
|
2010-04-10 18:06:11 -04:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'a':
|
|
|
|
RsInitConfig::autoLogin = true;
|
|
|
|
RsInitConfig::startMinimised = true;
|
|
|
|
std::cerr << "AutoLogin Allowed / Start Minimised On";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
RsInitConfig::startMinimised = true;
|
|
|
|
std::cerr << "Start Minimised On";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2011-03-21 18:16:03 -04:00
|
|
|
RsInitConfig::logfname = optarg;
|
2010-04-10 18:06:11 -04:00
|
|
|
std::cerr << "LogFile (" << RsInitConfig::logfname;
|
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
RsInitConfig::haveLogFile = true;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
RsInitConfig::passwd = optarg;
|
2011-01-29 09:27:16 -05:00
|
|
|
std::cerr << "Password Specified(********" ; //<< RsInitConfig::passwd;
|
2010-04-10 18:06:11 -04:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
strncpy(RsInitConfig::inet, optarg, 256);
|
|
|
|
std::cerr << "New Inet Addr(" << RsInitConfig::inet;
|
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
RsInitConfig::forceLocalAddr = true;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
RsInitConfig::port = atoi(optarg);
|
|
|
|
std::cerr << "New Listening Port(" << RsInitConfig::port;
|
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
RsInitConfig::basedir = optarg;
|
|
|
|
std::cerr << "New Base Config Dir(";
|
|
|
|
std::cerr << RsInitConfig::basedir;
|
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
RsInitConfig::outStderr = true;
|
|
|
|
RsInitConfig::haveLogFile = false;
|
|
|
|
std::cerr << "Output to Stderr";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
RsInitConfig::haveDebugLevel = true;
|
|
|
|
RsInitConfig::debugLevel = atoi(optarg);
|
|
|
|
std::cerr << "Opt for new Debug Level";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
RsInitConfig::udpListenerOnly = true;
|
|
|
|
std::cerr << "Opt for only udpListener";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'e':
|
|
|
|
RsInitConfig::forceExtPort = true;
|
|
|
|
std::cerr << "Opt for External Port Mode";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'U':
|
2010-06-27 12:28:44 -04:00
|
|
|
prefUserString = optarg;
|
2010-04-10 18:06:11 -04:00
|
|
|
std::cerr << "Opt for User Id ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2011-04-14 17:59:51 -04:00
|
|
|
case 'r':
|
|
|
|
RsInitConfig::RetroShareLink = optarg;
|
|
|
|
std::cerr << "Opt for RetroShare link";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2012-01-07 06:28:00 -05:00
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
case 'R':
|
|
|
|
portRestrictions = optarg;
|
|
|
|
doPortRestrictions = true;
|
|
|
|
std::cerr << "Opt for Port Restrictions";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
#endif
|
2010-04-10 18:06:11 -04:00
|
|
|
case 'h':
|
|
|
|
std::cerr << "Help: " << std::endl;
|
|
|
|
std::cerr << "The commandline options are for retroshare-nogui, a headless server in a shell, or systems without QT." << std::endl << std::endl;
|
|
|
|
std::cerr << "-l [logfile] Set the logfilename" << std::endl;
|
|
|
|
std::cerr << "-w [password] Set the password" << std::endl;
|
|
|
|
std::cerr << "-i [ip_adress] Set IP Adress to use" << std::endl;
|
|
|
|
std::cerr << "-p [port] Set the Port to listen on" << std::endl;
|
|
|
|
std::cerr << "-c [basedir] Set the config basdir" << std::endl;
|
|
|
|
std::cerr << "-s Output to Stderr" << std::endl;
|
|
|
|
std::cerr << "-d [debuglevel] Set the debuglevel" << std::endl;
|
|
|
|
std::cerr << "-a AutoLogin (Windows Only) + StartMinimised" << std::endl;
|
|
|
|
std::cerr << "-m StartMinimised" << std::endl;
|
|
|
|
std::cerr << "-u Only listen to UDP" << std::endl;
|
2010-06-27 12:28:44 -04:00
|
|
|
std::cerr << "-e Use a forwarded external Port" << std::endl ;
|
|
|
|
std::cerr << "-U [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled." << std::endl;
|
2011-04-14 17:59:51 -04:00
|
|
|
std::cerr << "-r link Use RetroShare link." << std::endl;
|
2012-01-07 06:28:00 -05:00
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
std::cerr << "-R <lport-uport> Port Restrictions." << std::endl;
|
|
|
|
#endif
|
2010-04-10 18:06:11 -04:00
|
|
|
exit(1);
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-14 17:59:51 -04:00
|
|
|
if (strictCheck) {
|
2010-05-08 17:44:08 -04:00
|
|
|
std::cerr << "Unknown Option!" << std::endl;
|
|
|
|
std::cerr << "Use '-h' for help." << std::endl;
|
|
|
|
exit(1);
|
2011-04-14 17:59:51 -04:00
|
|
|
}
|
2010-04-10 18:06:11 -04:00
|
|
|
}
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
// set the default Debug Level...
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::haveDebugLevel)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
if ((RsInitConfig::debugLevel > 0) &&
|
|
|
|
(RsInitConfig::debugLevel <= PQL_DEBUG_ALL))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "Setting Debug Level to: ";
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << RsInitConfig::debugLevel;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
setOutputLevel(RsInitConfig::debugLevel);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Ignoring Invalid Debug Level: ";
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << RsInitConfig::debugLevel;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the debug file.
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::haveLogFile)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2011-03-21 18:16:03 -04:00
|
|
|
setDebugFile(RsInitConfig::logfname.c_str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#else
|
|
|
|
// Windows Networking Init.
|
|
|
|
WORD wVerReq = MAKEWORD(2,2);
|
|
|
|
WSADATA wsaData;
|
|
|
|
|
|
|
|
if (0 != WSAStartup(wVerReq, &wsaData))
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to Startup Windows Networking";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Started Windows Networking";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
// SWITCH off the SIGPIPE - kills process on Linux.
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
struct sigaction sigact;
|
|
|
|
sigact.sa_handler = SIG_IGN;
|
|
|
|
sigact.sa_flags = 0;
|
|
|
|
|
2009-10-29 20:45:40 -04:00
|
|
|
sigset_t set;
|
|
|
|
sigemptyset(&set);
|
|
|
|
//sigaddset(&set, SIGINT); // or whatever other signal
|
|
|
|
sigact.sa_mask = set;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
if (0 == sigaction(SIGPIPE, &sigact, NULL))
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare:: Successfully Installed";
|
|
|
|
std::cerr << "the SIGPIPE Block" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare:: Failed to Install";
|
|
|
|
std::cerr << "the SIGPIPE Block" << std::endl;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
2008-11-09 11:52:14 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* 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.
|
2008-11-09 11:52:14 -05:00
|
|
|
*/
|
2010-07-04 06:42:17 -04:00
|
|
|
/* create singletons */
|
|
|
|
AuthSSLInit();
|
2012-04-09 13:03:47 -04:00
|
|
|
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL);
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
// first check config directories, and set bootstrap values.
|
2011-12-06 18:00:42 -05:00
|
|
|
if(!setupBaseDir())
|
|
|
|
return RS_INIT_BASE_DIR_ERROR ;
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId);
|
2010-04-30 10:34:48 -04:00
|
|
|
|
2012-06-09 17:01:22 -04:00
|
|
|
std::string pgp_dir = RsInitConfig::basedir + "/pgp" ;
|
|
|
|
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
|
|
|
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
|
|
|
|
2012-06-20 17:59:04 -04:00
|
|
|
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
|
|
|
|
pgp_dir + "/retroshare_secret_keyring.gpg",
|
|
|
|
pgp_dir + "/retroshare_trustdb.gpg",
|
|
|
|
pgp_dir + "/lock");
|
2012-04-09 13:03:47 -04:00
|
|
|
|
2010-11-03 18:54:34 -04:00
|
|
|
/* Initialize AuthGPG */
|
2012-04-08 10:52:01 -04:00
|
|
|
// if (AuthGPG::getAuthGPG()->InitAuth() == false) {
|
|
|
|
// std::cerr << "AuthGPG::InitAuth failed" << std::endl;
|
|
|
|
// return RS_INIT_AUTH_FAILED;
|
|
|
|
// }
|
2010-04-30 10:34:48 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
//std::list<accountId> ids;
|
|
|
|
std::list<accountId>::iterator it;
|
2012-06-09 17:01:22 -04:00
|
|
|
int failing_accounts ;
|
|
|
|
|
|
|
|
getAvailableAccounts(RsInitConfig::accountIds,failing_accounts);
|
2009-07-30 17:27:47 -04:00
|
|
|
|
2012-06-09 17:01:22 -04:00
|
|
|
if(failing_accounts > 0 && RsInitConfig::accountIds.empty())
|
|
|
|
return RS_INIT_NO_KEYRING ;
|
|
|
|
|
|
|
|
// if a different user id has been passed to cmd line check for that instead
|
2010-04-10 18:06:11 -04:00
|
|
|
|
2010-06-27 12:28:44 -04:00
|
|
|
std::string lower_case_user_string = toLowerCase(prefUserString) ;
|
|
|
|
std::string upper_case_user_string = toUpperCase(prefUserString) ;
|
2010-04-10 18:06:11 -04:00
|
|
|
|
2010-06-27 12:28:44 -04:00
|
|
|
bool pgpNameFound = false;
|
|
|
|
if(prefUserString != "")
|
|
|
|
{
|
2010-04-10 18:06:11 -04:00
|
|
|
|
2010-06-27 12:28:44 -04:00
|
|
|
for(it = RsInitConfig::accountIds.begin() ; it!= RsInitConfig::accountIds.end() ; it++)
|
|
|
|
{
|
|
|
|
std::cerr << "Checking account (gpgid = " << it->pgpId << ", name=" << it->pgpName << ", sslId=" << it->sslId << ")" << std::endl ;
|
2010-04-10 18:06:11 -04:00
|
|
|
|
2010-06-27 12:28:44 -04:00
|
|
|
if(prefUserString == it->pgpName || upper_case_user_string == it->pgpId || lower_case_user_string == it->sslId)
|
|
|
|
{
|
|
|
|
RsInitConfig::preferedId = it->sslId;
|
|
|
|
pgpNameFound = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!pgpNameFound){
|
|
|
|
std::cerr << "Invalid User name/GPG id/SSL id: not found in list" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return RS_INIT_AUTH_FAILED ;
|
2010-06-27 12:28:44 -04:00
|
|
|
}
|
|
|
|
}
|
2010-04-10 18:06:11 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* check that preferedId */
|
|
|
|
std::string userName;
|
|
|
|
std::string userId;
|
|
|
|
bool existingUser = false;
|
|
|
|
for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "Checking Account Id: " << it->sslId << std::endl;
|
|
|
|
if (RsInitConfig::preferedId == it->sslId)
|
|
|
|
{
|
|
|
|
std::cerr << " * Preferred * " << std::endl;
|
|
|
|
userId = it->sslId;
|
2012-06-16 05:40:59 -04:00
|
|
|
userName = it->pgpName;
|
2009-07-30 17:27:47 -04:00
|
|
|
existingUser = true;
|
2012-06-16 05:40:59 -04:00
|
|
|
break;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
if (!existingUser)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
std::cerr << "No Existing User" << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::preferedId == "";
|
2010-04-10 18:06:11 -04:00
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* if existing user, and havePasswd .... we can skip the login prompt */
|
|
|
|
if (existingUser)
|
|
|
|
{
|
2011-02-01 18:27:53 -05:00
|
|
|
if (RsInitConfig::passwd != "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-11-03 18:54:34 -04:00
|
|
|
return RS_INIT_HAVE_ACCOUNT;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2010-04-08 08:02:46 -04:00
|
|
|
|
|
|
|
RsInit::LoadPassword(RsInitConfig::preferedId, "");
|
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
if(RsLoginHandler::getSSLPassword(RsInitConfig::preferedId,false,RsInitConfig::passwd))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2010-04-08 08:02:46 -04:00
|
|
|
RsInit::setAutoLogin(true);
|
2011-01-29 09:27:16 -05:00
|
|
|
std::cerr << "Autologin has succeeded" << std::endl;
|
2010-11-03 18:54:34 -04:00
|
|
|
return RS_INIT_HAVE_ACCOUNT;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
2010-11-03 18:54:34 -04:00
|
|
|
return RS_INIT_OK;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************** Access Functions for Init Data **************************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2012-06-09 17:01:22 -04:00
|
|
|
bool RsInit::copyGnuPGKeyrings()
|
|
|
|
{
|
|
|
|
std::string pgp_dir = RsInitConfig::basedir + "/pgp" ;
|
|
|
|
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
|
|
|
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
|
|
|
|
2012-06-09 20:29:46 -04:00
|
|
|
std::string source_public_keyring;
|
|
|
|
std::string source_secret_keyring;
|
|
|
|
|
2012-06-09 17:01:22 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
2012-06-09 20:29:46 -04:00
|
|
|
if (RsInit::isPortable())
|
|
|
|
{
|
|
|
|
source_public_keyring = RsInit::RsConfigDirectory() + "/gnupg/pubring.gpg";
|
|
|
|
source_secret_keyring = RsInit::RsConfigDirectory() + "/gnupg/secring.gpg" ;
|
|
|
|
} else {
|
|
|
|
source_public_keyring = RsInitConfig::basedir + "/../gnupg/pubring.gpg" ;
|
|
|
|
source_secret_keyring = RsInitConfig::basedir + "/../gnupg/secring.gpg" ;
|
|
|
|
}
|
2012-06-09 17:01:22 -04:00
|
|
|
#else
|
|
|
|
// We need a specific part for MacOS and Linux as well
|
2012-06-09 20:29:46 -04:00
|
|
|
source_public_keyring = RsInitConfig::basedir + "/../.gnupg/pubring.gpg" ;
|
|
|
|
source_secret_keyring = RsInitConfig::basedir + "/../.gnupg/secring.gpg" ;
|
2012-06-09 17:01:22 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!RsDirUtil::copyFile(source_public_keyring,pgp_dir + "/retroshare_public_keyring.gpg"))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot copy pub keyring " << source_public_keyring << " to destination file " << pgp_dir + "/retroshare_public_keyring.pgp" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
if(!RsDirUtil::copyFile(source_secret_keyring,pgp_dir + "/retroshare_secret_keyring.gpg"))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot copy sec keyring " << source_secret_keyring << " to destination file " << pgp_dir + "/retroshare_secret_keyring.pgp" << std::endl;
|
|
|
|
return false ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true ;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::getPreferedAccountId(std::string &id)
|
|
|
|
{
|
|
|
|
id = RsInitConfig::preferedId;
|
|
|
|
return (RsInitConfig::preferedId != "");
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::getAccountIds(std::list<std::string> &ids)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::list<accountId>::iterator it;
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef AUTHSSL_DEBUG
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "getAccountIds:" << std::endl;
|
2010-02-07 16:28:40 -05:00
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++)
|
2009-05-24 06:33:08 -04:00
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef AUTHSSL_DEBUG
|
|
|
|
std::cerr << "SSL Id: " << it->sslId << " PGP Id " << it->pgpId;
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << " PGP Name: " << it->pgpName;
|
|
|
|
std::cerr << " PGP Email: " << it->pgpEmail;
|
2010-01-18 17:44:09 -05:00
|
|
|
std::cerr << " Location: " << it->location;
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << std::endl;
|
2010-02-07 16:28:40 -05:00
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
ids.push_back(it->sslId);
|
|
|
|
}
|
|
|
|
return true;
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::getAccountDetails(std::string id,
|
|
|
|
std::string &gpgId, std::string &gpgName,
|
2010-01-18 17:44:09 -05:00
|
|
|
std::string &gpgEmail, std::string &location)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::list<accountId>::iterator it;
|
|
|
|
for(it = RsInitConfig::accountIds.begin(); it != RsInitConfig::accountIds.end(); it++)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
if (id == it->sslId)
|
|
|
|
{
|
|
|
|
gpgId = it->pgpId;
|
|
|
|
gpgName = it->pgpName;
|
|
|
|
gpgEmail = it->pgpEmail;
|
2010-01-18 17:44:09 -05:00
|
|
|
location = it->location;
|
2009-07-30 17:27:47 -04:00
|
|
|
return true;
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
return false;
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************** Access Functions for Init Data **************************/
|
|
|
|
/**************************** Private Functions for InitRetroshare ********************/
|
|
|
|
/**************************** Private Functions for InitRetroshare ********************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
|
2011-12-06 18:00:42 -05:00
|
|
|
bool RsInit::setupBaseDir()
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
// get the default configuration location.
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::basedir == "")
|
|
|
|
{
|
|
|
|
// v0.4.x if unix. homedir + /.pqiPGPrc
|
|
|
|
// v0.5.x if unix. homedir + /.retroshare
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/******************************** 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" <<std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
RsInitConfig::basedir = h;
|
|
|
|
RsInitConfig::basedir += "/.retroshare";
|
|
|
|
#else
|
2010-04-30 10:34:48 -04:00
|
|
|
if (RsInitConfig::portable) {
|
|
|
|
// use directory "Data" in portable version
|
|
|
|
RsInitConfig::basedir = "Data";
|
|
|
|
} else {
|
2011-04-03 19:11:38 -04:00
|
|
|
wchar_t *wh = _wgetenv(L"APPDATA");
|
|
|
|
std::string h;
|
|
|
|
librs::util::ConvertUtf16ToUtf8(std::wstring(wh), h);
|
2010-04-30 10:34:48 -04:00
|
|
|
std::cerr << "retroShare::basedir() -> $APPDATA = ";
|
|
|
|
std::cerr << h << std::endl;
|
|
|
|
char *h2 = getenv("HOMEDRIVE");
|
|
|
|
std::cerr << "retroShare::basedir() -> $HOMEDRIVE = ";
|
|
|
|
std::cerr << h2 << std::endl;
|
2011-04-03 19:11:38 -04:00
|
|
|
wchar_t *wh3 = _wgetenv(L"HOMEPATH");
|
|
|
|
std::string h3;
|
|
|
|
librs::util::ConvertUtf16ToUtf8(std::wstring(wh3), h3);
|
2010-04-30 10:34:48 -04:00
|
|
|
std::cerr << "retroShare::basedir() -> $HOMEPATH = ";
|
|
|
|
std::cerr << h3 << std::endl;
|
2011-04-03 19:11:38 -04:00
|
|
|
if (h.empty())
|
2010-04-30 10:34:48 -04:00
|
|
|
{
|
|
|
|
// generating default
|
|
|
|
std::cerr << "load_check_basedir() getEnv Error --Win95/98?";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
RsInitConfig::basedir="C:\\Retro";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RsInitConfig::basedir = h;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
if (!RsDirUtil::checkCreateDirectory(RsInitConfig::basedir))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create BaseConfig Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2010-04-30 10:34:48 -04:00
|
|
|
}
|
|
|
|
RsInitConfig::basedir += "\\RetroShare";
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// fatal if cannot find/create.
|
|
|
|
std::cerr << "Creating Root Retroshare Config Directories" << std::endl;
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(RsInitConfig::basedir))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "Cannot Create BaseConfig Dir:" << RsInitConfig::basedir << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2011-12-06 18:00:42 -05:00
|
|
|
return true ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-10-28 18:59:46 -04:00
|
|
|
/***********************************************************
|
|
|
|
* This Directory is used to store data and "template" file that Retroshare requires.
|
|
|
|
* These files will either be copied into Retroshare's configuration directory,
|
|
|
|
* if they are to be modified. Or used directly, if read-only.
|
|
|
|
*
|
|
|
|
* This will initially be used for the DHT bootstrap file.
|
|
|
|
*
|
|
|
|
* Please modify the code below to suit your platform!
|
|
|
|
*
|
|
|
|
* WINDOWS:
|
|
|
|
* WINDOWS PORTABLE:
|
|
|
|
* Linux:
|
|
|
|
* OSX:
|
|
|
|
|
|
|
|
***********/
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
/* needs CoreFoundation Framework */
|
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
//#include <CFURL.h>
|
|
|
|
//#include <CFBundle.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::string RsInit::getRetroshareDataDirectory()
|
|
|
|
{
|
|
|
|
std::string dataDirectory;
|
|
|
|
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2012-02-19 15:05:41 -05:00
|
|
|
/* NOTE: OSX also qualifies as BSD... so this #ifdef must be before the BSD check. */
|
|
|
|
|
2010-10-28 18:59:46 -04:00
|
|
|
/* For OSX, applications are Bundled in a directory...
|
|
|
|
* need to get the path to the executable Bundle.
|
|
|
|
*
|
|
|
|
* Code nicely supplied by Qt!
|
|
|
|
*/
|
|
|
|
|
|
|
|
CFURLRef pluginRef = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
|
|
|
CFStringRef macPath = CFURLCopyFileSystemPath(pluginRef,
|
|
|
|
kCFURLPOSIXPathStyle);
|
|
|
|
const char *pathPtr = CFStringGetCStringPtr(macPath,
|
|
|
|
CFStringGetSystemEncoding());
|
|
|
|
dataDirectory = pathPtr;
|
|
|
|
CFRelease(pluginRef);
|
|
|
|
CFRelease(macPath);
|
|
|
|
|
|
|
|
dataDirectory += "/Contents/Resources";
|
|
|
|
std::cerr << "getRetroshareDataDirectory() OSX: " << dataDirectory;
|
|
|
|
|
2012-02-19 15:05:41 -05:00
|
|
|
#elif (defined(BSD) && (BSD >= 199103))
|
|
|
|
/* For BSD, the default is LOCALBASE which will be set
|
|
|
|
* before compilation via the ports/pkg-src mechanisms.
|
|
|
|
* For compilation without ports/pkg-src it is set to
|
|
|
|
* /usr/local (default on Open and Free; Net has /usr/pkg)
|
|
|
|
*/
|
|
|
|
dataDirectory = "/usr/local/share/retroshare";
|
|
|
|
std::cerr << "getRetroshareDataDirectory() BSD: " << dataDirectory;
|
|
|
|
|
2010-10-28 18:59:46 -04:00
|
|
|
#else
|
|
|
|
/* For Linux, we have a fixed standard data directory */
|
2010-11-19 17:40:08 -05:00
|
|
|
dataDirectory = "/usr/share/RetroShare";
|
2010-10-28 18:59:46 -04:00
|
|
|
std::cerr << "getRetroshareDataDirectory() Linux: " << dataDirectory;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#else
|
2010-11-02 21:33:49 -04:00
|
|
|
// if (RsInitConfig::portable)
|
|
|
|
// {
|
|
|
|
// /* For Windows Portable, files must be in the data directory */
|
|
|
|
// dataDirectory = "Data";
|
|
|
|
// std::cerr << "getRetroshareDataDirectory() WINDOWS PORTABLE: " << dataDirectory;
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// /* For Windows: environment variable APPDATA should be suitable */
|
|
|
|
// dataDirectory = getenv("APPDATA");
|
|
|
|
// dataDirectory += "\\RetroShare";
|
|
|
|
//
|
|
|
|
// std::cerr << "getRetroshareDataDirectory() WINDOWS: " << dataDirectory;
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
// }
|
|
|
|
|
|
|
|
/* Use RetroShare's exe dir */
|
|
|
|
dataDirectory = ".";
|
2010-10-28 18:59:46 -04:00
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
/* Make sure the directory exists, else return emptyString */
|
|
|
|
if (!RsDirUtil::checkDirectory(dataDirectory))
|
|
|
|
{
|
|
|
|
std::cerr << "Data Directory not Found: " << dataDirectory << std::endl;
|
|
|
|
dataDirectory = "";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Data Directory Found: " << dataDirectory << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return dataDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* directories with valid certificates in the expected location */
|
2012-06-09 17:01:22 -04:00
|
|
|
bool getAvailableAccounts(std::list<accountId> &ids,int& failing_accounts)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
2012-06-09 17:01:22 -04:00
|
|
|
failing_accounts = 0 ;
|
2009-07-30 17:27:47 -04:00
|
|
|
/* get the directories */
|
|
|
|
std::list<std::string> directories;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
std::cerr << "getAvailableAccounts()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2011-01-01 15:37:10 -05:00
|
|
|
/* now iterate through the directory...
|
|
|
|
* directories - flags as old,
|
|
|
|
* files checked to see if they have changed. (rehashed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* check for the dir existance */
|
2011-04-03 19:11:38 -04:00
|
|
|
librs::util::FolderIterator dirIt(RsInitConfig::basedir);
|
|
|
|
if (!dirIt.isValid())
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2011-04-03 19:11:38 -04:00
|
|
|
struct stat64 buf;
|
|
|
|
|
|
|
|
while (dirIt.readdir())
|
2011-01-01 15:37:10 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
/* check entry type */
|
2011-04-03 19:11:38 -04:00
|
|
|
std::string fname;
|
|
|
|
dirIt.d_name(fname);
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string fullname = RsInitConfig::basedir + "/" + fname;
|
2011-04-03 19:11:38 -04:00
|
|
|
#ifdef FIM_DEBUG
|
|
|
|
std::cerr << "calling stats on " << fullname <<std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
std::wstring wfullname;
|
|
|
|
librs::util::ConvertUtf8ToUtf16(fullname, wfullname);
|
|
|
|
if (-1 != _wstati64(wfullname.c_str(), &buf))
|
|
|
|
#else
|
|
|
|
if (-1 != stat64(fullname.c_str(), &buf))
|
|
|
|
#endif
|
2011-01-01 15:37:10 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
2011-01-01 15:37:10 -05:00
|
|
|
#ifdef FIM_DEBUG
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "buf.st_mode: " << buf.st_mode <<std::endl;
|
2011-01-01 15:37:10 -05:00
|
|
|
#endif
|
2009-07-30 17:27:47 -04:00
|
|
|
if (S_ISDIR(buf.st_mode))
|
|
|
|
{
|
|
|
|
if ((fname == ".") || (fname == ".."))
|
|
|
|
{
|
|
|
|
#ifdef FIM_DEBUG
|
|
|
|
std::cerr << "Skipping:" << fname << std::endl;
|
|
|
|
#endif
|
|
|
|
continue; /* skipping links */
|
|
|
|
}
|
2011-01-01 15:37:10 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#ifdef FIM_DEBUG
|
2011-01-01 15:37:10 -05:00
|
|
|
std::cerr << "Is Directory: " << fullname << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
#endif
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-01-01 15:37:10 -05:00
|
|
|
/* */
|
|
|
|
directories.push_back(fname);
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
}
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
2011-04-03 19:11:38 -04:00
|
|
|
/* close directory */
|
|
|
|
dirIt.closedir();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
for(it = directories.begin(); it != directories.end(); it++)
|
|
|
|
{
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string accountdir = RsInitConfig::basedir + "/" + *it;
|
2011-01-01 15:37:10 -05:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "getAvailableAccounts() Checking: " << *it << std::endl;
|
|
|
|
#endif
|
2008-02-05 08:45:04 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
accountId tmpId;
|
|
|
|
if (checkAccount(accountdir, tmpId))
|
|
|
|
{
|
2011-01-01 15:37:10 -05:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "getAvailableAccounts() Accepted: " << *it << std::endl;
|
|
|
|
#endif
|
2009-07-30 17:27:47 -04:00
|
|
|
ids.push_back(tmpId);
|
|
|
|
}
|
2012-06-09 17:01:22 -04:00
|
|
|
else
|
|
|
|
++failing_accounts ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
static bool checkAccount(std::string accountdir, accountId &id)
|
|
|
|
{
|
|
|
|
/* check if the cert/key file exists */
|
2008-11-02 06:38:11 -05:00
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string subdir1 = accountdir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string subdir2 = subdir1;
|
|
|
|
subdir1 += configKeyDir;
|
|
|
|
subdir2 += configCertDir;
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// Create the filename.
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string basename = accountdir + "/";
|
|
|
|
basename += configKeyDir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
basename += "user";
|
2008-07-02 12:58:13 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string cert_name = basename + "_cert.pem";
|
|
|
|
std::string userName, userId;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2012-06-14 16:13:31 -04:00
|
|
|
#ifdef AUTHSSL_DEBUG
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "checkAccount() dir: " << accountdir << std::endl;
|
2012-06-14 16:13:31 -04:00
|
|
|
#endif
|
2009-10-27 16:46:17 -04:00
|
|
|
bool ret = false;
|
2009-03-22 10:08:02 -04:00
|
|
|
|
2009-10-27 16:46:17 -04:00
|
|
|
/* check against authmanagers private keys */
|
2012-06-14 16:13:31 -04:00
|
|
|
if (LoadCheckX509(cert_name.c_str(), id.pgpId, id.location, id.sslId))
|
|
|
|
{
|
|
|
|
#ifdef AUTHSSL_DEBUG
|
|
|
|
std::cerr << "location: " << id.location << " id: " << id.sslId << std::endl;
|
|
|
|
std::cerr << "issuerName: " << id.pgpId << " id: " << id.sslId << std::endl;
|
|
|
|
#endif
|
2010-06-26 08:31:24 -04:00
|
|
|
|
2012-06-14 16:13:31 -04:00
|
|
|
if(! RsInit::GetPGPLoginDetails(id.pgpId, id.pgpName, id.pgpEmail))
|
|
|
|
return false ;
|
2012-06-09 17:01:22 -04:00
|
|
|
|
2012-06-14 16:13:31 -04:00
|
|
|
if(!AuthGPG::getAuthGPG()->isKeySupported(id.pgpId))
|
|
|
|
return false ;
|
2012-06-09 17:01:22 -04:00
|
|
|
|
2012-06-14 16:13:31 -04:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "PGPLoginDetails: " << id.pgpId << " name: " << id.pgpName;
|
|
|
|
std::cerr << " email: " << id.pgpEmail << std::endl;
|
|
|
|
#endif
|
|
|
|
ret = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "GetIssuerName FAILED!" << std::endl;
|
|
|
|
ret = false;
|
|
|
|
}
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
return ret;
|
|
|
|
}
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-11-15 18:44:12 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/************************* Generating Certificates ***************************/
|
|
|
|
/*****************************************************************************/
|
|
|
|
/*****************************************************************************/
|
2008-11-15 18:44:12 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Generating GPGme Account */
|
2010-01-13 15:56:55 -05:00
|
|
|
int RsInit::GetPGPLogins(std::list<std::string> &pgpIds) {
|
2010-01-13 16:22:52 -05:00
|
|
|
AuthGPG::getAuthGPG()->availableGPGCertificatesWithPrivateKeys(pgpIds);
|
2009-07-30 17:27:47 -04:00
|
|
|
return 1;
|
|
|
|
}
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
int RsInit::GetPGPLoginDetails(const std::string& id, std::string &name, std::string &email)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
2010-02-07 16:28:40 -05:00
|
|
|
#ifdef GPG_DEBUG
|
|
|
|
std::cerr << "RsInit::GetPGPLoginDetails for \"" << id << "\"" << std::endl;
|
|
|
|
#endif
|
2010-01-13 15:56:55 -05:00
|
|
|
|
2012-06-09 17:01:22 -04:00
|
|
|
bool ok = true ;
|
|
|
|
name = AuthGPG::getAuthGPG()->getGPGName(id,&ok);
|
|
|
|
if(!ok)
|
|
|
|
return 0 ;
|
|
|
|
email = AuthGPG::getAuthGPG()->getGPGEmail(id,&ok);
|
|
|
|
if(!ok)
|
|
|
|
return 0 ;
|
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
if (name != "") {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2010-07-01 16:30:36 -04:00
|
|
|
/*
|
|
|
|
* To prevent several running instances from using the same directory
|
|
|
|
* simultaneously we have to use a global lock.
|
|
|
|
* We use a lock file on Unix systems.
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 : Success
|
|
|
|
* 1 : Another instance already has the lock
|
|
|
|
* 2 : Unexpected error
|
|
|
|
*/
|
2011-03-16 19:25:57 -04:00
|
|
|
int RsInit::LockConfigDirectory(const std::string& accountDir, std::string& lockFilePath)
|
2010-07-01 16:30:36 -04:00
|
|
|
{
|
2011-05-15 08:42:55 -04:00
|
|
|
const std::string lockFile = accountDir + "/" + "lock";
|
2011-08-12 16:02:00 -04:00
|
|
|
lockFilePath = lockFile;
|
2010-09-29 20:27:23 -04:00
|
|
|
|
2012-06-12 16:31:13 -04:00
|
|
|
return RsDirUtil::createLockFile(lockFile,RsInitConfig::lockHandle) ;
|
2010-07-01 16:30:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlock the currently locked profile, if there is one.
|
|
|
|
* For Unix systems we simply close the handle of the lock file.
|
|
|
|
*/
|
|
|
|
void RsInit::UnlockConfigDirectory()
|
|
|
|
{
|
2012-06-12 16:31:13 -04:00
|
|
|
RsDirUtil::releaseLockFile(RsInitConfig::lockHandle) ;
|
2010-07-01 16:30:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Before any SSL stuff can be loaded, the correct PGP must be selected / generated:
|
|
|
|
**/
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2010-07-01 16:30:36 -04:00
|
|
|
bool RsInit::SelectGPGAccount(const std::string& gpgId)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
2010-07-01 16:30:36 -04:00
|
|
|
bool retVal = false;
|
2008-04-03 10:34:52 -04:00
|
|
|
|
2010-07-01 16:30:36 -04:00
|
|
|
if (0 < AuthGPG::getAuthGPG() -> GPGInit(gpgId))
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
2010-07-01 16:30:36 -04:00
|
|
|
retVal = true;
|
|
|
|
std::cerr << "PGP Auth Success!";
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
std::cerr << "PGP Auth Failed!";
|
2010-07-01 16:30:36 -04:00
|
|
|
|
|
|
|
std::cerr << " ID: " << gpgId << std::endl;
|
|
|
|
|
|
|
|
return retVal;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
bool RsInit::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString)
|
|
|
|
{
|
|
|
|
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2008-11-02 06:38:11 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Create SSL Certificates */
|
2011-08-12 16:02:00 -04:00
|
|
|
bool RsInit::GenerateSSLCertificate(const std::string& gpg_id, const std::string& org, const std::string& loc, const std::string& country, const std::string& passwd, std::string &sslId, std::string &errString)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
// generate the private_key / certificate.
|
|
|
|
// save to file.
|
2008-11-13 18:03:46 -05:00
|
|
|
//
|
2009-07-30 17:27:47 -04:00
|
|
|
// then load as if they had entered a passwd.
|
2008-11-15 18:44:12 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// check password.
|
|
|
|
if (passwd.length() < 4)
|
|
|
|
{
|
|
|
|
errString = "Password is Unsatisfactory (must be 4+ chars)";
|
|
|
|
return false;
|
|
|
|
}
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
int nbits = 2048;
|
2008-11-15 15:00:29 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
std::string name = AuthGPG::getAuthGPG()->getGPGName(gpg_id);
|
2010-01-18 07:30:54 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// Create the filename .....
|
|
|
|
// Temporary Directory for creating files....
|
|
|
|
std::string tmpdir = "TMPCFG";
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string tmpbase = RsInitConfig::basedir + "/" + tmpdir + "/";
|
2011-12-06 18:00:42 -05:00
|
|
|
|
|
|
|
if(!RsInit::setupAccount(tmpbase))
|
|
|
|
return false ;
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* create directory structure */
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string basename = tmpbase + configKeyDir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
basename += "user";
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string key_name = basename + "_pk.pem";
|
|
|
|
std::string cert_name = basename + "_cert.pem";
|
2008-07-02 09:19:59 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool gen_ok = false;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Extra step required for SSL + PGP, user must have selected
|
|
|
|
* or generated a suitable key so the signing can happen.
|
|
|
|
*/
|
2008-02-11 11:27:55 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
X509_REQ *req = GenerateX509Req(
|
|
|
|
key_name.c_str(),
|
|
|
|
passwd.c_str(),
|
|
|
|
name.c_str(),
|
|
|
|
"", //ui -> gen_email -> value(),
|
|
|
|
org.c_str(),
|
|
|
|
loc.c_str(),
|
|
|
|
"", //ui -> gen_state -> value(),
|
|
|
|
country.c_str(),
|
|
|
|
nbits, errString);
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2012-01-27 08:03:59 -05:00
|
|
|
if (req == NULL)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't create Request. Reason: %s\n", errString.c_str());
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
long days = 3000;
|
2011-08-12 16:02:00 -04:00
|
|
|
X509 *x509 = AuthSSL::getAuthSSL()->SignX509ReqWithGPG(req, days);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
X509_REQ_free(req);
|
2009-08-18 08:44:54 -04:00
|
|
|
if (x509 == NULL) {
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't sign ssl certificate. Probably PGP password is wrong.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* save to file */
|
|
|
|
if (x509)
|
|
|
|
{
|
|
|
|
gen_ok = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Print the signed Certificate! */
|
2011-08-12 16:02:00 -04:00
|
|
|
BIO *bio_out = NULL;
|
|
|
|
bio_out = BIO_new(BIO_s_file());
|
|
|
|
BIO_set_fp(bio_out,stdout,BIO_NOCLOSE);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
/* Print it out */
|
|
|
|
int nmflag = 0;
|
|
|
|
int reqflag = 0;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
X509_print_ex(bio_out, x509, nmflag, reqflag);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
BIO_flush(bio_out);
|
|
|
|
BIO_free(bio_out);
|
2008-06-13 19:22:20 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
else
|
2011-08-12 16:02:00 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
gen_ok = false;
|
2011-08-12 16:02:00 -04:00
|
|
|
}
|
2008-07-02 12:58:13 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (gen_ok)
|
|
|
|
{
|
|
|
|
/* Save cert to file */
|
2011-08-12 16:02:00 -04:00
|
|
|
// open the file.
|
|
|
|
FILE *out = NULL;
|
|
|
|
if (NULL == (out = RsDirUtil::rs_fopen(cert_name.c_str(), "w")))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't create Cert File");
|
|
|
|
fprintf(stderr," : %s\n", cert_name.c_str());
|
2009-07-30 17:27:47 -04:00
|
|
|
gen_ok = false;
|
2011-08-12 16:02:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!PEM_write_X509(out,x509))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't Save Cert");
|
|
|
|
fprintf(stderr," : %s\n", cert_name.c_str());
|
2009-07-30 17:27:47 -04:00
|
|
|
gen_ok = false;
|
2011-08-12 16:02:00 -04:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
fclose(out);
|
|
|
|
X509_free(x509);
|
|
|
|
}
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (!gen_ok)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
errString = "Generation of Certificate Failed";
|
|
|
|
return false;
|
2007-12-11 20:43:17 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* try to load it, and get Id */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
std::string location;
|
|
|
|
std::string gpgid;
|
|
|
|
if (LoadCheckX509(cert_name.c_str(), gpgid, location, sslId) == 0) {
|
|
|
|
std::cerr << "RsInit::GenerateSSLCertificate() Cannot check own signature, maybe the files are corrupted." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-27 17:31:25 -05:00
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
/* Move directory to correct id */
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string finalbase = RsInitConfig::basedir + "/" + sslId + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Rename Directory */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "Mv Config Dir from: " << tmpbase << " to: " << finalbase;
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-04-03 19:11:38 -04:00
|
|
|
if (!RsDirUtil::renameFile(tmpbase, finalbase))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "rename FAILED" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Flag as first time run */
|
|
|
|
RsInitConfig::firsttime_run = true;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
out << "RetroShare has Successfully generated";
|
|
|
|
out << "a Certficate/Key" << std::endl;
|
|
|
|
out << "\tCert Located: " << cert_name << std::endl;
|
|
|
|
out << "\tLocated: " << key_name << std::endl;
|
|
|
|
std::cerr << out.str();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
return true;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
/******************* PRIVATE FNS TO HELP with GEN **************/
|
2011-08-12 16:02:00 -04:00
|
|
|
bool RsInit::setupAccount(const std::string& accountdir)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
/* actual config directory isd */
|
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string subdir1 = accountdir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string subdir2 = subdir1;
|
|
|
|
subdir1 += configKeyDir;
|
|
|
|
subdir2 += configCertDir;
|
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string subdir3 = accountdir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
subdir3 += "cache";
|
|
|
|
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string subdir4 = subdir3 + "/";
|
|
|
|
std::string subdir5 = subdir3 + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
subdir4 += "local";
|
|
|
|
subdir5 += "remote";
|
|
|
|
|
|
|
|
// fatal if cannot find/create.
|
|
|
|
std::cerr << "Checking For Directories" << std::endl;
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(accountdir))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create BaseConfig Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir1))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Key Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir2))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cert Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir3))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir4))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache/local Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir5))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache/remote Dir" << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************** FINAL LOADING OF SETUP *************************/
|
|
|
|
/* Login SSL */
|
2011-08-12 16:02:00 -04:00
|
|
|
bool RsInit::LoadPassword(const std::string& id, const std::string& inPwd)
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
/* select configDir */
|
|
|
|
|
|
|
|
RsInitConfig::preferedId = id;
|
2011-05-15 08:42:55 -04:00
|
|
|
RsInitConfig::configDir = RsInitConfig::basedir + "/" + id;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::passwd = inPwd;
|
2010-04-08 08:02:46 -04:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
// if(inPwd != "")
|
|
|
|
// RsInitConfig::havePasswd = true;
|
2009-07-30 17:27:47 -04:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
// Create the filename.
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string basename = RsInitConfig::configDir + "/";
|
|
|
|
basename += configKeyDir + "/";
|
2009-08-18 08:43:19 -04:00
|
|
|
basename += "user";
|
2009-07-30 17:27:47 -04:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
RsInitConfig::load_key = basename + "_pk.pem";
|
|
|
|
RsInitConfig::load_cert = basename + "_cert.pem";
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-01 16:30:36 -04:00
|
|
|
/**
|
|
|
|
* Locks the profile directory and tries to finalize the login procedure
|
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 : success
|
|
|
|
* 1 : another instance is already running
|
|
|
|
* 2 : unexpected error while locking
|
|
|
|
* 3 : unexpected error while loading certificates
|
|
|
|
*/
|
2011-03-16 19:25:57 -04:00
|
|
|
int RsInit::LockAndLoadCertificates(bool autoLoginNT, std::string& lockFilePath)
|
2010-07-01 16:30:36 -04:00
|
|
|
{
|
2011-08-12 16:02:00 -04:00
|
|
|
int retVal = LockConfigDirectory(RsInitConfig::configDir, lockFilePath);
|
2010-07-01 16:30:36 -04:00
|
|
|
if(retVal != 0)
|
|
|
|
return retVal;
|
|
|
|
|
|
|
|
retVal = LoadCertificates(autoLoginNT);
|
|
|
|
if(retVal != 1) {
|
|
|
|
UnlockConfigDirectory();
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
|
2010-07-01 16:30:36 -04:00
|
|
|
/** *************************** FINAL LOADING OF SETUP *************************
|
2009-07-30 17:27:47 -04:00
|
|
|
* Requires:
|
|
|
|
* PGPid to be selected (Password not required).
|
|
|
|
* CertId to be selected (Password Required).
|
2010-07-01 16:30:36 -04:00
|
|
|
*
|
|
|
|
* Return value:
|
|
|
|
* 0 : unexpected error
|
|
|
|
* 1 : success
|
2009-07-30 17:27:47 -04:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-08-18 08:43:19 -04:00
|
|
|
//check if password is already in memory
|
2011-02-01 18:27:53 -05:00
|
|
|
|
2011-08-05 16:45:09 -04:00
|
|
|
if(RsInitConfig::passwd == "") {
|
|
|
|
if (RsLoginHandler::getSSLPassword(RsInitConfig::preferedId,true,RsInitConfig::passwd) == false) {
|
|
|
|
std::cerr << "RsLoginHandler::getSSLPassword() Failed!";
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile(RsInitConfig::preferedId,RsInitConfig::passwd) == false) {
|
|
|
|
std::cerr << "RsLoginHandler::checkAndStoreSSLPasswdIntoGPGFile() Failed!";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-04-08 08:02:46 -04:00
|
|
|
|
2009-08-18 08:43:19 -04:00
|
|
|
std::cerr << "RsInitConfig::load_key.c_str() : " << RsInitConfig::load_key.c_str() << std::endl;
|
2010-04-08 08:02:46 -04:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
if(0 == AuthSSL::getAuthSSL() -> InitAuth(RsInitConfig::load_cert.c_str(), RsInitConfig::load_key.c_str(), RsInitConfig::passwd.c_str()))
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
std::cerr << "SSL Auth Failed!";
|
2011-02-01 18:27:53 -05:00
|
|
|
return 0 ;
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
if(autoLoginNT)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2011-02-01 18:27:53 -05:00
|
|
|
std::cerr << "RetroShare will AutoLogin next time";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
RsLoginHandler::enableAutoLogin(RsInitConfig::preferedId,RsInitConfig::passwd);
|
|
|
|
RsInitConfig::autoLogin = true ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
/* wipe out password */
|
|
|
|
RsInitConfig::passwd = "";
|
|
|
|
create_configinit(RsInitConfig::basedir, RsInitConfig::preferedId);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2011-08-12 16:02:00 -04:00
|
|
|
|
2011-02-01 18:27:53 -05:00
|
|
|
bool RsInit::RsClearAutoLogin()
|
|
|
|
{
|
|
|
|
return RsLoginHandler::clearAutoLogin(RsInitConfig::preferedId);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2011-08-12 16:02:00 -04:00
|
|
|
|
|
|
|
bool RsInit::get_configinit(const std::string& dir, std::string &id)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
// have a config directories.
|
|
|
|
|
|
|
|
// Check for config file.
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string initfile = dir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
initfile += configInitFile;
|
|
|
|
|
|
|
|
// open and read in the lines.
|
2011-04-03 19:11:38 -04:00
|
|
|
FILE *ifd = RsDirUtil::rs_fopen(initfile.c_str(), "r");
|
2009-07-30 17:27:47 -04:00
|
|
|
char path[1024];
|
|
|
|
int i;
|
2008-11-09 11:52:14 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (ifd != NULL)
|
|
|
|
{
|
|
|
|
if (NULL != fgets(path, 1024, ifd))
|
|
|
|
{
|
|
|
|
for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++) {}
|
|
|
|
path[i] = '\0';
|
|
|
|
id = path;
|
|
|
|
}
|
|
|
|
fclose(ifd);
|
|
|
|
return true;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
// we have now
|
|
|
|
// 1) checked or created the config dirs.
|
|
|
|
// 2) loaded the config_init file - if possible.
|
2007-11-14 22:18:48 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-12 16:02:00 -04:00
|
|
|
bool RsInit::create_configinit(const std::string& dir, const std::string& id)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
// Check for config file.
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string initfile = dir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
initfile += configInitFile;
|
2008-11-09 11:52:14 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// open and read in the lines.
|
2011-04-03 19:11:38 -04:00
|
|
|
FILE *ifd = RsDirUtil::rs_fopen(initfile.c_str(), "w");
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
if (ifd != NULL)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
fprintf(ifd, "%s\n", id.c_str());
|
|
|
|
fclose(ifd);
|
|
|
|
|
|
|
|
std::cerr << "Creating Init File: " << initfile << std::endl;
|
|
|
|
std::cerr << "\tId: " << id << std::endl;
|
|
|
|
|
|
|
|
return true;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "Failed To Create Init File: " << initfile << std::endl;
|
|
|
|
return false;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string RsInit::getHomePath()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string home;
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
home = getenv("HOME");
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#else /* Windows */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::ostringstream out;
|
|
|
|
char *h2 = getenv("HOMEDRIVE");
|
|
|
|
out << "getHomePath() -> $HOMEDRIVE = ";
|
|
|
|
out << h2 << std::endl;
|
|
|
|
char *h3 = getenv("HOMEPATH");
|
|
|
|
out << "getHomePath() -> $HOMEPATH = ";
|
|
|
|
out << h3 << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (h2 == NULL)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
// Might be Win95/98
|
|
|
|
// generate default.
|
|
|
|
home = "C:\\Retro";
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
else
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
home = h2;
|
|
|
|
home += h3;
|
|
|
|
home += "\\Desktop";
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
out << "fltkserver::getHomePath() -> " << home << std::endl;
|
2009-12-13 16:59:26 -05:00
|
|
|
std::cerr << out.str();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// convert to FLTK desired format.
|
2011-05-15 08:42:55 -04:00
|
|
|
home = RsDirUtil::convertPathToUnix(home);
|
2009-07-30 17:27:47 -04:00
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
return home;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
2010-04-30 10:34:48 -04:00
|
|
|
bool RsInit::isPortable()
|
|
|
|
{
|
2010-05-02 18:28:33 -04:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
return RsInitConfig::portable;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2010-04-30 10:34:48 -04:00
|
|
|
}
|
|
|
|
|
2010-10-07 07:17:42 -04:00
|
|
|
bool RsInit::isWindowsXP()
|
|
|
|
{
|
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
return RsInitConfig::isWindowsXP;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
2011-02-01 18:27:53 -05:00
|
|
|
std::string RsInit::RsConfigKeysDirectory()
|
|
|
|
{
|
2011-05-15 08:42:55 -04:00
|
|
|
return RsInitConfig::basedir + "/" + RsInitConfig::preferedId + "/" + configKeyDir ;
|
2011-02-01 18:27:53 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string RsInit::RsConfigDirectory()
|
|
|
|
{
|
|
|
|
return RsInitConfig::basedir;
|
|
|
|
}
|
|
|
|
|
2010-01-27 17:31:25 -05:00
|
|
|
std::string RsInit::RsProfileConfigDirectory()
|
|
|
|
{
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string dir = RsInitConfig::basedir + "/" + RsInitConfig::preferedId;
|
2010-02-07 16:28:40 -05:00
|
|
|
//std::cerr << "RsInit::RsProfileConfigDirectory() returning : " << dir << std::endl;
|
2010-01-27 17:31:25 -05:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2011-04-14 17:59:51 -04:00
|
|
|
bool RsInit::getStartMinimised()
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
return RsInitConfig::startMinimised;
|
|
|
|
}
|
|
|
|
|
2011-04-14 17:59:51 -04:00
|
|
|
std::string RsInit::getRetroShareLink()
|
|
|
|
{
|
|
|
|
return RsInitConfig::RetroShareLink;
|
|
|
|
}
|
|
|
|
|
2010-04-08 08:02:46 -04:00
|
|
|
int RsInit::getSslPwdLen(){
|
|
|
|
return SSLPWD_LEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsInit::getAutoLogin(){
|
|
|
|
return RsInitConfig::autoLogin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RsInit::setAutoLogin(bool autoLogin){
|
|
|
|
RsInitConfig::autoLogin = autoLogin;
|
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Init Part of RsServer... needs the private
|
|
|
|
* variables so in the same file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
//#include <getopt.h>
|
|
|
|
|
|
|
|
#include "dbase/cachestrapper.h"
|
|
|
|
#include "ft/ftserver.h"
|
|
|
|
#include "ft/ftcontroller.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsiface.h"
|
|
|
|
#include "retroshare/rsturtle.h"
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
/* 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"
|
2011-09-29 05:20:09 -04:00
|
|
|
#include "pqi/p3historymgr.h"
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
#include "util/rsdebug.h"
|
|
|
|
#include "util/rsdir.h"
|
2011-07-09 20:41:39 -04:00
|
|
|
#include "util/rsrandom.h"
|
2011-12-13 11:19:37 -05:00
|
|
|
|
|
|
|
#ifdef RS_ENABLE_ZEROCONF
|
|
|
|
#include "zeroconf/p3zeroconf.h"
|
2012-01-14 11:41:00 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef RS_ENABLE_ZCNATASSIST
|
|
|
|
#include "zeroconf/p3zcnatassist.h"
|
2011-12-13 11:19:37 -05:00
|
|
|
#else
|
|
|
|
#include "upnp/upnphandler.h"
|
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include "services/p3disc.h"
|
|
|
|
#include "services/p3msgservice.h"
|
|
|
|
#include "services/p3chatservice.h"
|
|
|
|
#include "services/p3gamelauncher.h"
|
|
|
|
#include "services/p3photoservice.h"
|
|
|
|
#include "services/p3forums.h"
|
|
|
|
#include "services/p3channels.h"
|
2010-04-15 06:47:48 -04:00
|
|
|
#include "services/p3statusservice.h"
|
2010-02-03 17:53:35 -05:00
|
|
|
#include "services/p3blogs.h"
|
2009-07-30 17:27:47 -04:00
|
|
|
#include "turtle/p3turtle.h"
|
2010-06-24 14:06:10 -04:00
|
|
|
|
|
|
|
#ifndef PQI_DISABLE_TUNNEL
|
2009-12-13 16:59:26 -05:00
|
|
|
#include "services/p3tunnel.h"
|
2010-06-24 14:06:10 -04:00
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-08-03 13:43:26 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// for blocking signals
|
|
|
|
#include <signal.h>
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Implemented Rs Interfaces */
|
|
|
|
#include "rsserver/p3face.h"
|
|
|
|
#include "rsserver/p3peers.h"
|
|
|
|
#include "rsserver/p3msgs.h"
|
|
|
|
#include "rsserver/p3discovery.h"
|
|
|
|
#include "rsserver/p3photo.h"
|
2010-04-15 06:47:48 -04:00
|
|
|
#include "rsserver/p3status.h"
|
2011-09-29 05:20:09 -04:00
|
|
|
#include "rsserver/p3history.h"
|
2011-07-11 14:48:56 -04:00
|
|
|
#include "rsserver/p3serverconfig.h"
|
|
|
|
|
2010-08-06 05:40:23 -04:00
|
|
|
#include "retroshare/rsgame.h"
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
#include "pqi/p3peermgr.h"
|
|
|
|
#include "pqi/p3linkmgr.h"
|
|
|
|
#include "pqi/p3netmgr.h"
|
|
|
|
|
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#include "tcponudp/tou.h"
|
|
|
|
#include "tcponudp/rsudpstack.h"
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifdef RS_USE_BITDHT
|
|
|
|
#include "dht/p3bitdht.h"
|
2011-07-09 20:41:39 -04:00
|
|
|
#include "dht/stunaddrassist.h"
|
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#include "udp/udpstack.h"
|
2011-06-29 14:02:44 -04:00
|
|
|
#include "tcponudp/udppeer.h"
|
|
|
|
#include "tcponudp/udprelay.h"
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/****
|
2011-08-03 13:43:26 -04:00
|
|
|
* #define RS_RELEASE 1
|
2009-07-30 17:27:47 -04:00
|
|
|
****/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-08-03 13:43:26 -04:00
|
|
|
#define RS_RELEASE 1
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
#include "services/p3banlist.h"
|
|
|
|
#include "services/p3dsdv.h"
|
|
|
|
|
2009-07-12 12:11:09 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify)
|
|
|
|
{
|
|
|
|
RsServer *srv = new RsServer(iface, notify);
|
|
|
|
rsicontrol = srv;
|
|
|
|
return srv;
|
|
|
|
}
|
2009-07-12 12:11:09 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/*
|
|
|
|
* The Real RetroShare Startup Function.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int RsServer::StartupRetroShare()
|
|
|
|
{
|
|
|
|
/**************************************************************************/
|
|
|
|
/* STARTUP procedure */
|
|
|
|
/**************************************************************************/
|
|
|
|
/**************************************************************************/
|
|
|
|
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */
|
|
|
|
/**************************************************************************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
if (1 != AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "main() - Fatal Error....." << std::endl;
|
|
|
|
std::cerr << "Invalid Certificate configuration!" << std::endl;
|
|
|
|
std::cerr << std::endl;
|
2011-12-06 18:00:42 -05:00
|
|
|
return false ;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
std::string ownId = AuthSSL::getAuthSSL()->OwnId();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Any Initial Configuration (Commandline Options) */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* set the debugging to crashMode */
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "set the debugging to crashMode." << std::endl;
|
|
|
|
if ((!RsInitConfig::haveLogFile) && (!RsInitConfig::outStderr))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string crashfile = RsInitConfig::basedir + "/";
|
|
|
|
crashfile += ownId + "/" + configLogFileName;
|
2009-07-30 17:27:47 -04:00
|
|
|
setDebugCrashMode(crashfile.c_str());
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
unsigned long flags = 0;
|
|
|
|
if (RsInitConfig::udpListenerOnly)
|
|
|
|
{
|
|
|
|
flags |= PQIPERSON_NO_LISTENER;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
// Load up Certificates, and Old Configuration (if present)
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "Load up Certificates, and Old Configuration (if present)." << std::endl;
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string emergencySaveDir = RsInitConfig::configDir.c_str();
|
|
|
|
std::string emergencyPartialsDir = RsInitConfig::configDir.c_str();
|
2010-06-26 08:31:24 -04:00
|
|
|
if (emergencySaveDir != "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
emergencySaveDir += "/";
|
|
|
|
emergencyPartialsDir += "/";
|
|
|
|
}
|
|
|
|
emergencySaveDir += "Downloads";
|
|
|
|
emergencyPartialsDir += "Partials";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* setup classes / structures */
|
|
|
|
/**************************************************************************/
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "setup classes / structures" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-10-08 13:47:36 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-09-29 05:20:09 -04:00
|
|
|
/* History Manager */
|
|
|
|
mHistoryMgr = new p3HistoryMgr();
|
2011-07-13 10:22:25 -04:00
|
|
|
mPeerMgr = new p3PeerMgrIMPL();
|
|
|
|
mNetMgr = new p3NetMgrIMPL();
|
|
|
|
mLinkMgr = new p3LinkMgrIMPL(mPeerMgr, mNetMgr);
|
2011-10-08 13:47:36 -04:00
|
|
|
|
|
|
|
/* Setup Notify Early - So we can use it. */
|
|
|
|
rsNotify = new p3Notify();
|
|
|
|
rsPeers = new p3Peers(mLinkMgr, mPeerMgr, mNetMgr);
|
|
|
|
|
2012-02-14 17:55:14 -05:00
|
|
|
mPeerMgr->setManagers(mLinkMgr, mNetMgr);
|
2011-07-09 14:39:34 -04:00
|
|
|
mNetMgr->setManagers(mPeerMgr, mLinkMgr);
|
|
|
|
|
2010-01-13 16:16:18 -05:00
|
|
|
//load all the SSL certs as friends
|
2010-01-13 16:22:52 -05:00
|
|
|
// std::list<std::string> sslIds;
|
|
|
|
// AuthSSL::getAuthSSL()->getAuthenticatedList(sslIds);
|
|
|
|
// for (std::list<std::string>::iterator sslIdsIt = sslIds.begin(); sslIdsIt != sslIds.end(); sslIdsIt++) {
|
|
|
|
// mConnMgr->addFriend(*sslIdsIt);
|
|
|
|
// }
|
2009-12-14 13:10:49 -05:00
|
|
|
//p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInitConfig::configDir);
|
2010-07-31 14:14:10 -04:00
|
|
|
/**************************** BITDHT ***********************************/
|
|
|
|
|
|
|
|
// Make up an address. XXX
|
|
|
|
|
|
|
|
struct sockaddr_in tmpladdr;
|
|
|
|
sockaddr_clear(&tmpladdr);
|
2011-02-01 18:27:53 -05:00
|
|
|
tmpladdr.sin_port = htons(RsInitConfig::port);
|
2012-01-07 06:28:00 -05:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
|
|
|
|
rsUdpStack *mDhtStack = new rsUdpStack(UDP_TEST_RESTRICTED_LAYER, tmpladdr);
|
|
|
|
|
|
|
|
/* parse portRestrictions */
|
|
|
|
unsigned int lport, uport;
|
|
|
|
|
|
|
|
if (doPortRestrictions)
|
|
|
|
{
|
|
|
|
if (2 == sscanf(portRestrictions.c_str(), "%u-%u", &lport, &uport))
|
|
|
|
{
|
|
|
|
std::cerr << "Adding Port Restriction (" << lport << "-" << uport << ")";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to parse Port Restrictions ... exiting";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mDhtStack->getUdpLayer();
|
|
|
|
url->addRestrictedPortRange(lport, uport);
|
|
|
|
}
|
|
|
|
#else
|
2011-07-09 20:41:39 -04:00
|
|
|
rsUdpStack *mDhtStack = new rsUdpStack(tmpladdr);
|
2012-01-07 06:28:00 -05:00
|
|
|
#endif
|
2010-07-31 14:14:10 -04:00
|
|
|
|
|
|
|
#ifdef RS_USE_BITDHT
|
2010-10-28 18:59:46 -04:00
|
|
|
|
|
|
|
#define BITDHT_BOOTSTRAP_FILENAME "bdboot.txt"
|
|
|
|
|
|
|
|
|
2010-10-01 15:48:53 -04:00
|
|
|
std::string bootstrapfile = RsInitConfig::configDir.c_str();
|
|
|
|
if (bootstrapfile != "")
|
|
|
|
{
|
|
|
|
bootstrapfile += "/";
|
|
|
|
}
|
2010-10-28 18:59:46 -04:00
|
|
|
bootstrapfile += BITDHT_BOOTSTRAP_FILENAME;
|
|
|
|
|
|
|
|
std::cerr << "Checking for DHT bootstrap file: " << bootstrapfile << std::endl;
|
|
|
|
|
|
|
|
/* check if bootstrap file exists...
|
|
|
|
* if not... copy from dataDirectory
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!RsDirUtil::checkFile(bootstrapfile))
|
|
|
|
{
|
|
|
|
std::cerr << "DHT bootstrap file not in ConfigDir: " << bootstrapfile << std::endl;
|
|
|
|
std::string installfile = RsInit::getRetroshareDataDirectory();
|
2011-05-15 08:42:55 -04:00
|
|
|
installfile += "/";
|
2010-10-28 18:59:46 -04:00
|
|
|
installfile += BITDHT_BOOTSTRAP_FILENAME;
|
|
|
|
|
|
|
|
std::cerr << "Checking for Installation DHT bootstrap file " << installfile << std::endl;
|
|
|
|
if ((installfile != "") && (RsDirUtil::checkFile(installfile)))
|
|
|
|
{
|
|
|
|
std::cerr << "Copying Installation DHT bootstrap file..." << std::endl;
|
|
|
|
if (RsDirUtil::copyFile(installfile, bootstrapfile))
|
|
|
|
{
|
|
|
|
std::cerr << "Installed DHT bootstrap file in configDir" << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Failed Installation DHT bootstrap file..." << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "No Installation DHT bootstrap file to copy" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2010-07-31 14:14:10 -04:00
|
|
|
|
2011-06-29 14:02:44 -04:00
|
|
|
/* construct the rest of the stack, important to build them in the correct order! */
|
|
|
|
/* MOST OF THIS IS COMMENTED OUT UNTIL THE REST OF libretroshare IS READY FOR IT! */
|
|
|
|
|
2011-07-14 10:56:33 -04:00
|
|
|
UdpSubReceiver *udpReceivers[RSUDP_NUM_TOU_RECVERS];
|
|
|
|
int udpTypes[RSUDP_NUM_TOU_RECVERS];
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// FIRST DHT STUNNER.
|
2011-07-09 20:41:39 -04:00
|
|
|
UdpStunner *mDhtStunner = new UdpStunner(mDhtStack);
|
|
|
|
mDhtStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
|
|
|
mDhtStack->addReceiver(mDhtStunner);
|
2011-06-29 14:02:44 -04:00
|
|
|
|
2012-01-07 06:28:00 -05:00
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
mDhtStunner->SetAcceptLocalNet();
|
|
|
|
#endif
|
|
|
|
|
2011-06-29 14:02:44 -04:00
|
|
|
// NEXT BITDHT.
|
2011-07-09 20:41:39 -04:00
|
|
|
p3BitDht *mBitDht = new p3BitDht(ownId, mLinkMgr, mNetMgr, mDhtStack, bootstrapfile);
|
2011-07-06 09:04:50 -04:00
|
|
|
/* install external Pointer for Interface */
|
|
|
|
rsDht = mBitDht;
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
|
2011-07-09 20:41:39 -04:00
|
|
|
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
|
2011-07-14 10:56:33 -04:00
|
|
|
udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX] = mRelay; /* RELAY Connections (DHT Port) */
|
|
|
|
udpTypes[RSUDP_TOU_RECVER_RELAY_IDX] = TOU_RECEIVER_TYPE_UDPRELAY;
|
|
|
|
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX]);
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// LAST ON THIS STACK IS STANDARD DIRECT TOU
|
2011-07-14 10:56:33 -04:00
|
|
|
udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX] = new UdpPeerReceiver(mDhtStack); /* standard DIRECT Connections (DHT Port) */
|
|
|
|
udpTypes[RSUDP_TOU_RECVER_DIRECT_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
|
|
|
mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX]);
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// NOW WE BUILD THE SECOND STACK.
|
|
|
|
// Create the Second UdpStack... Port should be random (but openable!).
|
2011-08-04 18:57:12 -04:00
|
|
|
|
|
|
|
#define MIN_RANDOM_PORT 30000
|
|
|
|
#define MAX_RANDOM_PORT 50000
|
2011-07-09 20:41:39 -04:00
|
|
|
|
|
|
|
struct sockaddr_in sndladdr;
|
|
|
|
sockaddr_clear(&sndladdr);
|
2012-01-11 05:24:37 -05:00
|
|
|
|
|
|
|
#ifdef LOCALNET_TESTING
|
2012-01-07 07:22:30 -05:00
|
|
|
// HACK Proxy Port near Dht Port - For Relay Testing.
|
|
|
|
uint16_t rndport = RsInitConfig::port + 3;
|
2011-08-04 18:57:12 -04:00
|
|
|
sndladdr.sin_port = htons(rndport);
|
2012-01-11 05:24:37 -05:00
|
|
|
#else
|
|
|
|
uint16_t rndport = MIN_RANDOM_PORT + RSRandom::random_u32() % (MAX_RANDOM_PORT - MIN_RANDOM_PORT);
|
|
|
|
#endif
|
2012-01-07 06:28:00 -05:00
|
|
|
|
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
|
|
|
|
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(UDP_TEST_RESTRICTED_LAYER, sndladdr);
|
|
|
|
|
|
|
|
/* portRestrictions already parsed */
|
|
|
|
if (doPortRestrictions)
|
|
|
|
{
|
|
|
|
RestrictedUdpLayer *url = (RestrictedUdpLayer *) mProxyStack->getUdpLayer();
|
|
|
|
url->addRestrictedPortRange(lport, uport);
|
|
|
|
}
|
|
|
|
#else
|
2011-07-09 20:41:39 -04:00
|
|
|
rsFixedUdpStack *mProxyStack = new rsFixedUdpStack(sndladdr);
|
2012-01-07 06:28:00 -05:00
|
|
|
#endif
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// FIRSTLY THE PROXY STUNNER.
|
2011-07-09 20:41:39 -04:00
|
|
|
UdpStunner *mProxyStunner = new UdpStunner(mProxyStack);
|
|
|
|
mProxyStunner->setTargetStunPeriod(300); /* slow (5mins) */
|
|
|
|
mProxyStack->addReceiver(mProxyStunner);
|
2012-01-07 06:28:00 -05:00
|
|
|
|
|
|
|
#ifdef LOCALNET_TESTING
|
|
|
|
mProxyStunner->SetAcceptLocalNet();
|
|
|
|
#endif
|
|
|
|
|
2011-06-29 14:02:44 -04:00
|
|
|
|
|
|
|
// FINALLY THE PROXY UDP CONNECTIONS
|
2011-07-14 10:56:33 -04:00
|
|
|
udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */
|
|
|
|
udpTypes[RSUDP_TOU_RECVER_PROXY_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
|
|
|
|
mProxyStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX]);
|
2011-06-29 14:02:44 -04:00
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
// REAL INITIALISATION - WITH THREE MODES
|
2011-07-14 10:56:33 -04:00
|
|
|
tou_init((void **) udpReceivers, udpTypes, RSUDP_NUM_TOU_RECVERS);
|
2010-07-31 14:14:10 -04:00
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay);
|
|
|
|
|
|
|
|
mNetMgr->setAddrAssist(new stunAddrAssist(mDhtStunner), new stunAddrAssist(mProxyStunner));
|
2011-07-06 09:04:50 -04:00
|
|
|
#else
|
|
|
|
/* install NULL Pointer for rsDht Interface */
|
|
|
|
rsDht = NULL;
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/**************************** BITDHT ***********************************/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
SecurityPolicy *none = secpolicy_create();
|
2011-07-09 20:41:39 -04:00
|
|
|
pqih = new pqisslpersongrp(none, flags, mPeerMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
//pqih = new pqipersongrpDummy(none, flags);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/****** New Ft Server **** !!! */
|
2011-07-09 20:41:39 -04:00
|
|
|
ftserver = new ftServer(mPeerMgr, mLinkMgr);
|
2012-06-16 05:40:59 -04:00
|
|
|
ftserver->setP3Interface(pqih);
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->setConfigDirectory(RsInitConfig::configDir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->SetupFtServer(&(getNotify()));
|
|
|
|
CacheStrapper *mCacheStrapper = ftserver->getCacheStrapper();
|
|
|
|
CacheTransfer *mCacheTransfer = ftserver->getCacheTransfer();
|
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
/* setup any extra bits (Default Paths) */
|
|
|
|
ftserver->setPartialsDirectory(emergencyPartialsDir);
|
|
|
|
ftserver->setDownloadDirectory(emergencySaveDir);
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
/* This should be set by config ... there is no default */
|
2011-07-09 14:39:34 -04:00
|
|
|
//ftserver->setSharedDirectories(fileList);
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
rsFiles = ftserver;
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mConfigMgr = new p3ConfigMgr(RsInitConfig::configDir, "rs-v0.5.cfg", "rs-v0.5.sgn");
|
2009-07-30 17:27:47 -04:00
|
|
|
mGeneralConfig = new p3GeneralConfig();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
/* 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";
|
|
|
|
std::string blogsdir = config_dir + "/blogs";
|
|
|
|
std::string forumdir = config_dir + "/forums";
|
|
|
|
|
|
|
|
std::vector<std::string> plugins_directories ;
|
2011-06-17 15:59:01 -04:00
|
|
|
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
plugins_directories.push_back(std::string("/usr/lib/retroshare/extensions/")) ;
|
|
|
|
#endif
|
|
|
|
plugins_directories.push_back(RsInitConfig::basedir + "/extensions/") ;
|
2011-06-23 14:55:15 -04:00
|
|
|
#ifdef DEBUG_PLUGIN_SYSTEM
|
2011-06-16 17:59:26 -04:00
|
|
|
plugins_directories.push_back(".") ; // this list should be saved/set to some correct value.
|
|
|
|
// possible entries include: /usr/lib/retroshare, ~/.retroshare/extensions/, etc.
|
2011-06-23 14:55:15 -04:00
|
|
|
#endif
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
RsPluginManager *mPluginsManager = new RsPluginManager ;
|
|
|
|
rsPlugins = mPluginsManager ;
|
2011-07-05 16:29:07 -04:00
|
|
|
mConfigMgr->addConfiguration("plugins.cfg", mPluginsManager);
|
|
|
|
|
|
|
|
mPluginsManager->loadConfiguration() ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
// These are needed to load plugins: plugin devs might want to know the place of
|
|
|
|
// cache directories, get pointers to cache strapper, or access ownId()
|
|
|
|
//
|
|
|
|
mPluginsManager->setCacheDirectories(localcachedir,remotecachedir) ;
|
|
|
|
mPluginsManager->setFileServer(ftserver) ;
|
2012-02-19 10:03:07 -05:00
|
|
|
mPluginsManager->setLinkMgr(mLinkMgr) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
// Now load the plugins. This parses the available SO/DLL files for known symbols.
|
|
|
|
//
|
|
|
|
mPluginsManager->loadPlugins(plugins_directories) ;
|
|
|
|
|
2011-12-22 15:17:59 -05:00
|
|
|
// Also load some plugins explicitly. This is helpful for
|
|
|
|
// - developping plugins
|
|
|
|
//
|
|
|
|
std::vector<RsPlugin *> programatically_inserted_plugins ;
|
|
|
|
|
|
|
|
// Push your own plugins into this list, before the call:
|
|
|
|
//
|
|
|
|
// programatically_inserted_plugins.push_back(myCoolPlugin) ;
|
|
|
|
//
|
|
|
|
mPluginsManager->loadPlugins(programatically_inserted_plugins) ;
|
|
|
|
|
|
|
|
// set interfaces for plugins
|
|
|
|
RsPlugInInterfaces interfaces;
|
|
|
|
interfaces.mFiles = rsFiles;
|
|
|
|
interfaces.mPeers = rsPeers;
|
|
|
|
mPluginsManager->setInterfaces(interfaces);
|
2011-10-08 13:47:36 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* create Services */
|
2011-11-22 08:24:42 -05:00
|
|
|
ad = new p3disc(mPeerMgr, mLinkMgr, mNetMgr, pqih);
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2011-07-09 14:39:34 -04:00
|
|
|
msgSrv = new p3MsgService(mLinkMgr);
|
2011-09-29 05:20:09 -04:00
|
|
|
chatSrv = new p3ChatService(mLinkMgr, mHistoryMgr);
|
2011-07-09 14:39:34 -04:00
|
|
|
mStatusSrv = new p3StatusService(mLinkMgr);
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-06-24 14:06:10 -04:00
|
|
|
#ifndef PQI_DISABLE_TUNNEL
|
2010-01-13 15:56:55 -05:00
|
|
|
p3tunnel *tn = new p3tunnel(mConnMgr, pqih);
|
2009-12-13 16:59:26 -05:00
|
|
|
pqih -> addService(tn);
|
|
|
|
mConnMgr->setP3tunnel(tn);
|
2010-06-24 14:06:10 -04:00
|
|
|
#endif
|
2009-12-13 16:59:26 -05:00
|
|
|
|
2011-07-09 14:39:34 -04:00
|
|
|
p3turtle *tr = new p3turtle(mLinkMgr,ftserver) ;
|
2009-07-30 17:27:47 -04:00
|
|
|
rsTurtle = tr ;
|
|
|
|
pqih -> addService(tr);
|
|
|
|
ftserver->connectToTurtleRouter(tr) ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih -> addService(ad);
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih -> addService(msgSrv);
|
|
|
|
pqih -> addService(chatSrv);
|
2010-04-15 06:47:48 -04:00
|
|
|
pqih ->addService(mStatusSrv);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mForums = new p3Forums(RS_SERVICE_TYPE_FORUM, mCacheStrapper, mCacheTransfer, localcachedir, remotecachedir, forumdir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mCacheStrapper -> addCachePair( CachePair(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0)));
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih -> addService(mForums); /* This must be also ticked as a service */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL, mCacheStrapper, mCacheTransfer, rsFiles, localcachedir, remotecachedir, channelsdir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mCacheStrapper -> addCachePair(CachePair(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0)));
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih -> addService(mChannels); /* This must be also ticked as a service */
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifdef RS_USE_BLOGS
|
2011-06-16 17:59:26 -04:00
|
|
|
p3Blogs *mBlogs = new p3Blogs(RS_SERVICE_TYPE_QBLOG, mCacheStrapper, mCacheTransfer, rsFiles, localcachedir, remotecachedir, blogsdir);
|
2010-02-03 17:53:35 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mCacheStrapper -> addCachePair(CachePair(mBlogs, mBlogs, CacheId(RS_SERVICE_TYPE_QBLOG, 0)));
|
2010-02-03 17:53:35 -05:00
|
|
|
pqih -> addService(mBlogs); /* This must be also ticked as a service */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
2011-06-16 17:59:26 -04:00
|
|
|
// now add plugin objects inside the loop:
|
|
|
|
// - client services provided by plugins.
|
|
|
|
// - cache services provided by plugins.
|
|
|
|
//
|
|
|
|
mPluginsManager->registerClientServices(pqih) ;
|
|
|
|
mPluginsManager->registerCacheServices() ;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifndef RS_RELEASE
|
2011-07-09 14:39:34 -04:00
|
|
|
p3GameLauncher *gameLauncher = new p3GameLauncher(mLinkMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih -> addService(gameLauncher);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
|
|
|
|
mCacheStrapper, mCacheTransfer,
|
|
|
|
localcachedir, remotecachedir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp2);
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
2011-08-03 13:43:26 -04:00
|
|
|
|
|
|
|
#ifdef RS_VOIPTEST
|
|
|
|
p3VoRS *mVoipTest = new p3VoRS(mLinkMgr);
|
|
|
|
pqih -> addService(mVoipTest);
|
|
|
|
rsVoip = mVoipTest;
|
|
|
|
#endif
|
|
|
|
|
2011-11-24 19:58:01 -05:00
|
|
|
// new services to test.
|
|
|
|
p3BanList *mBanList = new p3BanList(mLinkMgr, mNetMgr);
|
|
|
|
pqih -> addService(mBanList);
|
|
|
|
mBitDht->setupPeerSharer(mBanList);
|
|
|
|
|
2011-12-01 12:21:52 -05:00
|
|
|
#ifdef RS_DSDVTEST
|
2011-11-24 19:58:01 -05:00
|
|
|
p3Dsdv *mDsdv = new p3Dsdv(mLinkMgr);
|
|
|
|
pqih -> addService(mDsdv);
|
|
|
|
rsDsdv = mDsdv;
|
|
|
|
mDsdv->addTestService();
|
2011-12-01 12:21:52 -05:00
|
|
|
#endif
|
2011-11-24 19:58:01 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifdef RS_USE_BITDHT
|
2011-07-09 14:39:34 -04:00
|
|
|
mNetMgr->addNetAssistConnect(1, mBitDht);
|
2011-07-09 20:41:39 -04:00
|
|
|
mNetMgr->addNetListener(mDhtStack);
|
|
|
|
mNetMgr->addNetListener(mProxyStack);
|
|
|
|
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
2011-12-13 11:19:37 -05:00
|
|
|
|
|
|
|
#ifdef RS_ENABLE_ZEROCONF
|
2012-01-06 07:48:04 -05:00
|
|
|
p3ZeroConf *mZeroConf = new p3ZeroConf(
|
|
|
|
AuthGPG::getAuthGPG()->getGPGOwnId(), ownId,
|
|
|
|
mLinkMgr, mNetMgr, mPeerMgr);
|
2011-12-13 11:19:37 -05:00
|
|
|
mNetMgr->addNetAssistConnect(2, mZeroConf);
|
|
|
|
mNetMgr->addNetListener(mZeroConf);
|
2012-01-14 11:41:00 -05:00
|
|
|
#endif
|
2011-12-13 11:19:37 -05:00
|
|
|
|
2012-01-14 11:41:00 -05:00
|
|
|
#ifdef RS_ENABLE_ZCNATASSIST
|
2011-12-13 11:19:37 -05:00
|
|
|
// Apple's UPnP & NAT-PMP assistance.
|
2012-01-14 11:41:00 -05:00
|
|
|
p3zcNatAssist *mZcNatAssist = new p3zcNatAssist();
|
|
|
|
mNetMgr->addNetAssistFirewall(1, mZcNatAssist);
|
2011-12-13 11:19:37 -05:00
|
|
|
#else
|
|
|
|
// Original UPnP Interface.
|
|
|
|
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
2011-07-09 14:39:34 -04:00
|
|
|
mNetMgr->addNetAssistFirewall(1, mUpnpMgr);
|
2011-12-13 11:19:37 -05:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* need to Monitor too! */
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->addMonitor(pqih);
|
|
|
|
mLinkMgr->addMonitor(mCacheStrapper);
|
|
|
|
mLinkMgr->addMonitor(ad);
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->addMonitor(msgSrv);
|
|
|
|
mLinkMgr->addMonitor(mStatusSrv);
|
|
|
|
mLinkMgr->addMonitor(chatSrv);
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* must also add the controller as a Monitor...
|
|
|
|
* a little hack to get it to work.
|
|
|
|
*/
|
2011-07-09 14:39:34 -04:00
|
|
|
mLinkMgr->addMonitor(((ftController *) mCacheTransfer));
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
2009-05-07 17:36:17 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
|
|
|
|
//
|
2012-04-08 10:52:01 -04:00
|
|
|
mConfigMgr->addConfiguration("gpg_prefs.cfg", AuthGPG::getAuthGPG());
|
2011-12-12 11:07:38 -05:00
|
|
|
mConfigMgr->loadConfiguration();
|
2010-01-13 16:26:30 -05:00
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
mConfigMgr->addConfiguration("peers.cfg", mPeerMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
2010-08-31 16:00:49 -04:00
|
|
|
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
|
|
|
|
#ifndef MINIMAL_LIBRS
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
|
|
|
mConfigMgr->addConfiguration("chat.cfg", chatSrv);
|
2011-09-29 05:20:09 -04:00
|
|
|
mConfigMgr->addConfiguration("p3History.cfg", mHistoryMgr);
|
|
|
|
#ifdef RS_USE_BLOGS
|
2011-07-05 16:29:07 -04:00
|
|
|
mConfigMgr->addConfiguration("blogs.cfg", mBlogs);
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
|
|
|
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
2010-08-31 16:00:49 -04:00
|
|
|
mConfigMgr->addConfiguration("p3Status.cfg", mStatusSrv);
|
|
|
|
#endif // MINIMAL_LIBRS
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
2011-06-16 17:59:26 -04:00
|
|
|
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
|
|
|
|
2011-12-19 21:07:00 -05:00
|
|
|
#ifdef RS_USE_BITDHT
|
|
|
|
mConfigMgr->addConfiguration("bitdht.cfg", mBitDht);
|
|
|
|
#endif
|
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
mPluginsManager->addConfigurations(mConfigMgr) ;
|
2009-05-07 17:36:17 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->addConfiguration(mConfigMgr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* (2) Load configuration files */
|
|
|
|
/**************************************************************************/
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "(2) Load configuration files" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->loadConfiguration();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* NOTE: CacheStrapper's load causes Cache Files to be
|
|
|
|
* loaded into all the CacheStores/Sources. This happens
|
|
|
|
* after all the other configurations have happened.
|
|
|
|
*/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* trigger generalConfig loading for classes that require it */
|
|
|
|
/**************************************************************************/
|
|
|
|
pqih->setConfig(mGeneralConfig);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih->load_config();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Force Any Configuration before Startup (After Load) */
|
|
|
|
/**************************************************************************/
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "Force Any Configuration before Startup (After Load)" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::forceLocalAddr)
|
|
|
|
{
|
|
|
|
struct sockaddr_in laddr;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* clean sockaddr before setting values (MaxOSX) */
|
|
|
|
sockaddr_clear(&laddr);
|
|
|
|
|
|
|
|
laddr.sin_family = AF_INET;
|
|
|
|
laddr.sin_port = htons(RsInitConfig::port);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// universal
|
|
|
|
laddr.sin_addr.s_addr = inet_addr(RsInitConfig::inet);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
mPeerMgr->setLocalAddress(ownId, laddr);
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::forceExtPort)
|
|
|
|
{
|
2011-07-09 20:41:39 -04:00
|
|
|
mPeerMgr->setOwnNetworkMode(RS_NET_MODE_EXT);
|
|
|
|
mPeerMgr->setOwnVisState(RS_VIS_STATE_STD);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* must load the trusted_peer before setting up the pqipersongrp */
|
|
|
|
if (firsttime_run)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
/* 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);
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-07-09 20:41:39 -04:00
|
|
|
mNetMgr -> checkNetAddress();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* startup (stuff dependent on Ids/peers is after this point) */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih->init_listener();
|
2011-07-09 20:41:39 -04:00
|
|
|
mNetMgr->addNetListener(pqih); /* add listener so we can reset all sockets later */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* load caches and secondary data */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-05-23 12:35:42 -04:00
|
|
|
// Clear the News Feeds that are generated by Initial Cache Loading.
|
|
|
|
|
|
|
|
/* Peer stuff is up to date */
|
|
|
|
|
|
|
|
/* Channel/Forum/Blog stuff will all come from Caches */
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_CHAN_NEW);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_CHAN_UPDATE);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_CHAN_MSG);
|
|
|
|
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FORUM_NEW);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FORUM_UPDATE);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FORUM_MSG);
|
|
|
|
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_BLOG_NEW);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_BLOG_UPDATE);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_BLOG_MSG);
|
|
|
|
|
|
|
|
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_CHAT_NEW);
|
|
|
|
getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_MESSAGE);
|
|
|
|
//getPqiNotify()->ClearFeedItems(RS_FEED_ITEM_FILES_NEW);
|
|
|
|
|
2011-02-02 16:03:46 -05:00
|
|
|
/* flag that the basic Caches are now in the pending Queues */
|
|
|
|
#ifndef MINIMAL_LIBRS
|
|
|
|
mForums->HistoricalCachesDone();
|
|
|
|
mChannels->HistoricalCachesDone();
|
|
|
|
|
|
|
|
#ifdef RS_USE_BLOGS
|
|
|
|
mBlogs->HistoricalCachesDone();
|
|
|
|
#endif
|
|
|
|
#endif // MINIMAL_LIBRS
|
|
|
|
|
|
|
|
|
2010-10-13 12:15:26 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Add AuthGPG services */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
AuthGPG::getAuthGPG()->addService(ad);
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Force Any Last Configuration Options */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Start up Threads */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-03-08 18:29:21 -05:00
|
|
|
ftserver->StartupThreads();
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->ResumeTransfers();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-12-14 13:10:49 -05:00
|
|
|
//mDhtMgr->start();
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifdef RS_USE_BITDHT
|
|
|
|
mBitDht->start();
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-01-29 20:37:59 -05:00
|
|
|
// startup the p3distrib threads (for cache loading).
|
|
|
|
#ifndef MINIMAL_LIBRS
|
|
|
|
mForums->start();
|
|
|
|
mChannels->start();
|
|
|
|
|
|
|
|
#ifdef RS_USE_BLOGS
|
|
|
|
mBlogs->start();
|
|
|
|
#endif
|
|
|
|
#endif // MINIMAL_LIBRS
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// create loopback device, and add to pqisslgrp.
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
SearchModule *mod = new SearchModule();
|
|
|
|
pqiloopback *ploop = new pqiloopback(ownId);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mod -> peerid = ownId;
|
|
|
|
mod -> pqi = ploop;
|
|
|
|
mod -> sp = secpolicy_create();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
pqih->AddSearchModule(mod);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Setup GUI Interfaces. */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2011-10-08 13:47:36 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
rsDisc = new p3Discovery(ad);
|
2011-07-30 12:57:40 -04:00
|
|
|
rsConfig = new p3ServerConfig(mPeerMgr, mLinkMgr, mNetMgr, mGeneralConfig);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2011-06-16 17:59:26 -04:00
|
|
|
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
2009-07-30 17:27:47 -04:00
|
|
|
rsForums = mForums;
|
|
|
|
rsChannels = mChannels;
|
2010-07-31 14:14:10 -04:00
|
|
|
#ifdef RS_USE_BLOGS
|
2010-02-03 17:53:35 -05:00
|
|
|
rsBlogs = mBlogs;
|
2010-07-31 14:14:10 -04:00
|
|
|
#endif
|
2010-04-20 13:10:45 -04:00
|
|
|
rsStatus = new p3Status(mStatusSrv);
|
2011-09-29 05:20:09 -04:00
|
|
|
rsHistory = new p3History(mHistoryMgr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#ifndef RS_RELEASE
|
|
|
|
rsGameLauncher = gameLauncher;
|
|
|
|
rsPhoto = new p3Photo(photoService);
|
|
|
|
#else
|
|
|
|
rsGameLauncher = NULL;
|
|
|
|
rsPhoto = NULL;
|
|
|
|
#endif
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-08-31 16:00:49 -04:00
|
|
|
#ifndef MINIMAL_LIBRS
|
2009-07-30 17:27:47 -04:00
|
|
|
/* put a welcome message in! */
|
|
|
|
if (RsInitConfig::firsttime_run)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
msgSrv->loadWelcomeMsg();
|
2011-03-08 18:29:21 -05:00
|
|
|
ftserver->shareDownloadDirectory(true);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
2010-08-31 16:00:49 -04:00
|
|
|
#endif // MINIMAL_LIBRS
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// load up the help page
|
2011-05-15 08:42:55 -04:00
|
|
|
std::string helppage = RsInitConfig::basedir + "/";
|
2009-07-30 17:27:47 -04:00
|
|
|
helppage += configHelpName;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Startup this thread! */
|
2010-12-14 16:56:37 -05:00
|
|
|
createThread(*this);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
return 1;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|