whoami.c revision 1.1.1.4
1/* $NetBSD: whoami.c,v 1.1.1.4 2014/05/28 09:58:42 tron Exp $ */ 2 3/* $OpenLDAP$ */ 4/* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1998-2014 The OpenLDAP Foundation. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted only as authorized by the OpenLDAP 11 * Public License. 12 * 13 * A copy of this license is available in the file LICENSE in the 14 * top-level directory of the distribution or, alternatively, at 15 * <http://www.OpenLDAP.org/license.html>. 16 */ 17/* ACKNOWLEDGEMENTS: 18 * This program was orignally developed by Kurt D. Zeilenga for inclusion in 19 * OpenLDAP Software. 20 */ 21 22#include "portable.h" 23 24#include <stdio.h> 25#include <ac/stdlib.h> 26#include <ac/string.h> 27#include <ac/time.h> 28 29#include "ldap-int.h" 30 31/* 32 * LDAP Who Am I? (Extended) Operation <draft-zeilenga-ldap-authzid-xx.txt> 33 */ 34 35int ldap_parse_whoami( 36 LDAP *ld, 37 LDAPMessage *res, 38 struct berval **authzid ) 39{ 40 int rc; 41 char *retoid = NULL; 42 43 assert( ld != NULL ); 44 assert( LDAP_VALID( ld ) ); 45 assert( res != NULL ); 46 assert( authzid != NULL ); 47 48 *authzid = NULL; 49 50 rc = ldap_parse_extended_result( ld, res, &retoid, authzid, 0 ); 51 52 if( rc != LDAP_SUCCESS ) { 53 ldap_perror( ld, "ldap_parse_whoami" ); 54 return rc; 55 } 56 57 ber_memfree( retoid ); 58 return rc; 59} 60 61int 62ldap_whoami( LDAP *ld, 63 LDAPControl **sctrls, 64 LDAPControl **cctrls, 65 int *msgidp ) 66{ 67 int rc; 68 69 assert( ld != NULL ); 70 assert( LDAP_VALID( ld ) ); 71 assert( msgidp != NULL ); 72 73 rc = ldap_extended_operation( ld, LDAP_EXOP_WHO_AM_I, 74 NULL, sctrls, cctrls, msgidp ); 75 76 return rc; 77} 78 79int 80ldap_whoami_s( 81 LDAP *ld, 82 struct berval **authzid, 83 LDAPControl **sctrls, 84 LDAPControl **cctrls ) 85{ 86 int rc; 87 int msgid; 88 LDAPMessage *res; 89 90 rc = ldap_whoami( ld, sctrls, cctrls, &msgid ); 91 if ( rc != LDAP_SUCCESS ) return rc; 92 93 if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res ) { 94 return ld->ld_errno; 95 } 96 97 rc = ldap_parse_whoami( ld, res, authzid ); 98 if( rc != LDAP_SUCCESS ) { 99 ldap_msgfree( res ); 100 return rc; 101 } 102 103 return( ldap_result2error( ld, res, 1 ) ); 104} 105