Changeset aaf92a9


Ignore:
Timestamp:
2007-12-02T23:18:25Z (16 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
08135df, de03374
Parents:
80e9db9
Message:

Imported setuid() patch from Simo Leone <simo@archlinux...> with some
modifications. Also adding some missing g_free()s to conf.c.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bitlbee.conf

    r80e9db9 raaf92a9  
    1919##
    2020# RunMode = Inetd
     21
     22## User:
     23##
     24## If BitlBee is started by root as a daemon, it can drop root privileges,
     25## and change to the specified user.
     26##
     27# User = bitlbee
    2128
    2229## DaemonPort/DaemonInterface:
  • conf.c

    r80e9db9 raaf92a9  
    6363        conf->ping_interval = 180;
    6464        conf->ping_timeout = 300;
     65        conf->user = NULL;
    6566        proxytype = 0;
    6667       
     
    7677        }
    7778       
    78         while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:" ) ) >= 0 )
     79        while( argc > 0 && ( opt = getopt( argc, argv, "i:p:P:nvIDFc:d:hR:u:" ) ) >= 0 )
    7980        /*     ^^^^ Just to make sure we skip this step from the REHASH handler. */
    8081        {
     
    132133                                "  -D  Daemon mode. (Still EXPERIMENTAL!)\n"
    133134                                "  -F  Forking daemon. (one process per client)\n"
     135                                "  -u  Run daemon as specified user.\n"
    134136                                "  -P  Specify PID-file (not for inetd mode)\n"
    135137                                "  -i  Specify the interface (by IP address) to listen on.\n"
     
    151153                        ipc_master_set_statefile( optarg );
    152154                }
     155                else if( opt == 'u' )
     156                {
     157                        g_free( conf->user );
     158                        conf->user = g_strdup( optarg );
     159                }
    153160        }
    154161       
     
    192199                        else if( g_strcasecmp( ini->key, "daemoninterface" ) == 0 )
    193200                        {
     201                                g_free( conf->iface );
    194202                                conf->iface = g_strdup( ini->value );
    195203                        }
    196204                        else if( g_strcasecmp( ini->key, "daemonport" ) == 0 )
    197205                        {
     206                                g_free( conf->port );
    198207                                conf->port = g_strdup( ini->value );
    199208                        }
     
    209218                        else if( g_strcasecmp( ini->key, "authpassword" ) == 0 )
    210219                        {
     220                                g_free( conf->auth_pass );
    211221                                conf->auth_pass = g_strdup( ini->value );
    212222                        }
    213223                        else if( g_strcasecmp( ini->key, "operpassword" ) == 0 )
    214224                        {
     225                                g_free( conf->oper_pass );
    215226                                conf->oper_pass = g_strdup( ini->value );
    216227                        }
    217228                        else if( g_strcasecmp( ini->key, "hostname" ) == 0 )
    218229                        {
     230                                g_free( conf->hostname );
    219231                                conf->hostname = g_strdup( ini->value );
    220232                        }
     
    281293                                g_free( url );
    282294                        }
     295                        else if( g_strcasecmp( ini->key, "user" ) == 0 )
     296                        {
     297                                g_free( conf->user );
     298                                conf->user = g_strdup( ini->value );
     299                        }
    283300                        else
    284301                        {
  • conf.h

    r80e9db9 raaf92a9  
    4949        int ping_interval;
    5050        int ping_timeout;
     51        char *user;
    5152} conf_t;
    5253
  • unix.c

    r80e9db9 raaf92a9  
    3434#include <sys/time.h>
    3535#include <sys/wait.h>
     36#include <pwd.h>
    3637
    3738global_t global;        /* Against global namespace pollution */
     
    4546        struct sigaction sig, old;
    4647       
    47         memset( &global, 0, sizeof( global_t ) );
    48        
    4948        log_init();
    5049        CONF_FILE = g_strdup( CONF_FILE_DEF );
     
    8786                return( i );
    8887       
     88        if( ( global.conf->user && *global.conf->user ) &&
     89            ( global.conf->runmode == RUNMODE_DAEMON ||
     90              global.conf->runmode == RUNMODE_FORKDAEMON ) &&
     91            ( !getuid() || !geteuid() ) )
     92        {
     93                struct passwd *pw = NULL;
     94                pw = getpwnam( global.conf->user );
     95                if( pw )
     96                {
     97                        setgid( pw->pw_gid );
     98                        setuid( pw->pw_uid );
     99                }
     100        }
     101
    89102        global.storage = storage_init( global.conf->primary_storage, global.conf->migrate_storage );
    90         if ( global.storage == NULL) {
     103        if( global.storage == NULL )
     104        {
    91105                log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage );
    92106                return( 1 );
    93107        }
    94        
    95108       
    96109        /* Catch some signals to tell the user what's happening before quitting */
Note: See TracChangeset for help on using the changeset viewer.