+
+# Get the authorization cookie from the current user.
+COOKIE="$(xauth nextract - $DISPLAY)"
+
+# XAUTHORITY needs to be unset now, so that the default $HOME/.Xauthority will
+# be used for the target user and not some locked auth file from the current
+# user.
+unset XAUTHORITY
+
+# Authorize the user.
+# Use "sudo -H" to cover the case when env_keep+="HOME" is set in /etc/sudoers
+echo "$COOKIE" | sudo -H -u "$USERNAME" xauth nmerge -