Skip to content

Commit

Permalink
Merge pull request #3 from razzmatazz/macosx-support
Browse files Browse the repository at this point in the history
Changes for OS X (tested with OS X 10.9/Mavericks only)
  • Loading branch information
ionelmc committed Apr 27, 2014
2 parents 9e78acc + 1827ad8 commit 6971055
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
25 changes: 20 additions & 5 deletions src/manhole.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import code
import signal
import errno
import platform

try:
import signalfd
except ImportError:
Expand Down Expand Up @@ -79,6 +81,10 @@ def _get_original(qual_name):
except ImportError:
pthread_setname_np = lambda ident, name: None

# OS X getsockopt(2) defines (may work for BSD too?)
SOL_LOCAL = 0
LOCAL_PEERCRED = 1

SO_PEERCRED = 17


Expand All @@ -96,9 +102,14 @@ def cry(message):
def get_peercred(sock):
"""Gets the (pid, uid, gid) for the client on the given *connected* socket."""

return struct.unpack('3i', sock.getsockopt(
socket.SOL_SOCKET, SO_PEERCRED, struct.calcsize('3i')
))
if platform.system() == 'Darwin':
return struct.unpack('3i', sock.getsockopt(
SOL_LOCAL, LOCAL_PEERCRED, struct.calcsize('3i')
))
else:
return struct.unpack('3i', sock.getsockopt(
socket.SOL_SOCKET, SO_PEERCRED, struct.calcsize('3i')
))


class SuspiciousClient(Exception):
Expand Down Expand Up @@ -178,6 +189,7 @@ def run(self):
@staticmethod
def check_credentials(client):
pid, uid, gid = get_peercred(client)

euid = os.geteuid()
client_name = "PID:%s UID:%s GID:%s" % (pid, uid, gid)
if uid not in (0, euid):
Expand All @@ -191,8 +203,11 @@ def check_credentials(client):
@staticmethod
def handle(client):
client.settimeout(None)
client.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 0)
client.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)

if platform.system() != 'Darwin':
client.setsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF, 0)
client.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 0)

backup = []
old_interval = getinterval()
try:
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ deps =
coverage
process-tests
nose
python-signalfd
;eventlet
;gevent
;yanc
Expand Down

0 comments on commit 6971055

Please sign in to comment.