X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libraries%2Flibldap%2Fgetvalues.c;h=a3763f7bfc62a3445eb3c8eaeb35f1602903e83e;hb=de01a6e3d791d3458549d2ceeccf4d7e0477ff78;hp=8f352dcd61ca94772f80ce44b7d4a003bb135d00;hpb=1bcec8bf6a17a65396b2c947faed846d20428db9;p=openldap diff --git a/libraries/libldap/getvalues.c b/libraries/libldap/getvalues.c index 8f352dcd61..a3763f7bfc 100644 --- a/libraries/libldap/getvalues.c +++ b/libraries/libldap/getvalues.c @@ -1,18 +1,26 @@ -/* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file - */ -/* Portions - * Copyright (c) 1990 Regents of the University of Michigan. - * All rights reserved. +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2007 The OpenLDAP Foundation. + * All rights reserved. * - * getvalues.c + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ +/* Portions Copyright (c) 1990 Regents of the University of Michigan. + * All rights reserved. */ #include "portable.h" #include -#include + +#include #include #include @@ -29,12 +37,17 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ) int found = 0; char **vals; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( entry != NULL ); + assert( target != NULL ); + Debug( LDAP_DEBUG_TRACE, "ldap_get_values\n", 0, 0, 0 ); ber = *entry->lm_ber; /* skip sequence, dn, sequence of, and snag the first attr */ - if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) { + if ( ber_scanf( &ber, "{x{{a" /*}}}*/, &attr ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return( NULL ); } @@ -47,7 +60,7 @@ ldap_get_values( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ) LDAP_FREE(attr); attr = NULL; - if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) { + if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return( NULL ); } @@ -81,12 +94,17 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ) int found = 0; struct berval **vals; + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( entry != NULL ); + assert( target != NULL ); + Debug( LDAP_DEBUG_TRACE, "ldap_get_values_len\n", 0, 0, 0 ); ber = *entry->lm_ber; /* skip sequence, dn, sequence of, and snag the first attr */ - if ( ber_scanf( &ber, "{x{{a", &attr ) == LBER_ERROR ) { + if ( ber_scanf( &ber, "{x{{a" /* }}} */, &attr ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return( NULL ); } @@ -99,7 +117,7 @@ ldap_get_values_len( LDAP *ld, LDAPMessage *entry, LDAP_CONST char *target ) LDAP_FREE( attr ); attr = NULL; - if ( ber_scanf( &ber, "x}{a", &attr ) == LBER_ERROR ) { + if ( ber_scanf( &ber, /*{*/ "x}{a" /*}*/, &attr ) == LBER_ERROR ) { ld->ld_errno = LDAP_DECODING_ERROR; return( NULL ); } @@ -147,25 +165,47 @@ ldap_count_values_len( struct berval **vals ) void ldap_value_free( char **vals ) { - int i; - - if ( vals == NULL ) - return; - for ( i = 0; vals[i] != NULL; i++ ) - LDAP_FREE( vals[i] ); - LDAP_FREE( (char *) vals ); + LDAP_VFREE( vals ); } void ldap_value_free_len( struct berval **vals ) { - int i; + ber_bvecfree( vals ); +} - if ( vals == NULL ) - return; - for ( i = 0; vals[i] != NULL; i++ ) { - LDAP_FREE( vals[i]->bv_val ); - LDAP_FREE( vals[i] ); +char ** +ldap_value_dup( char *const *vals ) +{ + char **new; + int i; + + if( vals == NULL ) { + return NULL; + } + + for( i=0; vals[i]; i++ ) { + ; /* Count the number of values */ + } + + if( i == 0 ) { + return NULL; } - LDAP_FREE( (char *) vals ); + + new = LDAP_MALLOC( (i+1)*sizeof(char *) ); /* Alloc array of pointers */ + if( new == NULL ) { + return NULL; + } + + for( i=0; vals[i]; i++ ) { + new[i] = LDAP_STRDUP( vals[i] ); /* Dup each value */ + if( new[i] == NULL ) { + LDAP_VFREE( new ); + return NULL; + } + } + new[i] = NULL; + + return new; } +