def delta_update_basesamdb(refsampath, sampath, creds, session, lp, message): """Update the provision container db: sam.ldb This function is aimed for alpha9 and newer; :param refsampath: Path to the samdb in the reference provision :param sampath: Path to the samdb in the upgraded provision :param creds: Credential used for openning LDB files :param session: Session to use for openning LDB files :param lp: A loadparam object :return: A msg_diff object with the difference between the @ATTRIBUTES of the current provision and the reference provision """ message(SIMPLE, "Update base samdb by searching difference with reference one") refsam = Ldb(refsampath, session_info=session, credentials=creds, lp=lp, options=["modules:"]) sam = Ldb(sampath, session_info=session, credentials=creds, lp=lp, options=["modules:"]) empty = ldb.Message() deltaattr = None reference = refsam.search(expression="") for refentry in reference: entry = sam.search(expression="distinguishedName=%s" % refentry["dn"], scope=SCOPE_SUBTREE) if not len(entry): delta = sam.msg_diff(empty, refentry) message(CHANGE, "Adding %s to sam db" % str(refentry.dn)) if str(refentry.dn) == "@PROVISION" and\ delta.get(samba.provision.LAST_PROVISION_USN_ATTRIBUTE): delta.remove(samba.provision.LAST_PROVISION_USN_ATTRIBUTE) delta.dn = refentry.dn sam.add(delta) else: delta = sam.msg_diff(entry[0], refentry) if str(refentry.dn) == "@ATTRIBUTES": deltaattr = sam.msg_diff(refentry, entry[0]) if str(refentry.dn) == "@PROVISION" and\ delta.get(samba.provision.LAST_PROVISION_USN_ATTRIBUTE): delta.remove(samba.provision.LAST_PROVISION_USN_ATTRIBUTE) if len(delta.items()) > 1: delta.dn = refentry.dn sam.modify(delta) return deltaattr
opts = parser.parse_args()[0] lp = sambaopts.get_loadparm() smbconf = lp.configfile if not opts.database: print "Parameter database is mandatory" sys.exit(1) creds = credopts.get_credentials(lp) creds.set_kerberos_state(DONT_USE_KERBEROS) session = system_session() empty = ldb.Message() newname="%s.new"%(opts.database) if os.path.exists(newname): os.remove(newname) old_ldb = Ldb(opts.database, session_info=session, credentials=creds,lp=lp) new_ldb = Ldb(newname,session_info=session, credentials=creds,lp=lp) new_ldb.transaction_start() res = old_ldb.search(expression="(dn=*)",base="", scope=SCOPE_SUBTREE) for i in range(0,len(res)): if str(res[i].dn) == "@BASEINFO": continue if str(res[i].dn).startswith("@INDEX:"): continue delta = new_ldb.msg_diff(empty,res[i]) delta.dn = res[i].dn delta.remove("distinguishedName") new_ldb.add(delta) new_ldb.transaction_commit()
opts = parser.parse_args()[0] lp = sambaopts.get_loadparm() smbconf = lp.configfile if not opts.database: print "Parameter database is mandatory" sys.exit(1) creds = credopts.get_credentials(lp) creds.set_kerberos_state(DONT_USE_KERBEROS) session = system_session() empty = ldb.Message() newname = "%s.new" % (opts.database) if os.path.exists(newname): os.remove(newname) old_ldb = Ldb(opts.database, session_info=session, credentials=creds, lp=lp) new_ldb = Ldb(newname, session_info=session, credentials=creds, lp=lp) new_ldb.transaction_start() res = old_ldb.search(expression="(dn=*)", base="", scope=SCOPE_SUBTREE) for i in range(0, len(res)): if str(res[i].dn) == "@BASEINFO": continue if str(res[i].dn).startswith("@INDEX:"): continue delta = new_ldb.msg_diff(empty, res[i]) delta.dn = res[i].dn delta.remove("distinguishedName") new_ldb.add(delta) new_ldb.transaction_commit()