aboutsummaryrefslogtreecommitdiffstats
path: root/bitlbee.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2005-12-26 15:02:47 +0100
committerWilmer van der Gaast <wilmer@gaast.net>2005-12-26 15:02:47 +0100
commitd25f6fcbe8e291dd858bf734fa85cde176dc8415 (patch)
tree58fffb8b1dd8cc0a3cf3583c0daf7c10271af871 /bitlbee.c
parentffea9b950b183dd54952b56703506508b0984d4b (diff)
Added OperPassword and RunMode = ForkDaemon settings. Oper stuff is
*INSECURE* because users can just do /mode +o to become operator.
Diffstat (limited to 'bitlbee.c')
-rw-r--r--bitlbee.c40
1 files changed, 30 insertions, 10 deletions
diff --git a/bitlbee.c b/bitlbee.c
index e920f2cb..45cb388d 100644
--- a/bitlbee.c
+++ b/bitlbee.c
@@ -36,12 +36,30 @@ gboolean bitlbee_io_new_client( GIOChannel *source, GIOCondition condition, gpoi
{
size_t size = sizeof( struct sockaddr_in );
struct sockaddr_in conn_info;
- int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info,
- &size );
+ int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size );
+ pid_t client_pid = 0;
+
+ if( global.conf->runmode == RUNMODE_FORKDAEMON )
+ client_pid = fork();
+
+ if( client_pid == 0 )
+ {
+ log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
+ irc_new( new_socket );
+
+ if( global.conf->runmode == RUNMODE_FORKDAEMON )
+ {
+ /* Close the listening socket, we're a client. */
+ close( global.listen_socket );
+ g_source_remove( global.listen_watch_source_id );
+ }
+ }
+ else
+ {
+ /* We don't need this one, only the client does. */
+ close( new_socket );
+ }
- log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
- irc_new( new_socket );
-
return TRUE;
}
@@ -65,24 +83,24 @@ int bitlbee_daemon_init()
listen_addr.sin_family = AF_INET;
listen_addr.sin_port = htons( global.conf->port );
listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface );
-
+
i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) );
if( i == -1 )
{
log_error( "bind" );
return( -1 );
}
-
+
i = listen( global.listen_socket, 10 );
if( i == -1 )
{
log_error( "listen" );
return( -1 );
}
-
+
ch = g_io_channel_unix_new( global.listen_socket );
- g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
-
+ global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
+
#ifndef _WIN32
if( !global.conf->nofork )
{
@@ -164,6 +182,8 @@ gboolean bitlbee_io_current_client_read( GIOChannel *source, GIOCondition condit
return FALSE;
}
+ return TRUE;
+
/* Very naughty, go read the RFCs! >:) */
if( irc->readbuffer && ( strlen( irc->readbuffer ) > 1024 ) )
{