(self, method_name, sudo_pythonpath)
| 208 | class FirewallClient: |
| 209 | |
| 210 | def __init__(self, method_name, sudo_pythonpath): |
| 211 | self.auto_nets = [] |
| 212 | |
| 213 | argv0 = sys.argv[0] |
| 214 | # argv0 is either be a normal Python file or an executable. |
| 215 | # After installed as a package, sshuttle command points to an .exe in Windows and Python shebang script elsewhere. |
| 216 | argvbase = (([sys.executable, sys.argv[0]] if argv0.endswith('.py') else [argv0]) + |
| 217 | ['-v'] * (helpers.verbose or 0) + |
| 218 | ['--method', method_name] + |
| 219 | ['--firewall']) |
| 220 | if ssyslog._p: |
| 221 | argvbase += ['--syslog'] |
| 222 | |
| 223 | # A list of commands that we can try to run to start the firewall. |
| 224 | argv_tries = [] |
| 225 | |
| 226 | if is_admin_user(): # No need to elevate privileges |
| 227 | argv_tries.append(argvbase) |
| 228 | else: |
| 229 | if sys.platform == 'win32': |
| 230 | # runas_path = which("runas") |
| 231 | # if runas_path: |
| 232 | # argv_tries.append([runas_path , '/noprofile', '/user:Administrator', 'python']) |
| 233 | # XXX: Attempt to elevate privilege using 'runas' in windows seems not working. |
| 234 | # Because underlying ShellExecute() Windows api does not allow child process to inherit stdio. |
| 235 | # TODO(nom3ad): Try to implement another way to achieve this. |
| 236 | raise Fatal("Privilege elevation for Windows is not yet implemented. Please run from an administrator shell") |
| 237 | |
| 238 | # Linux typically uses sudo; OpenBSD uses doas. However, some |
| 239 | # Linux distributions are starting to use doas. |
| 240 | sudo_cmd = ['sudo', '-p', '[local sudo] Password: '] |
| 241 | doas_cmd = ['doas'] |
| 242 | |
| 243 | # For clarity, try to replace executable name with the |
| 244 | # full path. |
| 245 | doas_path = which("doas") |
| 246 | if doas_path: |
| 247 | doas_cmd[0] = doas_path |
| 248 | sudo_path = which("sudo") |
| 249 | if sudo_path: |
| 250 | sudo_cmd[0] = sudo_path |
| 251 | |
| 252 | # sudo_pythonpath indicates if we should set the |
| 253 | # PYTHONPATH environment variable when elevating |
| 254 | # privileges. This can be adjusted with the |
| 255 | # --no-sudo-pythonpath option. |
| 256 | if sudo_pythonpath: |
| 257 | pp_prefix = ['/usr/bin/env', |
| 258 | 'PYTHONPATH=%s' % |
| 259 | os.path.dirname(os.path.dirname(__file__))] |
| 260 | sudo_cmd = sudo_cmd + pp_prefix |
| 261 | doas_cmd = doas_cmd + pp_prefix |
| 262 | |
| 263 | # Final order should be: sudo/doas command, env |
| 264 | # pythonpath, and then argvbase (sshuttle command). |
| 265 | sudo_cmd = sudo_cmd + argvbase |
| 266 | doas_cmd = doas_cmd + argvbase |
| 267 |
nothing calls this directly
no test coverage detected