def _ensure_authed(self, ptype, message):
if (<EOL>not self.server_mode<EOL>or ptype <= HIGHEST_USERAUTH_MESSAGE_ID<EOL>or self.is_authenticated()<EOL>):<EOL><INDENT>return None<EOL><DEDENT>reply = Message()<EOL>if ptype == MSG_GLOBAL_REQUEST:<EOL><INDENT>reply.add_byte(cMSG_REQUEST_FAILURE)<EOL><DEDENT>elif ptype == MSG_CHANNEL_OPEN:<EOL><INDENT>kind = message.get_text()  <EOL>chanid = message.get_int()<EOL>reply.add_byte(cMSG_CHANNEL_OPEN_FAILURE)<EOL>reply.add_int(chanid)<EOL>reply.add_int(OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED)<EOL>reply.add_string("<STR_LIT>")<EOL>reply.add_string("<STR_LIT>")<EOL><DEDENT>return reply<EOL>
Checks message type against current auth state.

If server mode, and auth has not succeeded, and the message is of a
post-auth type (channel open or global request) an appropriate error
response Message is crafted and returned to caller for sending.

Otherwise (client mode, authed, or pre-auth message) returns None.