17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the Netscape Public
37c478bd9Sstevel@tonic-gate  * License Version 1.1 (the "License"); you may not use this file
47c478bd9Sstevel@tonic-gate  * except in compliance with the License. You may obtain a copy of
57c478bd9Sstevel@tonic-gate  * the License at http://www.mozilla.org/NPL/
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  * Software distributed under the License is distributed on an "AS
87c478bd9Sstevel@tonic-gate  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
97c478bd9Sstevel@tonic-gate  * implied. See the License for the specific language governing
107c478bd9Sstevel@tonic-gate  * rights and limitations under the License.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  * The Original Code is Mozilla Communicator client code, released
137c478bd9Sstevel@tonic-gate  * March 31, 1998.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  * The Initial Developer of the Original Code is Netscape
167c478bd9Sstevel@tonic-gate  * Communications Corporation. Portions created by Netscape are
177c478bd9Sstevel@tonic-gate  * Copyright (C) 1998-1999 Netscape Communications Corporation. All
187c478bd9Sstevel@tonic-gate  * Rights Reserved.
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * Contributor(s):
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *  Copyright (c) 1990 Regents of the University of Michigan.
247c478bd9Sstevel@tonic-gate  *  All rights reserved.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  *  getentry.c
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #if 0
31*1da57d55SToomas Soome #ifndef lint
327c478bd9Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include "ldap-int.h"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate LDAPMessage *
397c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_first_entry(LDAP * ld,LDAPMessage * chain)407c478bd9Sstevel@tonic-gate ldap_first_entry( LDAP *ld, LDAPMessage *chain )
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || chain == NULLMSG ) {
437c478bd9Sstevel@tonic-gate 		return( NULLMSG );
447c478bd9Sstevel@tonic-gate 	}
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 	if ( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
477c478bd9Sstevel@tonic-gate 		return( chain );
487c478bd9Sstevel@tonic-gate 	}
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate 	return( ldap_next_entry( ld, chain ));
517c478bd9Sstevel@tonic-gate }
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate LDAPMessage *
557c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_next_entry(LDAP * ld,LDAPMessage * entry)567c478bd9Sstevel@tonic-gate ldap_next_entry( LDAP *ld, LDAPMessage *entry )
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld ) || entry == NULLMSG ) {
597c478bd9Sstevel@tonic-gate 		return( NULLMSG );
607c478bd9Sstevel@tonic-gate 	}
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate 	for ( entry = entry->lm_chain; entry != NULLMSG;
637c478bd9Sstevel@tonic-gate 	    entry = entry->lm_chain ) {
647c478bd9Sstevel@tonic-gate 		if ( entry->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
657c478bd9Sstevel@tonic-gate 			return( entry );
667c478bd9Sstevel@tonic-gate 		}
677c478bd9Sstevel@tonic-gate 	}
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate 	return( NULLMSG );
707c478bd9Sstevel@tonic-gate }
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate int
737c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_count_entries(LDAP * ld,LDAPMessage * chain)747c478bd9Sstevel@tonic-gate ldap_count_entries( LDAP *ld, LDAPMessage *chain )
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate 	int	i;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
797c478bd9Sstevel@tonic-gate 		return( -1 );
807c478bd9Sstevel@tonic-gate 	}
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	for ( i = 0; chain != NULL; chain = chain->lm_chain ) {
837c478bd9Sstevel@tonic-gate 		if ( chain->lm_msgtype == LDAP_RES_SEARCH_ENTRY ) {
847c478bd9Sstevel@tonic-gate 			++i;
857c478bd9Sstevel@tonic-gate 		}
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	return( i );
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate int
937c478bd9Sstevel@tonic-gate LDAP_CALL
ldap_get_entry_controls(LDAP * ld,LDAPMessage * entry,LDAPControl *** serverctrlsp)947c478bd9Sstevel@tonic-gate ldap_get_entry_controls( LDAP *ld, LDAPMessage *entry,
957c478bd9Sstevel@tonic-gate 	LDAPControl ***serverctrlsp )
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate 	int		rc;
987c478bd9Sstevel@tonic-gate 	BerElement	tmpber;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	LDAPDebug( LDAP_DEBUG_TRACE, "ldap_get_entry_controls\n", 0, 0, 0 );
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
1037c478bd9Sstevel@tonic-gate 		return( LDAP_PARAM_ERROR );
1047c478bd9Sstevel@tonic-gate 	}
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if ( !NSLDAPI_VALID_LDAPMESSAGE_ENTRY_POINTER( entry )
1077c478bd9Sstevel@tonic-gate 	    || serverctrlsp == NULL ) {
1087c478bd9Sstevel@tonic-gate 		rc = LDAP_PARAM_ERROR;
1097c478bd9Sstevel@tonic-gate 		goto report_error_and_return;
1107c478bd9Sstevel@tonic-gate 	}
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate 	*serverctrlsp = NULL;
1137c478bd9Sstevel@tonic-gate 	tmpber = *entry->lm_ber;	/* struct copy */
1147c478bd9Sstevel@tonic-gate 
115*1da57d55SToomas Soome 	/* skip past dn and entire attribute/value list */
1167c478bd9Sstevel@tonic-gate 	if ( ber_scanf( &tmpber, "{xx" ) == LBER_ERROR ) {
1177c478bd9Sstevel@tonic-gate 		rc = LDAP_DECODING_ERROR;
1187c478bd9Sstevel@tonic-gate 		goto report_error_and_return;
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	rc = nsldapi_get_controls( &tmpber, serverctrlsp );
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate report_error_and_return:
1247c478bd9Sstevel@tonic-gate 	LDAP_SET_LDERRNO( ld, rc, NULL, NULL );
1257c478bd9Sstevel@tonic-gate 	return( rc );
1267c478bd9Sstevel@tonic-gate }
127