* domain.c: use qsort() to sort MX records by preference. Why have a
authorArt Cancro <ajc@citadel.org>
Thu, 19 Jun 2003 04:12:30 +0000 (04:12 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 19 Jun 2003 04:12:30 +0000 (04:12 +0000)
  custom function when the operating system provides one for free?
* serv_smtp.c: accept mail from "<>" (empty sender).  RFC1123 5.2.9 demands it.

citadel/ChangeLog
citadel/domain.c
citadel/serv_smtp.c

index 68c3fd438e7d85f2e072230dfa591a469b8aa183..bba1f22b5a5583802324edd57d3cce75ac0b21a5 100644 (file)
@@ -1,4 +1,9 @@
  $Log$
+ Revision 607.4  2003/06/19 04:12:30  ajc
+ * domain.c: use qsort() to sort MX records by preference.  Why have a
+   custom function when the operating system provides one for free?
+ * serv_smtp.c: accept mail from "<>" (empty sender).  RFC1123 5.2.9 demands it.
+
  Revision 607.3  2003/06/19 03:55:22  ajc
  * Fixed a subtle but ugly bug in the SMTP sender that was causing it to
    ignore all successful connections except the last one.  Now when it gets
@@ -4772,4 +4777,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 1c43ef513671818696968547ef0b003d64763cc0..6e098708936cafce5d217badad11094722769cf2 100644 (file)
@@ -64,7 +64,13 @@ int get_hosts(char *mxbuf, char *rectype) {
  * number listed in the MX record.  If they're identical, randomize the
  * result.
  */
-inline int mx_compare_pref(int pref1, int pref2) {
+int mx_compare_pref(const void *mx1, const void *mx2) {
+       int pref1;
+       int pref2;
+
+       pref1 = ((const struct mx *)mx1)->pref;
+       pref2 = ((const struct mx *)mx2)->pref;
+
        if (pref1 > pref2) {
                return(1);
        }
@@ -77,33 +83,6 @@ inline int mx_compare_pref(int pref1, int pref2) {
 }
 
 
-/*
- * sort_mxrecs()
- *
- * Sort a pile of MX records (struct mx, definted in domain.h) by preference
- *
- */
-void sort_mxrecs(struct mx *mxrecs, int num_mxrecs) {
-       int a, b;
-       struct mx hold1, hold2;
-
-       if (num_mxrecs < 2) return;
-
-       /* do the sort */
-       for (a = num_mxrecs - 2; a >= 0; --a) {
-               for (b = 0; b <= a; ++b) {
-                       if (mx_compare_pref(mxrecs[b].pref,mxrecs[b+1].pref)) {
-                               memcpy(&hold1, &mxrecs[b], sizeof(struct mx));
-                               memcpy(&hold2, &mxrecs[b+1], sizeof(struct mx));
-                               memcpy(&mxrecs[b], &hold2, sizeof(struct mx));
-                               memcpy(&mxrecs[b+1], &hold1, sizeof(struct mx));
-                       }
-               }
-       }
-}
-
-
-
 /* 
  * getmx()
  *
@@ -237,7 +216,10 @@ int getmx(char *mxbuf, char *dest) {
        }
 #endif /* HAVE_RESOLV_H */
 
-       sort_mxrecs(mxrecs, num_mxrecs);
+       /* Sort the MX records by preference */
+       if (num_mxrecs > 1) {
+               qsort(mxrecs, num_mxrecs, sizeof(struct mx), mx_compare_pref);
+       }
 
        strcpy(mxbuf, "");
        for (n=0; n<num_mxrecs; ++n) {
index 44164aefa23a1b7d08b471b10d1e52817e369fe8..6f8fa715868664d3fbd53f69e4e218e8447d18c3 100644 (file)
@@ -366,10 +366,13 @@ void smtp_mail(char *argbuf) {
        striplt(SMTP->from);
        stripallbut(SMTP->from, '<', '>');
 
+       /* We used to reject empty sender names, until it was brought to our
+        * attention that RFC1123 5.2.9 requires that this be allowed.
        if (strlen(SMTP->from) == 0) {
                cprintf("501 5.1.7 Empty sender name is not permitted\r\n");
                return;
        }
+        */
 
        /* If this SMTP connection is from a logged-in user, force the 'from'
         * to be the user's Internet e-mail address as Citadel knows it.