Set a default for maxint that matches what xmlrpclib can handle. Also handle marshalling errors from xmlrpclib so users don't get a backtrace.

This was discovered by a typo in a dns serial number which exceeded 4 bytes. To test try something like:


$ ipa dnszone-add --name-server=192.168.122.214 --admin-email=t...@example.com --serial=20100101010 --refresh=300 --retry=300 --expire=1200000 --minimum=3000 --maximum=9200 --ttl=100 newzone

ticket 770

rob
>From 87f53c60c0962dd9848a83c36b636f77cb7cfd9e Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Mon, 17 Jan 2011 16:23:53 -0500
Subject: [PATCH] Set the default Int maxvalue to the maximum XML-RPC can handle.

Also handle marshalling errors thrown by xmlrpclib more gracefully.

ticket 770
---
 ipalib/errors.py     |   14 ++++++++++++++
 ipalib/parameters.py |    3 ++-
 ipalib/rpc.py        |    4 +++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/ipalib/errors.py b/ipalib/errors.py
index fd23d99..1d491fa 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -420,6 +420,20 @@ class JSONError(PublicError):
     format = _('Invalid JSON-RPC request: %(error)s')
 
 
+class XMLRPCMarshallError(PublicError):
+    """
+    **910** Raised when the XML-RPC lib cannot marshall the request
+
+    For example:
+
+    >>> raise XMLRPCMarshallError(error='int exceeds XML-RPC limits')
+    Traceback (most recent call last):
+      ...
+    XMLRPCMarshallError: error marshalling data for XML-RPC transport: int exceeds XML-RPC limits
+    """
+
+    errno = 910
+    format = _('error marshalling data for XML-RPC transport: %(error)s')
 
 ##############################################################################
 # 1000 - 1999: Authentication errors
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 78eacde..0d6c690 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -109,6 +109,7 @@ from errors import PasswordMismatch
 from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
 from text import Gettext, FixMe
 import csv
+from xmlrpclib import MAXINT
 
 
 class DefaultFrom(ReadOnly):
@@ -1002,7 +1003,7 @@ class Int(Number):
 
     kwargs = Param.kwargs + (
         ('minvalue', int, None),
-        ('maxvalue', int, None),
+        ('maxvalue', int, int(MAXINT)),
     )
 
     def __init__(self, name, *rules, **kw):
diff --git a/ipalib/rpc.py b/ipalib/rpc.py
index dd85076..3457640 100644
--- a/ipalib/rpc.py
+++ b/ipalib/rpc.py
@@ -38,7 +38,7 @@ import errno
 from xmlrpclib import Binary, Fault, dumps, loads, ServerProxy, Transport, ProtocolError
 import kerberos
 from ipalib.backend import Connectible
-from ipalib.errors import public_errors, PublicError, UnknownError, NetworkError, KerberosError
+from ipalib.errors import public_errors, PublicError, UnknownError, NetworkError, KerberosError, XMLRPCMarshallError
 from ipalib import errors
 from ipalib.request import context
 from ipapython import ipautil, dnsclient
@@ -373,3 +373,5 @@ class xmlclient(Connectible):
             raise NetworkError(uri=server, error=e.errmsg)
         except socket.error, e:
             raise NetworkError(uri=server, error=str(e))
+        except (OverflowError, TypeError), e:
+            raise XMLRPCMarshallError(error=str(e))
-- 
1.7.3.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to