From 45cda82eb1aed0aee6af81cd00dc46136d6199a4 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 6 Jan 2006 17:08:54 +0000 Subject: [PATCH] allow load_extop to replace an existing handler (not by default, though) --- servers/slapd/extended.c | 41 ++++++++++++++++++++++++-------------- servers/slapd/module.c | 2 ++ servers/slapd/proto-slap.h | 7 +++++-- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/servers/slapd/extended.c b/servers/slapd/extended.c index e77ac961e7..9d6aeb9505 100644 --- a/servers/slapd/extended.c +++ b/servers/slapd/extended.c @@ -249,13 +249,15 @@ done:; } int -load_extop( +load_extop2( const struct berval *ext_oid, slap_mask_t ext_flags, - SLAP_EXTOP_MAIN_FN *ext_main ) + SLAP_EXTOP_MAIN_FN *ext_main, + unsigned flags ) { struct berval oidm = BER_BVNULL; struct extop_list *ext; + int insertme = 0; if ( !ext_main ) { return -1; @@ -276,25 +278,34 @@ load_extop( for ( ext = supp_ext_list; ext; ext = ext->next ) { if ( bvmatch( ext_oid, &ext->oid ) ) { + if ( flags == 1 ) { + break; + } return -1; } } - ext = ch_calloc(1, sizeof(struct extop_list) + ext_oid->bv_len + 1); - if (ext == NULL) - return(-1); + if ( flags == 0 || ext == NULL ) { + ext = ch_calloc( 1, sizeof(struct extop_list) + ext_oid->bv_len + 1 ); + if ( ext == NULL ) { + return(-1); + } - ext->flags = ext_flags; + ext->oid.bv_val = (char *)(ext + 1); + AC_MEMCPY( ext->oid.bv_val, ext_oid->bv_val, ext_oid->bv_len ); + ext->oid.bv_len = ext_oid->bv_len; + ext->oid.bv_val[ext->oid.bv_len] = '\0'; - ext->oid.bv_val = (char *)(ext + 1); - AC_MEMCPY( ext->oid.bv_val, ext_oid->bv_val, ext_oid->bv_len ); - ext->oid.bv_len = ext_oid->bv_len; - ext->oid.bv_val[ext->oid.bv_len] = '\0'; + insertme = 1; + } + ext->flags = ext_flags; ext->ext_main = ext_main; - ext->next = supp_ext_list; - supp_ext_list = ext; + if ( insertme ) { + ext->next = supp_ext_list; + supp_ext_list = ext; + } return(0); } @@ -304,10 +315,10 @@ extops_init (void) { int i; - for (i = 0; builtin_extops[i].oid != NULL; i++) { - load_extop((struct berval *)builtin_extops[i].oid, + for ( i = 0; builtin_extops[i].oid != NULL; i++ ) { + load_extop( (struct berval *)builtin_extops[i].oid, builtin_extops[i].flags, - builtin_extops[i].ext_main); + builtin_extops[i].ext_main ); } return(0); } diff --git a/servers/slapd/module.c b/servers/slapd/module.c index c579004e63..b9e3ff5a6c 100644 --- a/servers/slapd/module.c +++ b/servers/slapd/module.c @@ -298,6 +298,8 @@ load_extop_module ( return(-1); } + /* FIXME: this is broken, and no longer needed, + * as a module can call load_extop() itself... */ rc = load_extop( &oid, ext_main ); return rc; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 2fe63f50f3..18c5000e44 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -875,10 +875,13 @@ typedef int (SLAP_EXTOP_MAIN_FN) LDAP_P(( Operation *op, SlapReply *rs )); typedef int (SLAP_EXTOP_GETOID_FN) LDAP_P(( int index, struct berval *oid, int blen )); -LDAP_SLAPD_F (int) load_extop LDAP_P(( +LDAP_SLAPD_F (int) load_extop2 LDAP_P(( const struct berval *ext_oid, slap_mask_t flags, - SLAP_EXTOP_MAIN_FN *ext_main )); + SLAP_EXTOP_MAIN_FN *ext_main, + unsigned tmpflags )); +#define load_extop(ext_oid, flags, ext_main) \ + load_extop2((ext_oid), (flags), (ext_main), 0) LDAP_SLAPD_F (int) extops_init LDAP_P(( void )); -- 2.39.5