Zhuchenko Valery
2015-May-27 09:50 UTC
[Samba] convert passwords samba3 smbpasswd to samba4
Hi All! I want update samba4 user passwords with smbpasswd, taken from samba3. After reading this post https://lists.samba.org/archive/samba/2013-April/172628.html I'm create similar script, and when run it, I can't login to samba4 resources with testaccount, but to samba3 resources I can do it. Where I'm wrong? ------------------- import sys import binascii import time from samba import Ldb, registry from samba.param import LoadParm from samba.samba3 import passdb from samba.samba3 import param as s3param from samba import dsdb def HexToByte( hexStr ): bytes = [] hexStr = ''.join( hexStr.split(" ") ) for i in range(0, len(hexStr), 2): bytes.append( chr( int (hexStr[i:i+2], 16 ) ) ) return ''.join( bytes ) new_lp_ctx = s3param.get_context() new_lp_ctx.load("/etc/samba/smb.conf") new_lp_ctx.set("private dir", "/var/lib/samba/private") s4_passdb = passdb.PDB(new_lp_ctx.get("passdb backend")) new_userdata = s4_passdb.getsampwnam("testaccount") if new_userdata.username: print new_userdata.username if new_userdata.nt_passwd: print binascii.hexlify(new_userdata.nt_passwd) new_userdata.nt_passwd = HexToByte("68434D070B60D728857018C972BDB75E") s4_passdb.update_sam_account(new_userdata) ------------------- samba version 4.1.17 Thank you, Valery.