2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1999-2006 The OpenLDAP Foundation.
5 * Portions Copyright 2001-2003 Pierangelo Masarati.
6 * Portions Copyright 1999-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 the Howard Chu for inclusion
19 * in OpenLDAP Software and subsequently enhanced by Pierangelo
28 #include <ac/socket.h>
29 #include <ac/string.h>
34 #include "../back-ldap/back-ldap.h"
35 #include "back-meta.h"
37 static LDAP_REBIND_PROC meta_back_default_rebind;
40 * a module could register a replacement for this function
42 LDAP_REBIND_PROC *meta_back_rebind_f = meta_back_default_rebind;
45 meta_back_bind( Operation *op, SlapReply *rs )
47 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
48 metaconn_t *mc = NULL;
55 SlapReply *candidates = meta_back_candidates_get( op );
57 rs->sr_err = LDAP_SUCCESS;
59 Debug( LDAP_DEBUG_ARGS, "%s meta_back_bind: dn=\"%s\".\n",
60 op->o_log_prefix, op->o_req_dn.bv_val, 0 );
62 /* the test on the bind method should be superfluous */
63 if ( op->orb_method == LDAP_AUTH_SIMPLE
64 && be_isroot_dn( op->o_bd, &op->o_req_ndn ) )
66 if ( !be_isroot_pw( op ) ) {
67 rs->sr_err = LDAP_INVALID_CREDENTIALS;
69 send_ldap_result( op, rs );
73 if ( META_BACK_DEFER_ROOTDN_BIND( mi ) ) {
74 rs->sr_err = LDAP_SUCCESS;
76 /* frontend will return success */
83 /* we need meta_back_getconn() not send result even on error,
84 * because we want to intercept the error and make it
85 * invalidCredentials */
86 mc = meta_back_getconn( op, rs, NULL, LDAP_BACK_BIND_DONTSEND );
88 char buf[ SLAP_TEXT_BUFLEN ];
90 snprintf( buf, sizeof( buf ),
91 "meta_back_bind: no target "
92 "for dn \"%s\" (%d%s%s).",
93 op->o_req_dn.bv_val, rs->sr_err,
94 rs->sr_text ? ". " : "",
95 rs->sr_text ? rs->sr_text : "" );
96 Debug( LDAP_DEBUG_ANY,
98 op->o_log_prefix, buf, 0 );
100 /* FIXME: there might be cases where we don't want
101 * to map the error onto invalidCredentials */
102 switch ( rs->sr_err ) {
103 case LDAP_NO_SUCH_OBJECT:
104 case LDAP_UNWILLING_TO_PERFORM:
105 rs->sr_err = LDAP_INVALID_CREDENTIALS;
109 send_ldap_result( op, rs );
114 * Each target is scanned ...
116 mc->mc_authz_target = META_BOUND_NONE;
117 for ( i = 0; i < mi->mi_ntargets; i++ ) {
123 * Skip non-candidates
125 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
130 /* set rc to LDAP_SUCCESS only if at least
131 * one candidate has been tried */
135 } else if ( isroot == 0 ) {
137 * A bind operation is expected to have
138 * ONE CANDIDATE ONLY!
140 Debug( LDAP_DEBUG_ANY,
141 "### %s meta_back_bind: more than one"
142 " candidate selected...\n",
143 op->o_log_prefix, 0, 0 );
147 if ( BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
149 metasingleconn_t *msc = &mc->mc_conns[ i ];
151 /* skip the target if no pseudorootdn is provided */
152 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
153 ch_free( msc->msc_bound_ndn.bv_val );
154 BER_BVZERO( &msc->msc_bound_ndn );
157 if ( LDAP_BACK_SAVECRED( mi ) &&
158 !BER_BVISNULL( &msc->msc_cred ) )
160 /* destroy sensitive data */
161 memset( msc->msc_cred.bv_val, 0,
162 msc->msc_cred.bv_len );
163 ch_free( msc->msc_cred.bv_val );
164 BER_BVZERO( &msc->msc_cred );
170 op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
171 op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
172 op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
173 op2.orb_method = LDAP_AUTH_SIMPLE;
178 lerr = meta_back_single_bind( &op2, rs, mc, i, massage );
180 if ( lerr != LDAP_SUCCESS ) {
181 rc = rs->sr_err = lerr;
182 candidates[ i ].sr_tag = META_NOT_CANDIDATE;
187 /* must re-insert if local DN changed as result of bind */
188 if ( rc == LDAP_SUCCESS ) {
190 mc->mc_authz_target = META_BOUND_ALL;
191 ber_dupbv( &op->orb_edn, be_root_dn( op->o_bd ) );
194 if ( !dn_match( &op->o_req_ndn, &mc->mc_local_ndn ) ) {
197 /* wait for all other ops to release the connection */
199 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
200 if ( mc->mc_refcnt > 1 ) {
201 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
202 ldap_pvt_thread_yield();
206 assert( mc->mc_refcnt == 1 );
207 mc = avl_delete( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
208 meta_back_dnconn_cmp );
209 assert( mc != NULL );
211 ber_bvreplace( &mc->mc_local_ndn, &op->o_req_ndn );
212 lerr = avl_insert( &mi->mi_conninfo.lai_tree, (caddr_t)mc,
213 meta_back_dnconn_cmp, meta_back_dnconn_dup );
214 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
216 for ( i = 0; i < mi->mi_ntargets; ++i ) {
217 if ( mc->mc_conns[ i ].msc_ld != NULL ) {
218 meta_clear_one_candidate( &mc->mc_conns[ i ] );
222 /* we can do this because mc_refcnt == 1 */
224 meta_back_conn_free( mc );
231 meta_back_release_conn( op, mc );
235 * rc is LDAP_SUCCESS if at least one bind succeeded,
236 * err is the last error that occurred during a bind;
237 * if at least (and at most?) one bind succeeds, fine.
239 if ( rc != LDAP_SUCCESS ) {
242 * deal with bind failure ...
246 * no target was found within the naming context,
247 * so bind must fail with invalid credentials
249 if ( rs->sr_err == LDAP_SUCCESS && gotit == 0 ) {
250 rs->sr_err = LDAP_INVALID_CREDENTIALS;
252 rs->sr_err = slap_map_api2result( rs );
254 send_ldap_result( op, rs );
263 * meta_back_single_bind
265 * attempts to perform a bind with creds
268 meta_back_single_bind(
275 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
276 metatarget_t *mt = &mi->mi_targets[ candidate ];
277 struct berval mdn = BER_BVNULL;
278 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
283 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
284 ch_free( msc->msc_bound_ndn.bv_val );
285 BER_BVZERO( &msc->msc_bound_ndn );
288 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
289 /* destroy sensitive data */
290 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
291 ch_free( msc->msc_cred.bv_val );
292 BER_BVZERO( &msc->msc_cred );
296 * Rewrite the bind dn if needed
302 dc.conn = op->o_conn;
306 if ( ldap_back_dn_massage( &dc, &op->o_req_dn, &mdn ) ) {
307 send_ldap_result( op, rs );
315 /* FIXME: this fixes the bind problem right now; we need
316 * to use the asynchronous version to get the "matched"
317 * and more in case of failure ... */
318 /* FIXME: should we check if at least some of the op->o_ctrls
319 * can/should be passed? */
321 rs->sr_err = ldap_sasl_bind( msc->msc_ld, mdn.bv_val,
322 LDAP_SASL_SIMPLE, &op->orb_cred,
323 op->o_ctrls, NULL, &msgid );
324 if ( rs->sr_err == LDAP_SUCCESS ) {
328 int nretries = mt->mt_nretries;
329 char buf[ SLAP_TEXT_BUFLEN ];
331 LDAP_BACK_TV_SET( &tv );
337 switch ( ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
339 snprintf( buf, sizeof( buf ),
340 "ldap_result=0 nretries=%d%s",
341 nretries, rebinding ? " rebinding" : "" );
342 Debug( LDAP_DEBUG_ANY,
343 "%s meta_back_single_bind[%d]: %s.\n",
344 op->o_log_prefix, candidate, buf );
346 if ( nretries != META_RETRY_NEVER ) {
347 ldap_pvt_thread_yield();
348 if ( nretries > 0 ) {
351 tv = mt->mt_bind_timeout;
355 rs->sr_err = LDAP_BUSY;
357 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
361 /* FIXME: some times the request times out
362 * while the other party is not willing to
363 * send a response any more. Give it a second
364 * chance with a freshly bound connection */
366 nretries = mt->mt_nretries;
370 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
374 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
377 snprintf( buf, sizeof( buf ),
378 "err=%d nretries=%d",
379 rs->sr_err, nretries );
380 Debug( LDAP_DEBUG_ANY,
381 "### %s meta_back_single_bind[%d]: %s.\n",
382 op->o_log_prefix, candidate, buf );
384 rc = slap_map_api2result( rs );
385 if ( rs->sr_err == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
386 rc = meta_back_retry( op, rs, mc, candidate, LDAP_BACK_DONTSEND );
388 if ( nretries > 0 ) {
391 ldap_pvt_thread_yield();
398 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
399 NULL, NULL, NULL, NULL, 1 );
400 if ( rc != LDAP_SUCCESS ) {
407 if ( rs->sr_err != LDAP_SUCCESS ) {
408 rs->sr_err = slap_map_api2result( rs );
412 ber_bvreplace( &msc->msc_bound_ndn, &op->o_req_dn );
413 LDAP_BACK_CONN_ISBOUND_SET( msc );
414 mc->mc_authz_target = candidate;
416 if ( LDAP_BACK_SAVECRED( mi ) ) {
417 ber_bvreplace( &msc->msc_cred, &op->orb_cred );
418 ldap_set_rebind_proc( msc->msc_ld, meta_back_rebind_f, msc );
421 if ( mi->mi_cache.ttl != META_DNCACHE_DISABLED
422 && op->o_req_ndn.bv_len != 0 )
424 ( void )meta_dncache_update_entry( &mi->mi_cache,
425 &op->o_req_ndn, candidate );
429 if ( mdn.bv_val != op->o_req_dn.bv_val ) {
437 * meta_back_single_dobind
440 meta_back_single_dobind(
445 ldap_back_send_t sendok,
449 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
450 metatarget_t *mt = &mi->mi_targets[ candidate ];
451 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
453 static struct berval cred = BER_BVC( "" );
456 save_nretries = nretries;
458 assert( !LDAP_BACK_CONN_ISBOUND( msc ) );
461 * Otherwise an anonymous bind is performed
462 * (note: if the target was already bound, the anonymous
463 * bind clears the previous bind).
465 if ( !BER_BVISNULL( &msc->msc_bound_ndn ) ) {
466 ber_memfree( msc->msc_bound_ndn.bv_val );
467 BER_BVZERO( &msc->msc_bound_ndn );
470 if ( LDAP_BACK_SAVECRED( mi ) && !BER_BVISNULL( &msc->msc_cred ) ) {
471 /* destroy sensitive data */
472 memset( msc->msc_cred.bv_val, 0, msc->msc_cred.bv_len );
473 ber_memfree( msc->msc_cred.bv_val );
474 BER_BVZERO( &msc->msc_cred );
477 /* FIXME: should we check if at least some of the op->o_ctrls
478 * can/should be passed? */
480 rc = ldap_sasl_bind( msc->msc_ld, "", LDAP_SASL_SIMPLE, &cred,
481 NULL, NULL, &msgid );
482 if ( rc == LDAP_SUCCESS ) {
485 char buf[ SLAP_TEXT_BUFLEN ];
487 LDAP_BACK_TV_SET( &tv );
493 switch ( ldap_result( msc->msc_ld, msgid, LDAP_MSG_ALL, &tv, &res ) ) {
495 snprintf( buf, sizeof( buf ),
496 "ldap_result=0 nretries=%d%s",
497 nretries, rebinding ? " rebinding" : "" );
498 Debug( LDAP_DEBUG_ANY,
499 "%s meta_back_single_dobind[%d]: %s.\n",
500 op->o_log_prefix, candidate, buf );
502 if ( nretries != META_RETRY_NEVER ) {
503 ldap_pvt_thread_yield();
504 if ( nretries > 0 ) {
507 tv = mt->mt_bind_timeout;
513 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
517 /* FIXME: some times the request times out
518 * while the other party is not willing to
519 * send a response any more. Give it a second
520 * chance with a freshly bound connection */
522 nretries = save_nretries;
526 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER,
530 ldap_abandon_ext( msc->msc_ld, msgid, NULL, NULL );
533 snprintf( buf, sizeof( buf ),
534 "err=%d nretries=%d",
535 rs->sr_err, nretries );
536 Debug( LDAP_DEBUG_ANY,
537 "### %s meta_back_single_dobind[%d]: %s.\n",
538 op->o_log_prefix, candidate, buf );
540 rc = slap_map_api2result( rs );
541 if ( rc == LDAP_UNAVAILABLE && nretries != META_RETRY_NEVER ) {
542 /* NOTE: we do not use meta_back_retry() here
543 * to avoid circular loops; mc_mutex is set
546 ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
549 if ( mc->mc_refcnt == 1 ) {
550 meta_clear_one_candidate( msc );
551 LDAP_BACK_CONN_ISBOUND_CLEAR( msc );
553 ( void )rewrite_session_delete( mt->mt_rwmap.rwm_rw, op->o_conn );
555 /* mc here must be the regular mc,
556 * reset and ready for init */
557 rc = meta_back_init_one_conn( op, rs,
559 LDAP_BACK_CONN_ISPRIV( mc ),
560 LDAP_BACK_DONTSEND );
563 /* can't do anything about it */
564 rc = LDAP_UNAVAILABLE;
568 ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
571 if ( rc == LDAP_SUCCESS ) {
572 ldap_pvt_thread_yield();
573 if ( nretries > 0 ) {
582 rc = ldap_parse_result( msc->msc_ld, res, &rs->sr_err,
583 NULL, NULL, NULL, NULL, 1 );
584 if ( rc == LDAP_SUCCESS ) {
585 rc = slap_map_api2result( rs );
592 rc = slap_map_api2result( rs );
596 if ( rc != LDAP_SUCCESS && ( sendok & LDAP_BACK_SENDERR ) ) {
597 send_ldap_result( op, rs );
611 ldap_back_send_t sendok )
613 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
619 SlapReply *candidates = meta_back_candidates_get( op );
621 if ( be_isroot( op ) ) {
625 Debug( LDAP_DEBUG_TRACE,
626 "%s meta_back_dobind: conn=%ld%s\n",
628 LDAP_BACK_PCONN_ID( mc->mc_conn ),
629 isroot ? " (isroot)" : "" );
631 ldap_pvt_thread_mutex_lock( &mc->mc_mutex );
634 * all the targets are bound as pseudoroot
636 if ( mc->mc_authz_target == META_BOUND_ALL ) {
641 for ( i = 0; i < mi->mi_ntargets; i++ ) {
642 metatarget_t *mt = &mi->mi_targets[ i ];
643 metasingleconn_t *msc = &mc->mc_conns[ i ];
644 int rc, do_retry = 1;
650 if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
654 assert( msc->msc_ld != NULL );
657 * If the target is already bound it is skipped
659 if ( LDAP_BACK_CONN_ISBOUND( msc ) || LDAP_BACK_CONN_ISANON( msc ) ) {
665 if ( isroot && !BER_BVISNULL( &mi->mi_targets[ i ].mt_pseudorootdn ) )
669 op2.o_tag = LDAP_REQ_BIND;
670 op2.o_req_dn = mi->mi_targets[ i ].mt_pseudorootdn;
671 op2.o_req_ndn = mi->mi_targets[ i ].mt_pseudorootdn;
672 op2.orb_cred = mi->mi_targets[ i ].mt_pseudorootpw;
673 op2.orb_method = LDAP_AUTH_SIMPLE;
675 rootdn = mi->mi_targets[ i ].mt_pseudorootdn.bv_val;
677 rc = meta_back_single_bind( &op2, rs, mc, i, 0 );
680 rc = meta_back_single_dobind( op, rs, mc, i,
681 LDAP_BACK_DONTSEND, mt->mt_nretries, 1 );
684 if ( rc != LDAP_SUCCESS ) {
685 char buf[ SLAP_TEXT_BUFLEN ];
687 if ( rc == LDAP_UNAVAILABLE && do_retry ) {
689 if ( meta_back_retry_lock( op, rs, mc, i, LDAP_BACK_DONTSEND, 0 ) ) {
694 snprintf( buf, sizeof( buf ),
695 "meta_back_dobind[%d]: (%s) err=%d.",
696 i, rootdn ? rootdn : "anonymous", rc );
697 Debug( LDAP_DEBUG_ANY,
699 op->o_log_prefix, buf, 0 );
702 * null cred bind should always succeed
703 * as anonymous, so a failure means
704 * the target is no longer candidate possibly
705 * due to technical reasons (remote host down?)
706 * so better clear the handle
708 /* leave the target candidate, but record the error for later use */
709 candidates[ i ].sr_err = rc;
710 if ( META_BACK_ONERR_STOP( mi ) ) {
717 Debug( LDAP_DEBUG_TRACE,
718 "%s meta_back_dobind[%d]: "
721 rootdn ? rootdn : "anonymous" );
724 LDAP_BACK_CONN_ISBOUND_SET( msc );
726 LDAP_BACK_CONN_ISANON_SET( msc );
732 ldap_pvt_thread_mutex_unlock( &mc->mc_mutex );
734 Debug( LDAP_DEBUG_TRACE,
735 "%s meta_back_dobind: conn=%ld bound=%d\n",
736 op->o_log_prefix, LDAP_BACK_PCONN_ID( mc->mc_conn ), bound );
739 meta_back_release_conn( op, mc );
741 if ( sendok & LDAP_BACK_SENDERR ) {
742 if ( rs->sr_err == LDAP_SUCCESS ) {
743 rs->sr_err = LDAP_BUSY;
745 send_ldap_result( op, rs );
753 * meta_back_default_rebind
755 * This is a callback used for chasing referrals using the same
756 * credentials as the original user on this session.
759 meta_back_default_rebind(
761 LDAP_CONST char *url,
766 metasingleconn_t *msc = ( metasingleconn_t * )params;
768 return ldap_sasl_bind_s( ld, msc->msc_bound_ndn.bv_val,
769 LDAP_SASL_SIMPLE, &msc->msc_cred,
774 * FIXME: error return must be handled in a cleaner way ...
783 metainfo_t *mi = ( metainfo_t * )op->o_bd->be_private;
789 const char *save_rmsg = NULL,
791 void *rmatch_ctx = NULL;
793 if ( candidate != META_TARGET_NONE ) {
794 metasingleconn_t *msc = &mc->mc_conns[ candidate ];
796 rs->sr_err = LDAP_SUCCESS;
798 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
799 if ( rs->sr_err != LDAP_SUCCESS ) {
801 * better check the type of error. In some cases
802 * (search ?) it might be better to return a
803 * success if at least one of the targets gave
804 * positive result ...
806 ldap_get_option( msc->msc_ld,
807 LDAP_OPT_ERROR_STRING, &rmsg );
808 if ( rmsg != NULL && rmsg[ 0 ] == '\0' ) {
809 ldap_memfree( rmsg );
813 ldap_get_option( msc->msc_ld,
814 LDAP_OPT_MATCHED_DN, &rmatch );
815 if ( rmatch != NULL && rmatch[ 0 ] == '\0' ) {
816 ldap_memfree( rmatch );
820 rerr = rs->sr_err = slap_map_api2result( rs );
822 Debug(LDAP_DEBUG_ANY,
823 "==> meta_back_op_result: target"
824 " <%d> sending msg \"%s\""
825 " (matched \"%s\")\n",
826 candidate, ( rmsg ? rmsg : "" ),
827 ( rmatch ? rmatch : "" ) );
831 for ( i = 0; i < mi->mi_ntargets; i++ ) {
832 metasingleconn_t *msc = &mc->mc_conns[ i ];
836 rs->sr_err = LDAP_SUCCESS;
838 ldap_get_option( msc->msc_ld, LDAP_OPT_ERROR_NUMBER, &rs->sr_err );
839 if ( rs->sr_err != LDAP_SUCCESS ) {
841 * better check the type of error. In some cases
842 * (search ?) it might be better to return a
843 * success if at least one of the targets gave
844 * positive result ...
846 ldap_get_option( msc->msc_ld,
847 LDAP_OPT_ERROR_STRING, &msg );
848 if ( msg != NULL && msg[ 0 ] == '\0' ) {
853 ldap_get_option( msc->msc_ld,
854 LDAP_OPT_MATCHED_DN, &match );
855 if ( match != NULL && match[ 0 ] == '\0' ) {
856 ldap_memfree( match );
860 rs->sr_err = slap_map_api2result( rs );
862 Debug(LDAP_DEBUG_ANY,
863 "==> meta_back_op_result: target"
864 " <%d> sending msg \"%s\""
865 " (matched \"%s\")\n",
866 i, ( msg ? msg : "" ),
867 ( match ? match : "" ) );
870 * FIXME: need to rewrite "match" (need rwinfo)
872 switch ( rs->sr_err ) {
877 ldap_memfree( rmsg );
882 if ( match != NULL ) {
884 ldap_memfree( rmatch );
897 ldap_memfree( match );
904 if ( rmsg != NULL ) {
905 save_rmsg = rs->sr_text;
908 if ( rmatch != NULL ) {
909 struct berval dn, pdn;
911 ber_str2bv( rmatch, 0, 0, &dn );
912 if ( dnPretty( NULL, &dn, &pdn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
913 ldap_memfree( rmatch );
914 rmatch_ctx = op->o_tmpmemctx;
917 save_rmatch = rs->sr_matched;
918 rs->sr_matched = rmatch;
920 send_ldap_result( op, rs );
921 if ( rmsg != NULL ) {
923 rs->sr_text = save_rmsg;
925 if ( rmatch != NULL ) {
926 ber_memfree_x( rmatch, rmatch_ctx );
927 rs->sr_matched = save_rmatch;
930 return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );