-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathuserdel
executable file
·36 lines (27 loc) · 1018 Bytes
/
userdel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env python
from manageldap import *
from subprocess import *
import argparse, os, pwd, re, shutil
def performLocal(name, remove):
user = pwd.getpwnam(name)
uid = user.pw_uid
gid = user.pw_gid
home = user.pw_dir
mail = "/var/mail/%s" % (name)
local = "/usr/local/sbin/deluser.local"
if os.path.exists(local):
deluser = call([local, name, str(uid), str(gid), home])
if not remove:
return
if os.path.isdir(home):
shutil.rmtree(home)
if os.path.isfile(mail):
os.remove(mail)
parser = argparse.ArgumentParser(description="Add users to LDAP Directory")
parser.add_argument('-r','--remove',action='store_true',help="Files in the user's home directory will be removed along with the home directory itself and the user's mail spool.")
parser.add_argument("login",type=str)
args = parser.parse_args()
# Do local things first (like remove home and mail)
performLocal(args.login, args.remove)
rmuser = userdel(args.login)
update(rmuser)