ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/ircd.c
(Generate patch)

Comparing:
ircd-hybrid-7.2/src/ircd.c (file contents), Revision 876 by michael, Wed Oct 24 21:51:21 2007 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 5737 by michael, Sun Mar 29 11:11:20 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  ircd.c: Starts up and runs the ircd.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
4 > *  Copyright (c) 1997-2015 ircd-hybrid development team
5   *
6   *  This program is free software; you can redistribute it and/or modify
7   *  it under the terms of the GNU General Public License as published by
# Line 16 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20 < *
21 < *  $Id$
20 > */
21 >
22 > /*! \file ircd.c
23 > * \brief Starts up and runs the ircd.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_user.h"
29 < #include "tools.h"
28 > #include "user.h"
29 > #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
32 #include "common.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36   #include "irc_string.h"
37 #include "sprintf_irc.h"
37   #include "ircd_signal.h"
38 < #include "list.h"
40 < #include "s_gline.h"
38 > #include "gline.h"
39   #include "motd.h"
40 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
40 > #include "conf.h"
41   #include "hostmask.h"
45 #include "numeric.h"
46 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45 < #include "s_auth.h"
45 > #include "rng_mt.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
54 < #include "s_misc.h"
55 < #include "s_serv.h"      /* try_connections */
56 < #include "s_stats.h"
48 > #include "log.h"
49 > #include "server.h"      /* try_connections */
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
63 #include "balloc.h"
64 #include "motd.h"
65 #include "supported.h"
56   #include "watch.h"
57 + #include "conf_db.h"
58 + #include "conf_class.h"
59 + #include "ipcache.h"
60  
68 /* Try and find the correct name to use with getrlimit() for setting the max.
69 * number of files allowed to be open by this process.
70 */
61  
62 < /* /quote set variables */
63 < struct SetOptions GlobalSetOptions;
62 > #ifdef HAVE_LIBGEOIP
63 > GeoIP *geoip_ctx;
64 > #endif
65  
66 < /* configuration set from ircd.conf */
67 < struct config_file_entry ConfigFileEntry;
68 < /* server info set from ircd.conf */
69 < struct server_info ServerInfo;
79 < /* admin info set from ircd.conf */
80 < struct admin_info AdminInfo = { NULL, NULL, NULL };
81 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
82 < struct ServerState_t server_state = { 0 };
83 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
66 > struct SetOptions GlobalSetOptions;  /* /quote set variables */
67 > struct Counter Count;
68 > struct ServerState_t server_state;
69 > struct ServerStatistics ServerStats;
70   struct timeval SystemTime;
71 < struct Client me;             /* That's me */
72 < struct LocalUser meLocalUser; /* That's also part of me */
87 < unsigned long connect_id = 0; /* unique connect ID */
71 > struct Connection meConnection;  /* That's also part of me */
72 > struct Client me = { .connection = &meConnection };  /* That's me */
73  
74 < static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
74 > char **myargv;
75   const char *logFileName = LPATH;
76   const char *pidFileName = PPATH;
77  
78 < char **myargv;
79 < char ircd_platform[PLATFORMLEN];
80 <
81 < int dorehash = 0;
82 < int doremotd = 0;
83 < time_t nextconnect = 1;       /* time for next try_connections call */
78 > unsigned int dorehash;
79 > unsigned int doremotd;
80 > unsigned int default_server_capabs;
81 > unsigned int splitmode;
82 > unsigned int splitchecking;
83 > unsigned int split_users;
84 > unsigned int split_servers;
85  
86 < /* Set to zero because it should be initialized later using
87 < * initialize_server_capabs
88 < */
89 < int default_server_capabs = 0;
86 > static struct event event_cleanup_glines =
87 > {
88 >  .name = "cleanup_glines",
89 >  .handler = cleanup_glines,
90 >  .when = CLEANUP_GLINES_TIME
91 > };
92  
93 < #ifdef HAVE_LIBCRYPTO
94 < int bio_spare_fd = -1;
95 < #endif
93 > static struct event event_cleanup_tklines =
94 > {
95 >  .name = "cleanup_tklines",
96 >  .handler = cleanup_tklines,
97 >  .when = CLEANUP_TKLINES_TIME
98 > };
99  
100 < int splitmode;
101 < int splitchecking;
102 < int split_users;
103 < unsigned int split_servers;
100 > static struct event event_try_connections =
101 > {
102 >  .name = "try_connections",
103 >  .handler = try_connections,
104 >  .when = STARTUP_CONNECTIONS_TIME
105 > };
106  
107 < /* Do klines the same way hybrid-6 did them, i.e. at the
108 < * top of the next io_loop instead of in the same loop as
109 < * the klines are being applied.
110 < *
111 < * This should fix strange CPU starvation as very indirectly reported.
112 < * (Why do you people not email bug reports? WHY? WHY?)
120 < *
121 < * - Dianora
122 < */
107 > static struct event event_comm_checktimeouts =
108 > {
109 >  .name = "comm_checktimeouts",
110 >  .handler = comm_checktimeouts,
111 >  .when = 1
112 > };
113  
114 < int rehashed_klines = 0;
114 > static struct event event_save_all_databases =
115 > {
116 >  .name = "save_all_databases",
117 >  .handler = save_all_databases,
118 >  .when = DATABASE_UPDATE_TIMEOUT
119 > };
120  
121 < /*
122 < * get_vm_top - get the operating systems notion of the resident set size
123 < */
124 < #ifndef _WIN32
125 < static unsigned long
131 < get_vm_top(void)
132 < {
133 <  /*
134 <   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
135 <   * however it seems that everyone defines it. Calling sbrk with a 0
136 <   * argument will return a pointer to the top of the process virtual
137 <   * memory without changing the process size, so this call should be
138 <   * reasonably safe (sbrk returns the new value for the top of memory).
139 <   * This code relies on the notion that the address returned will be an
140 <   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
141 <   * returned. We really shouldn't be using it here but...
142 <   */
121 > struct event event_write_links_file =
122 > {
123 >  .name = "write_links_file",
124 >  .handler = write_links_file,
125 > };
126  
144  void *vptr = sbrk(0);
145  return((unsigned long)vptr);
146 }
127  
128   /*
129   * print_startup - print startup information
# Line 151 | Line 131 | get_vm_top(void)
131   static void
132   print_startup(int pid)
133   {
134 <  printf("ircd: version %s\n", ircd_version);
134 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
135    printf("ircd: pid %d\n", pid);
136    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
137 <         : "foreground", ConfigFileEntry.dpath);
137 >         : "foreground", ConfigGeneral.dpath);
138   }
139  
140   static void
# Line 175 | Line 155 | make_daemon(void)
155  
156    setsid();
157   }
178 #endif
179
180 /*
181 * get_maxrss - get the operating systems notion of the resident set size
182 */
183 unsigned long
184 get_maxrss(void)
185 {
186 #ifdef _WIN32
187  return (0);   /* FIXME */
188 #else
189  return (get_vm_top() - initialVMTop);
190 #endif
191 }
158  
159   static int printVersion = 0;
160  
161 < struct lgetopt myopts[] = {
162 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
163 <   STRING, "File to use for dline.conf"},
198 <  {"configfile", &ConfigFileEntry.configfile,
161 > static struct lgetopt myopts[] =
162 > {
163 >  {"configfile", &ConfigGeneral.configfile,
164     STRING, "File to use for ircd.conf"},
165 <  {"klinefile",  &ConfigFileEntry.klinefile,
166 <   STRING, "File to use for kline.conf"},
167 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
168 <   STRING, "File to use for xline.conf"},
169 <  {"logfile",    &logFileName,
165 >  {"glinefile",  &ConfigGeneral.glinefile,
166 >   STRING, "File to use for gline database"},
167 >  {"klinefile",  &ConfigGeneral.klinefile,
168 >   STRING, "File to use for kline database"},
169 >  {"dlinefile",  &ConfigGeneral.dlinefile,
170 >   STRING, "File to use for dline database"},
171 >  {"xlinefile",  &ConfigGeneral.xlinefile,
172 >   STRING, "File to use for xline database"},
173 >  {"resvfile",  &ConfigGeneral.resvfile,
174 >   STRING, "File to use for resv database"},
175 >  {"logfile",    &logFileName,
176     STRING, "File to use for ircd.log"},
177    {"pidfile",    &pidFileName,
178     STRING, "File to use for process ID"},
179 <  {"foreground", &server_state.foreground,
179 >  {"foreground", &server_state.foreground,
180     YESNO, "Run in foreground (don't detach)"},
181 <  {"version",    &printVersion,
181 >  {"version",    &printVersion,
182     YESNO, "Print version and exit"},
183    {"help", NULL, USAGE, "Print this text"},
184    {NULL, NULL, STRING, NULL},
# Line 216 | Line 187 | struct lgetopt myopts[] = {
187   void
188   set_time(void)
189   {
190 <  static char to_send[200];
220 <  struct timeval newtime;
221 < #ifdef _WIN32
222 <  FILETIME ft;
223 <
224 <  GetSystemTimeAsFileTime(&ft);
225 <  if (ft.dwLowDateTime < 0xd53e8000)
226 <    ft.dwHighDateTime--;
227 <  ft.dwLowDateTime -= 0xd53e8000;
228 <  ft.dwHighDateTime -= 0x19db1de;
229 <
230 <  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
231 <  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
232 < #else
233 <  newtime.tv_sec  = 0;
234 <  newtime.tv_usec = 0;
190 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
191  
192    if (gettimeofday(&newtime, NULL) == -1)
193    {
194 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
194 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
195           strerror(errno));
196 <    sendto_realops_flags(UMODE_ALL, L_ALL,
196 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
197                           "Clock Failure (%s), TS can be corrupted",
198                           strerror(errno));
199 <    restart("Clock Failure");
199 >    server_die("Clock Failure", 1);
200    }
245 #endif
201  
202    if (newtime.tv_sec < CurrentTime)
203    {
204 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
205 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
206 <    report_error(L_ALL, to_send, me.name, 0);
204 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
205 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
206 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
207 >                         "System clock is running backwards - (%lu < %lu)",
208 >                         (unsigned long)newtime.tv_sec,
209 >                         (unsigned long)CurrentTime);
210      set_back_events(CurrentTime - newtime.tv_sec);
211    }
212  
# Line 259 | Line 217 | set_time(void)
217   static void
218   io_loop(void)
219   {
220 <  while (1 == 1)
220 >  while (1)
221    {
264    /*
265     * Maybe we want a flags word?
266     * ie. if (REHASHED_KLINES(global_flags))
267     * SET_REHASHED_KLINES(global_flags)
268     * CLEAR_REHASHED_KLINES(global_flags)
269     *
270     * - Dianora
271     */
272    if (rehashed_klines)
273    {
274      check_conf_klines();
275      rehashed_klines = 0;
276    }
277
222      if (listing_client_list.head)
223      {
224 <      dlink_node *ptr = NULL, *ptr_next = NULL;
225 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
226 <      {
283 <        struct Client *client_p = ptr->data;
284 <        assert(client_p->localClient->list_task);
285 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
286 <      }
224 >      dlink_node *node = NULL, *node_next = NULL;
225 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
226 >        safe_list_channels(node->data, 0);
227      }
228  
229 <    /* Run pending events, then get the number of seconds to the next
230 <     * event
291 <     */
292 <    while (eventNextTime() <= CurrentTime)
293 <      eventRun();
229 >    /* Run pending events */
230 >    event_run();
231  
232      comm_select();
233      exit_aborted_clients();
234      free_exited_clients();
298    send_queued_all();
235  
236      /* Check to see whether we have to rehash the configuration .. */
237      if (dorehash)
238      {
239 <      rehash(1);
239 >      conf_rehash(1);
240        dorehash = 0;
241      }
242 +
243      if (doremotd)
244      {
245 <      read_message_file(&ConfigFileEntry.motd);
246 <      sendto_realops_flags(UMODE_ALL, L_ALL,
247 <                           "Got signal SIGUSR1, reloading ircd motd file");
245 >      motd_recache();
246 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
247 >                           "Got signal SIGUSR1, reloading motd file(s)");
248        doremotd = 0;
249      }
250    }
# Line 317 | Line 254 | io_loop(void)
254   *
255   * inputs       - none
256   * output       - none
257 < * side effects - This sets all global set options needed
257 > * side effects - This sets all global set options needed
258   */
259   static void
260   initialize_global_set_options(void)
261   {
262 <  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
263 <
327 <  GlobalSetOptions.autoconn  = 1;
262 >  GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients;
263 >  GlobalSetOptions.autoconn = 1;
264    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
265 <  GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
266 <
267 <  if (ConfigFileEntry.default_floodcount)
268 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
333 <  else
334 <    GlobalSetOptions.floodcount = 10;
335 <
336 <  /* XXX I have no idea what to try here - Dianora */
337 <  GlobalSetOptions.joinfloodcount = 16;
338 <  GlobalSetOptions.joinfloodtime = 8;
265 >  GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
266 >  GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
267 >  GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count;
268 >  GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time;
269  
270    split_servers = ConfigChannel.default_split_server_count;
271    split_users   = ConfigChannel.default_split_user_count;
# Line 348 | Line 278 | initialize_global_set_options(void)
278    }
279  
280    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
351  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
352  /* End of global set options */
353 }
354
355 /* initialize_message_files()
356 *
357 * inputs       - none
358 * output       - none
359 * side effects - Set up all message files needed, motd etc.
360 */
361 static void
362 initialize_message_files(void)
363 {
364  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
365  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
366  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
367
368  read_message_file(&ConfigFileEntry.motd);
369  read_message_file(&ConfigFileEntry.opermotd);
370  read_message_file(&ConfigFileEntry.linksfile);
371
372  init_isupport();
281   }
282  
283   /* initialize_server_capabs()
# Line 381 | Line 289 | static void
289   initialize_server_capabs(void)
290   {
291    add_capability("QS", CAP_QS, 1);
384  add_capability("LL", CAP_LL, 1);
292    add_capability("EOB", CAP_EOB, 1);
293 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
387 <    add_capability("TS6", CAP_TS6, 0);
388 <  add_capability("ZIP", CAP_ZIP, 0);
293 >  add_capability("TS6", CAP_TS6, 0);
294    add_capability("CLUSTER", CAP_CLUSTER, 1);
295 < #ifdef HALFOPS
295 >  add_capability("SVS", CAP_SVS, 1);
296 >  add_capability("CHW", CAP_CHW, 1);
297    add_capability("HOPS", CAP_HOPS, 1);
392 #endif
298   }
299  
300   /* write_pidfile()
# Line 401 | Line 306 | initialize_server_capabs(void)
306   static void
307   write_pidfile(const char *filename)
308   {
309 <  FBFILE *fb;
309 >  FILE *fb;
310  
311 <  if ((fb = fbopen(filename, "w")))
311 >  if ((fb = fopen(filename, "w")))
312    {
313 <    char buff[32];
313 >    char buff[IRCD_BUFSIZE];
314      unsigned int pid = (unsigned int)getpid();
410    size_t nbytes = ircsprintf(buff, "%u\n", pid);
315  
316 <    if ((fbputs(buff, fb, nbytes) == -1))
317 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
318 <           pid, filename, strerror(errno));
316 >    snprintf(buff, sizeof(buff), "%u\n", pid);
317 >
318 >    if (fputs(buff, fb) == -1)
319 >      ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s",
320 >           filename, strerror(errno));
321  
322 <    fbclose(fb);
417 <    return;
322 >    fclose(fb);
323    }
324    else
325 <  {
326 <    ilog(L_ERROR, "Error opening pid file %s", filename);
422 <  }
325 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
326 >         filename, strerror(errno));
327   }
328  
329   /* check_pidfile()
# Line 433 | Line 337 | write_pidfile(const char *filename)
337   static void
338   check_pidfile(const char *filename)
339   {
340 < #ifndef _WIN32
341 <  FBFILE *fb;
438 <  char buff[32];
340 >  FILE *fb;
341 >  char buff[IRCD_BUFSIZE];
342    pid_t pidfromfile;
343  
344    /* Don't do logging here, since we don't have log() initialised */
345 <  if ((fb = fbopen(filename, "r")))
345 >  if ((fb = fopen(filename, "r")))
346    {
347 <    if (fbgets(buff, 20, fb) == NULL)
347 >    if (!fgets(buff, 20, fb))
348      {
349        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
350         * strerror(errno));
# Line 459 | Line 362 | check_pidfile(const char *filename)
362        }
363      }
364  
365 <    fbclose(fb);
365 >    fclose(fb);
366    }
367    else if (errno != ENOENT)
368    {
369      /* log(L_ERROR, "Error opening pid file %s", filename); */
370    }
468 #endif
371   }
372  
373   /* setup_corefile()
# Line 490 | Line 392 | setup_corefile(void)
392   #endif
393   }
394  
395 + #ifdef HAVE_LIBCRYPTO
396 + static int
397 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
398 + {
399 +  return 1;
400 + }
401 + #endif
402 +
403   /* init_ssl()
404   *
405   * inputs       - nothing
# Line 497 | Line 407 | setup_corefile(void)
407   * side effects - setups SSL context.
408   */
409   static void
410 < init_ssl(void)
410 > ssl_init(void)
411   {
412   #ifdef HAVE_LIBCRYPTO
413    SSL_load_error_strings();
414    SSLeay_add_ssl_algorithms();
415  
416 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
507 <  if (!ServerInfo.ctx)
416 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
417    {
418 <    const char *s;
418 >    const char *s = ERR_lib_error_string(ERR_get_error());
419  
420 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
421 <            s = ERR_lib_error_string(ERR_get_error()));
422 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
420 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
421 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
422 >    exit(EXIT_FAILURE);
423 >    return;  /* Not reached */
424    }
425  
426 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
427 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
428 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
426 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
427 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
428 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
429 >                     always_accept_verify_cb);
430 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
431 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
432  
433 <  bio_spare_fd = save_spare_fd("SSL private key validation");
434 < #endif /* HAVE_LIBCRYPTO */
435 < }
433 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
434 >  {
435 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
436  
437 < /* init_callbacks()
438 < *
439 < * inputs       - nothing
440 < * output       - nothing
441 < * side effects - setups standard hook points
442 < */
443 < static void
444 < init_callbacks(void)
445 < {
446 <  iorecv_cb = register_callback("iorecv", iorecv_default);
447 <  iosend_cb = register_callback("iosend", iosend_default);
448 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
449 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
437 >    if (key)
438 >    {
439 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
440 >      EC_KEY_free(key);
441 >    }
442 >  }
443 >
444 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
445 > #endif
446 >
447 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
448 >  {
449 >    const char *s = ERR_lib_error_string(ERR_get_error());
450 >
451 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
452 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
453 >    exit(EXIT_FAILURE);
454 >    return;  /* Not reached */
455 >  }
456 >
457 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
458 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
459 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
460 >                     always_accept_verify_cb);
461 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
462 > #endif /* HAVE_LIBCRYPTO */
463   }
464  
465   int
466   main(int argc, char *argv[])
467   {
468 <  /* Check to see if the user is running
469 <   * us as root, which is a nono
544 <   */
545 < #ifndef _WIN32
546 <  if (geteuid() == 0)
468 >  /* Check to see if the user is running us as root, which is a nono */
469 >  if (!geteuid())
470    {
471 <    fprintf(stderr, "Don't run ircd as root!!!\n");
472 <    return(-1);
471 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
472 >    return -1;
473    }
474  
475    /* Setup corefile size immediately after boot -kre */
476    setup_corefile();
477  
478 <  /* set initialVMTop before we allocate any memory */
556 <  initialVMTop = get_vm_top();
557 < #endif
558 <
559 <  /* save server boot time right away, so getrusage works correctly */
478 >  /* Save server boot time right away, so getrusage works correctly */
479    set_time();
480  
481 <    /* It ain't random, but it ought to be a little harder to guess */
482 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
483 <  memset(&me, 0, sizeof(me));
484 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
485 <  me.localClient = &meLocalUser;
486 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
487 <                                                   of Client list */
488 <
489 <  memset(&ServerInfo, 0, sizeof(ServerInfo));
490 <
491 <  /* Initialise the channel capability usage counts... */
492 <  init_chcap_usage_counts();
493 <
494 <  ConfigFileEntry.dpath      = DPATH;
495 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
577 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
578 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
579 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
580 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
581 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
582 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
583 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
584 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
481 >  /* It's not random, but it ought to be a little harder to guess */
482 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
483 >
484 >  dlinkAdd(&me, &me.node, &global_client_list);
485 >
486 >  ConfigGeneral.dpath      = DPATH;
487 >  ConfigGeneral.spath      = SPATH;
488 >  ConfigGeneral.mpath      = MPATH;
489 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
490 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
491 >  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
492 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
493 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
494 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
495 >
496    myargv = argv;
497 <  umask(077);                /* better safe than sorry --SRB */
497 >  umask(077);  /* umask 077: u=rwx,g=,o= */
498  
499    parseargs(&argc, &argv, myopts);
500  
501    if (printVersion)
502    {
503 <    printf("ircd: version %s\n", ircd_version);
503 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
504      exit(EXIT_SUCCESS);
505    }
506  
507 <  if (chdir(ConfigFileEntry.dpath))
507 >  if (chdir(ConfigGeneral.dpath))
508    {
509      perror("chdir");
510      exit(EXIT_FAILURE);
511    }
512  
513 <  init_ssl();
513 >  ssl_init();
514  
604 #ifndef _WIN32
515    if (!server_state.foreground)
516    {
517      make_daemon();
# Line 611 | Line 521 | main(int argc, char *argv[])
521      print_startup(getpid());
522  
523    setup_signals();
614 #endif
524  
616  get_ircd_platform(ircd_platform);
617
618  /* Init the event subsystem */
619  eventInit();
525    /* We need this to initialise the fd array before anything else */
526    fdlist_init();
527 <  init_log(logFileName);
528 <  check_can_use_v6();
529 <  init_comm();         /* This needs to be setup early ! -- adrian */
527 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
528 >
529 >  init_netio();         /* This needs to be setup early ! -- adrian */
530 >
531    /* Check if there is pidfile and daemon already running */
532    check_pidfile(pidFileName);
533  
534 < #ifndef NOBALLOC
629 <  initBlockHeap();
630 < #endif
534 >  mp_pool_init();
535    init_dlink_nodes();
536 <  init_callbacks();
633 <  initialize_message_files();
536 >  init_isupport();
537    dbuf_init();
538 <  init_hash();
539 <  init_ip_hash_table();      /* client host ip hash table */
540 <  init_host_hash();          /* Host-hashtable. */
541 <  clear_tree_parse();
542 <  init_client();
640 <  init_class();
641 <  init_whowas();
538 >  hash_init();
539 >  ipcache_init();
540 >  client_init();
541 >  class_init();
542 >  whowas_init();
543    watch_init();
544 <  init_stats();
544 >  auth_init();          /* Initialise the auth code */
545 >  init_resolver();      /* Needs to be setup before the io loop */
546 >  modules_init();
547    read_conf_files(1);   /* cold start init conf files */
645  initServerMask();
646  me.id[0] = '\0';
548    init_uid();
648  init_auth();          /* Initialise the auth code */
649 #ifndef _WIN32
650  init_resolver();      /* Needs to be setup before the io loop */
651 #endif
549    initialize_server_capabs();   /* Set up default_server_capabs */
550 <  initialize_global_set_options();
551 <  init_channels();
550 >  initialize_global_set_options();  /* Has to be called after read_conf_files() */
551 >  channel_init();
552 >  read_links_file();
553 >  motd_init();
554 >  user_usermodes_init();
555 > #ifdef HAVE_LIBGEOIP
556 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
557 > #endif
558  
559 <  if (ServerInfo.name == NULL)
559 >  if (EmptyString(ConfigServerInfo.sid))
560    {
561 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
561 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
562      exit(EXIT_FAILURE);
563    }
564 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
564 >
565 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
566 >
567 >  if (EmptyString(ConfigServerInfo.name))
568 >  {
569 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
570 >    exit(EXIT_FAILURE);
571 >  }
572 >
573 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
574  
575    /* serverinfo{} description must exist.  If not, error out.*/
576 <  if (ServerInfo.description == NULL)
576 >  if (EmptyString(ConfigServerInfo.description))
577    {
578 <    ilog(L_CRIT,
667 <      "ERROR: No server description specified in serverinfo block.");
578 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
579      exit(EXIT_FAILURE);
580    }
670  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
581  
582 <  me.from    = &me;
582 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
583 >
584 >  me.from = &me;
585    me.servptr = &me;
586 +  me.connection->lasttime = CurrentTime;
587 +  me.connection->since = CurrentTime;
588 +  me.connection->firsttime = CurrentTime;
589  
590    SetMe(&me);
591    make_server(&me);
592  
593 <  me.lasttime = me.since = me.firsttime = CurrentTime;
593 >  hash_add_id(&me);
594    hash_add_client(&me);
680  
681  /* add ourselves to global_serv_list */
682  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
595  
596 <  check_class();
596 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
597  
598 < #ifndef STATIC_MODULES
599 <  if (chdir(MODPATH))
600 <  {
601 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
602 <    exit(EXIT_FAILURE);
691 <  }
598 >  load_kline_database();
599 >  load_dline_database();
600 >  load_gline_database();
601 >  load_xline_database();
602 >  load_resv_database();
603  
604    load_all_modules(1);
605    load_conf_modules();
606    load_core_modules(1);
696  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
697  chdir(ConfigFileEntry.dpath);
698 #else
699  load_all_modules(1);
700 #endif
701  /*
702   * assemble_umode_buffer() has to be called after
703   * reading conf/loading modules.
704   */
705  assemble_umode_buffer();
607  
608    write_pidfile(pidFileName);
609  
610 <  ilog(L_NOTICE, "Server Ready");
610 >  ilog(LOG_TYPE_IRCD, "Server Ready");
611  
612 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
613 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
612 >  event_addish(&event_cleanup_glines, NULL);
613 >  event_addish(&event_cleanup_tklines, NULL);
614  
615    /* We want try_connections to be called as soon as possible now! -- adrian */
616    /* No, 'cause after a restart it would cause all sorts of nick collides */
617 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
717 <
718 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
617 >  event_addish(&event_try_connections, NULL);
618  
619    /* Setup the timeout check. I'll shift it later :)  -- adrian */
620 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
620 >  event_add(&event_comm_checktimeouts, NULL);
621 >
622 >  event_addish(&event_save_all_databases, NULL);
623  
624    if (ConfigServerHide.links_delay > 0)
625 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
625 >  {
626 >    event_write_links_file.when = ConfigServerHide.links_delay;
627 >    event_addish(&event_write_links_file, NULL);
628 >  }
629    else
630      ConfigServerHide.links_disabled = 1;
631  
632    if (splitmode)
633 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
633 >    event_addish(&splitmode_event, NULL);
634  
635    io_loop();
636 <  return(0);
636 >  return 0;
637   }

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)