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
|
|
|
|
|
|
|
|
2008-02-05 08:45:04 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include <unistd.h>
|
2008-07-10 12:29:18 -04:00
|
|
|
#include "util/rsdebug.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "util/rsdir.h"
|
2009-02-08 09:30:28 -05:00
|
|
|
#include "rsiface/rsinit.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>
|
|
|
|
|
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-01-13 15:56:55 -05:00
|
|
|
#include "pqi/authgpg.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
|
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:
|
|
|
|
/* OS Specifics */
|
|
|
|
static char dirSeperator;
|
|
|
|
|
|
|
|
/* Directories (SetupBaseDir) */
|
|
|
|
static std::string basedir;
|
|
|
|
static std::string homePath;
|
|
|
|
|
|
|
|
static std::list<accountId> accountIds;
|
|
|
|
static std::string preferedId;
|
|
|
|
|
|
|
|
/* for certificate creation */
|
|
|
|
//static std::string gpgPasswd;
|
|
|
|
|
|
|
|
/* These fields are needed for login */
|
|
|
|
static std::string loginId;
|
|
|
|
static std::string configDir;
|
|
|
|
static std::string load_cert;
|
|
|
|
static std::string load_key;
|
2009-08-18 08:43:19 -04:00
|
|
|
static std::string ssl_passphrase_file;
|
|
|
|
|
|
|
|
static std::string passwd;
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
static bool havePasswd; /* for Commandline password */
|
|
|
|
static bool autoLogin; /* autoLogin allowed */
|
|
|
|
static bool startMinimised; /* Icon or Full Window */
|
|
|
|
|
|
|
|
/* Key Parameters that must be set before
|
|
|
|
* RetroShare will start up:
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Listening Port */
|
|
|
|
static bool forceExtPort;
|
|
|
|
static bool forceLocalAddr;
|
|
|
|
static unsigned short port;
|
|
|
|
static char inet[256];
|
|
|
|
|
|
|
|
/* Logging */
|
|
|
|
static bool haveLogFile;
|
|
|
|
static bool outStderr;
|
|
|
|
static bool haveDebugLevel;
|
|
|
|
static int debugLevel;
|
|
|
|
static char logfname[1024];
|
|
|
|
|
|
|
|
static bool firsttime_run;
|
|
|
|
static bool load_trustedpeer;
|
|
|
|
static std::string load_trustedpeer_file;
|
|
|
|
|
|
|
|
static bool udpListenerOnly;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::list<accountId> RsInitConfig::accountIds;
|
|
|
|
std::string RsInitConfig::preferedId;
|
|
|
|
|
|
|
|
std::string RsInitConfig::configDir;
|
|
|
|
std::string RsInitConfig::load_cert;
|
|
|
|
std::string RsInitConfig::load_key;
|
2009-08-18 08:43:19 -04:00
|
|
|
std::string RsInitConfig::ssl_passphrase_file;
|
|
|
|
|
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::havePasswd; /* for Commandline password */
|
|
|
|
bool RsInitConfig::autoLogin; /* autoLogin allowed */
|
|
|
|
bool RsInitConfig::startMinimised; /* Icon or Full Window */
|
2009-02-08 09:30:28 -05:00
|
|
|
|
|
|
|
/* Win/Unix Differences */
|
2009-07-30 17:27:47 -04:00
|
|
|
char RsInitConfig::dirSeperator;
|
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;
|
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;
|
|
|
|
char RsInitConfig::logfname[1024];
|
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 */
|
|
|
|
static bool getAvailableAccounts(std::list<accountId> &ids);
|
|
|
|
static bool checkAccount(std::string accountdir, accountId &id);
|
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
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::dirSeperator = '/'; // For unix.
|
2007-11-14 22:18:48 -05:00
|
|
|
#else
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::dirSeperator = '\\'; // For windows.
|
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;
|
|
|
|
RsInitConfig::port = 7812; // default port.
|
|
|
|
RsInitConfig::forceLocalAddr = false;
|
|
|
|
RsInitConfig::haveLogFile = false;
|
|
|
|
RsInitConfig::outStderr = false;
|
|
|
|
RsInitConfig::forceExtPort = false;
|
|
|
|
|
|
|
|
strcpy(RsInitConfig::inet, "127.0.0.1");
|
|
|
|
strcpy(RsInitConfig::logfname, "");
|
|
|
|
|
|
|
|
RsInitConfig::autoLogin = true; // Always on now.
|
|
|
|
RsInitConfig::startMinimised = false;
|
|
|
|
RsInitConfig::passwd = "";
|
|
|
|
RsInitConfig::havePasswd = false;
|
|
|
|
RsInitConfig::haveDebugLevel = false;
|
|
|
|
RsInitConfig::debugLevel = PQL_WARNING;
|
|
|
|
RsInitConfig::udpListenerOnly = false;
|
|
|
|
|
|
|
|
RsInitConfig::/* setup the homePath (default save location) */
|
|
|
|
|
|
|
|
RsInitConfig::homePath = getHomePath();
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2008-06-14 09:22:39 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
2009-02-08 09:30:28 -05:00
|
|
|
int RsInit::InitRetroShare(int argc, char **argv)
|
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
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
/* THIS IS A HACK TO ALLOW WINDOWS TO ACCEPT COMMANDLINE ARGUMENTS */
|
|
|
|
|
|
|
|
const int MAX_ARGS = 32;
|
|
|
|
int i,j;
|
|
|
|
|
|
|
|
int argc;
|
|
|
|
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);)
|
|
|
|
{
|
|
|
|
/* find next space. */
|
|
|
|
for(;(j + 1 < cmdlen) && (dupline[j] != ' ');j++);
|
|
|
|
if (j + 1 < cmdlen)
|
|
|
|
{
|
|
|
|
dupline[j] = '\0';
|
|
|
|
argv[i++] = &(dupline[j+1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc = i;
|
|
|
|
for( i=0; i<argc; i++)
|
|
|
|
{
|
|
|
|
printf("%d: %s\n", i, argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 ******************/
|
|
|
|
|
|
|
|
int c;
|
2008-09-21 16:30:34 -04:00
|
|
|
/* getopt info: every availiable option is listet here. if it is followed by a ':' it
|
2008-04-24 04:41:07 -04:00
|
|
|
needs an argument. If it is followed by a '::' the argument is optional.
|
|
|
|
*/
|
2008-06-14 09:22:39 -04:00
|
|
|
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:")) != -1)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'a':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::autoLogin = true;
|
|
|
|
RsInitConfig::startMinimised = true;
|
2008-06-14 09:22:39 -04:00
|
|
|
std::cerr << "AutoLogin Allowed / Start Minimised On";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'm':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::startMinimised = true;
|
2008-06-14 09:22:39 -04:00
|
|
|
std::cerr << "Start Minimised On";
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2009-07-30 17:27:47 -04:00
|
|
|
strncpy(RsInitConfig::logfname, optarg, 1024);
|
|
|
|
std::cerr << "LogFile (" << RsInitConfig::logfname;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::haveLogFile = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'w':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::passwd = optarg;
|
|
|
|
std::cerr << "Password Specified(" << RsInitConfig::passwd;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::havePasswd = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'i':
|
2009-07-30 17:27:47 -04:00
|
|
|
strncpy(RsInitConfig::inet, optarg, 256);
|
|
|
|
std::cerr << "New Inet Addr(" << RsInitConfig::inet;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::forceLocalAddr = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'p':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::port = atoi(optarg);
|
|
|
|
std::cerr << "New Listening Port(" << RsInitConfig::port;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 'c':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::basedir = optarg;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "New Base Config Dir(";
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << RsInitConfig::basedir;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 's':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::outStderr = true;
|
|
|
|
RsInitConfig::haveLogFile = false;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "Output to Stderr";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::haveDebugLevel = true;
|
|
|
|
RsInitConfig::debugLevel = atoi(optarg);
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "Opt for new Debug Level";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'u':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::udpListenerOnly = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "Opt for only udpListener";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2008-03-21 15:06:34 -04:00
|
|
|
case 'e':
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::forceExtPort = true;
|
2008-03-21 15:06:34 -04:00
|
|
|
std::cerr << "Opt for External Port Mode";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
2008-04-24 04:41:07 -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;
|
2008-06-14 09:22:39 -04:00
|
|
|
std::cerr << "-a AutoLogin (Windows Only) + StartMinimised" << std::endl;
|
|
|
|
std::cerr << "-m StartMinimised" << std::endl;
|
2008-04-24 04:41:07 -04:00
|
|
|
std::cerr << "-u Only listen to UDP" << std::endl;
|
|
|
|
std::cerr << "-e Use a forwarded external Port" << std::endl << std::endl;
|
|
|
|
std::cerr << "Example" << std::endl;
|
|
|
|
std::cerr << "./retroshare-nogui -wmysecretpassword -e" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
break;
|
2007-11-14 22:18:48 -05:00
|
|
|
default:
|
2008-04-24 04:41:07 -04:00
|
|
|
std::cerr << "Unknown Option!" << std::endl;
|
|
|
|
std::cerr << "Use '-h' for help." << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
setDebugFile(RsInitConfig::logfname);
|
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-01-13 15:58:58 -05:00
|
|
|
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL);
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
// first check config directories, and set bootstrap values.
|
|
|
|
setupBaseDir();
|
|
|
|
get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId);
|
|
|
|
//std::list<accountId> ids;
|
|
|
|
std::list<accountId>::iterator it;
|
|
|
|
getAvailableAccounts(RsInitConfig::accountIds);
|
|
|
|
|
|
|
|
/* 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;
|
2010-01-18 17:44:09 -05:00
|
|
|
userName = it->pgpName;
|
2009-07-30 17:27:47 -04:00
|
|
|
existingUser = true;
|
|
|
|
}
|
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 == "";
|
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)
|
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::havePasswd)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsTryAutoLogin())
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************** Access Functions for Init Data **************************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
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;
|
|
|
|
std::cerr << "getAccountIds:" << std::endl;
|
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
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "SSL Id: " << it->sslId << " PGP Id " << it->pgpId <<
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
void RsInit::setupBaseDir()
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
RsInitConfig::basedir = h;
|
|
|
|
RsInitConfig::basedir += "/.retroshare";
|
|
|
|
#else
|
|
|
|
char *h = getenv("APPDATA");
|
|
|
|
std::cerr << "retroShare::basedir() -> $APPDATA = ";
|
|
|
|
std::cerr << h << std::endl;
|
|
|
|
char *h2 = getenv("HOMEDRIVE");
|
|
|
|
std::cerr << "retroShare::basedir() -> $HOMEDRIVE = ";
|
|
|
|
std::cerr << h2 << std::endl;
|
|
|
|
char *h3 = getenv("HOMEPATH");
|
|
|
|
std::cerr << "retroShare::basedir() -> $HOMEPATH = ";
|
|
|
|
std::cerr << h3 << std::endl;
|
|
|
|
if (h == NULL)
|
|
|
|
{
|
|
|
|
// generating default
|
|
|
|
std::cerr << "load_check_basedir() getEnv Error --Win95/98?";
|
|
|
|
std::cerr << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::basedir="C:\\Retro";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RsInitConfig::basedir = h;
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (!RsDirUtil::checkCreateDirectory(RsInitConfig::basedir))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create BaseConfig Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-07-31 09:11:33 -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;
|
2007-11-14 22:18:48 -05:00
|
|
|
exit(1);
|
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* directories with valid certificates in the expected location */
|
|
|
|
bool getAvailableAccounts(std::list<accountId> &ids)
|
|
|
|
{
|
|
|
|
/* get the directories */
|
|
|
|
std::list<std::string> directories;
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
|
|
|
|
std::cerr << "getAvailableAccounts()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* now iterate through the directory...
|
|
|
|
* directories - flags as old,
|
|
|
|
* files checked to see if they have changed. (rehashed)
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct dirent *dent;
|
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
/* check for the dir existance */
|
|
|
|
DIR *dir = opendir(RsInitConfig::basedir.c_str());
|
|
|
|
if (!dir)
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl;
|
|
|
|
exit(1);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
while(NULL != (dent = readdir(dir)))
|
|
|
|
{
|
|
|
|
/* check entry type */
|
|
|
|
std::string fname = dent -> d_name;
|
|
|
|
std::string fullname = RsInitConfig::basedir + "/" + fname;
|
|
|
|
|
|
|
|
if (-1 != stat(fullname.c_str(), &buf))
|
|
|
|
{
|
|
|
|
#ifdef FIM_DEBUG
|
|
|
|
std::cerr << "buf.st_mode: " << buf.st_mode <<std::endl;
|
|
|
|
#endif
|
|
|
|
if (S_ISDIR(buf.st_mode))
|
|
|
|
{
|
|
|
|
if ((fname == ".") || (fname == ".."))
|
|
|
|
{
|
|
|
|
#ifdef FIM_DEBUG
|
|
|
|
std::cerr << "Skipping:" << fname << std::endl;
|
|
|
|
#endif
|
|
|
|
continue; /* skipping links */
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef FIM_DEBUG
|
|
|
|
std::cerr << "Is Directory: " << fullname << std::endl;
|
|
|
|
#endif
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2009-07-30 17:27:47 -04: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
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
for(it = directories.begin(); it != directories.end(); it++)
|
|
|
|
{
|
|
|
|
std::string accountdir = RsInitConfig::basedir + RsInitConfig::dirSeperator + *it;
|
|
|
|
std::cerr << "getAvailableAccounts() Checking: " << *it;
|
|
|
|
std::cerr << std::endl;
|
2008-02-05 08:45:04 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
accountId tmpId;
|
|
|
|
if (checkAccount(accountdir, tmpId))
|
|
|
|
{
|
|
|
|
std::cerr << "getAvailableAccounts() Accepted: " << *it;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
ids.push_back(tmpId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string subdir1 = accountdir + RsInitConfig::dirSeperator;
|
|
|
|
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.
|
|
|
|
std::string basename = accountdir + RsInitConfig::dirSeperator;
|
|
|
|
basename += configKeyDir + RsInitConfig::dirSeperator;
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::cerr << "checkAccount() dir: " << accountdir << std::endl;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
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 */
|
2010-01-18 17:44:09 -05:00
|
|
|
LoadCheckX509andGetLocation(cert_name.c_str(), id.location, id.sslId);
|
|
|
|
std::cerr << "location: " << id.location << " id: " << id.sslId << std::endl;
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string tmpid;
|
|
|
|
if (LoadCheckX509andGetIssuerName(cert_name.c_str(), id.pgpId, tmpid))
|
|
|
|
{
|
|
|
|
std::cerr << "issuerName: " << id.pgpId << " id: " << tmpid << std::endl;
|
|
|
|
RsInit::GetPGPLoginDetails(id.pgpId, id.pgpName, id.pgpEmail);
|
|
|
|
std::cerr << "PGPLoginDetails: " << id.pgpId << " name: " << id.pgpName;
|
|
|
|
std::cerr << " email: " << id.pgpEmail << std::endl;
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
int RsInit::GetPGPLoginDetails(std::string id, std::string &name, std::string &email)
|
|
|
|
{
|
2010-01-13 15:56:55 -05:00
|
|
|
std::cerr << "RsInit::GetPGPLoginDetails for \"" << id << "\"";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
name = AuthGPG::getAuthGPG()->getGPGName(id);
|
|
|
|
email = AuthGPG::getAuthGPG()->getGPGEmail(id);
|
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
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::SelectGPGAccount(std::string id)
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
std::string gpgId = id;
|
|
|
|
std::string name = id;
|
2008-04-03 10:34:52 -04:00
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
if (0 < AuthGPG::getAuthGPG() -> GPGInit(gpgId))
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
std::cerr << "PGP Auth Success!";
|
|
|
|
std::cerr << "ID: " << id << " NAME: " << name;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "PGP Auth Failed!";
|
|
|
|
std::cerr << "ID: " << id << " NAME: " << name;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2010-01-13 16:06:53 -05:00
|
|
|
//bool RsInit::LoadGPGPassword(std::string inPGPpasswd)
|
|
|
|
//{
|
|
|
|
//
|
|
|
|
// bool ok = false;
|
|
|
|
// if (0 < AuthGPG::getAuthGPG() -> LoadGPGPassword(inPGPpasswd))
|
|
|
|
// {
|
|
|
|
// ok = true;
|
|
|
|
// std::cerr << "PGP LoadPwd Success!";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// std::cerr << "PGP LoadPwd Failed!";
|
|
|
|
// std::cerr << std::endl;
|
|
|
|
// }
|
|
|
|
// return ok;
|
|
|
|
//}
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
|
2010-01-18 07:30:54 -05:00
|
|
|
bool RsInit::GeneratePGPCertificate(std::string name, std::string email, std::string passwd, std::string &pgpId, std::string &errString) {
|
2010-01-26 15:41:55 -05:00
|
|
|
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 */
|
2010-01-18 07:30:54 -05:00
|
|
|
bool RsInit::GenerateSSLCertificate(std::string gpg_id, std::string org, std::string loc, std::string country, 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
|
|
|
|
2010-01-18 07:30:54 -05:00
|
|
|
std::string name = AuthGPG::getAuthGPG()->getGPGName(gpg_id);
|
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string tmpbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + tmpdir + RsInitConfig::dirSeperator;
|
|
|
|
RsInit::setupAccount(tmpbase);
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string basename = tmpbase + configKeyDir + RsInitConfig::dirSeperator;
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
long days = 3000;
|
2010-01-13 15:58:58 -05:00
|
|
|
X509 *x509 = AuthSSL::getAuthSSL()->SignX509Req(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! */
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Print it out */
|
|
|
|
int nmflag = 0;
|
|
|
|
int reqflag = 0;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
X509_print_ex(bio_out, x509, nmflag, reqflag);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -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
|
|
|
|
{
|
|
|
|
gen_ok = false;
|
|
|
|
}
|
2008-07-02 12:58:13 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (gen_ok)
|
|
|
|
{
|
|
|
|
/* Save cert to file */
|
|
|
|
// open the file.
|
|
|
|
FILE *out = NULL;
|
|
|
|
if (NULL == (out = fopen(cert_name.c_str(), "w")))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't create Cert File");
|
|
|
|
fprintf(stderr," : %s\n", cert_name.c_str());
|
|
|
|
gen_ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PEM_write_X509(out,x509))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"RsGenerateCert() Couldn't Save Cert");
|
|
|
|
fprintf(stderr," : %s\n", cert_name.c_str());
|
|
|
|
gen_ok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(out);
|
|
|
|
X509_free(x509);
|
|
|
|
}
|
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
|
|
|
|
2010-01-18 17:44:09 -05:00
|
|
|
std::string location;
|
2010-01-27 17:31:25 -05:00
|
|
|
if (LoadCheckX509andGetLocation(cert_name.c_str(), location, sslId) == 0) {
|
|
|
|
std::cerr << "RsInit::GenerateSSLCertificate() Cannot check own signature, maybe the files are corrupted." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move directory to correct id */
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string finalbase = RsInitConfig::basedir + RsInitConfig::dirSeperator + sslId + RsInitConfig::dirSeperator;
|
|
|
|
/* 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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (0 > rename(tmpbase.c_str(), finalbase.c_str()))
|
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 **************/
|
|
|
|
bool RsInit::setupAccount(std::string accountdir)
|
|
|
|
{
|
|
|
|
/* actual config directory isd */
|
|
|
|
|
|
|
|
std::string subdir1 = accountdir + RsInitConfig::dirSeperator;
|
|
|
|
std::string subdir2 = subdir1;
|
|
|
|
subdir1 += configKeyDir;
|
|
|
|
subdir2 += configCertDir;
|
|
|
|
|
|
|
|
std::string subdir3 = accountdir + RsInitConfig::dirSeperator;
|
|
|
|
subdir3 += "cache";
|
|
|
|
|
|
|
|
std::string subdir4 = subdir3 + RsInitConfig::dirSeperator;
|
|
|
|
std::string subdir5 = subdir3 + RsInitConfig::dirSeperator;
|
|
|
|
subdir4 += "local";
|
|
|
|
subdir5 += "remote";
|
|
|
|
|
|
|
|
// fatal if cannot find/create.
|
|
|
|
std::cerr << "Checking For Directories" << std::endl;
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(accountdir))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create BaseConfig Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir1))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Key Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir2))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cert Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir3))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir4))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache/local Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (!RsDirUtil::checkCreateDirectory(subdir5))
|
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create Config/Cache/remote Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************** FINAL LOADING OF SETUP *************************/
|
|
|
|
/* Login SSL */
|
|
|
|
bool RsInit::LoadPassword(std::string id, std::string inPwd)
|
|
|
|
{
|
|
|
|
/* select configDir */
|
|
|
|
|
|
|
|
RsInitConfig::preferedId = id;
|
|
|
|
RsInitConfig::configDir = RsInitConfig::basedir + RsInitConfig::dirSeperator + id;
|
|
|
|
RsInitConfig::passwd = inPwd;
|
|
|
|
RsInitConfig::havePasswd = true;
|
|
|
|
|
|
|
|
// Create the filename.
|
|
|
|
std::string basename = RsInitConfig::configDir + RsInitConfig::dirSeperator;
|
|
|
|
basename += configKeyDir + RsInitConfig::dirSeperator;
|
2009-08-18 08:43:19 -04:00
|
|
|
RsInitConfig::ssl_passphrase_file = basename + "ssl_passphrase.pgp";
|
|
|
|
basename += "user";
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
RsInitConfig::load_key = basename + "_pk.pem";
|
|
|
|
RsInitConfig::load_cert = basename + "_cert.pem";
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***************************** FINAL LOADING OF SETUP *************************
|
|
|
|
* Requires:
|
|
|
|
* PGPid to be selected (Password not required).
|
|
|
|
* CertId to be selected (Password Required).
|
|
|
|
*/
|
|
|
|
|
|
|
|
int RsInit::LoadCertificates(bool autoLoginNT)
|
|
|
|
{
|
|
|
|
if (RsInitConfig::load_cert == "")
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare needs a certificate" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (RsInitConfig::load_key == "")
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare needs a key" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
/* The SSL / SSL + PGP version requires, SSL init + PGP init. */
|
2009-08-18 08:43:19 -04:00
|
|
|
const char* sslPassword;
|
|
|
|
sslPassword = RsInitConfig::passwd.c_str();
|
|
|
|
//check if password is already in memory
|
|
|
|
if ((RsInitConfig::havePasswd) && (RsInitConfig::passwd != ""))
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare have a ssl Password" << std::endl;
|
|
|
|
sslPassword = RsInitConfig::passwd.c_str();
|
|
|
|
|
|
|
|
std::cerr << "let's store the ssl Password into a pgp ecrypted file" << std::endl;
|
|
|
|
FILE *sslPassphraseFile = fopen(RsInitConfig::ssl_passphrase_file.c_str(), "w");
|
2009-10-29 20:46:58 -04:00
|
|
|
std::cerr << "opening sslPassphraseFile : " << RsInitConfig::ssl_passphrase_file.c_str() << std::endl;
|
2009-08-18 08:43:19 -04:00
|
|
|
gpgme_data_t cipher;
|
|
|
|
gpgme_data_t plain;
|
2009-10-29 20:46:58 -04:00
|
|
|
gpgme_data_new_from_mem(&plain, sslPassword, strlen(sslPassword), 1);
|
|
|
|
gpgme_data_new_from_stream (&cipher, sslPassphraseFile);
|
2010-01-13 15:58:58 -05:00
|
|
|
if (0 < AuthGPG::getAuthGPG()->encryptText(plain, cipher)) {
|
2009-08-18 08:43:19 -04:00
|
|
|
std::cerr << "Encrypting went ok !" << std::endl;
|
2010-01-24 17:20:13 -05:00
|
|
|
} else {
|
|
|
|
std::cerr << "Encrypting went wrong !" << std::endl;
|
|
|
|
}
|
2009-10-27 16:45:58 -04:00
|
|
|
gpgme_data_release (cipher);
|
2009-08-18 08:43:19 -04:00
|
|
|
gpgme_data_release (plain);
|
|
|
|
fclose(sslPassphraseFile);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//let's read the password from an encrypted file
|
|
|
|
//let's check if there's a ssl_passpharese_file that we can decrypt with PGP
|
|
|
|
FILE *sslPassphraseFile = fopen(RsInitConfig::ssl_passphrase_file.c_str(), "r");
|
|
|
|
if (sslPassphraseFile == NULL)
|
|
|
|
{
|
2009-10-29 20:46:58 -04:00
|
|
|
std::cerr << "No password povided, and no sslPassphraseFile : " << RsInitConfig::ssl_passphrase_file.c_str() << std::endl;
|
2009-08-18 08:43:19 -04:00
|
|
|
return 0;
|
|
|
|
} else {
|
2009-10-29 20:46:58 -04:00
|
|
|
std::cerr << "opening sslPassphraseFile : " << RsInitConfig::ssl_passphrase_file.c_str() << std::endl;
|
2009-08-18 08:43:19 -04:00
|
|
|
gpgme_data_t cipher;
|
|
|
|
gpgme_data_t plain;
|
|
|
|
gpgme_data_new (&plain);
|
|
|
|
gpgme_error_t error_reading_file = gpgme_data_new_from_stream (&cipher, sslPassphraseFile);
|
2010-01-13 15:58:58 -05:00
|
|
|
if (0 < AuthGPG::getAuthGPG()->decryptText(cipher, plain)) {
|
2009-08-18 08:43:19 -04:00
|
|
|
std::cerr << "Decrypting went ok !" << std::endl;
|
2009-10-27 16:39:14 -04:00
|
|
|
gpgme_data_write (plain, "", 1);
|
2009-08-18 08:43:19 -04:00
|
|
|
sslPassword = gpgme_data_release_and_get_mem(plain, NULL);
|
|
|
|
} else {
|
|
|
|
gpgme_data_release (plain);
|
2009-10-27 16:39:14 -04:00
|
|
|
std::cerr << "Error : decrypting went wrong !" << std::endl;
|
2009-08-18 08:44:32 -04:00
|
|
|
return 0;
|
2009-08-18 08:43:19 -04:00
|
|
|
}
|
|
|
|
gpgme_data_release (cipher);
|
|
|
|
fclose(sslPassphraseFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "RsInitConfig::load_key.c_str() : " << RsInitConfig::load_key.c_str() << std::endl;
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "sslPassword : " << sslPassword << std::endl;;
|
2010-01-13 15:58:58 -05:00
|
|
|
if (0 < AuthSSL::getAuthSSL() -> InitAuth(RsInitConfig::load_cert.c_str(), RsInitConfig::load_key.c_str(), sslPassword))
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "SSL Auth Failed!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-05-23 11:07:35 -04:00
|
|
|
if (ok)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
if (autoLoginNT)
|
|
|
|
{
|
|
|
|
std::cerr << "RetroShare will AutoLogin next time";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
RsStoreAutoLogin();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
/* wipe password */
|
2009-07-30 17:27:47 -04:00
|
|
|
RsInitConfig::passwd = "";
|
|
|
|
create_configinit(RsInitConfig::basedir, RsInitConfig::preferedId);
|
2007-11-14 22:18:48 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "RetroShare Failed To Start!" << std::endl;
|
|
|
|
std::cerr << "Please Check File Names/Password" << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::get_configinit(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.
|
|
|
|
std::string initfile = dir + RsInitConfig::dirSeperator;
|
|
|
|
initfile += configInitFile;
|
|
|
|
|
|
|
|
// open and read in the lines.
|
|
|
|
FILE *ifd = fopen(initfile.c_str(), "r");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
bool RsInit::create_configinit(std::string dir, std::string id)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
// Check for config file.
|
|
|
|
std::string initfile = dir + RsInitConfig::dirSeperator;
|
|
|
|
initfile += configInitFile;
|
2008-11-09 11:52:14 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// open and read in the lines.
|
|
|
|
FILE *ifd = fopen(initfile.c_str(), "w");
|
|
|
|
|
|
|
|
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-31 09:11:33 -04:00
|
|
|
std::string make_path_unix(std::string path);
|
|
|
|
|
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.
|
|
|
|
home = make_path_unix(home);
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
return home;
|
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string make_path_unix(std::string path)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < path.length(); i++)
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
if (path[i] == '\\')
|
|
|
|
path[i] = '/';
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
2009-07-30 17:27:47 -04:00
|
|
|
return path;
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
/* WINDOWS STRUCTURES FOR DPAPI */
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
#else
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#include <windows.h>
|
|
|
|
#include <wincrypt.h>
|
|
|
|
#include <iomanip>
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/*
|
|
|
|
class CRYPTPROTECT_PROMPTSTRUCT;
|
|
|
|
*/
|
2009-07-12 12:11:09 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WINDOWS_SYS
|
2009-07-31 09:11:33 -04:00
|
|
|
#if defined(__CYGWIN__)
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
|
|
|
|
DWORD cbSize;
|
|
|
|
DWORD dwPromptFlags;
|
|
|
|
HWND hwndApp;
|
|
|
|
LPCWSTR szPrompt;
|
|
|
|
} CRYPTPROTECT_PROMPTSTRUCT,
|
|
|
|
*PCRYPTPROTECT_PROMPTSTRUCT;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* definitions for the two functions */
|
|
|
|
__declspec (dllimport)
|
|
|
|
extern BOOL WINAPI CryptProtectData(
|
|
|
|
DATA_BLOB* pDataIn,
|
|
|
|
LPCWSTR szDataDescr,
|
|
|
|
DATA_BLOB* pOptionalEntropy,
|
|
|
|
PVOID pvReserved,
|
|
|
|
/* PVOID prompt, */
|
|
|
|
/* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */
|
|
|
|
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
|
|
|
|
DWORD dwFlags,
|
|
|
|
DATA_BLOB* pDataOut
|
|
|
|
);
|
|
|
|
|
|
|
|
__declspec (dllimport)
|
|
|
|
extern BOOL WINAPI CryptUnprotectData(
|
|
|
|
DATA_BLOB* pDataIn,
|
|
|
|
LPWSTR* ppszDataDescr,
|
|
|
|
DATA_BLOB* pOptionalEntropy,
|
|
|
|
PVOID pvReserved,
|
|
|
|
/* PVOID prompt, */
|
|
|
|
/* CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, */
|
|
|
|
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
|
|
|
|
DWORD dwFlags,
|
|
|
|
DATA_BLOB* pDataOut
|
|
|
|
);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RsInit::RsStoreAutoLogin()
|
|
|
|
{
|
|
|
|
std::cerr << "RsStoreAutoLogin()" << std::endl;
|
|
|
|
/* Windows only */
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
/* store password encrypted in a file */
|
2009-07-31 09:11:33 -04:00
|
|
|
std::string entropy = RsInitConfig::load_cert;
|
2009-07-30 17:27:47 -04:00
|
|
|
|
|
|
|
DATA_BLOB DataIn;
|
|
|
|
DATA_BLOB DataEnt;
|
|
|
|
DATA_BLOB DataOut;
|
2009-07-31 09:11:33 -04:00
|
|
|
BYTE *pbDataInput = (BYTE *) strdup(RsInitConfig::passwd.c_str());
|
2009-07-30 17:27:47 -04:00
|
|
|
DWORD cbDataInput = strlen((char *)pbDataInput)+1;
|
|
|
|
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
|
|
|
|
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
|
|
|
|
DataIn.pbData = pbDataInput;
|
|
|
|
DataIn.cbData = cbDataInput;
|
|
|
|
DataEnt.pbData = pbDataEnt;
|
|
|
|
DataEnt.cbData = cbDataEnt;
|
|
|
|
LPWSTR pDescrOut = NULL;
|
|
|
|
|
|
|
|
CRYPTPROTECT_PROMPTSTRUCT prom;
|
|
|
|
|
|
|
|
prom.cbSize = sizeof(prom);
|
|
|
|
prom.dwPromptFlags = 0;
|
|
|
|
|
|
|
|
/*********
|
|
|
|
std::cerr << "Password (" << cbDataInput << "):";
|
|
|
|
std::cerr << pbDataInput << std::endl;
|
|
|
|
std::cerr << "Entropy (" << cbDataEnt << "):";
|
|
|
|
std::cerr << pbDataEnt << std::endl;
|
|
|
|
*********/
|
|
|
|
|
|
|
|
if(CryptProtectData(
|
|
|
|
&DataIn,
|
|
|
|
NULL,
|
|
|
|
&DataEnt, /* entropy.c_str(), */
|
|
|
|
NULL, // Reserved.
|
|
|
|
&prom,
|
|
|
|
0,
|
|
|
|
&DataOut))
|
2009-05-23 11:07:35 -04:00
|
|
|
{
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**********
|
|
|
|
std::cerr << "The encryption phase worked. (";
|
|
|
|
std::cerr << DataOut.cbData << ")" << std::endl;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
for(unsigned int i = 0; i < DataOut.cbData; i++)
|
|
|
|
{
|
|
|
|
std::cerr << std::setw(2) << (int) DataOut.pbData[i];
|
|
|
|
std::cerr << " ";
|
|
|
|
}
|
|
|
|
std::cerr << std::endl;
|
|
|
|
**********/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* save the data to the file */
|
|
|
|
std::string passwdfile = RsInitConfig::configDir;
|
|
|
|
passwdfile += RsInitConfig::dirSeperator;
|
|
|
|
passwdfile += "help.dta";
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
//std::cerr << "Save to: " << passwdfile;
|
|
|
|
//std::cerr << std::endl;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
FILE *fp = fopen(passwdfile.c_str(), "wb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fwrite(DataOut.pbData, 1, DataOut.cbData, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
std::cerr << "AutoLogin Data saved: ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
}
|
|
|
|
else
|
2009-07-30 17:27:47 -04:00
|
|
|
{
|
|
|
|
std::cerr << "Encryption Failed";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
free(pbDataInput);
|
|
|
|
free(pbDataEnt);
|
|
|
|
LocalFree(DataOut.pbData);
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool RsInit::RsTryAutoLogin()
|
|
|
|
{
|
|
|
|
std::cerr << "RsTryAutoLogin()" << std::endl;
|
|
|
|
/* Windows only */
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
/* Require a AutoLogin flag in the config to do this */
|
2009-07-31 09:11:33 -04:00
|
|
|
if (!RsInitConfig::autoLogin)
|
2009-07-12 12:11:09 -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
|
|
|
/* try to load from file */
|
2009-07-31 09:11:33 -04:00
|
|
|
std::string entropy = RsInitConfig::load_cert;
|
2009-07-30 17:27:47 -04:00
|
|
|
/* get the data out */
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* open the data to the file */
|
|
|
|
std::string passwdfile = RsInitConfig::configDir;
|
|
|
|
passwdfile += RsInitConfig::dirSeperator;
|
|
|
|
passwdfile += "help.dta";
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
DATA_BLOB DataIn;
|
|
|
|
DATA_BLOB DataEnt;
|
|
|
|
DATA_BLOB DataOut;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
|
|
|
|
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
|
|
|
|
DataEnt.pbData = pbDataEnt;
|
|
|
|
DataEnt.cbData = cbDataEnt;
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
char *dataptr = NULL;
|
|
|
|
int datalen = 0;
|
|
|
|
|
|
|
|
FILE *fp = fopen(passwdfile.c_str(), "rb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
datalen = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
dataptr = (char *) malloc(datalen);
|
|
|
|
fread(dataptr, 1, datalen, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
/*****
|
|
|
|
std::cerr << "Data loaded from: " << passwdfile;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
std::cerr << "Size :";
|
|
|
|
std::cerr << datalen << std::endl;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < datalen; i++)
|
|
|
|
{
|
|
|
|
std::cerr << std::setw(2) << (int) dataptr[i];
|
|
|
|
std::cerr << " ";
|
|
|
|
}
|
|
|
|
std::cerr << std::endl;
|
|
|
|
*****/
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BYTE *pbDataInput =(BYTE *) dataptr;
|
|
|
|
DWORD cbDataInput = datalen;
|
|
|
|
DataIn.pbData = pbDataInput;
|
|
|
|
DataIn.cbData = cbDataInput;
|
|
|
|
|
|
|
|
|
|
|
|
CRYPTPROTECT_PROMPTSTRUCT prom;
|
|
|
|
|
|
|
|
prom.cbSize = sizeof(prom);
|
|
|
|
prom.dwPromptFlags = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bool isDecrypt = CryptUnprotectData(
|
|
|
|
&DataIn,
|
|
|
|
NULL,
|
|
|
|
&DataEnt, /* entropy.c_str(), */
|
|
|
|
NULL, // Reserved
|
|
|
|
&prom, // Opt. Prompt
|
|
|
|
0,
|
|
|
|
&DataOut);
|
|
|
|
|
|
|
|
if (isDecrypt)
|
|
|
|
{
|
|
|
|
//std::cerr << "Decrypted size: " << DataOut.cbData;
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
if (DataOut.pbData[DataOut.cbData - 1] != '\0')
|
|
|
|
{
|
|
|
|
std::cerr << "Error: Decrypted Data not a string...";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
isDecrypt = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//std::cerr << "The decrypted data is: " << DataOut.pbData;
|
|
|
|
//std::cerr << std::endl;
|
2009-07-31 09:11:33 -04:00
|
|
|
RsInitConfig::passwd = (char *) DataOut.pbData;
|
|
|
|
RsInitConfig::havePasswd = true;
|
2009-07-30 17:27:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Decryption error!";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* strings to be freed */
|
|
|
|
free(pbDataInput);
|
|
|
|
free(pbDataEnt);
|
|
|
|
|
|
|
|
/* generated data space */
|
|
|
|
LocalFree(DataOut.pbData);
|
|
|
|
|
|
|
|
return isDecrypt;
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RsInit::RsClearAutoLogin()
|
|
|
|
{
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
std::string passwdfile = RsInitConfig::configDir;
|
|
|
|
passwdfile += RsInitConfig::dirSeperator;
|
|
|
|
passwdfile += "help.dta";
|
|
|
|
|
|
|
|
FILE *fp = fopen(passwdfile.c_str(), "wb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fwrite(" ", 1, 1, fp);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
std::cerr << "AutoLogin Data cleared! ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string RsInit::RsConfigDirectory()
|
|
|
|
{
|
|
|
|
return RsInitConfig::basedir;
|
|
|
|
}
|
|
|
|
|
2010-01-27 17:31:25 -05:00
|
|
|
std::string RsInit::RsProfileConfigDirectory()
|
|
|
|
{
|
|
|
|
std::string dir = RsInitConfig::basedir + RsInitConfig::dirSeperator + RsInitConfig::preferedId;
|
|
|
|
std::cerr << "RsInit::RsProfileConfigDirectory() returning : " << dir << std::endl;
|
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
bool RsInit::setStartMinimised()
|
|
|
|
{
|
|
|
|
return RsInitConfig::startMinimised;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
|
|
|
#include "rsiface/rsiface.h"
|
|
|
|
#include "rsiface/rsturtle.h"
|
|
|
|
|
|
|
|
/* global variable now points straight to
|
|
|
|
* ft/ code so variable defined here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
RsControl *rsicontrol = NULL;
|
|
|
|
RsFiles *rsFiles = NULL;
|
|
|
|
RsTurtle *rsTurtle = NULL ;
|
|
|
|
|
|
|
|
#include "pqi/pqipersongrp.h"
|
|
|
|
#include "pqi/pqisslpersongrp.h"
|
|
|
|
#include "pqi/pqiloopback.h"
|
|
|
|
#include "pqi/p3cfgmgr.h"
|
|
|
|
|
|
|
|
#include "util/rsdebug.h"
|
|
|
|
#include "util/rsdir.h"
|
|
|
|
|
|
|
|
#include "upnp/upnphandler.h"
|
|
|
|
#include "dht/opendhtmgr.h"
|
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/p3ranking.h"
|
|
|
|
#include "services/p3photoservice.h"
|
|
|
|
#include "services/p3forums.h"
|
|
|
|
#include "services/p3channels.h"
|
|
|
|
#include "services/p3status.h"
|
|
|
|
#include "services/p3Qblog.h"
|
|
|
|
#include "turtle/p3turtle.h"
|
2009-12-13 16:59:26 -05:00
|
|
|
#include "services/p3tunnel.h"
|
2009-05-23 11:07:35 -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/p3rank.h"
|
|
|
|
#include "rsserver/p3msgs.h"
|
|
|
|
#include "rsserver/p3discovery.h"
|
|
|
|
#include "rsserver/p3photo.h"
|
|
|
|
#include "rsserver/p3Blog.h"
|
|
|
|
#include "rsiface/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
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/****
|
|
|
|
#define RS_RELEASE 1
|
|
|
|
****/
|
2009-05-23 11:07:35 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#define RS_RELEASE 1
|
2009-05-23 11:07:35 -04:00
|
|
|
|
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;
|
|
|
|
exit(1);
|
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
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
std::string crashfile = RsInitConfig::basedir + RsInitConfig::dirSeperator;
|
|
|
|
crashfile += configLogFileName;
|
|
|
|
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 certConfigFile = RsInitConfig::configDir.c_str();
|
|
|
|
std::string certNeighDir = RsInitConfig::configDir.c_str();
|
|
|
|
std::string emergencySaveDir = RsInitConfig::configDir.c_str();
|
|
|
|
std::string emergencyPartialsDir = RsInitConfig::configDir.c_str();
|
|
|
|
if (certConfigFile != "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-07-30 17:27:47 -04:00
|
|
|
certConfigFile += "/";
|
|
|
|
certNeighDir += "/";
|
|
|
|
emergencySaveDir += "/";
|
|
|
|
emergencyPartialsDir += "/";
|
|
|
|
}
|
|
|
|
certConfigFile += configConfFile;
|
|
|
|
certNeighDir += configCertDir;
|
|
|
|
emergencySaveDir += "Downloads";
|
|
|
|
emergencyPartialsDir += "Partials";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* if we've loaded an old format file! */
|
|
|
|
bool oldFormat = false;
|
|
|
|
std::map<std::string, std::string> oldConfigMap;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-13 15:58:58 -05:00
|
|
|
AuthSSL::getAuthSSL() -> setConfigDirectories(certConfigFile, certNeighDir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-13 16:22:52 -05:00
|
|
|
//AuthSSL::getAuthSSL() -> loadCertificates();
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Setup Notify Early - So we can use it. */
|
|
|
|
rsNotify = new p3Notify();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
mConnMgr = new p3ConnectMgr();
|
2010-01-13 16:16:56 -05:00
|
|
|
AuthSSL::getAuthSSL()->mConnMgr = mConnMgr;
|
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-07-30 17:27:47 -04:00
|
|
|
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
2009-12-14 13:10:49 -05:00
|
|
|
//p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInitConfig::configDir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
SecurityPolicy *none = secpolicy_create();
|
|
|
|
pqih = new pqisslpersongrp(none, flags);
|
|
|
|
//pqih = new pqipersongrpDummy(none, flags);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/****** New Ft Server **** !!! */
|
2010-01-13 15:56:55 -05:00
|
|
|
ftserver = new ftServer(mConnMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->setP3Interface(pqih);
|
|
|
|
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();
|
|
|
|
|
|
|
|
/* setup any extra bits (Default Paths) */
|
|
|
|
ftserver->setPartialsDirectory(emergencyPartialsDir);
|
|
|
|
ftserver->setDownloadDirectory(emergencySaveDir);
|
|
|
|
|
|
|
|
/* This should be set by config ... there is no default */
|
|
|
|
//ftserver->setSharedDirectories(fileList);
|
|
|
|
rsFiles = ftserver;
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2010-01-13 15:56:55 -05: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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* create Services */
|
2010-01-13 15:56:55 -05:00
|
|
|
ad = new p3disc(mConnMgr, pqih);
|
2009-07-30 17:27:47 -04:00
|
|
|
msgSrv = new p3MsgService(mConnMgr);
|
|
|
|
chatSrv = new p3ChatService(mConnMgr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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);
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
p3turtle *tr = new p3turtle(mConnMgr,ftserver) ;
|
|
|
|
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);
|
|
|
|
pqih -> addService(msgSrv);
|
|
|
|
pqih -> addService(chatSrv);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -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";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
//mRanking = NULL;
|
|
|
|
mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */
|
|
|
|
mCacheStrapper, mCacheTransfer,
|
|
|
|
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp); /* end of declaration */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
|
|
|
|
mCacheStrapper, mCacheTransfer,
|
2010-01-13 15:56:55 -05:00
|
|
|
localcachedir, remotecachedir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
CachePair cp4(mForums, mForums, CacheId(RS_SERVICE_TYPE_FORUM, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp4);
|
|
|
|
pqih -> addService(mForums); /* This must be also ticked as a service */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL,
|
|
|
|
mCacheStrapper, mCacheTransfer, rsFiles,
|
2010-01-13 15:56:55 -05:00
|
|
|
localcachedir, remotecachedir, channelsdir);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
CachePair cp5(mChannels, mChannels, CacheId(RS_SERVICE_TYPE_CHANNEL, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp5);
|
|
|
|
pqih -> addService(mChannels); /* This must be also ticked as a service */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#ifndef RS_RELEASE
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */
|
|
|
|
mCacheStrapper, mCacheTransfer,
|
|
|
|
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp3);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
#else
|
|
|
|
mQblog = NULL;
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-12-14 13:10:49 -05:00
|
|
|
//mConnMgr->addNetAssistConnect(1, mDhtMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/**************************************************************************/
|
|
|
|
/* need to Monitor too! */
|
2009-10-27 16:45:58 -04:00
|
|
|
std::cerr << "need to Monitor too!" << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mConnMgr->addMonitor(pqih);
|
|
|
|
mConnMgr->addMonitor(mCacheStrapper);
|
|
|
|
mConnMgr->addMonitor(ad);
|
|
|
|
mConnMgr->addMonitor(msgSrv);
|
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.
|
|
|
|
*/
|
|
|
|
mConnMgr->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);
|
|
|
|
//
|
2010-01-13 16:26:30 -05:00
|
|
|
mConfigMgr->addConfiguration("gpg_prefs.cfg", AuthGPG::getAuthGPG());
|
|
|
|
mConfigMgr->loadConfiguration();
|
|
|
|
|
|
|
|
mConfigMgr->addConfiguration("peers.cfg", mConnMgr);
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
|
|
|
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
|
|
|
mConfigMgr->addConfiguration("chat.cfg", chatSrv);
|
|
|
|
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
|
2009-05-07 17:36:17 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
|
|
|
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
|
|
|
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
|
|
|
mConfigMgr->addConfiguration("turtle.cfg", tr);
|
2010-01-15 16:09:25 -05:00
|
|
|
mConfigMgr->addConfiguration("p3disc.cfg", ad);
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mConnMgr->setLocalAddress(ownId, laddr);
|
|
|
|
}
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
if (RsInitConfig::forceExtPort)
|
|
|
|
{
|
|
|
|
mConnMgr->setOwnNetConfig(RS_NET_MODE_EXT, 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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
mConnMgr -> 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();
|
2009-08-04 19:22:44 -04:00
|
|
|
mConnMgr->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
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
ftserver->StartupThreads();
|
|
|
|
ftserver->ResumeTransfers();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-12-14 13:10:49 -05:00
|
|
|
//mDhtMgr->start();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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
|
|
|
|
2010-01-13 15:56:55 -05:00
|
|
|
rsPeers = new p3Peers(mConnMgr);
|
2010-01-13 16:01:06 -05:00
|
|
|
rsMsgs = new p3Msgs(msgSrv, chatSrv);
|
2009-07-30 17:27:47 -04:00
|
|
|
rsDisc = new p3Discovery(ad);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
rsForums = mForums;
|
|
|
|
rsChannels = mChannels;
|
|
|
|
rsRanks = new p3Rank(mRanking);
|
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);
|
|
|
|
rsStatus = new p3Status();
|
|
|
|
rsQblog = new p3Blog(mQblog);
|
|
|
|
#else
|
|
|
|
rsGameLauncher = NULL;
|
|
|
|
rsPhoto = NULL;
|
|
|
|
rsStatus = NULL;
|
|
|
|
rsQblog = NULL;
|
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
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();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
// load up the help page
|
|
|
|
std::string helppage = RsInitConfig::basedir + RsInitConfig::dirSeperator;
|
|
|
|
helppage += configHelpName;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-07-30 17:27:47 -04:00
|
|
|
/* Startup this thread! */
|
|
|
|
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
|
|
|
}
|