Use ldap_parse_whoami

This commit is contained in:
Kurt Zeilenga 2010-12-14 18:17:28 +00:00
parent 2a9c5154ef
commit 0ba7be7a6f

View File

@ -111,8 +111,7 @@ main( int argc, char *argv[] )
int rc; int rc;
LDAP *ld = NULL; LDAP *ld = NULL;
char *matcheddn = NULL, *text = NULL, **refs = NULL; char *matcheddn = NULL, *text = NULL, **refs = NULL;
char *retoid = NULL; struct berval *authzid = NULL;
struct berval *retdata = NULL;
int id, code = 0; int id, code = 0;
LDAPMessage *res; LDAPMessage *res;
LDAPControl **ctrls = NULL; LDAPControl **ctrls = NULL;
@ -182,7 +181,8 @@ main( int argc, char *argv[] )
goto skip; goto skip;
} }
rc = ldap_parse_extended_result( ld, res, &retoid, &retdata, 1 ); rc = ldap_parse_whoami( ld, res, &authzid );
ldap_msgfree(res);
if( rc != LDAP_SUCCESS ) { if( rc != LDAP_SUCCESS ) {
tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL ); tool_perror( "ldap_parse_extended_result", rc, NULL, NULL, NULL, NULL );
@ -190,11 +190,11 @@ main( int argc, char *argv[] )
goto skip; goto skip;
} }
if( retdata != NULL ) { if( authzid != NULL ) {
if( retdata->bv_len == 0 ) { if( authzid->bv_len == 0 ) {
printf(_("anonymous\n") ); printf(_("anonymous\n") );
} else { } else {
printf("%s\n", retdata->bv_val ); printf("%s\n", authzid->bv_val );
} }
} }
@ -228,8 +228,7 @@ skip:
ber_memfree( text ); ber_memfree( text );
ber_memfree( matcheddn ); ber_memfree( matcheddn );
ber_memvfree( (void **) refs ); ber_memvfree( (void **) refs );
ber_memfree( retoid ); ber_bvfree( authzid );
ber_bvfree( retdata );
/* disconnect from server */ /* disconnect from server */
tool_unbind( ld ); tool_unbind( ld );