mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-23 14:41:04 -04:00
fixed merge with upstream
This commit is contained in:
commit
5b9666855d
241 changed files with 20561 additions and 3381 deletions
|
@ -4,6 +4,7 @@
|
|||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2004-2008 by Robert Fernie.
|
||||
* Copyright (C) 2015-2018 Gioacchino Mazzurco <gio@eigenlab.org>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -332,27 +333,29 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
|||
d.hiddenNodePort = 0;
|
||||
d.hiddenType = RS_HIDDEN_TYPE_NONE;
|
||||
|
||||
if (sockaddr_storage_isnull(ps.localaddr))
|
||||
if(!sockaddr_storage_isnull(ps.localaddr))
|
||||
{
|
||||
sockaddr_storage_ipv6_to_ipv4(ps.localaddr);
|
||||
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
|
||||
d.localPort = sockaddr_storage_port(ps.localaddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
d.localAddr = "INVALID_IP";
|
||||
d.localPort = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d.localAddr = sockaddr_storage_iptostring(ps.localaddr);
|
||||
d.localPort = sockaddr_storage_port(ps.localaddr);
|
||||
}
|
||||
|
||||
if (sockaddr_storage_isnull(ps.serveraddr))
|
||||
if(!sockaddr_storage_isnull(ps.serveraddr))
|
||||
{
|
||||
sockaddr_storage_ipv6_to_ipv4(ps.serveraddr);
|
||||
d.extAddr = sockaddr_storage_iptostring(ps.serveraddr);
|
||||
d.extPort = sockaddr_storage_port(ps.serveraddr);
|
||||
}
|
||||
else
|
||||
{
|
||||
d.extAddr = "INVALID_IP";
|
||||
d.extPort = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d.extAddr = sockaddr_storage_iptostring(ps.serveraddr);
|
||||
d.extPort = sockaddr_storage_port(ps.serveraddr);
|
||||
}
|
||||
|
||||
d.dyndns = ps.dyndns;
|
||||
|
||||
|
@ -360,16 +363,16 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
|||
for(it = ps.ipAddrs.mLocal.mAddrs.begin();
|
||||
it != ps.ipAddrs.mLocal.mAddrs.end(); ++it)
|
||||
{
|
||||
sockaddr_storage_ipv6_to_ipv4(it->mAddr);
|
||||
std::string toto;
|
||||
toto += "L:";
|
||||
toto += sockaddr_storage_tostring(it->mAddr);
|
||||
rs_sprintf_append(toto, " %ld sec", time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back(toto);
|
||||
}
|
||||
for(it = ps.ipAddrs.mExt.mAddrs.begin(); it != ps.ipAddrs.mExt.mAddrs.end(); ++it)
|
||||
{
|
||||
sockaddr_storage_ipv6_to_ipv4(it->mAddr);
|
||||
std::string toto;
|
||||
toto += "E:";
|
||||
toto += sockaddr_storage_tostring(it->mAddr);
|
||||
rs_sprintf_append(toto, " %ld sec", time(NULL) - it->mSeenTime);
|
||||
d.ipAddressList.push_back(toto);
|
||||
|
@ -416,6 +419,7 @@ bool p3Peers::getPeerDetails(const RsPeerId& id, RsPeerDetails &d)
|
|||
|
||||
if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
sockaddr_storage_ipv6_to_ipv4(pcs.connectaddr);
|
||||
d.connectAddr = sockaddr_storage_iptostring(pcs.connectaddr);
|
||||
d.connectPort = sockaddr_storage_port(pcs.connectaddr);
|
||||
}
|
||||
|
@ -900,68 +904,33 @@ bool p3Peers::setHiddenNode(const RsPeerId &id, const std::string &address, uin
|
|||
return true;
|
||||
}
|
||||
|
||||
bool p3Peers::setLocalAddress(const RsPeerId &id, const std::string &addr_str, uint16_t port)
|
||||
bool p3Peers::setLocalAddress(const RsPeerId &id,
|
||||
const std::string &addr_str, uint16_t port)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setLocalAddress() " << id << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " " << id << " " << addr_str << " "
|
||||
<< port << std::endl;
|
||||
#endif
|
||||
|
||||
if(port < 1024)
|
||||
{
|
||||
std::cerr << "(EE) attempt to use a port that is reserved to the system: " << port << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &addr;
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_port = htons(port);
|
||||
|
||||
int ret = 1;
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
if (ret && (0 != inet_aton(addr_str.c_str(), &(addrv4p->sin_addr))))
|
||||
#else
|
||||
addrv4p->sin_addr.s_addr = inet_addr(addr_str.c_str());
|
||||
if (ret)
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
return mPeerMgr->setLocalAddress(id, addr);
|
||||
}
|
||||
sockaddr_storage addr;
|
||||
if (sockaddr_storage_inet_pton(addr, addr_str))
|
||||
if (sockaddr_storage_setport(addr, port))
|
||||
return mPeerMgr->setLocalAddress(id, addr);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool p3Peers::setExtAddress(const RsPeerId &id, const std::string &addr_str, uint16_t port)
|
||||
bool p3Peers::setExtAddress(const RsPeerId &id,
|
||||
const std::string &addr_str, uint16_t port)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
std::cerr << "p3Peers::setExtAddress() " << id << std::endl;
|
||||
std::cerr << __PRETTY_FUNCTION__ << " " << id << " " << addr_str << " "
|
||||
<< port << std::endl;
|
||||
#endif
|
||||
if(port < 1024)
|
||||
{
|
||||
std::cerr << "(EE) attempt to use a port that is reserved to the system: " << port << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
|
||||
// NOTE THIS IS IPV4 FOR NOW.
|
||||
struct sockaddr_storage addr;
|
||||
struct sockaddr_in *addrv4p = (struct sockaddr_in *) &addr;
|
||||
addrv4p->sin_family = AF_INET;
|
||||
addrv4p->sin_port = htons(port);
|
||||
|
||||
int ret = 1;
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
if (ret && (0 != inet_aton(addr_str.c_str(), &(addrv4p->sin_addr))))
|
||||
#else
|
||||
addrv4p->sin_addr.s_addr = inet_addr(addr_str.c_str());
|
||||
if (ret)
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
return mPeerMgr->setExtAddress(id, addr);
|
||||
}
|
||||
sockaddr_storage addr;
|
||||
if (sockaddr_storage_inet_pton(addr, addr_str))
|
||||
if (sockaddr_storage_setport(addr, port))
|
||||
return mPeerMgr->setExtAddress(id, addr);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -1085,22 +1054,22 @@ std::string p3Peers::getPGPKey(const RsPgpId& pgp_id,bool include_signatures)
|
|||
unsigned char *mem_block = NULL;
|
||||
size_t mem_block_size = 0;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->exportPublicKey(RsPgpId(pgp_id),mem_block,mem_block_size,false,include_signatures))
|
||||
if( !AuthGPG::getAuthGPG()->exportPublicKey(
|
||||
RsPgpId(pgp_id), mem_block, mem_block_size,
|
||||
false, include_signatures ) )
|
||||
{
|
||||
std::cerr << "Cannot output certificate for id \"" << pgp_id << "\". Sorry." << std::endl;
|
||||
std::cerr << "Cannot output certificate for id \"" << pgp_id
|
||||
<< "\". Sorry." << std::endl;
|
||||
return "" ;
|
||||
}
|
||||
|
||||
RsPeerDetails Detail ;
|
||||
RsPeerDetails Detail;
|
||||
if(!getGPGDetails(pgp_id,Detail)) return "";
|
||||
|
||||
if(!getGPGDetails(pgp_id,Detail) )
|
||||
return "" ;
|
||||
RsCertificate cert( Detail,mem_block,mem_block_size );
|
||||
delete[] mem_block ;
|
||||
|
||||
RsCertificate cert( Detail,mem_block,mem_block_size ) ;
|
||||
|
||||
delete[] mem_block ;
|
||||
|
||||
return cert.armouredPGPKey() ;
|
||||
return cert.armouredPGPKey();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1358,11 +1358,11 @@ int RsServer::StartupRetroShare()
|
|||
|
||||
p3Wiki *mWiki = new p3Wiki(wiki_ds, NULL, mGxsIdService);
|
||||
// create GXS wiki service
|
||||
RsGxsNetService* wiki_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
|
||||
mWiki, mWiki->getServiceInfo(),
|
||||
mGxsIdService, mGxsCircles,
|
||||
pgpAuxUtils);
|
||||
RsGxsNetService* wiki_ns = new RsGxsNetService(
|
||||
RS_SERVICE_GXS_TYPE_WIKI, wiki_ds, nxsMgr,
|
||||
mWiki, mWiki->getServiceInfo(),
|
||||
mReputations, mGxsCircles, mGxsIdService,
|
||||
pgpAuxUtils);
|
||||
|
||||
mWiki->setNetworkExchangeService(wiki_ns) ;
|
||||
#endif
|
||||
|
|
|
@ -109,6 +109,19 @@ GnomeKeyringPasswordSchema my_schema = {
|
|||
NULL,
|
||||
NULL
|
||||
};
|
||||
#elif defined(HAS_LIBSECRET)
|
||||
#include <libsecret-1/libsecret/secret.h>
|
||||
const SecretSchema *libsecret_get_schema(void)
|
||||
{
|
||||
static const SecretSchema the_schema = {
|
||||
"org.Retroshare.Password", SECRET_SCHEMA_NONE,
|
||||
{
|
||||
{ "RetroShare SSL Id", SECRET_SCHEMA_ATTRIBUTE_STRING },
|
||||
{ "NULL", (SecretSchemaAttributeType)0 },
|
||||
}
|
||||
};
|
||||
return &the_schema;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -209,7 +222,7 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
|
|||
#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;
|
||||
std::cout << "Got SSL passwd ********************" /*<< passwd*/ << " from gnome keyring" << std::endl;
|
||||
ssl_passwd = std::string(passwd);
|
||||
return true ;
|
||||
}
|
||||
|
@ -220,7 +233,41 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
|
|||
#endif
|
||||
return false ;
|
||||
}
|
||||
#elif defined(HAS_LIBSECRET)
|
||||
// do synchronous lookup
|
||||
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Using attribute: " << ssl_id << std::endl;
|
||||
#endif
|
||||
|
||||
GError *error = NULL;
|
||||
gchar *password = secret_password_lookup_sync (libsecret_get_schema(), NULL, &error,
|
||||
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
|
||||
NULL);
|
||||
|
||||
if (error != NULL) {
|
||||
g_error_free (error);
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Could not get passwd using libsecret: error" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
} else if (password == NULL) {
|
||||
/* password will be null, if no matching password found */
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Could not get passwd using libsecret: not found" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
} else {
|
||||
std::cout << "Got SSL passwd ********************" /*<< passwd*/ << " using libsecret" << std::endl;
|
||||
ssl_passwd = std::string(password);
|
||||
|
||||
secret_password_free (password);
|
||||
return true;
|
||||
}
|
||||
#ifdef DEBUG_RSLOGINHANDLER
|
||||
std::cerr << "Could not get passwd from gnome keyring: unknown" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
#else
|
||||
/******************** OSX KeyChain stuff *****************************/
|
||||
#ifdef __APPLE__
|
||||
|
@ -281,7 +328,7 @@ bool RsLoginHandler::tryAutoLogin(const RsPeerId& ssl_id,std::string& ssl_passwd
|
|||
|
||||
/******************** OSX KeyChain stuff *****************************/
|
||||
#endif // APPLE
|
||||
#endif // HAS_GNOME_KEYRING
|
||||
#endif // HAS_GNOME_KEYRING / HAS_LIBSECRET
|
||||
#else /******* WINDOWS BELOW *****/
|
||||
|
||||
/* try to load from file */
|
||||
|
@ -405,9 +452,9 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
|
|||
#ifndef __HAIKU__
|
||||
#ifndef WINDOWS_SYS /* UNIX */
|
||||
#if defined(HAS_GNOME_KEYRING) || defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_store_password_sync(&my_schema, NULL, (gchar*)("RetroShare password for SSL Id "+ssl_id.toStdString()).c_str(),(gchar*)ssl_passwd.c_str(),"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL))
|
||||
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_store_password_sync(&my_schema, NULL, (gchar*)("RetroShare password for SSL Id "+ssl_id.toStdString()).c_str(),(gchar*)ssl_passwd.c_str(),"RetroShare SSL Id",ssl_id.toStdString().c_str(),NULL))
|
||||
{
|
||||
std::cerr << "Stored passwd " << "************************" << " into gnome keyring" << std::endl;
|
||||
std::cout << "Stored passwd " << "************************" << " into gnome keyring" << std::endl;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
|
@ -415,6 +462,24 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
|
|||
std::cerr << "Could not store passwd into gnome keyring" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
#elif defined(HAS_LIBSECRET)
|
||||
// do synchronous store
|
||||
|
||||
GError *error = NULL;
|
||||
secret_password_store_sync (libsecret_get_schema(), SECRET_COLLECTION_DEFAULT,
|
||||
(gchar*)("RetroShare password for SSL Id " + ssl_id.toStdString()).c_str(),
|
||||
(gchar*)ssl_passwd.c_str(),
|
||||
NULL, &error,
|
||||
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
|
||||
NULL);
|
||||
|
||||
if (error != NULL) {
|
||||
g_error_free (error);
|
||||
std::cerr << "Could not store passwd using libsecret" << std::endl;
|
||||
return false;
|
||||
}
|
||||
std::cout << "Stored passwd " << "************************" << " using libsecret" << std::endl;
|
||||
return true;
|
||||
#else
|
||||
#ifdef __APPLE__
|
||||
/***************** OSX KEYCHAIN ****************/
|
||||
|
@ -484,7 +549,7 @@ bool RsLoginHandler::enableAutoLogin(const RsPeerId& ssl_id,const std::string& s
|
|||
return true;
|
||||
#endif // TODO_CODE_ROTTEN
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_GNOME_KEYRING.
|
||||
#endif // HAS_GNOME_KEYRING / HAS_LIBSECRET
|
||||
#else /* windows */
|
||||
|
||||
/* store password encrypted in a file */
|
||||
|
@ -571,7 +636,7 @@ bool RsLoginHandler::clearAutoLogin(const RsPeerId& ssl_id)
|
|||
#ifdef HAS_GNOME_KEYRING
|
||||
if(GNOME_KEYRING_RESULT_OK == gnome_keyring_delete_password_sync(&my_schema,"RetroShare SSL Id", ssl_id.toStdString().c_str(),NULL))
|
||||
{
|
||||
std::cerr << "Successfully Cleared gnome keyring passwd for SSLID " << ssl_id << std::endl;
|
||||
std::cout << "Successfully Cleared gnome keyring passwd for SSLID " << ssl_id << std::endl;
|
||||
return true ;
|
||||
}
|
||||
else
|
||||
|
@ -579,7 +644,26 @@ bool RsLoginHandler::clearAutoLogin(const RsPeerId& ssl_id)
|
|||
std::cerr << "Could not clear gnome keyring passwd for SSLID " << ssl_id << std::endl;
|
||||
return false ;
|
||||
}
|
||||
#else
|
||||
#elif defined(HAS_LIBSECRET)
|
||||
// do synchronous clear
|
||||
|
||||
GError *error = NULL;
|
||||
gboolean removed = secret_password_clear_sync (libsecret_get_schema(), NULL, &error,
|
||||
"RetroShare SSL Id", ssl_id.toStdString().c_str(),
|
||||
NULL);
|
||||
|
||||
if (error != NULL) {
|
||||
g_error_free (error);
|
||||
std::cerr << "Could not clearpasswd for SSLID " << ssl_id << " using libsecret: error" << std::endl;
|
||||
return false ;
|
||||
} else if (removed == FALSE) {
|
||||
std::cerr << "Could not clearpasswd for SSLID " << ssl_id << " using libsecret: false" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
std::cout << "Successfully Cleared passwd for SSLID " << ssl_id << " using libsecret" << std::endl;
|
||||
return true ;
|
||||
#else // HAS_GNOME_KEYRING / HAS_LIBSECRET
|
||||
#ifdef __APPLE__
|
||||
|
||||
std::cerr << "clearAutoLogin() OSX Version" << std::endl;
|
||||
|
|
|
@ -75,5 +75,3 @@ std::ostream &operator<<(std::ostream &out, const FileInfo &info)
|
|||
out << "Hash: " << info.hash;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue