Fixed bug in protection damageto-permission.
Added permission-debug command. Closes #596