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/src/ircd.c (file contents), Revision 1028 by michael, Sun Nov 8 13:03:38 2009 UTC vs.
ircd-hybrid-8/src/ircd.c (file contents), Revision 1316 by michael, Tue Mar 27 17:05:51 2012 UTC

# Line 29 | Line 29
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"
37   #include "s_gline.h"
38   #include "motd.h"
41 #include "ircd_handler.h"
42 #include "msg.h"         /* msgtab */
39   #include "hostmask.h"
40   #include "numeric.h"
41   #include "packet.h"
# Line 49 | Line 45
45   #include "rng_mt.h"
46   #include "s_auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
48 > #include "conf.h"
49 > #include "log.h"
50   #include "s_misc.h"
51   #include "s_serv.h"      /* try_connections */
52   #include "send.h"
# Line 64 | Line 60
60   #include "supported.h"
61   #include "watch.h"
62  
67 /* 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 */
63  
64   /* /quote set variables */
65   struct SetOptions GlobalSetOptions;
# Line 77 | Line 70 | struct config_file_entry ConfigFileEntry
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 };
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, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
75 > struct logging_entry ConfigLoggingEntry = { 1, 1 };
76   struct ServerStatistics ServerStats;
77   struct timeval SystemTime;
78   struct Client me;             /* That's me */
# Line 98 | Line 91 | int doremotd = 0;
91   * initialize_server_capabs
92   */
93   int default_server_capabs = 0;
101
102 #ifdef HAVE_LIBCRYPTO
103 int bio_spare_fd = -1;
104 #endif
105
94   unsigned int splitmode;
95   unsigned int splitchecking;
96   unsigned int split_users;
# Line 185 | Line 173 | set_time(void)
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,
179                           "Clock Failure (%s), TS can be corrupted",
# Line 195 | Line 183 | set_time(void)
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 297 | Line 286 | initialize_global_set_options(void)
286    }
287  
288    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
300  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
289    /* End of global set options */
290   }
291  
# Line 331 | Line 319 | initialize_server_capabs(void)
319   {
320    add_capability("QS", CAP_QS, 1);
321    add_capability("EOB", CAP_EOB, 1);
322 <
335 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
336 <    add_capability("TS6", CAP_TS6, 0);
337 <
338 <  add_capability("ZIP", CAP_ZIP, 0);
322 >  add_capability("TS6", CAP_TS6, 0);
323    add_capability("CLUSTER", CAP_CLUSTER, 1);
324 +  add_capability("SVS", CAP_SVS, 1);
325   #ifdef HALFOPS
326    add_capability("HOPS", CAP_HOPS, 1);
327   #endif
# Line 357 | Line 342 | write_pidfile(const char *filename)
342    {
343      char buff[32];
344      unsigned int pid = (unsigned int)getpid();
345 <    size_t nbytes = ircsprintf(buff, "%u\n", pid);
345 >    size_t nbytes = snprintf(buff, sizeof(buff), "%u\n", pid);
346  
347      if ((fbputs(buff, fb, nbytes) == -1))
348 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
348 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
349             pid, filename, strerror(errno));
350  
351      fbclose(fb);
# Line 368 | Line 353 | write_pidfile(const char *filename)
353    }
354    else
355    {
356 <    ilog(L_ERROR, "Error opening pid file %s", filename);
356 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
357    }
358   }
359  
# Line 455 | Line 440 | init_ssl(void)
440    {
441      const char *s;
442  
443 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
443 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
444              s = ERR_lib_error_string(ERR_get_error()));
445 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
445 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
446    }
447  
448 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
448 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
449    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
450    SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
451  
452 <  bio_spare_fd = save_spare_fd("SSL private key validation");
452 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
453 >  {
454 >    const char *s;
455 >
456 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
457 >            s = ERR_lib_error_string(ERR_get_error()));
458 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
459 >  }
460 >
461 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
462 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
463 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
464   #endif /* HAVE_LIBCRYPTO */
465   }
466  
# Line 479 | Line 475 | init_callbacks(void)
475   {
476    iorecv_cb = register_callback("iorecv", iorecv_default);
477    iosend_cb = register_callback("iosend", iosend_default);
482  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
483  iosendctrl_cb = register_callback("iosendctrl", NULL);
478   }
479  
480   int
# Line 504 | Line 498 | main(int argc, char *argv[])
498    /* It ain't random, but it ought to be a little harder to guess */
499    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
500  
507  memset(&me, 0, sizeof(me));
508  memset(&meLocalUser, 0, sizeof(meLocalUser));
501    me.localClient = &meLocalUser;
502    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
503                                                     of Client list */
512
513  memset(&ServerInfo, 0, sizeof(ServerInfo));
514  memset(&ServerStats, 0, sizeof(ServerStats));
515
504    /* Initialise the channel capability usage counts... */
505    init_chcap_usage_counts();
506  
# Line 561 | Line 549 | main(int argc, char *argv[])
549    eventInit();
550    /* We need this to initialise the fd array before anything else */
551    fdlist_init();
552 <  init_log(logFileName);
552 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
553    check_can_use_v6();
554    init_comm();         /* This needs to be setup early ! -- adrian */
555    /* Check if there is pidfile and daemon already running */
# Line 583 | Line 571 | main(int argc, char *argv[])
571    init_auth();          /* Initialise the auth code */
572    init_resolver();      /* Needs to be setup before the io loop */
573    read_conf_files(1);   /* cold start init conf files */
586  me.id[0] = '\0';
574    init_uid();
575    initialize_server_capabs();   /* Set up default_server_capabs */
576    initialize_global_set_options();
577    init_channels();
578  
579 <  if (ServerInfo.name == NULL)
579 >  if (EmptyString(ServerInfo.sid))
580    {
581 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
581 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
582 >    exit(EXIT_FAILURE);
583 >  }
584 >
585 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
586 >
587 >  if (EmptyString(ServerInfo.name))
588 >  {
589 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
590      exit(EXIT_FAILURE);
591    }
592  
593    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
594  
595    /* serverinfo{} description must exist.  If not, error out.*/
596 <  if (ServerInfo.description == NULL)
596 >  if (EmptyString(ServerInfo.description))
597    {
598 <    ilog(L_CRIT,
604 <      "ERROR: No server description specified in serverinfo block.");
598 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
599      exit(EXIT_FAILURE);
600    }
601  
602    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
603  
604 <  me.from    = &me;
605 <  me.servptr = &me;
604 >  me.from                   = &me;
605 >  me.servptr                = &me;
606 >  me.localClient->lasttime  = CurrentTime;
607 >  me.localClient->since     = CurrentTime;
608 >  me.localClient->firsttime = CurrentTime;
609  
610    SetMe(&me);
611    make_server(&me);
612  
613 <  me.lasttime = me.since = me.firsttime = CurrentTime;
613 >  hash_add_id(&me);
614    hash_add_client(&me);
615    
616    /* add ourselves to global_serv_list */
617    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
618  
622 #ifndef STATIC_MODULES
619    if (chdir(MODPATH))
620    {
621 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
621 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
622      exit(EXIT_FAILURE);
623    }
624  
625    load_all_modules(1);
626    load_conf_modules();
627    load_core_modules(1);
628 +
629    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
630 <  chdir(ConfigFileEntry.dpath);
631 < #else
632 <  load_all_modules(1);
633 < #endif
630 >  if (chdir(ConfigFileEntry.dpath))
631 >  {
632 >    perror("chdir");
633 >    exit(EXIT_FAILURE);
634 >  }
635 >
636    /*
637     * assemble_umode_buffer() has to be called after
638     * reading conf/loading modules.
# Line 642 | Line 641 | main(int argc, char *argv[])
641  
642    write_pidfile(pidFileName);
643  
644 <  ilog(L_NOTICE, "Server Ready");
644 >  ilog(LOG_TYPE_IRCD, "Server Ready");
645  
646    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
647    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 651 | Line 650 | main(int argc, char *argv[])
650    /* No, 'cause after a restart it would cause all sorts of nick collides */
651    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
652  
654  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
655
653    /* Setup the timeout check. I'll shift it later :)  -- adrian */
654    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
655  

Diff Legend

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