+static gint smtp_auth_plain(SMTPSession *session)
+{
+ gchar buf[MSGBUFSIZE];
+
+ /*
+ * +1 +1 +1
+ * \0<user>\0<pass>\0
+ */
+ int b64len = (1 + strlen(session->user) + 1 + strlen(session->pass) + 1);
+ gchar *b64buf = g_malloc(b64len);
+
+ /* use the char *ptr to walk the base64 string with embedded \0 */
+ char *a = b64buf;
+ int b64cnt = 0;
+
+ session->state = SMTP_AUTH_PLAIN;
+ session->auth_type = SMTPAUTH_PLAIN;
+
+ memset(buf, 0, sizeof buf);
+
+ /*
+ * have to construct the string bit by bit. sprintf can't do it in one.
+ * first field is null, so string is \0<user>\0<password>
+ */
+ *a = 0;
+ a++;
+
+ g_snprintf (a, b64len - 1, "%s", session->user);
+
+ b64cnt = strlen(session->user)+1;
+ a += b64cnt;
+
+ g_snprintf (a, b64len - b64cnt - 1, "%s", session->pass);
+ b64cnt += strlen(session->pass) + 1;
+
+ /*
+ * reuse the char *ptr to offset into the textbuf to meld
+ * the plaintext ESMTP message and the base64 string value
+ */
+ strcpy(buf, "AUTH PLAIN ");
+ a = buf + strlen(buf);
+ base64_encode(a, b64buf, b64cnt);
+
+ session_send_msg(SESSION(session), SESSION_MSG_NORMAL, buf);
+
+ log_print("ESMTP> [AUTH PLAIN]\n");
+
+ g_free(b64buf);
+
+ return SM_OK;
+}
+