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/trunk/src/ircd.c (file contents):
Revision 1592 by michael, Sat Oct 27 21:02:32 2012 UTC vs.
Revision 3267 by michael, Sat Apr 5 19:16:06 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"
# Line 36 | Line 38
38   #include "ircd_signal.h"
39   #include "s_gline.h"
40   #include "motd.h"
41 + #include "conf.h"
42   #include "hostmask.h"
43   #include "numeric.h"
44   #include "packet.h"
# Line 45 | Line 48
48   #include "rng_mt.h"
49   #include "s_auth.h"
50   #include "s_bsd.h"
48 #include "conf.h"
51   #include "log.h"
52   #include "s_misc.h"
53   #include "s_serv.h"      /* try_connections */
# Line 53 | Line 55
55   #include "whowas.h"
56   #include "modules.h"
57   #include "memory.h"
58 + #include "mempool.h"
59   #include "hook.h"
60   #include "ircd_getopt.h"
58 #include "balloc.h"
59 #include "motd.h"
61   #include "supported.h"
62   #include "watch.h"
63 + #include "conf_db.h"
64 + #include "conf_class.h"
65  
66  
67 + #ifdef HAVE_LIBGEOIP
68 + GeoIP *geoip_ctx;
69 + #endif
70 +
71   /* /quote set variables */
72   struct SetOptions GlobalSetOptions;
73 <
74 < /* configuration set from ircd.conf */
68 < struct config_file_entry ConfigFileEntry;
69 < /* server info set from ircd.conf */
70 < struct server_info ServerInfo;
71 < /* admin info set from ircd.conf */
72 < struct admin_info AdminInfo = { NULL, NULL, NULL };
73 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
74 < struct ServerState_t server_state = { 0 };
75 < struct logging_entry ConfigLoggingEntry = { .use_logging = 1 };
73 > struct Counter Count;
74 > struct ServerState_t server_state;
75   struct ServerStatistics ServerStats;
76   struct timeval SystemTime;
77   struct Client me;             /* That's me */
# Line 114 | Line 113 | int rehashed_klines = 0;
113   static void
114   print_startup(int pid)
115   {
116 <  printf("ircd: version %s\n", ircd_version);
116 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
117    printf("ircd: pid %d\n", pid);
118    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
119           : "foreground", ConfigFileEntry.dpath);
# Line 141 | Line 140 | make_daemon(void)
140  
141   static int printVersion = 0;
142  
143 < static struct lgetopt myopts[] = {
144 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
145 <   STRING, "File to use for dline.conf"},
147 <  {"configfile", &ConfigFileEntry.configfile,
143 > static struct lgetopt myopts[] =
144 > {
145 >  {"configfile", &ConfigFileEntry.configfile,
146     STRING, "File to use for ircd.conf"},
147 <  {"klinefile",  &ConfigFileEntry.klinefile,
148 <   STRING, "File to use for kline.conf"},
149 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
150 <   STRING, "File to use for xline.conf"},
151 <  {"logfile",    &logFileName,
147 >  {"glinefile",  &ConfigFileEntry.glinefile,
148 >   STRING, "File to use for gline database"},
149 >  {"klinefile",  &ConfigFileEntry.klinefile,
150 >   STRING, "File to use for kline database"},
151 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
152 >   STRING, "File to use for dline database"},
153 >  {"xlinefile",  &ConfigFileEntry.xlinefile,
154 >   STRING, "File to use for xline database"},
155 >  {"resvfile",  &ConfigFileEntry.resvfile,
156 >   STRING, "File to use for resv database"},
157 >  {"logfile",    &logFileName,
158     STRING, "File to use for ircd.log"},
159    {"pidfile",    &pidFileName,
160     STRING, "File to use for process ID"},
161 <  {"foreground", &server_state.foreground,
161 >  {"foreground", &server_state.foreground,
162     YESNO, "Run in foreground (don't detach)"},
163 <  {"version",    &printVersion,
163 >  {"version",    &printVersion,
164     YESNO, "Print version and exit"},
165    {"help", NULL, USAGE, "Print this text"},
166    {NULL, NULL, STRING, NULL},
# Line 165 | Line 169 | static struct lgetopt myopts[] = {
169   void
170   set_time(void)
171   {
172 <  static char to_send[200];
169 <  struct timeval newtime;
170 <  newtime.tv_sec  = 0;
171 <  newtime.tv_usec = 0;
172 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
173  
174    if (gettimeofday(&newtime, NULL) == -1)
175    {
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");
181 >    server_die("Clock Failure", 1);
182    }
183  
184    if (newtime.tv_sec < CurrentTime)
185    {
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);
186 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
187 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
189 >                         "System clock is running backwards - (%lu < %lu)",
190 >                         (unsigned long)newtime.tv_sec,
191 >                         (unsigned long)CurrentTime);
192      set_back_events(CurrentTime - newtime.tv_sec);
193    }
194  
# Line 196 | Line 199 | set_time(void)
199   static void
200   io_loop(void)
201   {
202 <  while (1 == 1)
202 >  while (1)
203    {
204      /*
205       * Maybe we want a flags word?
206 <     * ie. if (REHASHED_KLINES(global_flags))
206 >     * ie. if (REHASHED_KLINES(global_flags))
207       * SET_REHASHED_KLINES(global_flags)
208       * CLEAR_REHASHED_KLINES(global_flags)
209       *
# Line 232 | Line 235 | io_loop(void)
235      comm_select();
236      exit_aborted_clients();
237      free_exited_clients();
235    send_queued_all();
238  
239      /* Check to see whether we have to rehash the configuration .. */
240      if (dorehash)
# Line 240 | Line 242 | io_loop(void)
242        rehash(1);
243        dorehash = 0;
244      }
245 +
246      if (doremotd)
247      {
248 <      read_message_file(&ConfigFileEntry.motd);
249 <      sendto_realops_flags(UMODE_ALL, L_ALL,
250 <                           "Got signal SIGUSR1, reloading ircd motd file");
248 >      motd_recache();
249 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
250 >                           "Got signal SIGUSR1, reloading motd file(s)");
251        doremotd = 0;
252      }
253    }
# Line 254 | Line 257 | io_loop(void)
257   *
258   * inputs       - none
259   * output       - none
260 < * side effects - This sets all global set options needed
260 > * side effects - This sets all global set options needed
261   */
262   static void
263   initialize_global_set_options(void)
# Line 288 | Line 291 | initialize_global_set_options(void)
291    /* End of global set options */
292   }
293  
291 /* initialize_message_files()
292 *
293 * inputs       - none
294 * output       - none
295 * side effects - Set up all message files needed, motd etc.
296 */
297 static void
298 initialize_message_files(void)
299 {
300  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
301  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
302
303  read_message_file(&ConfigFileEntry.motd);
304  read_message_file(&ConfigFileEntry.linksfile);
305
306  init_isupport();
307 }
308
294   /* initialize_server_capabs()
295   *
296   * inputs       - none
# Line 319 | Line 304 | initialize_server_capabs(void)
304    add_capability("TS6", CAP_TS6, 0);
305    add_capability("CLUSTER", CAP_CLUSTER, 1);
306    add_capability("SVS", CAP_SVS, 1);
307 +  add_capability("CHW", CAP_CHW, 1);
308   #ifdef HALFOPS
309    add_capability("HOPS", CAP_HOPS, 1);
310   #endif
# Line 337 | Line 323 | write_pidfile(const char *filename)
323  
324    if ((fb = fopen(filename, "w")))
325    {
326 <    char buff[32];
326 >    char buff[IRCD_BUFSIZE];
327      unsigned int pid = (unsigned int)getpid();
328  
329      snprintf(buff, sizeof(buff), "%u\n", pid);
# Line 366 | Line 352 | static void
352   check_pidfile(const char *filename)
353   {
354    FILE *fb;
355 <  char buff[32];
355 >  char buff[IRCD_BUFSIZE];
356    pid_t pidfromfile;
357  
358    /* Don't do logging here, since we don't have log() initialised */
# Line 420 | Line 406 | setup_corefile(void)
406   #endif
407   }
408  
409 + #ifdef HAVE_LIBCRYPTO
410 + static int
411 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
412 + {
413 +  return 1;
414 + }
415 + #endif
416 +
417   /* init_ssl()
418   *
419   * inputs       - nothing
# Line 427 | Line 421 | setup_corefile(void)
421   * side effects - setups SSL context.
422   */
423   static void
424 < init_ssl(void)
424 > ssl_init(void)
425   {
426   #ifdef HAVE_LIBCRYPTO
427 +  const unsigned char session_id[] = "ircd-hybrid";
428 +
429    SSL_load_error_strings();
430    SSLeay_add_ssl_algorithms();
431  
# Line 444 | Line 440 | init_ssl(void)
440  
441    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
442    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
443 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
443 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
444 >                     always_accept_verify_cb);
445 >  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
446  
447    if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
448    {
# Line 457 | Line 455 | init_ssl(void)
455  
456    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
457    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
458 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
458 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
459 >                     always_accept_verify_cb);
460   #endif /* HAVE_LIBCRYPTO */
461   }
462  
464 /* init_callbacks()
465 *
466 * inputs       - nothing
467 * output       - nothing
468 * side effects - setups standard hook points
469 */
470 static void
471 init_callbacks(void)
472 {
473  iorecv_cb = register_callback("iorecv", iorecv_default);
474  iosend_cb = register_callback("iosend", iosend_default);
475 }
476
463   int
464   main(int argc, char *argv[])
465   {
466 <  /* Check to see if the user is running
481 <   * us as root, which is a nono
482 <   */
466 >  /* Check to see if the user is running us as root, which is a nono */
467    if (geteuid() == 0)
468    {
469      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 496 | Line 480 | main(int argc, char *argv[])
480    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
481  
482    me.localClient = &meLocalUser;
483 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
483 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
484                                                     of Client list */
501  /* Initialise the channel capability usage counts... */
502  init_chcap_usage_counts();
503
485    ConfigFileEntry.dpath      = DPATH;
486 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
487 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
488 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
489 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
490 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
491 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
486 >  ConfigFileEntry.spath      = SPATH;
487 >  ConfigFileEntry.mpath      = MPATH;
488 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
489 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
490 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
491 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
492 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
493 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
494 >
495    myargv = argv;
496    umask(077);                /* better safe than sorry --SRB */
497  
# Line 515 | Line 499 | main(int argc, char *argv[])
499  
500    if (printVersion)
501    {
502 <    printf("ircd: version %s\n", ircd_version);
502 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
503      exit(EXIT_SUCCESS);
504    }
505  
# Line 525 | Line 509 | main(int argc, char *argv[])
509      exit(EXIT_FAILURE);
510    }
511  
512 <  init_ssl();
512 >  ssl_init();
513  
514    if (!server_state.foreground)
515    {
# Line 539 | Line 523 | main(int argc, char *argv[])
523  
524    /* Init the event subsystem */
525    eventInit();
526 +
527    /* We need this to initialise the fd array before anything else */
528    fdlist_init();
529 <  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
529 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
530    check_can_use_v6();
531 <  init_comm();         /* This needs to be setup early ! -- adrian */
531 >  init_netio();         /* This needs to be setup early ! -- adrian */
532 >
533    /* Check if there is pidfile and daemon already running */
534    check_pidfile(pidFileName);
535  
536 <  initBlockHeap();
536 >  mp_pool_init();
537    init_dlink_nodes();
538 <  init_callbacks();
553 <  initialize_message_files();
538 >  init_isupport();
539    dbuf_init();
540 <  init_hash();
540 >  hash_init();
541    init_ip_hash_table();      /* client host ip hash table */
542    init_host_hash();          /* Host-hashtable. */
543 <  init_client();
544 <  init_class();
543 >  client_init();
544 >  class_init();
545    whowas_init();
546    watch_init();
547 <  init_auth();          /* Initialise the auth code */
547 >  auth_init();          /* Initialise the auth code */
548    init_resolver();      /* Needs to be setup before the io loop */
549    modules_init();
550    read_conf_files(1);   /* cold start init conf files */
551    init_uid();
552    initialize_server_capabs();   /* Set up default_server_capabs */
553    initialize_global_set_options();
554 <  init_channels();
554 >  channel_init();
555 >  read_links_file();
556 >  motd_init();
557 > #ifdef HAVE_LIBGEOIP
558 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
559 > #endif
560  
561    if (EmptyString(ServerInfo.sid))
562    {
# Line 604 | Line 594 | main(int argc, char *argv[])
594  
595    hash_add_id(&me);
596    hash_add_client(&me);
597 <  
597 >
598    /* add ourselves to global_serv_list */
599    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
600  
601 +  load_kline_database();
602 +  load_dline_database();
603 +  load_gline_database();
604 +  load_xline_database();
605 +  load_resv_database();
606 +
607    if (chdir(MODPATH))
608    {
609      ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
# Line 645 | Line 641 | main(int argc, char *argv[])
641    /* Setup the timeout check. I'll shift it later :)  -- adrian */
642    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
643  
644 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
645 +
646    if (ConfigServerHide.links_delay > 0)
647      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
648    else

Diff Legend

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