Changeset d25f6fc


Ignore:
Timestamp:
2005-12-26T14:02:47Z (18 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
238f828
Parents:
ffea9b9
Message:

Added OperPassword and RunMode = ForkDaemon settings. Oper stuff is
*INSECURE* because users can just do /mode +o to become operator.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.c

    rffea9b9 rd25f6fc  
    3737        size_t size = sizeof( struct sockaddr_in );
    3838        struct sockaddr_in conn_info;
    39         int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info,
    40                                      &size );
    41        
    42         log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
    43         irc_new( new_socket );
    44 
     39        int new_socket = accept( global.listen_socket, (struct sockaddr *) &conn_info, &size );
     40        pid_t client_pid = 0;
     41       
     42        if( global.conf->runmode == RUNMODE_FORKDAEMON )
     43                client_pid = fork();
     44       
     45        if( client_pid == 0 )
     46        {
     47                log_message( LOGLVL_INFO, "Creating new connection with fd %d.", new_socket );
     48                irc_new( new_socket );
     49               
     50                if( global.conf->runmode == RUNMODE_FORKDAEMON )
     51                {
     52                        /* Close the listening socket, we're a client. */
     53                        close( global.listen_socket );
     54                        g_source_remove( global.listen_watch_source_id );
     55                }
     56        }
     57        else
     58        {
     59                /* We don't need this one, only the client does. */
     60                close( new_socket );
     61        }
     62       
    4563        return TRUE;
    4664}
     
    6684        listen_addr.sin_port = htons( global.conf->port );
    6785        listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface );
    68 
     86       
    6987        i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) );
    7088        if( i == -1 )
     
    7391                return( -1 );
    7492        }
    75 
     93       
    7694        i = listen( global.listen_socket, 10 );
    7795        if( i == -1 )
     
    8098                return( -1 );
    8199        }
    82 
     100       
    83101        ch = g_io_channel_unix_new( global.listen_socket );
    84         g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
    85 
     102        global.listen_watch_source_id = g_io_add_watch( ch, G_IO_IN, bitlbee_io_new_client, NULL );
     103       
    86104#ifndef _WIN32
    87105        if( !global.conf->nofork )
     
    164182                return FALSE;
    165183        }
     184       
     185        return TRUE;
    166186       
    167187        /* Very naughty, go read the RFCs! >:) */
  • bitlbee.conf

    rffea9b9 rd25f6fc  
    1414##    and other reasons, the use of daemon-mode is *STRONGLY* discouraged,
    1515##    don't even *think* of reporting bugs when you use this.
     16##  ForkDaemon -- Run as a stand-alone daemon, but keep all clients in separate
     17##    child processes. This should be pretty safe and reliable to use instead
     18##    of inetd mode.
    1619##
    1720# RunMode = Inetd
     
    4144##
    4245# AuthPassword = ItllBeBitlBee   ## Heh.. Our slogan. ;-)
     46
     47## OperPassword
     48##
     49## Password that unlocks access to special operator commands.
     50##
     51# OperPassword = ChangeMe!
    4352
    4453## HostName
  • bitlbee.h

    rffea9b9 rd25f6fc  
    114114typedef struct global_t {
    115115        int listen_socket;
     116        gint listen_watch_source_id;
    116117        help_t *help;
    117118        conf_t *conf;
  • conf.c

    rffea9b9 rd25f6fc  
    5353        conf->runmode = RUNMODE_INETD;
    5454        conf->authmode = AUTHMODE_OPEN;
    55         conf->password = NULL;
     55        conf->auth_pass = NULL;
     56        conf->oper_pass = NULL;
    5657        conf->configdir = g_strdup( CONFIG );
    5758        conf->plugindir = g_strdup( PLUGINDIR );
     
    7172        }
    7273       
    73         while( ( opt = getopt( argc, argv, "i:p:nvIDc:d:h" ) ) >= 0 )
     74        while( ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 )
    7475        {
    7576                if( opt == 'i' )
     
    9495                else if( opt == 'D' )
    9596                        conf->runmode=RUNMODE_DAEMON;
     97                else if( opt == 'F' )
     98                        conf->runmode=RUNMODE_FORKDAEMON;
    9699                else if( opt == 'c' )
    97100                {
     
    118121                                "  -I  Classic/InetD mode. (Default)\n"
    119122                                "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
     123                                "  -F  Forking daemon. (one process per client)\n"
    120124                                "  -i  Specify the interface (by IP address) to listen on.\n"
    121125                                "      (Default: 0.0.0.0 (any interface))\n"
     
    157161                                if( g_strcasecmp( ini->value, "daemon" ) == 0 )
    158162                                        conf->runmode = RUNMODE_DAEMON;
     163                                else if( g_strcasecmp( ini->value, "forkdaemon" ) == 0 )
     164                                        conf->runmode = RUNMODE_FORKDAEMON;
    159165                                else
    160166                                        conf->runmode = RUNMODE_INETD;
     
    184190                        else if( g_strcasecmp( ini->key, "authpassword" ) == 0 )
    185191                        {
    186                                 conf->password = g_strdup( ini->value );
     192                                conf->auth_pass = g_strdup( ini->value );
     193                        }
     194                        else if( g_strcasecmp( ini->key, "operpassword" ) == 0 )
     195                        {
     196                                conf->oper_pass = g_strdup( ini->value );
    187197                        }
    188198                        else if( g_strcasecmp( ini->key, "hostname" ) == 0 )
  • conf.h

    rffea9b9 rd25f6fc  
    2727#define __CONF_H
    2828
    29 typedef enum runmode { RUNMODE_DAEMON, RUNMODE_INETD } runmode_t;
     29typedef enum runmode { RUNMODE_DAEMON, RUNMODE_FORKDAEMON, RUNMODE_INETD } runmode_t;
    3030typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } authmode_t;
    3131
     
    3838        runmode_t runmode;
    3939        authmode_t authmode;
    40         char *password;
     40        char *auth_pass;
     41        char *oper_pass;
    4142        char *hostname;
    4243        char *configdir;
  • irc.c

    rffea9b9 rd25f6fc  
    264264        g_free(irc);
    265265       
    266         if( global.conf->runmode == RUNMODE_INETD )
     266        if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON )
    267267                g_main_quit( global.loop );
    268268}
     
    422422                                irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    423423                        }
    424                         else if( strcmp( cmd[1], (global.conf)->password ) == 0 )
     424                        else if( strcmp( cmd[1], (global.conf)->auth_pass ) == 0 )
    425425                        {
    426426                                irc->status = USTATUS_AUTHORIZED;
     
    500500        {
    501501                irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost );
     502        }
     503        else if( g_strcasecmp( cmd[0], "OPER" ) == 0 )
     504        {
     505                if( !cmd[2] )
     506                        irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
     507                else if( strcmp( cmd[2], global.conf->oper_pass ) == 0 )
     508                        irc_umode_set( irc, irc->nick, "+o" );
     509                // else
     510                        /* FIXME/TODO: Find out which reply to send now. */
    502511        }
    503512        else if( g_strcasecmp( cmd[0], "MODE" ) == 0 )
  • irc.h

    rffea9b9 rd25f6fc  
    4040#define FLOOD_SEND_MAXBUFFER (1024*20)
    4141
    42 #define UMODES "ais"
     42#define UMODES "aiso"
    4343#define CMODES "nt"
    4444#define CMODE "t"
  • storage_text.c

    rffea9b9 rd25f6fc  
    7171        user_t *ru = user_find( irc, ROOT_NICK );
    7272       
    73         if( irc->status == USTATUS_IDENTIFIED )
     73        if( irc->status >= USTATUS_IDENTIFIED )
    7474                return( 1 );
    7575       
  • unix.c

    rffea9b9 rd25f6fc  
    3232#include <unistd.h>
    3333#include <sys/time.h>
     34#include <sys/wait.h>
    3435
    3536global_t global;        /* Against global namespace pollution */
     
    4647        global.loop = g_main_new( FALSE );
    4748       
    48         log_init( );
     49        log_init();
    4950
    5051        nogaim_init();
     
    7071                log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION );
    7172        }
     73        else if( global.conf->runmode == RUNMODE_FORKDAEMON )
     74        {
     75                i = bitlbee_daemon_init();
     76                log_message( LOGLVL_INFO, "Bitlbee %s starting in forking daemon mode.", BITLBEE_VERSION );
     77        }
    7278        if( i != 0 )
    7379                return( i );
    7480
    75         global.storage = storage_init( global.conf->primary_storage,
    76                                                                    global.conf->migrate_storage );
     81        global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
    7782        if ( global.storage == NULL) {
    7883                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
     
    8489        memset( &sig, 0, sizeof( sig ) );
    8590        sig.sa_handler = sighandler;
     91        sigaction( SIGCHLD, &sig, &old );
    8692        sigaction( SIGPIPE, &sig, &old );
    8793        sig.sa_flags = SA_RESETHAND;
     
    107113static void sighandler( int signal )
    108114{
    109         /* FIXME: In fact, calling log_message() here can be dangerous. But well, let's take the risk for now. */
     115        /* FIXME: Calling log_message() here is not a very good idea! */
    110116       
    111117        if( signal == SIGTERM )
     
    133139                }
    134140        }
     141        else if( signal == SIGCHLD )
     142        {
     143                pid_t pid;
     144                int st;
     145               
     146                while( ( pid = waitpid( 0, &st, WNOHANG ) ) > 0 )
     147                {
     148                        if( WIFSIGNALED( st ) )
     149                                log_message( LOGLVL_INFO, "Client %d terminated normally. (status = %d)", pid, WEXITSTATUS( st ) );
     150                        else if( WIFEXITED( st ) )
     151                                log_message( LOGLVL_INFO, "Client %d killed by signal %d.", pid, WTERMSIG( st ) );
     152                }
     153        }
    135154        else if( signal != SIGPIPE )
    136155        {
Note: See TracChangeset for help on using the changeset viewer.