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-7.2/src/ircd.c (file contents), Revision 982 by michael, Thu Aug 13 22:15:08 2009 UTC vs.
ircd-hybrid-8/src/ircd.c (file contents), Revision 1404 by michael, Thu May 10 20:41:45 2012 UTC

# Line 24 | Line 24
24  
25   #include "stdinc.h"
26   #include "s_user.h"
27 < #include "tools.h"
27 > #include "list.h"
28   #include "ircd.h"
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"
39 #include "list.h"
37   #include "s_gline.h"
38   #include "motd.h"
42 #include "ircd_handler.h"
43 #include "msg.h"         /* msgtab */
39   #include "hostmask.h"
40   #include "numeric.h"
41   #include "packet.h"
# Line 50 | 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 65 | Line 60
60   #include "supported.h"
61   #include "watch.h"
62  
68 /* Try and find the correct name to use with getrlimit() for setting the max.
69 * number of files allowed to be open by this process.
70 */
63  
64   /* /quote set variables */
65   struct SetOptions GlobalSetOptions;
# Line 78 | 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 = { .use_logging = 1 };
76   struct ServerStatistics ServerStats;
77   struct timeval SystemTime;
78   struct Client me;             /* That's me */
# Line 90 | Line 82 | const char *logFileName = LPATH;
82   const char *pidFileName = PPATH;
83  
84   char **myargv;
93 char ircd_platform[PLATFORMLEN];
85  
86   int dorehash = 0;
87   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
88  
89   /* Set to zero because it should be initialized later using
90   * initialize_server_capabs
91   */
92   int default_server_capabs = 0;
93 <
94 < #ifdef HAVE_LIBCRYPTO
95 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
93 > unsigned int splitmode;
94 > unsigned int splitchecking;
95 > unsigned int split_users;
96   unsigned int split_servers;
97  
98   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 123 | Line 108 | unsigned int split_servers;
108   int rehashed_klines = 0;
109  
110  
126 #ifndef _WIN32
111   /*
112   * print_startup - print startup information
113   */
# Line 154 | Line 138 | make_daemon(void)
138  
139    setsid();
140   }
157 #endif
141  
142   static int printVersion = 0;
143  
144 < struct lgetopt myopts[] = {
144 > static struct lgetopt myopts[] = {
145    {"dlinefile",  &ConfigFileEntry.dlinefile,
146     STRING, "File to use for dline.conf"},
147    {"configfile", &ConfigFileEntry.configfile,
# Line 184 | Line 167 | set_time(void)
167   {
168    static char to_send[200];
169    struct timeval newtime;
187 #ifdef _WIN32
188  FILETIME ft;
189
190  GetSystemTimeAsFileTime(&ft);
191  if (ft.dwLowDateTime < 0xd53e8000)
192    ft.dwHighDateTime--;
193  ft.dwLowDateTime -= 0xd53e8000;
194  ft.dwHighDateTime -= 0x19db1de;
195
196  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
197  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
198 #else
170    newtime.tv_sec  = 0;
171    newtime.tv_usec = 0;
172  
173    if (gettimeofday(&newtime, NULL) == -1)
174    {
175 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
175 >    ilog(LOG_TYPE_IRCD, "Clock Failure (%s), TS can be corrupted",
176           strerror(errno));
177      sendto_realops_flags(UMODE_ALL, L_ALL,
178                           "Clock Failure (%s), TS can be corrupted",
179                           strerror(errno));
180      restart("Clock Failure");
181    }
211 #endif
182  
183    if (newtime.tv_sec < CurrentTime)
184    {
185 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
186 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
185 >    snprintf(to_send, sizeof(to_send),
186 >             "System clock is running backwards - (%lu < %lu)",
187 >             (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
188      report_error(L_ALL, to_send, me.name, 0);
189      set_back_events(CurrentTime - newtime.tv_sec);
190    }
# Line 314 | Line 285 | initialize_global_set_options(void)
285    }
286  
287    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
317  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
288    /* End of global set options */
289   }
290  
# Line 348 | Line 318 | initialize_server_capabs(void)
318   {
319    add_capability("QS", CAP_QS, 1);
320    add_capability("EOB", CAP_EOB, 1);
321 <
352 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
353 <    add_capability("TS6", CAP_TS6, 0);
354 <
355 <  add_capability("ZIP", CAP_ZIP, 0);
321 >  add_capability("TS6", CAP_TS6, 0);
322    add_capability("CLUSTER", CAP_CLUSTER, 1);
323 +  add_capability("SVS", CAP_SVS, 1);
324   #ifdef HALFOPS
325    add_capability("HOPS", CAP_HOPS, 1);
326   #endif
# Line 368 | Line 335 | initialize_server_capabs(void)
335   static void
336   write_pidfile(const char *filename)
337   {
338 <  FBFILE *fb;
338 >  FILE *fb;
339  
340 <  if ((fb = fbopen(filename, "w")))
340 >  if ((fb = fopen(filename, "w")))
341    {
342      char buff[32];
343      unsigned int pid = (unsigned int)getpid();
377    size_t nbytes = ircsprintf(buff, "%u\n", pid);
344  
345 <    if ((fbputs(buff, fb, nbytes) == -1))
346 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
345 >    snprintf(buff, sizeof(buff), "%u\n", pid);
346 >
347 >    if ((fputs(buff, fb) == -1))
348 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
349             pid, filename, strerror(errno));
350  
351 <    fbclose(fb);
384 <    return;
351 >    fclose(fb);
352    }
353    else
354    {
355 <    ilog(L_ERROR, "Error opening pid file %s", filename);
355 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s", filename);
356    }
357   }
358  
# Line 400 | Line 367 | write_pidfile(const char *filename)
367   static void
368   check_pidfile(const char *filename)
369   {
370 < #ifndef _WIN32
404 <  FBFILE *fb;
370 >  FILE *fb;
371    char buff[32];
372    pid_t pidfromfile;
373  
374    /* Don't do logging here, since we don't have log() initialised */
375 <  if ((fb = fbopen(filename, "r")))
375 >  if ((fb = fopen(filename, "r")))
376    {
377 <    if (fbgets(buff, 20, fb) == NULL)
377 >    if (fgets(buff, 20, fb) == NULL)
378      {
379        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
380         * strerror(errno));
# Line 426 | Line 392 | check_pidfile(const char *filename)
392        }
393      }
394  
395 <    fbclose(fb);
395 >    fclose(fb);
396    }
397    else if (errno != ENOENT)
398    {
399      /* log(L_ERROR, "Error opening pid file %s", filename); */
400    }
435 #endif
401   }
402  
403   /* setup_corefile()
# Line 474 | Line 439 | init_ssl(void)
439    {
440      const char *s;
441  
442 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
442 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n",
443              s = ERR_lib_error_string(ERR_get_error()));
444 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
444 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
445    }
446  
447 <  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2);
447 >  SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
448    SSL_CTX_set_options(ServerInfo.server_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
449    SSL_CTX_set_verify(ServerInfo.server_ctx, SSL_VERIFY_NONE, NULL);
450  
451 <  bio_spare_fd = save_spare_fd("SSL private key validation");
451 >  if ((ServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL)
452 >  {
453 >    const char *s;
454 >
455 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n",
456 >            s = ERR_lib_error_string(ERR_get_error()));
457 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
458 >  }
459 >
460 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1);
461 >  SSL_CTX_set_options(ServerInfo.client_ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
462 >  SSL_CTX_set_verify(ServerInfo.client_ctx, SSL_VERIFY_NONE, NULL);
463   #endif /* HAVE_LIBCRYPTO */
464   }
465  
# Line 498 | Line 474 | init_callbacks(void)
474   {
475    iorecv_cb = register_callback("iorecv", iorecv_default);
476    iosend_cb = register_callback("iosend", iosend_default);
501  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
502  iosendctrl_cb = register_callback("iosendctrl", NULL);
477   }
478  
479   int
# Line 508 | Line 482 | main(int argc, char *argv[])
482    /* Check to see if the user is running
483     * us as root, which is a nono
484     */
511 #ifndef _WIN32
485    if (geteuid() == 0)
486    {
487      fprintf(stderr, "Don't run ircd as root!!!\n");
# Line 517 | Line 490 | main(int argc, char *argv[])
490  
491    /* Setup corefile size immediately after boot -kre */
492    setup_corefile();
520 #endif
493  
494    /* save server boot time right away, so getrusage works correctly */
495    set_time();
# Line 525 | Line 497 | main(int argc, char *argv[])
497    /* It ain't random, but it ought to be a little harder to guess */
498    init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
499  
528  memset(&me, 0, sizeof(me));
529  memset(&meLocalUser, 0, sizeof(meLocalUser));
500    me.localClient = &meLocalUser;
501    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
502                                                     of Client list */
533
534  memset(&ServerInfo, 0, sizeof(ServerInfo));
535  memset(&ServerStats, 0, sizeof(ServerStats));
536
503    /* Initialise the channel capability usage counts... */
504    init_chcap_usage_counts();
505  
# Line 566 | Line 532 | main(int argc, char *argv[])
532  
533    init_ssl();
534  
569 #ifndef _WIN32
535    if (!server_state.foreground)
536    {
537      make_daemon();
# Line 576 | Line 541 | main(int argc, char *argv[])
541      print_startup(getpid());
542  
543    setup_signals();
579 #endif
580
581  get_ircd_platform(ircd_platform);
544  
545    /* Init the event subsystem */
546    eventInit();
547    /* We need this to initialise the fd array before anything else */
548    fdlist_init();
549 <  init_log(logFileName);
549 >  log_add_file(LOG_TYPE_IRCD, 0, logFileName);
550    check_can_use_v6();
551    init_comm();         /* This needs to be setup early ! -- adrian */
552    /* Check if there is pidfile and daemon already running */
553    check_pidfile(pidFileName);
554  
593 #ifndef NOBALLOC
555    initBlockHeap();
595 #endif
556    init_dlink_nodes();
557    init_callbacks();
558    initialize_message_files();
# Line 600 | Line 560 | main(int argc, char *argv[])
560    init_hash();
561    init_ip_hash_table();      /* client host ip hash table */
562    init_host_hash();          /* Host-hashtable. */
603  clear_tree_parse();
563    init_client();
564    init_class();
565 <  init_whowas();
565 >  whowas_init();
566    watch_init();
608  read_conf_files(1);   /* cold start init conf files */
609  me.id[0] = '\0';
610  init_uid();
567    init_auth();          /* Initialise the auth code */
612 #ifndef _WIN32
568    init_resolver();      /* Needs to be setup before the io loop */
569 < #endif
569 >  modules_init();
570 >  read_conf_files(1);   /* cold start init conf files */
571 >  init_uid();
572    initialize_server_capabs();   /* Set up default_server_capabs */
573    initialize_global_set_options();
574    init_channels();
575  
576 <  if (ServerInfo.name == NULL)
576 >  if (EmptyString(ServerInfo.sid))
577 >  {
578 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
579 >    exit(EXIT_FAILURE);
580 >  }
581 >
582 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
583 >
584 >  if (EmptyString(ServerInfo.name))
585    {
586 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
586 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
587      exit(EXIT_FAILURE);
588    }
589  
590    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
591  
592    /* serverinfo{} description must exist.  If not, error out.*/
593 <  if (ServerInfo.description == NULL)
593 >  if (EmptyString(ServerInfo.description))
594    {
595 <    ilog(L_CRIT,
631 <      "ERROR: No server description specified in serverinfo block.");
595 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
596      exit(EXIT_FAILURE);
597    }
598  
599    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
600  
601 <  me.from    = &me;
602 <  me.servptr = &me;
601 >  me.from                   = &me;
602 >  me.servptr                = &me;
603 >  me.localClient->lasttime  = CurrentTime;
604 >  me.localClient->since     = CurrentTime;
605 >  me.localClient->firsttime = CurrentTime;
606  
607    SetMe(&me);
608    make_server(&me);
609  
610 <  me.lasttime = me.since = me.firsttime = CurrentTime;
610 >  hash_add_id(&me);
611    hash_add_client(&me);
612    
613    /* add ourselves to global_serv_list */
614    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
615  
649  check_class();
650
651 #ifndef STATIC_MODULES
616    if (chdir(MODPATH))
617    {
618 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
618 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
619      exit(EXIT_FAILURE);
620    }
621  
622    load_all_modules(1);
623    load_conf_modules();
624    load_core_modules(1);
625 +
626    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
627 <  chdir(ConfigFileEntry.dpath);
628 < #else
629 <  load_all_modules(1);
630 < #endif
627 >  if (chdir(ConfigFileEntry.dpath))
628 >  {
629 >    perror("chdir");
630 >    exit(EXIT_FAILURE);
631 >  }
632 >
633    /*
634     * assemble_umode_buffer() has to be called after
635     * reading conf/loading modules.
# Line 671 | Line 638 | main(int argc, char *argv[])
638  
639    write_pidfile(pidFileName);
640  
641 <  ilog(L_NOTICE, "Server Ready");
641 >  ilog(LOG_TYPE_IRCD, "Server Ready");
642  
643    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
644    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 680 | Line 647 | main(int argc, char *argv[])
647    /* No, 'cause after a restart it would cause all sorts of nick collides */
648    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
649  
683  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
684
650    /* Setup the timeout check. I'll shift it later :)  -- adrian */
651    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
652  

Diff Legend

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