From 22ae85d9f461af307fb645f73f01f3a2f3a559d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Mon, 31 Oct 2016 17:44:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=D0=BE=20=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=B9=20=D0=B8=20=D0=B3=D1=80=D1=83=D0=BF=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pym/unix/variables/groups.py | 21 +++++++++++++++------ pym/unix/variables/users.py | 21 +++++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/pym/unix/variables/groups.py b/pym/unix/variables/groups.py index e8483ee..271440b 100644 --- a/pym/unix/variables/groups.py +++ b/pym/unix/variables/groups.py @@ -16,7 +16,7 @@ import sys from calculate.lib.datavars import (ReadonlyVariable, Variable, - VariableError) + VariableError, VariableInterface) from calculate.ldap.variables.helpers import (LdapSearchHelper, LdapMaxHelper) from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper, UnixActionHelper) @@ -29,8 +29,18 @@ from calculate.lib.cl_lang import (setLocalTranslate, getLazyLocalTranslate) setLocalTranslate('cl_unix3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) +class GroupNameHelper(VariableInterface): + """ + Вспомогательный объект для проверки имени группы + """ + def check_group_name(self, gname): + if len(gname) > 32: + raise VariableError(_("Wrong group name length")) + if ":" in gname: + raise VariableError(_("Wrong group name")) -class VariableUrUnixGroupName(LdapSearchHelper, UnixActionHelper, Variable): +class VariableUrUnixGroupName(GroupNameHelper, + LdapSearchHelper, UnixActionHelper, Variable): """ Название группы """ @@ -54,8 +64,7 @@ class VariableUrUnixGroupName(LdapSearchHelper, UnixActionHelper, Variable): def check(self, value): if not value: raise VariableError(_("You should specify group name")) - if not re.match("^[a-zA-Z_]([a-zA-Z0-9_ -]*[a-zA-Z0-9_-])?$", value): - raise VariableError(_("Wrong group name")) + self.check_group_name(value) if value == "list": raise VariableError(_("List is using as keyword")) if self.check_name(value): @@ -392,7 +401,7 @@ class VariableUrUnixGroupUsersDel(UnixUserHelper, Variable): return _("Not change") -class VariableUrUnixGroupNewname(UnixGroupHelper, Variable): +class VariableUrUnixGroupNewname(GroupNameHelper, UnixGroupHelper, Variable): opt = ("-n", "--new-name") value = "" metavalue = "NEW_GROUP" @@ -407,7 +416,7 @@ class VariableUrUnixGroupNewname(UnixGroupHelper, Variable): def check(self, value): if value == self.Get('ur_unix_group_name'): return - # raise VariableError(_("The new group name is the same as the old")) + self.check_group_name(value) if self.search_ldap_group_name(value): raise VariableError( _("Group {name} already exists").format(name=value)) diff --git a/pym/unix/variables/users.py b/pym/unix/variables/users.py index 489b7ee..a0ffe98 100644 --- a/pym/unix/variables/users.py +++ b/pym/unix/variables/users.py @@ -18,7 +18,8 @@ import sys from os import path from calculate.lib.cl_ldap import LDAPConnectError from calculate.lib.datavars import (ReadonlyVariable, Variable, - VariableError, PasswordError) + VariableError, PasswordError, + VariableInterface) from calculate.ldap.variables.helpers import (HashHelper, LdapMaxHelper) from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper, @@ -35,7 +36,20 @@ setLocalTranslate('cl_unix3', sys.modules[__name__]) __ = getLazyLocalTranslate(_) -class VariableUrUnixLogin(UnixUserHelper, UnixActionHelper, Variable): +class UserNameHelper(VariableInterface): + """ + Вспомогательный объект для проверки имени группы + """ + + def check_user_name(self, uname): + if len(uname) > 32: + raise VariableError(_("Wrong user name length")) + if ":" in uname: + raise VariableError(_("Wrong user name")) + + +class VariableUrUnixLogin(UserNameHelper, UnixUserHelper, UnixActionHelper, + Variable): """ Логин настраиваемого пользователя """ @@ -56,8 +70,7 @@ class VariableUrUnixLogin(UnixUserHelper, UnixActionHelper, Variable): def check_new(self, value): if not value: raise VariableError(_("You should specify login")) - if not re.match("^[a-zA-Z_]([a-zA-Z0-9_ -]*[a-zA-Z0-9_-])?$", value): - raise VariableError(_("Wrong user login")) + self.check_user_name(value) if value == "list": raise VariableError(_("List is using as keyword")) if self.search_ldap_user_name(value):