1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * Copyright (c) 2001 by Sun Microsystems, Inc.
3*0Sstevel@tonic-gate * All rights reserved.
4*0Sstevel@tonic-gate */
5*0Sstevel@tonic-gate
6*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gate /*
9*0Sstevel@tonic-gate * The contents of this file are subject to the Netscape Public
10*0Sstevel@tonic-gate * License Version 1.1 (the "License"); you may not use this file
11*0Sstevel@tonic-gate * except in compliance with the License. You may obtain a copy of
12*0Sstevel@tonic-gate * the License at http://www.mozilla.org/NPL/
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * Software distributed under the License is distributed on an "AS
15*0Sstevel@tonic-gate * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
16*0Sstevel@tonic-gate * implied. See the License for the specific language governing
17*0Sstevel@tonic-gate * rights and limitations under the License.
18*0Sstevel@tonic-gate *
19*0Sstevel@tonic-gate * The Original Code is Mozilla Communicator client code, released
20*0Sstevel@tonic-gate * March 31, 1998.
21*0Sstevel@tonic-gate *
22*0Sstevel@tonic-gate * The Initial Developer of the Original Code is Netscape
23*0Sstevel@tonic-gate * Communications Corporation. Portions created by Netscape are
24*0Sstevel@tonic-gate * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25*0Sstevel@tonic-gate * Rights Reserved.
26*0Sstevel@tonic-gate *
27*0Sstevel@tonic-gate * Contributor(s):
28*0Sstevel@tonic-gate */
29*0Sstevel@tonic-gate /*
30*0Sstevel@tonic-gate * Copyright (c) 1990 Regents of the University of Michigan.
31*0Sstevel@tonic-gate * All rights reserved.
32*0Sstevel@tonic-gate */
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate * getattr.c
35*0Sstevel@tonic-gate */
36*0Sstevel@tonic-gate
37*0Sstevel@tonic-gate #if 0
38*0Sstevel@tonic-gate #ifndef lint
39*0Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
40*0Sstevel@tonic-gate #endif
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #include "ldap-int.h"
44*0Sstevel@tonic-gate
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate static ber_len_t
bytes_remaining(BerElement * ber)47*0Sstevel@tonic-gate bytes_remaining( BerElement *ber )
48*0Sstevel@tonic-gate {
49*0Sstevel@tonic-gate ber_len_t len;
50*0Sstevel@tonic-gate
51*0Sstevel@tonic-gate if ( ber_get_option( ber, LBER_OPT_REMAINING_BYTES, &len ) != 0 ) {
52*0Sstevel@tonic-gate return( 0 ); /* not sure what else to do.... */
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate return( len );
55*0Sstevel@tonic-gate }
56*0Sstevel@tonic-gate
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gate char *
59*0Sstevel@tonic-gate LDAP_CALL
ldap_first_attribute(LDAP * ld,LDAPMessage * entry,BerElement ** ber)60*0Sstevel@tonic-gate ldap_first_attribute( LDAP *ld, LDAPMessage *entry, BerElement **ber )
61*0Sstevel@tonic-gate {
62*0Sstevel@tonic-gate char *attr;
63*0Sstevel@tonic-gate int err;
64*0Sstevel@tonic-gate ber_int_t seqlength;
65*0Sstevel@tonic-gate
66*0Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_first_attribute\n", 0, 0, 0 );
67*0Sstevel@tonic-gate
68*0Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
69*0Sstevel@tonic-gate return( NULL ); /* punt */
70*0Sstevel@tonic-gate }
71*0Sstevel@tonic-gate
72*0Sstevel@tonic-gate if ( ber == NULL || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( entry )) {
73*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
74*0Sstevel@tonic-gate return( NULL );
75*0Sstevel@tonic-gate }
76*0Sstevel@tonic-gate
77*0Sstevel@tonic-gate if ( nsldapi_alloc_ber_with_options( ld, ber ) != LDAP_SUCCESS ) {
78*0Sstevel@tonic-gate return( NULL );
79*0Sstevel@tonic-gate }
80*0Sstevel@tonic-gate
81*0Sstevel@tonic-gate **ber = *entry->lm_ber;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate attr = NULL; /* pessimistic */
84*0Sstevel@tonic-gate err = LDAP_DECODING_ERROR; /* ditto */
85*0Sstevel@tonic-gate
86*0Sstevel@tonic-gate /*
87*0Sstevel@tonic-gate * Skip past the sequence, dn, and sequence of sequence.
88*0Sstevel@tonic-gate * Reset number of bytes remaining so we confine the rest of our
89*0Sstevel@tonic-gate * decoding to the current sequence.
90*0Sstevel@tonic-gate */
91*0Sstevel@tonic-gate if ( ber_scanf( *ber, "{xl{", &seqlength ) != LBER_ERROR &&
92*0Sstevel@tonic-gate ber_set_option( *ber, LBER_OPT_REMAINING_BYTES, &seqlength )
93*0Sstevel@tonic-gate == 0 ) {
94*0Sstevel@tonic-gate /* snarf the attribute type, and skip the set of values,
95*0Sstevel@tonic-gate * leaving us positioned right before the next attribute
96*0Sstevel@tonic-gate * type/value sequence.
97*0Sstevel@tonic-gate */
98*0Sstevel@tonic-gate if ( ber_scanf( *ber, "{ax}", &attr ) != LBER_ERROR ||
99*0Sstevel@tonic-gate bytes_remaining( *ber ) == 0 ) {
100*0Sstevel@tonic-gate err = LDAP_SUCCESS;
101*0Sstevel@tonic-gate }
102*0Sstevel@tonic-gate }
103*0Sstevel@tonic-gate
104*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, err, NULL, NULL );
105*0Sstevel@tonic-gate if ( attr == NULL || err != LDAP_SUCCESS ) {
106*0Sstevel@tonic-gate ber_free( *ber, 0 );
107*0Sstevel@tonic-gate *ber = NULL;
108*0Sstevel@tonic-gate }
109*0Sstevel@tonic-gate return( attr );
110*0Sstevel@tonic-gate }
111*0Sstevel@tonic-gate
112*0Sstevel@tonic-gate /* ARGSUSED */
113*0Sstevel@tonic-gate char *
114*0Sstevel@tonic-gate LDAP_CALL
ldap_next_attribute(LDAP * ld,LDAPMessage * entry,BerElement * ber)115*0Sstevel@tonic-gate ldap_next_attribute( LDAP *ld, LDAPMessage *entry, BerElement *ber )
116*0Sstevel@tonic-gate {
117*0Sstevel@tonic-gate char *attr;
118*0Sstevel@tonic-gate int err;
119*0Sstevel@tonic-gate
120*0Sstevel@tonic-gate LDAPDebug( LDAP_DEBUG_TRACE, "ldap_next_attribute\n", 0, 0, 0 );
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
123*0Sstevel@tonic-gate return( NULL ); /* punt */
124*0Sstevel@tonic-gate }
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate if ( ber == NULL || !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( entry )) {
127*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
128*0Sstevel@tonic-gate return( NULL );
129*0Sstevel@tonic-gate }
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate attr = NULL; /* pessimistic */
132*0Sstevel@tonic-gate err = LDAP_DECODING_ERROR; /* ditto */
133*0Sstevel@tonic-gate
134*0Sstevel@tonic-gate /* skip sequence, snarf attribute type, skip values */
135*0Sstevel@tonic-gate if ( ber_scanf( ber, "{ax}", &attr ) != LBER_ERROR ||
136*0Sstevel@tonic-gate bytes_remaining( ber ) == 0 ) {
137*0Sstevel@tonic-gate err = LDAP_SUCCESS;
138*0Sstevel@tonic-gate }
139*0Sstevel@tonic-gate
140*0Sstevel@tonic-gate LDAP_SET_LDERRNO( ld, err, NULL, NULL );
141*0Sstevel@tonic-gate return( attr );
142*0Sstevel@tonic-gate }
143