1 /* distproc.c - implement distributed procedures */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2005-2015 The OpenLDAP Foundation.
6 * Portions Copyright 2003 Howard Chu.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
13 * A copy of this license is available in the file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
18 * This work was initially developed by Pierangelo Masarati for inclusion
19 * in OpenLDAP Software.
20 * Based on back-ldap and slapo-chain, developed by Howard Chu
27 #include <ac/string.h>
28 #include <ac/socket.h>
34 #include "back-ldap.h"
39 * From <draft-sermersheim-ldap-distproc>
42 ContinuationReference ::= SET {
43 referralURI [0] SET SIZE (1..MAX) OF URI,
44 localReference [2] LDAPDN,
45 referenceType [3] ReferenceType,
46 remainingName [4] RelativeLDAPDN OPTIONAL,
47 searchScope [5] SearchScope OPTIONAL,
48 searchedSubtrees [6] SearchedSubtrees OPTIONAL,
49 failedName [7] LDAPDN OPTIONAL,
52 ReferenceType ::= ENUMERATED {
56 nonSpecificSubordinate (3),
59 immediateSuperior (6),
63 SearchScope ::= ENUMERATED {
67 subordinateSubtree (3),
70 SearchedSubtrees ::= SET OF RelativeLDAPDN
72 LDAPDN, RelativeLDAPDN, and LDAPString, are defined in [RFC2251].
76 typedef enum ReferenceType_t {
77 LDAP_DP_RT_UNKNOWN = -1,
78 LDAP_DP_RT_SUPERIOR = 0,
79 LDAP_DP_RT_SUBORDINATE = 1,
81 LDAP_DP_RT_NONSPECIFICSUBORDINATE = 3,
82 LDAP_DP_RT_SUPPLIER = 4,
83 LDAP_DP_RT_MASTER = 5,
84 LDAP_DP_RT_IMMEDIATESUPERIOR = 6,
89 typedef enum SearchScope_t {
90 LDAP_DP_SS_UNKNOWN = -1,
91 LDAP_DP_SS_BASEOBJECT = 0,
92 LDAP_DP_SS_SINGLELEVEL = 1,
93 LDAP_DP_SS_WHOLESUBTREE = 2,
94 LDAP_DP_SS_SUBORDINATESUBTREE = 3,
98 typedef struct ContinuationReference_t {
99 BerVarray cr_referralURI;
101 struct berval cr_localReference;
102 ReferenceType_t cr_referenceType;
103 struct berval cr_remainingName;
104 SearchScope_t cr_searchScope;
105 BerVarray cr_searchedSubtrees;
106 struct berval cr_failedName;
107 } ContinuationReference_t;
108 #define CR_INIT { NULL, BER_BVNULL, LDAP_DP_RT_UNKNOWN, BER_BVNULL, LDAP_DP_SS_UNKNOWN, NULL, BER_BVNULL }
111 static struct berval bv2rt[] = {
112 BER_BVC( "superior" ),
113 BER_BVC( "subordinate" ),
115 BER_BVC( "nonSpecificSubordinate" ),
116 BER_BVC( "supplier" ),
118 BER_BVC( "immediateSuperior" ),
123 static struct berval bv2ss[] = {
124 BER_BVC( "baseObject" ),
125 BER_BVC( "singleLevel" ),
126 BER_BVC( "wholeSubtree" ),
127 BER_BVC( "subordinateSubtree" ),
131 static struct berval *
132 ldap_distproc_rt2bv( ReferenceType_t rt )
138 ldap_distproc_rt2str( ReferenceType_t rt )
140 return bv2rt[ rt ].bv_val;
143 static ReferenceType_t
144 ldap_distproc_bv2rt( struct berval *bv )
148 for ( rt = 0; !BER_BVISNULL( &bv2rt[ rt ] ); rt++ ) {
149 if ( ber_bvstrcasecmp( bv, &bv2rt[ rt ] ) == 0 ) {
154 return LDAP_DP_RT_UNKNOWN;
157 static ReferenceType_t
158 ldap_distproc_str2rt( const char *s )
162 ber_str2bv( s, 0, 0, &bv );
163 return ldap_distproc_bv2rt( &bv );
166 static struct berval *
167 ldap_distproc_ss2bv( SearchScope_t ss )
173 ldap_distproc_ss2str( SearchScope_t ss )
175 return bv2ss[ ss ].bv_val;
179 ldap_distproc_bv2ss( struct berval *bv )
183 for ( ss = 0; !BER_BVISNULL( &bv2ss[ ss ] ); ss++ ) {
184 if ( ber_bvstrcasecmp( bv, &bv2ss[ ss ] ) == 0 ) {
189 return LDAP_DP_SS_UNKNOWN;
193 ldap_distproc_str2ss( const char *s )
197 ber_str2bv( s, 0, 0, &bv );
198 return ldap_distproc_bv2ss( &bv );
203 * NOTE: this overlay assumes that the chainingBehavior control
204 * is registered by the chain overlay; it may move here some time.
205 * This overlay provides support for that control as well.
209 static int sc_returnContRef;
210 #define o_returnContRef o_ctrlflag[sc_returnContRef]
211 #define get_returnContRef(op) ((op)->o_returnContRef & SLAP_CONTROL_MASK)
213 static struct berval slap_EXOP_CHAINEDREQUEST = BER_BVC( LDAP_EXOP_X_CHAINEDREQUEST );
214 static struct berval slap_FEATURE_CANCHAINOPS = BER_BVC( LDAP_FEATURE_X_CANCHAINOPS );
216 static BackendInfo *lback;
218 typedef struct ldap_distproc_t {
219 /* "common" configuration info (anything occurring before an "uri") */
220 ldapinfo_t *lc_common_li;
222 /* current configuration info */
223 ldapinfo_t *lc_cfg_li;
225 /* tree of configured[/generated?] "uri" info */
226 ldap_avl_info_t lc_lai;
229 #define LDAP_DISTPROC_F_NONE (0x00U)
230 #define LDAP_DISTPROC_F_CHAINING (0x01U)
231 #define LDAP_DISTPROC_F_CACHE_URI (0x10U)
233 #define LDAP_DISTPROC_CHAINING( lc ) ( ( (lc)->lc_flags & LDAP_DISTPROC_F_CHAINING ) == LDAP_DISTPROC_F_CHAINING )
234 #define LDAP_DISTPROC_CACHE_URI( lc ) ( ( (lc)->lc_flags & LDAP_DISTPROC_F_CACHE_URI ) == LDAP_DISTPROC_F_CACHE_URI )
238 static int ldap_distproc_db_init_common( BackendDB *be );
239 static int ldap_distproc_db_init_one( BackendDB *be );
240 #define ldap_distproc_db_open_one(be) (lback)->bi_db_open( (be) )
241 #define ldap_distproc_db_close_one(be) (0)
242 #define ldap_distproc_db_destroy_one(be, ca) (lback)->bi_db_destroy( (be), (ca) )
245 ldap_distproc_uri_cmp( const void *c1, const void *c2 )
247 const ldapinfo_t *li1 = (const ldapinfo_t *)c1;
248 const ldapinfo_t *li2 = (const ldapinfo_t *)c2;
250 assert( li1->li_bvuri != NULL );
251 assert( !BER_BVISNULL( &li1->li_bvuri[ 0 ] ) );
252 assert( BER_BVISNULL( &li1->li_bvuri[ 1 ] ) );
254 assert( li2->li_bvuri != NULL );
255 assert( !BER_BVISNULL( &li2->li_bvuri[ 0 ] ) );
256 assert( BER_BVISNULL( &li2->li_bvuri[ 1 ] ) );
258 /* If local DNs don't match, it is definitely not a match */
259 return ber_bvcmp( &li1->li_bvuri[ 0 ], &li2->li_bvuri[ 0 ] );
263 ldap_distproc_uri_dup( void *c1, void *c2 )
265 ldapinfo_t *li1 = (ldapinfo_t *)c1;
266 ldapinfo_t *li2 = (ldapinfo_t *)c2;
268 assert( li1->li_bvuri != NULL );
269 assert( !BER_BVISNULL( &li1->li_bvuri[ 0 ] ) );
270 assert( BER_BVISNULL( &li1->li_bvuri[ 1 ] ) );
272 assert( li2->li_bvuri != NULL );
273 assert( !BER_BVISNULL( &li2->li_bvuri[ 0 ] ) );
274 assert( BER_BVISNULL( &li2->li_bvuri[ 1 ] ) );
276 /* Cannot have more than one shared session with same DN */
277 if ( ber_bvcmp( &li1->li_bvuri[ 0 ], &li2->li_bvuri[ 0 ] ) == 0 ) {
285 ldap_distproc_operational( Operation *op, SlapReply *rs )
287 /* Trap entries generated by back-ldap.
289 * FIXME: we need a better way to recognize them; a cleaner
290 * solution would be to be able to intercept the response
291 * of be_operational(), so that we can divert only those
292 * calls that fail because operational attributes were
293 * requested for entries that do not belong to the underlying
294 * database. This fix is likely to intercept also entries
295 * generated by back-perl and so. */
296 if ( rs->sr_entry->e_private == NULL ) {
300 return SLAP_CB_CONTINUE;
304 ldap_distproc_response( Operation *op, SlapReply *rs )
306 return SLAP_CB_CONTINUE;
314 /* NOTE: the chaining behavior control is registered
315 * by the chain overlay; it may move here some time */
322 static ConfigDriver distproc_cfgen;
323 static ConfigCfAdd distproc_cfadd;
324 static ConfigLDAPadd distproc_ldadd;
326 static ConfigTable distproc_cfg[] = {
327 { "distproc-chaining", "args",
328 2, 4, 0, ARG_MAGIC|ARG_BERVAL|DP_CHAINING, distproc_cfgen,
329 /* NOTE: using the same attributeTypes defined
330 * for the "chain" overlay */
331 "( OLcfgOvAt:3.1 NAME 'olcChainingBehavior' "
332 "DESC 'Chaining behavior control parameters (draft-sermersheim-ldap-chaining)' "
333 "SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
334 { "distproc-cache-uri", "TRUE/FALSE",
335 2, 2, 0, ARG_MAGIC|ARG_ON_OFF|DP_CACHE_URI, distproc_cfgen,
336 "( OLcfgOvAt:3.2 NAME 'olcChainCacheURI' "
337 "DESC 'Enables caching of URIs not present in configuration' "
339 "SINGLE-VALUE )", NULL, NULL },
340 { NULL, NULL, 0, 0, 0, ARG_IGNORED }
343 static ConfigOCs distproc_ocs[] = {
345 "NAME 'olcDistProcConfig' "
346 "DESC 'Distributed procedures <draft-sermersheim-ldap-distproc> configuration' "
347 "SUP olcOverlayConfig "
349 "olcChainingBehavior $ "
352 Cft_Overlay, distproc_cfg, NULL, distproc_cfadd },
354 "NAME 'olcDistProcDatabase' "
355 "DESC 'Distributed procedure remote server configuration' "
357 Cft_Misc, distproc_cfg, distproc_ldadd },
362 distproc_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca )
369 AttributeDescription *ad = NULL;
375 if ( p->ce_type != Cft_Overlay
377 || p->ce_bi->bi_cf_ocs != distproc_ocs )
379 return LDAP_CONSTRAINT_VIOLATION;
382 on = (slap_overinst *)p->ce_bi;
383 lc = (ldap_distproc_t *)on->on_bi.bi_private;
385 assert( ca->be == NULL );
386 ca->be = (BackendDB *)ch_calloc( 1, sizeof( BackendDB ) );
388 ca->be->bd_info = (BackendInfo *)on;
390 rc = slap_str2ad( "olcDbURI", &ad, &text );
391 assert( rc == LDAP_SUCCESS );
393 at = attr_find( e->e_attrs, ad );
394 if ( lc->lc_common_li == NULL && at != NULL ) {
395 /* FIXME: we should generate an empty default entry
396 * if none is supplied */
397 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
398 "first underlying database \"%s\" "
399 "cannot contain attribute \"%s\".\n",
400 e->e_name.bv_val, ad->ad_cname.bv_val, 0 );
401 rc = LDAP_CONSTRAINT_VIOLATION;
404 } else if ( lc->lc_common_li != NULL && at == NULL ) {
405 /* FIXME: we should generate an empty default entry
406 * if none is supplied */
407 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
408 "subsequent underlying database \"%s\" "
409 "must contain attribute \"%s\".\n",
410 e->e_name.bv_val, ad->ad_cname.bv_val, 0 );
411 rc = LDAP_CONSTRAINT_VIOLATION;
415 if ( lc->lc_common_li == NULL ) {
416 rc = ldap_distproc_db_init_common( ca->be );
419 rc = ldap_distproc_db_init_one( ca->be );
423 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
424 "unable to init %sunderlying database \"%s\".\n",
425 lc->lc_common_li == NULL ? "common " : "", e->e_name.bv_val, 0 );
426 rc = LDAP_CONSTRAINT_VIOLATION;
430 li = ca->be->be_private;
432 if ( lc->lc_common_li == NULL ) {
433 lc->lc_common_li = li;
435 } else if ( avl_insert( &lc->lc_lai.lai_tree, (caddr_t)li,
436 ldap_distproc_uri_cmp, ldap_distproc_uri_dup ) )
438 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
439 "database \"%s\" insert failed.\n",
440 e->e_name.bv_val, 0, 0 );
441 rc = LDAP_CONSTRAINT_VIOLATION;
446 if ( rc != LDAP_SUCCESS ) {
447 (void)ldap_distproc_db_destroy_one( ca->be, NULL );
455 typedef struct ldap_distproc_cfadd_apply_t {
461 } ldap_distproc_cfadd_apply_t;
464 ldap_distproc_cfadd_apply( void *datum, void *arg )
466 ldapinfo_t *li = (ldapinfo_t *)datum;
467 ldap_distproc_cfadd_apply_t *lca = (ldap_distproc_cfadd_apply_t *)arg;
471 /* FIXME: should not hardcode "olcDatabase" here */
472 bv.bv_len = snprintf( lca->ca->cr_msg, sizeof( lca->ca->cr_msg ),
473 "olcDatabase={%d}%s", lca->count, lback->bi_type );
474 bv.bv_val = lca->ca->cr_msg;
476 lca->ca->be->be_private = (void *)li;
477 config_build_entry( lca->op, lca->rs, lca->p->e_private, lca->ca,
478 &bv, lback->bi_cf_ocs, &distproc_ocs[ 1 ] );
486 distproc_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *ca )
488 CfEntryInfo *pe = p->e_private;
489 slap_overinst *on = (slap_overinst *)pe->ce_bi;
490 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
491 void *priv = (void *)ca->be->be_private;
493 if ( lback->bi_cf_ocs ) {
494 ldap_distproc_cfadd_apply_t lca = { 0 };
502 (void)ldap_distproc_cfadd_apply( (void *)lc->lc_common_li, (void *)&lca );
504 (void)avl_apply( lc->lc_lai.lai_tree, ldap_distproc_cfadd_apply,
505 &lca, 1, AVL_INORDER );
507 ca->be->be_private = priv;
514 distproc_cfgen( ConfigArgs *c )
516 slap_overinst *on = (slap_overinst *)c->bi;
517 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
521 if ( c->op == SLAP_CONFIG_EMIT ) {
524 c->value_int = LDAP_DISTPROC_CACHE_URI( lc );
533 } else if ( c->op == LDAP_MOD_DELETE ) {
539 lc->lc_flags &= ~LDAP_DISTPROC_F_CACHE_URI;
550 if ( c->value_int ) {
551 lc->lc_flags |= LDAP_DISTPROC_F_CACHE_URI;
553 lc->lc_flags &= ~LDAP_DISTPROC_F_CACHE_URI;
566 ldap_distproc_db_init(
570 slap_overinst *on = (slap_overinst *)be->bd_info;
571 ldap_distproc_t *lc = NULL;
573 if ( lback == NULL ) {
574 lback = backend_info( "ldap" );
576 if ( lback == NULL ) {
581 lc = ch_malloc( sizeof( ldap_distproc_t ) );
585 memset( lc, 0, sizeof( ldap_distproc_t ) );
586 ldap_pvt_thread_mutex_init( &lc->lc_lai.lai_mutex );
588 on->on_bi.bi_private = (void *)lc;
594 ldap_distproc_db_config(
601 slap_overinst *on = (slap_overinst *)be->bd_info;
602 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
604 int rc = SLAP_CONF_UNKNOWN;
606 if ( lc->lc_common_li == NULL ) {
607 void *be_private = be->be_private;
608 ldap_distproc_db_init_common( be );
609 lc->lc_common_li = lc->lc_cfg_li = (ldapinfo_t *)be->be_private;
610 be->be_private = be_private;
613 /* Something for the distproc database? */
614 if ( strncasecmp( argv[ 0 ], "distproc-", STRLENOF( "distproc-" ) ) == 0 ) {
615 char *save_argv0 = argv[ 0 ];
616 BackendInfo *bd_info = be->bd_info;
617 void *be_private = be->be_private;
618 ConfigOCs *be_cf_ocs = be->be_cf_ocs;
621 argv[ 0 ] += STRLENOF( "distproc-" );
623 if ( strcasecmp( argv[ 0 ], "uri" ) == 0 ) {
624 rc = ldap_distproc_db_init_one( be );
626 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
627 "underlying slapd-ldap initialization failed.\n.",
631 lc->lc_cfg_li = be->be_private;
635 /* TODO: add checks on what other slapd-ldap(5) args
636 * should be put in the template; this is not quite
637 * harmful, because attributes that shouldn't don't
638 * get actually used, but the user should at least
643 be->be_private = (void *)lc->lc_cfg_li;
644 be->be_cf_ocs = lback->bi_cf_ocs;
646 rc = config_generic_wrapper( be, fname, lineno, argc, argv );
648 argv[ 0 ] = save_argv0;
649 be->be_cf_ocs = be_cf_ocs;
650 be->be_private = be_private;
651 be->bd_info = bd_info;
659 db.be_private = (void *)lc->lc_cfg_li;
660 ldap_distproc_db_destroy_one( &db, NULL );
661 lc->lc_cfg_li = NULL;
664 if ( lc->lc_cfg_li->li_bvuri == NULL
665 || BER_BVISNULL( &lc->lc_cfg_li->li_bvuri[ 0 ] )
666 || !BER_BVISNULL( &lc->lc_cfg_li->li_bvuri[ 1 ] ) )
668 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
669 "no URI list allowed in slapo-distproc.\n",
672 goto private_destroy;
675 if ( avl_insert( &lc->lc_lai.lai_tree,
676 (caddr_t)lc->lc_cfg_li,
677 ldap_distproc_uri_cmp, ldap_distproc_uri_dup ) )
679 Debug( LDAP_DEBUG_ANY, "%s: line %d: "
680 "duplicate URI in slapo-distproc.\n",
683 goto private_destroy;
700 typedef struct ldap_distproc_db_apply_t {
703 } ldap_distproc_db_apply_t;
706 ldap_distproc_db_apply( void *datum, void *arg )
708 ldapinfo_t *li = (ldapinfo_t *)datum;
709 ldap_distproc_db_apply_t *lca = (ldap_distproc_db_apply_t *)arg;
711 lca->be->be_private = (void *)li;
713 return lca->func( lca->be, NULL );
717 ldap_distproc_db_func(
722 slap_overinst *on = (slap_overinst *)be->bd_info;
723 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
728 BI_db_func *func = (&lback->bi_db_open)[ which ];
730 if ( func != NULL && lc->lc_common_li != NULL ) {
734 db.be_private = lc->lc_common_li;
736 rc = func( &db, NULL );
742 if ( lc->lc_lai.lai_tree != NULL ) {
743 ldap_distproc_db_apply_t lca;
748 rc = avl_apply( lc->lc_lai.lai_tree,
749 ldap_distproc_db_apply, (void *)&lca,
750 1, AVL_INORDER ) != AVL_NOMORE;
759 ldap_distproc_db_open(
763 return ldap_distproc_db_func( be, db_open );
767 ldap_distproc_db_close(
771 return ldap_distproc_db_func( be, db_close );
775 ldap_distproc_db_destroy(
779 slap_overinst *on = (slap_overinst *) be->bd_info;
780 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
784 rc = ldap_distproc_db_func( be, db_destroy );
787 avl_free( lc->lc_lai.lai_tree, NULL );
788 ldap_pvt_thread_mutex_destroy( &lc->lc_lai.lai_mutex );
796 * inits one instance of the slapd-ldap backend, and stores
797 * the private info in be_private of the arg
800 ldap_distproc_db_init_common(
803 BackendInfo *bi = be->bd_info;
807 be->be_private = NULL;
808 t = lback->bi_db_init( be, NULL );
818 * inits one instance of the slapd-ldap backend, stores
819 * the private info in be_private of the arg and fills
820 * selected fields with data from the template.
822 * NOTE: add checks about the other fields of the template,
823 * which are ignored and SHOULD NOT be configured by the user.
826 ldap_distproc_db_init_one(
829 slap_overinst *on = (slap_overinst *)be->bd_info;
830 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
832 BackendInfo *bi = be->bd_info;
838 be->be_private = NULL;
839 t = lback->bi_db_init( be, NULL );
843 li = (ldapinfo_t *)be->be_private;
845 /* copy common data */
846 li->li_nretries = lc->lc_common_li->li_nretries;
847 li->li_flags = lc->lc_common_li->li_flags;
848 li->li_version = lc->lc_common_li->li_version;
849 for ( t = 0; t < SLAP_OP_LAST; t++ ) {
850 li->li_timeout[ t ] = lc->lc_common_li->li_timeout[ t ];
857 typedef struct ldap_distproc_conn_apply_t {
860 } ldap_distproc_conn_apply_t;
863 ldap_distproc_conn_apply( void *datum, void *arg )
865 ldapinfo_t *li = (ldapinfo_t *)datum;
866 ldap_distproc_conn_apply_t *lca = (ldap_distproc_conn_apply_t *)arg;
868 lca->be->be_private = (void *)li;
870 return lback->bi_connection_destroy( lca->be, lca->conn );
874 ldap_distproc_connection_destroy(
879 slap_overinst *on = (slap_overinst *) be->bd_info;
880 ldap_distproc_t *lc = (ldap_distproc_t *)on->on_bi.bi_private;
881 void *private = be->be_private;
882 ldap_distproc_conn_apply_t lca;
885 be->be_private = NULL;
888 ldap_pvt_thread_mutex_lock( &lc->lc_lai.lai_mutex );
889 rc = avl_apply( lc->lc_lai.lai_tree, ldap_distproc_conn_apply,
890 (void *)&lca, 1, AVL_INORDER ) != AVL_NOMORE;
891 ldap_pvt_thread_mutex_unlock( &lc->lc_lai.lai_mutex );
892 be->be_private = private;
898 ldap_distproc_parse_returnContRef_ctrl(
903 if ( get_returnContRef( op ) != SLAP_CONTROL_NONE ) {
904 rs->sr_text = "returnContinuationReference control specified multiple times";
905 return LDAP_PROTOCOL_ERROR;
908 if ( op->o_pagedresults != SLAP_CONTROL_NONE ) {
909 rs->sr_text = "returnContinuationReference control specified with pagedResults control";
910 return LDAP_PROTOCOL_ERROR;
913 if ( !BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
914 rs->sr_text = "returnContinuationReference control: value must be NULL";
915 return LDAP_PROTOCOL_ERROR;
918 op->o_returnContRef = ctrl->ldctl_iscritical ? SLAP_CONTROL_CRITICAL : SLAP_CONTROL_NONCRITICAL;
924 ldap_exop_chained_request(
928 Statslog( LDAP_DEBUG_STATS, "%s CHAINED REQUEST\n",
929 op->o_log_prefix, 0, 0, 0, 0 );
931 rs->sr_err = backend_check_restrictions( op, rs,
932 (struct berval *)&slap_EXOP_CHAINEDREQUEST );
933 if ( rs->sr_err != LDAP_SUCCESS ) {
937 /* by now, just reject requests */
938 rs->sr_text = "under development";
939 return LDAP_UNWILLING_TO_PERFORM;
943 static slap_overinst distproc;
946 distproc_initialize( void )
950 /* Make sure we don't exceed the bits reserved for userland */
951 config_check_userland( DP_LAST );
953 rc = load_extop( (struct berval *)&slap_EXOP_CHAINEDREQUEST,
954 SLAP_EXOP_HIDE, ldap_exop_chained_request );
955 if ( rc != LDAP_SUCCESS ) {
956 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
957 "unable to register chainedRequest exop: %d.\n",
962 rc = supported_feature_load( &slap_FEATURE_CANCHAINOPS );
963 if ( rc != LDAP_SUCCESS ) {
964 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
965 "unable to register canChainOperations supported feature: %d.\n",
970 rc = register_supported_control( LDAP_CONTROL_X_RETURNCONTREF,
971 SLAP_CTRL_GLOBAL|SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE, NULL,
972 ldap_distproc_parse_returnContRef_ctrl, &sc_returnContRef );
973 if ( rc != LDAP_SUCCESS ) {
974 Debug( LDAP_DEBUG_ANY, "slapd-distproc: "
975 "unable to register returnContinuationReference control: %d.\n",
980 distproc.on_bi.bi_type = "distproc";
981 distproc.on_bi.bi_db_init = ldap_distproc_db_init;
982 distproc.on_bi.bi_db_config = ldap_distproc_db_config;
983 distproc.on_bi.bi_db_open = ldap_distproc_db_open;
984 distproc.on_bi.bi_db_close = ldap_distproc_db_close;
985 distproc.on_bi.bi_db_destroy = ldap_distproc_db_destroy;
987 /* ... otherwise the underlying backend's function would be called,
988 * likely passing an invalid entry; on the contrary, the requested
989 * operational attributes should have been returned while chasing
990 * the referrals. This all in all is a bit messy, because part
991 * of the operational attributes are generated by the backend;
992 * part by the frontend; back-ldap should receive all the available
993 * ones from the remote server, but then, on its own, it strips those
994 * it assumes will be (re)generated by the frontend (e.g.
995 * subschemaSubentry, entryDN, ...) */
996 distproc.on_bi.bi_operational = ldap_distproc_operational;
998 distproc.on_bi.bi_connection_destroy = ldap_distproc_connection_destroy;
1000 distproc.on_response = ldap_distproc_response;
1002 distproc.on_bi.bi_cf_ocs = distproc_ocs;
1004 rc = config_register_schema( distproc_cfg, distproc_ocs );
1009 return overlay_register( &distproc );
1012 #endif /* SLAP_DISTPROC */