On 02/07/2012 01:52 PM, Petr Viktorin wrote:
Honor the default home directory base when creating a new user. Test
included. I also cleaned up the way home directory was created.

This patch removes the default from the --homedirectory option, letting
the server fill it in pre_callback. If I'm reading this correctly,
default_from and create_default run on the client-side, so they can't
get to the config without round-tripping to the server.

https://fedorahosted.org/freeipa/ticket/2332

Also, I've cleaned up the home directory generation to use
posixpath.join instead of '%s/%s' and ad-hoc cleanup. This should be
more robust. (It will also behave differently if the username starts
with '/' or maybe similar cases of the user asking for trouble.)

A question: Do we want to use posixpath here, or os.path? Put another
way, should the home directories separated by '\' if the server runs on
Windows?


_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Martin told me I need to make two changes: remove autofill along with default_from, and since I have touched the API, update API.txt.

Attaching the updated patch.
>From 18c267746f84dca2f16c1d8dd97d09d3e776d414 Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Tue, 7 Feb 2012 07:13:52 -0500
Subject: [PATCH] Honor the default home directory in user_add

The homedirectory argument had a default_from '/home/<name>', ignoring
the ipahomesrootdir config setting. This patch removes that default,
and adds a test case for ipahomesrootdir.

https://fedorahosted.org/freeipa/ticket/2332

Building the home directory from the default is changed to use
posixpath.join instead of string formatting and ad-hoc cleanup,
and to use '/home' instead of failing when the ipahomesrootdir
setting is not present for some reason.
---
 API.txt                               |    2 +-
 ipalib/plugins/user.py                |   11 ++----
 tests/test_xmlrpc/test_user_plugin.py |   65 +++++++++++++++++++++++++++++++++
 3 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/API.txt b/API.txt
