/usr/lib/python2.7/dist-packages/flashproxy/proc.py is in flashproxy-common 1.7-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import errno
import os
import socket
import stat
import pwd
DEFAULT_CLIENT_TRANSPORT = "websocket"
# Return true iff the given fd is readable, writable, and executable only by its
# owner.
def check_perms(fd):
mode = os.fstat(fd)[0]
return (mode & (stat.S_IRWXG | stat.S_IRWXO)) == 0
# Drop privileges by switching ID to that of the given user.
# http://stackoverflow.com/questions/2699907/dropping-root-permissions-in-python/2699996#2699996
# https://www.securecoding.cert.org/confluence/display/seccode/POS36-C.+Observe+correct+revocation+order+while+relinquishing+privileges
# https://www.securecoding.cert.org/confluence/display/seccode/POS37-C.+Ensure+that+privilege+relinquishment+is+successful
def drop_privs(username):
uid = pwd.getpwnam(username).pw_uid
gid = pwd.getpwnam(username).pw_gid
os.setgroups([])
os.setgid(gid)
os.setuid(uid)
try:
os.setuid(0)
except OSError:
pass
else:
raise AssertionError("setuid(0) succeeded after attempting to drop privileges")
# A decorator to ignore "broken pipe" errors.
def catch_epipe(fn):
def ret(self, *args):
try:
return fn(self, *args)
except socket.error, e:
try:
err_num = e.errno
except AttributeError:
# Before Python 2.6, exception can be a pair.
err_num, errstr = e
except:
raise
if err_num != errno.EPIPE:
raise
return ret
|