OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 |
| 3 suid-python <<END |
| 4 |
| 5 import Foundation |
| 6 import os |
| 7 import subprocess |
| 8 import tempfile |
| 9 import time |
| 10 import signal |
| 11 |
| 12 SERVICE_NAME = "org.chromium.chromoting" |
| 13 |
| 14 def get_job_pid(): |
| 15 process = subprocess.Popen(["launchctl", "list"], stdout=subprocess.PIPE) |
| 16 pid = None |
| 17 for line in process.stdout: |
| 18 # Format is: |
| 19 # 12345 - my.job (if my.job is running, number is job's PID) |
| 20 # - 0 my.other.job (if my.other.job is not running) |
| 21 print "*** %s ***" % line |
| 22 fields = line.strip().split('\t') |
| 23 print "*** field 2=%s, field 0=%s ***" % (fields[2], fields[0]) |
| 24 if fields[2] == SERVICE_NAME and fields[0] != "-": |
| 25 pid = fields[0] |
| 26 break |
| 27 process.wait() |
| 28 return pid |
| 29 |
| 30 print "*** Started mock pref pane ***" |
| 31 print "*** EUID=%d, UID=%d ***" % (os.geteuid(), os.getuid()) |
| 32 |
| 33 config_file = os.path.join(tempfile.gettempdir(), |
| 34 "%s.json" % SERVICE_NAME) |
| 35 |
| 36 print "*** config_file=%s" % config_file |
| 37 |
| 38 tool_script = "/Library/PrivilegedHelperTools/%s.me2me.sh" % SERVICE_NAME |
| 39 |
| 40 real_user_id = os.getuid() |
| 41 |
| 42 # Elevate privileges, otherwise tool_script executes with EUID != 0. |
| 43 os.setuid(0) |
| 44 subprocess.call([tool_script, "--save-config"], stdin=open(config_file)) |
| 45 |
| 46 # Drop privileges, in order to start the launchd job as the logged-in user. |
| 47 os.setuid(real_user_id) |
| 48 os.kill(int(get_job_pid()), signal.SIGHUP) |
| 49 |
| 50 notification_center = Foundation.NSDistributedNotificationCenter.defaultCenter() |
| 51 notification_center.postNotificationName_object_userInfo_( |
| 52 SERVICE_NAME + ".update_succeeded", None, None) |
| 53 |
| 54 time.sleep(10) |
| 55 |
| 56 END |
OLD | NEW |