+ p = msg;
+ q = p + sizeof(msg); /* points 1 byte past msg */
+
+ if (code == CHAP_SUCCESS) {
+#ifdef CHAPMS
+ if (cstate->chal_type == CHAP_MICROSOFT_V2) {
+ /*
+ * Success message must be formatted as
+ * "S=<auth_string> M=<message>"
+ * where
+ * <auth_string> is the Authenticator Response (mutual auth)
+ * <message> is a text message
+ */
+ slprintf(p, q - p, "S=");
+ p += 2;
+ slprintf(p, q - p, "%s", cstate->saresponse);
+ p += strlen(cstate->saresponse);
+ slprintf(p, q - p, " M=");
+ p += 3;
+ }
+#endif /* CHAPMS */
+
+ slprintf(p, q - p, "Welcome to %s.", hostname);
+ } else {
+#ifdef CHAPMS
+ if ((cstate->chal_type == CHAP_MICROSOFT_V2) ||
+ (cstate->chal_type == CHAP_MICROSOFT)) {
+ /*
+ * Failure message must be formatted as
+ * "E=e R=r C=c V=v M=m"
+ * where
+ * e = error code (we use 691, ERROR_AUTHENTICATION_FAILURE)
+ * r = retry (we use 1, ok to retry)
+ * c = challenge to use for next response, we reuse previous
+ * v = Change Password version supported, we use 0
+ * m = text message
+ *
+ * The M=m part is only for MS-CHAPv2, but MS-CHAP should ignore
+ * any extra text according to RFC 2433. So we'll go the easy
+ * (read: lazy) route and include it always.
+ */
+ slprintf(p, q - p, "E=691 R=1 C=");
+ p += 12;
+ for (i = 0; i < cstate->chal_len; i++)
+ sprintf(p + i * 2, "%02X", cstate->challenge[i]);
+ p += cstate->chal_len * 2;
+ slprintf(p, q - p, " V=0 M=");
+ p += 7;
+ }
+#endif /* CHAPMS */
+
+ slprintf(p, q - p, "I don't like you. Go 'way.");
+ }