]> git.sur5r.net Git - openldap/blob - libraries/libldap/os-ip.c
ITS#2657: authzid (and assertion) should apply to most everything
[openldap] / libraries / libldap / os-ip.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6 /*  Portions
7  *  Copyright (c) 1995 Regents of the University of Michigan.
8  *  All rights reserved.
9  *
10  *  os-ip.c -- platform-specific TCP & UDP related code
11  */
12
13 #include "portable.h"
14
15 #include <stdio.h>
16
17 #include <ac/stdlib.h>
18
19 #include <ac/errno.h>
20 #include <ac/socket.h>
21 #include <ac/string.h>
22 #include <ac/time.h>
23 #include <ac/unistd.h>
24
25 #ifdef HAVE_IO_H
26 #include <io.h>
27 #endif /* HAVE_IO_H */
28
29 #include "ldap-int.h"
30
31 int ldap_int_tblsize = 0;
32
33 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
34 #  ifdef LDAP_PF_INET6
35 int ldap_int_inet4or6 = AF_UNSPEC;
36 #  else
37 int ldap_int_inet4or6 = AF_INET;
38 #  endif
39 #endif
40
41 /*
42  * nonblock connect code
43  * written by Lars Uffmann, <lars.uffmann@mediaway.net>.
44  *
45  * Copyright 1999, Lars Uffmann, All rights reserved.
46  * This software is not subject to any license of my employer
47  * mediaWays GmbH.
48  *
49  * OpenLDAP COPYING RESTRICTIONS APPLY, see COPYRIGHT file
50  *
51  * Read about the rationale in ldap_connect_timeout: 
52  * ftp://koobera.math.uic.edu/www/docs/connect.html.
53  */
54
55 #ifdef LDAP_DEBUG
56
57 #define osip_debug(ld,fmt,arg1,arg2,arg3) \
58 do { \
59         ldap_log_printf(NULL, LDAP_DEBUG_TRACE, fmt, arg1, arg2, arg3); \
60 } while(0)
61
62 #else
63
64 #define osip_debug(ld,fmt,arg1,arg2,arg3) ((void)0)
65
66 #endif /* LDAP_DEBUG */
67
68 static void
69 ldap_pvt_set_errno(int err)
70 {
71         errno = err;
72 }
73
74 int
75 ldap_int_timeval_dup( struct timeval **dest, const struct timeval *src )
76 {
77         struct timeval *new;
78
79         assert( dest != NULL );
80
81         if (src == NULL) {
82                 *dest = NULL;
83                 return 0;
84         }
85
86         new = (struct timeval *) LDAP_MALLOC(sizeof(struct timeval));
87
88         if( new == NULL ) {
89                 *dest = NULL;
90                 return 1;
91         }
92
93         AC_MEMCPY( (char *) new, (const char *) src, sizeof(struct timeval));
94
95         *dest = new;
96         return 0;
97 }
98
99 static int
100 ldap_pvt_ndelay_on(LDAP *ld, int fd)
101 {
102         osip_debug(ld, "ldap_ndelay_on: %d\n",fd,0,0);
103         return ber_pvt_socket_set_nonblock( fd, 1 );
104 }
105    
106 static int
107 ldap_pvt_ndelay_off(LDAP *ld, int fd)
108 {
109         osip_debug(ld, "ldap_ndelay_off: %d\n",fd,0,0);
110         return ber_pvt_socket_set_nonblock( fd, 0 );
111 }
112
113 static ber_socket_t
114 ldap_int_socket(LDAP *ld, int family, int type )
115 {
116         ber_socket_t s = socket(family, type, 0);
117         osip_debug(ld, "ldap_new_socket: %d\n",s,0,0);
118         return ( s );
119 }
120
121 static int
122 ldap_pvt_close_socket(LDAP *ld, int s)
123 {
124         osip_debug(ld, "ldap_close_socket: %d\n",s,0,0);
125         return tcp_close(s);
126 }
127
128 static int
129 ldap_int_prepare_socket(LDAP *ld, int s, int proto )
130 {
131         osip_debug(ld, "ldap_prepare_socket: %d\n", s,0,0);
132
133 #ifdef TCP_NODELAY
134         if( proto == LDAP_PROTO_TCP ) {
135                 int dummy = 1;
136                 if ( setsockopt( s, IPPROTO_TCP, TCP_NODELAY,
137                         (char*) &dummy, sizeof(dummy) ) == AC_SOCKET_ERROR )
138                 {
139                         osip_debug(ld, "ldap_prepare_socket: "
140                                 "setsockopt(%d, TCP_NODELAY) failed (ignored).\n",
141                                 s, 0, 0);
142                 }
143         }
144 #endif
145
146         return 0;
147 }
148
149 #ifndef HAVE_WINSOCK
150
151 #undef TRACE
152 #define TRACE do { \
153         osip_debug(ld, \
154                 "ldap_is_socket_ready: error on socket %d: errno: %d (%s)\n", \
155                 s, \
156                 errno, \
157                 sock_errstr(errno) ); \
158 } while( 0 )
159
160 /*
161  * check the socket for errors after select returned.
162  */
163 static int
164 ldap_pvt_is_socket_ready(LDAP *ld, int s)
165 {
166         osip_debug(ld, "ldap_is_sock_ready: %d\n",s,0,0);
167
168 #if defined( notyet ) /* && defined( SO_ERROR ) */
169 {
170         int so_errno;
171         socklen_t dummy = sizeof(so_errno);
172         if ( getsockopt( s, SOL_SOCKET, SO_ERROR, &so_errno, &dummy )
173                 == AC_SOCKET_ERROR )
174         {
175                 return -1;
176         }
177         if ( so_errno ) {
178                 ldap_pvt_set_errno(so_errno);
179                 TRACE;
180                 return -1;
181         }
182         return 0;
183 }
184 #else
185 {
186         /* error slippery */
187 #ifdef LDAP_PF_INET6
188         struct sockaddr_storage sin;
189 #else
190         struct sockaddr_in sin;
191 #endif
192         char ch;
193         socklen_t dummy = sizeof(sin);
194         if ( getpeername( s, (struct sockaddr *) &sin, &dummy )
195                 == AC_SOCKET_ERROR )
196         {
197                 /* XXX: needs to be replace with ber_stream_read() */
198                 read(s, &ch, 1);
199                 TRACE;
200                 return -1;
201         }
202         return 0;
203 }
204 #endif
205         return -1;
206 }
207 #undef TRACE
208
209 #endif /* HAVE_WINSOCK */
210
211 static int
212 ldap_pvt_connect(LDAP *ld, ber_socket_t s,
213         struct sockaddr *sin, socklen_t addrlen,
214         int async)
215 {
216         int rc;
217         struct timeval  tv, *opt_tv=NULL;
218         fd_set          wfds, *z=NULL;
219 #ifdef HAVE_WINSOCK
220         fd_set          efds;
221 #endif
222
223 #ifdef LDAP_CONNECTIONLESS
224         /* We could do a connect() but that would interfere with
225          * attempts to poll a broadcast address
226          */
227         if (LDAP_IS_UDP(ld)) {
228                 if (ld->ld_options.ldo_peer)
229                         ldap_memfree(ld->ld_options.ldo_peer);
230                 ld->ld_options.ldo_peer=ldap_memalloc(sizeof(struct sockaddr));
231                 AC_MEMCPY(ld->ld_options.ldo_peer,sin,sizeof(struct sockaddr));
232                 return ( 0 );
233         }
234 #endif
235         if ( (opt_tv = ld->ld_options.ldo_tm_net) != NULL ) {
236                 tv.tv_usec = opt_tv->tv_usec;
237                 tv.tv_sec = opt_tv->tv_sec;
238         }
239
240         osip_debug(ld, "ldap_connect_timeout: fd: %d tm: %ld async: %d\n",
241                         s, opt_tv ? tv.tv_sec : -1L, async);
242
243         if ( ldap_pvt_ndelay_on(ld, s) == -1 )
244                 return ( -1 );
245
246         if ( connect(s, sin, addrlen) != AC_SOCKET_ERROR ) {
247                 if ( ldap_pvt_ndelay_off(ld, s) == -1 )
248                         return ( -1 );
249                 return ( 0 );
250         }
251
252 #ifdef HAVE_WINSOCK
253         ldap_pvt_set_errno( WSAGetLastError() );
254 #endif
255
256         if ( errno != EINPROGRESS && errno != EWOULDBLOCK ) {
257                 return ( -1 );
258         }
259         
260 #ifdef notyet
261         if ( async ) return ( -2 );
262 #endif
263
264         FD_ZERO(&wfds);
265         FD_SET(s, &wfds );
266
267 #ifdef HAVE_WINSOCK
268         FD_ZERO(&efds);
269         FD_SET(s, &efds );
270 #endif
271
272         do {
273                 rc = select(ldap_int_tblsize, z, &wfds,
274 #ifdef HAVE_WINSOCK
275                         &efds,
276 #else
277                         z,
278 #endif
279                         opt_tv ? &tv : NULL);
280         } while( rc == AC_SOCKET_ERROR && errno == EINTR &&
281                 LDAP_BOOL_GET(&ld->ld_options, LDAP_BOOL_RESTART ));
282
283         if( rc == AC_SOCKET_ERROR ) return rc;
284
285 #ifdef HAVE_WINSOCK
286         /* This means the connection failed */
287         if ( FD_ISSET(s, &efds) ) {
288             int so_errno;
289             int dummy = sizeof(so_errno);
290             if ( getsockopt( s, SOL_SOCKET, SO_ERROR,
291                         (char *) &so_errno, &dummy ) == AC_SOCKET_ERROR || !so_errno )
292             {
293                 /* impossible */
294                 so_errno = WSAGetLastError();
295             }
296             ldap_pvt_set_errno(so_errno);
297             osip_debug(ld, "ldap_pvt_connect: error on socket %d: "
298                        "errno: %d (%s)\n", s, errno, sock_errstr(errno));
299             return -1;
300         }
301 #endif
302         if ( FD_ISSET(s, &wfds) ) {
303 #ifndef HAVE_WINSOCK
304                 if ( ldap_pvt_is_socket_ready(ld, s) == -1 )
305                         return ( -1 );
306 #endif
307                 if ( ldap_pvt_ndelay_off(ld, s) == -1 )
308                         return ( -1 );
309                 return ( 0 );
310         }
311         osip_debug(ld, "ldap_connect_timeout: timed out\n",0,0,0);
312         ldap_pvt_set_errno( ETIMEDOUT );
313         return ( -1 );
314 }
315
316 #ifndef HAVE_INET_ATON
317 int
318 ldap_pvt_inet_aton( const char *host, struct in_addr *in)
319 {
320         unsigned long u = inet_addr( host );
321         if ( u != 0xffffffff || u != (unsigned long) -1 ) {
322                 in->s_addr = u;
323                 return 1;
324         }
325         return 0;
326 }
327 #endif
328
329
330 int
331 ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
332         int proto,
333         const char *host, int port,
334         int async )
335 {
336         int     rc;
337         int     socktype;
338         ber_socket_t            s = AC_SOCKET_INVALID;
339
340 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
341         char serv[7];
342         int err;
343         struct addrinfo hints, *res, *sai;
344 #else
345         int i;
346         int use_hp = 0;
347         struct hostent *hp = NULL;
348         struct hostent he_buf;
349         struct in_addr in;
350         char *ha_buf=NULL;
351 #endif
352
353         if( host == NULL ) host = "localhost";
354         
355         switch(proto) {
356         case LDAP_PROTO_TCP: socktype = SOCK_STREAM;
357                 osip_debug( ld,
358                         "ldap_connect_to_host: TCP %s:%d\n",
359                         host, port, 0);
360                 break;
361         case LDAP_PROTO_UDP: socktype = SOCK_DGRAM;
362                 osip_debug( ld,
363                         "ldap_connect_to_host: UDP %s:%d\n",
364                         host, port, 0);
365                 break;
366         default:
367                 osip_debug( ld, "ldap_connect_to_host: unknown proto: %d\n",
368                         proto, 0, 0 );
369                 return -1;
370         }
371
372 #if defined( HAVE_GETADDRINFO ) && defined( HAVE_INET_NTOP )
373         memset( &hints, '\0', sizeof(hints) );
374         hints.ai_family = ldap_int_inet4or6;
375         hints.ai_socktype = socktype;
376         snprintf(serv, sizeof serv, "%d", port );
377
378 #ifdef LDAP_R_COMPILE
379         /* most getaddrinfo(3) use non-threadsafe resolver libraries */
380         ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
381 #endif
382
383         err = getaddrinfo( host, serv, &hints, &res );
384
385 #ifdef LDAP_R_COMPILE
386         ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex);
387 #endif
388
389         if ( err != 0 ) {
390                 osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
391                         AC_GAI_STRERROR(err), 0, 0);
392                 return -1;
393         }
394         rc = -1;
395
396         for( sai=res; sai != NULL; sai=sai->ai_next) {
397                 if( sai->ai_addr == NULL ) {
398                         osip_debug(ld, "ldap_connect_to_host: getaddrinfo "
399                                 "ai_addr is NULL?\n", 0, 0, 0);
400                         continue;
401                 }
402
403                 /* we assume AF_x and PF_x are equal for all x */
404                 s = ldap_int_socket( ld, sai->ai_family, socktype );
405                 if ( s == AC_SOCKET_INVALID ) {
406                         continue;
407                 }
408
409                 if ( ldap_int_prepare_socket(ld, s, proto ) == -1 ) {
410                         ldap_pvt_close_socket(ld, s);
411                         break;
412                 }
413
414                 switch (sai->ai_family) {
415 #ifdef LDAP_PF_INET6
416                         case AF_INET6: {
417                                 char addr[INET6_ADDRSTRLEN];
418                                 inet_ntop( AF_INET6,
419                                         &((struct sockaddr_in6 *)sai->ai_addr)->sin6_addr,
420                                         addr, sizeof addr);
421                                 osip_debug(ld, "ldap_connect_to_host: Trying %s %s\n", 
422                                         addr, serv, 0);
423                         } break;
424 #endif
425                         case AF_INET: {
426                                 char addr[INET_ADDRSTRLEN];
427                                 inet_ntop( AF_INET,
428                                         &((struct sockaddr_in *)sai->ai_addr)->sin_addr,
429                                         addr, sizeof addr);
430                                 osip_debug(ld, "ldap_connect_to_host: Trying %s:%s\n", 
431                                         addr, serv, 0);
432                         } break;
433                 }
434
435                 rc = ldap_pvt_connect( ld, s,
436                         sai->ai_addr, sai->ai_addrlen, async );
437                 if ( (rc == 0) || (rc == -2) ) {
438                         ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
439                         break;
440                 }
441                 ldap_pvt_close_socket(ld, s);
442         }
443         freeaddrinfo(res);
444
445 #else
446         if (! inet_aton( host, &in ) ) {
447                 int local_h_errno;
448                 rc = ldap_pvt_gethostbyname_a( host, &he_buf, &ha_buf,
449                         &hp, &local_h_errno );
450
451                 if ( (rc < 0) || (hp == NULL) ) {
452 #ifdef HAVE_WINSOCK
453                         ldap_pvt_set_errno( WSAGetLastError() );
454 #else
455                         /* not exactly right, but... */
456                         ldap_pvt_set_errno( EHOSTUNREACH );
457 #endif
458                         if (ha_buf) LDAP_FREE(ha_buf);
459                         return -1;
460                 }
461
462                 use_hp = 1;
463         }
464
465         rc = s = -1;
466         for ( i = 0; !use_hp || (hp->h_addr_list[i] != 0); ++i, rc = -1 ) {
467                 struct sockaddr_in      sin;
468
469                 s = ldap_int_socket( ld, PF_INET, socktype );
470                 if ( s == AC_SOCKET_INVALID ) {
471                         /* use_hp ? continue : break; */
472                         break;
473                 }
474            
475                 if ( ldap_int_prepare_socket( ld, s, proto ) == -1 ) {
476                         ldap_pvt_close_socket(ld, s);
477                         break;
478                 }
479
480                 (void)memset((char *)&sin, '\0', sizeof sin);
481                 sin.sin_family = AF_INET;
482                 sin.sin_port = htons((short) port);
483
484                 if( use_hp ) {
485                         AC_MEMCPY( &sin.sin_addr, hp->h_addr_list[i],
486                                 sizeof(sin.sin_addr) );
487                 } else {
488                         AC_MEMCPY( &sin.sin_addr, &in.s_addr,
489                                 sizeof(sin.sin_addr) );
490                 }
491
492                 osip_debug(ld, "ldap_connect_to_host: Trying %s:%d\n", 
493                         inet_ntoa(sin.sin_addr), port, 0);
494
495                 rc = ldap_pvt_connect(ld, s,
496                         (struct sockaddr *)&sin, sizeof(sin),
497                         async);
498    
499                 if ( (rc == 0) || (rc == -2) ) {
500                         ber_sockbuf_ctrl( sb, LBER_SB_OPT_SET_FD, &s );
501                         break;
502                 }
503
504                 ldap_pvt_close_socket(ld, s);
505
506                 if (!use_hp) break;
507         }
508         if (ha_buf) LDAP_FREE(ha_buf);
509 #endif
510
511         return rc;
512 }
513
514 #if defined( LDAP_API_FEATURE_X_OPENLDAP_V2_KBIND ) || \
515         defined( HAVE_CYRUS_SASL )
516 char *
517 ldap_host_connected_to( Sockbuf *sb, const char *host )
518 {
519         socklen_t               len;
520 #ifdef LDAP_PF_INET6
521         struct sockaddr_storage sabuf;
522 #else
523         struct sockaddr sabuf;
524 #endif
525         struct sockaddr *sa = (struct sockaddr *) &sabuf;
526         int rc;
527         ber_socket_t    sd;
528
529         (void)memset( (char *)sa, '\0', sizeof sabuf );
530         len = sizeof sabuf;
531
532         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
533         if ( getpeername( sd, sa, &len ) == -1 ) {
534                 return( NULL );
535         }
536
537         /*
538          * do a reverse lookup on the addr to get the official hostname.
539          * this is necessary for kerberos to work right, since the official
540          * hostname is used as the kerberos instance.
541          */
542
543         switch (sa->sa_family) {
544 #ifdef LDAP_PF_LOCAL
545         case AF_LOCAL:
546                 return LDAP_STRDUP( ldap_int_hostname );
547 #endif
548 #ifdef LDAP_PF_INET6
549         case AF_INET6:
550                 {
551                         struct in6_addr localhost = IN6ADDR_LOOPBACK_INIT;
552                         if( memcmp ( &((struct sockaddr_in6 *)sa)->sin6_addr,
553                                 &localhost, sizeof(localhost)) == 0 )
554                         {
555                                 return LDAP_STRDUP( ldap_int_hostname );
556                         }
557                 }
558                 break;
559 #endif
560         case AF_INET:
561                 {
562                         struct in_addr localhost;
563                         localhost.s_addr = htonl( INADDR_ANY );
564
565                         if( memcmp ( &((struct sockaddr_in *)sa)->sin_addr,
566                                 &localhost, sizeof(localhost) ) == 0 )
567                         {
568                                 return LDAP_STRDUP( ldap_int_hostname );
569                         }
570
571 #ifdef INADDR_LOOPBACK
572                         localhost.s_addr = htonl( INADDR_LOOPBACK );
573
574                         if( memcmp ( &((struct sockaddr_in *)sa)->sin_addr,
575                                 &localhost, sizeof(localhost) ) == 0 )
576                         {
577                                 return LDAP_STRDUP( ldap_int_hostname );
578                         }
579 #endif
580                 }
581                 break;
582
583         default:
584                 return( NULL );
585                 break;
586         }
587
588 #if 0
589         {
590                 char *herr;
591                 char hbuf[NI_MAXHOST];
592                 hbuf[0] = 0;
593
594                 if (ldap_pvt_get_hname( sa, len, hbuf, sizeof(hbuf), &herr ) == 0
595                         && hbuf[0] ) 
596                 {
597                         return LDAP_STRDUP( hbuf );   
598                 }
599         }
600 #endif
601
602         return host ? LDAP_STRDUP( host ) : NULL;
603 }
604 #endif
605
606
607 /* for UNIX */
608 struct selectinfo {
609         fd_set  si_readfds;
610         fd_set  si_writefds;
611         fd_set  si_use_readfds;
612         fd_set  si_use_writefds;
613 };
614
615
616 void
617 ldap_mark_select_write( LDAP *ld, Sockbuf *sb )
618 {
619         struct selectinfo       *sip;
620         ber_socket_t            sd;
621
622         sip = (struct selectinfo *)ld->ld_selectinfo;
623         
624         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
625         if ( !FD_ISSET( sd, &sip->si_writefds )) {
626                 FD_SET( sd, &sip->si_writefds );
627         }
628 }
629
630
631 void
632 ldap_mark_select_read( LDAP *ld, Sockbuf *sb )
633 {
634         struct selectinfo       *sip;
635         ber_socket_t            sd;
636
637         sip = (struct selectinfo *)ld->ld_selectinfo;
638
639         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
640         if ( !FD_ISSET( sd, &sip->si_readfds )) {
641                 FD_SET( sd, &sip->si_readfds );
642         }
643 }
644
645
646 void
647 ldap_mark_select_clear( LDAP *ld, Sockbuf *sb )
648 {
649         struct selectinfo       *sip;
650         ber_socket_t            sd;
651
652         sip = (struct selectinfo *)ld->ld_selectinfo;
653
654         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
655         FD_CLR( sd, &sip->si_writefds );
656         FD_CLR( sd, &sip->si_readfds );
657 }
658
659
660 int
661 ldap_is_write_ready( LDAP *ld, Sockbuf *sb )
662 {
663         struct selectinfo       *sip;
664         ber_socket_t            sd;
665
666         sip = (struct selectinfo *)ld->ld_selectinfo;
667
668         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
669         return( FD_ISSET( sd, &sip->si_use_writefds ));
670 }
671
672
673 int
674 ldap_is_read_ready( LDAP *ld, Sockbuf *sb )
675 {
676         struct selectinfo       *sip;
677         ber_socket_t            sd;
678
679         sip = (struct selectinfo *)ld->ld_selectinfo;
680
681         ber_sockbuf_ctrl( sb, LBER_SB_OPT_GET_FD, &sd );
682         return( FD_ISSET( sd, &sip->si_use_readfds ));
683 }
684
685
686 void *
687 ldap_new_select_info( void )
688 {
689         struct selectinfo       *sip;
690
691         if (( sip = (struct selectinfo *)LDAP_CALLOC( 1,
692             sizeof( struct selectinfo ))) != NULL ) {
693                 FD_ZERO( &sip->si_readfds );
694                 FD_ZERO( &sip->si_writefds );
695         }
696
697         return( (void *)sip );
698 }
699
700
701 void
702 ldap_free_select_info( void *sip )
703 {
704         LDAP_FREE( sip );
705 }
706
707
708 void
709 ldap_int_ip_init( void )
710 {
711         int tblsize;
712 #if defined( HAVE_SYSCONF )
713         tblsize = sysconf( _SC_OPEN_MAX );
714 #elif defined( HAVE_GETDTABLESIZE )
715         tblsize = getdtablesize();
716 #else
717         tblsize = FD_SETSIZE;
718 #endif /* !USE_SYSCONF */
719
720 #ifdef FD_SETSIZE
721         if( tblsize > FD_SETSIZE )
722                 tblsize = FD_SETSIZE;
723 #endif  /* FD_SETSIZE*/
724         ldap_int_tblsize = tblsize;
725 }
726
727
728 int
729 ldap_int_select( LDAP *ld, struct timeval *timeout )
730 {
731         struct selectinfo       *sip;
732
733 #ifdef NEW_LOGGING
734         LDAP_LOG ( CONNECTION, ENTRY, "ldap_int_select\n", 0, 0, 0 );
735 #else
736         Debug( LDAP_DEBUG_TRACE, "ldap_int_select\n", 0, 0, 0 );
737 #endif
738
739         if ( ldap_int_tblsize == 0 )
740                 ldap_int_ip_init();
741
742         sip = (struct selectinfo *)ld->ld_selectinfo;
743         sip->si_use_readfds = sip->si_readfds;
744         sip->si_use_writefds = sip->si_writefds;
745         
746         return( select( ldap_int_tblsize,
747                         &sip->si_use_readfds, &sip->si_use_writefds,
748                         NULL, timeout ));
749 }