]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getdxbyname.c
Use getpassphrase() instead of getpass() if available.
[openldap] / libraries / libldap / getdxbyname.c
index 833af5adae49fdb42210e0c4e9666638f8d2acc8..0f5ba3c4578c1cfad9bd6c32f14a3bb10e69266f 100644 (file)
@@ -1,47 +1,30 @@
-#ifdef LDAP_DNS
+/* $OpenLDAP$ */
 /*
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
+/*  Portions
  *  Copyright (c) 1995 Regents of the University of Michigan.
  *  All rights reserved.
  *
  * ldap_getdxbyname - retrieve DX records from the DNS (from TXT records for now)
  */
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-#ifdef MACOS
-#include <stdlib.h>
-#include "macos.h"
-#endif /* MACOS */
-
-#if !defined(MACOS) && !defined(DOS) && !defined( _WIN32 )
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <arpa/nameser.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <resolv.h>
-#endif
-#include "lber.h"
-#include "ldap.h"
-#include "ldap-int.h"
 
-#if defined( DOS ) || defined( _WIN32 )
-#include "msdos.h"
-#endif /* DOS */
+#include "portable.h"
 
+#ifdef LDAP_API_FEATURE_X_OPENLDAP_V2_DNS
 
-#ifdef NEEDPROTOS
-static char ** decode_answer( unsigned char *answer, int len );
-#else /* NEEDPROTOS */
-static char **decode_answer();
-#endif /* NEEDPROTOS */
+#include <stdio.h>
+#include <ac/stdlib.h>
+
+#include <ac/ctype.h>
+#include <ac/socket.h>
+#include <ac/string.h>
+#include <ac/time.h>
 
-extern int h_errno;
-extern char *h_errlist[];
+#include "ldap-int.h"
 
+static char ** decode_answer LDAP_P(( unsigned char *answer, ber_len_t len ));
 
 #define MAX_TO_SORT    32
 
@@ -51,7 +34,7 @@ extern char *h_errlist[];
  *     array.
  */
 char **
-ldap_getdxbyname( char *domain )
+ldap_getdxbyname( const char *domain )
 {
     unsigned char      buf[ PACKETSZ ];
     char               **dxs;
@@ -61,15 +44,19 @@ ldap_getdxbyname( char *domain )
 
     memset( buf, 0, sizeof( buf ));
 
+#ifdef LDAP_R_COMPILE
+    ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
+#endif
+
     if (( rc = res_search( domain, C_IN, T_TXT, buf, sizeof( buf ))) < 0
                || ( dxs = decode_answer( buf, rc )) == NULL ) {
        /*
         * punt:  return list conisting of the original domain name only
         */
-       if (( dxs = (char **)malloc( 2 * sizeof( char * ))) == NULL ||
-               ( dxs[ 0 ] = strdup( domain )) == NULL ) {
+       if (( dxs = (char **)LDAP_MALLOC( 2 * sizeof( char * ))) == NULL ||
+               ( dxs[ 0 ] = LDAP_STRDUP( domain )) == NULL ) {
            if ( dxs != NULL ) {
-               free( dxs );
+               LDAP_FREE( dxs );
            }
            dxs = NULL;
        } else {
@@ -77,12 +64,16 @@ ldap_getdxbyname( char *domain )
        }
     }
 
+#ifdef LDAP_R_COMPILE
+    ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex);
+#endif
+
     return( dxs );
 }
 
 
 static char **
-decode_answer( unsigned char *answer, int len )
+decode_answer( unsigned char *answer, ber_len_t len )
 {
     HEADER             *hp;
     char               buf[ 256 ], **dxs;
@@ -91,9 +82,11 @@ decode_answer( unsigned char *answer, int len )
     int                        dx_pref[ MAX_TO_SORT ];
 
 #ifdef LDAP_DEBUG
+#ifdef notdef
     if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
-/*     __p_query( answer );    /* */
+               __p_query( answer );
     }
+#endif
 #endif /* LDAP_DEBUG */
 
     dxs = NULL;
@@ -139,7 +132,7 @@ decode_answer( unsigned char *answer, int len )
        rr_len = _getshort( p );
        p += INT16SZ;
        if ( class == C_IN && type == T_TXT ) {
-           int         i, n, pref, txt_len;
+           int         pref, txt_len;
            char        *q, *r;
 
            q = (char *)p;
@@ -147,12 +140,12 @@ decode_answer( unsigned char *answer, int len )
                if ( *q >= 3 && strncasecmp( q + 1, "dx:", 3 ) == 0 ) {
                    txt_len = *q - 3;
                    r = q + 4;
-                   while ( isspace( *r )) { 
+                   while ( isspace( (unsigned char) *r )) { 
                        ++r;
                        --txt_len;
                    }
                    pref = 0;
-                   while ( isdigit( *r )) {
+                   while ( isdigit( (unsigned char) *r )) {
                        pref *= 10;
                        pref += ( *r - '0' );
                        ++r;
@@ -161,18 +154,14 @@ decode_answer( unsigned char *answer, int len )
                    if ( dx_count < MAX_TO_SORT - 1 ) {
                        dx_pref[ dx_count ] = pref;
                    }
-                   while ( isspace( *r )) { 
+                   while ( isspace( (unsigned char) *r )) { 
                        ++r;
                        --txt_len;
                    }
-                   if ( dx_count == 0 ) {
-                       dxs = (char **)malloc( 2 * sizeof( char * ));
-                   } else {
-                       dxs = (char **)realloc( dxs,
+                       dxs = (char **)LDAP_REALLOC( dxs,
                                ( dx_count + 2 ) * sizeof( char * ));
-                   }
                    if ( dxs == NULL || ( dxs[ dx_count ] =
-                               (char *)calloc( 1, txt_len + 1 )) == NULL ) {
+                               (char *)LDAP_CALLOC( 1, txt_len + 1 )) == NULL ) {
                        err = NO_RECOVERY;
                        continue;
                    }
@@ -215,4 +204,4 @@ decode_answer( unsigned char *answer, int len )
     return( dxs );
 }
 
-#endif /* LDAP_DNS */
+#endif /* LDAP_API_FEATURE_X_OPENLDAP_V2_DNS */