From 0b560b0c51a1a42c5450a28ee014d6672d6bb2d6 Mon Sep 17 00:00:00 2001 From: Guus Bertens Date: Fri, 4 Oct 2024 14:21:11 +0200 Subject: [PATCH 1/2] sort imports --- obol/obol.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/obol/obol.py b/obol/obol.py index 1cf840f..1e22511 100755 --- a/obol/obol.py +++ b/obol/obol.py @@ -27,17 +27,18 @@ __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 sys +import time + from getpass import getpass from typing import List, Dict, Union From 9618587d6d804ca144cc872ecc75b53835ca1dbd Mon Sep 17 00:00:00 2001 From: Guus Bertens Date: Fri, 4 Oct 2024 15:28:02 +0200 Subject: [PATCH 2/2] create home dir by copying /etc/skel --- obol.conf | 1 + obol/obol.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) 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 1e22511..9f86e5d 100755 --- a/obol/obol.py +++ b/obol/obol.py @@ -36,6 +36,7 @@ import logging import os import secrets +import shutil import sys import time @@ -411,6 +412,7 @@ def user_add( groups=None, home=None, expire=None, + skel=None, **kwargs, ): """Add a user to the LDAP directory""" @@ -469,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)) @@ -533,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): @@ -1017,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(