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",
38 #ifdef SLAPD_OVER_ALLOP
41 #include <ac/string.h>
45 typedef struct allop_t {
58 slap_overinst *on = (slap_overinst *)be->bd_info;
59 allop_t *ao = (allop_t *)on->on_bi.bi_private;
61 if ( strcasecmp( argv[ 0 ], "allop-uri" ) == 0 ) {
69 fprintf( stderr, "%s line %d: "
71 "in \"allop-uri <ldapURI>\" "
77 if ( ldap_url_parse( argv[ 1 ], &lud ) != LDAP_URL_SUCCESS ) {
81 scope = lud->lud_scope;
82 if ( scope == LDAP_SCOPE_DEFAULT ) {
83 scope = LDAP_SCOPE_BASE;
86 if ( lud->lud_dn == NULL || lud->lud_dn[ 0 ] == '\0' ) {
87 if ( scope == LDAP_SCOPE_BASE ) {
91 ber_str2bv( "", 0, 1, &ndn );
96 ber_str2bv( lud->lud_dn, 0, 0, &dn );
97 rc = dnNormalize( 0, NULL, NULL, &dn, &ndn, NULL );
100 ldap_free_urldesc( lud );
101 if ( rc != LDAP_SUCCESS ) {
105 if ( BER_BVISNULL( &ndn ) ) {
108 ch_free( ao->ao_ndn.bv_val );
110 on->on_bi.bi_private = NULL;
115 ao = ch_calloc( 1, sizeof( allop_t ) );
116 on->on_bi.bi_private = (void *)ao;
119 ch_free( ao->ao_ndn.bv_val );
123 ao->ao_scope = scope;
127 return SLAP_CONF_UNKNOWN;
134 allop_db_destroy( BackendDB *be )
136 slap_overinst *on = (slap_overinst *)be->bd_info;
137 allop_t *ao = (allop_t *)on->on_bi.bi_private;
140 assert( !BER_BVISNULL( &ao->ao_ndn ) );
142 ch_free( ao->ao_ndn.bv_val );
144 on->on_bi.bi_private = NULL;
151 allop_op_search( Operation *op, SlapReply *rs )
153 slap_overinst *on = (slap_overinst *)op->o_bd->bd_info;
154 allop_t *ao = (allop_t *)on->on_bi.bi_private;
161 if ( !BER_BVISEMPTY( &op->o_req_ndn )
162 || op->ors_scope != LDAP_SCOPE_BASE )
164 return SLAP_CB_CONTINUE;
168 if ( !dnIsSuffix( &op->o_req_ndn, &ao->ao_ndn ) ) {
169 return SLAP_CB_CONTINUE;
172 switch ( ao->ao_scope ) {
173 case LDAP_SCOPE_BASE:
174 if ( op->o_req_ndn.bv_len != ao->ao_ndn.bv_len ) {
175 return SLAP_CB_CONTINUE;
179 case LDAP_SCOPE_ONELEVEL:
180 if ( op->ors_scope == LDAP_SCOPE_BASE ) {
181 struct berval rdn = op->o_req_ndn;
183 rdn.bv_len -= ao->ao_ndn.bv_len + STRLENOF( "," );
184 if ( !dnIsOneLevelRDN( &rdn ) ) {
185 return SLAP_CB_CONTINUE;
190 return SLAP_CB_CONTINUE;
192 case LDAP_SCOPE_SUBTREE:
197 mask = slap_attr_flags( op->ors_attrs );
198 if ( SLAP_OPATTRS( mask ) ) {
199 return SLAP_CB_CONTINUE;
202 if ( !SLAP_USERATTRS( mask ) ) {
203 return SLAP_CB_CONTINUE;
207 if ( op->ors_attrs == NULL ) {
211 for ( ; !BER_BVISNULL( &op->ors_attrs[ i ].an_name ); i++ )
215 op->ors_attrs = op->o_tmprealloc( op->ors_attrs,
216 sizeof( AttributeName ) * ( i + add_allUser + 2 ),
220 op->ors_attrs[ i ] = slap_anlist_all_user_attributes[ 0 ];
224 op->ors_attrs[ i ] = slap_anlist_all_operational_attributes[ 0 ];
226 BER_BVZERO( &op->ors_attrs[ i + 1 ].an_name );
228 return SLAP_CB_CONTINUE;
231 static slap_overinst allop;
236 allop.on_bi.bi_type = "allop";
238 allop.on_bi.bi_db_config = allop_db_config;
239 allop.on_bi.bi_db_destroy = allop_db_destroy;
241 allop.on_bi.bi_op_search = allop_op_search;
243 return overlay_register( &allop );
246 #if SLAPD_OVER_ALLOP == SLAPD_MOD_DYNAMIC
248 init_module( int argc, char *argv[] )
252 #endif /* SLAPD_OVER_ALLOP == SLAPD_MOD_DYNAMIC */
254 #endif /* defined(SLAPD_OVER_ALLOP) */