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

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: 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..1b775a0d03ac1af414afbb00bb34a07a1bca68f3 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,28 @@ class TrafficControlError(BaseException):
self.error = error
+def CheckRequirements():
+ """Checks if requirements are available to run traffic control commands.
DaleCurtis 2012/01/09 19:08:02 s/requirements/permissions ?
shadi 2012/01/09 23:47:44 Done.
+
+ Raises:
+ TrafficControlError: If requirements to run traffic control commands are not
+ available.
+ """
+ if os.geteuid() == 0:
DaleCurtis 2012/01/09 19:08:02 Not quite correct. You want os.geteuid() == 0 _OR_
shadi 2012/01/09 23:47:44 Shouldn't the sudo -n <blah> pass if os.geteuid()
+ try:
+ command = ['sudo', '-n', 'iptables', '-L']
DaleCurtis 2012/01/09 19:08:02 For short commands like these you might consider i
shadi 2012/01/09 23:47:44 Done.
+ _Exec(command)
+ # tc commands only ask for root access when modifying the network state.
+ command = ['sudo', '-n', 'tc', 'qdisc', 'add']
DaleCurtis 2012/01/09 19:08:02 For both of these it's enough to just run "--help"
shadi 2012/01/09 23:47:44 I thought we want to try to run a command that *do
+ _Exec(command)
+ except TrafficControlError as e:
+ if 'No such device' in e.error:
+ return
+ pass
+ raise TrafficControlError('Cannot run traffic control commands. Please check '
+ 'that you have root access.')
+
+
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