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

Comparing:
ircd-hybrid/src/ircd.c (file contents), Revision 1155 by michael, Tue Aug 9 20:27:45 2011 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 2150 by michael, Fri May 31 18:39:43 2013 UTC

# Line 29 | Line 29
29   #include "channel.h"
30   #include "channel_mode.h"
31   #include "client.h"
32 #include "common.h"
32   #include "event.h"
33   #include "fdlist.h"
34   #include "hash.h"
# Line 37 | Line 36
36   #include "ircd_signal.h"
37   #include "s_gline.h"
38   #include "motd.h"
39 < #include "ircd_handler.h"
41 < #include "msg.h"         /* msgtab */
39 > #include "conf.h"
40   #include "hostmask.h"
41   #include "numeric.h"
42   #include "packet.h"
# Line 48 | Line 46
46   #include "rng_mt.h"
47   #include "s_auth.h"
48   #include "s_bsd.h"
49 < #include "s_conf.h"
52 < #include "s_log.h"
49 > #include "log.h"
50   #include "s_misc.h"
51   #include "s_serv.h"      /* try_connections */
52   #include "send.h"
53   #include "whowas.h"
54   #include "modules.h"
55   #include "memory.h"
56 + #include "mempool.h"
57   #include "hook.h"
58   #include "ircd_getopt.h"
59 < #include "balloc.h"
62 < #include "motd.h"
59 > #include "message.h"
60   #include "supported.h"
61   #include "watch.h"
62 + #include "conf_db.h"
63 + #include "conf_class.h"
64  
66 /* Try and find the correct name to use with getrlimit() for setting the max.
67 * number of files allowed to be open by this process.
68 */
65  
66 + #ifdef HAVE_LIBGEOIP
67 + GeoIP *geoip_ctx;
68 + #endif
69   /* /quote set variables */
70   struct SetOptions GlobalSetOptions;
71  
# Line 78 | Line 77 | struct server_info ServerInfo;
77   struct admin_info AdminInfo = { NULL, NULL, NULL };
78   struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
79   struct ServerState_t server_state = { 0 };
80 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
80 > struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
81   struct ServerStatistics ServerStats;
82   struct timeval SystemTime;
83   struct Client me;             /* That's me */
# Line 88 | Line 87 | const char *logFileName = LPATH;
87   const char *pidFileName = PPATH;
88  
89   char **myargv;
91 char ircd_platform[PLATFORMLEN];
90  
91   int dorehash = 0;
92   int doremotd = 0;
# Line 97 | Line 95 | int doremotd = 0;
95   * initialize_server_capabs
96   */
97   int default_server_capabs = 0;
100
101 #ifdef HAVE_LIBCRYPTO
102 int bio_spare_fd = -1;
103 #endif
104
98   unsigned int splitmode;
99   unsigned int splitchecking;
100   unsigned int split_users;
# Line 153 | Line 146 | make_daemon(void)
146  
147   static int printVersion = 0;
148  
149 < struct lgetopt myopts[] = {
157 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
158 <   STRING, "File to use for dline.conf"},
149 > static struct lgetopt myopts[] = {
150    {"configfile", &ConfigFileEntry.configfile,
151     STRING, "File to use for ircd.conf"},
152 +  {"glinefile",  &ConfigFileEntry.glinefile,
153 +   STRING, "File to use for gline database"},
154    {"klinefile",  &ConfigFileEntry.klinefile,
155 <   STRING, "File to use for kline.conf"},
155 >   STRING, "File to use for kline database"},
156 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
157 >   STRING, "File to use for dline database"},
158    {"xlinefile",  &ConfigFileEntry.xlinefile,
159 <   STRING, "File to use for xline.conf"},
159 >   STRING, "File to use for xline database"},
160 >  {"resvfile",  &ConfigFileEntry.resvfile,
161 >   STRING, "File to use for resv database"},
162    {"logfile",    &logFileName,
163     STRING, "File to use for ircd.log"},
164    {"pidfile",    &pidFileName,
# Line 184 | Line 181 | set_time(void)
181  
182    if (gettimeofday(&newtime, NULL) == -1)
183    {
184 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
184 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
185           strerror(errno));
186 <    sendto_realops_flags(UMODE_ALL, L_ALL,
186 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
187                           "Clock Failure (%s), TS can be corrupted",
188                           strerror(errno));
189      restart("Clock Failure");
# Line 254 | Line 251 | io_loop(void)
251      }
252      if (doremotd)
253      {
254 <      read_message_file(&ConfigFileEntry.motd);
255 <      sendto_realops_flags(UMODE_ALL, L_ALL,
256 <                           "Got signal SIGUSR1, reloading ircd motd file");
254 >      motd_recache();
255 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
256 >                           "Got signal SIGUSR1, reloading motd files");
257        doremotd = 0;
258      }
259    }
# Line 297 | Line 294 | initialize_global_set_options(void)
294    }
295  
296    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
300  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
297    /* End of global set options */
298   }
299  
# Line 310 | Line 306 | initialize_global_set_options(void)
306   static void
307   initialize_message_files(void)
308   {
313  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
314  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
309    init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
310  
317  read_message_file(&ConfigFileEntry.motd);
318  read_message_file(&ConfigFileEntry.opermotd);
311    read_message_file(&ConfigFileEntry.linksfile);
312  
313    init_isupport();
# Line 332 | Line 324 | initialize_server_capabs(void)
324    add_capability("QS", CAP_QS, 1);
325    add_capability("EOB", CAP_EOB, 1);
326    add_capability("TS6", CAP_TS6, 0);
335  add_capability("ZIP", CAP_ZIP, 0);
327    add_capability("CLUSTER", CAP_CLUSTER, 1);
328 +  add_capability("SVS", CAP_SVS, 1);
329   #ifdef HALFOPS
330    add_capability("HOPS", CAP_HOPS, 1);
331   #endif
# Line 348 | Line 340 | initialize_server_capabs(void)
340   static void
341   write_pidfile(const char *filename)
342   {
343 <  FBFILE *fb;
343 >  FILE *fb;
344  
345 <  if ((fb = fbopen(filename, "w")))
345 >  if ((fb = fopen(filename, "w")))
346    {
347      char buff[32];
348      unsigned int pid = (unsigned int)getpid();
357    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
349  
350 <    if ((fbputs(buff, fb, nbytes) == -1))
351 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
350 >    snprintf(buff, sizeof(buff), "%u\n", pid);
351 >
352 >    if ((fputs(buff, fb) == -1))
353 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
354             pid, filename, strerror(errno));
355  
356 <    fbclose(fb);
364 <    return;
356 >    fclose(fb);
357    }
358    else
359    {
360 <    ilog(L_ERROR, "Error opening pid file %s", filename);
360 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
361    }
362   }
363  
# Line 380 | Line 372 | write_pidfile(const char *filename)
372   static void
373   check_pidfile(const char *filename)
374   {
375 <  FBFILE *fb;
375 >  FILE *fb;
376    char buff[32];
377    pid_t pidfromfile;
378  
379    /* Don't do logging here, since we don't have log() initialised */
380 <  if ((fb = fbopen(filename, "r")))
380 >  if ((fb = fopen(filename, "r")))
381    {
382 <    if (fbgets(buff, 20, fb) == NULL)
382 >    if (fgets(buff, 20, fb) == NULL)
383      {
384        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
385         * strerror(errno));
# Line 405 | Line 397 | check_pidfile(const char *filename)
397        }
398      }
399  
400 <    fbclose(fb);
400 >    fclose(fb);
401    }
402    else if (errno != ENOENT)
403    {
# Line 442 | Line 434 | setup_corefile(void)
434   * side effects - setups SSL context.
435   */
436   static void
437 < init_ssl(void)
437 > ssl_init(void)
438   {
439   #ifdef HAVE_LIBCRYPTO
440    SSL_load_error_strings();
# Line 452 | Line 444 | init_ssl(void)
444    {
445      const char *s;
446  
447 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
447 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
448              s = ERR_lib_error_string(ERR_get_error()));
449 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
449 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
450    }
451  
452 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
452 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
453    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
454    SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
455  
456 <  bio_spare_fd = save_spare_fd("SSL private key validation");
457 < #endif /* HAVE_LIBCRYPTO */
458 < }
456 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
457 >  {
458 >    const char *s;
459  
460 < /* init_callbacks()
461 < *
462 < * inputs       - nothing
463 < * output       - nothing
464 < * side effects - setups standard hook points
465 < */
466 < static void
467 < init_callbacks(void)
468 < {
477 <  iorecv_cb = register_callback("iorecv", iorecv_default);
478 <  iosend_cb = register_callback("iosend", iosend_default);
479 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
480 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
460 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
461 >            s = ERR_lib_error_string(ERR_get_error()));
462 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
463 >  }
464 >
465 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
466 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
467 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
468 > #endif /* HAVE_LIBCRYPTO */
469   }
470  
471   int
# Line 508 | Line 496 | main(int argc, char *argv[])
496    init_chcap_usage_counts();
497  
498    ConfigFileEntry.dpath      = DPATH;
499 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
500 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
501 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
502 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
503 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
504 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
505 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
518 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
519 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
499 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
500 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
501 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
502 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
503 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
504 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
505 >
506    myargv = argv;
507    umask(077);                /* better safe than sorry --SRB */
508  
# Line 534 | Line 520 | main(int argc, char *argv[])
520      exit(EXIT_FAILURE);
521    }
522  
523 <  init_ssl();
523 >  ssl_init();
524  
525    if (!server_state.foreground)
526    {
# Line 546 | Line 532 | main(int argc, char *argv[])
532  
533    setup_signals();
534  
549  get_ircd_platform(ircd_platform);
550
535    /* Init the event subsystem */
536    eventInit();
537    /* We need this to initialise the fd array before anything else */
538    fdlist_init();
539 <  init_log(logFileName);
539 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
540    check_can_use_v6();
541    init_comm();         /* This needs to be setup early ! -- adrian */
542    /* Check if there is pidfile and daemon already running */
543    check_pidfile(pidFileName);
544  
545 <  initBlockHeap();
545 >  mp_pool_init();
546    init_dlink_nodes();
563  init_callbacks();
547    initialize_message_files();
548    dbuf_init();
549 <  init_hash();
549 >  hash_init();
550    init_ip_hash_table();      /* client host ip hash table */
551    init_host_hash();          /* Host-hashtable. */
552 <  clear_tree_parse();
553 <  init_client();
554 <  init_class();
572 <  init_whowas();
552 >  client_init();
553 >  class_init();
554 >  whowas_init();
555    watch_init();
556 <  init_auth();          /* Initialise the auth code */
556 >  auth_init();          /* Initialise the auth code */
557    init_resolver();      /* Needs to be setup before the io loop */
558 +  modules_init();
559    read_conf_files(1);   /* cold start init conf files */
560    init_uid();
561    initialize_server_capabs();   /* Set up default_server_capabs */
562    initialize_global_set_options();
563 <  init_channels();
563 >  channel_init();
564 >  motd_init();
565 > #ifdef HAVE_LIBGEOIP
566 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
567 > #endif
568  
569    if (EmptyString(ServerInfo.sid))
570    {
571 <    ilog(L_CRIT, "ERROR: No server id specified in serverinfo block.");
571 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
572      exit(EXIT_FAILURE);
573    }
574  
# Line 589 | Line 576 | main(int argc, char *argv[])
576  
577    if (EmptyString(ServerInfo.name))
578    {
579 <    ilog(L_CRIT, "ERROR: No server name specified in serverinfo block.");
579 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
580      exit(EXIT_FAILURE);
581    }
582  
# Line 598 | Line 585 | main(int argc, char *argv[])
585    /* serverinfo{} description must exist.  If not, error out.*/
586    if (EmptyString(ServerInfo.description))
587    {
588 <    ilog(L_CRIT, "ERROR: No server description specified in serverinfo block.");
588 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
589      exit(EXIT_FAILURE);
590    }
591  
592    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
593  
594 <  me.from     = &me;
595 <  me.servptr  = &me;
596 <  me.lasttime = me.since = me.firsttime = CurrentTime;
594 >  me.from                   = &me;
595 >  me.servptr                = &me;
596 >  me.localClient->lasttime  = CurrentTime;
597 >  me.localClient->since     = CurrentTime;
598 >  me.localClient->firsttime = CurrentTime;
599  
600    SetMe(&me);
601    make_server(&me);
# Line 617 | Line 606 | main(int argc, char *argv[])
606    /* add ourselves to global_serv_list */
607    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
608  
609 +  load_kline_database();
610 +  load_dline_database();
611 +  load_gline_database();
612 +  load_xline_database();
613 +  load_resv_database();
614 +
615    if (chdir(MODPATH))
616    {
617 <    ilog(L_CRIT, "Could not load core modules. Terminating!");
617 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
618      exit(EXIT_FAILURE);
619    }
620  
# Line 642 | Line 637 | main(int argc, char *argv[])
637  
638    write_pidfile(pidFileName);
639  
640 <  ilog(L_NOTICE, "Server Ready");
640 >  ilog(LOG_TYPE_IRCD, "Server Ready");
641  
642    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
643    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 651 | Line 646 | main(int argc, char *argv[])
646    /* No, 'cause after a restart it would cause all sorts of nick collides */
647    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
648  
654  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
655
649    /* Setup the timeout check. I'll shift it later :)  -- adrian */
650    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
651  
652 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
653 +
654    if (ConfigServerHide.links_delay > 0)
655      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
656    else

Diff Legend

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