1

My program runs with root privileges, but I need a portion to run as an unprivileged user.

Basically, webbrowser.open(SITE) doesn't work as root. My code needs to run as root other than this. I've tried the following:

subprocess.call("sudo -u " + getpass.getuser() + " " + webbrowser.open("https://github.com/codywd/WiFiz/issues"))

It causes the following error:

Traceback (most recent call last):
  File "main.py", line 364, in OnReport
    subprocess.call("sudo -u " + getpass.getuser() + " " + webbrowser.open("https://github.com/codywd/WiFiz/issues"))
TypeError: cannot concatenate 'str' and 'bool' objects
START /usr/bin/chromium "https://github.com/codywd/WiFiz/issues"
[7250:7250:0201/231848:ERROR:chrome_browser_main_extra_parts_gtk.cc(50)] Startup refusing to run as root.

I understand WHY this error is happening, but I don't know how else to execute this code.

Thanks in advance guys!

Cody Dostal
  • 311
  • 1
  • 3
  • 13

1 Answers1

1

Looks like the answers given here are what you are looking for: Run child processes as different user from a long running Python process

However, since I can not find a way to directly access the subprocess started inside the webbrowser.open (see doc on http://docs.python.org/2/library/webbrowser.html), you have two options:

  • drop the webbrowser module from your code, open the browser via subprocess calls. On this you can set UID and GID bits.
  • set a wrapper arround the webbrowser (expanded below)
  1. Create a new python script, start normally webbrowser.open from there.

  2. Inside your main program create a subprocess, with the right UID + GID, this will call your wrapper script described at 1).

BogdanBiv
  • 1,485
  • 1
  • 16
  • 33