graymilter with DNS based whitelists support – part 2

In part 1 I showed how one can use tcp_wrappers to patch graymilter in order to support dns based whitelists (as opposed to IP based whitelists that it supports by default).

But what if you need something faster than having graymilter open /etc/hosts.allow for every message passed to it in order to decide whether the sending host is whitelisted or not?

Basically you need a strcmp(3) function with a twist. While the strcmp(3) family of functions compare from left to right, you need the opposite:

#ifndef _RIGHT_STRCMP_C_
#define _RIGHT_STRCMP_C_ 1

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Think of this as a rightmost strcmp() */

static int
right_strcmp(char *x, char *y)
{
int xl, yl, l;
char *s;

        xl = strlen(x);
        yl = strlen(y);
        l = xl - yl;

        if (l < 0) {
                return l;
        } else {
                s = x + l;
                return (strncmp(s, y, yl));
        }
}

#endif /* _RIGHT_STRCMP_C_ */

Now you can include the file right_strcmp.c at the top of graymilter.c (remember right_strcmp() is declared as a static function). If you are using graymilter version 1.26 you then scroll down at line 680 and add this snippet of code:

$ diff graymilter.c graymilter.c-
76d75
< #include "right_strcmp.c"
680,692d678
<     if (right_strcmp(connhost, ".example.com") == 0) {
<           syslog(LOG_INFO, "accepting host %s", connhost);
<           return SMFIS_ACCEPT;
<     }
<     if (right_strcmp(connhost, ".example.org") == 0) {
<           syslog(LOG_INFO, "accepting host %s", connhost);
<           return SMFIS_ACCEPT;
<     }
<     if (right_strcmp(connhost, ".example.net") == 0) {
<           syslog(LOG_INFO, "accepting host %s", connhost);
<           return SMFIS_ACCEPT;
<     }
<

Yes, the above example hardcodes the domains into the graymilter executable. One is free to play around and write a simple function that reads a domain list from a file and wraps around right_strcmp() with the help of stdarg(3). That way you only have to write one if statement. This is left as an exercise to the reader.

(part 1) (part 3)

Network byte order

Note to self:

Όταν διαβάζεις πακέτα από το καλώδιο να θυμάσαι πως οι τιμές στα headers είναι σε network byte order. Γι’αυτό και εκεί που περιμένεις 53 διαβάζεις 13568 (256 * 53). Τα παλικάρια που φτιάξανε το ntohs(3) κάτι ξέρανε.

SMS

Πάμε πάλι… Repeat after me:

Το SMS δεν είναι Instant Messaging

ξανά:

Το SMS δεν είναι Instant Messaging
:
Το SMS δεν είναι Instant Messaging

και:

Η αναφορά παράδοσης του μηνύματος δεν είναι αναφορά ανάγνωσης
:
Η αναφορά παράδοσης του μηνύματος δεν είναι αναφορά ανάγνωσης

(read more)

