/*
* ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2003 by Alexander Barton (alex@barton.de)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "portab.h"
-static char UNUSED id[] = "$Id: resolve.c,v 1.6 2003/04/21 10:52:51 alex Exp $";
+static char UNUSED id[] = "$Id: resolve.c,v 1.8 2004/03/11 22:16:31 alex Exp $";
#include "imp.h"
#include <assert.h>
#include <arpa/inet.h>
#include <netdb.h>
+#ifdef IDENTAUTH
+#ifdef HAVE_IDENT_H
+#include <ident.h>
+#endif
+#endif
+
#include "conn.h"
#include "defines.h"
#include "log.h"
#include "resolve.h"
+#ifdef IDENTAUTH
+LOCAL VOID Do_ResolveAddr PARAMS(( struct sockaddr_in *Addr, INT Sock, INT w_fd ));
+#else
LOCAL VOID Do_ResolveAddr PARAMS(( struct sockaddr_in *Addr, INT w_fd ));
+#endif
+
LOCAL VOID Do_ResolveName PARAMS(( CHAR *Host, INT w_fd ));
#ifdef h_errno
GLOBAL VOID
Resolve_Init( VOID )
{
- /* Modul initialisieren */
+ /* Initialize module */
FD_ZERO( &Resolver_FDs );
} /* Resolve_Init */
+#ifdef IDENTAUTH
+GLOBAL RES_STAT *
+Resolve_Addr( struct sockaddr_in *Addr, int Sock )
+#else
GLOBAL RES_STAT *
Resolve_Addr( struct sockaddr_in *Addr )
+#endif
{
- /* IP (asyncron!) aufloesen. Bei Fehler, z.B. wenn der
- * Child-Prozess nicht erzeugt werden kann, wird NULL geliefert.
- * Der Host kann dann nicht aufgeloest werden. */
+ /* Resolve IP (asynchronous!). On errors, e.g. if the child process
+ * can't be forked, this functions returns NULL. */
RES_STAT *s;
INT pid;
- /* Speicher anfordern */
- s = malloc( sizeof( RES_STAT ));
+ /* Allocate memory */
+ s = (RES_STAT *)malloc( sizeof( RES_STAT ));
if( ! s )
{
Log( LOG_EMERG, "Resolver: Can't allocate memory! [Resolve_Addr]" );
return NULL;
}
- /* Pipe fuer Antwort initialisieren */
+ /* Initialize pipe for result */
if( pipe( s->pipe ) != 0 )
{
free( s );
return NULL;
}
- /* Sub-Prozess erzeugen */
+ /* For sub-process */
pid = fork( );
if( pid > 0 )
{
- /* Haupt-Prozess */
+ /* Main process */
Log( LOG_DEBUG, "Resolver for %s created (PID %d).", inet_ntoa( Addr->sin_addr ), pid );
FD_SET( s->pipe[0], &Resolver_FDs );
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
}
else if( pid == 0 )
{
- /* Sub-Prozess */
+ /* Sub process */
Log_Init_Resolver( );
+#ifdef IDENTAUTH
+ Do_ResolveAddr( Addr, Sock, s->pipe[1] );
+#else
Do_ResolveAddr( Addr, s->pipe[1] );
+#endif
Log_Exit_Resolver( );
exit( 0 );
}
else
{
- /* Fehler */
+ /* Error! */
free( s );
Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
return NULL;
GLOBAL RES_STAT *
Resolve_Name( CHAR *Host )
{
- /* Hostnamen (asyncron!) aufloesen. Bei Fehler, z.B. wenn der
- * Child-Prozess nicht erzeugt werden kann, wird NULL geliefert.
- * Der Host kann dann nicht aufgeloest werden. */
+ /* Resolve hostname (asynchronous!). On errors, e.g. if the child
+ * process can't be forked, this functions returns NULL. */
RES_STAT *s;
INT pid;
- /* Speicher anfordern */
- s = malloc( sizeof( RES_STAT ));
+ /* Allocate memory */
+ s = (RES_STAT *)malloc( sizeof( RES_STAT ));
if( ! s )
{
Log( LOG_EMERG, "Resolver: Can't allocate memory! [Resolve_Name]" );
return NULL;
}
- /* Pipe fuer Antwort initialisieren */
+ /* Initialize the pipe for the result */
if( pipe( s->pipe ) != 0 )
{
free( s );
return NULL;
}
- /* Sub-Prozess erzeugen */
+ /* Fork sub-process */
pid = fork( );
if( pid > 0 )
{
- /* Haupt-Prozess */
+ /* Main process */
Log( LOG_DEBUG, "Resolver for \"%s\" created (PID %d).", Host, pid );
FD_SET( s->pipe[0], &Resolver_FDs );
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
}
else if( pid == 0 )
{
- /* Sub-Prozess */
+ /* Sub process */
Log_Init_Resolver( );
Do_ResolveName( Host, s->pipe[1] );
Log_Exit_Resolver( );
}
else
{
- /* Fehler */
+ /* Error! */
free( s );
Log( LOG_CRIT, "Resolver: Can't fork: %s!", strerror( errno ));
return NULL;
} /* Resolve_Name */
+#ifdef IDENTAUTH
+LOCAL VOID
+Do_ResolveAddr( struct sockaddr_in *Addr, int Sock, INT w_fd )
+#else
LOCAL VOID
Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd )
+#endif
{
- /* Resolver Sub-Prozess: IP aufloesen und Ergebnis in Pipe schreiben. */
+ /* Resolver sub-process: resolve IP address and write result into
+ * pipe to parent. */
CHAR hostname[HOST_LEN];
struct hostent *h;
+#ifdef IDENTAUTH
+ CHAR *res;
+#endif
Log_Resolver( LOG_DEBUG, "Now resolving %s ...", inet_ntoa( Addr->sin_addr ));
- /* Namen aufloesen */
+ /* Resolve IP address */
h = gethostbyaddr( (CHAR *)&Addr->sin_addr, sizeof( Addr->sin_addr ), AF_INET );
if( h ) strlcpy( hostname, h->h_name, sizeof( hostname ));
else
strlcpy( hostname, inet_ntoa( Addr->sin_addr ), sizeof( hostname ));
}
- /* Antwort an Parent schreiben */
+#ifdef IDENTAUTH
+ /* Do "IDENT" (aka "AUTH") lookup and write result to parent */
+ Log_Resolver( LOG_DEBUG, "Doing IDENT lookup on socket %d ...", Sock );
+ res = ident_id( Sock, 10 );
+ Log_Resolver( LOG_DEBUG, "IDENT lookup on socket %d done.", Sock );
+#endif
+
+ /* Write result into pipe to parent */
if( (size_t)write( w_fd, hostname, strlen( hostname ) + 1 ) != (size_t)( strlen( hostname ) + 1 ))
{
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
close( w_fd );
return;
}
+#ifdef IDENTAUTH
+ if( (size_t)write( w_fd, res ? res : "", strlen( res ? res : "" ) + 1 ) != (size_t)( strlen( res ? res : "" ) + 1 ))
+ {
+ Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent (IDENT): %s!", strerror( errno ));
+ close( w_fd );
+ free( res );
+ return;
+ }
+ free( res );
+#endif
Log_Resolver( LOG_DEBUG, "Ok, translated %s to \"%s\".", inet_ntoa( Addr->sin_addr ), hostname );
} /* Do_ResolveAddr */
LOCAL VOID
Do_ResolveName( CHAR *Host, INT w_fd )
{
- /* Resolver Sub-Prozess: Name aufloesen und Ergebnis in Pipe schreiben. */
+ /* Resolver sub-process: resolve name and write result into pipe
+ * to parent. */
CHAR ip[16];
struct hostent *h;
Log_Resolver( LOG_DEBUG, "Now resolving \"%s\" ...", Host );
- /* Namen aufloesen */
+ /* Resolve hostname */
h = gethostbyname( Host );
if( h )
{
strcpy( ip, "" );
}
- /* Antwort an Parent schreiben */
+ /* Write result into pipe to parent */
if( (size_t)write( w_fd, ip, strlen( ip ) + 1 ) != (size_t)( strlen( ip ) + 1 ))
{
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
LOCAL CHAR *
Get_Error( INT H_Error )
{
- /* Fehlerbeschreibung fuer H_Error liefern */
+ /* Get error message for H_Error */
switch( H_Error )
{