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 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (file contents), Revision 1361 by michael, Sun Apr 22 19:01:51 2012 UTC

# Line 19 | Line 19
19   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
20   *  USA
21   *
22 < *  $Id: ircd.c,v 7.369 2005/09/24 09:27:18 michael Exp $
22 > *  $Id$
23   */
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"
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 "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 */
56 #include "s_stats.h"
52   #include "send.h"
53   #include "whowas.h"
54   #include "modules.h"
# Line 63 | Line 58
58   #include "balloc.h"
59   #include "motd.h"
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 = { .use_logging = 1 };
76 > struct ServerStatistics ServerStats;
77   struct timeval SystemTime;
78   struct Client me;             /* That's me */
79   struct LocalUser meLocalUser; /* That's also part of me */
86 unsigned long connect_id = 0; /* unique connect ID */
80  
88 static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
81   const char *logFileName = LPATH;
82   const char *pidFileName = PPATH;
83  
# Line 94 | Line 86 | char ircd_platform[PLATFORMLEN];
86  
87   int dorehash = 0;
88   int doremotd = 0;
97 time_t nextconnect = 1;       /* time for next try_connections call */
89  
90   /* Set to zero because it should be initialized later using
91   * initialize_server_capabs
92   */
93   int default_server_capabs = 0;
94 <
95 < #ifdef HAVE_LIBCRYPTO
96 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
94 > unsigned int splitmode;
95 > unsigned int splitchecking;
96 > unsigned int split_users;
97   unsigned int split_servers;
98  
99   /* Do klines the same way hybrid-6 did them, i.e. at the
# Line 122 | Line 108 | unsigned int split_servers;
108  
109   int rehashed_klines = 0;
110  
125 /*
126 * get_vm_top - get the operating systems notion of the resident set size
127 */
128 #ifndef _WIN32
129 static unsigned long
130 get_vm_top(void)
131 {
132  /*
133   * NOTE: sbrk is not part of the ANSI C library or the POSIX.1 standard
134   * however it seems that everyone defines it. Calling sbrk with a 0
135   * argument will return a pointer to the top of the process virtual
136   * memory without changing the process size, so this call should be
137   * reasonably safe (sbrk returns the new value for the top of memory).
138   * This code relies on the notion that the address returned will be an
139   * offset from 0 (NULL), so the result of sbrk is cast to a size_t and
140   * returned. We really shouldn't be using it here but...
141   */
142
143  void *vptr = sbrk(0);
144  return((unsigned long)vptr);
145 }
111  
112   /*
113   * print_startup - print startup information
# Line 174 | Line 139 | make_daemon(void)
139  
140    setsid();
141   }
177 #endif
178
179 /*
180 * get_maxrss - get the operating systems notion of the resident set size
181 */
182 unsigned long
183 get_maxrss(void)
184 {
185 #ifdef _WIN32
186  return (0);   /* FIXME */
187 #else
188  return (get_vm_top() - initialVMTop);
189 #endif
190 }
142  
143   static int printVersion = 0;
144  
145 < struct lgetopt myopts[] = {
145 > static struct lgetopt myopts[] = {
146    {"dlinefile",  &ConfigFileEntry.dlinefile,
147     STRING, "File to use for dline.conf"},
148    {"configfile", &ConfigFileEntry.configfile,
# Line 217 | Line 168 | set_time(void)
168   {
169    static char to_send[200];
170    struct timeval newtime;
220 #ifdef _WIN32
221  FILETIME ft;
222
223  GetSystemTimeAsFileTime(&ft);
224  if (ft.dwLowDateTime < 0xd53e8000)
225    ft.dwHighDateTime--;
226  ft.dwLowDateTime -= 0xd53e8000;
227  ft.dwHighDateTime -= 0x19db1de;
228
229  newtime.tv_sec  = (*(uint64_t *) &ft) / 10000000;
230  newtime.tv_usec = (*(uint64_t *) &ft) / 10 % 1000000;
231 #else
171    newtime.tv_sec  = 0;
172    newtime.tv_usec = 0;
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",
180                           strerror(errno));
181      restart("Clock Failure");
182    }
244 #endif
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 281 | Line 220 | io_loop(void)
220        {
221          struct Client *client_p = ptr->data;
222          assert(client_p->localClient->list_task);
223 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
223 >        safe_list_channels(client_p, client_p->localClient->list_task, 0);
224        }
225      }
226  
# Line 347 | Line 286 | initialize_global_set_options(void)
286    }
287  
288    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
289    /* End of global set options */
290   }
291  
# Line 380 | Line 318 | static void
318   initialize_server_capabs(void)
319   {
320    add_capability("QS", CAP_QS, 1);
383  add_capability("LL", CAP_LL, 1);
321    add_capability("EOB", CAP_EOB, 1);
322 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
386 <    add_capability("TS6", CAP_TS6, 0);
387 <  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 400 | Line 336 | initialize_server_capabs(void)
336   static void
337   write_pidfile(const char *filename)
338   {
339 <  FBFILE *fb;
339 >  FILE *fb;
340  
341 <  if ((fb = fbopen(filename, "w")))
341 >  if ((fb = fopen(filename, "w")))
342    {
343      char buff[32];
344      unsigned int pid = (unsigned int)getpid();
409    size_t nbytes = ircsprintf(buff, "%u\n", pid);
345  
346 <    if ((fbputs(buff, fb, nbytes) == -1))
347 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
346 >    snprintf(buff, sizeof(buff), "%u\n", pid);
347 >
348 >    if ((fputs(buff, fb) == -1))
349 >      ilog(LOG_TYPE_IRCD, "Error writing %u to pid file %s (%s)",
350             pid, filename, strerror(errno));
351  
352 <    fbclose(fb);
416 <    return;
352 >    fclose(fb);
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 432 | Line 368 | write_pidfile(const char *filename)
368   static void
369   check_pidfile(const char *filename)
370   {
371 < #ifndef _WIN32
436 <  FBFILE *fb;
371 >  FILE *fb;
372    char buff[32];
373    pid_t pidfromfile;
374  
375    /* Don't do logging here, since we don't have log() initialised */
376 <  if ((fb = fbopen(filename, "r")))
376 >  if ((fb = fopen(filename, "r")))
377    {
378 <    if (fbgets(buff, 20, fb) == NULL)
378 >    if (fgets(buff, 20, fb) == NULL)
379      {
380        /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
381         * strerror(errno));
# Line 458 | Line 393 | check_pidfile(const char *filename)
393        }
394      }
395  
396 <    fbclose(fb);
396 >    fclose(fb);
397    }
398    else if (errno != ENOENT)
399    {
400      /* log(L_ERROR, "Error opening pid file %s", filename); */
401    }
467 #endif
402   }
403  
404   /* setup_corefile()
# Line 502 | Line 436 | init_ssl(void)
436    SSL_load_error_strings();
437    SSLeay_add_ssl_algorithms();
438  
439 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
439 >  if ((ServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL)
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.ctx, SSL_OP_NO_SSLv2);
449 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
450 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
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 >  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 <  bio_spare_fd = save_spare_fd("SSL private key validation");
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 529 | Line 473 | init_ssl(void)
473   static void
474   init_callbacks(void)
475   {
476 <  iorecv_cb = register_callback("iorecv", NULL);
477 <  iosend_cb = register_callback("iosend", NULL);
534 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
535 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
476 >  iorecv_cb = register_callback("iorecv", iorecv_default);
477 >  iosend_cb = register_callback("iosend", iosend_default);
478   }
479  
480   int
# Line 541 | Line 483 | main(int argc, char *argv[])
483    /* Check to see if the user is running
484     * us as root, which is a nono
485     */
544 #ifndef _WIN32
486    if (geteuid() == 0)
487    {
488      fprintf(stderr, "Don't run ircd as root!!!\n");
489 <    return(-1);
489 >    return -1;
490    }
491  
492    /* Setup corefile size immediately after boot -kre */
493    setup_corefile();
494  
554  /* set initialVMTop before we allocate any memory */
555  initialVMTop = get_vm_top();
556 #endif
557
495    /* save server boot time right away, so getrusage works correctly */
496    set_time();
497  
498 <    /* It ain't random, but it ought to be a little harder to guess */
499 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
500 <  memset(&me, 0, sizeof(me));
564 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
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 >
501    me.localClient = &meLocalUser;
502    dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
503                                                     of Client list */
568
569  memset(&ServerInfo, 0, sizeof(ServerInfo));
570
504    /* Initialise the channel capability usage counts... */
505    init_chcap_usage_counts();
506  
# Line 600 | Line 533 | main(int argc, char *argv[])
533  
534    init_ssl();
535  
603 #ifndef _WIN32
536    if (!server_state.foreground)
537    {
538      make_daemon();
# Line 610 | Line 542 | main(int argc, char *argv[])
542      print_startup(getpid());
543  
544    setup_signals();
613 #endif
545  
546    get_ircd_platform(ircd_platform);
547  
# Line 618 | 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 */
556    check_pidfile(pidFileName);
557  
627 #ifndef NOBALLOC
558    initBlockHeap();
629 #endif
559    init_dlink_nodes();
560    init_callbacks();
561    initialize_message_files();
# Line 634 | Line 563 | main(int argc, char *argv[])
563    init_hash();
564    init_ip_hash_table();      /* client host ip hash table */
565    init_host_hash();          /* Host-hashtable. */
637  clear_tree_parse();
566    init_client();
567    init_class();
568 <  init_whowas();
569 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
568 >  whowas_init();
569 >  watch_init();
570    init_auth();          /* Initialise the auth code */
647 #ifndef _WIN32
571    init_resolver();      /* Needs to be setup before the io loop */
572 < #endif
572 >  read_conf_files(1);   /* cold start init conf files */
573 >  init_uid();
574    initialize_server_capabs();   /* Set up default_server_capabs */
575    initialize_global_set_options();
576    init_channels();
577  
578 <  if (ServerInfo.name == NULL)
578 >  if (EmptyString(ServerInfo.sid))
579 >  {
580 >    ilog(LOG_TYPE_IRCD, "ERROR: No server id specified in serverinfo block.");
581 >    exit(EXIT_FAILURE);
582 >  }
583 >
584 >  strlcpy(me.id, ServerInfo.sid, sizeof(me.id));
585 >
586 >  if (EmptyString(ServerInfo.name))
587    {
588 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
588 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
589      exit(EXIT_FAILURE);
590    }
591 +
592    strlcpy(me.name, ServerInfo.name, sizeof(me.name));
593  
594    /* serverinfo{} description must exist.  If not, error out.*/
595 <  if (ServerInfo.description == NULL)
595 >  if (EmptyString(ServerInfo.description))
596    {
597 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
597 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
598      exit(EXIT_FAILURE);
599    }
600 +
601    strlcpy(me.info, ServerInfo.description, sizeof(me.info));
602  
603 <  me.from    = &me;
604 <  me.servptr = &me;
603 >  me.from                   = &me;
604 >  me.servptr                = &me;
605 >  me.localClient->lasttime  = CurrentTime;
606 >  me.localClient->since     = CurrentTime;
607 >  me.localClient->firsttime = CurrentTime;
608  
609    SetMe(&me);
610    make_server(&me);
611  
612 <  me.lasttime = me.since = me.firsttime = CurrentTime;
612 >  hash_add_id(&me);
613    hash_add_client(&me);
614    
615    /* add ourselves to global_serv_list */
616    dlinkAdd(&me, make_dlink_node(), &global_serv_list);
617  
682  check_class();
683
684 #ifndef STATIC_MODULES
618    if (chdir(MODPATH))
619    {
620 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
620 >    ilog(LOG_TYPE_IRCD, "Could not load core modules. Terminating!");
621      exit(EXIT_FAILURE);
622    }
623  
624    load_all_modules(1);
625    load_conf_modules();
626    load_core_modules(1);
627 +
628    /* Go back to DPATH after checking to see if we can chdir to MODPATH */
629 <  chdir(ConfigFileEntry.dpath);
630 < #else
631 <  load_all_modules(1);
632 < #endif
629 >  if (chdir(ConfigFileEntry.dpath))
630 >  {
631 >    perror("chdir");
632 >    exit(EXIT_FAILURE);
633 >  }
634 >
635    /*
636     * assemble_umode_buffer() has to be called after
637     * reading conf/loading modules.
# Line 704 | Line 640 | main(int argc, char *argv[])
640  
641    write_pidfile(pidFileName);
642  
643 <  ilog(L_NOTICE, "Server Ready");
643 >  ilog(LOG_TYPE_IRCD, "Server Ready");
644  
645    eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
646    eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
# Line 713 | Line 649 | main(int argc, char *argv[])
649    /* No, 'cause after a restart it would cause all sorts of nick collides */
650    eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
651  
716  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
717
652    /* Setup the timeout check. I'll shift it later :)  -- adrian */
653    eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
654  
# Line 727 | Line 661 | main(int argc, char *argv[])
661      eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
662  
663    io_loop();
664 <  return(0);
664 >  return 0;
665   }

Comparing:
ircd-hybrid/src/ircd.c (property svn:keywords), Revision 30 by adx, Sun Oct 2 20:03:27 2005 UTC vs.
ircd-hybrid-8/src/ircd.c (property svn:keywords), Revision 1361 by michael, Sun Apr 22 19:01:51 2012 UTC

# Line 1 | Line 1
1 < "Id Revision"
1 > Id Revision

Diff Legend

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