* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
*
- * $Id: conn.c,v 1.25 2002/01/02 02:44:36 alex Exp $
+ * $Id: conn.c,v 1.32 2002/01/05 23:25:25 alex Exp $
*
* connect.h: Verwaltung aller Netz-Verbindungen ("connections")
*
* $Log: conn.c,v $
- * Revision 1.25 2002/01/02 02:44:36 alex
- * - neue Defines fuer max. Anzahl Server und Operatoren.
+ * Revision 1.32 2002/01/05 23:25:25 alex
+ * - Vorbereitungen fuer Ident-Abfragen bei neuen Client-Strukturen.
+ *
+ * Revision 1.31 2002/01/05 19:15:03 alex
+ * - Fehlerpruefung bei select() in der "Hauptschleife" korrigiert.
+ *
+ * Revision 1.30 2002/01/05 15:56:23 alex
+ * - "arpa/inet.h" wird nur noch includiert, wenn vorhanden.
+ * - Ein Fehler bei select() fuerht nun zum Abbruch von ngIRCd.
+ * - NO_ADDRESS durch NO_DATA ersetzt: ist wohl portabler.
+ *
+ * Revision 1.29 2002/01/04 01:36:40 alex
+ * - Loglevel ein wenig angepasst.
+ *
+ * Revision 1.28 2002/01/04 01:20:23 alex
+ * - Client-Strukruren werden nur noch ueber Funktionen angesprochen.
+ *
+ * Revision 1.27 2002/01/03 02:25:36 alex
+ * - diverse Aenderungen und Umsetellungen fuer Server-Links.
+ *
+ * Revision 1.26 2002/01/02 02:50:47 alex
+ * - Asyncroner Resolver Hostname->IP.
+ * - Server-Links begonnen zu implementieren. Die Verbindung wird aufgebaut,
+ * jedoch noch keine SERVER-Befehle verschickt.
+ * - Diverse Bug-Fixes und kleinere Erweiterungen.
*
* Revision 1.24 2002/01/01 18:25:44 alex
* - #include's fuer stdlib.h ergaenzt.
#include <sys/types.h>
#include <time.h>
#include <netinet/in.h>
-#include <arpa/inet.h>
#include <netdb.h>
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#else
+#define PF_INET AF_INET
+#endif
+
#ifdef HAVE_STDINT_H
#include <stdint.h> /* u.a. fuer Mac OS X */
#endif
/* Auf Aktivitaet warten */
if( select( My_Max_Fd + 1, &read_sockets, &write_sockets, NULL, &tv ) == -1 )
{
- if( errno != EINTR ) Log( LOG_ALERT, "select(): %s!", strerror( errno ));
- return;
+ if( errno != EINTR )
+ {
+ Log( LOG_ALERT, "select(): %s!", strerror( errno ));
+ Log( LOG_ALERT, PACKAGE" exiting due to fatal errors!" );
+ exit( 1 );
+ }
+ continue;
}
/* Koennen Daten geschrieben werden? */
}
else
{
- Log( LOG_NOTICE, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port ));
+ Log( LOG_INFO, "Connection %d with %s:%d closed.", Idx, inet_ntoa( My_Connections[Idx].addr.sin_addr ), ntohs( My_Connections[Idx].addr.sin_port ));
}
c = Client_GetFromConn( Idx );
INT new_sock, new_sock_len;
RES_STAT *s;
CONN_ID idx;
-
+
assert( Sock >= 0 );
new_sock_len = sizeof( new_addr );
}
/* Client-Struktur initialisieren */
- if( ! Client_NewLocal( idx, inet_ntoa( new_addr.sin_addr )))
+ if( ! Client_NewLocal( idx, inet_ntoa( new_addr.sin_addr ), CLIENT_UNKNOWN, FALSE ))
{
Log( LOG_ALERT, "Can't accept connection: can't create client structure!" );
close( new_sock );
FD_SET( new_sock, &My_Sockets );
if( new_sock > My_Max_Fd ) My_Max_Fd = new_sock;
- Log( LOG_NOTICE, "Accepted connection %d from %s:%d on socket %d.", idx, inet_ntoa( new_addr.sin_addr ), ntohs( new_addr.sin_port), Sock );
+ Log( LOG_INFO, "Accepted connection %d from %s:%d on socket %d.", idx, inet_ntoa( new_addr.sin_addr ), ntohs( new_addr.sin_port), Sock );
/* Hostnamen ermitteln */
s = ResolveAddr( &new_addr );
assert( Idx >= 0 );
assert( My_Connections[Idx].sock > NONE );
- len = recv( My_Connections[Idx].sock, My_Connections[Idx].rbuf + My_Connections[Idx].rdatalen, READBUFFER_LEN - My_Connections[Idx].rdatalen - 1, 0 );
- My_Connections[Idx].rbuf[READBUFFER_LEN - 1] = '\0';
+ if( READBUFFER_LEN - My_Connections[Idx].rdatalen - 2 < 0 )
+ {
+ /* Der Lesepuffer ist voll */
+ Log( LOG_ALERT, "Read buffer overflow (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
+ Conn_Close( Idx, "Read buffer overflow!" );
+ return;
+ }
+
+ len = recv( My_Connections[Idx].sock, My_Connections[Idx].rbuf + My_Connections[Idx].rdatalen, READBUFFER_LEN - My_Connections[Idx].rdatalen - 2, 0 );
if( len == 0 )
{
/* Lesebuffer updaten */
My_Connections[Idx].rdatalen += len;
- assert( My_Connections[Idx].rdatalen <= READBUFFER_LEN );
+ assert( My_Connections[Idx].rdatalen < READBUFFER_LEN );
My_Connections[Idx].rbuf[My_Connections[Idx].rdatalen] = '\0';
- if( My_Connections[Idx].rdatalen > COMMAND_LEN )
- {
- /* Eine Anfrage darf(!) nicht laenger als 512 Zeichen
- * (incl. CR+LF!) werden; vgl. RFC 2812. Wenn soetwas
- * empfangen wird, wird der Client disconnectiert. */
- Log( LOG_ALERT, "Request too long (connection %d)!", Idx );
- Conn_Close( Idx, "Request too long!" );
- return;
- }
-
/* Timestamp aktualisieren */
My_Connections[Idx].lastdata = time( NULL );
ptr = strstr( My_Connections[Idx].rbuf, "\r\n" );
if( ptr ) delta = 2;
+#ifndef STRICT_RFC
else
{
/* Nicht RFC-konforme Anfrage mit nur CR oder LF? Leider
else if( ptr1 ) ptr = ptr1;
else if( ptr2 ) ptr = ptr2;
}
-
+#endif
+
if( ptr )
{
/* Ende der Anfrage wurde gefunden */
*ptr = '\0';
len = ( ptr - My_Connections[Idx].rbuf ) + delta;
+ if( len > COMMAND_LEN )
+ {
+ /* Eine Anfrage darf(!) nicht laenger als 512 Zeichen
+ * (incl. CR+LF!) werden; vgl. RFC 2812. Wenn soetwas
+ * empfangen wird, wird der Client disconnectiert. */
+ Log( LOG_ALERT, "Request too long (connection %d): %d bytes!", Idx, My_Connections[Idx].rdatalen );
+ Conn_Close( Idx, "Request too long!" );
+ return;
+ }
+
if( len > delta )
{
/* Es wurde ein Request gelesen */
if( My_Connections[i].sock == NONE ) continue;
c = Client_GetFromConn( i );
- if( c && (( c->type == CLIENT_USER ) || ( c->type == CLIENT_SERVER ) || ( c->type == CLIENT_SERVICE )))
+ if( c && (( Client_Type( c ) == CLIENT_USER ) || ( Client_Type( c ) == CLIENT_SERVER ) || ( Client_Type( c ) == CLIENT_SERVICE )))
{
/* verbundener User, Server oder Service */
if( My_Connections[i].lastping > My_Connections[i].lastdata )
/* es muss ein PING gesendet werden */
Log( LOG_DEBUG, "Connection %d: sending PING ...", i );
My_Connections[i].lastping = time( NULL );
- Conn_WriteStr( i, "PING :%s", This_Server->nick );
+ Conn_WriteStr( i, "PING :%s", Client_ID( Client_ThisServer( )));
}
}
else
struct sockaddr_in new_addr;
struct in_addr inaddr;
INT new_sock;
+ CLIENT *c;
assert( Server >= 0 );
assert( Idx >= 0 );
}
/* Client-Struktur initialisieren */
- if( ! Client_NewLocal( Idx, inet_ntoa( new_addr.sin_addr )))
+ c = Client_NewLocal( Idx, inet_ntoa( new_addr.sin_addr ), CLIENT_UNKNOWNSERVER, FALSE );
+ if( ! c )
{
close( new_sock );
Init_Conn_Struct( Idx );
Log( LOG_ALERT, "Can't establish connection: can't create client structure!" );
return;
}
+ Client_SetIntroducer( c, c );
/* Verbindung registrieren */
My_Connections[Idx].sock = new_sock;
/* Neuen Socket registrieren */
FD_SET( new_sock, &My_Sockets );
if( new_sock > My_Max_Fd ) My_Max_Fd = new_sock;
+
+ /* PASS und SERVER verschicken */
+ Conn_WriteStr( Idx, "PASS %s "PROTOVER""PROTOSUFFIX" IRC|"PACKAGE"-"VERSION" P", Conf_Server[Server].pwd );
+ Conn_WriteStr( Idx, "SERVER %s :%s", Conf_ServerName, Conf_ServerInfo );
} /* New_Server */
if( My_Connections[i].sock > NONE )
{
/* Eingehende Verbindung: Hostnamen setzen */
- strcpy( My_Connections[i].host, result );
c = Client_GetFromConn( i );
- if( c ) Client_SetHostname( c, result );
+ assert( c != NULL );
+ strcpy( My_Connections[i].host, result );
+ Client_SetHostname( c, result );
}
else
{
{
case HOST_NOT_FOUND:
return "host not found";
- case NO_ADDRESS:
+ case NO_DATA:
return "name valid but no IP address defined";
case NO_RECOVERY:
return "name server error";