diff -urN imap-2001a-orig/src/imapd/imapd.c imap-2001a/src/imapd/imapd.c --- imap-2001a-orig/src/imapd/imapd.c Thu Nov 15 00:26:07 2001 +++ imap-2001a/src/imapd/imapd.c Sun Dec 30 00:05:49 2001 @@ -29,6 +29,11 @@ #include "c-client.h" #include +#ifdef DRAC_AUTH +#include +#include +#include +#endif /* DRAC_AUTH */ #define CRLF PSOUT ("\015\012") /* primary output terpri */ @@ -173,6 +178,13 @@ /* Global storage */ +#ifdef DRAC_AUTH +#define DRACTIMEOUT 10*60 /* check every 10 minutes */ +time_t lastdrac = 0; /* time of last drac check */ +extern char *getenv (); +#endif /* DRAC_AUTH */ + + char *version = "2001.315"; /* version number of this server */ time_t alerttime = 0; /* time of last alert */ time_t sysalerttime = 0; /* time of last system alert */ @@ -1226,6 +1238,45 @@ lasterror ()); return; } + +#ifdef DRAC_AUTH + if (time (0) > lastdrac + DRACTIMEOUT) + { + FILE *dracconf; + char host[100]; + char *drachost; + char *err; + char *p; + + if ( (dracconf = fopen("/etc/mail/dracd.host", "r")) == NULL) + { + syslog (LOG_INFO, "dracd: error opening /etc/mail/dracd.host config file"); + exit(1); + } + + fgets(host, 100, dracconf); + p = strchr(host, '\n'); + if(p != NULL) + *p = '\0'; + fclose(dracconf); + + if( drachost = (host) ) + { + struct sockaddr_in sin; + int sinlen = sizeof (struct sockaddr_in); + char *client = getpeername (0,(struct sockaddr *) &sin,(void *) &sinlen) ? + "UNKNOWN" : inet_ntoa (sin.sin_addr); + + lastdrac = time(0); + + if (dracauth(drachost, inet_addr(client), &err) != 0) + syslog (LOG_INFO, err); + else + syslog (LOG_INFO, "dracd: authorized ip %s", client); + } + } +#endif /* DRAC_AUTH */ + /* change in number of messages? */ if (existsquelled || (nmsgs != stream->nmsgs)) { PSOUT ("* "); --- imap-2001a/src/ipopd/ipop3d.c.orig Tue Aug 20 10:16:10 2002 +++ imap-2001a/src/ipopd/ipop3d.c Tue Aug 20 10:16:21 2002 @@ -28,6 +28,11 @@ #include #include "c-client.h" +#ifdef DRAC_AUTH +#include +#include +#include +#endif /* DRAC_AUTH */ #define CRLF PSOUT ("\015\012") /* primary output terpri */ @@ -57,6 +62,13 @@ /* Global storage */ +#ifdef DRAC_AUTH +#define DRACTIMEOUT 10*60 /* check every 10 minutes */ +time_t lastdrac = 0; /* time of last drac check */ +extern char *getenv (); +#endif /* DRAC_AUTH */ + + char *version = "2001.78"; /* server version */ short state = AUTHORIZATION; /* server state */ short critical = NIL; /* non-zero if in critical code */ @@ -88,6 +100,9 @@ int mbxopen (char *mailbox); long blat (char *text,long lines,unsigned long size); void rset (); +#ifdef DRAC_AUTH +void drac_auth(); +#endif /* DRAC_AUTH */ /* Main program */ @@ -205,9 +220,13 @@ syslog (LOG_INFO,"AUTHENTICATE %s failure host=%.80s",s, tcp_clienthost ()); } - else if ((state = mbxopen ("INBOX")) == TRANSACTION) + else if ((state = mbxopen ("INBOX")) == TRANSACTION) { + #ifdef DRAC_AUTH + drac_auth(); + #endif /* DRAC_AUTH */ syslog (LOG_INFO,"Auth user=%.80s host=%.80s nmsgs=%ld/%ld", user,tcp_clienthost (),nmsgs,stream->nmsgs); + } else syslog (LOG_INFO,"Auth user=%.80s host=%.80s no mailbox", user,tcp_clienthost ()); } @@ -244,10 +263,14 @@ PSOUT ("-ERR Missing APOP argument\015\012"); else if (!(user = apop_login (challenge,s,t,argc,argv))) PSOUT ("-ERR Bad APOP\015\012"); - else if ((state = mbxopen ("INBOX")) == TRANSACTION) - syslog (LOG_INFO,"APOP user=%.80s host=%.80s nmsgs=%ld/%ld", - user,tcp_clienthost (),nmsgs,stream->nmsgs); - else syslog (LOG_INFO,"APOP user=%.80s host=%.80s no mailbox", + else if ((state = mbxopen ("INBOX")) == TRANSACTION) { + #ifdef DRAC_AUTH + drac_auth(); + #endif /* DRAC_AUTH */ + syslog (LOG_INFO,"APOP user=%.80s host=%.80s nmsgs=%ld/%ld", + user,tcp_clienthost (),nmsgs,stream->nmsgs); + } + else syslog (LOG_INFO,"APOP user=%.80s host=%.80s no mailbox", user,tcp_clienthost ()); } else PSOUT ("-ERR Not supported\015\012"); @@ -462,6 +485,49 @@ return 0; /* all done */ } +#ifdef DRAC_AUTH +/* DRAC Authorization + */ +void drac_auth () +{ + if (time (0) > lastdrac + DRACTIMEOUT) + { + FILE *dracconf; + char host[100]; + char *drachost; + char *err; + char *p; + + if ( (dracconf = fopen("/etc/mail/dracd.host", "r")) == NULL) + { + syslog (LOG_INFO, "dracd: error opening /etc/mail/dracd.host config file"); + exit(1); + } + + fgets(host, 100, dracconf); + p = strchr(host, '\n'); + if(p != NULL) + *p = '\0'; + fclose(dracconf); + + if( drachost = (host) ) + { + struct sockaddr_in sin; + int sinlen = sizeof (struct sockaddr_in); + char *client = getpeername (0,(struct sockaddr *) &sin,(void *) &sinlen) ? + "UNKNOWN" : inet_ntoa (sin.sin_addr); + + lastdrac = time(0); + + if (dracauth(drachost, inet_addr(client), &err) != 0) + syslog (LOG_INFO, err); + else + syslog (LOG_INFO, "dracd: authorized ip %s", client); + } + } +} +#endif /* DRAC_AUTH */ + /* Clock interrupt */ @@ -575,6 +641,9 @@ /* attempt the login */ if (server_login (user,pass,t,argc,argv)) { int ret = mbxopen ("INBOX"); + #ifdef DRAC_AUTH + drac_auth(); + #endif /* DRAC_AUTH */ if (ret == TRANSACTION) /* mailbox opened OK? */ syslog (LOG_INFO,"%sLogin user=%.80s host=%.80s nmsgs=%ld/%ld", t ? "Admin " : "",user,tcp_clienthost (),nmsgs,stream->nmsgs);