]> git.sur5r.net Git - openldap/blob - libraries/libldap/whoami.c
unifdef -DLDAP_NOCACHE
[openldap] / libraries / libldap / whoami.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
4  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
5  */
6
7 #include "portable.h"
8
9 #include <stdio.h>
10 #include <ac/stdlib.h>
11 #include <ac/string.h>
12 #include <ac/time.h>
13
14 #include "ldap-int.h"
15
16 /*
17  * LDAP Who Am I? (Extended) Operation <draft-zeilenga-ldap-authzid-xx.txt>
18  */
19
20 int ldap_parse_whoami(
21         LDAP *ld,
22         LDAPMessage *res,
23         struct berval **authzid )
24 {
25         int rc;
26         char *retoid = NULL;
27
28         assert( ld != NULL );
29         assert( LDAP_VALID( ld ) );
30         assert( res != NULL );
31         assert( authzid != NULL );
32
33         *authzid = NULL;
34
35         rc = ldap_parse_extended_result( ld, res, &retoid, authzid, 0 );
36
37         if( rc != LDAP_SUCCESS ) {
38                 ldap_perror( ld, "ldap_parse_whoami" );
39                 return rc;
40         }
41
42         ber_memfree( retoid );
43         return rc;
44 }
45
46 int
47 ldap_whoami( LDAP *ld,
48         LDAPControl             **sctrls,
49         LDAPControl             **cctrls,
50         int                             *msgidp )
51 {
52         int rc;
53
54         assert( ld != NULL );
55         assert( LDAP_VALID( ld ) );
56         assert( msgidp != NULL );
57
58         rc = ldap_extended_operation( ld, LDAP_EXOP_X_WHO_AM_I,
59                 NULL, sctrls, cctrls, msgidp );
60
61         return rc;
62 }
63
64 int
65 ldap_whoami_s(
66         LDAP *ld,
67         struct berval **authzid,
68         LDAPControl **sctrls,
69         LDAPControl **cctrls )
70 {
71         int             rc;
72         int             msgid;
73         LDAPMessage     *res;
74
75         rc = ldap_whoami( ld, sctrls, cctrls, &msgid );
76         if ( rc != LDAP_SUCCESS ) return rc;
77
78         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 ) {
79                 return ld->ld_errno;
80         }
81
82         rc = ldap_parse_whoami( ld, res, authzid );
83         if( rc != LDAP_SUCCESS ) {
84                 ldap_msgfree( res );
85                 return rc;
86         }
87
88         return( ldap_result2error( ld, res, 1 ) );
89 }