diff --git a/obol.conf b/obol.conf index 1434abb..5996e34 100644 --- a/obol.conf +++ b/obol.conf @@ -2,6 +2,7 @@ home = /trinity/home shell = /bin/bash +skel = /etc/skel [ldap] diff --git a/obol/obol.py b/obol/obol.py index 1cf840f..9f86e5d 100755 --- a/obol/obol.py +++ b/obol/obol.py @@ -27,17 +27,19 @@ __status__ = "Development" -import os -import sys -import time -import json -import hashlib -import base64 import argparse +import base64 import configparser -import secrets -import logging +import hashlib import inspect +import json +import logging +import os +import secrets +import shutil +import sys +import time + from getpass import getpass from typing import List, Dict, Union @@ -410,6 +412,7 @@ def user_add( groups=None, home=None, expire=None, + skel=None, **kwargs, ): """Add a user to the LDAP directory""" @@ -468,6 +471,7 @@ def user_add( sn = sn or username home = home or f"{self.config.get('users', 'home')}/{username}" shell = shell or self.config.get("users", "shell") + skel = skel or self.config.get('users', 'skel', fallback='/etc/skel') if (expire is not None) and (expire != "-1"): expire = str(int(expire) + int(time.time() / 86400)) @@ -532,8 +536,10 @@ def user_add( # Create the user's home directory if not os.path.exists(home): - os.mkdir(home) - os.chown(home, int(uid), int(gid)) + shutil.copytree(skel, home, symlinks=True) + for dirpath, dirnames, filenames, dir_fd in os.fwalk(home, follow_symlinks=False): + for n in dirnames + filenames: + os.chown(n, int(uid), int(gid), dir_fd=dir_fd, follow_symlinks=False) else: home_folder_uid = int(os.stat(home).st_uid) if home_folder_uid != int(uid): @@ -1016,6 +1022,7 @@ def run(): ), ) user_addsubcommand.add_argument("--home", metavar="HOME") + user_addsubcommand.add_argument("--skel", metavar="SKEL_DIR") # User modify command user_modifysubcommand = user_subcommands.add_parser(