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.3/src/ircd.c (file contents), Revision 1115 by michael, Tue Dec 21 14:42:54 2010 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 1718 by michael, Thu Dec 27 19:03:00 2012 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"
35   #include "irc_string.h"
37 #include "sprintf_irc.h"
36   #include "ircd_signal.h"
37   #include "s_gline.h"
38   #include "motd.h"
39 < #include "ircd_handler.h"
42 < #include "msg.h"         /* msgtab */
39 > #include "conf.h"
40   #include "hostmask.h"
41   #include "numeric.h"
42   #include "packet.h"
# Line 49 | Line 46
46   #include "rng_mt.h"
47   #include "s_auth.h"
48   #include "s_bsd.h"
49 < #include "s_conf.h"
53 < #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"
62 #include "balloc.h"
59   #include "motd.h"
60   #include "supported.h"
61   #include "watch.h"
62 <
63 < /* Try and find the correct name to use with getrlimit() for setting the max.
68 < * number of files allowed to be open by this process.
69 < */
62 > #include "conf_db.h"
63 > #include "conf_class.h"
64  
65   /* /quote set variables */
66   struct SetOptions GlobalSetOptions;
# Line 77 | Line 71 | struct config_file_entry ConfigFileEntry
71   struct server_info ServerInfo;
72   /* admin info set from ircd.conf */
73   struct admin_info AdminInfo = { NULL, NULL, NULL };
74 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
74 > struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
75   struct ServerState_t server_state = { 0 };
76 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
76 > struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
77   struct ServerStatistics ServerStats;
78   struct timeval SystemTime;
79   struct Client me;             /* That's me */
# Line 89 | Line 83 | const char *logFileName = LPATH;
83   const char *pidFileName = PPATH;
84  
85   char **myargv;
92 char ircd_platform[PLATFORMLEN];
86  
87   int dorehash = 0;
88   int doremotd = 0;
# Line 98 | Line 91 | int doremotd = 0;
91   * initialize_server_capabs
92   */
93   int default_server_capabs = 0;
101
102 #ifdef HAVE_LIBCRYPTO
103 int bio_spare_fd = -1;
104 #endif
105
94   unsigned int splitmode;
95   unsigned int splitchecking;
96   unsigned int split_users;
# Line 154 | Line 142 | make_daemon(void)
142  
143   static int printVersion = 0;
144  
145 < struct lgetopt myopts[] = {
158 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
159 <   STRING, "File to use for dline.conf"},
145 > static struct lgetopt myopts[] = {
146    {"configfile", &ConfigFileEntry.configfile,
147     STRING, "File to use for ircd.conf"},
148 +  {"glinefile",  &ConfigFileEntry.glinefile,
149 +   STRING, "File to use for gline database"},
150    {"klinefile",  &ConfigFileEntry.klinefile,
151 <   STRING, "File to use for kline.conf"},
151 >   STRING, "File to use for kline database"},
152 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
153 >   STRING, "File to use for dline database"},
154    {"xlinefile",  &ConfigFileEntry.xlinefile,
155 <   STRING, "File to use for xline.conf"},
155 >   STRING, "File to use for xline database"},
156 >  {"resvfile",  &ConfigFileEntry.resvfile,
157 >   STRING, "File to use for resv database"},
158    {"logfile",    &logFileName,
159     STRING, "File to use for ircd.log"},
160    {"pidfile",    &pidFileName,
# Line 185 | Line 177 | set_time(void)
177  
178    if (gettimeofday(&newtime, NULL) == -1)
179    {
180 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
180 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
181           strerror(errno));
182 <    sendto_realops_flags(UMODE_ALL, L_ALL,
182 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
183                           "Clock Failure (%s), TS can be corrupted",
184                           strerror(errno));
185      restart("Clock Failure");
# Line 195 | Line 187 | set_time(void)
187  
188    if (newtime.tv_sec < CurrentTime)
189    {
190 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
191 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
190 >    snprintf(to_send, sizeof(to_send),
191 >             "System clock is running backwards - (%lu < %lu)",
192 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
193      report_error(L_ALL, to_send, me.name, 0);
194      set_back_events(CurrentTime - newtime.tv_sec);
195    }
# Line 255 | Line 248 | io_loop(void)
248      if (doremotd)
249      {
250        read_message_file(&ConfigFileEntry.motd);
251 <      sendto_realops_flags(UMODE_ALL, L_ALL,
251 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
252                             "Got signal SIGUSR1, reloading ircd motd file");
253        doremotd = 0;
254      }
# Line 297 | Line 290 | initialize_global_set_options(void)
290    }
291  
292    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
300  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
293    /* End of global set options */
294   }
295  
# Line 311 | Line 303 | static void
303   initialize_message_files(void)
304   {
305    init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
314  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
306    init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
307  
308    read_message_file(&ConfigFileEntry.motd);
318  read_message_file(&ConfigFileEntry.opermotd);
309    read_message_file(&ConfigFileEntry.linksfile);
310  
311    init_isupport();
# Line 331 | Line 321 | initialize_server_capabs(void)
321   {
322    add_capability("QS", CAP_QS, 1);
323    add_capability("EOB", CAP_EOB, 1);
324 <
335 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
336 <    add_capability("TS6", CAP_TS6, 0);
337 <
338 <  add_capability("ZIP", CAP_ZIP, 0);
324 >  add_capability("TS6", CAP_TS6, 0);
325    add_capability("CLUSTER", CAP_CLUSTER, 1);
326 +  add_capability("SVS", CAP_SVS, 1);
327   #ifdef HALFOPS
328    add_capability("HOPS", CAP_HOPS, 1);
329   #endif
# Line 351 | Line 338 | initialize_server_capabs(void)
338   static void
339   write_pidfile(const char *filename)
340   {
341 <  FBFILE *fb;
341 >  FILE *fb;
342  
343 <  if ((fb = fbopen(filename, "w")))
343 >  if ((fb = fopen(filename, "w")))
344    {
345      char buff[32];
346      unsigned int pid = (unsigned int)getpid();
360    size_t nbytes = ircsprintf(buff, "%u\n", pid);
347  
348 <    if ((fbputs(buff, fb, nbytes) == -1))
349 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
348 >    snprintf(buff, sizeof(buff), "%u\n", pid);
349 >
350 >    if ((fputs(buff, fb) == -1))
351 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
352             pid, filename, strerror(errno));
353  
354 <    fbclose(fb);
367 <    return;
354 >    fclose(fb);
355    }
356    else
357    {
358 <    ilog(L_ERROR, "Error opening pid file %s", filename);
358 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
359    }
360   }
361  
# Line 383 | Line 370 | write_pidfile(const char *filename)
370   static void
371   check_pidfile(const char *filename)
372   {
373 <  FBFILE *fb;
373 >  FILE *fb;
374    char buff[32];
375    pid_t pidfromfile;
376  
377    /* Don't do logging here, since we don't have log() initialised */
378 <  if ((fb = fbopen(filename, "r")))
378 >  if ((fb = fopen(filename, "r")))
379    {
380 <    if (fbgets(buff, 20, fb) == NULL)
380 >    if (fgets(buff, 20, fb) == NULL)
381      {
382        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
383         * strerror(errno));
# Line 408 | Line 395 | check_pidfile(const char *filename)
395        }
396      }
397  
398 <    fbclose(fb);
398 >    fclose(fb);
399    }
400    else if (errno != ENOENT)
401    {
# Line 455 | Line 442 | init_ssl(void)
442    {
443      const char *s;
444  
445 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
445 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
446              s = ERR_lib_error_string(ERR_get_error()));
447 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
447 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
448    }
449  
450 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
450 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
451    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
452    SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
453  
454 <  bio_spare_fd = save_spare_fd("SSL private key validation");
454 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
455 >  {
456 >    const char *s;
457 >
458 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
459 >            s = ERR_lib_error_string(ERR_get_error()));
460 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
461 >  }
462 >
463 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
464 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
465 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
466   #endif /* HAVE_LIBCRYPTO */
467   }
468  
# Line 479 | Line 477 | init_callbacks(void)
477   {
478    iorecv_cb = register_callback("iorecv", iorecv_default);
479    iosend_cb = register_callback("iosend", iosend_default);
482  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
483  iosendctrl_cb = register_callback("iosendctrl", NULL);
480   }
481  
482   int
# Line 504 | Line 500 | main(int argc, char *argv[])
500    /* It ain't random, but it ought to be a little harder to guess */
501    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
502  
507  memset(&me, 0, sizeof(me));
508  memset(&meLocalUser, 0, sizeof(meLocalUser));
503    me.localClient = &meLocalUser;
504    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
505                                                     of Client list */
512
513  memset(&ServerInfo, 0, sizeof(ServerInfo));
514  memset(&ServerStats, 0, sizeof(ServerStats));
515
506    /* Initialise the channel capability usage counts... */
507    init_chcap_usage_counts();
508  
509    ConfigFileEntry.dpath      = DPATH;
510 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
511 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
512 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
513 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
514 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
515 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
516 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
527 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
528 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
510 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
511 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
512 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
513 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
514 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
515 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
516 >
517    myargv = argv;
518    umask(077);                /* better safe than sorry --SRB */
519  
# Line 555 | Line 543 | main(int argc, char *argv[])
543  
544    setup_signals();
545  
558  get_ircd_platform(ircd_platform);
559
546    /* Init the event subsystem */
547    eventInit();
548    /* We need this to initialise the fd array before anything else */
549    fdlist_init();
550 <  init_log(logFileName);
550 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
551    check_can_use_v6();
552    init_comm();         /* This needs to be setup early ! -- adrian */
553    /* Check if there is pidfile and daemon already running */
554    check_pidfile(pidFileName);
555  
556 <  initBlockHeap();
556 >  mp_pool_init();
557    init_dlink_nodes();
558    init_callbacks();
559    initialize_message_files();
# Line 575 | Line 561 | main(int argc, char *argv[])
561    init_hash();
562    init_ip_hash_table();      /* client host ip hash table */
563    init_host_hash();          /* Host-hashtable. */
578  clear_tree_parse();
564    init_client();
565 <  init_class();
566 <  init_whowas();
565 >  class_init();
566 >  whowas_init();
567    watch_init();
568    init_auth();          /* Initialise the auth code */
569    init_resolver();      /* Needs to be setup before the io loop */
570 +  modules_init();
571    read_conf_files(1);   /* cold start init conf files */
572    init_uid();
573    initialize_server_capabs();   /* Set up default_server_capabs */
# Line 590 | Line 576 | main(int argc, char *argv[])
576  
577    if (EmptyString(ServerInfo.sid))
578    {
579 <    ilog(L_CRIT, "ERROR: No server id specified in serverinfo block.");
579 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
580      exit(EXIT_FAILURE);
581    }
582  
# Line 598 | Line 584 | main(int argc, char *argv[])
584  
585    if (EmptyString(ServerInfo.name))
586    {
587 <    ilog(L_CRIT, "ERROR: No server name specified in serverinfo block.");
587 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
588      exit(EXIT_FAILURE);
589    }
590  
# Line 607 | Line 593 | main(int argc, char *argv[])
593    /* serverinfo{} description must exist.  If not, error out.*/
594    if (EmptyString(ServerInfo.description))
595    {
596 <    ilog(L_CRIT, "ERROR: No server description specified in serverinfo block.");
596 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
597      exit(EXIT_FAILURE);
598    }
599  
600    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
601  
602 <  me.from    = &me;
603 <  me.servptr = &me;
602 >  me.from                   = &me;
603 >  me.servptr                = &me;
604 >  me.localClient->lasttime  = CurrentTime;
605 >  me.localClient->since     = CurrentTime;
606 >  me.localClient->firsttime = CurrentTime;
607  
608    SetMe(&me);
609    make_server(&me);
610  
622  me.lasttime = me.since = me.firsttime = CurrentTime;
623
611    hash_add_id(&me);
612    hash_add_client(&me);
613    
614    /* add ourselves to global_serv_list */
615    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
616  
617 < #ifndef STATIC_MODULES
617 >  load_kline_database();
618 >  load_dline_database();
619 >  load_gline_database();
620 >  load_xline_database();
621 >  load_resv_database();
622 >
623    if (chdir(MODPATH))
624    {
625 <    ilog(L_CRIT, "Could not load core modules. Terminating!");
625 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
626      exit(EXIT_FAILURE);
627    }
628  
# Line 644 | Line 636 | main(int argc, char *argv[])
636      perror("chdir");
637      exit(EXIT_FAILURE);
638    }
639 < #else
648 <  load_all_modules(1);
649 < #endif
639 >
640    /*
641     * assemble_umode_buffer() has to be called after
642     * reading conf/loading modules.
# Line 655 | Line 645 | main(int argc, char *argv[])
645  
646    write_pidfile(pidFileName);
647  
648 <  ilog(L_NOTICE, "Server Ready");
648 >  ilog(LOG_TYPE_IRCD, "Server Ready");
649  
650    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
651    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 664 | Line 654 | main(int argc, char *argv[])
654    /* No, 'cause after a restart it would cause all sorts of nick collides */
655    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
656  
667  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
668
657    /* Setup the timeout check. I'll shift it later :)  -- adrian */
658    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
659  
660 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
661 +
662    if (ConfigServerHide.links_delay > 0)
663      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
664    else

Diff Legend

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