From: Art Cancro Date: Thu, 19 Jun 2003 04:12:30 +0000 (+0000) Subject: * domain.c: use qsort() to sort MX records by preference. Why have a X-Git-Tag: v7.86~5850 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=5485a5966fcfeda759901f5256b7c7287d1da0df;p=citadel.git * 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. --- diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 68c3fd438..bba1f22b5 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/domain.c b/citadel/domain.c index 1c43ef513..6e0987089 100644 --- a/citadel/domain.c +++ b/citadel/domain.c @@ -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; nfrom); 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.