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 998 by michael, Sun Aug 23 12:43:17 2009 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 4497 by michael, Sat Aug 16 18:20:57 2014 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-2014 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 18 | Line 17
17   *  along with this program; if not, write to the Free Software
18   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
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 "rng_mt.h"
46 < #include "s_auth.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
55 < #include "s_misc.h"
56 < #include "s_serv.h"      /* try_connections */
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  
75 /* configuration set from ircd.conf */
76 struct config_file_entry ConfigFileEntry;
77 /* server info set from ircd.conf */
78 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 ServerStatistics ServerStats;
67   struct timeval SystemTime;
68   struct Client me;             /* That's me */
# Line 90 | Line 72 | const char *logFileName = LPATH;
72   const char *pidFileName = PPATH;
73  
74   char **myargv;
93 char ircd_platform[PLATFORMLEN];
75  
76   int dorehash = 0;
77   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
78  
79   /* Set to zero because it should be initialized later using
80   * initialize_server_capabs
81   */
82 < int default_server_capabs = 0;
82 > unsigned int default_server_capabs;
83 > unsigned int splitmode;
84 > unsigned int splitchecking;
85 > unsigned int split_users;
86 > unsigned int split_servers;
87  
88 < #ifdef HAVE_LIBCRYPTO
89 < int bio_spare_fd = -1;
90 < #endif
88 > static struct event event_cleanup_glines =
89 > {
90 >  .name = "cleanup_glines",
91 >  .handler = cleanup_glines,
92 >  .when = CLEANUP_GLINES_TIME
93 > };
94  
95 < int splitmode;
96 < int splitchecking;
97 < int split_users;
98 < unsigned int split_servers;
95 > static struct event event_cleanup_tklines =
96 > {
97 >  .name = "cleanup_tklines",
98 >  .handler = cleanup_tklines,
99 >  .when = CLEANUP_TKLINES_TIME
100 > };
101  
102 < /* Do klines the same way hybrid-6 did them, i.e. at the
103 < * top of the next io_loop instead of in the same loop as
104 < * the klines are being applied.
105 < *
106 < * This should fix strange CPU starvation as very indirectly reported.
107 < * (Why do you people not email bug reports? WHY? WHY?)
119 < *
120 < * - Dianora
121 < */
102 > static struct event event_try_connections =
103 > {
104 >  .name = "try_connections",
105 >  .handler = try_connections,
106 >  .when = STARTUP_CONNECTIONS_TIME
107 > };
108  
109 < int rehashed_klines = 0;
109 > static struct event event_comm_checktimeouts =
110 > {
111 >  .name = "comm_checktimeouts",
112 >  .handler = comm_checktimeouts,
113 >  .when = 1
114 > };
115 >
116 > static struct event event_save_all_databases =
117 > {
118 >  .name = "save_all_databases",
119 >  .handler = save_all_databases,
120 >  .when = DATABASE_UPDATE_TIMEOUT
121 > };
122 >
123 > struct event event_write_links_file =
124 > {
125 >  .name = "write_links_file",
126 >  .handler = write_links_file,
127 > };
128  
129  
126 #ifndef _WIN32
130   /*
131   * print_startup - print startup information
132   */
133   static void
134   print_startup(int pid)
135   {
136 <  printf("ircd: version %s\n", ircd_version);
136 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
137    printf("ircd: pid %d\n", pid);
138    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
139 <         : "foreground", ConfigFileEntry.dpath);
139 >         : "foreground", ConfigGeneral.dpath);
140   }
141  
142   static void
# Line 154 | Line 157 | make_daemon(void)
157  
158    setsid();
159   }
157 #endif
160  
161   static int printVersion = 0;
162  
163 < struct lgetopt myopts[] = {
164 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
165 <   STRING, "File to use for dline.conf"},
164 <  {"configfile", &ConfigFileEntry.configfile,
163 > static struct lgetopt myopts[] =
164 > {
165 >  {"configfile", &ConfigGeneral.configfile,
166     STRING, "File to use for ircd.conf"},
167 <  {"klinefile",  &ConfigFileEntry.klinefile,
168 <   STRING, "File to use for kline.conf"},
169 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
170 <   STRING, "File to use for xline.conf"},
171 <  {"logfile",    &logFileName,
167 >  {"glinefile",  &ConfigGeneral.glinefile,
168 >   STRING, "File to use for gline database"},
169 >  {"klinefile",  &ConfigGeneral.klinefile,
170 >   STRING, "File to use for kline database"},
171 >  {"dlinefile",  &ConfigGeneral.dlinefile,
172 >   STRING, "File to use for dline database"},
173 >  {"xlinefile",  &ConfigGeneral.xlinefile,
174 >   STRING, "File to use for xline database"},
175 >  {"resvfile",  &ConfigGeneral.resvfile,
176 >   STRING, "File to use for resv database"},
177 >  {"logfile",    &logFileName,
178     STRING, "File to use for ircd.log"},
179    {"pidfile",    &pidFileName,
180     STRING, "File to use for process ID"},
181 <  {"foreground", &server_state.foreground,
181 >  {"foreground", &server_state.foreground,
182     YESNO, "Run in foreground (don't detach)"},
183 <  {"version",    &printVersion,
183 >  {"version",    &printVersion,
184     YESNO, "Print version and exit"},
185    {"help", NULL, USAGE, "Print this text"},
186    {NULL, NULL, STRING, NULL},
# Line 182 | Line 189 | struct lgetopt myopts[] = {
189   void
190   set_time(void)
191   {
192 <  static char to_send[200];
186 <  struct timeval newtime;
187 < #ifdef _WIN32
188 <  FILETIME ft;
189 <
190 <  GetSystemTimeAsFileTime(&ft);
191 <  if (ft.dwLowDateTime < 0xd53e8000)
192 <    ft.dwHighDateTime--;
193 <  ft.dwLowDateTime -= 0xd53e8000;
194 <  ft.dwHighDateTime -= 0x19db1de;
195 <
196 <  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
197 <  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
198 < #else
199 <  newtime.tv_sec  = 0;
200 <  newtime.tv_usec = 0;
192 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
193  
194    if (gettimeofday(&newtime, NULL) == -1)
195    {
196 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
196 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
197           strerror(errno));
198 <    sendto_realops_flags(UMODE_ALL, L_ALL,
198 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
199                           "Clock Failure (%s), TS can be corrupted",
200                           strerror(errno));
201 <    restart("Clock Failure");
201 >    server_die("Clock Failure", 1);
202    }
211 #endif
203  
204    if (newtime.tv_sec < CurrentTime)
205    {
206 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
207 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
208 <    report_error(L_ALL, to_send, me.name, 0);
206 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
207 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
208 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
209 >                         "System clock is running backwards - (%lu < %lu)",
210 >                         (unsigned long)newtime.tv_sec,
211 >                         (unsigned long)CurrentTime);
212      set_back_events(CurrentTime - newtime.tv_sec);
213    }
214  
# Line 225 | Line 219 | set_time(void)
219   static void
220   io_loop(void)
221   {
222 <  while (1 == 1)
222 >  while (1)
223    {
230    /*
231     * Maybe we want a flags word?
232     * ie. if (REHASHED_KLINES(global_flags))
233     * SET_REHASHED_KLINES(global_flags)
234     * CLEAR_REHASHED_KLINES(global_flags)
235     *
236     * - Dianora
237     */
238    if (rehashed_klines)
239    {
240      check_conf_klines();
241      rehashed_klines = 0;
242    }
243
224      if (listing_client_list.head)
225      {
226        dlink_node *ptr = NULL, *ptr_next = NULL;
227        DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
228 <      {
249 <        struct Client *client_p = ptr->data;
250 <        assert(client_p->localClient->list_task);
251 <        safe_list_channels(client_p, client_p->localClient->list_task, 0);
252 <      }
228 >        safe_list_channels(ptr->data, 0);
229      }
230  
231 <    /* Run pending events, then get the number of seconds to the next
232 <     * event
257 <     */
258 <    while (eventNextTime() <= CurrentTime)
259 <      eventRun();
231 >    /* Run pending events */
232 >    event_run();
233  
234      comm_select();
235      exit_aborted_clients();
236      free_exited_clients();
264    send_queued_all();
237  
238      /* Check to see whether we have to rehash the configuration .. */
239      if (dorehash)
# Line 269 | Line 241 | io_loop(void)
241        rehash(1);
242        dorehash = 0;
243      }
244 +
245      if (doremotd)
246      {
247 <      read_message_file(&ConfigFileEntry.motd);
248 <      sendto_realops_flags(UMODE_ALL, L_ALL,
249 <                           "Got signal SIGUSR1, reloading ircd motd file");
247 >      motd_recache();
248 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
249 >                           "Got signal SIGUSR1, reloading motd file(s)");
250        doremotd = 0;
251      }
252    }
# Line 283 | Line 256 | io_loop(void)
256   *
257   * inputs       - none
258   * output       - none
259 < * side effects - This sets all global set options needed
259 > * side effects - This sets all global set options needed
260   */
261   static void
262   initialize_global_set_options(void)
263   {
291  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
292
264    GlobalSetOptions.autoconn  = 1;
265    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
266    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
267  
268 <  if (ConfigFileEntry.default_floodcount)
269 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
268 >  if (ConfigGeneral.default_floodcount)
269 >    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
270    else
271      GlobalSetOptions.floodcount = 10;
272  
# Line 314 | Line 285 | initialize_global_set_options(void)
285    }
286  
287    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
317  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
318  /* End of global set options */
319 }
320
321 /* initialize_message_files()
322 *
323 * inputs       - none
324 * output       - none
325 * side effects - Set up all message files needed, motd etc.
326 */
327 static void
328 initialize_message_files(void)
329 {
330  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
331  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
332  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
333
334  read_message_file(&ConfigFileEntry.motd);
335  read_message_file(&ConfigFileEntry.opermotd);
336  read_message_file(&ConfigFileEntry.linksfile);
337
338  init_isupport();
288   }
289  
290   /* initialize_server_capabs()
# Line 348 | Line 297 | initialize_server_capabs(void)
297   {
298    add_capability("QS", CAP_QS, 1);
299    add_capability("EOB", CAP_EOB, 1);
300 <
352 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
353 <    add_capability("TS6", CAP_TS6, 0);
354 <
355 <  add_capability("ZIP", CAP_ZIP, 0);
300 >  add_capability("TS6", CAP_TS6, 0);
301    add_capability("CLUSTER", CAP_CLUSTER, 1);
302 < #ifdef HALFOPS
302 >  add_capability("SVS", CAP_SVS, 1);
303 >  add_capability("CHW", CAP_CHW, 1);
304    add_capability("HOPS", CAP_HOPS, 1);
359 #endif
305   }
306  
307   /* write_pidfile()
# Line 368 | Line 313 | initialize_server_capabs(void)
313   static void
314   write_pidfile(const char *filename)
315   {
316 <  FBFILE *fb;
316 >  FILE *fb;
317  
318 <  if ((fb = fbopen(filename, "w")))
318 >  if ((fb = fopen(filename, "w")))
319    {
320 <    char buff[32];
320 >    char buff[IRCD_BUFSIZE];
321      unsigned int pid = (unsigned int)getpid();
377    size_t nbytes = ircsprintf(buff, "%u\n", pid);
322  
323 <    if ((fbputs(buff, fb, nbytes) == -1))
324 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
323 >    snprintf(buff, sizeof(buff), "%u\n", pid);
324 >
325 >    if ((fputs(buff, fb) == -1))
326 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
327             pid, filename, strerror(errno));
328  
329 <    fbclose(fb);
384 <    return;
329 >    fclose(fb);
330    }
331    else
332    {
333 <    ilog(L_ERROR, "Error opening pid file %s", filename);
333 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
334    }
335   }
336  
# Line 400 | Line 345 | write_pidfile(const char *filename)
345   static void
346   check_pidfile(const char *filename)
347   {
348 < #ifndef _WIN32
349 <  FBFILE *fb;
405 <  char buff[32];
348 >  FILE *fb;
349 >  char buff[IRCD_BUFSIZE];
350    pid_t pidfromfile;
351  
352    /* Don't do logging here, since we don't have log() initialised */
353 <  if ((fb = fbopen(filename, "r")))
353 >  if ((fb = fopen(filename, "r")))
354    {
355 <    if (fbgets(buff, 20, fb) == NULL)
355 >    if (fgets(buff, 20, fb) == NULL)
356      {
357        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
358         * strerror(errno));
# Line 426 | Line 370 | check_pidfile(const char *filename)
370        }
371      }
372  
373 <    fbclose(fb);
373 >    fclose(fb);
374    }
375    else if (errno != ENOENT)
376    {
377      /* log(L_ERROR, "Error opening pid file %s", filename); */
378    }
435 #endif
379   }
380  
381   /* setup_corefile()
# Line 457 | Line 400 | setup_corefile(void)
400   #endif
401   }
402  
403 + #ifdef HAVE_LIBCRYPTO
404 + static int
405 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
406 + {
407 +  return 1;
408 + }
409 + #endif
410 +
411   /* init_ssl()
412   *
413   * inputs       - nothing
# Line 464 | Line 415 | setup_corefile(void)
415   * side effects - setups SSL context.
416   */
417   static void
418 < init_ssl(void)
418 > ssl_init(void)
419   {
420   #ifdef HAVE_LIBCRYPTO
421 +  const unsigned char session_id[] = "ircd-hybrid";
422 +
423    SSL_load_error_strings();
424    SSLeay_add_ssl_algorithms();
425  
426 <  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
426 >  if ((ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
427    {
428 <    const char *s;
428 >    const char *s = ERR_lib_error_string(ERR_get_error());
429  
430 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
431 <            s = ERR_lib_error_string(ERR_get_error()));
432 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
430 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
431 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
432 >    exit(EXIT_FAILURE);
433    }
434  
435 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
436 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
437 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
435 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
436 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE);
437 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
438 >                     always_accept_verify_cb);
439 >  SSL_CTX_set_session_id_context(ConfigServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
440  
441 <  bio_spare_fd = save_spare_fd("SSL private key validation");
442 < #endif /* HAVE_LIBCRYPTO */
443 < }
441 > #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
442 >  {
443 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
444  
445 < /* init_callbacks()
446 < *
447 < * inputs       - nothing
448 < * output       - nothing
449 < * side effects - setups standard hook points
450 < */
451 < static void
452 < init_callbacks(void)
453 < {
454 <  iorecv_cb = register_callback("iorecv", iorecv_default);
455 <  iosend_cb = register_callback("iosend", iosend_default);
456 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
457 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
445 >    if (key)
446 >    {
447 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
448 >      EC_KEY_free(key);
449 >    }
450 >  }
451 >
452 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
453 > #endif
454 >
455 >  if ((ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
456 >  {
457 >    const char *s = ERR_lib_error_string(ERR_get_error());
458 >
459 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
460 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
461 >    exit(EXIT_FAILURE);
462 >  }
463 >
464 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
465 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
466 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
467 >                     always_accept_verify_cb);
468 > #endif /* HAVE_LIBCRYPTO */
469   }
470  
471   int
472   main(int argc, char *argv[])
473   {
474 <  /* Check to see if the user is running
509 <   * us as root, which is a nono
510 <   */
511 < #ifndef _WIN32
474 >  /* Check to see if the user is running us as root, which is a nono */
475    if (geteuid() == 0)
476    {
477 <    fprintf(stderr, "Don't run ircd as root!!!\n");
477 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
478      return -1;
479    }
480  
481    /* Setup corefile size immediately after boot -kre */
482    setup_corefile();
520 #endif
483  
484    /* save server boot time right away, so getrusage works correctly */
485    set_time();
# Line 525 | Line 487 | main(int argc, char *argv[])
487    /* It ain't random, but it ought to be a little harder to guess */
488    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
489  
528  memset(&me, 0, sizeof(me));
529  memset(&meLocalUser, 0, sizeof(meLocalUser));
490    me.localClient = &meLocalUser;
491 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
491 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
492                                                     of Client list */
493 +  ConfigLog.use_logging = 1;
494 +  ConfigGeneral.dpath      = DPATH;
495 +  ConfigGeneral.spath      = SPATH;
496 +  ConfigGeneral.mpath      = MPATH;
497 +  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
498 +  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
499 +  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
500 +  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
501 +  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
502 +  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
503  
534  memset(&ServerInfo, 0, sizeof(ServerInfo));
535  memset(&ServerStats, 0, sizeof(ServerStats));
536
537  /* Initialise the channel capability usage counts... */
538  init_chcap_usage_counts();
539
540  ConfigFileEntry.dpath      = DPATH;
541  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
542  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
543  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
544  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
545  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
546  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
547  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
548  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
549  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
504    myargv = argv;
505    umask(077);                /* better safe than sorry --SRB */
506  
# Line 554 | Line 508 | main(int argc, char *argv[])
508  
509    if (printVersion)
510    {
511 <    printf("ircd: version %s\n", ircd_version);
511 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
512      exit(EXIT_SUCCESS);
513    }
514  
515 <  if (chdir(ConfigFileEntry.dpath))
515 >  if (chdir(ConfigGeneral.dpath))
516    {
517      perror("chdir");
518      exit(EXIT_FAILURE);
519    }
520  
521 <  init_ssl();
521 >  ssl_init();
522  
569 #ifndef _WIN32
523    if (!server_state.foreground)
524    {
525      make_daemon();
# Line 576 | Line 529 | main(int argc, char *argv[])
529      print_startup(getpid());
530  
531    setup_signals();
579 #endif
580
581  get_ircd_platform(ircd_platform);
532  
583  /* Init the event subsystem */
584  eventInit();
533    /* We need this to initialise the fd array before anything else */
534    fdlist_init();
535 <  init_log(logFileName);
536 <  check_can_use_v6();
537 <  init_comm();         /* This needs to be setup early ! -- adrian */
535 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
536 >
537 >  init_netio();         /* This needs to be setup early ! -- adrian */
538 >
539    /* Check if there is pidfile and daemon already running */
540    check_pidfile(pidFileName);
541  
542 < #ifndef NOBALLOC
594 <  initBlockHeap();
595 < #endif
542 >  mp_pool_init();
543    init_dlink_nodes();
544 <  init_callbacks();
598 <  initialize_message_files();
544 >  init_isupport();
545    dbuf_init();
546 <  init_hash();
547 <  init_ip_hash_table();      /* client host ip hash table */
546 >  hash_init();
547 >  ipcache_init();
548    init_host_hash();          /* Host-hashtable. */
549 <  clear_tree_parse();
550 <  init_client();
551 <  init_class();
606 <  init_whowas();
549 >  client_init();
550 >  class_init();
551 >  whowas_init();
552    watch_init();
553 <  init_auth();          /* Initialise the auth code */
553 >  auth_init();          /* Initialise the auth code */
554    init_resolver();      /* Needs to be setup before the io loop */
555 +  modules_init();
556    read_conf_files(1);   /* cold start init conf files */
611  me.id[0] = '\0';
557    init_uid();
558    initialize_server_capabs();   /* Set up default_server_capabs */
559    initialize_global_set_options();
560 <  init_channels();
560 >  channel_init();
561 >  read_links_file();
562 >  motd_init();
563 > #ifdef HAVE_LIBGEOIP
564 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
565 > #endif
566 >
567 >  if (EmptyString(ConfigServerInfo.sid))
568 >  {
569 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
570 >    exit(EXIT_FAILURE);
571 >  }
572 >
573 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
574  
575 <  if (ServerInfo.name == NULL)
575 >  if (EmptyString(ConfigServerInfo.name))
576    {
577 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
577 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
578      exit(EXIT_FAILURE);
579    }
580  
581 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
581 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
582  
583    /* serverinfo{} description must exist.  If not, error out.*/
584 <  if (ServerInfo.description == NULL)
584 >  if (EmptyString(ConfigServerInfo.description))
585    {
586 <    ilog(L_CRIT,
629 <      "ERROR: No server description specified in serverinfo block.");
586 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
587      exit(EXIT_FAILURE);
588    }
589  
590 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
590 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
591  
592 <  me.from    = &me;
593 <  me.servptr = &me;
592 >  me.from                   = &me;
593 >  me.servptr                = &me;
594 >  me.localClient->lasttime  = CurrentTime;
595 >  me.localClient->since     = CurrentTime;
596 >  me.localClient->firsttime = CurrentTime;
597  
598    SetMe(&me);
599    make_server(&me);
600  
601 <  me.lasttime = me.since = me.firsttime = CurrentTime;
601 >  hash_add_id(&me);
602    hash_add_client(&me);
643  
644  /* add ourselves to global_serv_list */
645  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
603  
604 <  check_class();
604 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
605 >
606 >  load_kline_database();
607 >  load_dline_database();
608 >  load_gline_database();
609 >  load_xline_database();
610 >  load_resv_database();
611  
649 #ifndef STATIC_MODULES
612    if (chdir(MODPATH))
613    {
614 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
614 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
615      exit(EXIT_FAILURE);
616    }
617  
618    load_all_modules(1);
619    load_conf_modules();
620    load_core_modules(1);
621 +
622    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
623 <  chdir(ConfigFileEntry.dpath);
624 < #else
625 <  load_all_modules(1);
626 < #endif
623 >  if (chdir(ConfigGeneral.dpath))
624 >  {
625 >    perror("chdir");
626 >    exit(EXIT_FAILURE);
627 >  }
628 >
629    /*
630     * assemble_umode_buffer() has to be called after
631     * reading conf/loading modules.
# Line 669 | Line 634 | main(int argc, char *argv[])
634  
635    write_pidfile(pidFileName);
636  
637 <  ilog(L_NOTICE, "Server Ready");
637 >  ilog(LOG_TYPE_IRCD, "Server Ready");
638  
639 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
640 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
639 >  event_addish(&event_cleanup_glines, NULL);
640 >  event_addish(&event_cleanup_tklines, NULL);
641  
642    /* We want try_connections to be called as soon as possible now! -- adrian */
643    /* No, 'cause after a restart it would cause all sorts of nick collides */
644 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
680 <
681 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
644 >  event_addish(&event_try_connections, NULL);
645  
646    /* Setup the timeout check. I'll shift it later :)  -- adrian */
647 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
647 >  event_add(&event_comm_checktimeouts, NULL);
648 >
649 >  event_addish(&event_save_all_databases, NULL);
650  
651    if (ConfigServerHide.links_delay > 0)
652 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
652 >  {
653 >    event_write_links_file.when = ConfigServerHide.links_delay;
654 >    event_addish(&event_write_links_file, NULL);
655 >  }
656    else
657      ConfigServerHide.links_disabled = 1;
658  
659    if (splitmode)
660 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
660 >    event_addish(&splitmode_event, NULL);
661  
662    io_loop();
663    return 0;

Diff Legend

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