r18864: merge lib/replace changes from samba4