1 /* allop.c - returns all operational attributes when appropriate */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2012 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 in
22 * The intended usage is as a global overlay for use with those clients
23 * that do not make use of the RFC3673 allOp ("+") in the requested
24 * attribute list, but expect all operational attributes to be returned.
32 * if the allop-URI is not given, the rootDSE, i.e. "ldap:///??base",
39 #include <ac/string.h>
44 #define SLAP_OVER_VERSION_REQUIRE(major,minor,patch) \
46 ( LDAP_VENDOR_VERSION_MAJOR == X || LDAP_VENDOR_VERSION_MAJOR >= (major) ) \
47 && ( LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR >= (minor) ) \
48 && ( LDAP_VENDOR_VERSION_PATCH == X || LDAP_VENDOR_VERSION_PATCH >= (patch) ) \
51 #if !SLAP_OVER_VERSION_REQUIRE(2,3,0)
52 #error "version mismatch"
55 typedef struct allop_t {
68 slap_overinst *on = (slap_overinst *)be->bd_info;
69 allop_t *ao = (allop_t *)on->on_bi.bi_private;
71 if ( strcasecmp( argv[ 0 ], "allop-uri" ) == 0 ) {
79 fprintf( stderr, "%s line %d: "
81 "in \"allop-uri <ldapURI>\" "
87 if ( ldap_url_parse( argv[ 1 ], &lud ) != LDAP_URL_SUCCESS ) {
91 scope = lud->lud_scope;
92 if ( scope == LDAP_SCOPE_DEFAULT ) {
93 scope = LDAP_SCOPE_BASE;
96 if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
97 if ( scope == LDAP_SCOPE_BASE ) {
101 ber_str2bv( "", 0, 1, &ndn );
106 ber_str2bv( lud->lud_dn, 0, 0, &dn );
107 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
110 ldap_free_urldesc( lud );
111 if ( rc != LDAP_SUCCESS ) {
115 if ( BER_BVISNULL( &ndn ) ) {
118 ch_free( ao->ao_ndn.bv_val );
120 on->on_bi.bi_private = NULL;
125 ao = ch_calloc( 1, sizeof( allop_t ) );
126 on->on_bi.bi_private = (void *)ao;
129 ch_free( ao->ao_ndn.bv_val );
133 ao->ao_scope = scope;
137 return SLAP_CONF_UNKNOWN;
144 allop_db_destroy( BackendDB *be, ConfigReply *cr )
146 slap_overinst *on = (slap_overinst *)be->bd_info;
147 allop_t *ao = (allop_t *)on->on_bi.bi_private;
150 assert( !BER_BVISNULL( &ao->ao_ndn ) );
152 ch_free( ao->ao_ndn.bv_val );
154 on->on_bi.bi_private = NULL;
161 allop_op_search( Operation *op, SlapReply *rs )
163 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
164 allop_t *ao = (allop_t *)on->on_bi.bi_private;
171 if ( !BER_BVISEMPTY( &op->o_req_ndn )
172 || op->ors_scope != LDAP_SCOPE_BASE )
174 return SLAP_CB_CONTINUE;
178 if ( !dnIsSuffix( &op->o_req_ndn, &ao->ao_ndn ) ) {
179 return SLAP_CB_CONTINUE;
182 switch ( ao->ao_scope ) {
183 case LDAP_SCOPE_BASE:
184 if ( op->o_req_ndn.bv_len != ao->ao_ndn.bv_len ) {
185 return SLAP_CB_CONTINUE;
189 case LDAP_SCOPE_ONELEVEL:
190 if ( op->ors_scope == LDAP_SCOPE_BASE ) {
191 struct berval rdn = op->o_req_ndn;
193 rdn.bv_len -= ao->ao_ndn.bv_len + STRLENOF( "," );
194 if ( !dnIsOneLevelRDN( &rdn ) ) {
195 return SLAP_CB_CONTINUE;
200 return SLAP_CB_CONTINUE;
202 case LDAP_SCOPE_SUBTREE:
207 mask = slap_attr_flags( op->ors_attrs );
208 if ( SLAP_OPATTRS( mask ) ) {
209 return SLAP_CB_CONTINUE;
212 if ( !SLAP_USERATTRS( mask ) ) {
213 return SLAP_CB_CONTINUE;
217 if ( op->ors_attrs == NULL ) {
221 for ( ; !BER_BVISNULL( &op->ors_attrs[ i ].an_name ); i++ )
225 op->ors_attrs = op->o_tmprealloc( op->ors_attrs,
226 sizeof( AttributeName ) * ( i + add_allUser + 2 ),
230 op->ors_attrs[ i ] = slap_anlist_all_user_attributes[ 0 ];
234 op->ors_attrs[ i ] = slap_anlist_all_operational_attributes[ 0 ];
236 BER_BVZERO( &op->ors_attrs[ i + 1 ].an_name );
238 return SLAP_CB_CONTINUE;
241 static slap_overinst allop;
246 allop.on_bi.bi_type = "allop";
248 allop.on_bi.bi_db_config = allop_db_config;
249 allop.on_bi.bi_db_destroy = allop_db_destroy;
251 allop.on_bi.bi_op_search = allop_op_search;
253 return overlay_register( &allop );
257 init_module( int argc, char *argv[] )