/* Copyright (C) 2003 Timo Sirainen, LGPLv2.1 */ /* Installation: export dovecot=~/src/dovecot gcc -Wall -W -shared -fPIC -DHAVE_CONFIG_H -I$dovecot -I$dovecot/src/lib \ drac.c -o drac.so -ldrac cp drac.so /usr/local/lib/dovecot/imap/ cp drac.so /usr/local/lib/dovecot/pop3/ */ #include "lib.h" #include "ioloop.h" #include "network.h" #include #define DRAC_TIMEOUT_SECS 60 #define DRAC_HOST "localhost" int dracauth(char *host, unsigned long ip, char **errmsg); static struct timeout *to_drac = NULL; static unsigned long in_ip; static void drac_timeout(void *context __attr_unused__) { char *err; if (dracauth(DRAC_HOST, in_ip, &err) != 0) i_error("dracauth() failed: %s", err); } void drac_init(void) { const char *ip_str; struct ip_addr ip; ip_str = getenv("IP"); if (ip_str == NULL) i_error("DRAC: IP environment not given"); else if (net_addr2ip(ip_str, &ip) < 0) i_error("DRAC: net_ip2addr(%s) failed: %m", ip_str); else if (!IPADDR_IS_V4(&ip)) i_error("DRAC: Only IPv4 addresses are supported (%s)", ip_str); else { in_ip = ((struct in_addr *) &ip.ip)->s_addr; drac_timeout(NULL); to_drac = timeout_add(1000*DRAC_TIMEOUT_SECS, drac_timeout, NULL); } } void drac_deinit(void) { if (to_drac != NULL) timeout_remove(&to_drac); }