[tor-commits] [stem/master] Pattern used by the ss connection resolver didn't work on Gentoo
atagar at torproject.org
atagar at torproject.org
Sat Jan 16 23:35:59 UTC 2016
commit 5f47e1ff4d79d1395e1ebca996931af932d0d3d6
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Jan 16 14:11:22 2016 -0800
Pattern used by the ss connection resolver didn't work on Gentoo
Nice catch by toralf! On Gentoo our ss connection resolver didn't work...
https://trac.torproject.org/projects/tor/ticket/18079
Reason is a slight difference at the end of lines. On Ubuntu I just have
values, but Gentoo labels what they are...
Ubuntu: users:(("ssh",16694,3))
Gentoo: users:(("tor",pid=25056,fd=997))
Easy to fix. The resolver now accepts both.
---
docs/change_log.rst | 1 +
stem/util/connection.py | 2 +-
test/unit/util/connection.py | 26 ++++++++++++++++++++++++++
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 798eb86..359156e 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -72,6 +72,7 @@ The following are only available within Stem's `git repository
* **Utilities**
* Added :func:`~stem.util.__init__.datetime_to_unix`
+ * Pattern used by our 'ss' connection resolver didn't work on Gentoo (:trac:`18079`)
* **Interpreter**
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 7d1adb0..c780f2d 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -116,7 +116,7 @@ RESOLVER_FILTER = {
Resolver.NETSTAT_WINDOWS: '^\s*{protocol}\s+{local_address}:{local_port}\s+{remote_address}:{remote_port}\s+ESTABLISHED\s+{pid}\s*$',
# tcp ESTAB 0 0 192.168.0.20:44415 38.229.79.2:443 users:(("tor",15843,9))
- Resolver.SS: '^{protocol}\s+ESTAB\s+.*\s+{local_address}:{local_port}\s+{remote_address}:{remote_port}\s+users:\(\("{name}",{pid},[0-9]+\)\)$',
+ Resolver.SS: '^{protocol}\s+ESTAB\s+.*\s+{local_address}:{local_port}\s+{remote_address}:{remote_port}\s+users:\(\("{name}",(?:pid=)?{pid},(?:fd=)?[0-9]+\)\)$',
# tor 3873 atagar 45u IPv4 40994 0t0 TCP 10.243.55.20:45724->194.154.227.109:9001 (ESTABLISHED)
Resolver.LSOF: '^{name}\s+{pid}\s+.*\s+{protocol}\s+{local_address}:{local_port}->{remote_address}:{remote_port} \(ESTABLISHED\)$',
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index c63f97f..8f3820c 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -53,6 +53,16 @@ tcp ESTAB 0 0 127.0.0.1:22 127.0.0.1:56673
tcp ESTAB 0 0 192.168.0.1:44415 38.229.79.2:443 users:(("tor",15843,9))
"""
+SS_GENTOO_OUTPUT = """\
+Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
+tcp ESTAB 0 0 5.9.158.75:443 107.170.93.13:56159 users:(("tor",pid=25056,fd=997))
+tcp ESTAB 0 0 5.9.158.75:443 159.203.97.91:37802 users:(("tor",pid=25056,fd=77))
+tcp ESTAB 0 0 2a01:4f8:190:514a::2:443 2001:638:a000:4140::ffff:189:38556 users:(("tor",pid=25056,fd=3175))
+tcp ESTAB 0 0 ::ffff:5.9.158.75:5222 ::ffff:78.54.131.65:34950 users:(("beam",pid=1712,fd=29))
+tcp ESTAB 0 0 2a01:4f8:190:514a::2:443 2001:858:2:2:aabb:0:563b:1526:51428 users:(("tor",pid=25056,fd=3248))
+tcp ESTAB 0 0 ::ffff:5.9.158.75:5222 ::ffff:78.54.131.65:34882 users:(("beam",pid=1712,fd=26))
+"""
+
LSOF_OUTPUT = """\
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ubuntu-ge 2164 atagar 11u IPv4 13593 0t0 TCP 192.168.0.1:55395->21.89.91.78:80 (CLOSE_WAIT)
@@ -231,6 +241,22 @@ class TestConnection(unittest.TestCase):
self.assertRaises(IOError, stem.util.connection.get_connections, Resolver.SS, process_pid = 1111)
@patch('stem.util.system.call')
+ def test_get_connections_by_ss_on_gentoo(self, call_mock):
+ """
+ Checks the get_connections function with the ss resolver results on a
+ hardened Gentoo system...
+
+ https://trac.torproject.org/projects/tor/ticket/18079
+ """
+
+ call_mock.return_value = SS_GENTOO_OUTPUT.split('\n')
+ expected = [
+ Connection('5.9.158.75', 443, '107.170.93.13', 56159, 'tcp'),
+ Connection('5.9.158.75', 443, '159.203.97.91', 37802, 'tcp'),
+ ]
+ self.assertEqual(expected, stem.util.connection.get_connections(Resolver.SS, process_pid = 25056, process_name = 'tor'))
+
+ @patch('stem.util.system.call')
def test_get_connections_by_lsof(self, call_mock):
"""
Checks the get_connections function with the lsof resolver.
More information about the tor-commits
mailing list