]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/util-int.c
For LDAP_PROTO_IPC set the SASL EXTERNAL authid to allow the mech to be
[openldap] / libraries / libldap / util-int.c
index 9e8a59fdedabe9159116b73393c0e2e9016990aa..6a2d5bd3487481f09f20644d3196a16db3c50a58 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /*
 
 #include "ldap-int.h"
 
-#if defined( LDAP_R_COMPILE )
-# include <ldap_pvt_thread.h>
-#else
+#if !defined( LDAP_R_COMPILE )
 # undef HAVE_REENTRANT_FUNCTIONS
-#endif
+# undef HAVE_CTIME_R
+# undef HAVE_GETHOSTBYNAME_R
+# undef HAVE_GETHOSTBYADDR_R
+
+#else
+#      include <ldap_pvt_thread.h>
 
 #if (defined( HAVE_CTIME_R ) || defined( HAVE_REENTRANT_FUNCTIONS)) \
        && defined( CTIME_R_NARGS )
 #      define USE_CTIME_R
+#else
+       static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
 #endif
 
 #if defined(HAVE_GETHOSTBYNAME_R) && \
-    (GETHOSTBYNAME_R_NARGS > 6 || GETHOSTBYNAME_R_NARGS < 5)
+       (GETHOSTBYNAME_R_NARGS < 5) || (6 < GETHOSTBYNAME_R_NARGS)
        /* Don't know how to handle this version, pretend it's not there */
 #      undef HAVE_GETHOSTBYNAME_R
 #endif
 #if defined(HAVE_GETHOSTBYADDR_R) && \
-    (GETHOSTBYADDR_R_NARGS > 8 || GETHOSTBYADDR_R_NARGS < 7)
+       (GETHOSTBYADDR_R_NARGS < 7) || (8 < GETHOSTBYADDR_R_NARGS)
        /* Don't know how to handle this version, pretend it's not there */
 #      undef HAVE_GETHOSTBYADDR_R
 #endif
 
-#ifdef LDAP_R_COMPILE
-# ifndef USE_CTIME_R
-       static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
-# endif
-# if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
-       static ldap_pvt_thread_mutex_t ldap_int_gethostby_mutex;
-# endif
-# ifdef HAVE_RES_QUERY
        ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
-# endif
 #endif /* LDAP_R_COMPILE */
 
 char *ldap_pvt_ctime( const time_t *tp, char *buf )
@@ -81,24 +77,29 @@ char *ldap_pvt_ctime( const time_t *tp, char *buf )
 # endif          
 
 #else
+
 # ifdef LDAP_R_COMPILE
        ldap_pvt_thread_mutex_lock( &ldap_int_ctime_mutex );
 # endif
+
        AC_MEMCPY( buf, ctime(tp), 26 );
+
 # ifdef LDAP_R_COMPILE
        ldap_pvt_thread_mutex_unlock( &ldap_int_ctime_mutex );
 # endif
+
        return buf;
 #endif 
 }
 
-#define BUFSTART 1024
-#define BUFMAX (32*1024)
+#define BUFSTART (1024-32)
+#define BUFMAX (32*1024-32)
 
 static char *safe_realloc( char **buf, int len );
 
 #if !defined(HAVE_GETHOSTBYNAME_R) && defined(LDAP_R_COMPILE)
-static int copy_hostent( struct hostent *res, char **buf, struct hostent * src );
+static int copy_hostent( struct hostent *res,
+       char **buf, struct hostent * src );
 #endif
 
 int ldap_pvt_gethostbyname_a(
@@ -148,7 +149,7 @@ int ldap_pvt_gethostbyname_a(
        int     retval;
        *buf = NULL;
        
-       ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
+       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
        
        he = gethostbyname( name );
        
@@ -163,7 +164,7 @@ int ldap_pvt_gethostbyname_a(
                retval = 0;
        }
        
-       ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
+       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
        
        return retval;
 #else  
@@ -229,7 +230,7 @@ int ldap_pvt_gethostbyaddr_a(
        int     retval;
        *buf = NULL;   
        
-       ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
+       ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
        
        he = gethostbyaddr( addr, len, type );
        
@@ -244,9 +245,10 @@ int ldap_pvt_gethostbyaddr_a(
                retval = 0;
        }
        
-       ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
+       ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
        
-       return retval;   
+       return retval;
+
 #else /* gethostbyaddr() */
        *buf = NULL;   
        *result = gethostbyaddr( addr, len, type );
@@ -269,21 +271,13 @@ void ldap_int_utils_init( void )
        done=1;
 
 #ifdef LDAP_R_COMPILE
-
 #if !defined( USE_CTIME_R ) && !defined( HAVE_REENTRANT_FUNCTIONS )
        ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
 #endif
-
-#if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
-       ldap_pvt_thread_mutex_init( &ldap_int_gethostby_mutex );
-#endif
-
-#ifdef HAVE_RES_QUERY
        ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
 #endif
 
        /* call other module init functions here... */
-#endif
 }
 
 #if defined( NEED_COPY_HOSTENT )
@@ -413,3 +407,39 @@ char * ldap_pvt_get_fqdn( char *name )
        LDAP_FREE( ha_buf );
        return fqdn;
 }
+
+#if defined( HAVE_GETADDRINFO ) && !defined( HAVE_GAI_STRERROR )
+char *ldap_pvt_gai_strerror (int code) {
+       static struct {
+               int code;
+               const char *msg;
+       } values[] = {
+#ifdef EAI_ADDRFAMILY
+               { EAI_ADDRFAMILY, "Address family for hostname not supported" },
+#endif
+               { EAI_AGAIN, "Temporary failure in name resolution" },
+               { EAI_BADFLAGS, "Bad value for ai_flags" },
+               { EAI_FAIL, "Non-recoverable failure in name resolution" },
+               { EAI_FAMILY, "ai_family not supported" },
+               { EAI_MEMORY, "Memory allocation failure" },
+#ifdef EAI_NODATA
+               { EAI_NODATA, "No address associated with hostname" },
+#endif    
+               { EAI_NONAME, "Name or service not known" },
+               { EAI_SERVICE, "Servname not supported for ai_socktype" },
+               { EAI_SOCKTYPE, "ai_socktype not supported" },
+               { EAI_SYSTEM, "System error" },
+               { 0, NULL }
+       };
+
+       int i;
+
+       for ( i = 0; values[i].msg != NULL; i++ ) {
+               if ( values[i].code == code ) {
+                       return (char *) values[i].msg;
+               }
+       }
+       
+       return "Unknown error";
+}
+#endif