10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * 3*3857Sstevel * Copyright 1998 Sun Microsystems, Inc. All rights reserved. 4*3857Sstevel * Use is subject to license terms. 50Sstevel@tonic-gate * 60Sstevel@tonic-gate * 70Sstevel@tonic-gate * Comments: 80Sstevel@tonic-gate * 90Sstevel@tonic-gate */ 100Sstevel@tonic-gate 110Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 120Sstevel@tonic-gate 130Sstevel@tonic-gate #include <stdio.h> 140Sstevel@tonic-gate #include <ctype.h> 150Sstevel@tonic-gate #include <string.h> 160Sstevel@tonic-gate #include "lber.h" 170Sstevel@tonic-gate #include "ldap.h" 180Sstevel@tonic-gate #include "ldap-private.h" 190Sstevel@tonic-gate #include "ldap-int.h" 200Sstevel@tonic-gate 210Sstevel@tonic-gate LDAPMessage * ldap_first_reference(LDAP *ld, LDAPMessage *res) 220Sstevel@tonic-gate { 230Sstevel@tonic-gate LDAPMessage *msg = res; 240Sstevel@tonic-gate 250Sstevel@tonic-gate while ( msg != NULLMSG) { 260Sstevel@tonic-gate if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) 270Sstevel@tonic-gate break; 280Sstevel@tonic-gate msg = msg->lm_chain; 290Sstevel@tonic-gate } 300Sstevel@tonic-gate return (msg); 310Sstevel@tonic-gate } 320Sstevel@tonic-gate 330Sstevel@tonic-gate LDAPMessage * ldap_next_reference(LDAP *ld, LDAPMessage *entry) 340Sstevel@tonic-gate { 350Sstevel@tonic-gate LDAPMessage *msg; 360Sstevel@tonic-gate 370Sstevel@tonic-gate if ( entry == NULLMSG) 380Sstevel@tonic-gate return( NULLMSG ); 390Sstevel@tonic-gate 400Sstevel@tonic-gate msg = entry->lm_chain; 410Sstevel@tonic-gate while(msg != NULLMSG){ 420Sstevel@tonic-gate if (msg->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) 430Sstevel@tonic-gate break; 440Sstevel@tonic-gate msg = msg->lm_chain; 450Sstevel@tonic-gate } 460Sstevel@tonic-gate 470Sstevel@tonic-gate return( msg ); 480Sstevel@tonic-gate } 490Sstevel@tonic-gate 500Sstevel@tonic-gate int 510Sstevel@tonic-gate ldap_count_references( LDAP *ld, LDAPMessage *res ) 520Sstevel@tonic-gate { 530Sstevel@tonic-gate int i; 540Sstevel@tonic-gate 550Sstevel@tonic-gate for ( i = 0; res != NULL; res = res->lm_chain ) 560Sstevel@tonic-gate if (res->lm_msgtype == LDAP_RES_SEARCH_REFERENCE) 570Sstevel@tonic-gate i++; 580Sstevel@tonic-gate 590Sstevel@tonic-gate return( i ); 600Sstevel@tonic-gate } 610Sstevel@tonic-gate 620Sstevel@tonic-gate char ** ldap_get_reference_urls(LDAP *ld, LDAPMessage *res) 630Sstevel@tonic-gate { 640Sstevel@tonic-gate BerElement tmp; 650Sstevel@tonic-gate char **urls = NULL; 660Sstevel@tonic-gate 670Sstevel@tonic-gate Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 1274, "ldap_get_reference_urls\n"), 0, 0, 0 ); 680Sstevel@tonic-gate 690Sstevel@tonic-gate if (res == NULL){ 700Sstevel@tonic-gate ld->ld_errno = LDAP_PARAM_ERROR; 710Sstevel@tonic-gate return (NULL); 720Sstevel@tonic-gate } 730Sstevel@tonic-gate tmp = *res->lm_ber; /* struct copy */ 740Sstevel@tonic-gate if ( ber_scanf( &tmp, "{v}", &urls) == LBER_ERROR){ 750Sstevel@tonic-gate ld->ld_errno = LDAP_DECODING_ERROR; 760Sstevel@tonic-gate return (NULL); 770Sstevel@tonic-gate } 780Sstevel@tonic-gate return (urls); 790Sstevel@tonic-gate } 80