1 /* $OpenLDAP: pkg/ldap/libraries/libldap/getattr.c,v 1.35.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
22 #include <ac/stdlib.h>
24 #include <ac/socket.h>
25 #include <ac/string.h>
31 ldap_first_attribute( LDAP
*ld
, LDAPMessage
*entry
, BerElement
**berout
)
39 Debug( LDAP_DEBUG_TRACE
, "ldap_first_attribute\n", 0, 0, 0 );
42 assert( LDAP_VALID( ld
) );
43 assert( entry
!= NULL
);
44 assert( berout
!= NULL
);
48 ber
= ldap_alloc_ber_with_options( ld
);
53 *ber
= *entry
->lm_ber
;
56 * Skip past the sequence, dn, sequence of sequence leaving
57 * us at the first attribute.
60 tag
= ber_scanf( ber
, "{xl{" /*}}*/, &len
);
61 if( tag
== LBER_ERROR
) {
62 ld
->ld_errno
= LDAP_DECODING_ERROR
;
67 /* set the length to avoid overrun */
68 rc
= ber_set_option( ber
, LBER_OPT_REMAINING_BYTES
, &len
);
69 if( rc
!= LBER_OPT_SUCCESS
) {
70 ld
->ld_errno
= LDAP_LOCAL_ERROR
;
75 if ( ber_pvt_ber_remaining( ber
) == 0 ) {
82 /* snatch the first attribute */
83 tag
= ber_scanf( ber
, "{ax}", &attr
);
84 if( tag
== LBER_ERROR
) {
85 ld
->ld_errno
= LDAP_DECODING_ERROR
;
96 ldap_next_attribute( LDAP
*ld
, LDAPMessage
*entry
, BerElement
*ber
)
101 Debug( LDAP_DEBUG_TRACE
, "ldap_next_attribute\n", 0, 0, 0 );
103 assert( ld
!= NULL
);
104 assert( LDAP_VALID( ld
) );
105 assert( entry
!= NULL
);
106 assert( ber
!= NULL
);
108 if ( ber_pvt_ber_remaining( ber
) == 0 ) {
112 /* skip sequence, snarf attribute type, skip values */
113 tag
= ber_scanf( ber
, "{ax}", &attr
);
114 if( tag
== LBER_ERROR
) {
115 ld
->ld_errno
= LDAP_DECODING_ERROR
;
122 /* Fetch attribute type and optionally fetch values. The type
123 * and values are referenced in-place from the BerElement, they are
124 * not dup'd into malloc'd memory.
128 ldap_get_attribute_ber( LDAP
*ld
, LDAPMessage
*entry
, BerElement
*ber
,
129 BerValue
*attr
, BerVarray
*vals
)
132 int rc
= LDAP_SUCCESS
;
134 Debug( LDAP_DEBUG_TRACE
, "ldap_get_attribute_ber\n", 0, 0, 0 );
136 assert( ld
!= NULL
);
137 assert( LDAP_VALID( ld
) );
138 assert( entry
!= NULL
);
139 assert( ber
!= NULL
);
140 assert( attr
!= NULL
);
145 if ( ber_pvt_ber_remaining( ber
) ) {
146 ber_len_t siz
= sizeof( BerValue
);
148 /* skip sequence, snarf attribute type */
149 tag
= ber_scanf( ber
, vals
? "{mM}" : "{mx}", attr
, vals
,
151 if( tag
== LBER_ERROR
) {
152 rc
= ld
->ld_errno
= LDAP_DECODING_ERROR
;