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/trunk/src/s_bsd.c (file contents):
Revision 2235 by michael, Sat Jun 15 18:14:12 2013 UTC vs.
Revision 2881 by michael, Mon Jan 20 17:15:39 2014 UTC

# 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 139 | 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   {
145  int fd = va_arg(args, int);
143    int opt = 1;
144  
145    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(opt));
# Line 153 | Line 150 | setup_socket(va_list args)
150   #endif
151  
152    fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
156
157  return NULL;
158 }
159
160 /*
161 * init_comm()
162 *
163 * Initializes comm subsystem.
164 */
165 void
166 init_comm(void)
167 {
168  setup_socket_cb = register_callback("setup_socket", setup_socket);
169  init_netio();
153   }
154  
155   /*
# Line 188 | Line 171 | close_connection(struct Client *client_p
171       * even if it is marked as blocked (COMM_SELECT_READ handler is called
172       * before COMM_SELECT_WRITE). Let's try, nothing to lose.. -adx
173       */
191    ClearSendqBlocked(client_p);
174      send_queued_write(client_p);
175    }
176  
# Line 252 | Line 234 | static void
234   ssl_handshake(int fd, struct Client *client_p)
235   {
236    X509 *cert = NULL;
237 <  int ret = SSL_accept(client_p->localClient->fd.ssl);
238 <  int err = SSL_get_error(client_p->localClient->fd.ssl, ret);
237 >  int ret = 0;
238 >
239 >  if ((ret = SSL_accept(client_p->localClient->fd.ssl)) <= 0)
240 >  {
241 >    if ((CurrentTime - client_p->localClient->firsttime) > 30)
242 >    {
243 >      exit_client(client_p, client_p, "Timeout during SSL handshake");
244 >      return;
245 >    }
246 >
247 >    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
248 >    {
249 >      case SSL_ERROR_WANT_WRITE:
250 >        comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
251 >                       (PF *) ssl_handshake, client_p, 30);
252 >        return;
253 >
254 >      case SSL_ERROR_WANT_READ:
255 >        comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
256 >                       (PF *) ssl_handshake, client_p, 30);
257 >        return;
258 >
259 >      default:
260 >        exit_client(client_p, client_p, "Error during SSL handshake");
261 >        return;
262 >    }
263 >  }
264  
265 <  ilog(LOG_TYPE_IRCD, "SSL Error %d %s", err, ERR_error_string(err, NULL));
265 >  comm_settimeout(&client_p->localClient->fd, 0, NULL, NULL);
266  
267    if ((cert = SSL_get_peer_certificate(client_p->localClient->fd.ssl)))
268    {
269      int res = SSL_get_verify_result(client_p->localClient->fd.ssl);
270      char buf[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
271 <    unsigned char md[EVP_MAX_MD_SIZE * 2 + 1] = { '\0' };
271 >    unsigned char md[EVP_MAX_MD_SIZE] = { '\0' };
272  
273      if (res == X509_V_OK || res == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN ||
274          res == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE ||
# Line 282 | Line 289 | ssl_handshake(int fd, struct Client *cli
289      X509_free(cert);
290    }
291  
285  if (ret <= 0)
286  {
287    switch (SSL_get_error(client_p->localClient->fd.ssl, ret))
288    {
289      case SSL_ERROR_WANT_WRITE:
290        comm_setselect(&client_p->localClient->fd, COMM_SELECT_WRITE,
291                       (PF *) ssl_handshake, client_p, 0);
292        return;
293
294      case SSL_ERROR_WANT_READ:
295        comm_setselect(&client_p->localClient->fd, COMM_SELECT_READ,
296                       (PF *) ssl_handshake, client_p, 0);
297        return;
298
299      default:
300        exit_client(client_p, client_p, "Error during SSL handshake");
301        return;
302    }
303  }
304
292    start_auth(client_p);
293   }
294   #endif
# Line 368 | Line 355 | add_connection(struct Listener *listener
355        return;
356      }
357  
358 +    AddFlag(new_client, FLAGS_SSL);
359      SSL_set_fd(new_client->localClient->fd.ssl, fd);
360      ssl_handshake(0, new_client);
361    }
# Line 714 | Line 702 | comm_open(fde_t *F, int family, int sock
702    if (fd < 0)
703      return -1; /* errno will be passed through, yay.. */
704  
705 <  execute_callback(setup_socket_cb, fd);
705 >  setup_socket(fd);
706  
707    /* update things in our fd tracking */
708    fd_open(F, fd, 1, note);
# Line 755 | Line 743 | comm_accept(struct Listener *lptr, struc
743    pn->ss_len = addrlen;
744   #endif
745  
746 <  execute_callback(setup_socket_cb, newfd);
746 >  setup_socket(newfd);
747  
748    /* .. and return */
749    return newfd;

Diff Legend

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