1 /* vc.c - LDAP Verify Credentials extop (no spec yet) */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2010 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
17 * This work was initially developed by Pierangelo Masarati for inclusion
18 * in OpenLDAP Software.
29 #include "ac/string.h"
31 static int authzid_cid;
38 if ( rs->sr_tag == LDAP_RES_BIND ) {
44 if ( rs->sr_err == LDAP_SASL_BIND_IN_PROGRESS ) {
45 if ( op->o_ctrlflag[ authzid_cid ] == SLAP_CONTROL_CRITICAL ) {
46 return rs->sr_err = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
49 op->o_ctrlflag[ authzid_cid ] = SLAP_CONTROL_IGNORED;
51 return SLAP_CB_CONTINUE;
53 /* end of TEMPORARY! */
55 if ( !BER_BVISEMPTY( &op->o_conn->c_dn ) ) {
56 len = STRLENOF("dn:") + op->o_conn->c_dn.bv_len;
59 /* save original controls in sc_private;
60 * will be restored by sc_cleanup
62 if ( rs->sr_ctrls != NULL ) {
63 op->o_callback->sc_private = rs->sr_ctrls;
64 for ( ; rs->sr_ctrls[n] != NULL; n++ )
68 ctrls = op->o_tmpalloc( sizeof( LDAPControl * )*( n + 2 ), op->o_tmpmemctx );
71 for ( ; rs->sr_ctrls[n] != NULL; n++ ) {
72 ctrls[n] = rs->sr_ctrls[n];
76 /* anonymous: "", otherwise "dn:<dn>" */
77 ctrls[n] = op->o_tmpalloc( sizeof( LDAPControl ) + len + 1, op->o_tmpmemctx );
78 ctrls[n]->ldctl_oid = LDAP_CONTROL_AUTHZID_RESPONSE;
79 ctrls[n]->ldctl_iscritical = 0;
80 ctrls[n]->ldctl_value.bv_len = len;
81 ctrls[n]->ldctl_value.bv_val = (char *)&ctrls[n][1];
85 ptr = lutil_strcopy( ctrls[n]->ldctl_value.bv_val, "dn:" );
86 ptr = lutil_strncopy( ptr, op->o_conn->c_dn.bv_val, op->o_conn->c_dn.bv_len );
88 ctrls[n]->ldctl_value.bv_val[len] = '\0';
94 return SLAP_CB_CONTINUE;
102 if ( rs->sr_ctrls ) {
105 /* if ours, cleanup */
106 ctrl = ldap_control_find( LDAP_CONTROL_AUTHZID_RESPONSE, rs->sr_ctrls, NULL );
108 op->o_tmpfree( ctrl, op->o_tmpmemctx );
109 op->o_tmpfree( rs->sr_ctrls, op->o_tmpmemctx );
112 if ( op->o_callback->sc_private != NULL ) {
113 rs->sr_ctrls = (LDAPControl **)op->o_callback->sc_private;
114 op->o_callback->sc_private = NULL;
118 op->o_tmpfree( op->o_callback, op->o_tmpmemctx );
119 op->o_callback = NULL;
121 return SLAP_CB_CONTINUE;
132 if ( op->o_ctrlflag[ authzid_cid ] != SLAP_CONTROL_NONE ) {
133 rs->sr_text = "authzid control specified multiple times";
134 return LDAP_PROTOCOL_ERROR;
137 if ( !BER_BVISNULL( &ctrl->ldctl_value ) ) {
138 rs->sr_text = "authzid control value not absent";
139 return LDAP_PROTOCOL_ERROR;
142 op->o_ctrlflag[ authzid_cid ] = ctrl->ldctl_iscritical ? SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL;
145 op->o_callback = op->o_tmpalloc( sizeof( slap_callback ), op->o_tmpmemctx );
146 op->o_callback->sc_response = authzid_response;
147 op->o_callback->sc_cleanup = authzid_cleanup;
148 op->o_callback->sc_private = NULL;
149 op->o_callback->sc_next = sc;
155 authzid_initialize( void )
159 rc = register_supported_control( LDAP_CONTROL_AUTHZID_REQUEST,
160 SLAP_CTRL_GLOBAL|SLAP_CTRL_BIND|SLAP_CTRL_HIDE, NULL,
161 parse_authzid_ctrl, &authzid_cid );
162 if ( rc != LDAP_SUCCESS ) {
163 Debug( LDAP_DEBUG_ANY,
164 "authzid_initialize: failed to register control %s (%d)\n",
165 LDAP_CONTROL_AUTHZID_REQUEST, rc, 0 );
173 init_module( int argc, char *argv[] )
175 return authzid_initialize();