First commit
This commit is contained in:
commit
3efa320587
2 changed files with 67 additions and 0 deletions
46
ldap2smb.py
Normal file
46
ldap2smb.py
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import json
|
||||||
|
|
||||||
|
import getpass
|
||||||
|
import ldb
|
||||||
|
from samba.auth import system_session
|
||||||
|
from samba.credentials import Credentials
|
||||||
|
from samba.dcerpc import security
|
||||||
|
from samba.dcerpc.security import dom_sid
|
||||||
|
from samba.ndr import ndr_pack, ndr_unpack
|
||||||
|
from samba.param import LoadParm
|
||||||
|
from samba.samdb import SamDB
|
||||||
|
|
||||||
|
lp = LoadParm()
|
||||||
|
creds = Credentials()
|
||||||
|
creds.guess(lp)
|
||||||
|
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"
|
||||||
|
attributes_list = []
|
||||||
|
|
||||||
|
with open(data_file, "r") 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_givenname = ldap_users["params"]["attributes"]["givenName"]
|
||||||
|
smb_surname = ldap_users["params"]["attributes"]["sn"]
|
||||||
|
smb_homedir = ldap_users["params"]["attributes"]["homeDirectory"]
|
||||||
|
smb_mail = ldap_users["params"]["attributes"]["mail"]
|
||||||
|
smb_uid_number = ldap_users["params"]["attributes"]["uidNumber"]
|
||||||
|
smb_gid_number = ldap_users["params"]["attributes"]["gidNumber"]
|
||||||
|
|
||||||
|
samdb.newuser(username=smb_username,password=smb_passwd,givenname=smb_givenname,surname=smb_surname,homedirectory=smb_homedir,mailaddress=smb_mail,uidnumber=smb_uid_number,gidnumber=smb_gid_number,useusernameascn=True)
|
||||||
|
|
||||||
|
query = "(objectclass=user)"
|
||||||
|
result = samdb.search('DC=nantes,DC=omero-fbi,DC=fr', expression=query, scope=ldb.SCOPE_SUBTREE)
|
||||||
|
for item in result:
|
||||||
|
if 'sAMAccountName' in item:
|
||||||
|
print(item['distinguishedName'])
|
||||||
|
print(item['sAMAccountName'])
|
21
user.json
Normal file
21
user.json
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"worker": "ldap",
|
||||||
|
"action": "update",
|
||||||
|
"params": {
|
||||||
|
"id": 25,
|
||||||
|
"attributes": {
|
||||||
|
"cn": "guillaume-jf@univ-nantes.fr",
|
||||||
|
"uid": "guillaume-jf@univ-nantes.fr",
|
||||||
|
"mail": "Jean-Francois.Guillaume@univ-nantes.fr",
|
||||||
|
"uidNumber": 8000001,
|
||||||
|
"gidNumber": 8000001,
|
||||||
|
"homeDirectory": "/home/guillaume-jf@univ-nantes.fr",
|
||||||
|
"givenName": "Jean-François",
|
||||||
|
"sn": "Guillaume",
|
||||||
|
"userPassword": "{ssha256}tagadapouetpouet"
|
||||||
|
},
|
||||||
|
"dn": "uid=guillaume-jf@univ-nantes.fr,ou=people,dc=glicid,dc=fr",
|
||||||
|
"type": "user",
|
||||||
|
"create_if_not_exist": "True"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue