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