From 053672c6c0b4a2ceb45f90b177c7d06e7b66e40d Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Tue, 21 Jan 2003 13:48:37 +0000 Subject: [PATCH] Added Slapi_AttrSet accessors in order to implement virtual operational attribute plugin --- servers/slapd/slapi/plugin.c | 5 +- servers/slapd/slapi/slapi.h | 15 ++- servers/slapd/slapi/slapi_utils.c | 216 +++++++++++++++++++++++++++++- servers/slapd/slapi/slapi_utils.h | 12 ++ 4 files changed, 245 insertions(+), 3 deletions(-) diff --git a/servers/slapd/slapi/plugin.c b/servers/slapd/slapi/plugin.c index ec0b7477a3..6bbd607729 100644 --- a/servers/slapd/slapi/plugin.c +++ b/servers/slapd/slapi/plugin.c @@ -619,6 +619,8 @@ netscape_plugin( iType = SLAPI_PLUGIN_POSTOPERATION; } else if ( strcasecmp( argv[1], "extendedop" ) == 0 ) { iType = SLAPI_PLUGIN_EXTENDEDOP; + } else if ( strcasecmp( argv[1], "opattrsp" ) == 0 ) { + iType = SLAPI_PLUGIN_OPATTR_SP; } else { fprintf( stderr, "%s: line %d: invalid plugin type \"%s\".\n", fname, lineno, argv[1] ); @@ -634,7 +636,8 @@ netscape_plugin( if ( iType == SLAPI_PLUGIN_PREOPERATION || iType == SLAPI_PLUGIN_EXTENDEDOP || - iType == SLAPI_PLUGIN_POSTOPERATION ) { + iType == SLAPI_PLUGIN_POSTOPERATION || + iType == SLAPI_PLUGIN_OPATTR_SP ) { int rc; Slapi_PBlock *pPlugin; diff --git a/servers/slapd/slapi/slapi.h b/servers/slapd/slapi/slapi.h index c1dfd99f3d..50d258229e 100644 --- a/servers/slapd/slapi/slapi.h +++ b/servers/slapd/slapi/slapi.h @@ -20,8 +20,9 @@ LDAP_BEGIN_DECL typedef struct slapi_pblock Slapi_PBlock; typedef struct slap_entry Slapi_Entry; typedef struct slap_attr Slapi_Attr; +typedef struct slap_attr * Slapi_AttrSet; +typedef struct berval Slapi_Value; typedef BerVarray Slapi_ValueSet; -typedef struct berval Slapi_Value; typedef Filter Slapi_Filter; LDAP_END_DECL @@ -74,6 +75,15 @@ LDAP_BEGIN_DECL #define SLAPI_PLUGIN_PWD_STORAGE_SCHEME 14 #define SLAPI_PLUGIN_VATTR_SP 15 #define SLAPI_PLUGIN_REVER_PWD_STORAGE_SCHEME 16 +/* + * Because the Sun ONE DS virtual attribute service + * is quite complicated, we've added a "lightweight" + * virtual attribute service. Virtual attribute + * plugins are called for each search result; + * they should examine the list of attributes + * requested to minimise the performance impact. + */ +#define SLAPI_PLUGIN_OPATTR_SP 17 #define SLAPI_PLUGIN_EXTENDED_SENT_RESULT -1 #define SLAPI_PLUGIN_EXTENDED_NOT_HANDLED -2 @@ -227,6 +237,9 @@ LDAP_BEGIN_DECL #define SLAPI_RESULT_TEXT 882 #define SLAPI_RESULT_MATCHED 883 +/* Virtual attribute service */ +#define SLAPI_PLUGIN_OPATTR_COALESCE_FN 900 + #define SLAPI_PLUGIN_SYNTAX_FLAG_ORKEYS 1 #define SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING 2 diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index 804602a2cc..2af2e49f1d 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -9,6 +9,13 @@ * given to IBM Corporation. This software is provided ``as is'' * without express or implied warranty. */ +/* + * Portions (C) Copyright PADL Software Pty Ltd. + * Redistribution and use in source and binary forms are permitted + * provided that this notice is preserved and that due credit is + * given to PADL Software Pty Ltd. This software is provided ``as is'' + * without express or implied warranty. + */ #include "portable.h" #include "slapi_common.h" @@ -1246,6 +1253,8 @@ int slapi_x_connection_set_pb( Slapi_PBlock *pb, Connection *conn ) if ( rc != LDAP_SUCCESS ) return rc; } + + return rc; #else return -1; #endif /* defined(LDAP_SLAPI) */ @@ -1934,7 +1943,11 @@ void slapi_valueset_free(Slapi_ValueSet *vs) { #ifdef LDAP_SLAPI if ( vs != NULL ) { - ber_bvarray_free( *vs ); + BerVarray vp = *vs; + + ber_bvarray_free( vp ); + slapi_ch_free( (void **)&vp ); + *vs = NULL; } #endif @@ -2037,3 +2050,204 @@ void slapi_valueset_set_valueset(Slapi_ValueSet *vs1, const Slapi_ValueSet *vs2) #endif } +/* + * Attribute sets are an OpenLDAP extension for the + * virtual operational attribute coalescing plugin + */ +Slapi_AttrSet *slapi_x_attrset_new( void ) +{ +#ifdef LDAP_SLAPI + Slapi_AttrSet *a; + + /* + * Like a Slapi_ValueSet, a Slapi_AttrSet is a container + * for objects: we need this because it may be initially + * empty. + */ + a = (Slapi_AttrSet *)slapi_ch_malloc( sizeof( *a ) ); + *a = NULL; + + return a; +#else + return NULL; +#endif +} + +Slapi_AttrSet *slapi_x_attrset_init( Slapi_AttrSet *as, Slapi_Attr *a ) +{ +#ifdef LDAP_SLAPI + *as = a; + a->a_next = NULL; + + return as; +#else + return NULL; +#endif +} + +void slapi_x_attrset_free( Slapi_AttrSet **pAs ) +{ +#ifdef LDAP_SLAPI + Slapi_AttrSet *as = *pAs; + + if ( as != NULL ) { + attrs_free( *as ); + slapi_ch_free( (void **)&as ); + *pAs = NULL; + } +#endif +} + +Slapi_AttrSet *slapi_x_attrset_dup( Slapi_AttrSet *as ) +{ +#ifdef LDAP_SLAPI + Slapi_AttrSet *newAs = slapi_x_attrset_new(); + + if ( *as != NULL ) + *newAs = attrs_dup( *as ); + + return newAs; +#else + return NULL; +#endif +} + +int slapi_x_attrset_add_attr( Slapi_AttrSet *as, Slapi_Attr *a ) +{ +#ifdef LDAP_SLAPI + Slapi_Attr *nextAttr; + + if ( as == NULL || a == NULL ) + return -1; + + if ( *as == NULL ) { + /* First attribute */ + nextAttr = NULL; + (*as) = a; + } else { + /* Non-first attribute */ + nextAttr = (*as)->a_next; + (*as)->a_next = a; + } + + a->a_next = nextAttr; + + return 0; +#else + return -1; +#endif +} + +int slapi_x_attrset_add_attr_copy( Slapi_AttrSet *as, Slapi_Attr *a ) +{ +#ifdef LDAP_SLAPI + Slapi_Attr *adup; + + adup = slapi_attr_dup( a ); + return slapi_x_attrset_add_attr( as, adup ); +#else + return -1; +#endif +} + +int slapi_x_attrset_find( Slapi_AttrSet *as, const char *type, Slapi_Attr **attr ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad; + const char *text; + + if ( as == NULL || *as == NULL ) { + return -1; + } + + if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) { + return -1; + } + *attr = attrs_find( *as, ad ); + return ( *attr == NULL ) ? -1 : 0; +#else + return -1; +#endif +} + +int slapi_x_attrset_merge( Slapi_AttrSet *as, const char *type, Slapi_ValueSet *vals ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad; + Slapi_AttrSet *a; + const char *text; + + if ( vals == NULL || *vals == NULL ) { + /* Must have something to add. */ + return -1; + } + + if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) { + return -1; + } + + for ( a = as; *a != NULL; a = &(*a)->a_next ) { + if ( ad_cmp( (*a)->a_desc, ad ) == 0 ) { + break; + } + } + + if ( *a == NULL ) { + *a = (Slapi_Attr *) slapi_ch_malloc( sizeof(Attribute) ); + (*a)->a_desc = ad; + (*a)->a_vals = NULL; + (*a)->a_next = NULL; + (*a)->a_flags = 0; + } + + return value_add ( &(*a)->a_vals, *vals ); +#else + return -1; +#endif +} + +int slapi_x_attrset_merge_bervals( Slapi_AttrSet *as, const char *type, struct berval **vals ) +{ +#ifdef LDAP_SLAPI + BerVarray vp; + int rc; + + if ( bvptr2obj( vals, &vp ) != LDAP_SUCCESS ) { + return -1; + } + rc = slapi_x_attrset_merge( as, type, &vp ); + slapi_ch_free( (void **)&vp ); + + return rc; +#else + return -1; +#endif +} + +int slapi_x_attrset_delete( Slapi_AttrSet *as, const char *type ) +{ +#ifdef LDAP_SLAPI + AttributeDescription *ad; + const char *text; + + if ( as == NULL ) { + return -1; + } + + if ( *as == NULL ) { + return -1; + } + + if ( slap_str2ad( type, &ad, &text ) != LDAP_SUCCESS ) { + return -1; + } + + if ( attr_delete( as, ad ) != LDAP_SUCCESS ) { + return -1; + } + + return 0; +#else + return -1; +#endif +} diff --git a/servers/slapd/slapi/slapi_utils.h b/servers/slapd/slapi/slapi_utils.h index b5ae767da8..ee7be4b62d 100644 --- a/servers/slapd/slapi/slapi_utils.h +++ b/servers/slapd/slapi/slapi_utils.h @@ -55,6 +55,18 @@ Slapi_Entry *slapi_entry_alloc(); void slapi_entry_free( Slapi_Entry *e ); int slapi_attr_get_values( Slapi_Attr *attr, struct berval ***vals ); +/* OpenLDAP AttrSet extensions for virtual attribute service */ +Slapi_AttrSet *slapi_x_attrset_new( void ); +Slapi_AttrSet *slapi_x_attrset_init( Slapi_AttrSet *as, Slapi_Attr *a ); +void slapi_x_attrset_free( Slapi_AttrSet **as ); +Slapi_AttrSet *slapi_x_attrset_dup( Slapi_AttrSet *as ); +int slapi_x_attrset_add_attr( Slapi_AttrSet *as, Slapi_Attr *a ); +int slapi_x_attrset_add_attr_copy( Slapi_AttrSet *as, Slapi_Attr *a ); +int slapi_x_attrset_find( Slapi_AttrSet *as, const char *type, Slapi_Attr **attr ); +int slapi_x_attrset_merge( Slapi_AttrSet *as, const char *type, Slapi_ValueSet *vals ); +int slapi_x_attrset_merge_bervals( Slapi_AttrSet *as, const char *type, struct berval **vals ); +int slapi_x_attrset_delete( Slapi_AttrSet *as, const char *type ); + /* DS 5.x SLAPI */ Slapi_Attr *slapi_attr_new( void ); Slapi_Attr *slapi_attr_init( Slapi_Attr *a, const char *type ); -- 2.39.5