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/trunk/src/ircd.c (file contents):
Revision 4105 by michael, Mon Jun 30 15:39:47 2014 UTC vs.
Revision 5392 by michael, Tue Jan 20 13:40:41 2015 UTC

# Line 1 | Line 1
1   /*
2   *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (c) 1997-2014 ircd-hybrid development team
4 > *  Copyright (c) 1997-2015 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 15 | Line 15
15   *
16   *  You should have received a copy of the GNU General Public License
17   *  along with this program; if not, write to the Free Software
18 < *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
18 > *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19   *  USA
20   */
21  
# Line 56 | Line 56
56   #include "watch.h"
57   #include "conf_db.h"
58   #include "conf_class.h"
59 + #include "ipcache.h"
60  
61  
62   #ifdef HAVE_LIBGEOIP
63   GeoIP *geoip_ctx;
64   #endif
65  
65 /* /quote set variables */
66 struct SetOptions GlobalSetOptions;
67 struct Counter Count;
68 struct ServerState_t server_state;
69 struct ServerStatistics ServerStats;
66   struct timeval SystemTime;
67   struct Client me;             /* That's me */
68 < struct LocalUser meLocalUser; /* That's also part of me */
68 > struct Connection meConnection; /* That's also part of me */
69  
70   const char *logFileName = LPATH;
71   const char *pidFileName = PPATH;
# Line 129 | Line 125 | struct event event_write_links_file =
125    .handler = write_links_file,
126   };
127  
132 struct event event_check_splitmode =
133 {
134  .name = "check_splitmode",
135  .handler = check_splitmode,
136  .when = 60
137 };
128  
129   /*
130   * print_startup - print startup information
# Line 145 | Line 135 | print_startup(int pid)
135    printf("ircd: version %s(%s)\n", ircd_version, serno);
136    printf("ircd: pid %d\n", pid);
137    printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
138 <         : "foreground", ConfigFileEntry.dpath);
138 >         : "foreground", ConfigGeneral.dpath);
139   }
140  
141   static void
# Line 171 | Line 161 | static int printVersion = 0;
161  
162   static struct lgetopt myopts[] =
163   {
164 <  {"configfile", &ConfigFileEntry.configfile,
164 >  {"configfile", &ConfigGeneral.configfile,
165     STRING, "File to use for ircd.conf"},
166 <  {"glinefile",  &ConfigFileEntry.glinefile,
166 >  {"glinefile",  &ConfigGeneral.glinefile,
167     STRING, "File to use for gline database"},
168 <  {"klinefile",  &ConfigFileEntry.klinefile,
168 >  {"klinefile",  &ConfigGeneral.klinefile,
169     STRING, "File to use for kline database"},
170 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
170 >  {"dlinefile",  &ConfigGeneral.dlinefile,
171     STRING, "File to use for dline database"},
172 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
172 >  {"xlinefile",  &ConfigGeneral.xlinefile,
173     STRING, "File to use for xline database"},
174 <  {"resvfile",  &ConfigFileEntry.resvfile,
174 >  {"resvfile",  &ConfigGeneral.resvfile,
175     STRING, "File to use for resv database"},
176    {"logfile",    &logFileName,
177     STRING, "File to use for ircd.log"},
# Line 232 | Line 222 | io_loop(void)
222    {
223      if (listing_client_list.head)
224      {
225 <      dlink_node *ptr = NULL, *ptr_next = NULL;
226 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
227 <        safe_list_channels(ptr->data, 0);
225 >      dlink_node *node = NULL, *node_next = NULL;
226 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
227 >        safe_list_channels(node->data, 0);
228      }
229  
230      /* Run pending events */
# Line 247 | Line 237 | io_loop(void)
237      /* Check to see whether we have to rehash the configuration .. */
238      if (dorehash)
239      {
240 <      rehash(1);
240 >      conf_rehash(1);
241        dorehash = 0;
242      }
243  
# Line 270 | Line 260 | io_loop(void)
260   static void
261   initialize_global_set_options(void)
262   {
273  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
274
263    GlobalSetOptions.autoconn  = 1;
264    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
265    GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
266  
267 <  if (ConfigFileEntry.default_floodcount)
268 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
267 >  if (ConfigGeneral.default_floodcount)
268 >    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
269    else
270      GlobalSetOptions.floodcount = 10;
271  
# Line 296 | Line 284 | initialize_global_set_options(void)
284    }
285  
286    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
299  /* End of global set options */
287   }
288  
289   /* initialize_server_capabs()
# Line 334 | Line 321 | write_pidfile(const char *filename)
321  
322      snprintf(buff, sizeof(buff), "%u\n", pid);
323  
324 <    if ((fputs(buff, fb) == -1))
324 >    if (fputs(buff, fb) == -1)
325        ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
326             pid, filename, strerror(errno));
327  
# Line 342 | Line 329 | write_pidfile(const char *filename)
329    }
330    else
331    {
332 <    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
332 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s (%s)",
333 >         filename, strerror(errno));
334    }
335   }
336  
# Line 364 | Line 352 | check_pidfile(const char *filename)
352    /* Don't do logging here, since we don't have log() initialised */
353    if ((fb = fopen(filename, "r")))
354    {
355 <    if (fgets(buff, 20, fb) == NULL)
355 >    if (!fgets(buff, 20, fb))
356      {
357        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
358         * strerror(errno));
# Line 430 | Line 418 | static void
418   ssl_init(void)
419   {
420   #ifdef HAVE_LIBCRYPTO
433  const unsigned char session_id[] = "ircd-hybrid";
434
421    SSL_load_error_strings();
422    SSLeay_add_ssl_algorithms();
423  
424 <  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
424 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
425    {
426 <    const char *s;
426 >    const char *s = ERR_lib_error_string(ERR_get_error());
427  
428 <    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
429 <            s = ERR_lib_error_string(ERR_get_error()));
430 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
428 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
429 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
430 >    exit(EXIT_FAILURE);
431 >    return;  /* Not reached */
432    }
433  
434 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
435 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG);
436 <  SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
434 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
435 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
436 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
437                       always_accept_verify_cb);
438 <  SSL_CTX_set_session_id_context(ServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
438 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
439 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
440  
441 < #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
441 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
442    {
443      EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
444  
445      if (key)
446      {
447 <      SSL_CTX_set_tmp_ecdh(ServerInfo.server_ctx, key);
447 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
448        EC_KEY_free(key);
449      }
450    }
451  
452 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
452 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
453   #endif
454  
455 <  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
455 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
456    {
457 <    const char *s;
457 >    const char *s = ERR_lib_error_string(ERR_get_error());
458  
459 <    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
460 <            s = ERR_lib_error_string(ERR_get_error()));
461 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
459 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
460 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
461 >    exit(EXIT_FAILURE);
462 >    return;  /* Not reached */
463    }
464  
465 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
466 <  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG);
467 <  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
465 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
466 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
467 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
468                       always_accept_verify_cb);
469 +  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
470   #endif /* HAVE_LIBCRYPTO */
471   }
472  
# Line 484 | Line 474 | int
474   main(int argc, char *argv[])
475   {
476    /* Check to see if the user is running us as root, which is a nono */
477 <  if (geteuid() == 0)
477 >  if (!geteuid())
478    {
479      fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
480      return -1;
# Line 499 | Line 489 | main(int argc, char *argv[])
489    /* It ain't random, but it ought to be a little harder to guess */
490    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
491  
492 <  me.localClient = &meLocalUser;
492 >  me.connection = &meConnection;
493    dlinkAdd(&me, &me.node, &global_client_list);  /* Pointer to beginning
494                                                     of Client list */
495 <  ConfigLoggingEntry.use_logging = 1;
496 <  ConfigFileEntry.dpath      = DPATH;
497 <  ConfigFileEntry.spath      = SPATH;
498 <  ConfigFileEntry.mpath      = MPATH;
499 <  ConfigFileEntry.configfile = CPATH;    /* Server configuration file */
500 <  ConfigFileEntry.klinefile  = KPATH;    /* Server kline file         */
501 <  ConfigFileEntry.glinefile  = GPATH;    /* Server gline file         */
502 <  ConfigFileEntry.xlinefile  = XPATH;    /* Server xline file         */
503 <  ConfigFileEntry.dlinefile  = DLPATH;   /* dline file                */
504 <  ConfigFileEntry.resvfile   = RESVPATH; /* resv file                 */
495 >  ConfigLog.use_logging = 1;
496 >  ConfigGeneral.dpath      = DPATH;
497 >  ConfigGeneral.spath      = SPATH;
498 >  ConfigGeneral.mpath      = MPATH;
499 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
500 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
501 >  ConfigGeneral.glinefile  = GPATH;    /* Server gline file         */
502 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
503 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
504 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
505  
506    myargv = argv;
507    umask(077);                /* better safe than sorry --SRB */
# Line 524 | Line 514 | main(int argc, char *argv[])
514      exit(EXIT_SUCCESS);
515    }
516  
517 <  if (chdir(ConfigFileEntry.dpath))
517 >  if (chdir(ConfigGeneral.dpath))
518    {
519      perror("chdir");
520      exit(EXIT_FAILURE);
# Line 545 | Line 535 | main(int argc, char *argv[])
535    /* We need this to initialise the fd array before anything else */
536    fdlist_init();
537    log_set_file(LOG_TYPE_IRCD, 0, logFileName);
538 <  check_can_use_v6();
538 >
539    init_netio();         /* This needs to be setup early ! -- adrian */
540  
541    /* Check if there is pidfile and daemon already running */
# Line 556 | Line 546 | main(int argc, char *argv[])
546    init_isupport();
547    dbuf_init();
548    hash_init();
549 <  init_ip_hash_table();      /* client host ip hash table */
560 <  init_host_hash();          /* Host-hashtable. */
549 >  ipcache_init();
550    client_init();
551    class_init();
552    whowas_init();
# Line 572 | Line 561 | main(int argc, char *argv[])
561    channel_init();
562    read_links_file();
563    motd_init();
564 +  user_usermodes_init();
565   #ifdef HAVE_LIBGEOIP
566    geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
567   #endif
568  
569 <  if (EmptyString(ServerInfo.sid))
569 >  if (EmptyString(ConfigServerInfo.sid))
570    {
571      ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
572      exit(EXIT_FAILURE);
573    }
574  
575 <  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
575 >  strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
576  
577 <  if (EmptyString(ServerInfo.name))
577 >  if (EmptyString(ConfigServerInfo.name))
578    {
579      ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
580      exit(EXIT_FAILURE);
581    }
582  
583 <  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
583 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
584  
585    /* serverinfo{} description must exist.  If not, error out.*/
586 <  if (EmptyString(ServerInfo.description))
586 >  if (EmptyString(ConfigServerInfo.description))
587    {
588      ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
589      exit(EXIT_FAILURE);
590    }
591  
592 <  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
592 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
593  
594    me.from                   = &me;
595    me.servptr                = &me;
596 <  me.localClient->lasttime  = CurrentTime;
597 <  me.localClient->since     = CurrentTime;
598 <  me.localClient->firsttime = CurrentTime;
596 >  me.connection->lasttime  = CurrentTime;
597 >  me.connection->since     = CurrentTime;
598 >  me.connection->firsttime = CurrentTime;
599  
600    SetMe(&me);
601    make_server(&me);
# Line 613 | Line 603 | main(int argc, char *argv[])
603    hash_add_id(&me);
604    hash_add_client(&me);
605  
606 <  /* add ourselves to global_serv_list */
617 <  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
606 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
607  
608    load_kline_database();
609    load_dline_database();
# Line 633 | Line 622 | main(int argc, char *argv[])
622    load_core_modules(1);
623  
624    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
625 <  if (chdir(ConfigFileEntry.dpath))
625 >  if (chdir(ConfigGeneral.dpath))
626    {
627      perror("chdir");
628      exit(EXIT_FAILURE);
629    }
630  
642  /*
643   * assemble_umode_buffer() has to be called after
644   * reading conf/loading modules.
645   */
646  assemble_umode_buffer();
647
631    write_pidfile(pidFileName);
632  
633    ilog(LOG_TYPE_IRCD, "Server Ready");
# Line 657 | Line 640 | main(int argc, char *argv[])
640    event_addish(&event_try_connections, NULL);
641  
642    /* Setup the timeout check. I'll shift it later :)  -- adrian */
643 <  event_addish(&event_comm_checktimeouts, NULL);
643 >  event_add(&event_comm_checktimeouts, NULL);
644  
645    event_addish(&event_save_all_databases, NULL);
646  
# Line 670 | Line 653 | main(int argc, char *argv[])
653      ConfigServerHide.links_disabled = 1;
654  
655    if (splitmode)
656 <    event_addish(&event_check_splitmode, NULL);
656 >    event_addish(&splitmode_event, NULL);
657  
658    io_loop();
659    return 0;

Diff Legend

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