xref: /onnv-gate/usr/src/lib/libldap5/sources/ldap/common/getentry.c (revision 0:68f95e015346)
1*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
2*0Sstevel@tonic-gate 
3*0Sstevel@tonic-gate /*
4*0Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
5*0Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
6*0Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
7*0Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
10*0Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11*0Sstevel@tonic-gate  * implied. See the License for the specific language governing
12*0Sstevel@tonic-gate  * rights and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
15*0Sstevel@tonic-gate  * March 31, 1998.
16*0Sstevel@tonic-gate  *
17*0Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
18*0Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
19*0Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
20*0Sstevel@tonic-gate  * Rights Reserved.
21*0Sstevel@tonic-gate  *
22*0Sstevel@tonic-gate  * Contributor(s):
23*0Sstevel@tonic-gate  */
24*0Sstevel@tonic-gate /*
25*0Sstevel@tonic-gate  *  Copyright (c) 1990 Regents of the University of Michigan.
26*0Sstevel@tonic-gate  *  All rights reserved.
27*0Sstevel@tonic-gate  */
28*0Sstevel@tonic-gate /*
29*0Sstevel@tonic-gate  *  getentry.c
30*0Sstevel@tonic-gate  */
31*0Sstevel@tonic-gate 
32*0Sstevel@tonic-gate #if 0
33*0Sstevel@tonic-gate #ifndef lint
34*0Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
35*0Sstevel@tonic-gate #endif
36*0Sstevel@tonic-gate #endif
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate #include "ldap-int.h"
39*0Sstevel@tonic-gate 
40*0Sstevel@tonic-gate LDAPMessage *
41*0Sstevel@tonic-gate LDAP_CALL
ldap_first_entry(LDAP * ld,LDAPMessage * chain)42*0Sstevel@tonic-gate ldap_first_entry( LDAP *ld, LDAPMessage *chain )
43*0Sstevel@tonic-gate {
44*0Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || chain == NULLMSG ) {
45*0Sstevel@tonic-gate 		return( NULLMSG );
46*0Sstevel@tonic-gate 	}
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate 	if ( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
49*0Sstevel@tonic-gate 		return( chain );
50*0Sstevel@tonic-gate 	}
51*0Sstevel@tonic-gate 
52*0Sstevel@tonic-gate 	return( ldap_next_entry( ld, chain ));
53*0Sstevel@tonic-gate }
54*0Sstevel@tonic-gate 
55*0Sstevel@tonic-gate 
56*0Sstevel@tonic-gate LDAPMessage *
57*0Sstevel@tonic-gate LDAP_CALL
ldap_next_entry(LDAP * ld,LDAPMessage * entry)58*0Sstevel@tonic-gate ldap_next_entry( LDAP *ld, LDAPMessage *entry )
59*0Sstevel@tonic-gate {
60*0Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || entry == NULLMSG ) {
61*0Sstevel@tonic-gate 		return( NULLMSG );
62*0Sstevel@tonic-gate 	}
63*0Sstevel@tonic-gate 
64*0Sstevel@tonic-gate 	for ( entry = entry->lm_chain; entry != NULLMSG;
65*0Sstevel@tonic-gate 	    entry = entry->lm_chain ) {
66*0Sstevel@tonic-gate 		if ( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
67*0Sstevel@tonic-gate 			return( entry );
68*0Sstevel@tonic-gate 		}
69*0Sstevel@tonic-gate 	}
70*0Sstevel@tonic-gate 
71*0Sstevel@tonic-gate 	return( NULLMSG );
72*0Sstevel@tonic-gate }
73*0Sstevel@tonic-gate 
74*0Sstevel@tonic-gate int
75*0Sstevel@tonic-gate LDAP_CALL
ldap_count_entries(LDAP * ld,LDAPMessage * chain)76*0Sstevel@tonic-gate ldap_count_entries( LDAP *ld, LDAPMessage *chain )
77*0Sstevel@tonic-gate {
78*0Sstevel@tonic-gate 	int	i;
79*0Sstevel@tonic-gate 
80*0Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
81*0Sstevel@tonic-gate 		return( -1 );
82*0Sstevel@tonic-gate 	}
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate 	for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
85*0Sstevel@tonic-gate 		if ( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
86*0Sstevel@tonic-gate 			++i;
87*0Sstevel@tonic-gate 		}
88*0Sstevel@tonic-gate 	}
89*0Sstevel@tonic-gate 
90*0Sstevel@tonic-gate 	return( i );
91*0Sstevel@tonic-gate }
92*0Sstevel@tonic-gate 
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate int
95*0Sstevel@tonic-gate LDAP_CALL
ldap_get_entry_controls(LDAP * ld,LDAPMessage * entry,LDAPControl *** serverctrlsp)96*0Sstevel@tonic-gate ldap_get_entry_controls( LDAP *ld, LDAPMessage *entry,
97*0Sstevel@tonic-gate 	LDAPControl ***serverctrlsp )
98*0Sstevel@tonic-gate {
99*0Sstevel@tonic-gate 	int		rc;
100*0Sstevel@tonic-gate 	BerElement	tmpber;
101*0Sstevel@tonic-gate 
102*0Sstevel@tonic-gate 	LDAPDebug( LDAP_DEBUG_TRACE, "ldap_get_entry_controls\n", 0, 0, 0 );
103*0Sstevel@tonic-gate 
104*0Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
105*0Sstevel@tonic-gate 		return( LDAP_PARAM_ERROR );
106*0Sstevel@tonic-gate 	}
107*0Sstevel@tonic-gate 
108*0Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( entry )
109*0Sstevel@tonic-gate 	    || serverctrlsp == NULL ) {
110*0Sstevel@tonic-gate 		rc = LDAP_PARAM_ERROR;
111*0Sstevel@tonic-gate 		goto report_error_and_return;
112*0Sstevel@tonic-gate 	}
113*0Sstevel@tonic-gate 
114*0Sstevel@tonic-gate 	*serverctrlsp = NULL;
115*0Sstevel@tonic-gate 	tmpber = *entry->lm_ber;	/* struct copy */
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate 	/* skip past dn and entire attribute/value list */
118*0Sstevel@tonic-gate 	if ( ber_scanf( &tmpber, "{xx" ) == LBER_ERROR ) {
119*0Sstevel@tonic-gate 		rc = LDAP_DECODING_ERROR;
120*0Sstevel@tonic-gate 		goto report_error_and_return;
121*0Sstevel@tonic-gate 	}
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate 	rc = nsldapi_get_controls( &tmpber, serverctrlsp );
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate report_error_and_return:
126*0Sstevel@tonic-gate 	LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
127*0Sstevel@tonic-gate 	return( rc );
128*0Sstevel@tonic-gate }
129