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-8/src/ircd.c (file contents), Revision 1309 by michael, Sun Mar 25 11:24:18 2012 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 2632 by michael, Sun Dec 8 18:33:48 2013 UTC

# Line 36 | Line 36
36   #include "ircd_signal.h"
37   #include "s_gline.h"
38   #include "motd.h"
39 + #include "conf.h"
40   #include "hostmask.h"
41   #include "numeric.h"
42   #include "packet.h"
# Line 45 | Line 46
46   #include "rng_mt.h"
47   #include "s_auth.h"
48   #include "s_bsd.h"
48 #include "conf.h"
49   #include "log.h"
50   #include "s_misc.h"
51   #include "s_serv.h"      /* try_connections */
# Line 53 | Line 53
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"
58 #include "balloc.h"
59 #include "motd.h"
59   #include "supported.h"
60   #include "watch.h"
61 + #include "conf_db.h"
62 + #include "conf_class.h"
63  
64  
65 + #ifdef HAVE_LIBGEOIP
66 + GeoIP *geoip_ctx;
67 + #endif
68   /* /quote set variables */
69   struct SetOptions GlobalSetOptions;
70  
# Line 72 | Line 76 | struct server_info ServerInfo;
76   struct admin_info AdminInfo = { NULL, NULL, NULL };
77   struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
78   struct ServerState_t server_state = { 0 };
79 < struct logging_entry ConfigLoggingEntry = { 1, 1 };
79 > struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
80   struct ServerStatistics ServerStats;
81   struct timeval SystemTime;
82   struct Client me;             /* That's me */
# Line 82 | Line 86 | const char *logFileName = LPATH;
86   const char *pidFileName = PPATH;
87  
88   char **myargv;
85 char ircd_platform[PLATFORMLEN];
89  
90   int dorehash = 0;
91   int doremotd = 0;
# Line 142 | Line 145 | make_daemon(void)
145  
146   static int printVersion = 0;
147  
148 < struct lgetopt myopts[] = {
146 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
147 <   STRING, "File to use for dline.conf"},
148 > static struct lgetopt myopts[] = {
149    {"configfile", &ConfigFileEntry.configfile,
150     STRING, "File to use for ircd.conf"},
151 +  {"glinefile",  &ConfigFileEntry.glinefile,
152 +   STRING, "File to use for gline database"},
153    {"klinefile",  &ConfigFileEntry.klinefile,
154 <   STRING, "File to use for kline.conf"},
154 >   STRING, "File to use for kline database"},
155 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
156 >   STRING, "File to use for dline database"},
157    {"xlinefile",  &ConfigFileEntry.xlinefile,
158 <   STRING, "File to use for xline.conf"},
158 >   STRING, "File to use for xline database"},
159 >  {"resvfile",  &ConfigFileEntry.resvfile,
160 >   STRING, "File to use for resv database"},
161    {"logfile",    &logFileName,
162     STRING, "File to use for ircd.log"},
163    {"pidfile",    &pidFileName,
# Line 175 | Line 182 | set_time(void)
182    {
183      ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
184           strerror(errno));
185 <    sendto_realops_flags(UMODE_ALL, L_ALL,
185 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
186                           "Clock Failure (%s), TS can be corrupted",
187                           strerror(errno));
188      restart("Clock Failure");
# Line 243 | Line 250 | io_loop(void)
250      }
251      if (doremotd)
252      {
253 <      read_message_file(&ConfigFileEntry.motd);
254 <      sendto_realops_flags(UMODE_ALL, L_ALL,
255 <                           "Got signal SIGUSR1, reloading ircd motd file");
253 >      motd_recache();
254 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
255 >                           "Got signal SIGUSR1, reloading motd files");
256        doremotd = 0;
257      }
258    }
# Line 289 | Line 296 | initialize_global_set_options(void)
296    /* End of global set options */
297   }
298  
292 /* initialize_message_files()
293 *
294 * inputs       - none
295 * output       - none
296 * side effects - Set up all message files needed, motd etc.
297 */
298 static void
299 initialize_message_files(void)
300 {
301  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
302  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
303  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
304
305  read_message_file(&ConfigFileEntry.motd);
306  read_message_file(&ConfigFileEntry.opermotd);
307  read_message_file(&ConfigFileEntry.linksfile);
308
309  init_isupport();
310 }
311
299   /* initialize_server_capabs()
300   *
301   * inputs       - none
# Line 321 | Line 308 | initialize_server_capabs(void)
308    add_capability("EOB", CAP_EOB, 1);
309    add_capability("TS6", CAP_TS6, 0);
310    add_capability("CLUSTER", CAP_CLUSTER, 1);
311 + //  add_capability("FAKEHOST", CAP_FAKEHOST, 1);
312    add_capability("SVS", CAP_SVS, 1);
313   #ifdef HALFOPS
314    add_capability("HOPS", CAP_HOPS, 1);
# Line 336 | Line 324 | initialize_server_capabs(void)
324   static void
325   write_pidfile(const char *filename)
326   {
327 <  FBFILE *fb;
327 >  FILE *fb;
328  
329 <  if ((fb = fbopen(filename, "w")))
329 >  if ((fb = fopen(filename, "w")))
330    {
331      char buff[32];
332      unsigned int pid = (unsigned int)getpid();
345    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
333  
334 <    if ((fbputs(buff, fb, nbytes) == -1))
334 >    snprintf(buff, sizeof(buff), "%u\n", pid);
335 >
336 >    if ((fputs(buff, fb) == -1))
337        ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
338             pid, filename, strerror(errno));
339  
340 <    fbclose(fb);
352 <    return;
340 >    fclose(fb);
341    }
342    else
343    {
# Line 368 | Line 356 | write_pidfile(const char *filename)
356   static void
357   check_pidfile(const char *filename)
358   {
359 <  FBFILE *fb;
359 >  FILE *fb;
360    char buff[32];
361    pid_t pidfromfile;
362  
363    /* Don't do logging here, since we don't have log() initialised */
364 <  if ((fb = fbopen(filename, "r")))
364 >  if ((fb = fopen(filename, "r")))
365    {
366 <    if (fbgets(buff, 20, fb) == NULL)
366 >    if (fgets(buff, 20, fb) == NULL)
367      {
368        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
369         * strerror(errno));
# Line 393 | Line 381 | check_pidfile(const char *filename)
381        }
382      }
383  
384 <    fbclose(fb);
384 >    fclose(fb);
385    }
386    else if (errno != ENOENT)
387    {
# Line 423 | Line 411 | setup_corefile(void)
411   #endif
412   }
413  
414 + #ifdef HAVE_LIBCRYPTO
415 + static int
416 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
417 + {
418 +  return 1;
419 + }
420 + #endif
421 +
422   /* init_ssl()
423   *
424   * inputs       - nothing
# Line 430 | Line 426 | setup_corefile(void)
426   * side effects - setups SSL context.
427   */
428   static void
429 < init_ssl(void)
429 > ssl_init(void)
430   {
431   #ifdef HAVE_LIBCRYPTO
432    SSL_load_error_strings();
# Line 445 | Line 441 | init_ssl(void)
441      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
442    }
443  
444 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
444 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
445    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
446 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
446 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
447 >                     always_accept_verify_cb);
448  
449    if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
450    {
# Line 458 | Line 455 | init_ssl(void)
455      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
456    }
457  
458 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2);
458 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
459    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
460 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
460 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
461 >                     always_accept_verify_cb);
462   #endif /* HAVE_LIBCRYPTO */
463   }
464  
467 /* init_callbacks()
468 *
469 * inputs       - nothing
470 * output       - nothing
471 * side effects - setups standard hook points
472 */
473 static void
474 init_callbacks(void)
475 {
476  iorecv_cb = register_callback("iorecv", iorecv_default);
477  iosend_cb = register_callback("iosend", iosend_default);
478 }
479
465   int
466   main(int argc, char *argv[])
467   {
468 <  /* Check to see if the user is running
484 <   * us as root, which is a nono
485 <   */
468 >  /* Check to see if the user is running us as root, which is a nono */
469    if (geteuid() == 0)
470    {
471      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 499 | Line 482 | main(int argc, char *argv[])
482    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
483  
484    me.localClient = &meLocalUser;
485 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
485 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
486                                                     of Client list */
487    /* Initialise the channel capability usage counts... */
488    init_chcap_usage_counts();
489  
490    ConfigFileEntry.dpath      = DPATH;
491 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
492 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
493 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
494 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
495 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
496 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
497 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
515 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
516 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
491 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
492 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
493 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
494 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
495 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
496 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
497 >
498    myargv = argv;
499    umask(077);                /* better safe than sorry --SRB */
500  
# Line 531 | Line 512 | main(int argc, char *argv[])
512      exit(EXIT_FAILURE);
513    }
514  
515 <  init_ssl();
515 >  ssl_init();
516  
517    if (!server_state.foreground)
518    {
# Line 543 | Line 524 | main(int argc, char *argv[])
524  
525    setup_signals();
526  
546  get_ircd_platform(ircd_platform);
547
527    /* Init the event subsystem */
528    eventInit();
529 +
530    /* We need this to initialise the fd array before anything else */
531    fdlist_init();
532 <  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
532 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
533    check_can_use_v6();
534 <  init_comm();         /* This needs to be setup early ! -- adrian */
534 >  init_netio();         /* This needs to be setup early ! -- adrian */
535 >
536    /* Check if there is pidfile and daemon already running */
537    check_pidfile(pidFileName);
538  
539 <  initBlockHeap();
539 >  mp_pool_init();
540    init_dlink_nodes();
541 <  init_callbacks();
561 <  initialize_message_files();
541 >  init_isupport();
542    dbuf_init();
543 <  init_hash();
543 >  hash_init();
544    init_ip_hash_table();      /* client host ip hash table */
545    init_host_hash();          /* Host-hashtable. */
546 <  clear_tree_parse();
547 <  init_client();
548 <  init_class();
569 <  init_whowas();
546 >  client_init();
547 >  class_init();
548 >  whowas_init();
549    watch_init();
550 <  init_auth();          /* Initialise the auth code */
550 >  auth_init();          /* Initialise the auth code */
551    init_resolver();      /* Needs to be setup before the io loop */
552 +  modules_init();
553    read_conf_files(1);   /* cold start init conf files */
554    init_uid();
555    initialize_server_capabs();   /* Set up default_server_capabs */
556    initialize_global_set_options();
557 <  init_channels();
557 >  channel_init();
558 >  read_links_file();
559 >  motd_init();
560 > #ifdef HAVE_LIBGEOIP
561 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
562 > #endif
563  
564    if (EmptyString(ServerInfo.sid))
565    {
# Line 616 | Line 601 | main(int argc, char *argv[])
601    /* add ourselves to global_serv_list */
602    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
603  
604 +  load_kline_database();
605 +  load_dline_database();
606 +  load_gline_database();
607 +  load_xline_database();
608 +  load_resv_database();
609 +
610    if (chdir(MODPATH))
611    {
612      ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
# Line 653 | Line 644 | main(int argc, char *argv[])
644    /* Setup the timeout check. I'll shift it later :)  -- adrian */
645    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
646  
647 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
648 +
649    if (ConfigServerHide.links_delay > 0)
650      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
651    else

Diff Legend

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