mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-02 06:06:10 -04:00
Merge pull request #937 from csoler/v0.6-ImprovedNoGUI
V0.6 improved no gui
This commit is contained in:
commit
98b0585ba4
11 changed files with 602 additions and 421 deletions
|
@ -20,7 +20,7 @@
|
|||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -46,6 +46,8 @@
|
|||
#define LIMIT_CERTIFICATE_SIZE 1
|
||||
#define MAX_CERTIFICATE_SIZE 10000
|
||||
|
||||
//#define DEBUG_AUTHGPG 1
|
||||
|
||||
const time_t STORE_KEY_TIMEOUT = 1 * 60 * 60; //store key is call around every hour
|
||||
|
||||
AuthGPG *AuthGPG::_instance = NULL ;
|
||||
|
@ -88,7 +90,6 @@ bool AuthGPG::encryptTextToFile(const std::string& text,const std::string& outfi
|
|||
|
||||
std::string pgp_pwd_callback(void * /*hook*/, const char *uid_title, const char *uid_hint, const char * /*passphrase_info*/, int prev_was_bad,bool *cancelled)
|
||||
{
|
||||
#define GPG_DEBUG2
|
||||
#ifdef GPG_DEBUG2
|
||||
fprintf(stderr, "pgp_pwd_callback() called.\n");
|
||||
#endif
|
||||
|
@ -121,12 +122,12 @@ void AuthGPG::exit()
|
|||
}
|
||||
|
||||
AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& path_to_secret_keyring,const std::string& path_to_trustdb,const std::string& pgp_lock_file)
|
||||
:p3Config(),
|
||||
:p3Config(),
|
||||
PGPHandler(path_to_public_keyring,path_to_secret_keyring,path_to_trustdb,pgp_lock_file),
|
||||
gpgMtxService("AuthGPG-service"),
|
||||
gpgMtxEngine("AuthGPG-engine"),
|
||||
gpgMtxEngine("AuthGPG-engine"),
|
||||
gpgMtxData("AuthGPG-data"),
|
||||
gpgKeySelected(false)
|
||||
gpgKeySelected(false)
|
||||
{
|
||||
_force_sync_database = false ;
|
||||
mCount = 0;
|
||||
|
@ -162,7 +163,9 @@ AuthGPG::AuthGPG(const std::string& path_to_public_keyring,const std::string& pa
|
|||
*/
|
||||
int AuthGPG::GPGInit(const RsPgpId &ownId)
|
||||
{
|
||||
#ifdef DEBUG_AUTHGPG
|
||||
std::cerr << "AuthGPG::GPGInit() called with own gpg id : " << ownId.toStdString() << std::endl;
|
||||
#endif
|
||||
|
||||
mOwnGpgId = RsPgpId(ownId);
|
||||
|
||||
|
@ -170,7 +173,9 @@ int AuthGPG::GPGInit(const RsPgpId &ownId)
|
|||
privateTrustCertificate(ownId, 5);
|
||||
updateOwnSignatureFlag(mOwnGpgId) ;
|
||||
|
||||
#ifdef DEBUG_AUTHGPG
|
||||
std::cerr << "AuthGPG::GPGInit finished." << std::endl;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -231,9 +236,9 @@ void AuthGPG::processServices()
|
|||
}
|
||||
|
||||
AuthGPGOperationLoadOrSave *loadOrSave = dynamic_cast<AuthGPGOperationLoadOrSave*>(operation);
|
||||
if (loadOrSave)
|
||||
if (loadOrSave)
|
||||
{
|
||||
if (loadOrSave->m_load)
|
||||
if (loadOrSave->m_load)
|
||||
{
|
||||
/* process load operation */
|
||||
|
||||
|
@ -285,8 +290,8 @@ void AuthGPG::processServices()
|
|||
}
|
||||
|
||||
service->setGPGOperation(loadOrSave);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPGimpl::processServices() Unknown operation" << std::endl;
|
||||
|
@ -313,7 +318,7 @@ bool AuthGPG::parseSignature(const void *sig, unsigned int siglen, RsPgpId& issu
|
|||
return PGPHandler::parseSignature((unsigned char*)sig,siglen,issuer_id) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::exportProfile(const std::string& fname,const RsPgpId& exported_id)
|
||||
bool AuthGPG::exportProfile(const std::string& fname,const RsPgpId& exported_id)
|
||||
{
|
||||
return PGPHandler::exportGPGKeyPair(fname,exported_id) ;
|
||||
}
|
||||
|
@ -328,7 +333,7 @@ bool AuthGPG::importProfileFromString(const std::string &data, RsPgpId &gpg_id,
|
|||
return PGPHandler::importGPGKeyPairFromString(data, gpg_id, import_error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AuthGPG::active()
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
@ -427,7 +432,7 @@ bool AuthGPG::isKeySupported(const RsPgpId& id) const
|
|||
return !(pc->_flags & PGPCertificateInfo::PGP_CERTIFICATE_FLAG_UNSUPPORTED_ALGORITHM) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
|
||||
bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
|
@ -458,7 +463,7 @@ bool AuthGPG::getGPGDetails(const RsPgpId& pgp_id, RsPeerDetails &d)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool AuthGPG::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&))
|
||||
bool AuthGPG::getGPGFilteredList(std::list<RsPgpId>& list,bool (*filter)(const PGPCertificateInfo&))
|
||||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
|
@ -492,20 +497,20 @@ bool AuthGPG::getGPGSignedList(std::list<RsPgpId> &ids)
|
|||
// #else
|
||||
// certificate = PGPHandler::SaveCertificateToString(RsPgpId(id),true) ;
|
||||
// #endif
|
||||
//
|
||||
//
|
||||
// // #ifdef LIMIT_CERTIFICATE_SIZE
|
||||
// // std::string cleaned_key ;
|
||||
// // if(PGPKeyManagement::createMinimalKey(certificate,cleaned_key))
|
||||
// // certificate = cleaned_key ;
|
||||
// // #endif
|
||||
//
|
||||
//
|
||||
// return certificate.length() > 0 ;
|
||||
// }
|
||||
|
||||
/*****************************************************************
|
||||
* Loading and Saving Certificates - this has to
|
||||
* Loading and Saving Certificates - this has to
|
||||
* be able to handle both openpgp and X509 certificates.
|
||||
*
|
||||
*
|
||||
* X509 are passed onto AuthSSL, OpenPGP are passed to gpgme.
|
||||
*
|
||||
*/
|
||||
|
@ -515,7 +520,7 @@ bool AuthGPG::getGPGSignedList(std::list<RsPgpId> &ids)
|
|||
std::string AuthGPG::SaveCertificateToString(const RsPgpId &id,bool include_signatures)
|
||||
{
|
||||
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
|
||||
|
||||
|
||||
return PGPHandler::SaveCertificateToString(id,include_signatures) ;
|
||||
}
|
||||
|
||||
|
@ -536,10 +541,10 @@ bool AuthGPG::LoadCertificateFromString(const std::string &str, RsPgpId& gpg_id,
|
|||
/*****************************************************************
|
||||
* Auth...? Signing, Revoke, Trust are all done at
|
||||
* the PGP level....
|
||||
*
|
||||
*
|
||||
* Only Signing of SSL is done at setup.
|
||||
* Auth should be done... ?? not sure
|
||||
* maybe
|
||||
* Auth should be done... ?? not sure
|
||||
* maybe
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -596,12 +601,12 @@ bool AuthGPG::TrustCertificate(const RsPgpId& id, int trustlvl)
|
|||
return privateTrustCertificate(id, trustlvl) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::encryptDataBin(const RsPgpId& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
bool AuthGPG::encryptDataBin(const RsPgpId& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return PGPHandler::encryptDataBin(RsPgpId(pgp_id),data,datalen,sign,signlen) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return PGPHandler::decryptDataBin(mOwnGpgId,data,datalen,sign,signlen) ;
|
||||
}
|
||||
|
@ -610,7 +615,7 @@ bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char
|
|||
return DoOwnSignature(data, datalen, sign, signlen, reason);
|
||||
}
|
||||
|
||||
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint)
|
||||
bool AuthGPG::VerifySignBin(const void *data, uint32_t datalen, unsigned char *sign, unsigned int signlen, const PGPFingerprintType& withfingerprint)
|
||||
{
|
||||
return VerifySignature(data, datalen, sign, signlen, withfingerprint);
|
||||
}
|
||||
|
@ -639,12 +644,12 @@ int AuthGPG::privateTrustCertificate(const RsPgpId& id, int trustlvl)
|
|||
{
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
||||
/* The certificate should be in Peers list ??? */
|
||||
if(!isGPGAccepted(id))
|
||||
{
|
||||
std::cerr << "Invalid Certificate" << std::endl;
|
||||
// csoler: Why are we not allowing this when the peer is not in the accepted peers list??
|
||||
// The trust level is only a user-defined property that has nothing to
|
||||
// do with the fact that we allow connections or not.
|
||||
|
||||
if(!isGPGAccepted(id))
|
||||
return 0;
|
||||
}
|
||||
|
||||
int res = PGPHandler::privateTrustCertificate(id,trustlvl) ;
|
||||
_force_sync_database = true ;
|
||||
|
@ -667,7 +672,7 @@ bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
|||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::saveList() called" << std::endl ;
|
||||
#endif
|
||||
std::list<RsPgpId> ids ;
|
||||
std::list<RsPgpId> ids ;
|
||||
getGPGAcceptedList(ids) ; // needs to be done before the lock
|
||||
|
||||
RsStackMutex stack(gpgMtxData); /******* LOCKED ******/
|
||||
|
@ -677,7 +682,7 @@ bool AuthGPG::saveList(bool& cleanup, std::list<RsItem*>& lst)
|
|||
// Now save config for network digging strategies
|
||||
RsConfigKeyValueSet *vitem = new RsConfigKeyValueSet ;
|
||||
|
||||
for (std::list<RsPgpId>::const_iterator it(ids.begin()); it != ids.end(); ++it)
|
||||
for (std::list<RsPgpId>::const_iterator it(ids.begin()); it != ids.end(); ++it)
|
||||
if((*it) != mOwnGpgId) // skip our own id.
|
||||
{
|
||||
RsTlvKeyValue kv;
|
||||
|
@ -705,7 +710,7 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
|
|||
for(it = load.begin(); it != load.end(); ++it)
|
||||
{
|
||||
RsConfigKeyValueSet *vitem = dynamic_cast<RsConfigKeyValueSet *>(*it);
|
||||
if(vitem)
|
||||
if(vitem)
|
||||
{
|
||||
#ifdef GPG_DEBUG
|
||||
std::cerr << "AuthGPG::loadList() General Variable Config Item:" << std::endl;
|
||||
|
@ -715,7 +720,7 @@ bool AuthGPG::loadList(std::list<RsItem*>& load)
|
|||
|
||||
std::list<RsTlvKeyValue>::iterator kit;
|
||||
for(kit = vitem->tlvkvs.pairs.begin(); kit != vitem->tlvkvs.pairs.end(); ++kit)
|
||||
if (kit->key != mOwnGpgId.toStdString())
|
||||
if (kit->key != mOwnGpgId.toStdString())
|
||||
PGPHandler::setAcceptConnexion(RsPgpId(kit->key), (kit->value == "TRUE"));
|
||||
}
|
||||
delete (*it);
|
||||
|
|
|
@ -109,6 +109,8 @@ bool RsAccountsDetail::checkAccountDirectory()
|
|||
return setupAccount(PathAccountDirectory());
|
||||
}
|
||||
|
||||
#warning we need to clean that up. Login should only ask for a SSL id, instead of a std::string.
|
||||
|
||||
bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString)
|
||||
{
|
||||
if (mAccountsLocked)
|
||||
|
@ -137,9 +139,14 @@ bool RsAccountsDetail::selectAccountByString(const std::string &prefUserString)
|
|||
{
|
||||
mPreferredId = it->second.mSslId;
|
||||
pgpNameFound = true;
|
||||
|
||||
std::cerr << "Account selected: " << ssl_id << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return pgpNameFound;
|
||||
std::cerr << "No suitable candidate found." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -453,15 +460,19 @@ bool RsAccountsDetail::getPreferredAccountId(RsPeerId &id)
|
|||
bool RsAccountsDetail::getAccountIds(std::list<RsPeerId> &ids)
|
||||
{
|
||||
std::map<RsPeerId, AccountDetails>::iterator it;
|
||||
#ifdef DEBUG_ACCOUNTS
|
||||
std::cerr << "getAccountIds:" << std::endl;
|
||||
#endif
|
||||
|
||||
for(it = mAccounts.begin(); it != mAccounts.end(); ++it)
|
||||
{
|
||||
#ifdef DEBUG_ACCOUNTS
|
||||
std::cerr << "SSL Id: " << it->second.mSslId << " PGP Id " << it->second.mPgpId;
|
||||
std::cerr << " PGP Name: " << it->second.mPgpName;
|
||||
std::cerr << " PGP Email: " << it->second.mPgpEmail;
|
||||
std::cerr << " Location: " << it->second.mLocation;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
ids.push_back(it->first);
|
||||
}
|
||||
|
@ -868,12 +879,16 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId)
|
|||
if (0 < AuthGPG::getAuthGPG() -> GPGInit(pgpId))
|
||||
{
|
||||
retVal = true;
|
||||
#ifdef DEBUG_ACCOUNTS
|
||||
std::cerr << "PGP Auth Success!";
|
||||
#endif
|
||||
}
|
||||
else
|
||||
std::cerr << "PGP Auth Failed!";
|
||||
|
||||
#ifdef DEBUG_ACCOUNTS
|
||||
std::cerr << " ID: " << pgpId << std::endl;
|
||||
#endif
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
// #define GPG_DEBUG
|
||||
// #define AUTHSSL_DEBUG
|
||||
// #define FIM_DEBUG
|
||||
// #define DEBUG_RSINIT
|
||||
|
||||
//std::map<std::string,std::vector<std::string> > RsInit::unsupported_keys ;
|
||||
|
||||
|
@ -270,303 +271,250 @@ bool doPortRestrictions = false;
|
|||
|
||||
#endif
|
||||
|
||||
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
int RsInit::InitRetroShare(int argc, char **argv, bool /* strictCheck */)
|
||||
{
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#else
|
||||
|
||||
/* for static PThreads under windows... we need to init the library...
|
||||
*/
|
||||
#ifdef PTW32_STATIC_LIB
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck)
|
||||
{
|
||||
|
||||
/* THIS IS A HACK TO ALLOW WINDOWS TO ACCEPT COMMANDLINE ARGUMENTS */
|
||||
int argc;
|
||||
int i;
|
||||
#ifdef USE_CMD_ARGS
|
||||
char** argv = argvIgnored;
|
||||
argc = argcIgnored;
|
||||
#else
|
||||
const int MAX_ARGS = 32;
|
||||
int j;
|
||||
char *argv[MAX_ARGS];
|
||||
char *wholeline = (char*)GetCommandLine();
|
||||
int cmdlen = strlen(wholeline);
|
||||
// duplicate line, so we can put in spaces..
|
||||
char dupline[cmdlen+1];
|
||||
strcpy(dupline, wholeline);
|
||||
|
||||
/* break wholeline down ....
|
||||
* NB. This is very simplistic, and will not
|
||||
* 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;
|
||||
#ifdef WINDOWS_SYS
|
||||
#ifdef PTW32_STATIC_LIB
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
for( i=0; i<argc; i++)
|
||||
printf("%d: %s\n", i, argv[i]);
|
||||
int RsInit::InitRetroShare(int _argc, char **_argv, bool /* strictCheck */)
|
||||
{
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifdef WINDOWS_SYS
|
||||
/* THIS IS A HACK TO ALLOW WINDOWS TO ACCEPT COMMANDLINE ARGUMENTS */
|
||||
|
||||
/* for static PThreads under windows... we need to init the library...
|
||||
*/
|
||||
#ifdef PTW32_STATIC_LIB
|
||||
pthread_win32_process_attach_np();
|
||||
#endif
|
||||
int argc;
|
||||
int i;
|
||||
const int MAX_ARGS = 32;
|
||||
int j;
|
||||
char *argv[MAX_ARGS];
|
||||
char *wholeline = (char*)GetCommandLine();
|
||||
int cmdlen = strlen(wholeline);
|
||||
// duplicate line, so we can put in spaces..
|
||||
char dupline[cmdlen+1];
|
||||
strcpy(dupline, wholeline);
|
||||
|
||||
/* break wholeline down ....
|
||||
* NB. This is very simplistic, and will not
|
||||
* 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;
|
||||
#else
|
||||
char **argv = _argv ;
|
||||
int argc = _argc ;
|
||||
#endif
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
std::string prefUserString = "";
|
||||
std::string opt_base_dir;
|
||||
#ifdef DEBUG_RSINIT
|
||||
for(int i=0; i<argc; i++)
|
||||
printf("%d: %s\n", i, argv[i]);
|
||||
#endif
|
||||
|
||||
/* getopt info: every availiable option is listed here. if it is followed by a ':' it
|
||||
needs an argument. If it is followed by a '::' the argument is optional.
|
||||
*/
|
||||
//rsInitConfig->logfname = "" ;
|
||||
//rsInitConfig->inet = "" ;
|
||||
/* for static PThreads under windows... we need to init the library... */
|
||||
#ifdef PTW32_STATIC_LIB
|
||||
pthread_win32_process_attach_np();
|
||||
#endif
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
std::string prefUserString = "";
|
||||
std::string opt_base_dir;
|
||||
|
||||
/* getopt info: every availiable option is listed here. if it is followed by a ':' it
|
||||
needs an argument. If it is followed by a '::' the argument is optional.
|
||||
*/
|
||||
//rsInitConfig->logfname = "" ;
|
||||
//rsInitConfig->inet = "" ;
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* HACK to avoid stupid OSX Finder behaviour
|
||||
* remove the commandline arguments - if we detect we are launched from Finder,
|
||||
/* HACK to avoid stupid OSX Finder behaviour
|
||||
* remove the commandline arguments - if we detect we are launched from Finder,
|
||||
* and we have the unparsable "-psn_0_12332" option.
|
||||
* this is okay, as you cannot pass commandline arguments via Finder anyway
|
||||
*/
|
||||
if ((argc >= 2) && (0 == strncmp(argv[1], "-psn", 4)))
|
||||
{
|
||||
argc = 1;
|
||||
}
|
||||
if ((argc >= 2) && (0 == strncmp(argv[1], "-psn", 4)))
|
||||
{
|
||||
argc = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
argstream as(argc,argv) ;
|
||||
argstream as(argc,argv) ;
|
||||
|
||||
|
||||
as >> option('a',"auto-login" ,rsInitConfig->autoLogin ,"AutoLogin (Windows Only) + StartMinimised")
|
||||
>> option('m',"minimized" ,rsInitConfig->startMinimised ,"Start minimized." )
|
||||
>> option('s',"stderr" ,rsInitConfig->outStderr ,"output to stderr instead of log file." )
|
||||
>> option('u',"udp" ,rsInitConfig->udpListenerOnly,"Only listen to UDP." )
|
||||
>> option('e',"external-port" ,rsInitConfig->forceExtPort ,"Use a forwarded external port." )
|
||||
as
|
||||
#ifdef RS_AUTOLOGIN
|
||||
>> option('a',"auto-login" ,rsInitConfig->autoLogin ,"AutoLogin (Windows Only) + StartMinimised")
|
||||
#endif
|
||||
>> option('m',"minimized" ,rsInitConfig->startMinimised ,"Start minimized." )
|
||||
>> option('s',"stderr" ,rsInitConfig->outStderr ,"output to stderr instead of log file." )
|
||||
>> option('u',"udp" ,rsInitConfig->udpListenerOnly,"Only listen to UDP." )
|
||||
>> option('e',"external-port" ,rsInitConfig->forceExtPort ,"Use a forwarded external port." )
|
||||
|
||||
>> parameter('l',"log-file" ,rsInitConfig->logfname ,"logfile" ,"Set Log filename." ,false)
|
||||
>> parameter('d',"debug-level" ,rsInitConfig->debugLevel ,"level" ,"Set debug level." ,false)
|
||||
>> parameter('w',"password" ,rsInitConfig->passwd ,"password" ,"Set Login Password." ,false)
|
||||
>> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Set IP address to use." ,false)
|
||||
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
|
||||
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
|
||||
>> parameter('U',"user-id" ,prefUserString ,"ID", "[User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled",false)
|
||||
// by rshare 'r' "link" "Link" "Open RsLink with protocol retroshare://"
|
||||
// by rshare 'f' "rsfile" "RsFile" "Open RsFile like RsCollection"
|
||||
>> parameter('l',"log-file" ,rsInitConfig->logfname ,"logfile" ,"Set Log filename." ,false)
|
||||
>> parameter('d',"debug-level" ,rsInitConfig->debugLevel ,"level" ,"Set debug level." ,false)
|
||||
#ifdef TO_REMOVE
|
||||
// This as removed because it is not used anymore.
|
||||
|
||||
>> parameter('w',"password" ,rsInitConfig->passwd ,"password" ,"Set Login Password." ,false)
|
||||
#endif
|
||||
>> parameter('i',"ip-address" ,rsInitConfig->inet ,"nnn.nnn.nnn.nnn", "Force IP address to use (if cannot be detected)." ,false)
|
||||
>> parameter('p',"port" ,rsInitConfig->port ,"port", "Set listenning port to use." ,false)
|
||||
>> parameter('c',"base-dir" ,opt_base_dir ,"directory", "Set base directory." ,false)
|
||||
>> parameter('U',"user-id" ,prefUserString ,"ID", "[ocation Id] Sets Account to Use, Useful when Autologin is enabled.",false)
|
||||
// by rshare 'r' "link" "Link" "Open RsLink with protocol retroshare://"
|
||||
// by rshare 'f' "rsfile" "RsFile" "Open RsFile like RsCollection"
|
||||
#ifdef LOCALNET_TESTING
|
||||
>> parameter('R',"restrict-port" ,portRestrictions ,"port1-port2","Apply port restriction" ,false)
|
||||
>> parameter('R',"restrict-port" ,portRestrictions ,"port1-port2","Apply port restriction" ,false)
|
||||
#endif
|
||||
>> help('h',"help","Display this Help") ;
|
||||
>> help('h',"help","Display this Help") ;
|
||||
|
||||
as.defaultErrorHandling(true) ;
|
||||
as.defaultErrorHandling(true,true) ;
|
||||
|
||||
if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ;
|
||||
if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ;
|
||||
if(!rsInitConfig->logfname.empty()) rsInitConfig->haveLogFile = true;
|
||||
if(rsInitConfig->inet != "127.0.0.1") rsInitConfig->forceLocalAddr = true;
|
||||
if(rsInitConfig->autoLogin) rsInitConfig->startMinimised = true ;
|
||||
if(rsInitConfig->outStderr) rsInitConfig->haveLogFile = false ;
|
||||
if(!rsInitConfig->logfname.empty()) rsInitConfig->haveLogFile = true;
|
||||
if(rsInitConfig->inet != "127.0.0.1") rsInitConfig->forceLocalAddr = true;
|
||||
#ifdef LOCALNET_TESTING
|
||||
if(!portRestrictions.empty()) doPortRestrictions = true;
|
||||
if(!portRestrictions.empty()) doPortRestrictions = true;
|
||||
#endif
|
||||
|
||||
#ifdef SUSPENDED_CODE
|
||||
#ifdef LOCALNET_TESTING
|
||||
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:R:")) != -1)
|
||||
#else
|
||||
while((c = getopt(argc, argv,"hesamui:p:c:w:l:d:U:r:")) != -1)
|
||||
#endif
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'h':
|
||||
std::cerr << "Help: " << std::endl;
|
||||
std::cerr << "The commandline options are for retroshare-nogui, a headless server in a shell, or systems without QT." << std::endl << std::endl;
|
||||
std::cerr << "-l [logfile] Set the logfilename" << std::endl;
|
||||
std::cerr << "-w [password] Set the password" << std::endl;
|
||||
std::cerr << "-i [ip_adress] Set IP Adress to use" << std::endl;
|
||||
std::cerr << "-p [port] Set the Port to listen on" << std::endl;
|
||||
std::cerr << "-c [basedir] Set the config basdir" << std::endl;
|
||||
std::cerr << "-s Output to Stderr" << std::endl;
|
||||
std::cerr << "-d [debuglevel] Set the debuglevel" << std::endl;
|
||||
std::cerr << "-a AutoLogin (Windows Only) + StartMinimised" << std::endl;
|
||||
std::cerr << "-m StartMinimised" << std::endl;
|
||||
std::cerr << "-u Only listen to UDP" << std::endl;
|
||||
std::cerr << "-e Use a forwarded external Port" << std::endl ;
|
||||
std::cerr << "-U [User Name/GPG id/SSL id] Sets Account to Use, Useful when Autologin is enabled." << std::endl;
|
||||
std::cerr << "-r link Use RetroShare link." << std::endl;
|
||||
#ifdef LOCALNET_TESTING
|
||||
std::cerr << "-R <lport-uport> Port Restrictions." << std::endl;
|
||||
#endif
|
||||
exit(1);
|
||||
break;
|
||||
default:
|
||||
if (strictCheck) {
|
||||
std::cerr << "Unknown Option!" << std::endl;
|
||||
std::cerr << "Use '-h' for help." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
setOutputLevel((RsLog::logLvl)rsInitConfig->debugLevel);
|
||||
|
||||
setOutputLevel((RsLog::logLvl)rsInitConfig->debugLevel);
|
||||
// set the debug file.
|
||||
if (rsInitConfig->haveLogFile)
|
||||
setDebugFile(rsInitConfig->logfname.c_str());
|
||||
|
||||
// // set the default Debug Level...
|
||||
// if (rsInitConfig->haveDebugLevel)
|
||||
// {
|
||||
// if ((rsInitConfig->debugLevel > 0) &&
|
||||
// (rsInitConfig->debugLevel <= PQL_DEBUG_ALL))
|
||||
// {
|
||||
// std::cerr << "Setting Debug Level to: ";
|
||||
// std::cerr << rsInitConfig->debugLevel;
|
||||
// std::cerr << std::endl;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// std::cerr << "Ignoring Invalid Debug Level: ";
|
||||
// std::cerr << rsInitConfig->debugLevel;
|
||||
// std::cerr << std::endl;
|
||||
// }
|
||||
// }
|
||||
|
||||
// set the debug file.
|
||||
if (rsInitConfig->haveLogFile)
|
||||
setDebugFile(rsInitConfig->logfname.c_str());
|
||||
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#else
|
||||
// Windows Networking Init.
|
||||
WORD wVerReq = MAKEWORD(2,2);
|
||||
WSADATA wsaData;
|
||||
// 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;
|
||||
}
|
||||
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 ******************/
|
||||
/********************************** 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;
|
||||
struct sigaction sigact;
|
||||
sigact.sa_handler = SIG_IGN;
|
||||
sigact.sa_flags = 0;
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
//sigaddset(&set, SIGINT); // or whatever other signal
|
||||
sigact.sa_mask = set;
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
//sigaddset(&set, SIGINT); // or whatever other signal
|
||||
sigact.sa_mask = set;
|
||||
|
||||
if (0 == sigaction(SIGPIPE, &sigact, NULL))
|
||||
{
|
||||
std::cerr << "RetroShare:: Successfully installed the SIGPIPE Block" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RetroShare:: Failed to install the SIGPIPE Block" << std::endl;
|
||||
}
|
||||
if (0 == sigaction(SIGPIPE, &sigact, NULL))
|
||||
{
|
||||
std::cerr << "RetroShare:: Successfully installed the SIGPIPE Block" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "RetroShare:: Failed to install the SIGPIPE Block" << std::endl;
|
||||
}
|
||||
#endif
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
// Hash the main executable.
|
||||
|
||||
uint64_t tmp_size ;
|
||||
// Hash the main executable.
|
||||
|
||||
if(!RsDirUtil::getFileHash(argv[0],rsInitConfig->main_executable_hash,tmp_size,NULL))
|
||||
std::cerr << "Cannot hash executable! Plugins will not be loaded correctly." << std::endl;
|
||||
else
|
||||
std::cerr << "Hashed main executable: " << rsInitConfig->main_executable_hash << std::endl;
|
||||
uint64_t tmp_size ;
|
||||
|
||||
/* At this point we want to.
|
||||
if(!RsDirUtil::getFileHash(argv[0],rsInitConfig->main_executable_hash,tmp_size,NULL))
|
||||
std::cerr << "Cannot hash executable! Plugins will not be loaded correctly." << std::endl;
|
||||
else
|
||||
std::cerr << "Hashed main executable: " << rsInitConfig->main_executable_hash << std::endl;
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
/* create singletons */
|
||||
AuthSSL::AuthSSLInit();
|
||||
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL, "");
|
||||
/* create singletons */
|
||||
AuthSSL::AuthSSLInit();
|
||||
AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL, "");
|
||||
|
||||
rsAccounts = new RsAccountsDetail();
|
||||
rsAccounts = new RsAccountsDetail();
|
||||
|
||||
// first check config directories, and set bootstrap values.
|
||||
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
|
||||
return RS_INIT_BASE_DIR_ERROR ;
|
||||
// first check config directories, and set bootstrap values.
|
||||
if(!rsAccounts->setupBaseDirectory(opt_base_dir))
|
||||
return RS_INIT_BASE_DIR_ERROR ;
|
||||
|
||||
// Setup PGP stuff.
|
||||
std::string pgp_dir = rsAccounts->PathPGPDirectory();
|
||||
// Setup PGP stuff.
|
||||
std::string pgp_dir = rsAccounts->PathPGPDirectory();
|
||||
|
||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
||||
if(!RsDirUtil::checkCreateDirectory(pgp_dir))
|
||||
throw std::runtime_error("Cannot create pgp directory " + pgp_dir) ;
|
||||
|
||||
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
|
||||
pgp_dir + "/retroshare_secret_keyring.gpg",
|
||||
pgp_dir + "/retroshare_trustdb.gpg",
|
||||
pgp_dir + "/lock");
|
||||
AuthGPG::init( pgp_dir + "/retroshare_public_keyring.gpg",
|
||||
pgp_dir + "/retroshare_secret_keyring.gpg",
|
||||
pgp_dir + "/retroshare_trustdb.gpg",
|
||||
pgp_dir + "/lock");
|
||||
|
||||
// load Accounts.
|
||||
if (!rsAccounts->loadAccounts())
|
||||
{
|
||||
return RS_INIT_NO_KEYRING ;
|
||||
}
|
||||
// load Accounts.
|
||||
if (!rsAccounts->loadAccounts())
|
||||
return RS_INIT_NO_KEYRING ;
|
||||
|
||||
// choose alternative account.
|
||||
if(prefUserString != "")
|
||||
{
|
||||
if (!rsAccounts->selectAccountByString(prefUserString))
|
||||
// choose alternative account.
|
||||
if(prefUserString != "")
|
||||
{
|
||||
std::cerr << "Invalid User name/GPG id/SSL id: not found in list";
|
||||
std::cerr << std::endl;
|
||||
return RS_INIT_AUTH_FAILED ;
|
||||
}
|
||||
}
|
||||
RsPeerId ssl_id(prefUserString);
|
||||
|
||||
/* check that we have selected someone */
|
||||
RsPeerId preferredId;
|
||||
bool existingUser = rsAccounts->getPreferredAccountId(preferredId);
|
||||
if(ssl_id.isNull())
|
||||
{
|
||||
std::cerr << "Invalid User location id: not found in list";
|
||||
std::cerr << std::endl;
|
||||
return RS_INIT_AUTH_FAILED ;
|
||||
}
|
||||
|
||||
if (existingUser)
|
||||
{
|
||||
if (rsInitConfig->passwd != "")
|
||||
{
|
||||
return RS_INIT_HAVE_ACCOUNT;
|
||||
if(rsAccounts->selectId(ssl_id))
|
||||
{
|
||||
std::cerr << "Auto-selectng account ID " << ssl_id << std::endl;
|
||||
return RS_INIT_HAVE_ACCOUNT;
|
||||
}
|
||||
}
|
||||
|
||||
if(RsLoginHandler::getSSLPassword(preferredId,false,rsInitConfig->passwd))
|
||||
#ifdef TO_REMOVE
|
||||
/* check that we have selected someone */
|
||||
RsPeerId preferredId;
|
||||
bool existingUser = rsAccounts->getPreferredAccountId(preferredId);
|
||||
|
||||
if (existingUser)
|
||||
{
|
||||
RsInit::setAutoLogin(true);
|
||||
std::cerr << "Autologin has succeeded" << std::endl;
|
||||
return RS_INIT_HAVE_ACCOUNT;
|
||||
if (rsInitConfig->passwd != "")
|
||||
|
||||
if(RsLoginHandler::getSSLPassword(preferredId,false,rsInitConfig->passwd))
|
||||
{
|
||||
RsInit::setAutoLogin(true);
|
||||
std::cerr << "Autologin has succeeded" << std::endl;
|
||||
return RS_INIT_HAVE_ACCOUNT;
|
||||
}
|
||||
}
|
||||
}
|
||||
return RS_INIT_OK;
|
||||
#endif
|
||||
return RS_INIT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -705,7 +653,9 @@ int RsInit::LoadCertificates(bool autoLoginNT)
|
|||
|
||||
if(rsInitConfig->passwd == "") {
|
||||
if (RsLoginHandler::getSSLPassword(preferredId,true,rsInitConfig->passwd) == false) {
|
||||
#ifdef DEBUG_RSINIT
|
||||
std::cerr << "RsLoginHandler::getSSLPassword() Failed!";
|
||||
#endif
|
||||
return 0 ;
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "util/rsdir.h"
|
||||
#include "rsaccounts.h"
|
||||
|
||||
//#define DEBUG_RSLOGINHANDLER 1
|
||||
|
||||
bool RsLoginHandler::getSSLPassword( const RsPeerId& ssl_id,
|
||||
bool enable_gpg_ask_passwd,
|
||||
std::string& ssl_passwd )
|
||||
|
@ -59,15 +61,21 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const RsPeerId& ssl_id,std::string&
|
|||
|
||||
fclose(sslPassphraseFile);
|
||||
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "opening sslPassphraseFile : "
|
||||
<< getSSLPasswdFileName(ssl_id).c_str() << std::endl;
|
||||
#endif
|
||||
|
||||
std::string plain;
|
||||
if ( AuthGPG::getAuthGPG()->decryptTextFromFile(
|
||||
plain, getSSLPasswdFileName(ssl_id)) )
|
||||
if ( AuthGPG::getAuthGPG()->decryptTextFromFile( plain, getSSLPasswdFileName(ssl_id)) )
|
||||
{
|
||||
std::cerr << "Decrypting went ok !" << std::endl;
|
||||
sslPassword = plain;
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
if(sslPassword.length() > 0)
|
||||
std::cerr << "Decrypting went ok !" << std::endl;
|
||||
else
|
||||
std::cerr << "Passphrase is empty!" << std::endl;
|
||||
#endif
|
||||
|
||||
return sslPassword.length() > 0 ;
|
||||
}
|
||||
|
@ -185,7 +193,9 @@ extern BOOL WINAPI CryptUnprotectData(
|
|||
|
||||
bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd)
|
||||
{
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "RsTryAutoLogin()" << std::endl;
|
||||
#endif
|
||||
|
||||
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef __HAIKU__
|
||||
|
@ -194,7 +204,9 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
|
|||
|
||||
gchar *passwd = NULL;
|
||||
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Using attribute: " << ssl_id << std::endl;
|
||||
#endif
|
||||
if( gnome_keyring_find_password_sync(&my_schema, &passwd,"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL) == GNOME_KEYRING_RESULT_OK )
|
||||
{
|
||||
std::cerr << "Got SSL passwd ********************" /*<< passwd*/ << " from gnome keyring" << std::endl;
|
||||
|
@ -203,7 +215,9 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
|
|||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Could not get passwd from gnome keyring" << std::endl;
|
||||
#endif
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
|
|
@ -252,8 +252,8 @@ namespace
|
|||
inline bool helpRequested() const;
|
||||
inline bool isOk() const;
|
||||
inline std::string errorLog() const;
|
||||
inline std::string usage() const;
|
||||
inline bool defaultErrorHandling(bool ignoreUnused=false) const;
|
||||
inline std::string usage(bool skipCommandLine = false) const;
|
||||
inline bool defaultErrorHandling(bool ignoreUnused=false,bool skipCommandLine=false) const;
|
||||
static inline char uniqueLetter();
|
||||
protected:
|
||||
void parse(int argc,char** argv);
|
||||
|
@ -569,10 +569,12 @@ namespace
|
|||
return helpRequested_;
|
||||
}
|
||||
inline std::string
|
||||
argstream::usage() const
|
||||
argstream::usage(bool skipCommandLine) const
|
||||
{
|
||||
std::ostringstream os;
|
||||
os<<"usage: "<<progName_<<cmdLine_<<'\n';
|
||||
|
||||
if(!skipCommandLine)
|
||||
os<<"usage: "<<progName_<<cmdLine_<<'\n';
|
||||
unsigned int lmax = 0;
|
||||
for (std::deque<help_entry>::const_iterator
|
||||
iter = argHelps_.begin();iter != argHelps_.end();++iter)
|
||||
|
@ -820,11 +822,11 @@ namespace
|
|||
return s;
|
||||
}
|
||||
inline bool
|
||||
argstream::defaultErrorHandling(bool ignoreUnused) const
|
||||
argstream::defaultErrorHandling(bool ignoreUnused,bool skipCommandLine) const
|
||||
{
|
||||
if (helpRequested_)
|
||||
{
|
||||
std::cout<<usage();
|
||||
std::cout<<usage(skipCommandLine);
|
||||
exit(1);
|
||||
}
|
||||
if (!isOk_)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue