mirror of
https://github.com/osmarks/ngircd.git
synced 2025-05-05 17:04:05 +00:00
Fixed resolver when using IDENT lookups, cleaned up code.
This commit is contained in:
parent
26390c60fb
commit
3012c232eb
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
|
|
||||||
static char UNUSED id[] = "$Id: conn.c,v 1.134 2004/04/25 14:06:12 alex Exp $";
|
static char UNUSED id[] = "$Id: conn.c,v 1.135 2004/05/11 00:01:11 alex Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -1600,35 +1600,28 @@ Init_Socket( INT Sock )
|
|||||||
LOCAL VOID
|
LOCAL VOID
|
||||||
Read_Resolver_Result( INT r_fd )
|
Read_Resolver_Result( INT r_fd )
|
||||||
{
|
{
|
||||||
/* Ergebnis von Resolver Sub-Prozess aus Pipe lesen
|
/* Read result of resolver sub-process from pipe and update the
|
||||||
* und entsprechende Connection aktualisieren */
|
* apropriate connection/client structure(s): hostname and/or
|
||||||
|
* IDENT user name.*/
|
||||||
|
|
||||||
CHAR result[HOST_LEN];
|
|
||||||
CLIENT *c;
|
CLIENT *c;
|
||||||
INT len, i, n;
|
INT len, i, n;
|
||||||
|
RES_STAT *s;
|
||||||
FD_CLR( r_fd, &Resolver_FDs );
|
CHAR *ptr;
|
||||||
|
|
||||||
/* Read result from pipe */
|
|
||||||
len = read( r_fd, result, HOST_LEN - 1 );
|
|
||||||
if( len < 0 )
|
|
||||||
{
|
|
||||||
/* Error! */
|
|
||||||
close( r_fd );
|
|
||||||
Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
result[len] = '\0';
|
|
||||||
|
|
||||||
/* Search associated connection ... */
|
/* Search associated connection ... */
|
||||||
for( i = 0; i < Pool_Size; i++ )
|
for( i = 0; i < Pool_Size; i++ )
|
||||||
{
|
{
|
||||||
if(( My_Connections[i].sock != NONE ) && ( My_Connections[i].res_stat ) && ( My_Connections[i].res_stat->pipe[0] == r_fd )) break;
|
if(( My_Connections[i].sock != NONE )
|
||||||
|
&& ( My_Connections[i].res_stat != NULL )
|
||||||
|
&& ( My_Connections[i].res_stat->pipe[0] == r_fd ))
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if( i >= Pool_Size )
|
if( i >= Pool_Size )
|
||||||
{
|
{
|
||||||
/* Ops, none found? Probably the connection has already
|
/* Ops, none found? Probably the connection has already
|
||||||
* been closed. */
|
* been closed!? We'll ignore that ... */
|
||||||
|
FD_CLR( r_fd, &Resolver_FDs );
|
||||||
close( r_fd );
|
close( r_fd );
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Log( LOG_DEBUG, "Resolver: Got result for unknown connection!?" );
|
Log( LOG_DEBUG, "Resolver: Got result for unknown connection!?" );
|
||||||
@ -1636,61 +1629,100 @@ Read_Resolver_Result( INT r_fd )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get resolver structure */
|
||||||
|
s = My_Connections[i].res_stat;
|
||||||
|
assert( s != NULL );
|
||||||
|
|
||||||
|
/* Read result from pipe */
|
||||||
|
len = read( r_fd, s->buffer + s->bufpos, sizeof( s->buffer ) - HOST_LEN - 1 );
|
||||||
|
if( len < 0 )
|
||||||
|
{
|
||||||
|
/* Error! */
|
||||||
|
close( r_fd );
|
||||||
|
Log( LOG_CRIT, "Resolver: Can't read result: %s!", strerror( errno ));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s->bufpos += len;
|
||||||
|
s->buffer[s->bufpos] = '\0';
|
||||||
|
|
||||||
|
/* If the result string is incomplete, return to main loop and
|
||||||
|
* wait until we can read in more bytes. */
|
||||||
|
try_resolve:
|
||||||
|
ptr = strchr( s->buffer, '\n' );
|
||||||
|
if( ! ptr ) return;
|
||||||
|
*ptr = '\0';
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Log( LOG_DEBUG, "Resolver: %s is \"%s\".", My_Connections[i].host, result );
|
Log( LOG_DEBUG, "Got result from resolver: \"%s\" (%d bytes), stage %d.", s->buffer, len, s->stage );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Clean up ... */
|
/* Okay, we got a complete result: this is a host name for outgoing
|
||||||
close( My_Connections[i].res_stat->pipe[0] );
|
* connections and a host name or IDENT user name (if enabled) for
|
||||||
close( My_Connections[i].res_stat->pipe[1] );
|
* incoming conneciions.*/
|
||||||
free( My_Connections[i].res_stat );
|
|
||||||
My_Connections[i].res_stat = NULL;
|
|
||||||
|
|
||||||
if( My_Connections[i].sock > NONE )
|
if( My_Connections[i].sock > NONE )
|
||||||
{
|
{
|
||||||
/* Incoming connection */
|
/* Incoming connection */
|
||||||
#ifdef IDENTAUTH
|
|
||||||
CHAR *ident;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Search client ... */
|
/* Search client ... */
|
||||||
c = Client_GetFromConn( i );
|
c = Client_GetFromConn( i );
|
||||||
assert( c != NULL );
|
assert( c != NULL );
|
||||||
|
|
||||||
/* Only update client information of unregistered clients */
|
/* Only update client information of unregistered clients */
|
||||||
if( Client_Type( c ) != CLIENT_UNKNOWN )
|
if( Client_Type( c ) == CLIENT_UNKNOWN )
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if( s->stage == 0 )
|
||||||
Log( LOG_DEBUG, "Resolver: discarding result for already registered connection %d.", i );
|
{
|
||||||
#endif
|
/* host name */
|
||||||
return;
|
strlcpy( My_Connections[i].host, s->buffer, sizeof( My_Connections[i].host ));
|
||||||
}
|
Client_SetHostname( c, s->buffer );
|
||||||
|
|
||||||
/* Set hostname */
|
|
||||||
strlcpy( My_Connections[i].host, result, sizeof( My_Connections[i].host ));
|
|
||||||
Client_SetHostname( c, result );
|
|
||||||
|
|
||||||
#ifdef IDENTAUTH
|
#ifdef IDENTAUTH
|
||||||
ident = strchr( result, 0 );
|
/* clean up buffer for IDENT result */
|
||||||
ident++;
|
len = strlen( s->buffer ) + 1;
|
||||||
|
memmove( s->buffer, s->buffer + len, sizeof( s->buffer ) - len );
|
||||||
|
s->bufpos -= len;
|
||||||
|
|
||||||
/* Do we have a result of the IDENT lookup? If so, set it as the user name */
|
/* Don't close pipe and clean up, but
|
||||||
if( *ident )
|
* instead wait for IDENT result */
|
||||||
{
|
s->stage = 1;
|
||||||
Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, ident );
|
goto try_resolve;
|
||||||
Client_SetUser( c, ident, TRUE );
|
}
|
||||||
|
else if( s->stage == 1 )
|
||||||
|
{
|
||||||
|
/* IDENT user name */
|
||||||
|
if( s->buffer[0] )
|
||||||
|
{
|
||||||
|
Log( LOG_INFO, "IDENT lookup for connection %ld: \"%s\".", i, s->buffer );
|
||||||
|
Client_SetUser( c, s->buffer, TRUE );
|
||||||
|
}
|
||||||
|
else Log( LOG_INFO, "IDENT lookup for connection %ld: no result.", i );
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else Log( LOG_ERR, "Resolver: got result for unknown stage %d!?", s->stage );
|
||||||
}
|
}
|
||||||
else Log( LOG_INFO, "IDENT lookup for connection %ld: no result.", i );
|
#ifdef DEBUG
|
||||||
|
else Log( LOG_DEBUG, "Resolver: discarding result for already registered connection %d.", i );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Outgoing connection (server link!): set IP address */
|
/* Outgoing connection (server link): set the IP address
|
||||||
|
* so that we can connect to it in the main loop. */
|
||||||
|
|
||||||
|
/* Search server ... */
|
||||||
n = Conf_GetServer( i );
|
n = Conf_GetServer( i );
|
||||||
assert( n > NONE );
|
assert( n > NONE );
|
||||||
strlcpy( Conf_Server[n].ip, result, sizeof( Conf_Server[n].ip ));
|
|
||||||
|
strlcpy( Conf_Server[n].ip, s->buffer, sizeof( Conf_Server[n].ip ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clean up ... */
|
||||||
|
FD_CLR( r_fd, &Resolver_FDs );
|
||||||
|
close( My_Connections[i].res_stat->pipe[0] );
|
||||||
|
close( My_Connections[i].res_stat->pipe[1] );
|
||||||
|
free( My_Connections[i].res_stat );
|
||||||
|
My_Connections[i].res_stat = NULL;
|
||||||
|
|
||||||
/* Reset penalty time */
|
/* Reset penalty time */
|
||||||
Conn_ResetPenalty( i );
|
Conn_ResetPenalty( i );
|
||||||
} /* Read_Resolver_Result */
|
} /* Read_Resolver_Result */
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
|
|
||||||
static char UNUSED id[] = "$Id: irc-server.c,v 1.36 2004/04/25 15:43:18 alex Exp $";
|
static char UNUSED id[] = "$Id: irc-server.c,v 1.37 2004/05/11 00:01:11 alex Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -23,6 +23,7 @@ static char UNUSED id[] = "$Id: irc-server.c,v 1.36 2004/04/25 15:43:18 alex Exp
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
#include "conn-zip.h"
|
#include "conn-zip.h"
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
|
|
||||||
static char UNUSED id[] = "$Id: ngircd.c,v 1.84 2004/05/07 11:19:21 alex Exp $";
|
static char UNUSED id[] = "$Id: ngircd.c,v 1.85 2004/05/11 00:01:11 alex Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -31,13 +31,13 @@ static char UNUSED id[] = "$Id: ngircd.c,v 1.84 2004/05/07 11:19:21 alex Exp $";
|
|||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
|
||||||
|
#include "defines.h"
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
#include "conn.h"
|
#include "conn.h"
|
||||||
#include "client.h"
|
#include "client.h"
|
||||||
#include "channel.h"
|
#include "channel.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "cvs-version.h"
|
#include "cvs-version.h"
|
||||||
#include "defines.h"
|
|
||||||
#include "lists.h"
|
#include "lists.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#include "portab.h"
|
#include "portab.h"
|
||||||
|
|
||||||
static char UNUSED id[] = "$Id: resolve.c,v 1.8 2004/03/11 22:16:31 alex Exp $";
|
static char UNUSED id[] = "$Id: resolve.c,v 1.9 2004/05/11 00:01:11 alex Exp $";
|
||||||
|
|
||||||
#include "imp.h"
|
#include "imp.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
@ -102,6 +102,8 @@ Resolve_Addr( struct sockaddr_in *Addr )
|
|||||||
FD_SET( s->pipe[0], &Resolver_FDs );
|
FD_SET( s->pipe[0], &Resolver_FDs );
|
||||||
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
|
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
|
||||||
s->pid = pid;
|
s->pid = pid;
|
||||||
|
s->stage = 0;
|
||||||
|
s->bufpos = 0;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
else if( pid == 0 )
|
else if( pid == 0 )
|
||||||
@ -160,6 +162,8 @@ Resolve_Name( CHAR *Host )
|
|||||||
FD_SET( s->pipe[0], &Resolver_FDs );
|
FD_SET( s->pipe[0], &Resolver_FDs );
|
||||||
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
|
if( s->pipe[0] > Conn_MaxFD ) Conn_MaxFD = s->pipe[0];
|
||||||
s->pid = pid;
|
s->pid = pid;
|
||||||
|
s->stage = 0;
|
||||||
|
s->bufpos = 0;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
else if( pid == 0 )
|
else if( pid == 0 )
|
||||||
@ -193,13 +197,13 @@ Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd )
|
|||||||
|
|
||||||
CHAR hostname[HOST_LEN];
|
CHAR hostname[HOST_LEN];
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
|
INT len;
|
||||||
#ifdef IDENTAUTH
|
#ifdef IDENTAUTH
|
||||||
CHAR *res;
|
CHAR *res;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Log_Resolver( LOG_DEBUG, "Now resolving %s ...", inet_ntoa( Addr->sin_addr ));
|
|
||||||
|
|
||||||
/* Resolve IP address */
|
/* Resolve IP address */
|
||||||
|
Log_Resolver( LOG_DEBUG, "Now resolving %s ...", inet_ntoa( Addr->sin_addr ));
|
||||||
h = gethostbyaddr( (CHAR *)&Addr->sin_addr, sizeof( Addr->sin_addr ), AF_INET );
|
h = gethostbyaddr( (CHAR *)&Addr->sin_addr, sizeof( Addr->sin_addr ), AF_INET );
|
||||||
if( h ) strlcpy( hostname, h->h_name, sizeof( hostname ));
|
if( h ) strlcpy( hostname, h->h_name, sizeof( hostname ));
|
||||||
else
|
else
|
||||||
@ -211,33 +215,35 @@ Do_ResolveAddr( struct sockaddr_in *Addr, INT w_fd )
|
|||||||
#endif
|
#endif
|
||||||
strlcpy( hostname, inet_ntoa( Addr->sin_addr ), sizeof( hostname ));
|
strlcpy( hostname, inet_ntoa( Addr->sin_addr ), sizeof( hostname ));
|
||||||
}
|
}
|
||||||
|
Log_Resolver( LOG_DEBUG, "Ok, translated %s to \"%s\".", inet_ntoa( Addr->sin_addr ), hostname );
|
||||||
|
|
||||||
#ifdef IDENTAUTH
|
/* Write resolver result into pipe to parent */
|
||||||
/* Do "IDENT" (aka "AUTH") lookup and write result to parent */
|
len = strlen( hostname );
|
||||||
Log_Resolver( LOG_DEBUG, "Doing IDENT lookup on socket %d ...", Sock );
|
hostname[len] = '\n'; len++;
|
||||||
res = ident_id( Sock, 10 );
|
if( (size_t)write( w_fd, hostname, len ) != (size_t)len )
|
||||||
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 ));
|
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
|
||||||
close( w_fd );
|
close( w_fd );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef IDENTAUTH
|
#ifdef IDENTAUTH
|
||||||
if( (size_t)write( w_fd, res ? res : "", strlen( res ? res : "" ) + 1 ) != (size_t)( strlen( res ? res : "" ) + 1 ))
|
/* 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, "Ok, IDENT lookup on socket %d done: \"%s\"", Sock, res ? res : "" );
|
||||||
|
|
||||||
|
/* Write IDENT result into pipe to parent */
|
||||||
|
len = strlen( res ? res : "" );
|
||||||
|
if( res != NULL ) res[len] = '\n';
|
||||||
|
len++;
|
||||||
|
if( (size_t)write( w_fd, res ? res : "\n", len ) != (size_t)len )
|
||||||
{
|
{
|
||||||
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent (IDENT): %s!", strerror( errno ));
|
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent (IDENT): %s!", strerror( errno ));
|
||||||
close( w_fd );
|
close( w_fd );
|
||||||
free( res );
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
free( res );
|
free( res );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Log_Resolver( LOG_DEBUG, "Ok, translated %s to \"%s\".", inet_ntoa( Addr->sin_addr ), hostname );
|
|
||||||
} /* Do_ResolveAddr */
|
} /* Do_ResolveAddr */
|
||||||
|
|
||||||
|
|
||||||
@ -250,6 +256,7 @@ Do_ResolveName( CHAR *Host, INT w_fd )
|
|||||||
CHAR ip[16];
|
CHAR ip[16];
|
||||||
struct hostent *h;
|
struct hostent *h;
|
||||||
struct in_addr *addr;
|
struct in_addr *addr;
|
||||||
|
INT len;
|
||||||
|
|
||||||
Log_Resolver( LOG_DEBUG, "Now resolving \"%s\" ...", Host );
|
Log_Resolver( LOG_DEBUG, "Now resolving \"%s\" ...", Host );
|
||||||
|
|
||||||
@ -269,16 +276,16 @@ Do_ResolveName( CHAR *Host, INT w_fd )
|
|||||||
#endif
|
#endif
|
||||||
strcpy( ip, "" );
|
strcpy( ip, "" );
|
||||||
}
|
}
|
||||||
|
if( ip[0] ) Log_Resolver( LOG_DEBUG, "Ok, translated \"%s\" to %s.", Host, ip );
|
||||||
|
|
||||||
/* Write result into pipe to parent */
|
/* Write result into pipe to parent */
|
||||||
if( (size_t)write( w_fd, ip, strlen( ip ) + 1 ) != (size_t)( strlen( ip ) + 1 ))
|
len = strlen( ip );
|
||||||
|
ip[len] = '\n'; len++;
|
||||||
|
if( (size_t)write( w_fd, ip, len ) != (size_t)len )
|
||||||
{
|
{
|
||||||
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
|
Log_Resolver( LOG_CRIT, "Resolver: Can't write to parent: %s!", strerror( errno ));
|
||||||
close( w_fd );
|
close( w_fd );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ip[0] ) Log_Resolver( LOG_DEBUG, "Ok, translated \"%s\" to %s.", Host, ip );
|
|
||||||
} /* Do_ResolveName */
|
} /* Do_ResolveName */
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
* Please read the file COPYING, README and AUTHORS for more information.
|
* Please read the file COPYING, README and AUTHORS for more information.
|
||||||
*
|
*
|
||||||
* $Id: resolve.h,v 1.6 2003/12/27 13:01:12 alex Exp $
|
* $Id: resolve.h,v 1.7 2004/05/11 00:01:11 alex Exp $
|
||||||
*
|
*
|
||||||
* Asynchronous resolver (header)
|
* Asynchronous resolver (header)
|
||||||
*/
|
*/
|
||||||
@ -29,6 +29,9 @@ typedef struct _Res_Stat
|
|||||||
{
|
{
|
||||||
INT pid; /* PID des Child-Prozess */
|
INT pid; /* PID des Child-Prozess */
|
||||||
INT pipe[2]; /* Pipe fuer IPC */
|
INT pipe[2]; /* Pipe fuer IPC */
|
||||||
|
INT stage; /* Hostname/IP(0) or IDENT(1)? */
|
||||||
|
INT bufpos; /* Position in buffer */
|
||||||
|
CHAR buffer[HOST_LEN]; /* Buffer */
|
||||||
} RES_STAT;
|
} RES_STAT;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user