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?
>From 53a9c0aef831a51566508ce6fcf51ecfb0147e9e 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.
---
ipalib/plugins/user.py | 10 ++---
tests/test_xmlrpc/test_user_plugin.py | 65 +++++++++++++++++++++++++++++++++
2 files changed, 69 insertions(+), 6 deletions(-)
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index 70a111dd34c66ff22f906834a1348c65dbfd1bd5..3fde3f234e6d894ee4594164c5f306b961cc4e01 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,10 +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?',
@@ -419,11 +419,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