diff options
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/__init__.py | 2 | ||||
-rw-r--r-- | ipalib/errors.py | 16 | ||||
-rw-r--r-- | ipalib/parameters.py | 19 | ||||
-rw-r--r-- | ipalib/plugins/automount.py | 28 | ||||
-rw-r--r-- | ipalib/plugins/config.py | 8 |
5 files changed, 54 insertions, 19 deletions
diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 2589cf15..169b47a1 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -878,7 +878,7 @@ from backend import Backend from frontend import Command, LocalOrRemote from frontend import Object, Method, Property from crud import Create, Retrieve, Update, Delete, Search -from parameters import DefaultFrom, Bool, Flag, Int, Float, Bytes, Str, Password,List +from parameters import DefaultFrom, Bool, Flag, Int, Float, Bytes, Str, IA5Str, Password,List from parameters import BytesEnum, StrEnum, AccessTime, File from errors import SkipPluginModule from text import _, ngettext, GettextFactory, NGettextFactory diff --git a/ipalib/errors.py b/ipalib/errors.py index 58799628..49d6343a 100644 --- a/ipalib/errors.py +++ b/ipalib/errors.py @@ -1252,6 +1252,22 @@ class OnlyOneValueAllowed(ExecutionError): format = _('%(attr)s: Only one value allowed.') +class InvalidSyntax(ExecutionError): + """ + **4208** Raised when trying to set more than one value to single-value attributes + + For example: + + >> raise OnlyOneValueAllowed(attr='ipahomesrootdir') + Traceback (most recent call last): + ... + InvalidSyntax: ipahomesrootdir: Invalid syntax + """ + + errno = 4208 + format = _('%(attr)s: Invalid syntax.') + + class CertificateError(ExecutionError): """ **4300** Base class for Certificate execution errors (*4300 - 4399*). diff --git a/ipalib/parameters.py b/ipalib/parameters.py index cf4f3ba4..f3b13bdb 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -1278,6 +1278,25 @@ class Str(Data): ) +class IA5Str(Str): + """ + An IA5String per RFC 4517 + """ + + def __init__(self, name, *rules, **kw): + super(IA5Str, self).__init__(name, *rules, **kw) + + def _convert_scalar(self, value, index=None): + if isinstance(value, basestring): + for i in xrange(len(value)): + if ord(value[i]) > 127: + raise ConversionError(name=self.name, index=index, + error=_('The character \'%(char)r\' is not allowed.') % + dict(char=value[i],) + ) + return super(IA5Str, self)._convert_scalar(value, index) + + class Password(Str): """ A parameter for passwords (stored in the ``unicode`` type). diff --git a/ipalib/plugins/automount.py b/ipalib/plugins/automount.py index df9b3411..958b4c23 100644 --- a/ipalib/plugins/automount.py +++ b/ipalib/plugins/automount.py @@ -168,7 +168,7 @@ automountInformation: -ro,soft,rsize=8192,wsize=8192 nfs.example.com:/vol/arch """ from ipalib import api, errors from ipalib import Object, Command -from ipalib import Flag, Str +from ipalib import Flag, Str, IA5Str from ipalib.plugins.baseldap import * from ipalib import _, ngettext import os @@ -486,11 +486,11 @@ class automountmap(LDAPObject): default_attributes = ['automountmapname', 'description'] takes_params = ( - Str('automountmapname', - cli_name='map', - label=_('Map'), - doc=_('Automount map name'), - primary_key=True, + IA5Str('automountmapname', + cli_name='map', + label=_('Map'), + doc=_('Automount map name'), + primary_key=True, ), Str('description?', cli_name='desc', @@ -568,15 +568,15 @@ class automountkey(LDAPObject): ] takes_params = ( - Str('automountkey', - cli_name='key', - label=_('Key'), - doc=_('Automount key name'), - primary_key=True, + IA5Str('automountkey', + cli_name='key', + label=_('Key'), + doc=_('Automount key name'), + primary_key=True, ), - Str('automountinformation', - cli_name='info', - label=_('Mount information'), + IA5Str('automountinformation', + cli_name='info', + label=_('Mount information'), ), Str('description?', cli_name='desc', diff --git a/ipalib/plugins/config.py b/ipalib/plugins/config.py index 79db77e9..0fa142b9 100644 --- a/ipalib/plugins/config.py +++ b/ipalib/plugins/config.py @@ -54,7 +54,7 @@ Server Configuration. """ from ipalib import api -from ipalib import Bool, Int, Str +from ipalib import Bool, Int, Str, IA5Str from ipalib.plugins.baseldap import * from ipalib import _ @@ -79,7 +79,7 @@ class config(LDAPObject): label=_('Max username length'), minvalue=1, ), - Str('ipahomesrootdir?', + IA5Str('ipahomesrootdir?', cli_name='homedirectory', label=_('Home directory base'), doc=_('Default location of home directories'), @@ -111,12 +111,12 @@ class config(LDAPObject): doc=_('Max. number of records to search (-1 is unlimited)'), minvalue=-1, ), - Str('ipausersearchfields?', + IA5Str('ipausersearchfields?', cli_name='usersearch', label=_('User search fields'), doc=_('A comma-separated list of fields to search when searching for users'), ), - Str('ipagroupsearchfields?', + IA5Str('ipagroupsearchfields?', cli_name='groupsearch', label='Group search fields', doc=_('A comma-separated list of fields to search when searching for groups'), |