/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright 2001-2005 The OpenLDAP Foundation.
+ * Copyright 2001-2006 The OpenLDAP Foundation.
* Portions Copyright 2001-2003 Pierangelo Masarati.
* All rights reserved.
*
#if 0 && defined(SLAPD_LDBM)
#include "../back-ldbm/back-ldbm.h"
#endif /* defined(SLAPD_LDBM) */
+#if defined(SLAPD_META)
+#include "../back-meta/back-meta.h"
+#endif /* defined(SLAPD_META) */
/* for PATH_MAX on some systems (e.g. Solaris) */
#ifdef HAVE_LIMITS_H
#define PATH_MAX 4095
#endif /* ! PATH_MAX */
+static int
+monitor_subsys_database_modify(
+ Operation *op,
+ SlapReply *rs,
+ Entry *e );
+
static struct restricted_ops_t {
struct berval op;
unsigned int tag;
struct berval *tf = ( ( restrictops & SLAP_RESTRICT_OP_MASK ) == SLAP_RESTRICT_OP_WRITES ) ?
(struct berval *)&slap_true_bv : (struct berval *)&slap_false_bv;
- return attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL );
+ return attr_merge_one( e, mi->mi_ad_readOnly, tf, tf );
}
static int
for ( i = 0; restricted_ops[ i ].op.bv_val; i++ ) {
if ( restrictops & restricted_ops[ i ].tag ) {
rc = attr_merge_one( e, mi->mi_ad_restrictedOperation,
- &restricted_ops[ i ].op, NULL );
+ &restricted_ops[ i ].op,
+ &restricted_ops[ i ].op );
if ( rc ) {
return rc;
}
for ( i = 0; restricted_exops[ i ].op.bv_val; i++ ) {
if ( restrictops & restricted_exops[ i ].tag ) {
rc = attr_merge_one( e, mi->mi_ad_restrictedOperation,
- &restricted_exops[ i ].op, NULL );
+ &restricted_exops[ i ].op,
+ &restricted_exops[ i ].op );
if ( rc ) {
return rc;
}
assert( be != NULL );
+ ms->mss_modify = monitor_subsys_database_modify;
+
mi = ( monitor_info_t * )be->be_private;
ms_backend = monitor_back_get_subsys( SLAPD_MONITOR_BACKEND_NAME );
slap_overinfo *oi = NULL;
BackendInfo *bi, *bi2;
Entry *e;
+ struct berval bv;
i++;
continue;
}
- snprintf( buf, sizeof( buf ),
- "dn: cn=Database %d,%s\n"
- "objectClass: %s\n"
- "structuralObjectClass: %s\n"
- "cn: Database %d\n"
- "description: This object contains the type of the database.\n"
- "%s: %s\n"
- "creatorsName: %s\n"
- "modifiersName: %s\n"
- "createTimestamp: %s\n"
- "modifyTimestamp: %s\n",
- i,
- ms->mss_dn.bv_val,
- mi->mi_oc_monitoredObject->soc_cname.bv_val,
- mi->mi_oc_monitoredObject->soc_cname.bv_val,
- i,
- mi->mi_ad_monitoredInfo->ad_cname.bv_val,
- bi->bi_type,
- mi->mi_creatorsName.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_startTime.bv_val,
- mi->mi_startTime.bv_val );
-
- e = str2entry( buf );
+ bv.bv_len = snprintf( buf, sizeof( buf ),
+ "cn=Database %d", i );
+ bv.bv_val = buf;
+ e = monitor_entry_stub( &ms->mss_dn, &ms->mss_ndn, &bv,
+ mi->mi_oc_monitoredObject, mi, NULL, NULL );
+
if ( e == NULL ) {
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_database_init: "
i, ms->mss_dn.bv_val, 0 );
return( -1 );
}
-
- if ( SLAP_MONITOR(be) ) {
+
+ ber_str2bv( bi->bi_type, 0, 0, &bv );
+ attr_merge_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
+ attr_merge_one( e, mi->mi_ad_monitorIsShadow,
+ SLAP_SHADOW( be ) ? (struct berval *)&slap_true_bv :
+ (struct berval *)&slap_false_bv, NULL );
+
+ if ( SLAP_MONITOR( be ) ) {
attr_merge( e, slap_schema.si_ad_monitorContext,
be->be_suffix, be->be_nsuffix );
attr_merge( e_database, slap_schema.si_ad_monitorContext,
(void)init_readOnly( mi, e, be->be_restrictops );
(void)init_restrictedOperation( mi, e, be->be_restrictops );
+ if ( SLAP_SHADOW( be ) && be->be_update_refs ) {
+ attr_merge_normalize( e, mi->mi_ad_monitorUpdateRef,
+ be->be_update_refs, NULL );
+ }
+
if ( oi != NULL ) {
slap_overinst *on = oi->oi_list,
*on1 = on;
break;
}
- bv.bv_val = on->on_bi.bi_type;
- bv.bv_len = strlen( bv.bv_val );
+ ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
attr_merge_normalize_one( e, mi->mi_ad_monitorOverlay,
&bv, NULL );
break;
}
}
- assert( on2 );
+ assert( on2 != NULL );
snprintf( buf, sizeof( buf ),
"cn=Overlay %d,%s",
j, ms_overlay->mss_dn.bv_val );
- bv.bv_val = buf;
- bv.bv_len = strlen( buf );
- attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
+ ber_str2bv( buf, 0, 0, &bv );
+ attr_merge_normalize_one( e,
+ slap_schema.si_ad_seeAlso,
&bv, NULL );
}
}
+
+ if ( 0 ) {
+ assert( 0 );
+
#if defined(SLAPD_BDB) || defined(SLAPD_HDB)
- if ( strcmp( bi->bi_type, "bdb" ) == 0
+ } else if ( strcmp( bi->bi_type, "bdb" ) == 0
|| strcmp( bi->bi_type, "hdb" ) == 0 )
{
struct berval bv;
ber_len_t pathlen = 0, len = 0;
char path[ PATH_MAX ] = { '\0' };
- char *fname = NULL;
-
- if ( strcmp( bi->bi_type, "bdb" ) == 0
- || strcmp( bi->bi_type, "hdb" ) == 0 )
- {
- struct bdb_info *bdb = (struct bdb_info *) be->be_private;
-
- fname = bdb->bi_dbenv_home;
-#if 0
- } else if ( strcmp( bi->bi_type, "ldbm" ) == 0 ) {
- struct ldbminfo *ldbm = (struct ldbminfo *) be->be_private;
-
- /* FIXME: there's a conflict
- * between back-bdb.h and back.ldbm.h;
- * anyway, this code will be moved
- * to the backends as soon as the
- * issue with filtering on namingContexts
- * is fixed */
- fname = ldbm->li_directory;
-#endif
- }
+ struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+ char *fname = bdb->bi_dbenv_home;
len = strlen( fname );
if ( fname[ 0 ] != '/' ) {
&bv, NULL );
ch_free( bv.bv_val );
- }
-#endif /* defined(SLAPD_LDAP) || defined(SLAPD_HDB) */
+#endif /* defined(SLAPD_BDB) || defined(SLAPD_HDB) */
#if defined(SLAPD_LDAP)
- if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
- struct ldapinfo *li =
- (struct ldapinfo *)be->be_private;
- struct berval bv;
+ } else if ( strcmp( bi->bi_type, "ldap" ) == 0 ) {
+ ldapinfo_t *li = (ldapinfo_t *)be->be_private;
+#if 0
+ attr_merge_normalize( e, slap_schema.si_ad_labeledURI,
+ li->li_bvuri, NULL );
+#else
+ char **urls = ldap_str2charray( li->li_uri, " " );
- ber_str2bv( li->url, 0, 0, &bv );
+ if ( urls != NULL ) {
+ int u;
+
+ for ( u = 0; urls[ u ] != NULL; u++ ) {
+ struct berval bv;
+
+ ber_str2bv( urls[ u ], 0, 0, &bv );
+
+ attr_merge_normalize_one( e,
+ slap_schema.si_ad_labeledURI,
+ &bv, NULL );
+ }
+
+ ldap_charray_free( urls );
+ }
+#endif
- attr_merge_normalize_one( e,
- slap_schema.si_ad_labeledURI,
- &bv, NULL );
- }
#endif /* defined(SLAPD_LDAP) */
+#if defined(SLAPD_META)
+ } else if ( strcmp( bi->bi_type, "meta" ) == 0 ) {
+ metainfo_t *mi = (metainfo_t *)be->be_private;
+ int t;
+
+ for ( t = 0; t < mi->mi_ntargets; t++ ) {
+ char **urls = ldap_str2charray( mi->mi_targets[ t ].mt_uri, " " );
+
+ if ( urls != NULL ) {
+ int u;
+
+ for ( u = 0; urls[ u ] != NULL; u++ ) {
+ struct berval bv;
+
+ ber_str2bv( urls[ u ], 0, 0, &bv );
+
+ attr_merge_normalize_one( e,
+ slap_schema.si_ad_labeledURI,
+ &bv, NULL );
+ }
+ ldap_charray_free( urls );
+ }
+ }
+#endif /* defined(SLAPD_META) */
+ }
j = -1;
LDAP_STAILQ_FOREACH( bi2, &backendInfo, bi_next ) {
j, ms_backend->mss_dn.bv_val );
bv.bv_val = buf;
bv.bv_len = strlen( buf );
- attr_merge_normalize_one( e, mi->mi_ad_seeAlso,
+ attr_merge_normalize_one( e,
+ slap_schema.si_ad_seeAlso,
&bv, NULL );
break;
}
break;
}
}
- assert( on2 );
-
- snprintf( buf, sizeof( buf ),
- "dn: cn=Overlay %d,cn=Database %d,%s\n"
- "objectClass: %s\n"
- "structuralObjectClass: %s\n"
- "cn: Overlay %d\n"
- "description: This object contains the type of the overlay.\n"
- "%s: %s\n"
- "seeAlso: cn=Overlay %d,%s\n"
- "creatorsName: %s\n"
- "modifiersName: %s\n"
- "createTimestamp: %s\n"
- "modifyTimestamp: %s\n",
- o,
- i,
- ms->mss_dn.bv_val,
- mi->mi_oc_monitoredObject->soc_cname.bv_val,
- mi->mi_oc_monitoredObject->soc_cname.bv_val,
- o,
- mi->mi_ad_monitoredInfo->ad_cname.bv_val,
- on->on_bi.bi_type,
- j,
- ms_overlay->mss_dn.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_creatorsName.bv_val,
- mi->mi_startTime.bv_val,
- mi->mi_startTime.bv_val );
-
- e_overlay = str2entry( buf );
+ assert( on2 != NULL );
+
+ bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d", o );
+ bv.bv_val = buf;
+
+ e_overlay = monitor_entry_stub( &e->e_name, &e->e_nname, &bv,
+ mi->mi_oc_monitoredObject, mi, NULL, NULL );
+
if ( e_overlay == NULL ) {
Debug( LDAP_DEBUG_ANY,
"monitor_subsys_database_init: "
o, i, ms->mss_dn.bv_val );
return( -1 );
}
+ ber_str2bv( on->on_bi.bi_type, 0, 0, &bv );
+ attr_merge_one( e, mi->mi_ad_monitoredInfo, &bv, NULL );
+
+ bv.bv_len = snprintf( buf, sizeof( buf ), "cn=Overlay %d,%s",
+ j, ms_overlay->mss_dn.bv_val );
+ bv.bv_val = buf;
+ attr_merge_normalize_one( e, slap_schema.si_ad_seeAlso,
+ &bv, NULL );
mp_overlay = monitor_entrypriv_create();
if ( mp_overlay == NULL ) {
return LDAP_SUCCESS;
}
-int
+static int
monitor_subsys_database_modify(
Operation *op,
- Entry *e
-)
+ SlapReply *rs,
+ Entry *e )
{
monitor_info_t *mi = (monitor_info_t *)op->o_bd->be_private;
int rc = LDAP_OTHER;
Attribute *save_attrs, *a;
- Modifications *modlist = op->oq_modify.rs_modlist;
Modifications *ml;
Backend *be;
int ro_gotval = 1, i, n;
struct berval *tf;
i = sscanf( e->e_nname.bv_val, "cn=database %d,", &n );
- if ( i != 1 )
- return LDAP_UNWILLING_TO_PERFORM;
+ if ( i != 1 ) {
+ return SLAP_CB_CONTINUE;
+ }
- if ( n < 0 || n >= nBackendDB )
- return LDAP_NO_SUCH_OBJECT;
+ if ( n < 0 || n >= nBackendDB ) {
+ rs->sr_text = "invalid database index";
+ return ( rs->sr_err = LDAP_NO_SUCH_OBJECT );
+ }
LDAP_STAILQ_FOREACH( be, &backendDB, be_next ) {
- if ( n == 0 ) break;
+ if ( n == 0 ) {
+ break;
+ }
n--;
}
/* do not allow some changes on back-monitor (needs work)... */
- if ( SLAP_MONITOR( be ) )
- return LDAP_UNWILLING_TO_PERFORM;
+ if ( SLAP_MONITOR( be ) ) {
+ rs->sr_text = "no modifications allowed to monitor database entry";
+ return ( rs->sr_err = LDAP_UNWILLING_TO_PERFORM );
+ }
rp_cur = be->be_restrictops;
save_attrs = e->e_attrs;
e->e_attrs = attrs_dup( e->e_attrs );
- for ( ml=modlist; ml; ml=ml->sml_next ) {
+ for ( ml = op->orm_modlist; ml; ml = ml->sml_next ) {
Modification *mod = &ml->sml_mod;
if ( mod->sm_desc == mi->mi_ad_readOnly ) {
if ( mod->sm_values ) {
if ( !BER_BVISNULL( &mod->sm_values[ 1 ] ) ) {
- rc = LDAP_CONSTRAINT_VIOLATION;
+ rs->sr_text = "attempting to modify multiple values of single-valued attribute";
+ rc = rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
goto done;
}
val = 0;
} else {
- rc = LDAP_INVALID_SYNTAX;
+ assert( 0 );
+ rc = rs->sr_err = LDAP_INVALID_SYNTAX;
goto done;
}
}
switch ( mod->sm_op ) {
case LDAP_MOD_DELETE:
if ( ro_gotval < 1 ) {
- rc = LDAP_CONSTRAINT_VIOLATION;
+ rc = rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
goto done;
}
ro_gotval--;
if ( val == 0 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) == SLAP_RESTRICT_OP_WRITES ) {
- rc = LDAP_NO_SUCH_ATTRIBUTE;
+ rc = rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
goto done;
}
if ( val == 1 && ( rp_cur & SLAP_RESTRICT_OP_WRITES ) != SLAP_RESTRICT_OP_WRITES ) {
- rc = LDAP_NO_SUCH_ATTRIBUTE;
+ rc = rs->sr_err = LDAP_NO_SUCH_ATTRIBUTE;
goto done;
}
case LDAP_MOD_ADD:
if ( ro_gotval > 0 ) {
- rc = LDAP_CONSTRAINT_VIOLATION;
+ rc = rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
goto done;
}
ro_gotval++;
break;
default:
- rc = LDAP_OTHER;
+ rc = rs->sr_err = LDAP_OTHER;
goto done;
}
rp_delete &= ~mask;
} else if ( rc == LDAP_OTHER ) {
- rc = LDAP_TYPE_OR_VALUE_EXISTS;
+ rc = rs->sr_err = LDAP_TYPE_OR_VALUE_EXISTS;
}
break;
default:
- rc = LDAP_OTHER;
+ rc = rs->sr_err = LDAP_OTHER;
break;
}
rc = attr_merge( e, mod->sm_desc, mod->sm_values,
mod->sm_nvalues );
if ( rc ) {
- rc = LDAP_OTHER;
+ rc = rs->sr_err = LDAP_OTHER;
break;
}
} else {
- rc = LDAP_UNWILLING_TO_PERFORM;
+ rc = rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
break;
}
}
/* sanity checks: */
if ( ro_gotval < 1 ) {
- rc = LDAP_CONSTRAINT_VIOLATION;
+ rc = rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
goto done;
}
if ( ( rp_cur & SLAP_RESTRICT_OP_EXTENDED ) && ( rp_cur & SLAP_RESTRICT_EXOP_MASK ) ) {
- rc = LDAP_CONSTRAINT_VIOLATION;
+ rc = rs->sr_err = LDAP_CONSTRAINT_VIOLATION;
goto done;
}
if ( rp_delete & rp_add ) {
- rc = LDAP_OTHER;
+ rc = rs->sr_err = LDAP_OTHER;
goto done;
}
if ( !bvmatch( &a->a_vals[ 0 ], tf ) ) {
attr_delete( &e->e_attrs, mi->mi_ad_readOnly );
- rc = attr_merge_one( e, mi->mi_ad_readOnly, tf, NULL );
+ rc = attr_merge_one( e, mi->mi_ad_readOnly, tf, tf );
}
if ( rc == LDAP_SUCCESS ) {
} else {
a = attr_find( e->e_attrs, mi->mi_ad_restrictedOperation );
if ( a == NULL ) {
- rc = LDAP_OTHER;
+ rc = rs->sr_err = LDAP_OTHER;
goto done;
}
for ( i = 0; !BER_BVISNULL( &restricted_ops[ i ].op ); i++ ) {
if ( rp_add & restricted_ops[ i ].tag ) {
attr_merge_one( e, mi->mi_ad_restrictedOperation,
- &restricted_ops[ i ].op, NULL );
+ &restricted_ops[ i ].op,
+ &restricted_ops[ i ].op );
}
}
for ( i = 0; !BER_BVISNULL( &restricted_exops[ i ].op ); i++ ) {
if ( rp_add & restricted_exops[ i ].tag ) {
attr_merge_one( e, mi->mi_ad_restrictedOperation,
- &restricted_exops[ i ].op, NULL );
+ &restricted_exops[ i ].op,
+ &restricted_exops[ i ].op );
}
}
}
done:;
if ( rc == LDAP_SUCCESS ) {
attrs_free( save_attrs );
+ rc = SLAP_CB_CONTINUE;
} else {
Attribute *tmp = e->e_attrs;
srchdesc->spd_version,
srchdesc->spd_description );
- bv.bv_val = buf;
- bv.bv_len = strlen( buf );
+ ber_str2bv( buf, 0, 0, &bv );
attr_merge_normalize_one( e_database,
mi->mi_ad_monitoredInfo, &bv, NULL );