Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions obol.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

home = /trinity/home
shell = /bin/bash
skel = /etc/skel

[ldap]

Expand Down
27 changes: 17 additions & 10 deletions obol/obol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -410,6 +412,7 @@ def user_add(
groups=None,
home=None,
expire=None,
skel=None,
**kwargs,
):
"""Add a user to the LDAP directory"""
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down