Use the stashed runas groups instead of using getgrouplist() Reset perms to the initial value on error