1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-06 06:07:37 +02:00

* Don't accept 0.0.0.0 as a visible / valid address.

This commit is contained in:
Christian Muehlhaeuser
2011-11-28 16:36:01 +01:00
parent 48d07a679b
commit 7c9fc46caa
2 changed files with 24 additions and 18 deletions

View File

@@ -63,8 +63,8 @@ Servent::Servent( QObject* parent )
{ {
s_instance = this; s_instance = this;
m_lanHack = qApp->arguments().contains( "--lanhack" );
new ACLSystem( this ); new ACLSystem( this );
setProxy( QNetworkProxy::NoProxy ); setProxy( QNetworkProxy::NoProxy );
{ {
@@ -142,7 +142,7 @@ Servent::startListening( QHostAddress ha, bool upnp, int port )
case TomahawkSettings::Upnp: case TomahawkSettings::Upnp:
// TODO check if we have a public/internet IP on this machine directly // TODO check if we have a public/internet IP on this machine directly
tLog() << "External address mode set to upnp...."; tLog() << "External address mode set to upnp...";
m_portfwd = new PortFwdThread( m_port ); m_portfwd = new PortFwdThread( m_port );
connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ), connect( m_portfwd, SIGNAL( externalAddressDetected( QHostAddress, unsigned int ) ),
SLOT( setExternalAddress( QHostAddress, unsigned int ) ) ); SLOT( setExternalAddress( QHostAddress, unsigned int ) ) );
@@ -171,6 +171,19 @@ Servent::createConnectionKey( const QString& name, const QString &nodeid, const
} }
bool
Servent::isValidExternalIP( const QHostAddress& addr ) const
{
QString ip = addr.toString();
if ( !m_lanHack && ( ip.startsWith( "10." ) || ip.startsWith( "172.16." ) || ip.startsWith( "192.168." ) ) )
{
return false;
}
return !addr.isNull();
}
void void
Servent::setInternalAddress() Servent::setInternalAddress()
{ {
@@ -181,7 +194,7 @@ Servent::setInternalAddress()
if ( ha.toString().contains( ":" ) ) if ( ha.toString().contains( ":" ) )
continue; //ipv6 continue; //ipv6
if ( qApp->arguments().contains( "--lanhack" ) ) if ( m_lanHack && isValidExternalIP( ha ) )
{ {
tLog() << "LANHACK: set external address to lan address" << ha.toString(); tLog() << "LANHACK: set external address to lan address" << ha.toString();
setExternalAddress( ha, m_port ); setExternalAddress( ha, m_port );
@@ -199,26 +212,13 @@ Servent::setInternalAddress()
void void
Servent::setExternalAddress( QHostAddress ha, unsigned int port ) Servent::setExternalAddress( QHostAddress ha, unsigned int port )
{ {
QString ip = ha.toString(); if ( isValidExternalIP( ha ) )
if ( !qApp->arguments().contains( "--lanhack" ) )
{
if ( ip.startsWith( "10." ) || ip.startsWith( "172.16." ) || ip.startsWith( "192.168." ) )
{
tDebug() << Q_FUNC_INFO << "Tried to set an invalid ip as external address!";
setInternalAddress();
return;
}
m_externalAddress = ha;
m_externalPort = port;
}
else
{ {
m_externalAddress = ha; m_externalAddress = ha;
m_externalPort = port; m_externalPort = port;
} }
if ( m_externalPort == 0 || m_externalAddress.toString().isEmpty() ) if ( m_externalPort == 0 || !isValidExternalIP( ha ) )
{ {
if ( !TomahawkSettings::instance()->externalHostname().isEmpty() && if ( !TomahawkSettings::instance()->externalHostname().isEmpty() &&
!TomahawkSettings::instance()->externalPort() == 0 ) !TomahawkSettings::instance()->externalPort() == 0 )
@@ -228,7 +228,11 @@ Servent::setExternalAddress( QHostAddress ha, unsigned int port )
tDebug() << "UPnP failed, have external address/port - falling back" << m_externalHostname << m_externalPort << m_externalAddress; tDebug() << "UPnP failed, have external address/port - falling back" << m_externalHostname << m_externalPort << m_externalAddress;
} }
else else
{
tLog() << "No external access, LAN and outbound connections only!"; tLog() << "No external access, LAN and outbound connections only!";
setInternalAddress();
return;
}
} }
m_ready = true; m_ready = true;

View File

@@ -152,6 +152,7 @@ private slots:
Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any ); Connection* claimOffer( ControlConnection* cc, const QString &nodeid, const QString &key, const QHostAddress peer = QHostAddress::Any );
private: private:
bool isValidExternalIP( const QHostAddress& addr ) const;
void handoverSocket( Connection* conn, QTcpSocketExtra* sock ); void handoverSocket( Connection* conn, QTcpSocketExtra* sock );
bool checkACL( const Connection* conn, const QString &nodeid, bool showDialog ) const; bool checkACL( const Connection* conn, const QString &nodeid, bool showDialog ) const;
void printCurrentTransfers(); void printCurrentTransfers();
@@ -165,6 +166,7 @@ private:
QHostAddress m_externalAddress; QHostAddress m_externalAddress;
QString m_externalHostname; QString m_externalHostname;
bool m_ready; bool m_ready;
bool m_lanHack;
// currently active file transfers: // currently active file transfers:
QList< StreamConnection* > m_scsessions; QList< StreamConnection* > m_scsessions;