Changeset d25f6fc
- Timestamp:
- 2005-12-26T14:02:47Z (19 years ago)
- Branches:
- master
- Children:
- 238f828
- Parents:
- ffea9b9
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
bitlbee.c
rffea9b9 rd25f6fc 37 37 size_t size = sizeof( struct sockaddr_in ); 38 38 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 45 63 return TRUE; 46 64 } … … 66 84 listen_addr.sin_port = htons( global.conf->port ); 67 85 listen_addr.sin_addr.s_addr = inet_addr( global.conf->iface ); 68 86 69 87 i = bind( global.listen_socket, (struct sockaddr *) &listen_addr, sizeof( struct sockaddr ) ); 70 88 if( i == -1 ) … … 73 91 return( -1 ); 74 92 } 75 93 76 94 i = listen( global.listen_socket, 10 ); 77 95 if( i == -1 ) … … 80 98 return( -1 ); 81 99 } 82 100 83 101 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 86 104 #ifndef _WIN32 87 105 if( !global.conf->nofork ) … … 164 182 return FALSE; 165 183 } 184 185 return TRUE; 166 186 167 187 /* Very naughty, go read the RFCs! >:) */ -
bitlbee.conf
rffea9b9 rd25f6fc 14 14 ## and other reasons, the use of daemon-mode is *STRONGLY* discouraged, 15 15 ## 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. 16 19 ## 17 20 # RunMode = Inetd … … 41 44 ## 42 45 # AuthPassword = ItllBeBitlBee ## Heh.. Our slogan. ;-) 46 47 ## OperPassword 48 ## 49 ## Password that unlocks access to special operator commands. 50 ## 51 # OperPassword = ChangeMe! 43 52 44 53 ## HostName -
bitlbee.h
rffea9b9 rd25f6fc 114 114 typedef struct global_t { 115 115 int listen_socket; 116 gint listen_watch_source_id; 116 117 help_t *help; 117 118 conf_t *conf; -
conf.c
rffea9b9 rd25f6fc 53 53 conf->runmode = RUNMODE_INETD; 54 54 conf->authmode = AUTHMODE_OPEN; 55 conf->password = NULL; 55 conf->auth_pass = NULL; 56 conf->oper_pass = NULL; 56 57 conf->configdir = g_strdup( CONFIG ); 57 58 conf->plugindir = g_strdup( PLUGINDIR ); … … 71 72 } 72 73 73 while( ( opt = getopt( argc, argv, "i:p:nvID c:d:h" ) ) >= 0 )74 while( ( opt = getopt( argc, argv, "i:p:nvIDFc:d:h" ) ) >= 0 ) 74 75 { 75 76 if( opt == 'i' ) … … 94 95 else if( opt == 'D' ) 95 96 conf->runmode=RUNMODE_DAEMON; 97 else if( opt == 'F' ) 98 conf->runmode=RUNMODE_FORKDAEMON; 96 99 else if( opt == 'c' ) 97 100 { … … 118 121 " -I Classic/InetD mode. (Default)\n" 119 122 " -D Daemon mode. (Still EXPERIMENTAL!)\n" 123 " -F Forking daemon. (one process per client)\n" 120 124 " -i Specify the interface (by IP address) to listen on.\n" 121 125 " (Default: 0.0.0.0 (any interface))\n" … … 157 161 if( g_strcasecmp( ini->value, "daemon" ) == 0 ) 158 162 conf->runmode = RUNMODE_DAEMON; 163 else if( g_strcasecmp( ini->value, "forkdaemon" ) == 0 ) 164 conf->runmode = RUNMODE_FORKDAEMON; 159 165 else 160 166 conf->runmode = RUNMODE_INETD; … … 184 190 else if( g_strcasecmp( ini->key, "authpassword" ) == 0 ) 185 191 { 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 ); 187 197 } 188 198 else if( g_strcasecmp( ini->key, "hostname" ) == 0 ) -
conf.h
rffea9b9 rd25f6fc 27 27 #define __CONF_H 28 28 29 typedef enum runmode { RUNMODE_DAEMON, RUNMODE_ INETD } runmode_t;29 typedef enum runmode { RUNMODE_DAEMON, RUNMODE_FORKDAEMON, RUNMODE_INETD } runmode_t; 30 30 typedef enum authmode { AUTHMODE_OPEN, AUTHMODE_CLOSED, AUTHMODE_REGISTERED } authmode_t; 31 31 … … 38 38 runmode_t runmode; 39 39 authmode_t authmode; 40 char *password; 40 char *auth_pass; 41 char *oper_pass; 41 42 char *hostname; 42 43 char *configdir; -
irc.c
rffea9b9 rd25f6fc 264 264 g_free(irc); 265 265 266 if( global.conf->runmode == RUNMODE_INETD )266 if( global.conf->runmode == RUNMODE_INETD || global.conf->runmode == RUNMODE_FORKDAEMON ) 267 267 g_main_quit( global.loop ); 268 268 } … … 422 422 irc_reply( irc, 461, "%s :Need more parameters", cmd[0] ); 423 423 } 424 else if( strcmp( cmd[1], (global.conf)-> password) == 0 )424 else if( strcmp( cmd[1], (global.conf)->auth_pass ) == 0 ) 425 425 { 426 426 irc->status = USTATUS_AUTHORIZED; … … 500 500 { 501 501 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. */ 502 511 } 503 512 else if( g_strcasecmp( cmd[0], "MODE" ) == 0 ) -
irc.h
rffea9b9 rd25f6fc 40 40 #define FLOOD_SEND_MAXBUFFER (1024*20) 41 41 42 #define UMODES "ais "42 #define UMODES "aiso" 43 43 #define CMODES "nt" 44 44 #define CMODE "t" -
storage_text.c
rffea9b9 rd25f6fc 71 71 user_t *ru = user_find( irc, ROOT_NICK ); 72 72 73 if( irc->status == USTATUS_IDENTIFIED )73 if( irc->status >= USTATUS_IDENTIFIED ) 74 74 return( 1 ); 75 75 -
unix.c
rffea9b9 rd25f6fc 32 32 #include <unistd.h> 33 33 #include <sys/time.h> 34 #include <sys/wait.h> 34 35 35 36 global_t global; /* Against global namespace pollution */ … … 46 47 global.loop = g_main_new( FALSE ); 47 48 48 log_init( 49 log_init(); 49 50 50 51 nogaim_init(); … … 70 71 log_message( LOGLVL_INFO, "Bitlbee %s starting in daemon mode.", BITLBEE_VERSION ); 71 72 } 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 } 72 78 if( i != 0 ) 73 79 return( i ); 74 80 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 ); 77 82 if ( global.storage == NULL) { 78 83 log_message( LOGLVL_ERROR, "Unable to load storage backend '%s'", global.conf->primary_storage ); … … 84 89 memset( &sig, 0, sizeof( sig ) ); 85 90 sig.sa_handler = sighandler; 91 sigaction( SIGCHLD, &sig, &old ); 86 92 sigaction( SIGPIPE, &sig, &old ); 87 93 sig.sa_flags = SA_RESETHAND; … … 107 113 static void sighandler( int signal ) 108 114 { 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! */ 110 116 111 117 if( signal == SIGTERM ) … … 133 139 } 134 140 } 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 } 135 154 else if( signal != SIGPIPE ) 136 155 {
Note: See TracChangeset
for help on using the changeset viewer.