No empty .Rs/.Re
[netbsd-mini2440.git] / external / bsd / openldap / dist / libraries / libldap / whoami.c
blob07606b132376395f11481b0eba98a7eef37dd012
1 /* $OpenLDAP: pkg/ldap/libraries/libldap/whoami.c,v 1.10.2.3 2008/02/11 23:26:41 kurt Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * All rights reserved.
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.
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>.
15 /* ACKNOWLEDGEMENTS:
16 * This program was orignally developed by Kurt D. Zeilenga for inclusion in
17 * OpenLDAP Software.
20 #include "portable.h"
22 #include <stdio.h>
23 #include <ac/stdlib.h>
24 #include <ac/string.h>
25 #include <ac/time.h>
27 #include "ldap-int.h"
30 * LDAP Who Am I? (Extended) Operation <draft-zeilenga-ldap-authzid-xx.txt>
33 int ldap_parse_whoami(
34 LDAP *ld,
35 LDAPMessage *res,
36 struct berval **authzid )
38 int rc;
39 char *retoid = NULL;
41 assert( ld != NULL );
42 assert( LDAP_VALID( ld ) );
43 assert( res != NULL );
44 assert( authzid != NULL );
46 *authzid = NULL;
48 rc = ldap_parse_extended_result( ld, res, &retoid, authzid, 0 );
50 if( rc != LDAP_SUCCESS ) {
51 ldap_perror( ld, "ldap_parse_whoami" );
52 return rc;
55 ber_memfree( retoid );
56 return rc;
59 int
60 ldap_whoami( LDAP *ld,
61 LDAPControl **sctrls,
62 LDAPControl **cctrls,
63 int *msgidp )
65 int rc;
67 assert( ld != NULL );
68 assert( LDAP_VALID( ld ) );
69 assert( msgidp != NULL );
71 rc = ldap_extended_operation( ld, LDAP_EXOP_WHO_AM_I,
72 NULL, sctrls, cctrls, msgidp );
74 return rc;
77 int
78 ldap_whoami_s(
79 LDAP *ld,
80 struct berval **authzid,
81 LDAPControl **sctrls,
82 LDAPControl **cctrls )
84 int rc;
85 int msgid;
86 LDAPMessage *res;
88 rc = ldap_whoami( ld, sctrls, cctrls, &msgid );
89 if ( rc != LDAP_SUCCESS ) return rc;
91 if ( ldap_result( ld, msgid, LDAP_MSG_ALL, (struct timeval *) NULL, &res ) == -1 || !res ) {
92 return ld->ld_errno;
95 rc = ldap_parse_whoami( ld, res, authzid );
96 if( rc != LDAP_SUCCESS ) {
97 ldap_msgfree( res );
98 return rc;
101 return( ldap_result2error( ld, res, 1 ) );