def owner(conn, target: str, owner: str):
    """
    Changes target ownership with provided owner (WriteOwner permission required)

    :param target: sAMAccountName, DN, GUID or SID of the target
    :param owner: sAMAccountName, DN, GUID or SID of the new owner
    """
    new_sid = next(conn.ldap.bloodysearch(owner, attr=["objectSid"]))["objectSid"]

    new_sd, _ = utils.getSD(
        conn, target, "nTSecurityDescriptor", accesscontrol.OWNER_SECURITY_INFORMATION
    )

    old_sid = new_sd["OwnerSid"].formatCanonical()
    if old_sid == new_sid:
        LOG.warning(f"[!] {old_sid} is already the owner, no modification will be made")
    else:
        new_sd["OwnerSid"].fromCanonical(new_sid)

        req_flags = msldap.wintypes.asn1.sdflagsrequest.SDFlagsRequestValue(
            {"Flags": accesscontrol.OWNER_SECURITY_INFORMATION}
        )
        controls = [("1.2.840.113556.1.4.801", True, req_flags.dump())]

        conn.ldap.bloodymodify(
            target,
            {"nTSecurityDescriptor": [(Change.REPLACE.value, new_sd.getData())]},
            controls,
        )

        LOG.info(f"[+] Old owner {old_sid} is now replaced by {owner} on {target}")

    Changes target ownership with provided owner (WriteOwner permission required)

    :param target: sAMAccountName, DN, GUID or SID of the target
    :param owner: sAMAccountName, DN, GUID or SID of the new owner
    
bloodyAD/cli_modules/set.py