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 4497 by michael, Sat Aug 16 18:20:57 2014 UTC vs.
Revision 5796 by michael, Fri Apr 17 16:12:30 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 63 | Line 63
63   GeoIP *geoip_ctx;
64   #endif
65  
66 + struct SetOptions GlobalSetOptions;  /* /quote set variables */
67 + struct Counter Count;
68 + struct ServerState_t server_state;
69   struct ServerStatistics ServerStats;
70   struct timeval SystemTime;
71 < struct Client me;             /* That's me */
72 < struct LocalUser meLocalUser; /* That's also part of me */
71 > struct Connection meConnection;  /* That's also part of me */
72 > struct Client me = { .connection = &meConnection };  /* That's me */
73  
74 + char **myargv;
75   const char *logFileName = LPATH;
76   const char *pidFileName = PPATH;
77  
78 < char **myargv;
79 <
76 < int dorehash = 0;
77 < int doremotd = 0;
78 <
79 < /* Set to zero because it should be initialized later using
80 < * initialize_server_capabs
81 < */
82 < unsigned int default_server_capabs;
78 > unsigned int dorehash;
79 > unsigned int doremotd;
80   unsigned int splitmode;
81   unsigned int splitchecking;
82   unsigned int split_users;
# Line 223 | Line 220 | io_loop(void)
220    {
221      if (listing_client_list.head)
222      {
223 <      dlink_node *ptr = NULL, *ptr_next = NULL;
224 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
225 <        safe_list_channels(ptr->data, 0);
223 >      dlink_node *node = NULL, *node_next = NULL;
224 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
225 >        safe_list_channels(node->data, 0);
226      }
227  
228      /* Run pending events */
# Line 238 | Line 235 | io_loop(void)
235      /* Check to see whether we have to rehash the configuration .. */
236      if (dorehash)
237      {
238 <      rehash(1);
238 >      conf_rehash(1);
239        dorehash = 0;
240      }
241  
# Line 261 | Line 258 | io_loop(void)
258   static void
259   initialize_global_set_options(void)
260   {
261 <  GlobalSetOptions.autoconn  = 1;
261 >  GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients;
262 >  GlobalSetOptions.autoconn = 1;
263    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
264 <  GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
265 <
266 <  if (ConfigGeneral.default_floodcount)
267 <    GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
270 <  else
271 <    GlobalSetOptions.floodcount = 10;
272 <
273 <  /* XXX I have no idea what to try here - Dianora */
274 <  GlobalSetOptions.joinfloodcount = 16;
275 <  GlobalSetOptions.joinfloodtime = 8;
264 >  GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
265 >  GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
266 >  GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count;
267 >  GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time;
268  
269    split_servers = ConfigChannel.default_split_server_count;
270    split_users   = ConfigChannel.default_split_user_count;
# Line 295 | Line 287 | initialize_global_set_options(void)
287   static void
288   initialize_server_capabs(void)
289   {
290 <  add_capability("QS", CAP_QS, 1);
291 <  add_capability("EOB", CAP_EOB, 1);
292 <  add_capability("TS6", CAP_TS6, 0);
293 <  add_capability("CLUSTER", CAP_CLUSTER, 1);
294 <  add_capability("SVS", CAP_SVS, 1);
295 <  add_capability("CHW", CAP_CHW, 1);
304 <  add_capability("HOPS", CAP_HOPS, 1);
290 >  add_capability("QS", CAP_QS);
291 >  add_capability("EOB", CAP_EOB);
292 >  add_capability("CLUSTER", CAP_CLUSTER);
293 >  add_capability("SVS", CAP_SVS);
294 >  add_capability("CHW", CAP_CHW);
295 >  add_capability("HOPS", CAP_HOPS);
296   }
297  
298   /* write_pidfile()
# Line 322 | Line 313 | write_pidfile(const char *filename)
313  
314      snprintf(buff, sizeof(buff), "%u\n", pid);
315  
316 <    if ((fputs(buff, fb) == -1))
317 <      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
318 <           pid, filename, strerror(errno));
316 >    if (fputs(buff, fb) == -1)
317 >      ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s",
318 >           filename, strerror(errno));
319  
320      fclose(fb);
321    }
322    else
323 <  {
324 <    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
334 <  }
323 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
324 >         filename, strerror(errno));
325   }
326  
327   /* check_pidfile()
# Line 352 | Line 342 | check_pidfile(const char *filename)
342    /* Don't do logging here, since we don't have log() initialised */
343    if ((fb = fopen(filename, "r")))
344    {
345 <    if (fgets(buff, 20, fb) == NULL)
345 >    if (!fgets(buff, 20, fb))
346      {
347        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
348         * strerror(errno));
# Line 418 | Line 408 | static void
408   ssl_init(void)
409   {
410   #ifdef HAVE_LIBCRYPTO
421  const unsigned char session_id[] = "ircd-hybrid";
422
411    SSL_load_error_strings();
412    SSLeay_add_ssl_algorithms();
413  
414 <  if ((ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
414 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
415    {
416      const char *s = ERR_lib_error_string(ERR_get_error());
417  
418      fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
419 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
419 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
420      exit(EXIT_FAILURE);
421 +    return;  /* Not reached */
422    }
423  
424 <  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
425 <  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE);
424 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
425 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
426    SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
427                       always_accept_verify_cb);
428 <  SSL_CTX_set_session_id_context(ConfigServerInfo.server_ctx, session_id, sizeof(session_id) - 1);
428 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
429 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
430  
431 < #if OPENSSL_VERSION_NUMBER >= 0x1000005FL && !defined(OPENSSL_NO_ECDH)
431 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
432    {
433      EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
434  
# Line 452 | Line 442 | ssl_init(void)
442    SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
443   #endif
444  
445 <  if ((ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
445 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
446    {
447      const char *s = ERR_lib_error_string(ERR_get_error());
448  
449      fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
450 <    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
450 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
451      exit(EXIT_FAILURE);
452 +    return;  /* Not reached */
453    }
454  
455 <  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3);
455 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
456    SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
457    SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
458                       always_accept_verify_cb);
459 +  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
460   #endif /* HAVE_LIBCRYPTO */
461   }
462  
# Line 472 | Line 464 | int
464   main(int argc, char *argv[])
465   {
466    /* Check to see if the user is running us as root, which is a nono */
467 <  if (geteuid() == 0)
467 >  if (!geteuid())
468    {
469      fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
470      return -1;
# Line 481 | Line 473 | main(int argc, char *argv[])
473    /* Setup corefile size immediately after boot -kre */
474    setup_corefile();
475  
476 <  /* save server boot time right away, so getrusage works correctly */
476 >  /* Save server boot time right away, so getrusage works correctly */
477    set_time();
478  
479 <  /* It ain't random, but it ought to be a little harder to guess */
479 >  /* It's not random, but it ought to be a little harder to guess */
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
492 <                                                   of Client list */
493 <  ConfigLog.use_logging = 1;
482 >  dlinkAdd(&me, &me.node, &global_client_list);
483 >
484    ConfigGeneral.dpath      = DPATH;
485    ConfigGeneral.spath      = SPATH;
486    ConfigGeneral.mpath      = MPATH;
# Line 502 | Line 492 | main(int argc, char *argv[])
492    ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
493  
494    myargv = argv;
495 <  umask(077);                /* better safe than sorry --SRB */
495 >  umask(077);  /* umask 077: u=rwx,g=,o= */
496  
497    parseargs(&argc, &argv, myopts);
498  
# Line 545 | Line 535 | main(int argc, char *argv[])
535    dbuf_init();
536    hash_init();
537    ipcache_init();
548  init_host_hash();          /* Host-hashtable. */
538    client_init();
539    class_init();
540    whowas_init();
# Line 556 | Line 545 | main(int argc, char *argv[])
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();
548 >  initialize_global_set_options();  /* Has to be called after read_conf_files() */
549    channel_init();
550    read_links_file();
551    motd_init();
552 +  user_usermodes_init();
553   #ifdef HAVE_LIBGEOIP
554    geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
555   #endif
# Line 589 | Line 579 | main(int argc, char *argv[])
579  
580    strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
581  
582 <  me.from                   = &me;
583 <  me.servptr                = &me;
584 <  me.localClient->lasttime  = CurrentTime;
585 <  me.localClient->since     = CurrentTime;
586 <  me.localClient->firsttime = CurrentTime;
582 >  me.from = &me;
583 >  me.servptr = &me;
584 >  me.connection->lasttime = CurrentTime;
585 >  me.connection->since = CurrentTime;
586 >  me.connection->firsttime = CurrentTime;
587  
588    SetMe(&me);
589    make_server(&me);
# Line 609 | Line 599 | main(int argc, char *argv[])
599    load_xline_database();
600    load_resv_database();
601  
612  if (chdir(MODPATH))
613  {
614    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
615    exit(EXIT_FAILURE);
616  }
617
602    load_all_modules(1);
603    load_conf_modules();
604    load_core_modules(1);
605  
622  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
623  if (chdir(ConfigGeneral.dpath))
624  {
625    perror("chdir");
626    exit(EXIT_FAILURE);
627  }
628
629  /*
630   * assemble_umode_buffer() has to be called after
631   * reading conf/loading modules.
632   */
633  assemble_umode_buffer();
634
606    write_pidfile(pidFileName);
607  
608    ilog(LOG_TYPE_IRCD, "Server Ready");

Diff Legend

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