Can create multiple user at once with ldap2smb
This commit is contained in:
parent
e3e9e79965
commit
4e9c4fa853
1 changed files with 43 additions and 35 deletions
18
ldap2smb.py
18
ldap2smb.py
|
@ -1,3 +1,4 @@
|
|||
import sys
|
||||
import json
|
||||
|
||||
import getpass
|
||||
|
@ -10,6 +11,10 @@ from samba.ndr import ndr_pack, ndr_unpack
|
|||
from samba.param import LoadParm
|
||||
from samba.samdb import SamDB
|
||||
|
||||
global lp
|
||||
global creds
|
||||
global samdb
|
||||
|
||||
lp = LoadParm()
|
||||
creds = Credentials()
|
||||
creds.guess(lp)
|
||||
|
@ -17,16 +22,14 @@ creds.set_username('admin')
|
|||
creds.set_password('Jps55Sk8An9y2nVL')
|
||||
samdb = SamDB(url='/var/lib/samba/private/sam.ldb', session_info=system_session(),credentials=creds, lp=lp)
|
||||
|
||||
data_file="user.json"
|
||||
|
||||
with open(data_file, "r") as file:
|
||||
def adduser():
|
||||
with open(DATA_FILE, "r", encoding="utf8") as file:
|
||||
ldap_users = json.load(file)
|
||||
|
||||
smb_full_username = ldap_users["params"]["attributes"]["uid"]
|
||||
smb_username = smb_full_username.split('@', 1)[0]
|
||||
|
||||
smb_full_passwd = ldap_users["params"]["attributes"]["userPassword"]
|
||||
smb_passwd = smb_full_passwd.split('}', 1)[1]
|
||||
smb_passwd = ldap_users["params"]["attributes"]["userPassword"]
|
||||
|
||||
smb_givenname = ldap_users["params"]["attributes"]["givenName"]
|
||||
smb_surname = ldap_users["params"]["attributes"]["sn"]
|
||||
|
@ -53,3 +56,8 @@ with open(data_file, "r") as file:
|
|||
if 'sAMAccountName' in item:
|
||||
print(item['distinguishedName'])
|
||||
print(item['sAMAccountName'])
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
print(arg)
|
||||
DATA_FILE = arg
|
||||
adduser()
|
||||
|
|
Loading…
Reference in a new issue