ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/s_bsd.c
(Generate patch)

Comparing:
ircd-hybrid-8/src/s_bsd.c (file contents), Revision 1302 by michael, Wed Mar 21 17:48:54 2012 UTC vs.
ircd-hybrid/trunk/src/s_bsd.c (file contents), Revision 2733 by michael, Fri Jan 3 17:30:13 2014 UTC

# Line 40 | Line 40
40   #include "irc_res.h"
41   #include "restart.h"
42   #include "s_auth.h"
43 < #include "s_conf.h"
44 < #include "s_log.h"
43 > #include "conf.h"
44 > #include "log.h"
45   #include "s_serv.h"
46   #include "send.h"
47   #include "memory.h"
# Line 52 | Line 52 | static const char *comm_err_str[] = { "C
52    "Error during DNS lookup", "connect timeout", "Error during connect()",
53    "Comm Error" };
54  
55 struct Callback *setup_socket_cb = NULL;
56
55   static void comm_connect_callback(fde_t *, int);
56   static PF comm_connect_timeout;
57   static void comm_connect_dns_callback(void *, const struct irc_ssaddr *, const char *);
# Line 129 | Line 127 | report_error(int level, const char* text
127   {
128    who = (who) ? who : "";
129  
130 <  sendto_realops_flags(UMODE_DEBUG, level, text, who, strerror(error));
130 >  sendto_realops_flags(UMODE_DEBUG, level, SEND_NOTICE,
131 >                       text, who, strerror(error));
132    ilog(LOG_TYPE_IRCD, text, who, strerror(error));
133   }
134  
# Line 138 | Line 137 | report_error(int level, const char* text
137   *
138   * Set the socket non-blocking, and other wonderful bits.
139   */
140 < static void *
141 < setup_socket(va_list args)
140 > static void
141 > setup_socket(int fd)
142   {
144  int fd = va_arg(args, int);
143    int opt = 1;
144  
145    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
# Line 152 | Line 150 | setup_socket(va_list args)
150   #endif
151  
152    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
155
156  return NULL;
157 }
158
159 /*
160 * init_comm()
161 *
162 * Initializes comm subsystem.
163 */
164 void
165 init_comm(void)
166 {
167  setup_socket_cb = register_callback("setup_socket", setup_socket);
168  init_netio();
153   }
154  
155   /*
# Line 176 | Line 160 | init_comm(void)
160   void
161   close_connection(struct Client *client_p)
162   {
163 <  struct ConfItem *conf;
180 <  struct AccessItem *aconf;
181 <  struct ClassItem *aclass;
163 >  dlink_node *ptr = NULL;
164  
165 <  assert(NULL != client_p);
165 >  assert(client_p);
166  
167    if (!IsDead(client_p))
168    {
# Line 207 | Line 189 | close_connection(struct Client *client_p
189      ServerStats.is_sbr += client_p->localClient->recv.bytes;
190      ServerStats.is_sti += CurrentTime - client_p->localClient->firsttime;
191  
192 <    /* XXX Does this even make any sense at all anymore?
211 <     * scheduling a 'quick' reconnect could cause a pile of
212 <     * nick collides under TSora protocol... -db
213 <     */
214 <    /*
215 <     * If the connection has been up for a long amount of time, schedule
216 <     * a 'quick' reconnect, else reset the next-connect cycle.
217 <     */
218 <    if ((conf = find_conf_exact(SERVER_TYPE, client_p->name,
219 <                                client_p->username, client_p->host)))
192 >    DLINK_FOREACH(ptr, server_items.head)
193      {
194 +      struct MaskItem *conf = ptr->data;
195 +
196 +      if (irccmp(conf->name, client_p->name))
197 +        continue;
198 +
199        /*
200 <       * Reschedule a faster reconnect, if this was a automatically
201 <       * connected configuration entry. (Note that if we have had
224 <       * a rehash in between, the status has been changed to
225 <       * CONF_ILLEGAL). But only do this if it was a "good" link.
200 >       * Reset next-connect cycle of all connect{} blocks that match
201 >       * this servername.
202         */
203 <      aconf  = map_to_conf(conf);
228 <      aclass = map_to_conf(aconf->class_ptr);
229 <      aconf->hold = time(NULL);
230 <      aconf->hold += (aconf->hold - client_p->localClient->since > HANGONGOODLINK) ?
231 <        HANGONRETRYDELAY : ConFreq(aclass);
203 >      conf->until = CurrentTime + conf->class->con_freq;
204      }
205    }
206    else
# Line 250 | Line 222 | close_connection(struct Client *client_p
222    dbuf_clear(&client_p->localClient->buf_recvq);
223    
224    MyFree(client_p->localClient->passwd);
225 <  detach_conf(client_p, CONF_TYPE);
225 >  detach_conf(client_p, CONF_CLIENT|CONF_OPER|CONF_SERVER);
226    client_p->from = NULL; /* ...this should catch them! >:) --msa */
227   }
228  
# Line 262 | Line 234 | close_connection(struct Client *client_p
234   static void
235   ssl_handshake(int fd, struct Client *client_p)
236   {
237 <  int ret = SSL_accept(client_p->localClient->fd.ssl);
237 >  X509 *cert = NULL;
238 >  int ret = 0;
239 >
240 >  if ((ret = SSL_accept(client_p->localClient->fd.ssl)) <= 0)
241 >  {
242 >    if ((CurrentTime - client_p->localClient->firsttime) > 30)
243 >    {
244 >      exit_client(client_p, client_p, "Timeout during SSL handshake");
245 >      return;
246 >    }
247  
267  if (ret <= 0)
248      switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
249      {
250        case SSL_ERROR_WANT_WRITE:
251          comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
252 <                       (PF *) ssl_handshake, client_p, 0);
252 >                       (PF *) ssl_handshake, client_p, 30);
253          return;
254  
255        case SSL_ERROR_WANT_READ:
256          comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
257 <                       (PF *) ssl_handshake, client_p, 0);
257 >                       (PF *) ssl_handshake, client_p, 30);
258          return;
259  
260        default:
261          exit_client(client_p, client_p, "Error during SSL handshake");
262          return;
263      }
264 +  }
265 +
266 +  comm_settimeout(&client_p->localClient->fd, 0, NULL, NULL);
267 +
268 +  if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
269 +  {
270 +    int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
271 +    char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
272 +    unsigned char md[EVP_MAX_MD_SIZE] = { '\0' };
273 +
274 +    if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
275 +        res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
276 +        res == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT)
277 +    {
278 +      unsigned int i = 0, n = 0;
279 +
280 +      if (X509_digest(cert, EVP_sha256(), md, &n))
281 +      {
282 +        for (; i < n; ++i)
283 +          snprintf(buf + 2 * i, 3, "%02X", md[i]);
284 +        client_p->certfp = xstrdup(buf);
285 +      }
286 +    }
287 +    else
288 +      ilog(LOG_TYPE_IRCD, "Client %s!%s@%s gave bad SSL client certificate: %d",
289 +           client_p->name, client_p->username, client_p->host, res);
290 +    X509_free(cert);
291 +  }
292  
293 <  execute_callback(auth_cb, client_p);
293 >  start_auth(client_p);
294   }
295   #endif
296  
# Line 313 | Line 321 | add_connection(struct Listener *listener
321                sizeof(new_client->sockhost), NULL, 0, NI_NUMERICHOST);
322    new_client->localClient->aftype = new_client->localClient->ip.ss.ss_family;
323  
324 + #ifdef HAVE_LIBGEOIP
325 +  /* XXX IPV6 SUPPORT XXX */
326 +  if (irn->ss.ss_family == AF_INET && geoip_ctx)
327 +  {
328 +    const struct sockaddr_in *v4 = (const struct sockaddr_in *)&new_client->localClient->ip;
329 +    new_client->localClient->country_id = GeoIP_id_by_ipnum(geoip_ctx, (unsigned long)ntohl(v4->sin_addr.s_addr));
330 +  }
331 + #endif
332 +
333    if (new_client->sockhost[0] == ':' && new_client->sockhost[1] == ':')
334    {
335      strlcpy(new_client->host, "0", sizeof(new_client->host));
# Line 339 | Line 356 | add_connection(struct Listener *listener
356        return;
357      }
358  
359 +    AddFlag(new_client, FLAGS_SSL);
360      SSL_set_fd(new_client->localClient->fd.ssl, fd);
361      ssl_handshake(0, new_client);
362    }
363    else
364   #endif
365 <    execute_callback(auth_cb, new_client);
365 >    start_auth(new_client);
366   }
367  
368   /*
# Line 685 | Line 703 | comm_open(fde_t *F, int family, int sock
703    if (fd < 0)
704      return -1; /* errno will be passed through, yay.. */
705  
706 <  execute_callback(setup_socket_cb, fd);
706 >  setup_socket(fd);
707  
708    /* update things in our fd tracking */
709    fd_open(F, fd, 1, note);
# Line 726 | Line 744 | comm_accept(struct Listener *lptr, struc
744    pn->ss_len = addrlen;
745   #endif
746  
747 <  execute_callback(setup_socket_cb, newfd);
747 >  setup_socket(newfd);
748  
749    /* .. and return */
750    return newfd;

Diff Legend

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