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 950 by michael, Tue Jul 21 23:07:52 2009 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 1654 by michael, Fri Nov 16 19:39:37 2012 UTC

# Line 24 | Line 24
24  
25   #include "stdinc.h"
26   #include "s_user.h"
27 < #include "tools.h"
27 > #include "list.h"
28   #include "ircd.h"
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"
39 #include "list.h"
37   #include "s_gline.h"
38   #include "motd.h"
39 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
39 > #include "conf.h"
40   #include "hostmask.h"
41   #include "numeric.h"
42   #include "packet.h"
43   #include "parse.h"
44   #include "irc_res.h"
45   #include "restart.h"
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 */
80   struct LocalUser meLocalUser; /* That's also part of me */
81  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
82   const char *logFileName = LPATH;
83   const char *pidFileName = PPATH;
84  
85   char **myargv;
93 char ircd_platform[PLATFORMLEN];
86  
87   int dorehash = 0;
88   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
89  
90   /* Set to zero because it should be initialized later using
91   * initialize_server_capabs
92   */
93   int default_server_capabs = 0;
94 <
95 < #ifdef HAVE_LIBCRYPTO
96 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
94 > unsigned int splitmode;
95 > unsigned int splitchecking;
96 > unsigned int split_users;
97   unsigned int split_servers;
98  
99   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 123 | Line 109 | unsigned int split_servers;
109   int rehashed_klines = 0;
110  
111  
126 #ifndef _WIN32
112   /*
113   * print_startup - print startup information
114   */
# Line 154 | Line 139 | make_daemon(void)
139  
140    setsid();
141   }
157 #endif
142  
143   static int printVersion = 0;
144  
145 < struct lgetopt myopts[] = {
145 > static struct lgetopt myopts[] = {
146    {"dlinefile",  &ConfigFileEntry.dlinefile,
147     STRING, "File to use for dline.conf"},
148    {"configfile", &ConfigFileEntry.configfile,
# Line 184 | Line 168 | set_time(void)
168   {
169    static char to_send[200];
170    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
171    newtime.tv_sec  = 0;
172    newtime.tv_usec = 0;
173  
174    if (gettimeofday(&newtime, NULL) == -1)
175    {
176 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
176 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
177           strerror(errno));
178 <    sendto_realops_flags(UMODE_ALL, L_ALL,
178 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
179                           "Clock Failure (%s), TS can be corrupted",
180                           strerror(errno));
181      restart("Clock Failure");
182    }
211 #endif
183  
184    if (newtime.tv_sec < CurrentTime)
185    {
186 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
187 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
186 >    snprintf(to_send, sizeof(to_send),
187 >             "System clock is running backwards - (%lu < %lu)",
188 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
189      report_error(L_ALL, to_send, me.name, 0);
190      set_back_events(CurrentTime - newtime.tv_sec);
191    }
# Line 272 | Line 244 | io_loop(void)
244      if (doremotd)
245      {
246        read_message_file(&ConfigFileEntry.motd);
247 <      sendto_realops_flags(UMODE_ALL, L_ALL,
247 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
248                             "Got signal SIGUSR1, reloading ircd motd file");
249        doremotd = 0;
250      }
# Line 314 | Line 286 | initialize_global_set_options(void)
286    }
287  
288    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
317  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
289    /* End of global set options */
290   }
291  
# Line 328 | Line 299 | static void
299   initialize_message_files(void)
300   {
301    init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
331  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
302    init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
303  
304    read_message_file(&ConfigFileEntry.motd);
335  read_message_file(&ConfigFileEntry.opermotd);
305    read_message_file(&ConfigFileEntry.linksfile);
306  
307    init_isupport();
# Line 348 | Line 317 | initialize_server_capabs(void)
317   {
318    add_capability("QS", CAP_QS, 1);
319    add_capability("EOB", CAP_EOB, 1);
320 <
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);
320 >  add_capability("TS6", CAP_TS6, 0);
321    add_capability("CLUSTER", CAP_CLUSTER, 1);
322 +  add_capability("SVS", CAP_SVS, 1);
323   #ifdef HALFOPS
324    add_capability("HOPS", CAP_HOPS, 1);
325   #endif
# Line 368 | Line 334 | initialize_server_capabs(void)
334   static void
335   write_pidfile(const char *filename)
336   {
337 <  FBFILE *fb;
337 >  FILE *fb;
338  
339 <  if ((fb = fbopen(filename, "w")))
339 >  if ((fb = fopen(filename, "w")))
340    {
341      char buff[32];
342      unsigned int pid = (unsigned int)getpid();
377    size_t nbytes = ircsprintf(buff, "%u\n", pid);
343  
344 <    if ((fbputs(buff, fb, nbytes) == -1))
345 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
344 >    snprintf(buff, sizeof(buff), "%u\n", pid);
345 >
346 >    if ((fputs(buff, fb) == -1))
347 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
348             pid, filename, strerror(errno));
349  
350 <    fbclose(fb);
384 <    return;
350 >    fclose(fb);
351    }
352    else
353    {
354 <    ilog(L_ERROR, "Error opening pid file %s", filename);
354 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
355    }
356   }
357  
# Line 400 | Line 366 | write_pidfile(const char *filename)
366   static void
367   check_pidfile(const char *filename)
368   {
369 < #ifndef _WIN32
404 <  FBFILE *fb;
369 >  FILE *fb;
370    char buff[32];
371    pid_t pidfromfile;
372  
373    /* Don't do logging here, since we don't have log() initialised */
374 <  if ((fb = fbopen(filename, "r")))
374 >  if ((fb = fopen(filename, "r")))
375    {
376 <    if (fbgets(buff, 20, fb) == NULL)
376 >    if (fgets(buff, 20, fb) == NULL)
377      {
378        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
379         * strerror(errno));
# Line 426 | Line 391 | check_pidfile(const char *filename)
391        }
392      }
393  
394 <    fbclose(fb);
394 >    fclose(fb);
395    }
396    else if (errno != ENOENT)
397    {
398      /* log(L_ERROR, "Error opening pid file %s", filename); */
399    }
435 #endif
400   }
401  
402   /* setup_corefile()
# Line 470 | Line 434 | init_ssl(void)
434    SSL_load_error_strings();
435    SSLeay_add_ssl_algorithms();
436  
437 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
474 <  if (!ServerInfo.ctx)
437 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
438    {
439      const char *s;
440  
441 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
441 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
442              s = ERR_lib_error_string(ERR_get_error()));
443 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
443 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
444    }
445  
446 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
447 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
448 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
446 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
447 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
448 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
449 >
450 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
451 >  {
452 >    const char *s;
453 >
454 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
455 >            s = ERR_lib_error_string(ERR_get_error()));
456 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
457 >  }
458  
459 <  bio_spare_fd = save_spare_fd("SSL private key validation");
459 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
460 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
461 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
462   #endif /* HAVE_LIBCRYPTO */
463   }
464  
# Line 499 | Line 473 | init_callbacks(void)
473   {
474    iorecv_cb = register_callback("iorecv", iorecv_default);
475    iosend_cb = register_callback("iosend", iosend_default);
502  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
503  iosendctrl_cb = register_callback("iosendctrl", NULL);
476   }
477  
478   int
# Line 509 | Line 481 | main(int argc, char *argv[])
481    /* Check to see if the user is running
482     * us as root, which is a nono
483     */
512 #ifndef _WIN32
484    if (geteuid() == 0)
485    {
486      fprintf(stderr, "Don't run ircd as root!!!\n");
487 <    return(-1);
487 >    return -1;
488    }
489  
490    /* Setup corefile size immediately after boot -kre */
491    setup_corefile();
521 #endif
492  
493    /* save server boot time right away, so getrusage works correctly */
494    set_time();
495  
496 <    /* It ain't random, but it ought to be a little harder to guess */
497 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
498 <  memset(&me, 0, sizeof(me));
529 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
496 >  /* It ain't random, but it ought to be a little harder to guess */
497 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
498 >
499    me.localClient = &meLocalUser;
500    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
501                                                     of Client list */
533
534  memset(&ServerInfo, 0, sizeof(ServerInfo));
535  memset(&ServerStats, 0, sizeof(ServerStats));
536
502    /* Initialise the channel capability usage counts... */
503    init_chcap_usage_counts();
504  
# Line 541 | Line 506 | main(int argc, char *argv[])
506    ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
507    ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
508    ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
544  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
545  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
509    ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
510 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
511 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
549 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
510 > //  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
511 > //  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
512    myargv = argv;
513    umask(077);                /* better safe than sorry --SRB */
514  
# Line 566 | Line 528 | main(int argc, char *argv[])
528  
529    init_ssl();
530  
569 #ifndef _WIN32
531    if (!server_state.foreground)
532    {
533      make_daemon();
# Line 576 | Line 537 | main(int argc, char *argv[])
537      print_startup(getpid());
538  
539    setup_signals();
579 #endif
580
581  get_ircd_platform(ircd_platform);
540  
541    /* Init the event subsystem */
542    eventInit();
543    /* We need this to initialise the fd array before anything else */
544    fdlist_init();
545 <  init_log(logFileName);
545 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
546    check_can_use_v6();
547    init_comm();         /* This needs to be setup early ! -- adrian */
548    /* Check if there is pidfile and daemon already running */
549    check_pidfile(pidFileName);
550  
551 < #ifndef NOBALLOC
594 <  initBlockHeap();
595 < #endif
551 >  mp_pool_init();
552    init_dlink_nodes();
553    init_callbacks();
554    initialize_message_files();
# Line 600 | Line 556 | main(int argc, char *argv[])
556    init_hash();
557    init_ip_hash_table();      /* client host ip hash table */
558    init_host_hash();          /* Host-hashtable. */
603  clear_tree_parse();
559    init_client();
560 <  init_class();
561 <  init_whowas();
560 >  class_init();
561 >  whowas_init();
562    watch_init();
608  read_conf_files(1);   /* cold start init conf files */
609  me.id[0] = '\0';
610  init_uid();
563    init_auth();          /* Initialise the auth code */
612 #ifndef _WIN32
564    init_resolver();      /* Needs to be setup before the io loop */
565 < #endif
565 >  modules_init();
566 >  read_conf_files(1);   /* cold start init conf files */
567 >  init_uid();
568    initialize_server_capabs();   /* Set up default_server_capabs */
569    initialize_global_set_options();
570    init_channels();
571  
572 <  if (ServerInfo.name == NULL)
572 >  if (EmptyString(ServerInfo.sid))
573 >  {
574 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
575 >    exit(EXIT_FAILURE);
576 >  }
577 >
578 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
579 >
580 >  if (EmptyString(ServerInfo.name))
581    {
582 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
582 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
583      exit(EXIT_FAILURE);
584    }
585  
586    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
587  
588    /* serverinfo{} description must exist.  If not, error out.*/
589 <  if (ServerInfo.description == NULL)
589 >  if (EmptyString(ServerInfo.description))
590    {
591 <    ilog(L_CRIT,
631 <      "ERROR: No server description specified in serverinfo block.");
591 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
592      exit(EXIT_FAILURE);
593    }
594  
595    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
596  
597 <  me.from    = &me;
598 <  me.servptr = &me;
597 >  me.from                   = &me;
598 >  me.servptr                = &me;
599 >  me.localClient->lasttime  = CurrentTime;
600 >  me.localClient->since     = CurrentTime;
601 >  me.localClient->firsttime = CurrentTime;
602  
603    SetMe(&me);
604    make_server(&me);
605  
606 <  me.lasttime = me.since = me.firsttime = CurrentTime;
606 >  hash_add_id(&me);
607    hash_add_client(&me);
608    
609    /* add ourselves to global_serv_list */
610    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
611  
612 <  check_class();
612 >  load_kline_database();
613 >  load_dline_database();
614 >  load_gline_database();
615 >  load_xline_database();
616 >  load_resv_database();
617  
651 #ifndef STATIC_MODULES
618    if (chdir(MODPATH))
619    {
620 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
620 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
621      exit(EXIT_FAILURE);
622    }
623  
624    load_all_modules(1);
625    load_conf_modules();
626    load_core_modules(1);
627 +
628    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
629 <  chdir(ConfigFileEntry.dpath);
630 < #else
631 <  load_all_modules(1);
632 < #endif
629 >  if (chdir(ConfigFileEntry.dpath))
630 >  {
631 >    perror("chdir");
632 >    exit(EXIT_FAILURE);
633 >  }
634 >
635    /*
636     * assemble_umode_buffer() has to be called after
637     * reading conf/loading modules.
# Line 671 | Line 640 | main(int argc, char *argv[])
640  
641    write_pidfile(pidFileName);
642  
643 <  ilog(L_NOTICE, "Server Ready");
643 >  ilog(LOG_TYPE_IRCD, "Server Ready");
644  
645    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
646    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 680 | Line 649 | main(int argc, char *argv[])
649    /* No, 'cause after a restart it would cause all sorts of nick collides */
650    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
651  
683  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
684
652    /* Setup the timeout check. I'll shift it later :)  -- adrian */
653    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
654  
655 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
656 +
657    if (ConfigServerHide.links_delay > 0)
658      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
659    else

Diff Legend

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