From d17b314d405d2c127a3d51d2076e8982d43aa505 Mon Sep 17 00:00:00 2001
From: Jan Cholasta <jcholast@redhat.com>
Date: Wed, 23 Sep 2015 13:09:44 +0200
Subject: [PATCH] platform: add option to create home directory when adding
user
https://fedorahosted.org/freeipa/ticket/5314
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
---
ipaplatform/base/tasks.py | 8 ++++++--
ipaplatform/redhat/tasks.py | 4 ++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/ipaplatform/base/tasks.py b/ipaplatform/base/tasks.py
index 65715145af533c90038b3e8667da07fd28b7ec56..573287c6bf732991946a75c8817899ee6c1842e3 100644
--- a/ipaplatform/base/tasks.py
+++ b/ipaplatform/base/tasks.py
@@ -184,7 +184,7 @@ class BaseTaskNamespace(object):
return
- def create_system_user(self, name, group, homedir, shell, uid = None, gid = None, comment = None):
+ def create_system_user(self, name, group, homedir, shell, uid=None, gid=None, comment=None, create_homedir=False):
"""Create a system user with a corresponding group"""
try:
grp.getgrnam(group)
@@ -211,12 +211,16 @@ class BaseTaskNamespace(object):
'-g', group,
'-d', homedir,
'-s', shell,
- '-M', '-r', name,
+ '-r', name,
]
if uid:
args += ['-u', str(uid)]
if comment:
args += ['-c', comment]
+ if create_homedir:
+ args += ['-m']
+ else:
+ args += ['-M']
try:
ipautil.run(args)
log.debug('Done adding user')
diff --git a/ipaplatform/redhat/tasks.py b/ipaplatform/redhat/tasks.py
index 1af99d318c6745b1e5285c7829c2b292f86c8390..db31cd04cb234fac8fee97f3579ba2ca919f3262 100644
--- a/ipaplatform/redhat/tasks.py
+++ b/ipaplatform/redhat/tasks.py
@@ -399,7 +399,7 @@ class RedHatTaskNamespace(BaseTaskNamespace):
return True
- def create_system_user(self, name, group, homedir, shell, uid = None, gid = None, comment = None):
+ def create_system_user(self, name, group, homedir, shell, uid=None, gid=None, comment=None, create_homedir=False):
"""
Create a system user with a corresponding group
@@ -420,7 +420,7 @@ class RedHatTaskNamespace(BaseTaskNamespace):
comment = 'DS System User'
super(RedHatTaskNamespace, self).create_system_user(name, group,
- homedir, shell, uid, gid, comment)
+ homedir, shell, uid, gid, comment, create_homedir)
tasks = RedHatTaskNamespace()
--
2.4.3