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