Normalize debug message
[freeradius.git] / src / main / tls_listen.c
1 /*
2  * tls.c
3  *
4  * Version:     $Id$
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
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  *
20  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
21  * Copyright 2003  Alan DeKok <aland@freeradius.org>
22  * Copyright 2006  The FreeRADIUS server project
23  */
24
25 RCSID("$Id$")
26 USES_APPLE_DEPRECATED_API       /* OpenSSL API has been deprecated by Apple */
27
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/process.h>
30 #include <freeradius-devel/rad_assert.h>
31
32 #ifdef HAVE_SYS_STAT_H
33 #include <sys/stat.h>
34 #endif
35
36 #ifdef WITH_TLS
37 #ifdef HAVE_OPENSSL_RAND_H
38 #include <openssl/rand.h>
39 #endif
40
41 #ifdef HAVE_OPENSSL_OCSP_H
42 #include <openssl/ocsp.h>
43 #endif
44
45 #ifdef HAVE_PTHREAD_H
46 #define PTHREAD_MUTEX_LOCK pthread_mutex_lock
47 #define PTHREAD_MUTEX_UNLOCK pthread_mutex_unlock
48 #else
49 #define PTHREAD_MUTEX_LOCK(_x)
50 #define PTHREAD_MUTEX_UNLOCK(_x)
51 #endif
52
53 static void dump_hex(char const *msg, uint8_t const *data, size_t data_len)
54 {
55         size_t i;
56
57         if (debug_flag < 3) return;
58
59         printf("%s %d\n", msg, (int) data_len);
60         if (data_len > 256) data_len = 256;
61
62         for (i = 0; i < data_len; i++) {
63                 if ((i & 0x0f) == 0x00) printf ("%02x: ", (unsigned int) i);
64                 printf("%02x ", data[i]);
65                 if ((i & 0x0f) == 0x0f) printf ("\n");
66         }
67         printf("\n");
68         fflush(stdout);
69 }
70
71 static void tls_socket_close(rad_listen_t *listener)
72 {
73         listen_socket_t *sock = listener->data;
74
75         SSL_shutdown(sock->ssn->ssl);
76
77         listener->status = RAD_LISTEN_STATUS_EOL;
78         listener->tls = NULL; /* parent owns this! */
79
80         if (sock->parent) {
81                 /*
82                  *      Decrement the number of connections.
83                  */
84                 if (sock->parent->limit.num_connections > 0) {
85                         sock->parent->limit.num_connections--;
86                 }
87                 if (sock->client->limit.num_connections > 0) {
88                         sock->client->limit.num_connections--;
89                 }
90         }
91
92         /*
93          *      Tell the event handler that an FD has disappeared.
94          */
95         DEBUG("Client has closed connection");
96         radius_add_listener(listener);
97
98         /*
99          *      Do NOT free the listener here.  It's in use by
100          *      a request, and will need to hang around until
101          *      all of the requests are done.
102          *
103          *      It is instead free'd in remove_from_request_hash()
104          */
105 }
106
107 static int CC_HINT(nonnull) tls_socket_write(rad_listen_t *listener, REQUEST *request)
108 {
109         uint8_t *p;
110         ssize_t rcode;
111         listen_socket_t *sock = listener->data;
112
113         p = sock->ssn->dirty_out.data;
114
115         while (p < (sock->ssn->dirty_out.data + sock->ssn->dirty_out.used)) {
116                 RDEBUG3("Writing to socket %d", request->packet->sockfd);
117                 rcode = write(request->packet->sockfd, p,
118                               (sock->ssn->dirty_out.data + sock->ssn->dirty_out.used) - p);
119                 if (rcode <= 0) {
120                         RDEBUG("Error writing to TLS socket: %s", fr_syserror(errno));
121
122                         tls_socket_close(listener);
123                         return 0;
124                 }
125                 p += rcode;
126         }
127
128         sock->ssn->dirty_out.used = 0;
129
130         return 1;
131 }
132
133
134 static int tls_socket_recv(rad_listen_t *listener)
135 {
136         bool doing_init = false;
137         ssize_t rcode;
138         RADIUS_PACKET *packet;
139         REQUEST *request;
140         listen_socket_t *sock = listener->data;
141         fr_tls_status_t status;
142         RADCLIENT *client = sock->client;
143
144         if (!sock->packet) {
145                 sock->packet = rad_alloc(sock, 0);
146                 if (!sock->packet) return 0;
147
148                 sock->packet->sockfd = listener->fd;
149                 sock->packet->src_ipaddr = sock->other_ipaddr;
150                 sock->packet->src_port = sock->other_port;
151                 sock->packet->dst_ipaddr = sock->my_ipaddr;
152                 sock->packet->dst_port = sock->my_port;
153
154                 if (sock->request) {
155                         (void) talloc_steal(sock->request, sock->packet);
156                         sock->request->packet = sock->packet;
157                 }
158         }
159
160         /*
161          *      Allocate a REQUEST for debugging.
162          */
163         if (!sock->request) {
164                 sock->request = request = request_alloc(NULL);
165                 if (!sock->request) {
166                         ERROR("Out of memory");
167                         return 0;
168                 }
169
170                 rad_assert(request->packet == NULL);
171                 rad_assert(sock->packet != NULL);
172                 request->packet = sock->packet;
173
174                 request->component = "<core>";
175                 request->component = "<tls-connect>";
176
177                 /*
178                  *      Not sure if we should do this on every packet...
179                  */
180                 request->reply = rad_alloc(request, 0);
181                 if (!request->reply) return 0;
182
183                 rad_assert(sock->ssn == NULL);
184
185                 sock->ssn = tls_new_session(listener->tls, sock->request,
186                                             listener->tls->require_client_cert);
187                 if (!sock->ssn) {
188                         request_free(&sock->request);
189                         sock->packet = NULL;
190                         return 0;
191                 }
192
193                 (void) talloc_steal(sock, sock->ssn);
194                 SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_REQUEST, (void *)request);
195                 SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_CERTS, (void *)&request->packet->vps);
196                 SSL_set_ex_data(sock->ssn->ssl, FR_TLS_EX_INDEX_TALLOC, sock->parent);
197
198                 doing_init = true;
199         }
200
201         rad_assert(sock->request != NULL);
202         rad_assert(sock->request->packet != NULL);
203         rad_assert(sock->packet != NULL);
204         rad_assert(sock->ssn != NULL);
205
206         request = sock->request;
207
208         RDEBUG3("Reading from socket %d", request->packet->sockfd);
209         PTHREAD_MUTEX_LOCK(&sock->mutex);
210         rcode = read(request->packet->sockfd,
211                      sock->ssn->dirty_in.data,
212                      sizeof(sock->ssn->dirty_in.data));
213         if ((rcode < 0) && (errno == ECONNRESET)) {
214         do_close:
215                 DEBUG("Closing TLS socket from client port %u", sock->other_port);
216                 tls_socket_close(listener);
217                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
218                 return 0;
219         }
220
221         if (rcode < 0) {
222                 RDEBUG("Error reading TLS socket: %s", fr_syserror(errno));
223                 goto do_close;
224         }
225
226         /*
227          *      Normal socket close.
228          */
229         if (rcode == 0) goto do_close;
230
231         sock->ssn->dirty_in.used = rcode;
232
233         dump_hex("READ FROM SSL", sock->ssn->dirty_in.data, sock->ssn->dirty_in.used);
234
235         /*
236          *      Catch attempts to use non-SSL.
237          */
238         if (doing_init && (sock->ssn->dirty_in.data[0] != handshake)) {
239                 RDEBUG("Non-TLS data sent to TLS socket: closing");
240                 goto do_close;
241         }
242
243         /*
244          *      Skip ahead to reading application data.
245          */
246         if (SSL_is_init_finished(sock->ssn->ssl)) goto app;
247
248         if (!tls_handshake_recv(request, sock->ssn)) {
249                 RDEBUG("FAILED in TLS handshake receive");
250                 goto do_close;
251         }
252
253         if (sock->ssn->dirty_out.used > 0) {
254                 tls_socket_write(listener, request);
255                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
256                 return 0;
257         }
258
259 app:
260         /*
261          *      FIXME: Run the packet through a virtual server in
262          *      order to see if we like the certificate presented by
263          *      the client.
264          */
265
266         status = tls_application_data(sock->ssn, request);
267         RDEBUG("Application data status %d", status);
268
269         if (status == FR_TLS_MORE_FRAGMENTS) {
270                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
271                 return 0;
272         }
273
274         if (sock->ssn->clean_out.used == 0) {
275                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
276                 return 0;
277         }
278
279         dump_hex("TUNNELED DATA", sock->ssn->clean_out.data, sock->ssn->clean_out.used);
280
281         /*
282          *      If the packet is a complete RADIUS packet, return it to
283          *      the caller.  Otherwise...
284          */
285         if ((sock->ssn->clean_out.used < 20) ||
286             (((sock->ssn->clean_out.data[2] << 8) | sock->ssn->clean_out.data[3]) != (int) sock->ssn->clean_out.used)) {
287                 RDEBUG("Received bad packet: Length %d contents %d",
288                        sock->ssn->clean_out.used,
289                        (sock->ssn->clean_out.data[2] << 8) | sock->ssn->clean_out.data[3]);
290                 goto do_close;
291         }
292
293         packet = sock->packet;
294         packet->data = talloc_array(packet, uint8_t, sock->ssn->clean_out.used);
295         packet->data_len = sock->ssn->clean_out.used;
296         sock->ssn->record_minus(&sock->ssn->clean_out, packet->data, packet->data_len);
297         packet->vps = NULL;
298         PTHREAD_MUTEX_UNLOCK(&sock->mutex);
299
300         if (!rad_packet_ok(packet, 0, NULL)) {
301                 RDEBUG("Received bad packet: %s", fr_strerror());
302                 DEBUG("Closing TLS socket from client");
303                 PTHREAD_MUTEX_LOCK(&sock->mutex);
304                 tls_socket_close(listener);
305                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
306                 return 0;       /* do_close unlocks the mutex */
307         }
308
309         /*
310          *      Copied from src/lib/radius.c, rad_recv();
311          */
312         if (fr_debug_flag) {
313                 char host_ipaddr[128];
314
315                 if (is_radius_code(packet->code)) {
316                         RDEBUG("tls_recv: %s packet from host %s port %d, id=%d, length=%d",
317                                fr_packet_codes[packet->code],
318                                inet_ntop(packet->src_ipaddr.af,
319                                          &packet->src_ipaddr.ipaddr,
320                                          host_ipaddr, sizeof(host_ipaddr)),
321                                packet->src_port,
322                                packet->id, (int) packet->data_len);
323                 } else {
324                         RDEBUG("tls_recv: Packet from host %s port %d code=%d, id=%d, length=%d",
325                                inet_ntop(packet->src_ipaddr.af,
326                                          &packet->src_ipaddr.ipaddr,
327                                          host_ipaddr, sizeof(host_ipaddr)),
328                                packet->src_port,
329                                packet->code,
330                                packet->id, (int) packet->data_len);
331                 }
332         }
333
334         FR_STATS_INC(auth, total_requests);
335
336         return 1;
337 }
338
339
340 int dual_tls_recv(rad_listen_t *listener)
341 {
342         RADIUS_PACKET *packet;
343         REQUEST *request;
344         RAD_REQUEST_FUNP fun = NULL;
345         listen_socket_t *sock = listener->data;
346         RADCLIENT       *client = sock->client;
347
348         if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
349
350         if (!tls_socket_recv(listener)) {
351                 return 0;
352         }
353
354         rad_assert(sock->request != NULL);
355         rad_assert(sock->request->packet != NULL);
356         rad_assert(sock->packet != NULL);
357         rad_assert(sock->ssn != NULL);
358         rad_assert(client != NULL);
359
360         request = sock->request;
361         packet = sock->packet;
362
363         /*
364          *      Some sanity checks, based on the packet code.
365          *
366          *      "auth+acct" are marked as "auth", with the "dual" flag
367          *      set.
368          */
369         switch(packet->code) {
370         case PW_CODE_AUTHENTICATION_REQUEST:
371                 if (listener->type != RAD_LISTEN_AUTH) goto bad_packet;
372                 FR_STATS_INC(auth, total_requests);
373                 fun = rad_authenticate;
374                 break;
375
376 #ifdef WITH_ACCOUNTING
377         case PW_CODE_ACCOUNTING_REQUEST:
378                 if (listener->type != RAD_LISTEN_ACCT) {
379                         /*
380                          *      Allow auth + dual.  Disallow
381                          *      everything else.
382                          */
383                         if (!((listener->type == RAD_LISTEN_AUTH) &&
384                               (listener->dual))) {
385                                     goto bad_packet;
386                         }
387                 }
388                 FR_STATS_INC(acct, total_requests);
389                 fun = rad_accounting;
390                 break;
391 #endif
392
393         case PW_CODE_STATUS_SERVER:
394                 if (!mainconfig.status_server) {
395                         FR_STATS_INC(auth, total_unknown_types);
396                         WDEBUG("Ignoring Status-Server request due to security configuration");
397                         rad_free(&sock->packet);
398                         request->packet = NULL;
399                         return 0;
400                 }
401                 fun = rad_status_server;
402                 break;
403
404         default:
405         bad_packet:
406                 FR_STATS_INC(auth, total_unknown_types);
407
408                 DEBUG("Invalid packet code %d sent from client %s port %d : IGNORED",
409                       packet->code, client->shortname, packet->src_port);
410                 rad_free(&sock->packet);
411                 request->packet = NULL;
412                 return 0;
413         } /* switch over packet types */
414
415         if (!request_receive(listener, packet, client, fun)) {
416                 FR_STATS_INC(auth, total_packets_dropped);
417                 rad_free(&sock->packet);
418                 request->packet = NULL;
419                 return 0;
420         }
421
422         sock->packet = NULL;    /* we have no need for more partial reads */
423         request->packet = NULL;
424
425         return 1;
426 }
427
428
429 /*
430  *      Send a response packet
431  */
432 int dual_tls_send(rad_listen_t *listener, REQUEST *request)
433 {
434         listen_socket_t *sock = listener->data;
435
436         VERIFY_REQUEST(request);
437
438         rad_assert(request->listener == listener);
439         rad_assert(listener->send == dual_tls_send);
440
441         if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
442
443         /*
444          *      Accounting reject's are silently dropped.
445          *
446          *      We do it here to avoid polluting the rest of the
447          *      code with this knowledge
448          */
449         if (request->reply->code == 0) return 0;
450
451         /*
452          *      Pack the VPs
453          */
454         if (rad_encode(request->reply, request->packet,
455                        request->client->secret) < 0) {
456                 RERROR("Failed encoding packet: %s", fr_strerror());
457                 return 0;
458         }
459
460         /*
461          *      Sign the packet.
462          */
463         if (rad_sign(request->reply, request->packet,
464                        request->client->secret) < 0) {
465                 RERROR("Failed signing packet: %s", fr_strerror());
466                 return 0;
467         }
468
469         PTHREAD_MUTEX_LOCK(&sock->mutex);
470         /*
471          *      Write the packet to the SSL buffers.
472          */
473         sock->ssn->record_plus(&sock->ssn->clean_in,
474                                request->reply->data, request->reply->data_len);
475
476         /*
477          *      Do SSL magic to get encrypted data.
478          */
479         tls_handshake_send(request, sock->ssn);
480
481         /*
482          *      And finally write the data to the socket.
483          */
484         if (sock->ssn->dirty_out.used > 0) {
485                 dump_hex("WRITE TO SSL", sock->ssn->dirty_out.data, sock->ssn->dirty_out.used);
486
487                 tls_socket_write(listener, request);
488         }
489         PTHREAD_MUTEX_UNLOCK(&sock->mutex);
490
491         return 0;
492 }
493
494
495 #ifdef WITH_PROXY
496 /*
497  *      Read from the SSL socket.  Safe with either blocking or
498  *      non-blocking IO.  This level of complexity is probably not
499  *      necessary, as each packet gets put into one SSL application
500  *      record.  When SSL has a full record, we should be able to read
501  *      the entire packet via one SSL_read().
502  *
503  *      When SSL has a partial record, SSL_read() will return
504  *      WANT_READ or WANT_WRITE, and zero application data.
505  *
506  *      Called with the mutex held.
507  */
508 static ssize_t proxy_tls_read(rad_listen_t *listener)
509 {
510         int rcode;
511         size_t length;
512         uint8_t *data;
513         listen_socket_t *sock = listener->data;
514
515         /*
516          *      Get the maximum size of data to receive.
517          */
518         if (!sock->data) sock->data = talloc_array(sock, uint8_t,
519                                                    sock->ssn->offset);
520
521         data = sock->data;
522
523         if (sock->partial < 4) {
524                 rcode = SSL_read(sock->ssn->ssl, data + sock->partial,
525                                  4 - sock->partial);
526                 if (rcode <= 0) {
527                         int err = SSL_get_error(sock->ssn->ssl, rcode);
528                         switch (err) {
529                         case SSL_ERROR_WANT_READ:
530                         case SSL_ERROR_WANT_WRITE:
531                                 return 0; /* do some more work later */
532
533                         case SSL_ERROR_ZERO_RETURN:
534                                 /* remote end sent close_notify, send one back */
535                                 SSL_shutdown(sock->ssn->ssl);
536
537                         case SSL_ERROR_SYSCALL:
538                         do_close:
539                                 return -1;
540
541                         default:
542                                 while ((err = ERR_get_error())) {
543                                         DEBUG("proxy recv says %s",
544                                               ERR_error_string(err, NULL));
545                                 }
546
547                                 goto do_close;
548                         }
549                 }
550
551                 sock->partial = rcode;
552         } /* try reading the packet header */
553
554         if (sock->partial < 4) return 0; /* read more data */
555
556         length = (data[2] << 8) | data[3];
557
558         /*
559          *      Do these checks only once, when we read the header.
560          */
561         if (sock->partial == 4) {
562                 DEBUG3("Proxy received header saying we have a packet of %u bytes",
563                        (unsigned int) length);
564
565                 /*
566                  *      FIXME: allocate a RADIUS_PACKET, and set
567                  *      "data" to be as large as necessary.
568                  */
569                 if (length > sock->ssn->offset) {
570                         INFO("Received packet will be too large! Set \"fragment_size = %u\"",
571                              (data[2] << 8) | data[3]);
572                         goto do_close;
573                 }
574         }
575
576         /*
577          *      Try to read some more.
578          */
579         if (sock->partial < length) {
580                 rcode = SSL_read(sock->ssn->ssl, data + sock->partial,
581                                  length - sock->partial);
582                 if (rcode <= 0) {
583                         switch (SSL_get_error(sock->ssn->ssl, rcode)) {
584                         case SSL_ERROR_WANT_READ:
585                         case SSL_ERROR_WANT_WRITE:
586                                 return 0;
587
588                         case SSL_ERROR_ZERO_RETURN:
589                                 /* remote end sent close_notify, send one back */
590                                 SSL_shutdown(sock->ssn->ssl);
591                                 goto do_close;
592                         default:
593                                 goto do_close;
594                         }
595                 }
596
597                 sock->partial += rcode;
598         }
599
600         /*
601          *      If we're not done, say so.
602          *
603          *      Otherwise, reset the partially read data flag, and say
604          *      we have a packet.
605          */
606         if (sock->partial < length) {
607                 return 0;
608         }
609
610         sock->partial = 0;      /* we've now read the packet */
611         return length;
612 }
613
614
615 int proxy_tls_recv(rad_listen_t *listener)
616 {
617         listen_socket_t *sock = listener->data;
618         char buffer[256];
619         RADIUS_PACKET *packet;
620         uint8_t *data;
621         ssize_t data_len;
622
623         if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
624
625         DEBUG3("Proxy SSL socket has data to read");
626         PTHREAD_MUTEX_LOCK(&sock->mutex);
627         data_len = proxy_tls_read(listener);
628         PTHREAD_MUTEX_UNLOCK(&sock->mutex);
629
630         if (data_len < 0) {
631                 DEBUG("Closing TLS socket to home server");
632                 PTHREAD_MUTEX_LOCK(&sock->mutex);
633                 tls_socket_close(listener);
634                 PTHREAD_MUTEX_UNLOCK(&sock->mutex);
635                 return 0;
636         }
637
638         if (data_len == 0) return 0; /* not done yet */
639
640         data = sock->data;
641
642         packet = rad_alloc(sock, 0);
643         packet->sockfd = listener->fd;
644         packet->src_ipaddr = sock->other_ipaddr;
645         packet->src_port = sock->other_port;
646         packet->dst_ipaddr = sock->my_ipaddr;
647         packet->dst_port = sock->my_port;
648         packet->code = data[0];
649         packet->id = data[1];
650         packet->data_len = data_len;
651         packet->data = talloc_array(packet, uint8_t, packet->data_len);
652         memcpy(packet->data, data, packet->data_len);
653         memcpy(packet->vector, packet->data + 4, 16);
654
655         /*
656          *      FIXME: Client MIB updates?
657          */
658         switch(packet->code) {
659         case PW_CODE_AUTHENTICATION_ACK:
660         case PW_CODE_ACCESS_CHALLENGE:
661         case PW_CODE_AUTHENTICATION_REJECT:
662                 break;
663
664 #ifdef WITH_ACCOUNTING
665         case PW_CODE_ACCOUNTING_RESPONSE:
666                 break;
667 #endif
668
669         default:
670                 /*
671                  *      FIXME: Update MIB for packet types?
672                  */
673                 ERROR("Invalid packet code %d sent to a proxy port "
674                        "from home server %s port %d - ID %d : IGNORED",
675                        packet->code,
676                        ip_ntoh(&packet->src_ipaddr, buffer, sizeof(buffer)),
677                        packet->src_port, packet->id);
678                 rad_free(&packet);
679                 return 0;
680         }
681
682         if (!request_proxy_reply(packet)) {
683                 rad_free(&packet);
684                 return 0;
685         }
686
687         return 1;
688 }
689
690
691 int proxy_tls_send(rad_listen_t *listener, REQUEST *request)
692 {
693         int rcode;
694         listen_socket_t *sock = listener->data;
695
696         VERIFY_REQUEST(request);
697
698         if (listener->status != RAD_LISTEN_STATUS_KNOWN) return 0;
699
700         /*
701          *      Normal proxying calls us with the data already
702          *      encoded.  The "ping home server" code does not.  So,
703          *      if there's no packet, encode it here.
704          */
705         if (!request->proxy->data) {
706                 request->proxy_listener->encode(request->proxy_listener,
707                                                 request);
708         }
709
710         DEBUG3("Proxy is writing %u bytes to SSL",
711                (unsigned int) request->proxy->data_len);
712         PTHREAD_MUTEX_LOCK(&sock->mutex);
713         rcode = SSL_write(sock->ssn->ssl, request->proxy->data,
714                           request->proxy->data_len);
715         if (rcode < 0) {
716                 int err;
717
718                 err = ERR_get_error();
719                 switch (err) {
720                 case SSL_ERROR_NONE:
721                 case SSL_ERROR_WANT_READ:
722                 case SSL_ERROR_WANT_WRITE:
723                         break;  /* let someone else retry */
724
725                 default:
726                         DEBUG("proxy SSL_write says %s",
727                               ERR_error_string(err, NULL));
728                         DEBUG("Closing TLS socket to home server");
729                         tls_socket_close(listener);
730                         PTHREAD_MUTEX_UNLOCK(&sock->mutex);
731                         return 0;
732                 }
733         }
734         PTHREAD_MUTEX_UNLOCK(&sock->mutex);
735
736         return 1;
737 }
738 #endif  /* WITH_PROXY */
739
740 #endif  /* WITH_TLS */