Убрано ограничение на название пользователей и групп

legacy27 3.5.0_alpha3
parent 04c0c9a973
commit 22ae85d9f4

@ -16,7 +16,7 @@
import sys import sys
from calculate.lib.datavars import (ReadonlyVariable, Variable, from calculate.lib.datavars import (ReadonlyVariable, Variable,
VariableError) VariableError, VariableInterface)
from calculate.ldap.variables.helpers import (LdapSearchHelper, LdapMaxHelper) from calculate.ldap.variables.helpers import (LdapSearchHelper, LdapMaxHelper)
from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper, from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper,
UnixActionHelper) UnixActionHelper)
@ -29,8 +29,18 @@ from calculate.lib.cl_lang import (setLocalTranslate, getLazyLocalTranslate)
setLocalTranslate('cl_unix3', sys.modules[__name__]) setLocalTranslate('cl_unix3', sys.modules[__name__])
__ = getLazyLocalTranslate(_) __ = 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): def check(self, value):
if not value: if not value:
raise VariableError(_("You should specify group name")) raise VariableError(_("You should specify group name"))
if not re.match("^[a-zA-Z_]([a-zA-Z0-9_ -]*[a-zA-Z0-9_-])?$", value): self.check_group_name(value)
raise VariableError(_("Wrong group name"))
if value == "list": if value == "list":
raise VariableError(_("List is using as keyword")) raise VariableError(_("List is using as keyword"))
if self.check_name(value): if self.check_name(value):
@ -392,7 +401,7 @@ class VariableUrUnixGroupUsersDel(UnixUserHelper, Variable):
return _("Not change") return _("Not change")
class VariableUrUnixGroupNewname(UnixGroupHelper, Variable): class VariableUrUnixGroupNewname(GroupNameHelper, UnixGroupHelper, Variable):
opt = ("-n", "--new-name") opt = ("-n", "--new-name")
value = "" value = ""
metavalue = "NEW_GROUP" metavalue = "NEW_GROUP"
@ -407,7 +416,7 @@ class VariableUrUnixGroupNewname(UnixGroupHelper, Variable):
def check(self, value): def check(self, value):
if value == self.Get('ur_unix_group_name'): if value == self.Get('ur_unix_group_name'):
return 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): if self.search_ldap_group_name(value):
raise VariableError( raise VariableError(
_("Group {name} already exists").format(name=value)) _("Group {name} already exists").format(name=value))

@ -18,7 +18,8 @@ import sys
from os import path from os import path
from calculate.lib.cl_ldap import LDAPConnectError from calculate.lib.cl_ldap import LDAPConnectError
from calculate.lib.datavars import (ReadonlyVariable, Variable, from calculate.lib.datavars import (ReadonlyVariable, Variable,
VariableError, PasswordError) VariableError, PasswordError,
VariableInterface)
from calculate.ldap.variables.helpers import (HashHelper, from calculate.ldap.variables.helpers import (HashHelper,
LdapMaxHelper) LdapMaxHelper)
from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper, from calculate.unix.variables.helpers import (UnixUserHelper, UnixGroupHelper,
@ -35,7 +36,20 @@ setLocalTranslate('cl_unix3', sys.modules[__name__])
__ = getLazyLocalTranslate(_) __ = 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): def check_new(self, value):
if not value: if not value:
raise VariableError(_("You should specify login")) raise VariableError(_("You should specify login"))
if not re.match("^[a-zA-Z_]([a-zA-Z0-9_ -]*[a-zA-Z0-9_-])?$", value): self.check_user_name(value)
raise VariableError(_("Wrong user login"))
if value == "list": if value == "list":
raise VariableError(_("List is using as keyword")) raise VariableError(_("List is using as keyword"))
if self.search_ldap_user_name(value): if self.search_ldap_user_name(value):

Loading…
Cancel
Save