shit happens :(

Είχα ετοιμάσει την εικονίτσα ωραία-ωραία για να το γιορτάσω: t_34.jpg

Δεν πειράζει…
(ref)

Υ.Γ.1: Η γκαντεμιά του να είσαι ο Γιώργος Ανατολάκης: Δεν έχει καμία σημασία εάν παίζεις καλά ή όχι. Το γκολ θα έρθει από τη μεριά σου.
Υ.Γ.2: Από τα αξιοσημείωτα το πανώ που σηκώθηκε στα Σέρβικα(;) και έγραφε (υποθέτω) πως το “Το Κόσοβο είναι Σερβικό”.
Υ.Γ.3: Δεν είναι και πολύ έξυπνο να πετάς τα καπνογόνα έτσι ώστε να μη βλέπει ο δικός σου τερματοφύλακας.

email

Repeat after me:

Το email δεν είναι Instant Messaging

ξανά:

Το email δεν είναι Instant Messaging
:
Το email δεν είναι Instant Messaging

Και για όποιον δεν κατάλαβε:

Instant messaging or IM is a form of real-time communication between two or more people based on typed text.

Που σημαίνει πως εάν ένα mail που περιμένετε έχει καθυστερήσει, αυτό είναι κάτι φυσιολογικό ανεξάρτητα από το τι εσείς πιστεύετε για τη δρομολόγησή του (και το πόση ώρα μπορεί να χρειαστεί για να παραδοθεί). Το ότι όλα τα προηγούμενα emails σας παραδόθηκαν “αμέσως” δεν είναι κριτήριο για το χρόνο παράδοσης του επόμενου. Αυτό συμβαίνει γιατί το ηλεκτρονικό ταχυδρομείο είναι store-and-forward και όχι real-time service.

Εάν χρειάζεστε άμεση παράδοση / ανταπόκριση στοιχείων και αρχείων χρησιμοποιείστε ΙΜ, όχι το email.

Update: 2009/03/26: Σχετικό post: Email is store-and-forward.

Άνθρωποι και ζώα

Πριν μερικές μέρες και ενώ γύρισε η γυναίκα μου στο σπίτι (μετά από ψώνια βεβαίως βεβαίως) μου δείχνει ένα σημείωμα που βρήκε στο αυτοκίνητο:

“Σας χτύπησα, το τηλέφωνό μου είναι 69xxxxxxxx. Δήμητρα”

Το περίεργο ήταν πως η γυναίκα μου δεν μπορούσε να εντοπίσει τη ζημιά. Πηγαίνοντας κάτω να δω το αυτοκίνητο, παρατήρησα μια μικρή γρατζουνιά χαμηλά στην πόρτα του οδηγού, από αυτές που εύκολα αγνοεί κανείς όταν οδηγεί στην Αθήνα.

Τηλεφωνήσαμε στην κοπέλα η οποία μας είπε:

– Σας χτύπησα το αμάξι και επειδή το είδα καινούργιο και δεν θα ήθελα να μου κάνουν το ίδιο στο δικό μου και να φύγουν, σας άφησα σημείωμα.

Εννοείται πως δεν έχουμε καμία αξίωση από τη Δήμητρα. Πόσο διαφορετική η συμπεριφορά της όμως σε σχέση με αυτό που έπαθε ο betabug: betabugcar.jpg
[image source]

graymilter with DNS based whitelists support – part 1

graymilter is an excellent (and very simple) tool to implement Greylisting. But what if you want to have whitelists not based on IP lists, but on DNS instead? Say to allow all .amazon.com machines to connect to your mail server without having to know the IP addresses range of Amazon’s outgoing mail servers?

A first attempt using tcp_wrappers:

Here comes my patch on graymilter.c (version 1.23):

Tue Jun 14 16:54 [146] > diff graymilter.c graymilter.c-
76d75
< #include <tcpd.h>
543d541
<     struct request_info req;
582,593d579
<
<     /*
<      * Check if the hostname is allowed in /etc/hosts.allow.
<      * Note 1: We are searching only for ALLOW entries.  DENY entries
<      *         are ignored
<      * Note 2: The servicename in /etc/hosts.allow is graymilter
<      */
<     request_init(&req, RQ_DAEMON, "graymilter", RQ_CLIENT_NAME, connhost, 0);
<     fromhost(&req);
<     if (hosts_access(&req)) {
<         syslog( LOG_INFO, "%s is whitelisted by /etc/hosts.allow - accepting",
<                 connhost );
<         return SMFIS_ACCEPT;
<     }

Please remember to add -lwrap at LDFLAGS in your Makefile.

Use this hack with great care. An enty like:

graymilter: .gr : ALLOW

in /etc/hosts.allow would mean that any host in the .gr domain name space is whitelisted. This includes DSL and dialup customers of all the Greek ISPs! This is definately not what you wanted whitelisted.

Drawback of this patch: On a mail server with hundred of messages per hour (the patched) graymilter crashes because it opens far too many times /etc/hosts.allow for reading. Part 2 of this post will deal with a solution to this problem.

(part 2)

Κάτσε κάτω από τη μπάρα!

Έκανα χτες ένα πρόχειρο υπολογισμό και για να διαβάσω ότι έχει μαζευτεί στο σπίτι και το γραφείο σχετικό με τη δουλειά μου (βιβλία, περιοδικά, papers και κώδικας), θα χρειαστώ 2 χρόνια καθημερινό διάβασμα0 (όχι μελέτη) just to keep up-to-date1 (χωρίς να υπολογίζω την εξέλιξη που ταυτόχρονα θα έχουν τα ίδια πεδία).

Και σα να μη φτάνουν αυτά, πρέπει να διαβάζω και την αντίστοιχη νομοθεσία. Και έχω διαβάσει τόση τα τελευταία 4 χρόνια, που θα ήταν καλύτερα να είχα γραφτεί στη Νομική (δίπλα είναι). Να έχει και ένα αντίκρυσμα το διάβασμα που κάνω. Από την άλλη ίσως είναι καλύτερα που δεν γράφτηκα.

Οποιαδήποτε ιδέα για home project είτε αναβάλλεται, είτε πρέπει να συνδιαστεί με παραίτηση.
:(


[0] – Και δεν υπολογίζω λογοτεχνία ή άλλα αναγνώσματα.
[1] – Δες και το Sage Salary Survey 2005-2006. Ο μέσος χρόνος που αφιερώνει ο System Administrator σε διάβασμα just to keep up-to-date είναι 8.7 ώρες την εβδομάδα.