$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
Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
* Initial CVS import
-
* 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);
}
}
-/*
- * 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()
*
}
#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) {
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.