]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/getdn.c
Add ber_bvstr and ber_bvstrdup string to berval allocators.
[openldap] / libraries / libldap / getdn.c
index 31d6381f6e69c6ca4c812e66ec1041fc7940989d..0110e298e719649340db1af1513c6c3e8072fc37 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
@@ -12,7 +13,8 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <stdlib.h>
+
+#include <ac/stdlib.h>
 
 #include <ac/ctype.h>
 #include <ac/socket.h>
@@ -21,7 +23,7 @@
 
 #include "ldap-int.h"
 
-static char **explode_name( LDAP_CONST char *name, int notypes, int is_dn );
+static char **explode_name( const char *name, int notypes, int is_dn );
 
 char *
 ldap_get_dn( LDAP *ld, LDAPMessage *entry )
@@ -37,7 +39,7 @@ ldap_get_dn( LDAP *ld, LDAPMessage *entry )
        }
 
        tmp = *entry->lm_ber;   /* struct copy */
-       if ( ber_scanf( &tmp, "{a", &dn ) == LBER_ERROR ) {
+       if ( ber_scanf( &tmp, "{a" /*}*/, &dn ) == LBER_ERROR ) {
                ld->ld_errno = LDAP_DECODING_ERROR;
                return( NULL );
        }
@@ -53,10 +55,18 @@ ldap_dn2ufn( LDAP_CONST char *dn )
 
        Debug( LDAP_DEBUG_TRACE, "ldap_dn2ufn\n", 0, 0, 0 );
 
-       if ( ldap_is_dns_dn( dn ) || ( p = strchr( dn, '=' )) == NULL )
-               return( strdup( dn ) );
+       if( dn == NULL ) {
+               return NULL;
+       }
+
+       if ( ldap_is_dns_dn( dn ) ||
+               ( p = strchr( dn, '=' ) ) == NULL )
+       {
+               return( LDAP_STRDUP( dn ) );
+       }
+
 
-       ufn = strdup( ++p );
+       ufn = LDAP_STRDUP( ++p );
 
 #define INQUOTE                1
 #define OUTQUOTE       2
@@ -129,7 +139,7 @@ ldap_explode_dns( LDAP_CONST char *dn_in )
        int ncomps;
        int maxcomps = 8;
 
-       if ( (dn = strdup( dn_in )) == NULL ) {
+       if ( (dn = LDAP_STRDUP( dn_in )) == NULL ) {
                return( NULL );
        }
 
@@ -151,7 +161,7 @@ ldap_explode_dns( LDAP_CONST char *dn_in )
                                return NULL;
                        }
                }
-               rdns[ncomps++] = strdup( s );
+               rdns[ncomps++] = LDAP_STRDUP( s );
        }
        LDAP_FREE(dn);
 
@@ -181,7 +191,7 @@ ldap_explode_rdn( LDAP_CONST char *rdn, int notypes )
 }
 
 static char **
-explode_name( LDAP_CONST char *name, int notypes, int is_dn )
+explode_name( const char *name, int notypes, int is_dn )
 {
        const char *p, *q;
        char **parts = NULL;
@@ -278,7 +288,9 @@ explode_name( LDAP_CONST char *name, int notypes, int is_dn )
 int
 ldap_is_dns_dn( LDAP_CONST char *dn )
 {
-       return( dn[ 0 ] != '\0' && strchr( dn, '=' ) == NULL &&
-           strchr( dn, ',' ) == NULL );
+       return( dn[ 0 ] != '\0'
+               && strchr( dn, '=' ) == NULL
+               && strchr( dn, ',' ) == NULL
+               && strchr( dn, ';' ) == NULL );
 }