Turns out that my second patch doesn't correctly handle aliases which expand to a non-existent local user, so in that case, my first patch may be preferable.
Turns out that my second patch doesn't correctly handle aliases which expand to a non-existent local user, so in that case, my first patch may be preferable.