Commit 42e6a70f authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Support home renaming

parent 60ebefa3
......@@ -5,6 +5,7 @@ import socket
from re2oapi import Re2oAPIClient
import os
import shutil
import grp
import sys
......@@ -33,8 +34,26 @@ def reconfigure(api_client):
gid = user['gid']
if not os.path.exists(home): # Home dosen't exist, create it
os.makedirs(home,0o701)
os.chown(home,int(uid),int(gid))
users_dirs = []
for dirname in os.listdir("/home-adh"):
if os.stat("/home-adh/" + dirname).st_uid == uid and os.path.islink("/home-adh/" + dirname):
users_dirs.append(dirname)
if len(users_dirs) == 1:
# This user had already a home directory before, renaming it
# Renaming home directory
shutil.move("/home-adh/" + users_dirs[0][0].lower() + '/' + users_dirs[0], home)
os.chown(home,int(uid),int(gid))
os.chown(home + '/Mail', int(uid), int(gid))
# Deleting the symlink, will be recreated later
os.remove("/home-adh/" + users_dirs[0])
# Renaming the maildir
os.rename("/home-adh/mail/" + users_dirs[0], '/home-adh/mail/' + user['pseudo'])
os.chown('/home-adh/mail/' + user['pseudo'], int(uid), 8)
elif len(users_dirs) == 0:
os.makedirs(home,0o701)
os.chown(home,int(uid),int(gid))
# Mail
if not(os.path.exists(home + '/Mail')) and not(os.path.islink(home + '/Mail')):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment