From: Pierangelo Masarati Date: Sat, 22 Dec 2001 14:24:13 +0000 (+0000) Subject: better handling of on-the-fly operational attrs by means of helpers X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~579 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=328d38713ae9b3a6b57160d36b9fa3a2dc992d8a;p=openldap better handling of on-the-fly operational attrs by means of helpers --- diff --git a/servers/slapd/Makefile.in b/servers/slapd/Makefile.in index 54ce1cbc28..985bff3209 100644 --- a/servers/slapd/Makefile.in +++ b/servers/slapd/Makefile.in @@ -19,7 +19,7 @@ SRCS = main.c daemon.c connection.c search.c filter.c add.c charray.c \ schemaparse.c ad.c at.c mr.c syntax.c oc.c saslauthz.c \ configinfo.c starttls.c index.c sets.c referral.c \ root_dse.c sasl.c module.c suffixalias.c mra.c mods.c \ - limits.c backglue.c \ + limits.c backglue.c operational.c \ $(@PLAT@_SRCS) OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \ @@ -32,7 +32,7 @@ OBJS = main.o daemon.o connection.o search.o filter.o add.o charray.o \ schemaparse.o ad.o at.o mr.o syntax.o oc.o saslauthz.o \ configinfo.o starttls.o index.o sets.o referral.o \ root_dse.o sasl.o module.o suffixalias.o mra.o mods.o \ - limits.o backglue.o \ + limits.o backglue.o operational.o \ $(@PLAT@_OBJS) LDAP_INCDIR= ../../include diff --git a/servers/slapd/back-ldbm/operational.c b/servers/slapd/back-ldbm/operational.c index 81fe0efb1e..b553a677d3 100644 --- a/servers/slapd/back-ldbm/operational.c +++ b/servers/slapd/back-ldbm/operational.c @@ -37,16 +37,10 @@ ldbm_back_operational( int hs; hs = has_children( be, e ); - - *aa = ch_malloc( sizeof( Attribute ) ); - (*aa)->a_desc = slap_schema.si_ad_hasSubordinates; - - (*aa)->a_vals = ch_malloc( 2 * sizeof( struct berval * ) ); - (*aa)->a_vals[0] = ber_bvstrdup( hs ? "TRUE" : "FALSE" ); - (*aa)->a_vals[1] = NULL; - - (*aa)->a_next = NULL; - aa = &(*aa)->a_next; + *aa = slap_operational_hasSubordinate( hs ); + if ( *aa != NULL ) { + aa = &(*aa)->a_next; + } } return 0; diff --git a/servers/slapd/back-monitor/operational.c b/servers/slapd/back-monitor/operational.c index 46366905df..62d750dfc9 100644 --- a/servers/slapd/back-monitor/operational.c +++ b/servers/slapd/back-monitor/operational.c @@ -42,16 +42,10 @@ monitor_back_operational( assert( mp ); hs = MONITOR_HAS_CHILDREN( mp ); - - *aa = ch_malloc( sizeof( Attribute ) ); - (*aa)->a_desc = slap_schema.si_ad_hasSubordinates; - - (*aa)->a_vals = ch_malloc( 2 * sizeof( struct berval * ) ); - (*aa)->a_vals[0] = ber_bvstrdup( hs ? "TRUE" : "FALSE" ); - (*aa)->a_vals[1] = NULL; - - (*aa)->a_next = NULL; - aa = &(*aa)->a_next; + *aa = slap_operational_hasSubordinate( hs ); + if ( *aa != NULL ) { + aa = &(*aa)->a_next; + } } return 0; diff --git a/servers/slapd/backend.c b/servers/slapd/backend.c index 8b1469ef38..0aff46c443 100644 --- a/servers/slapd/backend.c +++ b/servers/slapd/backend.c @@ -1094,16 +1094,8 @@ Attribute *backend_operational( Attribute *a = NULL, **ap = &a; #ifdef SLAPD_SCHEMA_DN - a = ch_malloc( sizeof( Attribute ) ); - a->a_desc = slap_schema.si_ad_subschemaSubentry; - - /* Should be backend specific */ - a->a_vals = ch_malloc( 2 * sizeof( struct berval * ) ); - a->a_vals[0] = ber_bvstrdup( SLAPD_SCHEMA_DN ); - a->a_vals[1] = NULL; - - a->a_next = NULL; - ap = &a->a_next; + *ap = slap_operational_subschemaSubentry(); + ap = &(*ap)->a_next; #endif /* @@ -1111,7 +1103,7 @@ Attribute *backend_operational( * and the backend supports specific operational attributes, * add them to the attribute list */ - if ( ( opattrs || attrs ) && be->be_operational != NULL ) { + if ( ( opattrs || attrs ) && be && be->be_operational != NULL ) { ( void )be->be_operational( be, conn, op, e, attrs, opattrs, ap ); } diff --git a/servers/slapd/operational.c b/servers/slapd/operational.c new file mode 100644 index 0000000000..989b11b155 --- /dev/null +++ b/servers/slapd/operational.c @@ -0,0 +1,51 @@ +/* operational.c - routines to deal with on-the-fly operational attrs */ +/* + * Copyright 2001 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include "slap.h" + +/* + * helpers for on-the-fly operational attribute generation + */ + +#ifdef SLAPD_SCHEMA_DN +Attribute * +slap_operational_subschemaSubentry( void ) +{ + Attribute *a; + + a = ch_malloc( sizeof( Attribute ) ); + a->a_desc = slap_schema.si_ad_subschemaSubentry; + + /* Should be backend specific */ + a->a_vals = ch_malloc( 2 * sizeof( struct berval * ) ); + a->a_vals[0] = ber_bvstrdup( SLAPD_SCHEMA_DN ); + a->a_vals[1] = NULL; + + a->a_next = NULL; + + return a; +} +#endif /* SLAPD_SCHEMA_DN */ + +Attribute * +slap_operational_hasSubordinate( int hs ) +{ + Attribute *a; + + a = ch_malloc( sizeof( Attribute ) ); + a->a_desc = slap_schema.si_ad_hasSubordinates; + + a->a_vals = ch_malloc( 2 * sizeof( struct berval * ) ); + a->a_vals[0] = ber_bvstrdup( hs ? "TRUE" : "FALSE" ); + a->a_vals[1] = NULL; + + a->a_next = NULL; + + return a; +} + diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index f25c69e769..915c40321f 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -886,6 +886,12 @@ LDAP_SLAPD_V (char) *ldap_srvtab; LDAP_SLAPD_V (int) krbv4_ldap_auth(); #endif +/* + * operational.c + */ +LDAP_SLAPD_F (Attribute *) slap_operational_subschemaSubentry( void ); +LDAP_SLAPD_F (Attribute *) slap_operational_hasSubordinate( int has ); + /* * Other... */ diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index 43e80bf8e5..ef6bad5d1f 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -220,3 +220,16 @@ int read_root_dse_file ( const char *file ) { return 0; } + +Attribute * +slap_operational_subschemaSubentry( void ) +{ + return NULL; +} + +Attribute * +slap_operational_hasSubordinate( int hs ) +{ + return NULL; +} +