1 /* allop.c - returns all operational attributes when appropriate */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005 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>
43 #define SLAP_OVER_VERSION_REQUIRE(major,minor,patch) \
45 ( LDAP_VENDOR_VERSION_MAJOR == X || LDAP_VENDOR_VERSION_MAJOR >= (major) ) \
46 && ( LDAP_VENDOR_VERSION_MINOR == X || LDAP_VENDOR_VERSION_MINOR >= (minor) ) \
47 && ( LDAP_VENDOR_VERSION_PATCH == X || LDAP_VENDOR_VERSION_PATCH >= (patch) ) \
50 #if !SLAP_OVER_VERSION_REQUIRE(2,3,0)
51 #error "version mismatch"
54 typedef struct allop_t {
67 slap_overinst *on = (slap_overinst *)be->bd_info;
68 allop_t *ao = (allop_t *)on->on_bi.bi_private;
70 if ( strcasecmp( argv[ 0 ], "allop-uri" ) == 0 ) {
78 fprintf( stderr, "%s line %d: "
80 "in \"allop-uri <ldapURI>\" "
86 if ( ldap_url_parse( argv[ 1 ], &lud ) != LDAP_URL_SUCCESS ) {
90 scope = lud->lud_scope;
91 if ( scope == LDAP_SCOPE_DEFAULT ) {
92 scope = LDAP_SCOPE_BASE;
95 if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
96 if ( scope == LDAP_SCOPE_BASE ) {
100 ber_str2bv( "", 0, 1, &ndn );
105 ber_str2bv( lud->lud_dn, 0, 0, &dn );
106 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
109 ldap_free_urldesc( lud );
110 if ( rc != LDAP_SUCCESS ) {
114 if ( BER_BVISNULL( &ndn ) ) {
117 ch_free( ao->ao_ndn.bv_val );
119 on->on_bi.bi_private = NULL;
124 ao = ch_calloc( 1, sizeof( allop_t ) );
125 on->on_bi.bi_private = (void *)ao;
128 ch_free( ao->ao_ndn.bv_val );
132 ao->ao_scope = scope;
136 return SLAP_CONF_UNKNOWN;
143 allop_db_destroy( BackendDB *be )
145 slap_overinst *on = (slap_overinst *)be->bd_info;
146 allop_t *ao = (allop_t *)on->on_bi.bi_private;
149 assert( !BER_BVISNULL( &ao->ao_ndn ) );
151 ch_free( ao->ao_ndn.bv_val );
153 on->on_bi.bi_private = NULL;
160 allop_op_search( Operation *op, SlapReply *rs )
162 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
163 allop_t *ao = (allop_t *)on->on_bi.bi_private;
170 if ( !BER_BVISEMPTY( &op->o_req_ndn )
171 || op->ors_scope != LDAP_SCOPE_BASE )
173 return SLAP_CB_CONTINUE;
177 if ( !dnIsSuffix( &op->o_req_ndn, &ao->ao_ndn ) ) {
178 return SLAP_CB_CONTINUE;
181 switch ( ao->ao_scope ) {
182 case LDAP_SCOPE_BASE:
183 if ( op->o_req_ndn.bv_len != ao->ao_ndn.bv_len ) {
184 return SLAP_CB_CONTINUE;
188 case LDAP_SCOPE_ONELEVEL:
189 if ( op->ors_scope == LDAP_SCOPE_BASE ) {
190 struct berval rdn = op->o_req_ndn;
192 rdn.bv_len -= ao->ao_ndn.bv_len + STRLENOF( "," );
193 if ( !dnIsOneLevelRDN( &rdn ) ) {
194 return SLAP_CB_CONTINUE;
199 return SLAP_CB_CONTINUE;
201 case LDAP_SCOPE_SUBTREE:
206 mask = slap_attr_flags( op->ors_attrs );
207 if ( SLAP_OPATTRS( mask ) ) {
208 return SLAP_CB_CONTINUE;
211 if ( !SLAP_USERATTRS( mask ) ) {
212 return SLAP_CB_CONTINUE;
216 if ( op->ors_attrs == NULL ) {
220 for ( ; !BER_BVISNULL( &op->ors_attrs[ i ].an_name ); i++ )
224 op->ors_attrs = op->o_tmprealloc( op->ors_attrs,
225 sizeof( AttributeName ) * ( i + add_allUser + 2 ),
229 op->ors_attrs[ i ] = slap_anlist_all_user_attributes[ 0 ];
233 op->ors_attrs[ i ] = slap_anlist_all_operational_attributes[ 0 ];
235 BER_BVZERO( &op->ors_attrs[ i + 1 ].an_name );
237 return SLAP_CB_CONTINUE;
240 static slap_overinst allop;
245 allop.on_bi.bi_type = "allop";
247 allop.on_bi.bi_db_config = allop_db_config;
248 allop.on_bi.bi_db_destroy = allop_db_destroy;
250 allop.on_bi.bi_op_search = allop_op_search;
252 return overlay_register( &allop );
256 init_module( int argc, char *argv[] )