]> code.citadel.org Git - citadel.git/commitdiff
* serv_smtp: implemented RFC821 "VRFY" and "EXPN" commands
authorArt Cancro <ajc@citadel.org>
Fri, 10 Dec 1999 21:34:19 +0000 (21:34 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 10 Dec 1999 21:34:19 +0000 (21:34 +0000)
citadel/ChangeLog
citadel/serv_smtp.c

index e5961c534aed046f5882331e4e5b964ba3f574f9..f4fce1e14741ea44b048cb73f93fde47001ad316 100644 (file)
@@ -1,4 +1,7 @@
 $Log$
+Revision 1.427  1999/12/10 21:34:19  ajc
+* serv_smtp: implemented RFC821 "VRFY" and "EXPN" commands
+
 Revision 1.426  1999/12/09 05:01:14  ajc
 * Split cmd_user() and cmd_pass() into frontend/backend functions
 * serv_smtp: implemented AUTH LOGIN for client authentication
@@ -1486,4 +1489,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Initial CVS import 
-
index 6d03178053cd4c57ab008c00d76233f1ba303ccd..5cfa5fa8301fc94f57644fcd4b9989c1679a7e48 100644 (file)
@@ -29,6 +29,9 @@
 
 struct citsmtp {
        int command_state;
+       struct usersupp vrfy_buffer;
+       int vrfy_count;
+       char vrfy_match[256];
 };
 
 enum {
@@ -78,11 +81,13 @@ void smtp_hello(char *argbuf, int is_esmtp) {
 void smtp_help(void) {
        cprintf("214-Here's the frequency, Kenneth:\n");
        cprintf("214-    EHLO\n");
+       cprintf("214-    EXPN\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");
+       cprintf("214-    VRFY\n");
+       cprintf("214 I could tell you more, but then I'd have to kill you.\n");
 }
 
 
@@ -149,6 +154,107 @@ void smtp_auth(char *argbuf) {
 }
 
 
+/*
+ * Return 0 if a given string fuzzy-matches a Citadel user account
+ *
+ * FIX ... this needs to be updated to match any and all ways of addressing
+ *         a user.  It may even be appropriate to move this out of SMTP and
+ *         into the server core.
+ */
+int fuzzy_match(struct usersupp *us, char *matchstring) {
+       int a;
+
+       for (a=0; a<strlen(us->fullname); ++a) {
+               if (!strncasecmp(&us->fullname[a],
+                  matchstring, strlen(matchstring))) {
+                       return 0;
+               }
+       }
+       return -1;
+}
+
+
+/*
+ * Back end for smtp_vrfy() command
+ */
+void smtp_vrfy_backend(struct usersupp *us) {
+
+       if (!fuzzy_match(us, SMTP->vrfy_match)) {
+               ++SMTP->vrfy_count;
+               memcpy(&SMTP->vrfy_buffer, us, sizeof(struct usersupp));
+       }
+}
+
+
+/* 
+ * Implements the VRFY (verify user name) command.
+ * Performs fuzzy match on full user names.
+ */
+void smtp_vrfy(char *argbuf) {
+       SMTP->vrfy_count = 0;
+       strcpy(SMTP->vrfy_match, argbuf);
+       ForEachUser(smtp_vrfy_backend);
+
+       if (SMTP->vrfy_count < 1) {
+               cprintf("550 String does not match anything.\n");
+       }
+       else if (SMTP->vrfy_count == 1) {
+               cprintf("250 %s <cit%ld@%s>\n",
+                       SMTP->vrfy_buffer.fullname,
+                       SMTP->vrfy_buffer.usernum,
+                       config.c_fqdn);
+       }
+       else if (SMTP->vrfy_count > 1) {
+               cprintf("553 Request ambiguous: %d users matched.\n",
+                       SMTP->vrfy_count);
+       }
+
+}
+
+
+
+/*
+ * Back end for smtp_expn() command
+ */
+void smtp_expn_backend(struct usersupp *us) {
+
+       if (!fuzzy_match(us, SMTP->vrfy_match)) {
+
+               if (SMTP->vrfy_count >= 1) {
+                       cprintf("250-%s <cit%ld@%s>\n",
+                               SMTP->vrfy_buffer.fullname,
+                               SMTP->vrfy_buffer.usernum,
+                               config.c_fqdn);
+               }
+
+               ++SMTP->vrfy_count;
+               memcpy(&SMTP->vrfy_buffer, us, sizeof(struct usersupp));
+       }
+}
+
+
+/* 
+ * Implements the EXPN (expand user name) command.
+ * Performs fuzzy match on full user names.
+ */
+void smtp_expn(char *argbuf) {
+       SMTP->vrfy_count = 0;
+       strcpy(SMTP->vrfy_match, argbuf);
+       ForEachUser(smtp_expn_backend);
+
+       if (SMTP->vrfy_count < 1) {
+               cprintf("550 String does not match anything.\n");
+       }
+       else if (SMTP->vrfy_count >= 1) {
+               cprintf("250 %s <cit%ld@%s>\n",
+                       SMTP->vrfy_buffer.fullname,
+                       SMTP->vrfy_buffer.usernum,
+                       config.c_fqdn);
+       }
+}
+
+
+
 /* 
  * Main command loop for SMTP sessions.
  */
@@ -181,6 +287,10 @@ void smtp_command_loop(void) {
                smtp_hello(&cmdbuf[5], 1);
        }
 
+       else if (!strncasecmp(cmdbuf, "EXPN", 4)) {
+               smtp_expn(&cmdbuf[5]);
+       }
+
        else if (!strncasecmp(cmdbuf, "HELO", 4)) {
                smtp_hello(&cmdbuf[5], 0);
        }
@@ -199,6 +309,10 @@ void smtp_command_loop(void) {
                return;
                }
 
+       else if (!strncasecmp(cmdbuf, "VRFY", 4)) {
+               smtp_vrfy(&cmdbuf[5]);
+       }
+
        else {
                cprintf("500 I'm afraid I can't do that, Dave.\n");
        }