Skip to content

Commit

Permalink
Test permissions to socket for detailed errors if socket.error raised
Browse files Browse the repository at this point in the history
  • Loading branch information
leeclemens committed Jul 4, 2015
1 parent e9e00d7 commit 77f5983
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion bin/fail2ban-client
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,34 @@ class Fail2banClient:
streamRet = False
except socket.error:
if showRet:
logSys.error("Unable to contact server. Is it running?")
self.__logSocketError()
return False
except Exception, e:
if showRet:
logSys.error(e)
return False
return streamRet

def __logSocketError(self):
try:
if os.access(self.__conf["socket"], os.F_OK):
# This doesn't check if path is a socket,
# but socket.error should be raised
if os.access(self.__conf["socket"], os.W_OK):
# Permissions look good, but socket.error was raised
logSys.error("Unable to contact server. Is it running?")
else:
logSys.error("Permission denied to socket: %s,"
" (you must be root)", self.__conf["socket"])
else:
logSys.error("Failed to access socket path: %s."
" Is fail2ban running?",
self.__conf["socket"])
except Exception as e:
logSys.error("Exception while checking socket access: %s",
self.__conf["socket"])
logSys.error(e)

##
# Process a command line.
#
Expand Down

0 comments on commit 77f5983

Please sign in to comment.