summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Kupka <dkupka@redhat.com>2015-08-26 14:11:21 +0200
committerPetr Vobornik <pvoborni@redhat.com>2015-08-26 16:11:42 +0200
commit9fc82bc66992eaa5daeed80e366e10986a8583d8 (patch)
tree0fdae146ca95638c1aada79d52faa493246cfa40
parent91de475fd9d4499c05052e74bd2918569da4f269 (diff)
downloadfreeipa-9fc82bc66992eaa5daeed80e366e10986a8583d8.tar.gz
freeipa-9fc82bc66992eaa5daeed80e366e10986a8583d8.tar.xz
freeipa-9fc82bc66992eaa5daeed80e366e10986a8583d8.zip
vault: Limit size of data stored in vault
https://fedorahosted.org/freeipa/ticket/5231 Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
-rw-r--r--ipalib/plugins/vault.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py
index 667524465..e369eeee2 100644
--- a/ipalib/plugins/vault.py
+++ b/ipalib/plugins/vault.py
@@ -237,6 +237,7 @@ def validated_read(argname, filename, mode='r', encoding=None):
register = Registry()
+MAX_VAULT_DATA_SIZE = 2**20 # = 1 MB
vault_options = (
Str(
@@ -1233,10 +1234,28 @@ class vault_archive(PKQuery, Local):
raise errors.MutuallyExclusiveError(
reason=_('Input data specified multiple times'))
+ elif data:
+ if len(data) > MAX_VAULT_DATA_SIZE:
+ raise errors.ValidationError(name="data", error=_(
+ "Size of data exceeds the limit. Current vault data size "
+ "limit is %(limit)d B")
+ % {'limit': MAX_VAULT_DATA_SIZE})
+
elif input_file:
+ try:
+ stat = os.stat(input_file)
+ except OSError as exc:
+ raise errors.ValidationError(name="in", error=_(
+ "Cannot read file '%(filename)s': %(exc)s")
+ % {'filename': input_file, 'exc': exc[1]})
+ if stat.st_size > MAX_VAULT_DATA_SIZE:
+ raise errors.ValidationError(name="in", error=_(
+ "Size of data exceeds the limit. Current vault data size "
+ "limit is %(limit)d B")
+ % {'limit': MAX_VAULT_DATA_SIZE})
data = validated_read('in', input_file, mode='rb')
- elif not data:
+ else:
data = ''
if self.api.env.in_server: