+/*
+ * Implement HELO and EHLO commands.
+ */
+void smtp_hello(char *argbuf, int is_esmtp) {
+
+ if (!is_esmtp) {
+ cprintf("250 Greetings and joyous salutations.\n");
+ }
+ else {
+ cprintf("250-Greetings and joyous salutations.\n");
+ cprintf("250-HELP\n");
+ cprintf("250-SIZE %ld\n", config.c_maxmsglen);
+ cprintf("250 AUTH=LOGIN\n");
+ }
+}
+
+
+/*
+ * Implement HELP command.
+ */
+void smtp_help(void) {
+ cprintf("214-Here's the frequency, Kenneth:\n");
+ cprintf("214- EHLO\n");
+ cprintf("214- HELO\n");
+ cprintf("214- HELP\n");
+ cprintf("214- NOOP\n");
+ cprintf("214- QUIT\n");
+ cprintf("214 I'd tell you more, but then I'd have to kill you.\n");
+}
+
+
+/*
+ *
+ */
+void smtp_get_user(char *argbuf) {
+ char buf[256];
+ char username[256];
+
+ decode_base64(username, argbuf);
+ lprintf(9, "Trying <%s>\n", username);
+ if (CtdlLoginExistingUser(username) == login_ok) {
+ encode_base64(buf, "Password:");
+ cprintf("334 %s\n", buf);
+ SMTP->command_state = smtp_password;
+ }
+ else {
+ cprintf("500 No such user.\n");
+ SMTP->command_state = smtp_command;
+ }
+}
+
+
+/*
+ *
+ */
+void smtp_get_pass(char *argbuf) {
+ char password[256];
+
+ decode_base64(password, argbuf);
+ lprintf(9, "Trying <%s>\n", password);
+ if (CtdlTryPassword(password) == pass_ok) {
+ cprintf("235 Authentication successful.\n");
+ lprintf(9, "SMTP auth login successful\n");
+ }
+ else {
+ cprintf("500 Authentication failed.\n");
+ }
+ SMTP->command_state = smtp_command;
+}
+
+
+/*
+ *
+ */
+void smtp_auth(char *argbuf) {
+ char buf[256];
+
+ if (strncasecmp(argbuf, "login", 5) ) {
+ cprintf("500 We only support LOGIN authentication.\n");
+ return;
+ }
+
+ if (strlen(argbuf) >= 7) {
+ smtp_get_user(&argbuf[6]);
+ }
+
+ else {
+ encode_base64(buf, "Username:");
+ cprintf("334 %s\n", buf);
+ SMTP->command_state = smtp_user;
+ }
+}
+
+