Back to index

openldap  2.4.31
whoami.c
Go to the documentation of this file.
00001 /* $OpenLDAP$ */
00002 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
00003  *
00004  * Copyright 1998-2012 The OpenLDAP Foundation.
00005  * All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted only as authorized by the OpenLDAP
00009  * Public License.
00010  *
00011  * A copy of this license is available in the file LICENSE in the
00012  * top-level directory of the distribution or, alternatively, at
00013  * <http://www.OpenLDAP.org/license.html>.
00014  */
00015 /* ACKNOWLEDGEMENTS:
00016  * This program was orignally developed by Kurt D. Zeilenga for inclusion in
00017  * OpenLDAP Software.
00018  */
00019 
00020 #include "portable.h"
00021 
00022 #include <stdio.h>
00023 #include <ac/stdlib.h>
00024 #include <ac/string.h>
00025 #include <ac/time.h>
00026 
00027 #include "ldap-int.h"
00028 
00029 /*
00030  * LDAP Who Am I? (Extended) Operation <draft-zeilenga-ldap-authzid-xx.txt>
00031  */
00032 
00033 int ldap_parse_whoami(
00034        LDAP *ld,
00035        LDAPMessage *res,
00036        struct berval **authzid )
00037 {
00038        int rc;
00039        char *retoid = NULL;
00040 
00041        assert( ld != NULL );
00042        assert( LDAP_VALID( ld ) );
00043        assert( res != NULL );
00044        assert( authzid != NULL );
00045 
00046        *authzid = NULL;
00047 
00048        rc = ldap_parse_extended_result( ld, res, &retoid, authzid, 0 );
00049 
00050        if( rc != LDAP_SUCCESS ) {
00051               ldap_perror( ld, "ldap_parse_whoami" );
00052               return rc;
00053        }
00054 
00055        ber_memfree( retoid );
00056        return rc;
00057 }
00058 
00059 int
00060 ldap_whoami( LDAP *ld,
00061        LDAPControl          **sctrls,
00062        LDAPControl          **cctrls,
00063        int                         *msgidp )
00064 {
00065        int rc;
00066 
00067        assert( ld != NULL );
00068        assert( LDAP_VALID( ld ) );
00069        assert( msgidp != NULL );
00070 
00071        rc = ldap_extended_operation( ld, LDAP_EXOP_WHO_AM_I,
00072               NULL, sctrls, cctrls, msgidp );
00073 
00074        return rc;
00075 }
00076 
00077 int
00078 ldap_whoami_s(
00079        LDAP *ld,
00080        struct berval **authzid,
00081        LDAPControl **sctrls,
00082        LDAPControl **cctrls )
00083 {
00084        int           rc;
00085        int           msgid;
00086        LDAPMessage   *res;
00087 
00088        rc = ldap_whoami( ld, sctrls, cctrls, &msgid );
00089        if ( rc != LDAP_SUCCESS ) return rc;
00090 
00091        if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res ) {
00092               return ld->ld_errno;
00093        }
00094 
00095        rc = ldap_parse_whoami( ld, res, authzid );
00096        if( rc != LDAP_SUCCESS ) {
00097               ldap_msgfree( res );
00098               return rc;
00099        }
00100 
00101        return( ldap_result2error( ld, res, 1 ) );
00102 }