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 3274 by michael, Sun Apr 6 12:22:23 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 27 | Line 29
29   #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
33   #include "event.h"
34   #include "fdlist.h"
# Line 36 | Line 37
37   #include "ircd_signal.h"
38   #include "s_gline.h"
39   #include "motd.h"
40 + #include "conf.h"
41   #include "hostmask.h"
40 #include "numeric.h"
41 #include "packet.h"
42   #include "parse.h"
43   #include "irc_res.h"
44   #include "restart.h"
45   #include "rng_mt.h"
46   #include "s_auth.h"
47   #include "s_bsd.h"
48 #include "conf.h"
48   #include "log.h"
50 #include "s_misc.h"
49   #include "s_serv.h"      /* try_connections */
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
58 #include "balloc.h"
59 #include "motd.h"
56   #include "supported.h"
57   #include "watch.h"
58 + #include "conf_db.h"
59 + #include "conf_class.h"
60  
61  
62 + #ifdef HAVE_LIBGEOIP
63 + GeoIP *geoip_ctx;
64 + #endif
65 +
66   /* /quote set variables */
67   struct SetOptions GlobalSetOptions;
68 <
69 < /* 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 = { 1, 1 };
68 > struct Counter Count;
69 > struct ServerState_t server_state;
70   struct ServerStatistics ServerStats;
71   struct timeval SystemTime;
72   struct Client me;             /* That's me */
# Line 82 | Line 76 | const char *logFileName = LPATH;
76   const char *pidFileName = PPATH;
77  
78   char **myargv;
85 char ircd_platform[PLATFORMLEN];
79  
80   int dorehash = 0;
81   int doremotd = 0;
# Line 115 | Line 108 | int rehashed_klines = 0;
108   static void
109   print_startup(int pid)
110   {
111 <  printf("ircd: version %s\n", ircd_version);
111 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
112    printf("ircd: pid %d\n", pid);
113    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
114           : "foreground", ConfigFileEntry.dpath);
# Line 142 | Line 135 | make_daemon(void)
135  
136   static int printVersion = 0;
137  
138 < struct lgetopt myopts[] = {
139 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
140 <   STRING, "File to use for dline.conf"},
148 <  {"configfile", &ConfigFileEntry.configfile,
138 > static struct lgetopt myopts[] =
139 > {
140 >  {"configfile", &ConfigFileEntry.configfile,
141     STRING, "File to use for ircd.conf"},
142 <  {"klinefile",  &ConfigFileEntry.klinefile,
143 <   STRING, "File to use for kline.conf"},
144 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
145 <   STRING, "File to use for xline.conf"},
146 <  {"logfile",    &logFileName,
142 >  {"glinefile",  &ConfigFileEntry.glinefile,
143 >   STRING, "File to use for gline database"},
144 >  {"klinefile",  &ConfigFileEntry.klinefile,
145 >   STRING, "File to use for kline database"},
146 >  {"dlinefile",  &ConfigFileEntry.dlinefile,
147 >   STRING, "File to use for dline database"},
148 >  {"xlinefile",  &ConfigFileEntry.xlinefile,
149 >   STRING, "File to use for xline database"},
150 >  {"resvfile",  &ConfigFileEntry.resvfile,
151 >   STRING, "File to use for resv database"},
152 >  {"logfile",    &logFileName,
153     STRING, "File to use for ircd.log"},
154    {"pidfile",    &pidFileName,
155     STRING, "File to use for process ID"},
156 <  {"foreground", &server_state.foreground,
156 >  {"foreground", &server_state.foreground,
157     YESNO, "Run in foreground (don't detach)"},
158 <  {"version",    &printVersion,
158 >  {"version",    &printVersion,
159     YESNO, "Print version and exit"},
160    {"help", NULL, USAGE, "Print this text"},
161    {NULL, NULL, STRING, NULL},
# Line 166 | Line 164 | struct lgetopt myopts[] = {
164   void
165   set_time(void)
166   {
167 <  static char to_send[200];
170 <  struct timeval newtime;
171 <  newtime.tv_sec  = 0;
172 <  newtime.tv_usec = 0;
167 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
168  
169    if (gettimeofday(&newtime, NULL) == -1)
170    {
171      ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
172           strerror(errno));
173 <    sendto_realops_flags(UMODE_ALL, L_ALL,
173 >    sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
174                           "Clock Failure (%s), TS can be corrupted",
175                           strerror(errno));
176 <    restart("Clock Failure");
176 >    server_die("Clock Failure", 1);
177    }
178  
179    if (newtime.tv_sec < CurrentTime)
180    {
181 <    snprintf(to_send, sizeof(to_send),
182 <             "System clock is running backwards - (%lu < %lu)",
183 <             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
184 <    report_error(L_ALL, to_send, me.name, 0);
181 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%lu < %lu)",
182 >         (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
183 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
184 >                         "System clock is running backwards - (%lu < %lu)",
185 >                         (unsigned long)newtime.tv_sec,
186 >                         (unsigned long)CurrentTime);
187      set_back_events(CurrentTime - newtime.tv_sec);
188    }
189  
# Line 197 | Line 194 | set_time(void)
194   static void
195   io_loop(void)
196   {
197 <  while (1 == 1)
197 >  while (1)
198    {
199      /*
200       * Maybe we want a flags word?
201 <     * ie. if (REHASHED_KLINES(global_flags))
201 >     * ie. if (REHASHED_KLINES(global_flags))
202       * SET_REHASHED_KLINES(global_flags)
203       * CLEAR_REHASHED_KLINES(global_flags)
204       *
# Line 233 | Line 230 | io_loop(void)
230      comm_select();
231      exit_aborted_clients();
232      free_exited_clients();
236    send_queued_all();
233  
234      /* Check to see whether we have to rehash the configuration .. */
235      if (dorehash)
# Line 241 | Line 237 | io_loop(void)
237        rehash(1);
238        dorehash = 0;
239      }
240 +
241      if (doremotd)
242      {
243 <      read_message_file(&ConfigFileEntry.motd);
244 <      sendto_realops_flags(UMODE_ALL, L_ALL,
245 <                           "Got signal SIGUSR1, reloading ircd motd file");
243 >      motd_recache();
244 >      sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE,
245 >                           "Got signal SIGUSR1, reloading motd file(s)");
246        doremotd = 0;
247      }
248    }
# Line 255 | Line 252 | io_loop(void)
252   *
253   * inputs       - none
254   * output       - none
255 < * side effects - This sets all global set options needed
255 > * side effects - This sets all global set options needed
256   */
257   static void
258   initialize_global_set_options(void)
# Line 289 | Line 286 | initialize_global_set_options(void)
286    /* End of global set options */
287   }
288  
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
289   /* initialize_server_capabs()
290   *
291   * inputs       - none
# Line 322 | Line 299 | initialize_server_capabs(void)
299    add_capability("TS6", CAP_TS6, 0);
300    add_capability("CLUSTER", CAP_CLUSTER, 1);
301    add_capability("SVS", CAP_SVS, 1);
302 +  add_capability("CHW", CAP_CHW, 1);
303   #ifdef HALFOPS
304    add_capability("HOPS", CAP_HOPS, 1);
305   #endif
# Line 336 | Line 314 | initialize_server_capabs(void)
314   static void
315   write_pidfile(const char *filename)
316   {
317 <  FBFILE *fb;
317 >  FILE *fb;
318  
319 <  if ((fb = fbopen(filename, "w")))
319 >  if ((fb = fopen(filename, "w")))
320    {
321 <    char buff[32];
321 >    char buff[IRCD_BUFSIZE];
322      unsigned int pid = (unsigned int)getpid();
345    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
323  
324 <    if ((fbputs(buff, fb, nbytes) == -1))
324 >    snprintf(buff, sizeof(buff), "%u\n", pid);
325 >
326 >    if ((fputs(buff, fb) == -1))
327        ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
328             pid, filename, strerror(errno));
329  
330 <    fbclose(fb);
352 <    return;
330 >    fclose(fb);
331    }
332    else
333    {
# Line 368 | Line 346 | write_pidfile(const char *filename)
346   static void
347   check_pidfile(const char *filename)
348   {
349 <  FBFILE *fb;
350 <  char buff[32];
349 >  FILE *fb;
350 >  char buff[IRCD_BUFSIZE];
351    pid_t pidfromfile;
352  
353    /* Don't do logging here, since we don't have log() initialised */
354 <  if ((fb = fbopen(filename, "r")))
354 >  if ((fb = fopen(filename, "r")))
355    {
356 <    if (fbgets(buff, 20, fb) == NULL)
356 >    if (fgets(buff, 20, fb) == NULL)
357      {
358        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
359         * strerror(errno));
# Line 393 | Line 371 | check_pidfile(const char *filename)
371        }
372      }
373  
374 <    fbclose(fb);
374 >    fclose(fb);
375    }
376    else if (errno != ENOENT)
377    {
# Line 423 | Line 401 | setup_corefile(void)
401   #endif
402   }
403  
404 + #ifdef HAVE_LIBCRYPTO
405 + static int
406 + always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
407 + {
408 +  return 1;
409 + }
410 + #endif
411 +
412   /* init_ssl()
413   *
414   * inputs       - nothing
# Line 430 | Line 416 | setup_corefile(void)
416   * side effects - setups SSL context.
417   */
418   static void
419 < init_ssl(void)
419 > ssl_init(void)
420   {
421   #ifdef HAVE_LIBCRYPTO
422 +  const unsigned char session_id[] = "ircd-hybrid";
423 +
424    SSL_load_error_strings();
425    SSLeay_add_ssl_algorithms();
426  
# Line 445 | Line 433 | init_ssl(void)
433      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
434    }
435  
436 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
436 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
437    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
438 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
438 >  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
439 >                     always_accept_verify_cb);
440 >  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
441  
442    if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
443    {
# Line 458 | Line 448 | init_ssl(void)
448      ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
449    }
450  
451 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2);
451 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
452    SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
453 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
453 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
454 >                     always_accept_verify_cb);
455   #endif /* HAVE_LIBCRYPTO */
456   }
457  
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
458   int
459   main(int argc, char *argv[])
460   {
461 <  /* Check to see if the user is running
484 <   * us as root, which is a nono
485 <   */
461 >  /* Check to see if the user is running us as root, which is a nono */
462    if (geteuid() == 0)
463    {
464      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 499 | Line 475 | main(int argc, char *argv[])
475    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
476  
477    me.localClient = &meLocalUser;
478 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
478 >  dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
479                                                     of Client list */
504  /* Initialise the channel capability usage counts... */
505  init_chcap_usage_counts();
506
480    ConfigFileEntry.dpath      = DPATH;
481 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
482 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
483 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
484 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
485 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
486 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
487 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
488 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
489 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
481 >  ConfigFileEntry.spath      = SPATH;
482 >  ConfigFileEntry.mpath      = MPATH;
483 >  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
484 >  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
485 >  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
486 >  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
487 >  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
488 >  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
489 >
490    myargv = argv;
491    umask(077);                /* better safe than sorry --SRB */
492  
# Line 521 | Line 494 | main(int argc, char *argv[])
494  
495    if (printVersion)
496    {
497 <    printf("ircd: version %s\n", ircd_version);
497 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
498      exit(EXIT_SUCCESS);
499    }
500  
# Line 531 | Line 504 | main(int argc, char *argv[])
504      exit(EXIT_FAILURE);
505    }
506  
507 <  init_ssl();
507 >  ssl_init();
508  
509    if (!server_state.foreground)
510    {
# Line 543 | Line 516 | main(int argc, char *argv[])
516  
517    setup_signals();
518  
546  get_ircd_platform(ircd_platform);
547
519    /* Init the event subsystem */
520    eventInit();
521 +
522    /* We need this to initialise the fd array before anything else */
523    fdlist_init();
524 <  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
524 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
525    check_can_use_v6();
526 <  init_comm();         /* This needs to be setup early ! -- adrian */
526 >  init_netio();         /* This needs to be setup early ! -- adrian */
527 >
528    /* Check if there is pidfile and daemon already running */
529    check_pidfile(pidFileName);
530  
531 <  initBlockHeap();
531 >  mp_pool_init();
532    init_dlink_nodes();
533 <  init_callbacks();
561 <  initialize_message_files();
533 >  init_isupport();
534    dbuf_init();
535 <  init_hash();
535 >  hash_init();
536    init_ip_hash_table();      /* client host ip hash table */
537    init_host_hash();          /* Host-hashtable. */
538 <  clear_tree_parse();
539 <  init_client();
540 <  init_class();
569 <  init_whowas();
538 >  client_init();
539 >  class_init();
540 >  whowas_init();
541    watch_init();
542 <  init_auth();          /* Initialise the auth code */
542 >  auth_init();          /* Initialise the auth code */
543    init_resolver();      /* Needs to be setup before the io loop */
544 +  modules_init();
545    read_conf_files(1);   /* cold start init conf files */
546    init_uid();
547    initialize_server_capabs();   /* Set up default_server_capabs */
548    initialize_global_set_options();
549 <  init_channels();
549 >  channel_init();
550 >  read_links_file();
551 >  motd_init();
552 > #ifdef HAVE_LIBGEOIP
553 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
554 > #endif
555  
556    if (EmptyString(ServerInfo.sid))
557    {
# Line 612 | Line 589 | main(int argc, char *argv[])
589  
590    hash_add_id(&me);
591    hash_add_client(&me);
592 <  
592 >
593    /* add ourselves to global_serv_list */
594    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
595  
596 +  load_kline_database();
597 +  load_dline_database();
598 +  load_gline_database();
599 +  load_xline_database();
600 +  load_resv_database();
601 +
602    if (chdir(MODPATH))
603    {
604      ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
# Line 653 | Line 636 | main(int argc, char *argv[])
636    /* Setup the timeout check. I'll shift it later :)  -- adrian */
637    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
638  
639 +  eventAddIsh("save_all_databases", save_all_databases, NULL, DATABASE_UPDATE_TIMEOUT);
640 +
641    if (ConfigServerHide.links_delay > 0)
642      eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
643    else

Diff Legend

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