index d031039a6a6cf0a8dadb0422851fc84909b6bba2..3f89435f9f46c6f43e3bb58f03085193f9d2ad08 100644
--- a/API.txt
+++ b/API.txt
@@ -3093,7 +3093,7 @@ option: Str('sn', attribute=True, cli_name='last', multivalue=False, required=Tr
 option: Str('cn', attribute=True, autofill=True, cli_name='cn', multivalue=False, required=True)
 option: Str('displayname', attribute=True, autofill=True, cli_name='displayname', multivalue=False, required=False)
 option: Str('initials', attribute=True, autofill=True, cli_name='initials', multivalue=False, required=False)
-option: Str('homedirectory', attribute=True, autofill=True, cli_name='homedir', multivalue=False, required=True)
+option: Str('homedirectory', attribute=True, autofill=False, cli_name='homedir', multivalue=False, required=False)
 option: Str('gecos', attribute=True, autofill=True, cli_name='gecos', multivalue=False, required=False)
 option: Str('loginshell', attribute=True, cli_name='shell', default=u'/bin/sh', multivalue=False, required=False)
 option: Str('krbprincipalname', attribute=True, autofill=True, cli_name='principal', multivalue=False, required=False)
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index 70a111dd34c66ff22f906834a1348c65dbfd1bd5..41c7c7413a99165e9cce5114c809fe30475b05cd 100644
--- a/ipalib/plugins/user.py
+++ b/ipalib/plugins/user.py
@@ -27,6 +27,7 @@ import copy
 from ipalib import _, ngettext
 from ipapython.ipautil import ipa_generate_password
 import string
+import posixpath
 
 __doc__ = _("""
 Users
@@ -207,11 +208,9 @@ class user(LDAPObject):
             default_from=lambda givenname, sn: '%c%c' % (givenname[0], sn[0]),
             autofill=True,
         ),
-        Str('homedirectory',
+        Str('homedirectory?',
             cli_name='homedir',
             label=_('Home directory'),
-            default_from=lambda uid: '/home/%s' % uid,
-            autofill=True,
         ),
         Str('gecos?',
             label=_('GECOS field'),
@@ -419,11 +418,9 @@ class user_add(LDAPCreate):
         entry_attrs.setdefault('cn', full_name)
         if 'homedirectory' not in entry_attrs:
             # get home's root directory from config
-            homes_root = config.get('ipahomesrootdir', '/home')[0]
+            homes_root = config.get('ipahomesrootdir', ['/home'])[0]
             # build user's home directory based on his uid
-            home_dir = '%s/%s' % (homes_root, keys[-1])
-            home_dir = home_dir.replace('//', '/').rstrip('/')
-            entry_attrs['homedirectory'] = home_dir
+            entry_attrs['homedirectory'] = posixpath.join(homes_root, keys[-1])
         entry_attrs.setdefault('krbpwdpolicyreference', 'cn=global_policy,cn=%s,cn=kerberos,%s' % (api.env.realm, api.env.basedn))
         entry_attrs.setdefault('krbprincipalname', '%s@%s' % (entry_attrs['uid'], api.env.realm))
 
diff --git a/tests/test_xmlrpc/test_user_plugin.py b/tests/test_xmlrpc/test_user_plugin.py
index 0370ec74d294f15b742aadacbdbf6fa296ebb718..100f8a21f3caca9daa9a92177ab4dd506bd6e3d9 100644
--- a/tests/test_xmlrpc/test_user_plugin.py
+++ b/tests/test_xmlrpc/test_user_plugin.py
@@ -909,5 +909,70 @@ class test_user(Declarative):
             expected=errors.MalformedUserPrincipal(principal='%s@b...@notfound.org' % user1),
         ),
 
+        dict(
+            desc='Delete %r' % user1,
+            command=('user_del', [user1], {}),
+            expected=dict(
+                result=dict(failed=u''),
+                summary=u'Deleted user "tuser1"',
+                value=user1,
+            ),
+        ),
+
+        dict(
+            desc='Change default home directory',
+            command=(
+                'config_mod', [], dict(ipahomesrootdir=u'/other-home'),
+            ),
+            expected=lambda x: True,
+        ),
+
+        dict(
+            desc='Create user %r with different default home directory' % user1,
+            command=(
+                'user_add', [user1], dict(givenname=u'Test', sn=u'User1')
+            ),
+            expected=dict(
+                value=user1,
+                summary=u'Added user "tuser1"',
+                result=dict(
+                    gecos=[u'Test User1'],
+                    givenname=[u'Test'],
+                    homedirectory=[u'/other-home/tuser1'],
+                    krbprincipalname=[u'tuser1@' + api.env.realm],
+                    loginshell=[u'/bin/sh'],
+                    objectclass=objectclasses.user,
+                    sn=[u'User1'],
+                    uid=[user1],
+                    uidnumber=[fuzzy_digits],
+                    gidnumber=[fuzzy_digits],
+                    displayname=[u'Test User1'],
+                    cn=[u'Test User1'],
+                    initials=[u'TU'],
+                    ipauniqueid=[fuzzy_uuid],
+                    krbpwdpolicyreference=lambda x: [DN(i) for i in x] == \
+                        [DN(('cn','global_policy'),('cn',api.env.realm),
+                            ('cn','kerberos'),api.env.basedn)],
+                    mepmanagedentry=lambda x: [DN(i) for i in x] == \
+                        [DN(('cn',user1),('cn','groups'),('cn','accounts'),
+                            api.env.basedn)],
+                    memberof_group=[u'ipausers'],
+                    has_keytab=False,
+                    has_password=False,
+                    dn=lambda x: DN(x) == \
+                        DN(('uid','tuser1'),('cn','users'),('cn','accounts'),
+                           api.env.basedn),
+                ),
+            ),
+        ),
+
+
+        dict(
+            desc='Reset default home directory',
+            command=(
+                'config_mod', [], dict(ipahomesrootdir=u'/home'),
+            ),
+            expected=lambda x: True,
+        ),
 
     ]
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to