xref: /onnv-gate/usr/src/lib/libldap4/common/getattr.c (revision 3857:21b9b714e4ab)
10Sstevel@tonic-gate /*
2*3857Sstevel  * Portions Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
3*3857Sstevel  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
70Sstevel@tonic-gate 
80Sstevel@tonic-gate /*
90Sstevel@tonic-gate  *  Copyright (c) 1990 Regents of the University of Michigan.
100Sstevel@tonic-gate  *  All rights reserved.
110Sstevel@tonic-gate  *
120Sstevel@tonic-gate  *  getattr.c
130Sstevel@tonic-gate  */
140Sstevel@tonic-gate 
150Sstevel@tonic-gate #ifndef lint
160Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
170Sstevel@tonic-gate #endif
180Sstevel@tonic-gate 
190Sstevel@tonic-gate #include <stdio.h>
200Sstevel@tonic-gate #include <ctype.h>
210Sstevel@tonic-gate #include <string.h>
220Sstevel@tonic-gate #ifdef MACOS
230Sstevel@tonic-gate #include <stdlib.h>
240Sstevel@tonic-gate #include "macos.h"
250Sstevel@tonic-gate #else /* MACOS */
260Sstevel@tonic-gate #if defined( DOS ) || defined( _WIN32 )
270Sstevel@tonic-gate #include <malloc.h>
280Sstevel@tonic-gate #include "msdos.h"
290Sstevel@tonic-gate #else /* DOS */
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/socket.h>
320Sstevel@tonic-gate #endif /* DOS */
330Sstevel@tonic-gate #endif /* MACOS */
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include "lber.h"
360Sstevel@tonic-gate #include "ldap.h"
370Sstevel@tonic-gate #include "ldap-private.h"
380Sstevel@tonic-gate #include "ldap-int.h"
390Sstevel@tonic-gate 
400Sstevel@tonic-gate char *
ldap_first_attribute(LDAP * ld,LDAPMessage * entry,BerElement ** ber)410Sstevel@tonic-gate ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	int	len;
440Sstevel@tonic-gate 	char	*attrbuffer;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 	if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) {
470Sstevel@tonic-gate 		return (NULL);
480Sstevel@tonic-gate 	}
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 179, "ldap_first_attribute\n"), 0, 0, 0 );
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 	if ( (*ber = alloc_ber_with_options( ld )) == NULLBER ) {
530Sstevel@tonic-gate 		free(attrbuffer);
540Sstevel@tonic-gate 		return( NULL );
550Sstevel@tonic-gate 	}
560Sstevel@tonic-gate 
570Sstevel@tonic-gate 	**ber = *entry->lm_ber;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate 	/*
600Sstevel@tonic-gate 	 * Skip past the sequence, dn, sequence of sequence, snarf the
610Sstevel@tonic-gate 	 * attribute type, and skip the set of values, leaving us
620Sstevel@tonic-gate 	 * positioned right before the next attribute type/value sequence.
630Sstevel@tonic-gate 	 */
640Sstevel@tonic-gate 
650Sstevel@tonic-gate 	len = LDAP_MAX_ATTR_LEN;
660Sstevel@tonic-gate 	if ( ber_scanf( *ber, "{x{{sx}", attrbuffer, &len )
670Sstevel@tonic-gate 	    == LBER_ERROR ) {
680Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
690Sstevel@tonic-gate 		ber_free( *ber, 0 );
700Sstevel@tonic-gate 		*ber = NULL;
710Sstevel@tonic-gate 		free(attrbuffer);
720Sstevel@tonic-gate 		return( NULL );
730Sstevel@tonic-gate 	}
740Sstevel@tonic-gate 
750Sstevel@tonic-gate 	return( attrbuffer );
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate /* ARGSUSED */
790Sstevel@tonic-gate char *
ldap_next_attribute(LDAP * ld,LDAPMessage * entry,BerElement * ber)800Sstevel@tonic-gate ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	int	len;
830Sstevel@tonic-gate 	char	*attrbuffer;
840Sstevel@tonic-gate 
850Sstevel@tonic-gate 	if ((attrbuffer = (char *)malloc(LDAP_MAX_ATTR_LEN)) == NULL) {
860Sstevel@tonic-gate 		return (NULL);
870Sstevel@tonic-gate 	}
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 180, "ldap_next_attribute\n"), 0, 0, 0 );
900Sstevel@tonic-gate 
910Sstevel@tonic-gate 	/* skip sequence, snarf attribute type, skip values */
920Sstevel@tonic-gate 	len = LDAP_MAX_ATTR_LEN;
930Sstevel@tonic-gate 	if ( ber_scanf( ber, "{sx}", attrbuffer, &len )
940Sstevel@tonic-gate 	    == LBER_ERROR ) {
950Sstevel@tonic-gate 		ld->ld_errno = LDAP_DECODING_ERROR;
960Sstevel@tonic-gate 		free(attrbuffer);
970Sstevel@tonic-gate 		return( NULL );
980Sstevel@tonic-gate 	}
990Sstevel@tonic-gate 	ld->ld_errno = LDAP_SUCCESS;
1000Sstevel@tonic-gate 	return( attrbuffer );
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
ldap_memfree(char * mem)1030Sstevel@tonic-gate void ldap_memfree(char *mem)
1040Sstevel@tonic-gate {
1050Sstevel@tonic-gate 	free(mem);
1060Sstevel@tonic-gate }
1070Sstevel@tonic-gate 
108