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 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (file contents), Revision 6802 by michael, Wed Nov 18 11:25:16 2015 UTC

# Line 1 | Line 1
1   /*
2 < *  ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 < *  ircd.c: Starts up and runs the ircd.
2 > *  ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3   *
4 < *  Copyright (C) 2002 by the past and present ircd coders, and others.
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 16 | 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 < *  $Id$
20 > */
21 >
22 > /*! \file ircd.c
23 > * \brief Starts up and runs the ircd.
24 > * \version $Id$
25   */
26  
27   #include "stdinc.h"
28 < #include "s_user.h"
29 < #include "tools.h"
28 > #include "user.h"
29 > #include "list.h"
30   #include "ircd.h"
31   #include "channel.h"
30 #include "channel_mode.h"
32   #include "client.h"
32 #include "common.h"
33   #include "event.h"
34   #include "fdlist.h"
35   #include "hash.h"
36 + #include "id.h"
37   #include "irc_string.h"
37 #include "sprintf_irc.h"
38   #include "ircd_signal.h"
39 #include "list.h"
40 #include "s_gline.h"
39   #include "motd.h"
40 < #include "ircd_handler.h"
43 < #include "msg.h"         /* msgtab */
40 > #include "conf.h"
41   #include "hostmask.h"
45 #include "numeric.h"
46 #include "packet.h"
42   #include "parse.h"
43 < #include "irc_res.h"
43 > #include "res.h"
44   #include "restart.h"
45 < #include "s_auth.h"
45 > #include "rng_mt.h"
46 > #include "auth.h"
47   #include "s_bsd.h"
48 < #include "s_conf.h"
49 < #include "s_log.h"
54 < #include "s_misc.h"
55 < #include "s_serv.h"      /* try_connections */
56 < #include "s_stats.h"
48 > #include "log.h"
49 > #include "server.h"
50   #include "send.h"
51   #include "whowas.h"
52   #include "modules.h"
53   #include "memory.h"
54 < #include "hook.h"
54 > #include "mempool.h"
55   #include "ircd_getopt.h"
56 < #include "balloc.h"
57 < #include "motd.h"
58 < #include "supported.h"
59 <
60 < /* Try and find the correct name to use with getrlimit() for setting the max.
61 < * number of files allowed to be open by this process.
62 < */
63 <
64 < /* /quote set variables */
65 < struct SetOptions GlobalSetOptions;
66 <
67 < /* configuration set from ircd.conf */
68 < struct config_file_entry ConfigFileEntry;
69 < /* server info set from ircd.conf */
70 < struct server_info ServerInfo;
71 < /* admin info set from ircd.conf */
79 < struct admin_info AdminInfo = { NULL, NULL, NULL };
80 < struct Counter Count = { 0, 0, 0, 0, 0, 0, 0, 0 };
81 < struct ServerState_t server_state = { 0 };
82 < struct logging_entry ConfigLoggingEntry = { 1, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0} };
56 > #include "watch.h"
57 > #include "conf_db.h"
58 > #include "conf_class.h"
59 > #include "ipcache.h"
60 > #include "isupport.h"
61 > #include "userhost.h"
62 >
63 >
64 > #ifdef HAVE_LIBGEOIP
65 > GeoIP *geoip_ctx;
66 > #endif
67 >
68 > struct SetOptions GlobalSetOptions;  /* /quote set variables */
69 > struct Counter Count;
70 > struct ServerState_t server_state;
71 > struct ServerStatistics ServerStats;
72   struct timeval SystemTime;
73 < struct Client me;             /* That's me */
74 < struct LocalUser meLocalUser; /* That's also part of me */
86 < unsigned long connect_id = 0; /* unique connect ID */
73 > struct Connection meConnection;  /* That's also part of me */
74 > struct Client me = { .connection = &meConnection };  /* That's me */
75  
76 < static unsigned long initialVMTop = 0;   /* top of virtual memory at init */
76 > char **myargv;
77   const char *logFileName = LPATH;
78   const char *pidFileName = PPATH;
79  
80 < char **myargv;
81 < char ircd_platform[PLATFORMLEN];
80 > unsigned int dorehash;
81 > unsigned int doremotd;
82  
83 < int dorehash = 0;
96 < int doremotd = 0;
97 < time_t nextconnect = 1;       /* time for next try_connections call */
83 > static int printVersion;
84  
85 < /* Set to zero because it should be initialized later using
100 < * initialize_server_capabs
101 < */
102 < int default_server_capabs = 0;
103 <
104 < #ifdef HAVE_LIBCRYPTO
105 < int bio_spare_fd = -1;
106 < #endif
107 <
108 < int splitmode;
109 < int splitchecking;
110 < int split_users;
111 < unsigned int split_servers;
112 <
113 < /* Do klines the same way hybrid-6 did them, i.e. at the
114 < * top of the next io_loop instead of in the same loop as
115 < * the klines are being applied.
116 < *
117 < * This should fix strange CPU starvation as very indirectly reported.
118 < * (Why do you people not email bug reports? WHY? WHY?)
119 < *
120 < * - Dianora
121 < */
122 <
123 < int rehashed_klines = 0;
124 <
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 < }
146 <
147 < /*
148 < * print_startup - print startup information
149 < */
150 < static void
151 < print_startup(int pid)
85 > static struct lgetopt myopts[] =
86   {
87 <  printf("ircd: version %s\n", ircd_version);
88 <  printf("ircd: pid %d\n", pid);
89 <  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
90 <         : "foreground", ConfigFileEntry.dpath);
91 < }
87 >  { "configfile", &ConfigGeneral.configfile,
88 >   STRING, "File to use for ircd.conf" },
89 >  { "klinefile",  &ConfigGeneral.klinefile,
90 >   STRING, "File to use for kline database" },
91 >  { "dlinefile",  &ConfigGeneral.dlinefile,
92 >   STRING, "File to use for dline database" },
93 >  { "xlinefile",  &ConfigGeneral.xlinefile,
94 >   STRING, "File to use for xline database" },
95 >  { "resvfile",   &ConfigGeneral.resvfile,
96 >   STRING, "File to use for resv database" },
97 >  { "logfile",    &logFileName,
98 >   STRING, "File to use for ircd.log" },
99 >  { "pidfile",    &pidFileName,
100 >   STRING, "File to use for process ID" },
101 >  { "foreground", &server_state.foreground,
102 >   YESNO, "Run in foreground (don't detach)" },
103 >  { "version",    &printVersion,
104 >   YESNO, "Print version and exit" },
105 >  { "help", NULL, USAGE, "Print this text" },
106 >  { NULL, NULL, STRING, NULL },
107 > };
108  
109 < static void
160 < make_daemon(void)
109 > static struct event event_cleanup_tklines =
110   {
111 <  int pid;
112 <
113 <  if ((pid = fork()) < 0)
114 <  {
166 <    perror("fork");
167 <    exit(EXIT_FAILURE);
168 <  }
169 <  else if (pid > 0)
170 <  {
171 <    print_startup(pid);
172 <    exit(EXIT_SUCCESS);
173 <  }
111 >  .name = "cleanup_tklines",
112 >  .handler = cleanup_tklines,
113 >  .when = CLEANUP_TKLINES_TIME
114 > };
115  
116 <  setsid();
117 < }
118 < #endif
116 > static struct event event_try_connections =
117 > {
118 >  .name = "try_connections",
119 >  .handler = try_connections,
120 >  .when = STARTUP_CONNECTIONS_TIME
121 > };
122  
123 < /*
180 < * get_maxrss - get the operating systems notion of the resident set size
181 < */
182 < unsigned long
183 < get_maxrss(void)
123 > static struct event event_comm_checktimeouts =
124   {
125 < #ifdef _WIN32
126 <  return (0);   /* FIXME */
127 < #else
128 <  return (get_vm_top() - initialVMTop);
189 < #endif
190 < }
125 >  .name = "comm_checktimeouts",
126 >  .handler = comm_checktimeouts,
127 >  .when = 1
128 > };
129  
130 < static int printVersion = 0;
130 > static struct event event_save_all_databases =
131 > {
132 >  .name = "save_all_databases",
133 >  .handler = save_all_databases,
134 >  .when = DATABASE_UPDATE_TIMEOUT
135 > };
136  
137 < struct lgetopt myopts[] = {
138 <  {"dlinefile",  &ConfigFileEntry.dlinefile,
139 <   STRING, "File to use for dline.conf"},
140 <  {"configfile", &ConfigFileEntry.configfile,
198 <   STRING, "File to use for ircd.conf"},
199 <  {"klinefile",  &ConfigFileEntry.klinefile,
200 <   STRING, "File to use for kline.conf"},
201 <  {"xlinefile",  &ConfigFileEntry.xlinefile,
202 <   STRING, "File to use for xline.conf"},
203 <  {"logfile",    &logFileName,
204 <   STRING, "File to use for ircd.log"},
205 <  {"pidfile",    &pidFileName,
206 <   STRING, "File to use for process ID"},
207 <  {"foreground", &server_state.foreground,
208 <   YESNO, "Run in foreground (don't detach)"},
209 <  {"version",    &printVersion,
210 <   YESNO, "Print version and exit"},
211 <  {"help", NULL, USAGE, "Print this text"},
212 <  {NULL, NULL, STRING, NULL},
137 > struct event event_write_links_file =
138 > {
139 >  .name = "write_links_file",
140 >  .handler = write_links_file,
141   };
142  
143 +
144   void
145   set_time(void)
146   {
147 <  static char to_send[200];
219 <  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
232 <  newtime.tv_sec  = 0;
233 <  newtime.tv_usec = 0;
147 >  struct timeval newtime = { .tv_sec = 0, .tv_usec = 0 };
148  
149    if (gettimeofday(&newtime, NULL) == -1)
150    {
151 <    ilog(L_ERROR, "Clock Failure (%s), TS can be corrupted",
152 <         strerror(errno));
153 <    sendto_realops_flags(UMODE_ALL, L_ALL,
154 <                         "Clock Failure (%s), TS can be corrupted",
155 <                         strerror(errno));
242 <    restart("Clock Failure");
151 >    char buf[IRCD_BUFSIZE];
152 >
153 >    snprintf(buf, sizeof(buf), "Clock failure, TS can be corrupted: %s",
154 >             strerror(errno));
155 >    server_die(buf, SERVER_SHUTDOWN);
156    }
244 #endif
157  
158    if (newtime.tv_sec < CurrentTime)
159    {
160 <    ircsprintf(to_send, "System clock is running backwards - (%lu < %lu)",
161 <               (unsigned long)newtime.tv_sec, (unsigned long)CurrentTime);
162 <    report_error(L_ALL, to_send, me.name, 0);
163 <    set_back_events(CurrentTime - newtime.tv_sec);
160 >    ilog(LOG_TYPE_IRCD, "System clock is running backwards - (%ju < %ju)",
161 >         newtime.tv_sec, CurrentTime);
162 >    sendto_realops_flags(UMODE_DEBUG, L_ALL, SEND_NOTICE,
163 >                         "System clock is running backwards - (%ju < %ju)",
164 >                         newtime.tv_sec, CurrentTime);
165 >    event_set_back_events(CurrentTime - newtime.tv_sec);
166    }
167  
168 <  SystemTime.tv_sec  = newtime.tv_sec;
168 >  SystemTime.tv_sec = newtime.tv_sec;
169    SystemTime.tv_usec = newtime.tv_usec;
170   }
171  
172   static void
173   io_loop(void)
174   {
175 <  while (1 == 1)
175 >  while (1)
176    {
263    /*
264     * Maybe we want a flags word?
265     * ie. if (REHASHED_KLINES(global_flags))
266     * SET_REHASHED_KLINES(global_flags)
267     * CLEAR_REHASHED_KLINES(global_flags)
268     *
269     * - Dianora
270     */
271    if (rehashed_klines)
272    {
273      check_conf_klines();
274      rehashed_klines = 0;
275    }
276
177      if (listing_client_list.head)
178      {
179 <      dlink_node *ptr = NULL, *ptr_next = NULL;
180 <      DLINK_FOREACH_SAFE(ptr, ptr_next, listing_client_list.head)
181 <      {
282 <        struct Client *client_p = ptr->data;
283 <        assert(client_p->localClient->list_task);
284 <        safe_list_channels(client_p, client_p->localClient->list_task, 0, 0);
285 <      }
179 >      dlink_node *node = NULL, *node_next = NULL;
180 >      DLINK_FOREACH_SAFE(node, node_next, listing_client_list.head)
181 >        safe_list_channels(node->data, 0);
182      }
183  
184 <    /* Run pending events, then get the number of seconds to the next
185 <     * event
290 <     */
291 <    while (eventNextTime() <= CurrentTime)
292 <      eventRun();
184 >    /* Run pending events */
185 >    event_run();
186  
187      comm_select();
188      exit_aborted_clients();
189      free_exited_clients();
297    send_queued_all();
190  
191 <    /* Check to see whether we have to rehash the configuration .. */
191 >    /* Check to see whether we have to rehash the configuration. */
192      if (dorehash)
193      {
194 <      rehash(1);
194 >      conf_rehash(1);
195        dorehash = 0;
196      }
197 +
198      if (doremotd)
199      {
200 <      read_message_file(&ConfigFileEntry.motd);
201 <      sendto_realops_flags(UMODE_ALL, L_ALL,
202 <                           "Got signal SIGUSR1, reloading ircd motd file");
200 >      motd_recache();
201 >      sendto_realops_flags(UMODE_SERVNOTICE, L_ALL, SEND_NOTICE,
202 >                           "Got signal SIGUSR1, reloading motd file(s)");
203        doremotd = 0;
204      }
205    }
# Line 316 | Line 209 | io_loop(void)
209   *
210   * inputs       - none
211   * output       - none
212 < * side effects - This sets all global set options needed
212 > * side effects - This sets all global set options needed
213   */
214   static void
215   initialize_global_set_options(void)
216   {
217 <  memset(&GlobalSetOptions, 0, sizeof(GlobalSetOptions));
218 <
326 <  GlobalSetOptions.autoconn  = 1;
217 >  GlobalSetOptions.maxclients = ConfigServerInfo.default_max_clients;
218 >  GlobalSetOptions.autoconn = 1;
219    GlobalSetOptions.spam_time = MIN_JOIN_LEAVE_TIME;
220 <  GlobalSetOptions.spam_num  = MAX_JOIN_LEAVE_COUNT;
221 <
222 <  if (ConfigFileEntry.default_floodcount)
223 <    GlobalSetOptions.floodcount = ConfigFileEntry.default_floodcount;
332 <  else
333 <    GlobalSetOptions.floodcount = 10;
334 <
335 <  /* XXX I have no idea what to try here - Dianora */
336 <  GlobalSetOptions.joinfloodcount = 16;
337 <  GlobalSetOptions.joinfloodtime = 8;
338 <
339 <  split_servers = ConfigChannel.default_split_server_count;
340 <  split_users   = ConfigChannel.default_split_user_count;
341 <
342 <  if (split_users && split_servers && (ConfigChannel.no_create_on_split ||
343 <                                       ConfigChannel.no_join_on_split))
344 <  {
345 <    splitmode     = 1;
346 <    splitchecking = 1;
347 <  }
348 <
220 >  GlobalSetOptions.spam_num = MAX_JOIN_LEAVE_COUNT;
221 >  GlobalSetOptions.floodcount = ConfigGeneral.default_floodcount;
222 >  GlobalSetOptions.joinfloodcount = ConfigChannel.default_join_flood_count;
223 >  GlobalSetOptions.joinfloodtime = ConfigChannel.default_join_flood_time;
224    GlobalSetOptions.ident_timeout = IDENT_TIMEOUT;
350  GlobalSetOptions.idletime = ConfigFileEntry.idletime;
351  /* End of global set options */
352 }
353
354 /* initialize_message_files()
355 *
356 * inputs       - none
357 * output       - none
358 * side effects - Set up all message files needed, motd etc.
359 */
360 static void
361 initialize_message_files(void)
362 {
363  init_message_file(USER_MOTD, MPATH, &ConfigFileEntry.motd);
364  init_message_file(OPER_MOTD, OPATH, &ConfigFileEntry.opermotd);
365  init_message_file(USER_LINKS, LIPATH, &ConfigFileEntry.linksfile);
366
367  read_message_file(&ConfigFileEntry.motd);
368  read_message_file(&ConfigFileEntry.opermotd);
369  read_message_file(&ConfigFileEntry.linksfile);
370
371  init_isupport();
225   }
226  
227   /* initialize_server_capabs()
# Line 379 | Line 232 | initialize_message_files(void)
232   static void
233   initialize_server_capabs(void)
234   {
235 <  add_capability("QS", CAP_QS, 1);
236 <  add_capability("LL", CAP_LL, 1);
237 <  add_capability("EOB", CAP_EOB, 1);
238 <  if (ServerInfo.sid != NULL)   /* only enable TS6 if we have an SID */
239 <    add_capability("TS6", CAP_TS6, 0);
240 <  add_capability("ZIP", CAP_ZIP, 0);
388 <  add_capability("CLUSTER", CAP_CLUSTER, 1);
389 < #ifdef HALFOPS
390 <  add_capability("HOPS", CAP_HOPS, 1);
391 < #endif
235 >  add_capability("QS", CAPAB_QS);
236 >  add_capability("EOB", CAPAB_EOB);
237 >  add_capability("CLUSTER", CAPAB_CLUSTER);
238 >  add_capability("SVS", CAPAB_SVS);
239 >  add_capability("CHW", CAPAB_CHW);
240 >  add_capability("HOPS", CAPAB_HOPS);
241   }
242  
243   /* write_pidfile()
# Line 400 | Line 249 | initialize_server_capabs(void)
249   static void
250   write_pidfile(const char *filename)
251   {
252 <  FBFILE *fb;
252 >  FILE *fb;
253  
254 <  if ((fb = fbopen(filename, "w")))
254 >  if ((fb = fopen(filename, "w")))
255    {
256 <    char buff[32];
256 >    char buf[IRCD_BUFSIZE];
257      unsigned int pid = (unsigned int)getpid();
409    size_t nbytes = ircsprintf(buff, "%u\n", pid);
258  
259 <    if ((fbputs(buff, fb, nbytes) == -1))
412 <      ilog(L_ERROR, "Error writing %u to pid file %s (%s)",
413 <           pid, filename, strerror(errno));
259 >    snprintf(buf, sizeof(buf), "%u\n", pid);
260  
261 <    fbclose(fb);
262 <    return;
261 >    if (fputs(buf, fb) == -1)
262 >      ilog(LOG_TYPE_IRCD, "Error writing to pid file %s: %s",
263 >           filename, strerror(errno));
264 >
265 >    fclose(fb);
266    }
267    else
268 <  {
269 <    ilog(L_ERROR, "Error opening pid file %s", filename);
421 <  }
268 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
269 >         filename, strerror(errno));
270   }
271  
272   /* check_pidfile()
# Line 432 | Line 280 | write_pidfile(const char *filename)
280   static void
281   check_pidfile(const char *filename)
282   {
283 < #ifndef _WIN32
284 <  FBFILE *fb;
437 <  char buff[32];
438 <  pid_t pidfromfile;
283 >  FILE *fb;
284 >  char buf[IRCD_BUFSIZE];
285  
286 <  /* Don't do logging here, since we don't have log() initialised */
441 <  if ((fb = fbopen(filename, "r")))
286 >  if ((fb = fopen(filename, "r")))
287    {
288 <    if (fbgets(buff, 20, fb) == NULL)
289 <    {
290 <      /* log(L_ERROR, "Error reading from pid file %s (%s)", filename,
446 <       * strerror(errno));
447 <       */
448 <    }
288 >    if (!fgets(buf, 20, fb))
289 >      ilog(LOG_TYPE_IRCD, "Error reading from pid file %s: %s",
290 >           filename, strerror(errno));
291      else
292      {
293 <      pidfromfile = atoi(buff);
293 >      pid_t pid = atoi(buf);
294  
295 <      if (!kill(pidfromfile, 0))
295 >      if (!kill(pid, 0))
296        {
297          /* log(L_ERROR, "Server is already running"); */
298          printf("ircd: daemon is already running\n");
299 <        exit(-1);
299 >        exit(EXIT_FAILURE);
300        }
301      }
302  
303 <    fbclose(fb);
303 >    fclose(fb);
304    }
305    else if (errno != ENOENT)
306 <  {
307 <    /* log(L_ERROR, "Error opening pid file %s", filename); */
466 <  }
467 < #endif
306 >    ilog(LOG_TYPE_IRCD, "Error opening pid file %s: %s",
307 >         filename, strerror(errno));
308   }
309  
310   /* setup_corefile()
# Line 489 | Line 329 | setup_corefile(void)
329   #endif
330   }
331  
332 < /* init_ssl()
332 > #ifdef HAVE_LIBCRYPTO
333 > static int
334 > always_accept_verify_cb(int preverify_ok, X509_STORE_CTX *x509_ctx)
335 > {
336 >  return 1;
337 > }
338 > #endif
339 >
340 > /* ssl_init()
341   *
342   * inputs       - nothing
343   * output       - nothing
344   * side effects - setups SSL context.
345   */
346   static void
347 < init_ssl(void)
347 > ssl_init(void)
348   {
349   #ifdef HAVE_LIBCRYPTO
350    SSL_load_error_strings();
351    SSLeay_add_ssl_algorithms();
352  
353 <  ServerInfo.ctx = SSL_CTX_new(SSLv23_server_method());
506 <  if (!ServerInfo.ctx)
353 >  if (!(ConfigServerInfo.server_ctx = SSL_CTX_new(SSLv23_server_method())))
354    {
355 <    const char *s;
355 >    const char *s = ERR_lib_error_string(ERR_get_error());
356  
357 <    fprintf(stderr, "ERROR: Could not initialize the SSL context -- %s\n",
358 <            s = ERR_lib_error_string(ERR_get_error()));
359 <    ilog(L_CRIT, "ERROR: Could not initialize the SSL context -- %s\n", s);
357 >    fprintf(stderr, "ERROR: Could not initialize the SSL Server context -- %s\n", s);
358 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Server context -- %s", s);
359 >    exit(EXIT_FAILURE);
360 >    return;  /* Not reached */
361    }
362  
363 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_NO_SSLv2);
364 <  SSL_CTX_set_options(ServerInfo.ctx, SSL_OP_TLS_ROLLBACK_BUG|SSL_OP_ALL);
365 <  SSL_CTX_set_verify(ServerInfo.ctx, SSL_VERIFY_NONE, NULL);
363 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
364 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_DH_USE|SSL_OP_CIPHER_SERVER_PREFERENCE);
365 >  SSL_CTX_set_verify(ConfigServerInfo.server_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
366 >                     always_accept_verify_cb);
367 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.server_ctx, SSL_SESS_CACHE_OFF);
368 >  SSL_CTX_set_cipher_list(ConfigServerInfo.server_ctx, "EECDH+HIGH:EDH+HIGH:HIGH:!aNULL");
369 >
370 > #if OPENSSL_VERSION_NUMBER >= 0x009080FFL && !defined(OPENSSL_NO_ECDH)
371 >  {
372 >    EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
373 >
374 >    if (key)
375 >    {
376 >      SSL_CTX_set_tmp_ecdh(ConfigServerInfo.server_ctx, key);
377 >      EC_KEY_free(key);
378 >    }
379 >  }
380  
381 <  bio_spare_fd = save_spare_fd("SSL private key validation");
381 >  SSL_CTX_set_options(ConfigServerInfo.server_ctx, SSL_OP_SINGLE_ECDH_USE);
382 > #endif
383 >
384 >  if (!(ConfigServerInfo.client_ctx = SSL_CTX_new(SSLv23_client_method())))
385 >  {
386 >    const char *s = ERR_lib_error_string(ERR_get_error());
387 >
388 >    fprintf(stderr, "ERROR: Could not initialize the SSL Client context -- %s\n", s);
389 >    ilog(LOG_TYPE_IRCD, "ERROR: Could not initialize the SSL Client context -- %s", s);
390 >    exit(EXIT_FAILURE);
391 >    return;  /* Not reached */
392 >  }
393 >
394 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TICKET);
395 >  SSL_CTX_set_options(ConfigServerInfo.client_ctx, SSL_OP_SINGLE_DH_USE);
396 >  SSL_CTX_set_verify(ConfigServerInfo.client_ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
397 >                     always_accept_verify_cb);
398 >  SSL_CTX_set_session_cache_mode(ConfigServerInfo.client_ctx, SSL_SESS_CACHE_OFF);
399   #endif /* HAVE_LIBCRYPTO */
400   }
401  
402 < /* init_callbacks()
403 < *
525 < * inputs       - nothing
526 < * output       - nothing
527 < * side effects - setups standard hook points
402 > /*
403 > * print_startup - print startup information
404   */
405   static void
406 < init_callbacks(void)
406 > print_startup(int pid)
407   {
408 <  iorecv_cb = register_callback("iorecv", NULL);
409 <  iosend_cb = register_callback("iosend", NULL);
410 <  iorecvctrl_cb = register_callback("iorecvctrl", NULL);
411 <  iosendctrl_cb = register_callback("iosendctrl", NULL);
408 >  printf("ircd: version %s(%s)\n", ircd_version, serno);
409 >  printf("ircd: pid %d\n", pid);
410 >  printf("ircd: running in %s mode from %s\n", !server_state.foreground ? "background"
411 >         : "foreground", ConfigGeneral.dpath);
412 > }
413 >
414 > static void
415 > make_daemon(void)
416 > {
417 >  int pid;
418 >
419 >  if ((pid = fork()) < 0)
420 >  {
421 >    perror("fork");
422 >    exit(EXIT_FAILURE);
423 >  }
424 >  else if (pid > 0)
425 >  {
426 >    print_startup(pid);
427 >    exit(EXIT_SUCCESS);
428 >  }
429 >
430 >  setsid();
431   }
432  
433   int
434   main(int argc, char *argv[])
435   {
436 <  /* Check to see if the user is running
437 <   * us as root, which is a nono
543 <   */
544 < #ifndef _WIN32
545 <  if (geteuid() == 0)
436 >  /* Check to see if the user is running us as root, which is a nono */
437 >  if (!geteuid())
438    {
439 <    fprintf(stderr, "Don't run ircd as root!!!\n");
440 <    return(-1);
439 >    fprintf(stderr, "ERROR: This server won't run as root/superuser\n");
440 >    return -1;
441    }
442  
443    /* Setup corefile size immediately after boot -kre */
444    setup_corefile();
445  
446 <  /* set initialVMTop before we allocate any memory */
555 <  initialVMTop = get_vm_top();
556 < #endif
557 <
558 <  /* save server boot time right away, so getrusage works correctly */
446 >  /* Save server boot time right away, so getrusage works correctly */
447    set_time();
448  
449 <    /* It ain't random, but it ought to be a little harder to guess */
450 <  srand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
451 <  memset(&me, 0, sizeof(me));
452 <  memset(&meLocalUser, 0, sizeof(meLocalUser));
453 <  me.localClient = &meLocalUser;
454 <  dlinkAdd(&me, &me.node, &global_client_list); /* Pointer to beginning
455 <                                                   of Client list */
456 <
457 <  memset(&ServerInfo, 0, sizeof(ServerInfo));
458 <
459 <  /* Initialise the channel capability usage counts... */
460 <  init_chcap_usage_counts();
573 <
574 <  ConfigFileEntry.dpath      = DPATH;
575 <  ConfigFileEntry.configfile = CPATH;  /* Server configuration file */
576 <  ConfigFileEntry.klinefile  = KPATH;  /* Server kline file         */
577 <  ConfigFileEntry.xlinefile  = XPATH;  /* Server xline file         */
578 <  ConfigFileEntry.rxlinefile = RXPATH; /* Server regex xline file   */
579 <  ConfigFileEntry.rklinefile = RKPATH; /* Server regex kline file   */
580 <  ConfigFileEntry.dlinefile  = DLPATH; /* dline file                */
581 <  ConfigFileEntry.glinefile  = GPATH;  /* gline log file            */
582 <  ConfigFileEntry.cresvfile  = CRESVPATH; /* channel resv file      */
583 <  ConfigFileEntry.nresvfile  = NRESVPATH; /* nick resv file         */
449 >  /* It's not random, but it ought to be a little harder to guess */
450 >  init_genrand(SystemTime.tv_sec ^ (SystemTime.tv_usec | (getpid() << 20)));
451 >
452 >  ConfigGeneral.dpath      = DPATH;
453 >  ConfigGeneral.spath      = SPATH;
454 >  ConfigGeneral.mpath      = MPATH;
455 >  ConfigGeneral.configfile = CPATH;    /* Server configuration file */
456 >  ConfigGeneral.klinefile  = KPATH;    /* Server kline file         */
457 >  ConfigGeneral.xlinefile  = XPATH;    /* Server xline file         */
458 >  ConfigGeneral.dlinefile  = DLPATH;   /* dline file                */
459 >  ConfigGeneral.resvfile   = RESVPATH; /* resv file                 */
460 >
461    myargv = argv;
462 <  umask(077);                /* better safe than sorry --SRB */
462 >  umask(077);  /* umask 077: u=rwx,g=,o= */
463  
464    parseargs(&argc, &argv, myopts);
465  
466    if (printVersion)
467    {
468 <    printf("ircd: version %s\n", ircd_version);
468 >    printf("ircd: version %s(%s)\n", ircd_version, serno);
469      exit(EXIT_SUCCESS);
470    }
471  
472 <  if (chdir(ConfigFileEntry.dpath))
472 >  if (chdir(ConfigGeneral.dpath))
473    {
474      perror("chdir");
475      exit(EXIT_FAILURE);
476    }
477  
478 <  init_ssl();
478 >  ssl_init();
479  
603 #ifndef _WIN32
480    if (!server_state.foreground)
481    {
482      make_daemon();
# Line 610 | Line 486 | main(int argc, char *argv[])
486      print_startup(getpid());
487  
488    setup_signals();
613 #endif
614
615  get_ircd_platform(ircd_platform);
489  
617  /* Init the event subsystem */
618  eventInit();
490    /* We need this to initialise the fd array before anything else */
491    fdlist_init();
492 <  init_log(logFileName);
493 <  check_can_use_v6();
494 <  init_comm();         /* This needs to be setup early ! -- adrian */
492 >  log_set_file(LOG_TYPE_IRCD, 0, logFileName);
493 >
494 >  init_netio();         /* This needs to be setup early ! -- adrian */
495 >
496    /* Check if there is pidfile and daemon already running */
497    check_pidfile(pidFileName);
498  
499 < #ifndef NOBALLOC
628 <  initBlockHeap();
629 < #endif
499 >  mp_pool_init();
500    init_dlink_nodes();
501 <  init_callbacks();
632 <  initialize_message_files();
501 >  isupport_init();
502    dbuf_init();
503 <  init_hash();
504 <  init_ip_hash_table();      /* client host ip hash table */
505 <  init_host_hash();          /* Host-hashtable. */
506 <  clear_tree_parse();
507 <  init_client();
508 <  init_class();
509 <  init_whowas();
510 <  init_stats();
642 <  read_conf_files(1);   /* cold start init conf files */
643 <  initServerMask();
644 <  me.id[0] = '\0';
645 <  init_uid();
646 <  init_auth();          /* Initialise the auth code */
647 < #ifndef _WIN32
503 >  hash_init();
504 >  userhost_init();
505 >  ipcache_init();
506 >  client_init();
507 >  class_init();
508 >  whowas_init();
509 >  watch_init();
510 >  auth_init();          /* Initialise the auth code */
511    init_resolver();      /* Needs to be setup before the io loop */
512 < #endif
512 >  modules_init();
513 >  read_conf_files(1);   /* cold start init conf files */
514    initialize_server_capabs();   /* Set up default_server_capabs */
515 <  initialize_global_set_options();
516 <  init_channels();
515 >  initialize_global_set_options();  /* Has to be called after read_conf_files() */
516 >  channel_init();
517 >  read_links_file();
518 >  motd_init();
519 >  user_modes_init();
520 > #ifdef HAVE_LIBGEOIP
521 >  geoip_ctx = GeoIP_new(GEOIP_MEMORY_CACHE);
522 > #endif
523  
524 <  if (ServerInfo.name == NULL)
524 >  if (EmptyString(ConfigServerInfo.name))
525    {
526 <    ilog(L_CRIT, "No server name specified in serverinfo block.");
526 >    ilog(LOG_TYPE_IRCD, "ERROR: No server name specified in serverinfo block.");
527      exit(EXIT_FAILURE);
528    }
659  strlcpy(me.name, ServerInfo.name, sizeof(me.name));
529  
530 <  /* serverinfo{} description must exist.  If not, error out.*/
531 <  if (ServerInfo.description == NULL)
530 >  strlcpy(me.name, ConfigServerInfo.name, sizeof(me.name));
531 >
532 >  /* serverinfo {} description must exist.  If not, error out.*/
533 >  if (EmptyString(ConfigServerInfo.description))
534    {
535 <    ilog(L_CRIT,
665 <      "ERROR: No server description specified in serverinfo block.");
535 >    ilog(LOG_TYPE_IRCD, "ERROR: No server description specified in serverinfo block.");
536      exit(EXIT_FAILURE);
537    }
668  strlcpy(me.info, ServerInfo.description, sizeof(me.info));
538  
539 <  me.from    = &me;
539 >  strlcpy(me.info, ConfigServerInfo.description, sizeof(me.info));
540 >
541 >  if (EmptyString(ConfigServerInfo.sid))
542 >  {
543 >    ilog(LOG_TYPE_IRCD, "Generating server ID");
544 >    generate_sid();
545 >  }
546 >  else
547 >    strlcpy(me.id, ConfigServerInfo.sid, sizeof(me.id));
548 >
549 >  init_uid();
550 >
551 >  me.from = &me;
552    me.servptr = &me;
553 +  me.connection->lasttime = CurrentTime;
554 +  me.connection->since = CurrentTime;
555 +  me.connection->firsttime = CurrentTime;
556  
557    SetMe(&me);
558    make_server(&me);
559  
560 <  me.lasttime = me.since = me.firsttime = CurrentTime;
560 >  hash_add_id(&me);
561    hash_add_client(&me);
678  
679  /* add ourselves to global_serv_list */
680  dlinkAdd(&me, make_dlink_node(), &global_serv_list);
562  
563 <  check_class();
563 >  dlinkAdd(&me, make_dlink_node(), &global_server_list);
564 >  dlinkAdd(&me, &me.node, &global_client_list);
565  
566 < #ifndef STATIC_MODULES
567 <  if (chdir(MODPATH))
568 <  {
569 <    ilog (L_CRIT, "Could not load core modules. Terminating!");
688 <    exit(EXIT_FAILURE);
689 <  }
566 >  load_kline_database();
567 >  load_dline_database();
568 >  load_xline_database();
569 >  load_resv_database();
570  
571    load_all_modules(1);
572    load_conf_modules();
573    load_core_modules(1);
694  /* Go back to DPATH after checking to see if we can chdir to MODPATH */
695  chdir(ConfigFileEntry.dpath);
696 #else
697  load_all_modules(1);
698 #endif
699  /*
700   * assemble_umode_buffer() has to be called after
701   * reading conf/loading modules.
702   */
703  assemble_umode_buffer();
574  
575    write_pidfile(pidFileName);
576  
577 <  ilog(L_NOTICE, "Server Ready");
708 <
709 <  eventAddIsh("cleanup_glines", cleanup_glines, NULL, CLEANUP_GLINES_TIME);
710 <  eventAddIsh("cleanup_tklines", cleanup_tklines, NULL, CLEANUP_TKLINES_TIME);
577 >  event_addish(&event_cleanup_tklines, NULL);
578  
579    /* We want try_connections to be called as soon as possible now! -- adrian */
580    /* No, 'cause after a restart it would cause all sorts of nick collides */
581 <  eventAddIsh("try_connections", try_connections, NULL, STARTUP_CONNECTIONS_TIME);
715 <
716 <  eventAddIsh("collect_zipstats", collect_zipstats, NULL, ZIPSTATS_TIME);
581 >  event_addish(&event_try_connections, NULL);
582  
583    /* Setup the timeout check. I'll shift it later :)  -- adrian */
584 <  eventAddIsh("comm_checktimeouts", comm_checktimeouts, NULL, 1);
584 >  event_add(&event_comm_checktimeouts, NULL);
585  
586 <  if (ConfigServerHide.links_delay > 0)
722 <    eventAddIsh("write_links_file", write_links_file, NULL, ConfigServerHide.links_delay);
723 <  else
724 <    ConfigServerHide.links_disabled = 1;
586 >  event_addish(&event_save_all_databases, NULL);
587  
588 <  if (splitmode)
589 <    eventAddIsh("check_splitmode", check_splitmode, NULL, 60);
588 >  if (ConfigServerHide.flatten_links_delay && event_write_links_file.active == 0)
589 >  {
590 >    event_write_links_file.when = ConfigServerHide.flatten_links_delay;
591 >    event_add(&event_write_links_file, NULL);
592 >  }
593  
594 +  ilog(LOG_TYPE_IRCD, "Server Ready");
595    io_loop();
596 <  return(0);
596 >
597 >  return 0;
598   }

Comparing:
ircd-hybrid/src/ircd.c (property svn:keywords), Revision 32 by knight, Sun Oct 2 20:41:23 2005 UTC vs.
ircd-hybrid/trunk/src/ircd.c (property svn:keywords), Revision 6802 by michael, Wed Nov 18 11:25:16 2015 UTC

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

Diff Legend

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