This patch moves the permission handling code around a bit.