-#else
-static int
-slap_sasl_authorize(
- void *context,
- char *authcid,
- char *authzid,
- const char **user,
- const char **errstr)
-{
- struct berval authcDN, authzDN = BER_BVNULL;
- int rc;
- Connection *conn = context;
- char *realm;
- struct berval bvauthcid, bvauthzid;
-
- *user = NULL;
- if ( conn->c_sasl_dn.bv_val ) {
- ch_free( conn->c_sasl_dn.bv_val );
- BER_BVZERO( &conn->c_sasl_dn );
- }
-
- Debug( LDAP_DEBUG_ARGS, "SASL Authorize [conn=%ld]: "
- "authcid=\"%s\" authzid=\"%s\"\n",
- (long) (conn ? conn->c_connid : -1),
- authcid ? authcid : "<empty>",
- authzid ? authzid : "<empty>" );
-
- /* Figure out how much data we have for the dn */
- rc = sasl_getprop( conn->c_sasl_authctx, SASL_REALM, (void **)&realm );
- if( rc != SASL_OK && rc != SASL_NOTDONE ) {
- Debug(LDAP_DEBUG_TRACE,
- "authorize: getprop(REALM) failed!\n", 0,0,0);
- *errstr = "Could not extract realm";
- return SASL_NOAUTHZ;
- }
-
- /* Convert the identities to DN's. If no authzid was given, client will
- be bound as the DN matching their username */
- bvauthcid.bv_val = authcid;
- bvauthcid.bv_len = authcid ? strlen( authcid ) : 0;
- rc = slap_sasl_getdn( conn, NULL, &bvauthcid, realm,
- &authcDN, SLAP_GETDN_AUTHCID );
- if( rc != LDAP_SUCCESS ) {
- *errstr = ldap_err2string( rc );
- return SASL_NOAUTHZ;
- }
- conn->c_sasl_dn = authcDN;
- if( ( authzid == NULL ) || !strcmp( authcid, authzid ) ) {
- Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
- "Using authcDN=%s\n", (long) (conn ? conn->c_connid : -1), authcDN.bv_val,0 );
-
- goto ok;
- }
-
- bvauthzid.bv_val = authzid;
- bvauthzid.bv_len = authzid ? strlen( authzid ) : 0;
- rc = slap_sasl_getdn( conn, NULL, &bvauthzid, realm,
- &authzDN, SLAP_GETDN_AUTHZID );
- if( rc != LDAP_SUCCESS ) {
- *errstr = ldap_err2string( rc );
- return SASL_NOAUTHZ;
- }
-
- rc = slap_sasl_authorized( conn->c_sasl_bindop, &authcDN, &authzDN );
- if( rc ) {
- Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
- "proxy authorization disallowed (%d)\n",
- (long) (conn ? conn->c_connid : -1), rc, 0 );
-
- *errstr = "not authorized";
- ch_free( authzDN.bv_val );
- return SASL_NOAUTHZ;
- }
-
- /* FIXME: we need yet another dup because slap_sasl_getdn()
- * is using the bind operation slab */
- if ( conn->c_sasl_bindop ) {
- ber_dupbv( &conn->c_sasl_authz_dn, &authzDN );
- slap_sl_free( authzDN.bv_val,
- conn->c_sasl_bindop->o_tmpmemctx );
-
- } else {
- conn->c_sasl_authz_dn = authzDN;
- }
-
-ok:
- Debug( LDAP_DEBUG_TRACE, "SASL Authorize [conn=%ld]: "
- " authorization allowed authzDN=\"%s\"\n",
- (long) (conn ? conn->c_connid : -1),
- authzDN.bv_val ? authzDN.bv_val : "", 0 );
-
- if ( conn->c_sasl_bindop ) {
- Statslog( LDAP_DEBUG_STATS,
- "conn=%lu op=%lu BIND authcid=\"%s\" authzid=\"%s\"\n",
- conn->c_connid, conn->c_sasl_bindop->o_opid,
- authcid, authzid ? authzid : "", 0);
- }
-
- *errstr = NULL;
- return SASL_OK;
-}
-#endif /* SASL_VERSION_MAJOR >= 2 */