2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
* "$Id: p3face-startup.cc,v 1.9 2007-05-05 16:10:06 rmf24 Exp $"
|
|
|
|
*
|
|
|
|
* RetroShare C++ Interface.
|
|
|
|
*
|
|
|
|
* Copyright 2004-2006 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
//#include <getopt.h>
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "dbase/cachestrapper.h"
|
2008-11-13 18:03:46 -05:00
|
|
|
#include "ft/ftserver.h"
|
|
|
|
#include "ft/ftcontroller.h"
|
2008-11-02 06:38:11 -05:00
|
|
|
|
|
|
|
/* global variable now points straight to
|
|
|
|
* ft/ code so variable defined here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
RsFiles *rsFiles = NULL;
|
2008-02-05 08:45:04 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "pqi/pqipersongrp.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "pqi/pqisslpersongrp.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "pqi/pqiloopback.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "pqi/p3cfgmgr.h"
|
2008-02-05 08:45:04 -05:00
|
|
|
|
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"
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "upnp/upnphandler.h"
|
|
|
|
#include "dht/opendhtmgr.h"
|
|
|
|
|
2008-02-03 01:29:02 -05:00
|
|
|
#include "services/p3disc.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
#include "services/p3msgservice.h"
|
|
|
|
#include "services/p3chatservice.h"
|
2008-01-21 04:22:42 -05:00
|
|
|
#include "services/p3gamelauncher.h"
|
2008-02-03 01:29:02 -05:00
|
|
|
#include "services/p3ranking.h"
|
2008-03-04 16:31:11 -05:00
|
|
|
#include "services/p3photoservice.h"
|
2008-04-09 08:54:15 -04:00
|
|
|
#include "services/p3forums.h"
|
2008-06-24 00:22:42 -04:00
|
|
|
#include "services/p3channels.h"
|
2008-04-26 05:39:02 -04:00
|
|
|
#include "services/p3status.h"
|
2008-05-10 16:00:02 -04:00
|
|
|
#include "services/p3Qblog.h"
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <list>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
// for blocking signals
|
|
|
|
#include <signal.h>
|
|
|
|
|
2008-03-04 16:31:11 -05:00
|
|
|
/* Implemented Rs Interfaces */
|
2007-11-14 22:18:48 -05:00
|
|
|
#include "rsserver/p3face.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
#include "rsserver/p3peers.h"
|
2008-02-03 01:29:02 -05:00
|
|
|
#include "rsserver/p3rank.h"
|
2008-02-04 12:55:13 -05:00
|
|
|
#include "rsserver/p3msgs.h"
|
2008-03-04 16:31:11 -05:00
|
|
|
#include "rsserver/p3discovery.h"
|
|
|
|
#include "rsserver/p3photo.h"
|
2008-06-04 06:59:24 -04:00
|
|
|
#include "rsserver/p3Blog.h"
|
2008-01-21 04:22:42 -05:00
|
|
|
#include "rsiface/rsgame.h"
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-07-02 12:58:13 -04:00
|
|
|
#include "rsserver/p3files.h"
|
2008-06-04 06:59:24 -04:00
|
|
|
|
2008-03-06 07:07:54 -05:00
|
|
|
#include "pqi/p3notify.h" // HACK - moved to pqi for compilation order.
|
|
|
|
|
2008-04-03 10:34:52 -04:00
|
|
|
|
2008-04-09 08:54:15 -04:00
|
|
|
// COMMENT THIS FOR UNFINISHED SERVICES
|
|
|
|
/****
|
2008-09-21 16:30:34 -04:00
|
|
|
#define RS_RELEASE 1
|
2008-04-09 08:54:15 -04:00
|
|
|
****/
|
2008-04-03 10:34:52 -04:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
#define RS_RELEASE 1
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
|
|
|
#include "pqi/authxpgp.h"
|
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
2008-11-09 11:52:14 -05:00
|
|
|
#include "pqi/authssl.h"
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
std::string RsInit::load_cert;
|
|
|
|
std::string RsInit::load_key;
|
|
|
|
std::string RsInit::passwd;
|
|
|
|
|
|
|
|
bool RsInit::havePasswd; /* for Commandline password */
|
|
|
|
bool RsInit::autoLogin; /* autoLogin allowed */
|
|
|
|
bool RsInit::startMinimised; /* Icon or Full Window */
|
|
|
|
|
|
|
|
/* Win/Unix Differences */
|
|
|
|
char RsInit::dirSeperator;
|
|
|
|
|
|
|
|
/* Directories */
|
|
|
|
std::string RsInit::basedir;
|
|
|
|
std::string RsInit::homePath;
|
|
|
|
|
|
|
|
/* Listening Port */
|
|
|
|
bool RsInit::forceExtPort;
|
|
|
|
bool RsInit::forceLocalAddr;
|
|
|
|
unsigned short RsInit::port;
|
|
|
|
char RsInit::inet[256];
|
|
|
|
|
|
|
|
/* Logging */
|
|
|
|
bool RsInit::haveLogFile;
|
|
|
|
bool RsInit::outStderr;
|
|
|
|
bool RsInit::haveDebugLevel;
|
|
|
|
int RsInit::debugLevel;
|
|
|
|
char RsInit::logfname[1024];
|
|
|
|
|
|
|
|
bool RsInit::firsttime_run;
|
|
|
|
bool RsInit::load_trustedpeer;
|
|
|
|
std::string RsInit::load_trustedpeer_file;
|
|
|
|
|
|
|
|
bool RsInit::udpListenerOnly;
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Helper Functions */
|
2009-02-08 09:30:28 -05:00
|
|
|
//void load_check_basedir(RsInit *config);
|
|
|
|
//int create_configinit(RsInit *config);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify)
|
|
|
|
{
|
|
|
|
RsServer *srv = new RsServer(iface, notify);
|
|
|
|
return srv;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
//void CleanupRsConfig(RsInit *config)
|
|
|
|
//{
|
|
|
|
// delete config;
|
|
|
|
//}
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
static std::string getHomePath();
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
void RsInit::InitRsConfig()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
load_trustedpeer = false;
|
|
|
|
firsttime_run = false;
|
|
|
|
port = 7812; // default port.
|
|
|
|
forceLocalAddr = false;
|
|
|
|
haveLogFile = false;
|
|
|
|
outStderr = false;
|
|
|
|
forceExtPort = false;
|
|
|
|
|
|
|
|
strcpy(inet, "127.0.0.1");
|
|
|
|
strcpy(logfname, "");
|
|
|
|
|
|
|
|
autoLogin = true; // Always on now.
|
|
|
|
startMinimised = false;
|
|
|
|
passwd = "";
|
|
|
|
havePasswd = false;
|
|
|
|
haveDebugLevel = false;
|
|
|
|
debugLevel = PQL_WARNING;
|
|
|
|
udpListenerOnly = false;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
#ifndef WINDOWS_SYS
|
2009-02-08 09:30:28 -05:00
|
|
|
dirSeperator = '/'; // For unix.
|
2007-11-14 22:18:48 -05:00
|
|
|
#else
|
2009-02-08 09:30:28 -05:00
|
|
|
dirSeperator = '\\'; // For windows.
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup the homePath (default save location) */
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
const char *RsInit::RsConfigDirectory()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
return basedir.c_str();
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::setStartMinimised()
|
2008-06-14 09:22:39 -04:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
return startMinimised;
|
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-02-08 09:30:28 -05:00
|
|
|
autoLogin = true;
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
strncpy(logfname, optarg, 1024);
|
|
|
|
std::cerr << "LogFile (" << logfname;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
haveLogFile = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'w':
|
2009-02-08 09:30:28 -05:00
|
|
|
passwd = optarg;
|
|
|
|
std::cerr << "Password Specified(" << passwd;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
havePasswd = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'i':
|
2009-02-08 09:30:28 -05:00
|
|
|
strncpy(inet, optarg, 256);
|
|
|
|
std::cerr << "New Inet Addr(" << inet;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
forceLocalAddr = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
break;
|
|
|
|
case 'p':
|
2009-02-08 09:30:28 -05:00
|
|
|
port = atoi(optarg);
|
|
|
|
std::cerr << "New Listening Port(" << port;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 'c':
|
2009-02-08 09:30:28 -05:00
|
|
|
basedir = optarg;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "New Base Config Dir(";
|
2009-02-08 09:30:28 -05:00
|
|
|
std::cerr << basedir;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << ") Selected" << std::endl;
|
|
|
|
break;
|
|
|
|
case 's':
|
2009-02-08 09:30:28 -05:00
|
|
|
outStderr = true;
|
|
|
|
haveLogFile = false;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "Output to Stderr";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2009-02-08 09:30:28 -05:00
|
|
|
haveDebugLevel = true;
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
if (haveDebugLevel)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
if ((debugLevel > 0) &&
|
|
|
|
(debugLevel <= PQL_DEBUG_ALL))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "Setting Debug Level to: ";
|
2009-02-08 09:30:28 -05:00
|
|
|
std::cerr << debugLevel;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
setOutputLevel(debugLevel);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Ignoring Invalid Debug Level: ";
|
2009-02-08 09:30:28 -05:00
|
|
|
std::cerr << debugLevel;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the debug file.
|
2009-02-08 09:30:28 -05:00
|
|
|
if (haveLogFile)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
setDebugFile(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 ******************/
|
|
|
|
|
|
|
|
// first check config directories, and set bootstrap values.
|
2009-02-08 09:30:28 -05:00
|
|
|
load_check_basedir();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
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 ******************/
|
|
|
|
|
|
|
|
std::string userName;
|
2008-03-20 22:02:58 -04:00
|
|
|
std::string userId;
|
2007-11-14 22:18:48 -05:00
|
|
|
bool existingUser = false;
|
2008-11-09 11:52:14 -05:00
|
|
|
|
|
|
|
/* do a null init to allow the SSL libray to startup! */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2009-02-08 09:30:28 -05:00
|
|
|
if (LoadCheckXPGPandGetName(load_cert.c_str(), userName, userId))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "Existing Name: " << userName << std::endl;
|
2008-03-20 22:02:58 -04:00
|
|
|
std::cerr << "Existing Id: " << userId << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
existingUser = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "No Existing User" << std::endl;
|
|
|
|
}
|
2008-11-09 11:52:14 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
|
|
|
/* here we need to decide if existing user is okay....
|
|
|
|
* obviously - it can't be until we have functions
|
|
|
|
* to do it!
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* do a null init to allow the SSL libray to startup! */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
|
|
|
/* do a null init to allow the SSL libray to startup! */
|
2008-09-21 16:30:34 -04:00
|
|
|
getAuthMgr() -> InitAuth(NULL, NULL, NULL);
|
2007-11-14 22:18:48 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
2008-11-09 11:52:14 -05:00
|
|
|
getAuthMgr() -> InitAuth(NULL, NULL, NULL);
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
|
|
|
/* if existing user, and havePasswd .... we can skip the login prompt */
|
|
|
|
if (existingUser)
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
if (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-02-08 09:30:28 -05:00
|
|
|
const std::string& RsServer::certificateFileName() { return RsInit::load_cert ; }
|
2008-09-21 16:30:34 -04:00
|
|
|
/*
|
2007-11-14 22:18:48 -05:00
|
|
|
* The Real RetroShare Startup Function.
|
|
|
|
*/
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
int RsServer::StartupRetroShare()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/* STARTUP procedure */
|
|
|
|
/**************************************************************************/
|
|
|
|
/**************************************************************************/
|
|
|
|
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
mAuthMgr = getAuthMgr();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2008-01-25 02:58:29 -05:00
|
|
|
if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL))
|
2007-11-14 22:18:48 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
2008-11-09 11:52:14 -05:00
|
|
|
if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL))
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
{
|
|
|
|
std::cerr << "main() - Fatal Error....." << std::endl;
|
|
|
|
std::cerr << "Invalid Certificate configuration!" << std::endl;
|
|
|
|
std::cerr << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
std::string ownId = mAuthMgr->OwnId();
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Any Initial Configuration (Commandline Options) */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/* set the debugging to crashMode */
|
2009-02-08 09:30:28 -05:00
|
|
|
if ((!RsInit::haveLogFile) && (!RsInit::outStderr))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string crashfile = RsInit::basedir + RsInit::dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
crashfile += configLogFileName;
|
|
|
|
setDebugCrashMode(crashfile.c_str());
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
unsigned long flags = 0;
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::udpListenerOnly)
|
2008-01-25 02:58:29 -05:00
|
|
|
{
|
|
|
|
flags |= PQIPERSON_NO_LISTENER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
// Load up Certificates, and Old Configuration (if present)
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string certConfigFile = RsInit::basedir.c_str();
|
|
|
|
std::string certNeighDir = RsInit::basedir.c_str();
|
|
|
|
std::string emergencySaveDir = RsInit::basedir.c_str();
|
|
|
|
std::string emergencyPartialsDir = RsInit::basedir.c_str();
|
2008-02-07 11:18:34 -05:00
|
|
|
if (certConfigFile != "")
|
|
|
|
{
|
|
|
|
certConfigFile += "/";
|
|
|
|
certNeighDir += "/";
|
2008-03-31 10:06:59 -04:00
|
|
|
emergencySaveDir += "/";
|
2008-11-02 06:38:11 -05:00
|
|
|
emergencyPartialsDir += "/";
|
2008-02-07 11:18:34 -05:00
|
|
|
}
|
|
|
|
certConfigFile += configConfFile;
|
|
|
|
certNeighDir += configCertDir;
|
2008-03-31 10:06:59 -04:00
|
|
|
emergencySaveDir += "Downloads";
|
2008-11-02 06:38:11 -05:00
|
|
|
emergencyPartialsDir += "Partials";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-02-07 11:18:34 -05: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
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
mAuthMgr -> setConfigDirectories(certConfigFile, certNeighDir);
|
2008-11-09 11:52:14 -05:00
|
|
|
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2008-02-07 11:18:34 -05:00
|
|
|
((AuthXPGP *) mAuthMgr) -> loadCertificates(oldFormat, oldConfigMap);
|
2008-11-09 11:52:14 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
mAuthMgr -> loadCertificates();
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* setup classes / structures */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-03-05 11:32:18 -05:00
|
|
|
/* Setup Notify Early - So we can use it. */
|
|
|
|
rsNotify = new p3Notify();
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
mConnMgr = new p3ConnectMgr(mAuthMgr);
|
2008-08-16 11:02:24 -04:00
|
|
|
pqiNetAssistFirewall *mUpnpMgr = new upnphandler();
|
2009-02-08 09:30:28 -05:00
|
|
|
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr, RsInit::basedir);
|
2008-02-05 08:45:04 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
SecurityPolicy *none = secpolicy_create();
|
2008-01-28 00:40:32 -05:00
|
|
|
pqih = new pqisslpersongrp(none, flags);
|
|
|
|
//pqih = new pqipersongrpDummy(none, flags);
|
2008-01-25 02:58:29 -05:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
/****** New Ft Server **** !!! */
|
2008-11-02 06:38:11 -05:00
|
|
|
ftserver = new ftServer(mAuthMgr, mConnMgr);
|
|
|
|
ftserver->setP3Interface(pqih);
|
2009-02-08 09:30:28 -05:00
|
|
|
ftserver->setConfigDirectory(RsInit::basedir);
|
2008-11-02 06:38:11 -05: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-11-13 18:03:46 -05:00
|
|
|
|
2008-07-02 12:58:13 -04:00
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
mConfigMgr = new p3ConfigMgr(mAuthMgr, RsInit::basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
|
2008-02-07 11:18:34 -05:00
|
|
|
mGeneralConfig = new p3GeneralConfig();
|
|
|
|
|
|
|
|
/* create Services */
|
|
|
|
ad = new p3disc(mAuthMgr, mConnMgr);
|
|
|
|
msgSrv = new p3MsgService(mConnMgr);
|
|
|
|
chatSrv = new p3ChatService(mConnMgr);
|
|
|
|
|
|
|
|
pqih -> addService(ad);
|
|
|
|
pqih -> addService(msgSrv);
|
|
|
|
pqih -> addService(chatSrv);
|
|
|
|
|
2008-02-09 07:47:45 -05:00
|
|
|
/* create Cache Services */
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string config_dir = RsInit::basedir;
|
|
|
|
std::string localcachedir = config_dir + "/cache/local";
|
2008-02-09 07:47:45 -05:00
|
|
|
std::string remotecachedir = config_dir + "/cache/remote";
|
2008-11-09 17:17:20 -05:00
|
|
|
std::string channelsdir = config_dir + "/channels";
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2008-11-15 18:44:12 -05:00
|
|
|
//mRanking = NULL;
|
2008-06-04 06:59:24 -04:00
|
|
|
mRanking = new p3Ranking(mConnMgr, RS_SERVICE_TYPE_RANK, /* declaration of cache enable service rank */
|
2008-09-21 16:30:34 -04:00
|
|
|
mCacheStrapper, mCacheTransfer,
|
2008-07-10 12:29:18 -04:00
|
|
|
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
|
2008-02-09 07:47:45 -05:00
|
|
|
|
|
|
|
CachePair cp(mRanking, mRanking, CacheId(RS_SERVICE_TYPE_RANK, 0));
|
2008-06-04 06:59:24 -04:00
|
|
|
mCacheStrapper -> addCachePair(cp); /* end of declaration */
|
2008-02-07 11:18:34 -05:00
|
|
|
|
2008-11-15 18:44:12 -05:00
|
|
|
p3Forums *mForums = new p3Forums(RS_SERVICE_TYPE_FORUM,
|
|
|
|
mCacheStrapper, mCacheTransfer,
|
2008-12-05 19:23:43 -05:00
|
|
|
localcachedir, remotecachedir, mAuthMgr);
|
2008-11-15 18:44:12 -05: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 */
|
|
|
|
|
|
|
|
p3Channels *mChannels = new p3Channels(RS_SERVICE_TYPE_CHANNEL,
|
|
|
|
mCacheStrapper, mCacheTransfer, rsFiles,
|
2008-12-05 19:23:43 -05:00
|
|
|
localcachedir, remotecachedir, channelsdir, mAuthMgr);
|
2008-11-15 18:44:12 -05: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 */
|
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2008-11-15 18:44:12 -05:00
|
|
|
#ifndef RS_RELEASE
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2008-06-13 19:22:20 -04:00
|
|
|
p3GameLauncher *gameLauncher = new p3GameLauncher(mConnMgr);
|
|
|
|
pqih -> addService(gameLauncher);
|
|
|
|
|
2008-06-04 06:59:24 -04:00
|
|
|
p3PhotoService *photoService = new p3PhotoService(RS_SERVICE_TYPE_PHOTO, /* .... for photo service */
|
2008-09-21 16:30:34 -04:00
|
|
|
mCacheStrapper, mCacheTransfer,
|
2008-03-04 16:31:11 -05:00
|
|
|
localcachedir, remotecachedir);
|
|
|
|
|
|
|
|
CachePair cp2(photoService, photoService, CacheId(RS_SERVICE_TYPE_PHOTO, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp2);
|
2008-04-09 08:54:15 -04:00
|
|
|
|
2008-06-04 06:59:24 -04:00
|
|
|
mQblog = new p3Qblog(mConnMgr, RS_SERVICE_TYPE_QBLOG, /* ...then for Qblog */
|
2008-09-21 16:30:34 -04:00
|
|
|
mCacheStrapper, mCacheTransfer,
|
2008-07-10 12:29:18 -04:00
|
|
|
localcachedir, remotecachedir, 3600 * 24 * 30 * 6); // 6 Months
|
2008-06-04 06:59:24 -04:00
|
|
|
|
|
|
|
CachePair cp3(mQblog, mQblog, CacheId(RS_SERVICE_TYPE_QBLOG, 0));
|
|
|
|
mCacheStrapper -> addCachePair(cp3);
|
2008-09-21 16:30:34 -04:00
|
|
|
|
|
|
|
|
2008-04-03 10:34:52 -04:00
|
|
|
#else
|
2008-11-13 18:03:46 -05:00
|
|
|
mQblog = NULL;
|
2008-04-03 10:34:52 -04:00
|
|
|
#endif
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-08-16 11:02:24 -04:00
|
|
|
mConnMgr->addNetAssistConnect(1, mDhtMgr);
|
|
|
|
mConnMgr->addNetAssistFirewall(1, mUpnpMgr);
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
/**************************************************************************/
|
2008-02-09 07:47:45 -05:00
|
|
|
/* need to Monitor too! */
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
mConnMgr->addMonitor(pqih);
|
|
|
|
mConnMgr->addMonitor(mCacheStrapper);
|
2008-02-07 11:18:34 -05:00
|
|
|
mConnMgr->addMonitor(ad);
|
|
|
|
mConnMgr->addMonitor(msgSrv);
|
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
/* must also add the controller as a Monitor...
|
|
|
|
* a little hack to get it to work.
|
|
|
|
*/
|
|
|
|
mConnMgr->addMonitor(((ftController *) mCacheTransfer));
|
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
//mConfigMgr->addConfiguration("ftserver.cfg", ftserver);
|
2008-11-13 18:03:46 -05:00
|
|
|
//
|
2008-02-07 11:18:34 -05:00
|
|
|
mConfigMgr->addConfiguration("peers.cfg", mConnMgr);
|
|
|
|
mConfigMgr->addConfiguration("general.cfg", mGeneralConfig);
|
|
|
|
mConfigMgr->addConfiguration("msgs.cfg", msgSrv);
|
2008-02-09 07:47:45 -05:00
|
|
|
mConfigMgr->addConfiguration("cache.cfg", mCacheStrapper);
|
2008-11-15 18:44:12 -05:00
|
|
|
|
2008-11-13 18:03:46 -05:00
|
|
|
mConfigMgr->addConfiguration("ranklink.cfg", mRanking);
|
2008-06-13 11:42:08 -04:00
|
|
|
mConfigMgr->addConfiguration("forums.cfg", mForums);
|
2008-06-24 00:22:42 -04:00
|
|
|
mConfigMgr->addConfiguration("channels.cfg", mChannels);
|
2008-11-15 18:44:12 -05:00
|
|
|
|
|
|
|
#ifndef RS_RELEASE
|
2008-11-13 18:03:46 -05:00
|
|
|
#else
|
2008-04-15 12:35:46 -04:00
|
|
|
#endif
|
2008-02-09 07:47:45 -05:00
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
ftserver->addConfiguration(mConfigMgr);
|
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* (2) Load configuration files */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
mConfigMgr->loadConfiguration();
|
|
|
|
|
2008-07-02 09:19:59 -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.
|
|
|
|
*/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Hack Old Configuration into new System (first load only) */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-11-09 11:52:14 -05:00
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
if (oldFormat)
|
|
|
|
{
|
2008-02-08 07:39:40 -05:00
|
|
|
std::cerr << "Startup() Loaded Old Certificate Format" << std::endl;
|
|
|
|
|
2008-02-07 11:18:34 -05:00
|
|
|
/* transfer all authenticated peers to friend list */
|
|
|
|
std::list<std::string> authIds;
|
|
|
|
mAuthMgr->getAuthenticatedList(authIds);
|
|
|
|
|
|
|
|
std::list<std::string>::iterator it;
|
|
|
|
for(it = authIds.begin(); it != authIds.end(); it++)
|
|
|
|
{
|
|
|
|
mConnMgr->addFriend(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move other configuration options */
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/* trigger generalConfig loading for classes that require it */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-02-09 07:47:45 -05:00
|
|
|
pqih->setConfig(mGeneralConfig);
|
|
|
|
|
|
|
|
pqih->load_config();
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Force Any Configuration before Startup (After Load) */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::forceLocalAddr)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
struct sockaddr_in laddr;
|
|
|
|
|
2008-10-19 09:43:56 -04:00
|
|
|
/* clean sockaddr before setting values (MaxOSX) */
|
|
|
|
sockaddr_clear(&laddr);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
laddr.sin_family = AF_INET;
|
2009-02-08 09:30:28 -05:00
|
|
|
laddr.sin_port = htons(RsInit::port);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// universal
|
2009-02-08 09:30:28 -05:00
|
|
|
laddr.sin_addr.s_addr = inet_addr(RsInit::inet);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
mConnMgr->setLocalAddress(ownId, laddr);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::forceExtPort)
|
2008-03-21 15:06:34 -04:00
|
|
|
{
|
|
|
|
mConnMgr->setOwnNetConfig(RS_NET_MODE_EXT, RS_VIS_STATE_STD);
|
|
|
|
}
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
#if 0
|
2007-11-14 22:18:48 -05:00
|
|
|
/* must load the trusted_peer before setting up the pqipersongrp */
|
2009-02-08 09:30:28 -05:00
|
|
|
if (firsttime_run)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* at this point we want to load and start the trusted peer -> if selected */
|
2009-02-08 09:30:28 -05:00
|
|
|
if (load_trustedpeer)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/* sslroot does further checks */
|
2009-02-08 09:30:28 -05:00
|
|
|
sslr -> loadInitialTrustedPeer(load_trustedpeer_file);
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
}
|
2008-01-25 02:58:29 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mConnMgr -> checkNetAddress();
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* startup (stuff dependent on Ids/peers is after this point) */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-01-28 00:40:32 -05:00
|
|
|
pqih->init_listener();
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* load caches and secondary data */
|
|
|
|
/**************************************************************************/
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Force Any Last Configuration Options */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-02-11 11:27:55 -05:00
|
|
|
/**************************************************************************/
|
|
|
|
/* Start up Threads */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
ftserver->StartupThreads();
|
2008-11-15 15:00:29 -05:00
|
|
|
ftserver->ResumeTransfers();
|
2008-11-13 18:03:46 -05:00
|
|
|
|
2008-11-02 06:38:11 -05:00
|
|
|
mDhtMgr->start();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
// create loopback device, and add to pqisslgrp.
|
|
|
|
|
|
|
|
SearchModule *mod = new SearchModule();
|
2008-01-25 02:58:29 -05:00
|
|
|
pqiloopback *ploop = new pqiloopback(ownId);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
mod -> peerid = ownId;
|
2007-11-14 22:18:48 -05:00
|
|
|
mod -> pqi = ploop;
|
|
|
|
mod -> sp = secpolicy_create();
|
|
|
|
|
|
|
|
pqih->AddSearchModule(mod);
|
|
|
|
|
2008-02-09 07:47:45 -05:00
|
|
|
/* Setup GUI Interfaces. */
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-02-09 07:47:45 -05:00
|
|
|
rsPeers = new p3Peers(mConnMgr, mAuthMgr);
|
2008-02-04 12:55:13 -05:00
|
|
|
rsMsgs = new p3Msgs(mAuthMgr, msgSrv, chatSrv);
|
2008-03-04 16:31:11 -05:00
|
|
|
rsDisc = new p3Discovery(ad);
|
2008-06-13 19:22:20 -04:00
|
|
|
|
2008-11-15 18:44:12 -05:00
|
|
|
rsForums = mForums;
|
|
|
|
rsChannels = mChannels;
|
|
|
|
rsRanks = new p3Rank(mRanking);
|
2008-07-02 12:58:13 -04:00
|
|
|
|
2008-04-03 10:34:52 -04:00
|
|
|
#ifndef RS_RELEASE
|
|
|
|
rsGameLauncher = gameLauncher;
|
2008-03-04 16:31:11 -05:00
|
|
|
rsPhoto = new p3Photo(photoService);
|
2008-04-26 05:39:02 -04:00
|
|
|
rsStatus = new p3Status();
|
2008-06-04 06:59:24 -04:00
|
|
|
rsQblog = new p3Blog(mQblog);
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2008-04-03 10:34:52 -04:00
|
|
|
#else
|
|
|
|
rsGameLauncher = NULL;
|
|
|
|
rsPhoto = NULL;
|
2008-04-26 05:39:02 -04:00
|
|
|
rsStatus = NULL;
|
2008-05-10 16:00:02 -04:00
|
|
|
rsQblog = NULL;
|
2008-04-03 10:34:52 -04:00
|
|
|
#endif
|
2007-12-11 20:43:17 -05:00
|
|
|
|
2008-03-05 11:32:18 -05:00
|
|
|
|
2007-12-11 20:43:17 -05:00
|
|
|
/* put a welcome message in! */
|
2009-02-08 09:30:28 -05:00
|
|
|
if (RsInit::firsttime_run)
|
2007-12-11 20:43:17 -05:00
|
|
|
{
|
|
|
|
msgSrv->loadWelcomeMsg();
|
|
|
|
}
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
// load up the help page
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string helppage = RsInit::basedir + RsInit::dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
helppage += configHelpName;
|
|
|
|
|
|
|
|
/* for DHT/UPnP stuff */
|
2009-02-08 09:30:28 -05:00
|
|
|
//InitNetworking(basedir + "/kadc.ini");
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* Startup this thread! */
|
2008-01-25 02:58:29 -05:00
|
|
|
createThread(*this);
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-11-15 15:00:29 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
int RsInit::LoadCertificates(bool autoLoginNT)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
if (load_cert == "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "RetroShare needs a certificate" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (load_key == "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "RetroShare needs a key" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if ((!havePasswd) || (passwd == ""))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "RetroShare needs a Password" << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string ca_loc = basedir + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
ca_loc += configCaFile;
|
|
|
|
|
2008-01-25 02:58:29 -05:00
|
|
|
p3AuthMgr *authMgr = getAuthMgr();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2009-02-08 09:30:28 -05:00
|
|
|
if (0 < authMgr -> InitAuth(load_cert.c_str(), load_key.c_str(),passwd.c_str()))
|
2007-11-14 22:18:48 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
2008-11-09 11:52:14 -05:00
|
|
|
/* The SSL + PGP version will require
|
|
|
|
* Id of pgp account + password
|
|
|
|
* padding with NULLs
|
|
|
|
*/
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (0 < authMgr -> InitAuth(load_cert.c_str(), NULL, passwd.c_str()))
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
|
|
|
{
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
passwd = "";
|
|
|
|
create_configinit();
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* To Enter RetroShare.... must call either:
|
|
|
|
* LoadPassword, or
|
|
|
|
* RsGenerateCertificate.
|
|
|
|
*
|
|
|
|
* Then call LoadCertificate .... if it returns true....
|
|
|
|
* its all okay.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Assistance for Login */
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::ValidateCertificate(std::string &userName)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string fname = load_cert;
|
2008-03-20 22:02:58 -04:00
|
|
|
std::string userId;
|
2007-11-14 22:18:48 -05:00
|
|
|
if (fname != "")
|
|
|
|
{
|
2008-11-09 11:52:14 -05:00
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2008-03-20 22:02:58 -04:00
|
|
|
return LoadCheckXPGPandGetName(fname.c_str(), userName, userId);
|
2008-11-09 11:52:14 -05:00
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
/* check against authmanagers private keys */
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::ValidateTrustedUser(std::string fname, std::string &userName)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2008-03-20 22:02:58 -04:00
|
|
|
std::string userId;
|
2008-11-09 11:52:14 -05:00
|
|
|
bool valid = false;
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
|
|
|
valid = LoadCheckXPGPandGetName(fname.c_str(), userName, userId);
|
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
if (valid)
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
load_trustedpeer = true;
|
|
|
|
load_trustedpeer_file = fname;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
load_trustedpeer = false;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
return valid;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::LoadPassword(std::string _passwd)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
passwd = _passwd;
|
|
|
|
havePasswd = true;
|
2007-11-14 22:18:48 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A little nasty fn....
|
|
|
|
* (1) returns true, if successful, and updates config.
|
|
|
|
* (2) returns false if fails, with error msg to errString.
|
|
|
|
*/
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::RsGenerateCertificate(
|
2008-09-21 16:30:34 -04:00
|
|
|
std::string name,
|
|
|
|
std::string org,
|
|
|
|
std::string loc,
|
|
|
|
std::string country,
|
2009-02-10 04:33:30 -05:00
|
|
|
std::string password,
|
2007-11-14 22:18:48 -05:00
|
|
|
std::string &errString)
|
|
|
|
{
|
|
|
|
// In the XPGP world this is easy...
|
|
|
|
// generate the private_key / certificate.
|
|
|
|
// save to file.
|
|
|
|
//
|
|
|
|
// then load as if they had entered a passwd.
|
|
|
|
|
|
|
|
// check password.
|
2009-02-10 04:33:30 -05:00
|
|
|
if (password.length() < 4)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
errString = "Password is Unsatisfactory (must be 4+ chars)";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
if (name.length() < 3)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
errString = "Name is too short (must be 3+ chars)";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int nbits = 2048;
|
|
|
|
|
|
|
|
// Create the filename.
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string basename = basedir + dirSeperator;
|
|
|
|
basename += configKeyDir + dirSeperator;
|
2008-09-21 16:30:34 -04:00
|
|
|
basename += "user";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
std::string key_name = basename + "_pk.pem";
|
|
|
|
std::string cert_name = basename + "_cert.pem";
|
|
|
|
|
|
|
|
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
#if defined(PQI_USE_XPGP)
|
2008-09-21 16:30:34 -04:00
|
|
|
if (!generate_xpgp(cert_name.c_str(), key_name.c_str(),
|
2009-02-10 04:33:30 -05:00
|
|
|
password.c_str(),
|
2008-09-21 16:30:34 -04:00
|
|
|
name.c_str(),
|
|
|
|
"", //ui -> gen_email -> value(),
|
2007-11-14 22:18:48 -05:00
|
|
|
org.c_str(),
|
|
|
|
loc.c_str(),
|
2008-09-21 16:30:34 -04:00
|
|
|
"", //ui -> gen_state -> value(),
|
2007-11-14 22:18:48 -05:00
|
|
|
country.c_str(),
|
|
|
|
nbits))
|
|
|
|
#else /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
/* UNTIL THIS IS FILLED IN CANNOT GENERATE X509 REQ */
|
2008-11-09 11:52:14 -05:00
|
|
|
/* What should happen here - is a new openpgp certificate
|
|
|
|
* is created, with a retroshare subkey,
|
|
|
|
* this is then used to generate a self-signed certificate
|
|
|
|
*/
|
|
|
|
//mAuthMgr->createUser( );
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif /* X509 Certificates */
|
|
|
|
/**************** PQI_USE_XPGP ******************/
|
|
|
|
{
|
|
|
|
errString = "Generation of XPGP Failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
/* set the load passwd to the gen version
|
2007-11-14 22:18:48 -05:00
|
|
|
* and try to load it!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* if we get here .... then save details to the configuration class */
|
2009-02-08 09:30:28 -05:00
|
|
|
load_cert = cert_name;
|
|
|
|
load_key = key_name;
|
2009-02-10 04:33:30 -05:00
|
|
|
passwd = password;
|
2009-02-08 09:30:28 -05:00
|
|
|
havePasswd = true;
|
|
|
|
firsttime_run = true;
|
2007-11-14 22:18:48 -05: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();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
void RsInit::load_check_basedir()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
// get the default configuration location.
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (basedir == "")
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
// if unix. homedir + /.pqiPGPrc
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS
|
|
|
|
char *h = getenv("HOME");
|
|
|
|
std::cerr << "retroShare::basedir() -> $HOME = ";
|
|
|
|
std::cerr << h << std::endl;
|
|
|
|
if (h == NULL)
|
|
|
|
{
|
|
|
|
std::cerr << "load_check_basedir() Fatal Error --";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
std::cerr << "\tcannot determine $HOME dir" <<std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-02-08 09:30:28 -05:00
|
|
|
basedir = h;
|
|
|
|
basedir += "/.pqiPGPrc";
|
2007-11-14 22:18:48 -05:00
|
|
|
#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;
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
basedir="C:\\Retro";
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
basedir = h;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
if (!RsDirUtil::checkCreateDirectory(basedir))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::cerr << "Cannot Create BaseConfig Dir" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
2009-02-08 09:30:28 -05:00
|
|
|
basedir += "\\RetroShare";
|
2007-11-14 22:18:48 -05:00
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string subdir1 = basedir + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
std::string subdir2 = subdir1;
|
|
|
|
subdir1 += configKeyDir;
|
|
|
|
subdir2 += configCertDir;
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string subdir3 = basedir + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
subdir3 += "cache";
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string subdir4 = subdir3 + dirSeperator;
|
|
|
|
std::string subdir5 = subdir3 + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
subdir4 += "local";
|
|
|
|
subdir5 += "remote";
|
|
|
|
|
|
|
|
// fatal if cannot find/create.
|
|
|
|
std::cerr << "Checking For Directories" << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
if (!RsDirUtil::checkCreateDirectory(basedir))
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// have a config directories.
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
// Check for config file.
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string initfile = basedir + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
initfile += configInitFile;
|
|
|
|
|
|
|
|
// open and read in the lines.
|
|
|
|
FILE *ifd = fopen(initfile.c_str(), "r");
|
|
|
|
char path[1024];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ifd != NULL)
|
|
|
|
{
|
|
|
|
if (NULL != fgets(path, 1024, ifd))
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++) {}
|
2007-11-14 22:18:48 -05:00
|
|
|
path[i] = '\0';
|
2009-02-08 09:30:28 -05:00
|
|
|
load_cert = path;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
if (NULL != fgets(path, 1024, ifd))
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
for(i = 0; (path[i] != '\0') && (path[i] != '\n'); i++) {}
|
2007-11-14 22:18:48 -05:00
|
|
|
path[i] = '\0';
|
2009-02-08 09:30:28 -05:00
|
|
|
load_key = path;
|
2007-11-14 22:18:48 -05:00
|
|
|
}
|
|
|
|
fclose(ifd);
|
|
|
|
}
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
// we have now
|
2007-11-14 22:18:48 -05:00
|
|
|
// 1) checked or created the config dirs.
|
|
|
|
// 2) loaded the config_init file - if possible.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
int RsInit::create_configinit()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
// Check for config file.
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string initfile = basedir + dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
initfile += configInitFile;
|
|
|
|
|
|
|
|
// open and read in the lines.
|
|
|
|
FILE *ifd = fopen(initfile.c_str(), "w");
|
|
|
|
|
|
|
|
if (ifd != NULL)
|
|
|
|
{
|
2009-02-08 09:30:28 -05:00
|
|
|
fprintf(ifd, "%s\n", load_cert.c_str());
|
|
|
|
fprintf(ifd, "%s\n", load_key.c_str());
|
2007-11-14 22:18:48 -05:00
|
|
|
fclose(ifd);
|
|
|
|
|
|
|
|
std::cerr << "Creating Init File: " << initfile << std::endl;
|
2009-02-08 09:30:28 -05:00
|
|
|
std::cerr << "\tLoad Cert: " << load_cert << std::endl;
|
|
|
|
std::cerr << "\tLoad Key: " << load_key << std::endl;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
std::cerr << "Failed To Create Init File: " << initfile << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
|
|
int check_create_directory(std::string dir)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
int val = stat(dir.c_str(), &buf);
|
|
|
|
if (val == -1)
|
|
|
|
{
|
|
|
|
// directory don't exist. create.
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS // UNIX
|
|
|
|
if (-1 == mkdir(dir.c_str(), 0777))
|
|
|
|
#else // WIN
|
|
|
|
if (-1 == mkdir(dir.c_str()))
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
{
|
|
|
|
std::cerr << "check_create_directory() Fatal Error --";
|
|
|
|
std::cerr <<std::endl<< "\tcannot create:" <<dir<<std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "check_create_directory()";
|
|
|
|
std::cerr <<std::endl<< "\tcreated:" <<dir<<std::endl;
|
2008-09-21 16:30:34 -04:00
|
|
|
}
|
2007-11-14 22:18:48 -05:00
|
|
|
else if (!S_ISDIR(buf.st_mode))
|
|
|
|
{
|
|
|
|
// Some other type - error.
|
|
|
|
std::cerr<<"check_create_directory() Fatal Error --";
|
|
|
|
std::cerr<<std::endl<<"\t"<<dir<<" is nor Directory"<<std::endl;
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
std::cerr << "check_create_directory()";
|
|
|
|
std::cerr <<std::endl<< "\tDir Exists:" <<dir<<std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string RsInit::getHomePath()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
std::string home;
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
|
|
|
|
home = getenv("HOME");
|
|
|
|
|
|
|
|
#else /* Windows */
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (h2 == NULL)
|
|
|
|
{
|
|
|
|
// Might be Win95/98
|
|
|
|
// generate default.
|
|
|
|
home = "C:\\Retro";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
home = h2;
|
|
|
|
home += h3;
|
|
|
|
home += "\\Desktop";
|
|
|
|
}
|
|
|
|
|
|
|
|
out << "fltkserver::getHomePath() -> " << home << std::endl;
|
|
|
|
std::cerr << out;
|
|
|
|
|
|
|
|
// convert to FLTK desired format.
|
|
|
|
home = make_path_unix(home);
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
return home;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string make_path_unix(std::string path)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < path.length(); i++)
|
|
|
|
{
|
|
|
|
if (path[i] == '\\')
|
|
|
|
path[i] = '/';
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
/* WINDOWS STRUCTURES FOR DPAPI */
|
|
|
|
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
#else
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <windows.h>
|
2009-02-08 09:30:28 -05:00
|
|
|
#include <wincrypt.h>
|
2007-11-14 22:18:48 -05:00
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
/*
|
|
|
|
class CRYPTPROTECT_PROMPTSTRUCT;
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2009-02-08 09:30:28 -05:00
|
|
|
#ifdef A_VIRER
|
2007-11-14 22:18:48 -05:00
|
|
|
typedef struct _CRYPTPROTECT_PROMPTSTRUCT {
|
|
|
|
DWORD cbSize;
|
|
|
|
DWORD dwPromptFlags;
|
|
|
|
HWND hwndApp;
|
|
|
|
LPCWSTR szPrompt;
|
2008-09-21 16:30:34 -04:00
|
|
|
} CRYPTPROTECT_PROMPTSTRUCT,
|
2007-11-14 22:18:48 -05:00
|
|
|
*PCRYPTPROTECT_PROMPTSTRUCT;
|
2009-02-08 09:30:28 -05:00
|
|
|
#endif
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/* 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, */
|
2008-09-21 16:30:34 -04:00
|
|
|
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
|
2007-11-14 22:18:48 -05:00
|
|
|
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, */
|
2008-09-21 16:30:34 -04:00
|
|
|
CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
|
2007-11-14 22:18:48 -05:00
|
|
|
DWORD dwFlags,
|
|
|
|
DATA_BLOB* pDataOut
|
|
|
|
);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::RsStoreAutoLogin()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
std::string entropy = load_cert;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
DATA_BLOB DataIn;
|
|
|
|
DATA_BLOB DataEnt;
|
|
|
|
DATA_BLOB DataOut;
|
2009-02-08 09:30:28 -05:00
|
|
|
BYTE *pbDataInput = (BYTE *) strdup(passwd.c_str());
|
2007-11-14 22:18:48 -05:00
|
|
|
DWORD cbDataInput = strlen((char *)pbDataInput)+1;
|
|
|
|
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
|
|
|
|
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
|
2008-09-21 16:30:34 -04:00
|
|
|
DataIn.pbData = pbDataInput;
|
|
|
|
DataIn.cbData = cbDataInput;
|
|
|
|
DataEnt.pbData = pbDataEnt;
|
|
|
|
DataEnt.cbData = cbDataEnt;
|
2007-11-14 22:18:48 -05:00
|
|
|
LPWSTR pDescrOut = NULL;
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
CRYPTPROTECT_PROMPTSTRUCT prom;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
|
|
|
|
/**********
|
|
|
|
std::cerr << "The encryption phase worked. (";
|
|
|
|
std::cerr << DataOut.cbData << ")" << std::endl;
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < DataOut.cbData; i++)
|
|
|
|
{
|
|
|
|
std::cerr << std::setw(2) << (int) DataOut.pbData[i];
|
|
|
|
std::cerr << " ";
|
|
|
|
}
|
|
|
|
std::cerr << std::endl;
|
|
|
|
**********/
|
|
|
|
|
|
|
|
/* save the data to the file */
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string passwdfile = basedir;
|
|
|
|
passwdfile += dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
passwdfile += "help.dta";
|
|
|
|
|
|
|
|
//std::cerr << "Save to: " << passwdfile;
|
|
|
|
//std::cerr << std::endl;
|
|
|
|
|
|
|
|
FILE *fp = fopen(passwdfile.c_str(), "wb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fwrite(DataOut.pbData, 1, DataOut.cbData, fp);
|
|
|
|
fclose(fp);
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "AutoLogin Data saved: ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cerr << "Encryption Failed";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pbDataInput);
|
|
|
|
free(pbDataEnt);
|
|
|
|
LocalFree(DataOut.pbData);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::RsTryAutoLogin()
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
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-02-08 09:30:28 -05:00
|
|
|
if (!autoLogin)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to load from file */
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string entropy = load_cert;
|
2007-11-14 22:18:48 -05:00
|
|
|
/* get the data out */
|
|
|
|
|
|
|
|
/* open the data to the file */
|
2009-02-08 09:30:28 -05:00
|
|
|
std::string passwdfile = basedir;
|
|
|
|
passwdfile += dirSeperator;
|
2007-11-14 22:18:48 -05:00
|
|
|
passwdfile += "help.dta";
|
|
|
|
|
|
|
|
DATA_BLOB DataIn;
|
|
|
|
DATA_BLOB DataEnt;
|
|
|
|
DATA_BLOB DataOut;
|
|
|
|
|
|
|
|
BYTE *pbDataEnt =(BYTE *) strdup(entropy.c_str());
|
|
|
|
DWORD cbDataEnt = strlen((char *)pbDataEnt)+1;
|
2008-09-21 16:30:34 -04:00
|
|
|
DataEnt.pbData = pbDataEnt;
|
2007-11-14 22:18:48 -05:00
|
|
|
DataEnt.cbData = cbDataEnt;
|
|
|
|
|
|
|
|
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;
|
2008-09-21 16:30:34 -04:00
|
|
|
DataIn.pbData = pbDataInput;
|
2007-11-14 22:18:48 -05:00
|
|
|
DataIn.cbData = cbDataInput;
|
|
|
|
|
|
|
|
|
2008-09-21 16:30:34 -04:00
|
|
|
CRYPTPROTECT_PROMPTSTRUCT prom;
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
prom.cbSize = sizeof(prom);
|
|
|
|
prom.dwPromptFlags = 0;
|
|
|
|
|
|
|
|
|
|
|
|
bool isDecrypt = CryptUnprotectData(
|
|
|
|
&DataIn,
|
2008-09-21 16:30:34 -04:00
|
|
|
NULL,
|
2007-11-14 22:18:48 -05:00
|
|
|
&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-02-08 09:30:28 -05:00
|
|
|
passwd = (char *) DataOut.pbData;
|
|
|
|
havePasswd = true;
|
2007-11-14 22:18:48 -05: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;
|
|
|
|
}
|
|
|
|
|
2009-02-08 09:30:28 -05:00
|
|
|
bool RsInit::RsClearAutoLogin(std::string basedir)
|
2007-11-14 22:18:48 -05:00
|
|
|
{
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
#ifndef WINDOWS_SYS /* UNIX */
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
std::string file = basedir;
|
|
|
|
file += "\\help.dta";
|
|
|
|
|
|
|
|
FILE *fp = fopen(file.c_str(), "wb");
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
fwrite(" ", 1, 1, fp);
|
|
|
|
fclose(fp);
|
2008-09-21 16:30:34 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
std::cerr << "AutoLogin Data cleared! ";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|