Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2225)

Unified Diff: media/tools/constrained_network_server/traffic_control.py

Issue 9125022: Add root access check to cns server. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Edit error msg. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/tools/constrained_network_server/cns.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/tools/constrained_network_server/traffic_control.py
diff --git a/media/tools/constrained_network_server/traffic_control.py b/media/tools/constrained_network_server/traffic_control.py
index c27a255365b766cdd68ade24204916fc9d02285d..38756776ca98f9818c9c566937eca11ec7af1251 100755
--- a/media/tools/constrained_network_server/traffic_control.py
+++ b/media/tools/constrained_network_server/traffic_control.py
@@ -9,6 +9,7 @@ Traffic to the constrained port is forwarded to a specified server port.
"""
import logging
+import os
import re
import subprocess
@@ -37,6 +38,22 @@ class TrafficControlError(BaseException):
self.error = error
+def CheckRequirements():
+ """Checks if permissions are available to run traffic control commands.
+
+ Raises:
+ TrafficControlError: If permissions to run traffic control commands are not
+ available.
+ """
+ if os.geteuid() != 0:
+ _Exec(['sudo', '-n', 'tc', '-help'],
Ami GONE FROM CHROMIUM 2012/01/10 22:30:56 Note that this isn't fool-proof; sudo uses an expi
+ msg=('Cannot run \'tc\' command. Traffic Control must be run as root '
+ 'or have password-less sudo access to this command.'))
+ _Exec(['sudo', '-n', 'iptables', '-help'],
+ msg=('Cannot run \'iptables\' command. Traffic Control must be run '
+ 'as root or have password-less sudo access to this command.'))
+
+
def CreateConstrainedPort(config):
"""Creates a new constrained port.
« no previous file with comments | « media/tools/constrained_network_server/cns.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698