summaryrefslogtreecommitdiffstats
path: root/ipaserver
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2012-03-01 21:54:06 -0500
committerMartin Kosek <mkosek@redhat.com>2012-03-02 10:59:31 +0100
commit95b85f6384637e6c5c79a8567de3583e7d3af046 (patch)
treeca436427fbbedcd8722bd1596c15f41052c386bd /ipaserver
parent6c3e908232a2974fc88260d9322242c2beaa5898 (diff)
downloadfreeipa-95b85f6384637e6c5c79a8567de3583e7d3af046.tar.gz
freeipa-95b85f6384637e6c5c79a8567de3583e7d3af046.tar.xz
freeipa-95b85f6384637e6c5c79a8567de3583e7d3af046.zip
Fix WSGI error handling
A number of different errors could occur when trying to handle an error which just confused matters. If no CCache was received then trying to retrieve context.principal in the error message caused yet another exception to be raised. Trying to get Command[name] if name wasn't defined in command would raise an exception. Trying to raise errors.CCache was failing because the response hadn't been started. https://fedorahosted.org/freeipa/ticket/2371
Diffstat (limited to 'ipaserver')
-rw-r--r--ipaserver/rpcserver.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/ipaserver/rpcserver.py b/ipaserver/rpcserver.py
index 147707b35..2fbd79f20 100644
--- a/ipaserver/rpcserver.py
+++ b/ipaserver/rpcserver.py
@@ -322,7 +322,7 @@ class WSGIExecutioner(Executioner):
error = InternalError()
finally:
os.environ['LANG'] = lang
- if name:
+ if name and name in self.Command:
try:
params = self.Command[name].args_options_2_params(*args, **options)
except Exception, e:
@@ -331,10 +331,11 @@ class WSGIExecutioner(Executioner):
)
# get at least some context of what is going on
params = options
+ principal = getattr(context, 'principal', 'UNKNOWN')
if error:
- self.info('%s: %s(%s): %s', context.principal, name, ', '.join(self.Command[name]._repr_iter(**params)), e.__class__.__name__)
+ self.info('%s: %s(%s): %s', principal, name, ', '.join(self.Command[name]._repr_iter(**params)), e.__class__.__name__)
else:
- self.info('%s: %s(%s): SUCCESS', context.principal, name, ', '.join(self.Command[name]._repr_iter(**params)))
+ self.info('%s: %s(%s): SUCCESS', principal, name, ', '.join(self.Command[name]._repr_iter(**params)))
else:
self.info('%s: %s', context.principal, e.__class__.__name__)
return self.marshal(result, error, _id)
@@ -377,7 +378,7 @@ class WSGIExecutioner(Executioner):
raise NotImplementedError('%s.marshal()' % self.fullname)
-class xmlserver(WSGIExecutioner):
+class xmlserver(WSGIExecutioner, HTTP_Status):
"""
Execution backend plugin for XML-RPC server.
@@ -402,6 +403,8 @@ class xmlserver(WSGIExecutioner):
self.debug('WSGI xmlserver.__call__:')
user_ccache=environ.get('KRB5CCNAME')
if user_ccache is None:
+ self.internal_error(environ, start_response,
+ 'xmlserver.__call__: KRB5CCNAME not defined in HTTP request environment')
return self.marshal(None, CCacheError())
try:
self.create_context(ccache=user_ccache)
@@ -548,7 +551,7 @@ def json_decode_binary(val):
else:
return val
-class jsonserver(WSGIExecutioner):
+class jsonserver(WSGIExecutioner, HTTP_Status):
"""
JSON RPC server.
@@ -576,11 +579,12 @@ class jsonserver(WSGIExecutioner):
message=error.strerror,
name=error.__class__.__name__,
)
+ principal = getattr(context, 'principal', 'UNKNOWN')
response = dict(
result=result,
error=error,
id=_id,
- principal=unicode(context.principal),
+ principal=unicode(principal),
version=unicode(VERSION),
)
response = json_encode_binary(response)
@@ -844,6 +848,8 @@ class jsonserver_kerb(jsonserver):
user_ccache=environ.get('KRB5CCNAME')
if user_ccache is None:
+ self.internal_error(environ, start_response,
+ 'jsonserver_kerb.__call__: KRB5CCNAME not defined in HTTP request environment')
return self.marshal(None, CCacheError())
self.create_context(ccache=user_ccache)