Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 313561 Details for
Bug 450613
IPA doesn't handle group names with spaces properly
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Use same regex as shadow-utils
freeipa-68-goodname.patch (text/plain), 9.01 KB, created by
Rob Crittenden
on 2008-08-06 13:28:25 UTC
(
hide
)
Description:
Use same regex as shadow-utils
Filename:
MIME Type:
Creator:
Rob Crittenden
Created:
2008-08-06 13:28:25 UTC
Size:
9.01 KB
patch
obsolete
>From c5402964fe43546ef7c87052bfde0344d4bbfc65 Mon Sep 17 00:00:00 2001 >From: Rob Crittenden <rcrit@ipa.greyoak.com> >Date: Wed, 6 Aug 2008 09:15:47 -0400 >Subject: [PATCH] Change user and group validators to match shadow-utils > >This sets the regex to [a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]? > >450613, 457124 >--- > ipa-admintools/ipa-addgroup | 14 +++++++---- > ipa-admintools/ipa-adduser | 14 +++++++---- > ipa-python/ipaadminutil.py | 10 ++++++++ > ipa-python/ipavalidate.py | 25 +++++++++++++++++++++ > ipa-python/test/test_ipavalidate.py | 12 ++++++++++ > ipa-server/ipa-gui/ipagui/forms/group.py | 5 ++- > ipa-server/ipa-gui/ipagui/forms/user.py | 3 +- > ipa-server/ipa-gui/ipagui/helpers/validators.py | 27 +++++++++++++++++++++++ > 8 files changed, 97 insertions(+), 13 deletions(-) > >diff --git a/ipa-admintools/ipa-addgroup b/ipa-admintools/ipa-addgroup >index caf4e93..978a9a6 100644 >--- a/ipa-admintools/ipa-addgroup >+++ b/ipa-admintools/ipa-addgroup >@@ -27,6 +27,7 @@ try: > import ipa.ipautil as ipautil > import ipa.config > import ipa.ipaerror >+ import ipa.ipaadminutil as ipaadminutil > > import xmlrpclib > import kerberos >@@ -86,14 +87,17 @@ def main(): > if (len(args) != 2): > while (cont != True): > cn = raw_input("Group name: ") >- if (ipavalidate.String(cn, notEmpty=True)): >- print "Please enter a value" >- else: >+ try: >+ ipaadminutil.check_name(cn) > cont = True >+ except ValueError, e: >+ print "group name " + str(e) > else: > cn = args[1] >- if (ipavalidate.String(cn, notEmpty=True)): >- print "Please enter a value" >+ try: >+ ipaadminutil.check_name(cn) >+ except ValueError, e: >+ print "group name " + str(e) > return 1 > > cont = False >diff --git a/ipa-admintools/ipa-adduser b/ipa-admintools/ipa-adduser >index 2c32d1e..42d1436 100644 >--- a/ipa-admintools/ipa-adduser >+++ b/ipa-admintools/ipa-adduser >@@ -26,6 +26,7 @@ try: > import ipa.ipavalidate as ipavalidate > import ipa.ipautil as ipautil > import ipa.config >+ import ipa.ipaadminutil as ipaadminutil > > import xmlrpclib > import kerberos >@@ -146,14 +147,17 @@ def main(): > if (len(args) != 2): > while (cont != True): > username = raw_input("Login name: ") >- if (ipavalidate.Plain(username, notEmpty=True, allowSpaces=False)): >- print "Please enter a value" >- else: >+ try: >+ ipaadminutil.check_name(username) > cont = True >+ except ValueError, e: >+ print "user name " + str(e) > else: > username = args[1] >- if (ipavalidate.Plain(username, notEmpty=True, allowSpaces=False)): >- print "Username is required and may only include letters and numbers" >+ try: >+ ipaadminutil.check_name(username) >+ except ValueError, e: >+ print "user name " + str(e) > return 1 > > if options.password_prompt: >diff --git a/ipa-python/ipaadminutil.py b/ipa-python/ipaadminutil.py >index d94ced4..cd840a0 100644 >--- a/ipa-python/ipaadminutil.py >+++ b/ipa-python/ipaadminutil.py >@@ -22,6 +22,7 @@ import tempfile > import logging > import subprocess > import os >+import ipa.ipavalidate as ipavalidate > > def select_user(counter, users): > """counter is the number of User objects in users >@@ -82,3 +83,12 @@ def select_group(counter, groups): > print "Please enter a number between 1 and %s" % counter > > return groupindex >+ >+def check_name(name): >+ """Helper to ensure that a user or group name is legal""" >+ >+ if (ipavalidate.GoodName(name, notEmpty=True)): >+ raise ValueError("may only include letters, numbers, _, -, . and $") >+ >+ return >+ >diff --git a/ipa-python/ipavalidate.py b/ipa-python/ipavalidate.py >index 4dc7fe1..1017724 100644 >--- a/ipa-python/ipavalidate.py >+++ b/ipa-python/ipavalidate.py >@@ -107,3 +107,28 @@ def Path(text, notEmpty=False): > > return 0 > >+def GoodName(text, notEmpty=False): >+ """From shadow-utils: >+ >+ User/group names must match gnu e-regex: >+ [a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]? >+ >+ as a non-POSIX, extension, allow "$" as the last char for >+ sake of Samba 3.x "add machine script" >+ """ >+ textRE = re.compile(r"^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$") >+ >+ if not text and notEmpty is True: >+ return 1 >+ >+ if text is None: >+ if notEmpty is True: >+ return 1 >+ else: >+ return 0 >+ >+ m = textRE.match(text) >+ if not m or text != m.group(0): >+ return 1 >+ >+ return 0 >diff --git a/ipa-python/test/test_ipavalidate.py b/ipa-python/test/test_ipavalidate.py >index de4693c..36ca511 100644 >--- a/ipa-python/test/test_ipavalidate.py >+++ b/ipa-python/test/test_ipavalidate.py >@@ -80,6 +80,18 @@ class TestValidate(unittest.TestCase): > self.assertEqual(1, ipavalidate.Path("", notEmpty=True)) > self.assertEqual(1, ipavalidate.Path(None, notEmpty=True)) > >+ def test_validName(self): >+ self.assertEqual(0, ipavalidate.GoodName("foo")) >+ self.assertEqual(0, ipavalidate.GoodName("1foo")) >+ self.assertEqual(0, ipavalidate.GoodName("foo.bar")) >+ self.assertEqual(0, ipavalidate.GoodName("foo.bar$")) >+ >+ def test_invalidName(self): >+ self.assertEqual(1, ipavalidate.GoodName("foo bar")) >+ self.assertEqual(1, ipavalidate.GoodName("foo%bar")) >+ self.assertEqual(1, ipavalidate.GoodName("*foo")) >+ self.assertEqual(1, ipavalidate.GoodName("$foo.bar$")) >+ > if __name__ == '__main__': > unittest.main() > >diff --git a/ipa-server/ipa-gui/ipagui/forms/group.py b/ipa-server/ipa-gui/ipagui/forms/group.py >index 4835e91..826ad0e 100644 >--- a/ipa-server/ipa-gui/ipagui/forms/group.py >+++ b/ipa-server/ipa-gui/ipagui/forms/group.py >@@ -19,6 +19,7 @@ import turbogears > from turbogears import validators, widgets > from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm > from ipagui.helpers import ipahelper >+from ipagui.helpers.validators import * > > class GroupFields(object): > cn = widgets.TextField(name="cn", label="Name") >@@ -36,7 +37,7 @@ class GroupFields(object): > dn_to_info_json = widgets.HiddenField(name="dn_to_info_json") > > class GroupNewValidator(validators.Schema): >- cn = validators.String(not_empty=True) >+ cn = GoodName(not_empty=True) > description = validators.String(not_empty=False) > > >@@ -59,7 +60,7 @@ class GroupNewForm(widgets.Form): > > > class GroupEditValidator(validators.Schema): >- cn = validators.String(not_empty=False) >+ cn = GoodName(not_empty=False) > gidnumber = validators.Int(not_empty=False) > description = validators.String(not_empty=False) > >diff --git a/ipa-server/ipa-gui/ipagui/forms/user.py b/ipa-server/ipa-gui/ipagui/forms/user.py >index 22a4965..62fc0df 100644 >--- a/ipa-server/ipa-gui/ipagui/forms/user.py >+++ b/ipa-server/ipa-gui/ipagui/forms/user.py >@@ -86,7 +86,7 @@ class UserFields(object): > custom_fields = [] > > class UserNewValidator(validators.Schema): >- uid = validators.PlainText(not_empty=True) >+ uid = GoodName(not_empty=True) > krbprincipalkey = validators.String(not_empty=False) > krbprincipalkey_confirm = validators.String(not_empty=False) > givenname = validators.String(not_empty=True) >@@ -129,6 +129,7 @@ class UserNewForm(widgets.Form): > super(UserNewForm,self).update_params(params) > > class UserEditValidator(validators.Schema): >+ uid = GoodName(not_empty=False) > krbprincipalkey = validators.String(not_empty=False) > krbprincipalkey_confirm = validators.String(not_empty=False) > givenname = validators.String(not_empty=True) >diff --git a/ipa-server/ipa-gui/ipagui/helpers/validators.py b/ipa-server/ipa-gui/ipagui/helpers/validators.py >index 6e78781..8ed73b8 100644 >--- a/ipa-server/ipa-gui/ipagui/helpers/validators.py >+++ b/ipa-server/ipa-gui/ipagui/helpers/validators.py >@@ -63,3 +63,30 @@ class UniqueList(FancyValidator): > if orig > check: > raise Invalid(self.message('notunique', state), > value, state) >+ >+class GoodName(Regex): >+ """ >+ Test that the field contains only letters, numbers, underscore, >+ dash, hyphen and $. >+ >+ Examples:: >+ >+ >>> GoodName.to_python('_this9_') >+ '_this9_' >+ >>> GoodName.from_python(' this ') >+ ' this ' >+ >>> GoodName(accept_python=False).from_python(' this ') >+ Traceback (most recent call last): >+ ... >+ Invalid: Enter only letters, numbers, _ (underscore), - (dash) or $') >+ >>> GoodName(strip=True).to_python(' this ') >+ 'this' >+ >>> GoodName(strip=True).from_python(' this ') >+ 'this' >+ """ >+ >+ regex = r"^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,30}[a-zA-Z0-9_.$-]?$" >+ >+ messages = { >+ 'invalid': _('Enter only letters, numbers, _ (underscore), - (dash) or $'), >+ } >-- >1.5.4.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 450613
:
313561
|
313645