217
219
session_tracking_extops, NULL,
218
220
parseSessionTracking, LDAP_SLIST_ENTRY_INITIALIZER(next) },
222
#ifdef SLAP_CONTROL_X_WHATFAILED
223
{ LDAP_CONTROL_X_WHATFAILED,
224
(int)offsetof(struct slap_control_ids, sc_whatFailed),
225
SLAP_CTRL_GLOBAL|SLAP_CTRL_ACCESS|SLAP_CTRL_HIDE,
227
parseWhatFailed, LDAP_SLIST_ENTRY_INITIALIZER(next) },
220
230
{ NULL, 0, 0, NULL, 0, NULL, LDAP_SLIST_ENTRY_INITIALIZER(next) }
592
603
if (( sc->sc_mask & tagmask ) == tagmask ) {
593
604
/* available extension */
605
if ( sc->sc_parse ) {
606
rc = sc->sc_parse( op, rs, control );
607
assert( rc != LDAP_UNAVAILABLE_CRITICAL_EXTENSION );
596
if( !sc->sc_parse ) {
609
} else if ( control->ldctl_iscritical ) {
597
610
*text = "not yet implemented";
601
rc = sc->sc_parse( op, rs, control );
603
assert( rc != LDAP_UNAVAILABLE_CRITICAL_EXTENSION );
607
} else if( control->ldctl_iscritical ) {
615
} else if ( control->ldctl_iscritical ) {
608
616
/* unavailable CRITICAL control */
609
617
*text = "critical extension is unavailable";
610
return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
618
rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
612
} else if( control->ldctl_iscritical ) {
621
} else if ( control->ldctl_iscritical ) {
613
622
/* unrecognized CRITICAL control */
614
623
*text = "critical extension is not recognized";
615
return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
624
rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
784
805
send_ldap_disconnect( op, rs );
785
806
rs->sr_err = SLAPD_DISCONNECT;
808
#ifdef SLAP_CONTROL_X_WHATFAILED
809
/* might have not been parsed yet? */
810
if ( failed_oid != NULL ) {
811
if ( !get_whatFailed( op ) ) {
814
/* step through each remaining element */
815
for ( ; tag != LBER_ERROR; tag = ber_next_element( ber, &len, opaque ) )
817
LDAPControl c = { 0 };
819
tag = ber_scanf( ber, "{m" /*}*/, &bv );
820
c.ldctl_oid = bv.bv_val;
822
if ( tag == LBER_ERROR ) {
823
slap_free_ctrls( op, op->o_ctrls );
827
} else if ( c.ldctl_oid == NULL ) {
828
slap_free_ctrls( op, op->o_ctrls );
833
tag = ber_peek_tag( ber, &len );
834
if ( tag == LBER_BOOLEAN ) {
836
tag = ber_scanf( ber, "b", &crit );
837
if( tag == LBER_ERROR ) {
838
slap_free_ctrls( op, op->o_ctrls );
843
tag = ber_peek_tag( ber, &len );
846
if ( tag == LBER_OCTETSTRING ) {
847
tag = ber_scanf( ber, "m", &c.ldctl_value );
849
if( tag == LBER_ERROR ) {
850
slap_free_ctrls( op, op->o_ctrls );
856
if ( strcmp( c.ldctl_oid, LDAP_CONTROL_X_WHATFAILED ) == 0 ) {
858
slap_parse_ctrl( op, rs, &c, &text );
864
if ( get_whatFailed( op ) ) {
866
oids[ 0 ] = failed_oid;
868
slap_ctrl_whatFailed_add( op, rs, oids );
787
873
send_ldap_result( op, rs );
1226
1324
return LDAP_SUCCESS;
1229
static int parsePreRead (
1234
ber_len_t siz, off, i;
1235
AttributeName *an = NULL;
1238
if ( op->o_preread != SLAP_CONTROL_NONE ) {
1239
rs->sr_text = "preread control specified multiple times";
1240
return LDAP_PROTOCOL_ERROR;
1243
if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1244
rs->sr_text = "preread control value is absent";
1245
return LDAP_PROTOCOL_ERROR;
1248
if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1249
rs->sr_text = "preread control value is empty";
1250
return LDAP_PROTOCOL_ERROR;
1254
if ( op->o_txnSpec ) { /* temporary limitation */
1255
rs->sr_text = "cannot perform pre-read in transaction";
1256
return LDAP_UNWILLING_TO_PERFORM;
1260
ber = ber_init( &(ctrl->ldctl_value) );
1262
rs->sr_text = "preread control: internal error";
1266
rs->sr_err = LDAP_SUCCESS;
1268
siz = sizeof( AttributeName );
1269
off = offsetof( AttributeName, an_name );
1270
if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1271
rs->sr_text = "preread control: decoding error";
1272
rs->sr_err = LDAP_PROTOCOL_ERROR;
1276
for( i=0; i<siz; i++ ) {
1277
const char *dummy = NULL;
1279
an[i].an_desc = NULL;
1281
an[i].an_oc_exclude = 0;
1282
rs->sr_err = slap_bv2ad( &an[i].an_name, &an[i].an_desc, &dummy );
1283
if ( rs->sr_err != LDAP_SUCCESS && ctrl->ldctl_iscritical ) {
1286
: "postread control: unknown attributeType";
1291
op->o_preread = ctrl->ldctl_iscritical
1292
? SLAP_CONTROL_CRITICAL
1293
: SLAP_CONTROL_NONCRITICAL;
1295
op->o_preread_attrs = an;
1298
(void) ber_free( ber, 1 );
1302
static int parsePostRead (
1307
ber_len_t siz, off, i;
1308
AttributeName *an = NULL;
1311
if ( op->o_postread != SLAP_CONTROL_NONE ) {
1312
rs->sr_text = "postread control specified multiple times";
1313
return LDAP_PROTOCOL_ERROR;
1316
if ( BER_BVISNULL( &ctrl->ldctl_value )) {
1317
rs->sr_text = "postread control value is absent";
1318
return LDAP_PROTOCOL_ERROR;
1321
if ( BER_BVISEMPTY( &ctrl->ldctl_value )) {
1322
rs->sr_text = "postread control value is empty";
1323
return LDAP_PROTOCOL_ERROR;
1327
if ( op->o_txnSpec ) { /* temporary limitation */
1328
rs->sr_text = "cannot perform post-read in transaction";
1329
return LDAP_UNWILLING_TO_PERFORM;
1333
ber = ber_init( &(ctrl->ldctl_value) );
1335
rs->sr_text = "postread control: internal error";
1339
rs->sr_err = LDAP_SUCCESS;
1340
siz = sizeof( AttributeName );
1341
off = offsetof( AttributeName, an_name );
1342
if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1343
rs->sr_text = "postread control: decoding error";
1327
#define READMSG(post, msg) \
1328
( post ? "postread control: " msg : "preread control: " msg )
1337
ber_len_t siz, off, i;
1339
AttributeName *an = NULL;
1341
if ( ( post && op->o_postread != SLAP_CONTROL_NONE ) ||
1342
( !post && op->o_preread != SLAP_CONTROL_NONE ) )
1344
rs->sr_text = READMSG( post, "specified multiple times" );
1345
return LDAP_PROTOCOL_ERROR;
1348
if ( BER_BVISNULL( &ctrl->ldctl_value ) ) {
1349
rs->sr_text = READMSG( post, "value is absent" );
1350
return LDAP_PROTOCOL_ERROR;
1353
if ( BER_BVISEMPTY( &ctrl->ldctl_value ) ) {
1354
rs->sr_text = READMSG( post, "value is empty" );
1355
return LDAP_PROTOCOL_ERROR;
1359
if ( op->o_txnSpec ) { /* temporary limitation */
1360
rs->sr_text = READMSG( post, "cannot perform in transaction" );
1361
return LDAP_UNWILLING_TO_PERFORM;
1365
ber = ber_init( &ctrl->ldctl_value );
1366
if ( ber == NULL ) {
1367
rs->sr_text = READMSG( post, "internal error" );
1371
rs->sr_err = LDAP_SUCCESS;
1372
siz = sizeof( AttributeName );
1373
off = offsetof( AttributeName, an_name );
1374
if ( ber_scanf( ber, "{M}", &an, &siz, off ) == LBER_ERROR ) {
1375
rs->sr_text = READMSG( post, "decoding error" );
1344
1376
rs->sr_err = LDAP_PROTOCOL_ERROR;
1365
1400
/* deal with special attribute types */
1366
for ( i = 0; !BER_BVISNULL( &special_attrs[ i ] ); i++ ) {
1367
if ( bvmatch( &an[i].an_name, &special_attrs[ i ] ) ) {
1401
for ( j = 0; !BER_BVISNULL( &special_attrs[ j ] ); j++ ) {
1402
if ( bvmatch( &an[i].an_name, &special_attrs[ j ] ) ) {
1403
an[i].an_name = special_attrs[ j ];
1372
if ( BER_BVISNULL( &special_attrs[ i ] ) && ctrl->ldctl_iscritical ) {
1408
if ( BER_BVISNULL( &special_attrs[ j ] ) && ctrl->ldctl_iscritical ) {
1373
1409
rs->sr_err = rc;
1376
: "postread control: unknown attributeType";
1410
rs->sr_text = dummy ? dummy
1411
: READMSG( post, "unknown attributeType" );
1382
op->o_postread = ctrl->ldctl_iscritical
1383
? SLAP_CONTROL_CRITICAL
1384
: SLAP_CONTROL_NONCRITICAL;
1386
op->o_postread_attrs = an;
1418
op->o_postread_attrs = an;
1419
op->o_postread = ctrl->ldctl_iscritical
1420
? SLAP_CONTROL_CRITICAL
1421
: SLAP_CONTROL_NONCRITICAL;
1423
op->o_preread_attrs = an;
1424
op->o_preread = ctrl->ldctl_iscritical
1425
? SLAP_CONTROL_CRITICAL
1426
: SLAP_CONTROL_NONCRITICAL;
1389
1430
(void) ber_free( ber, 1 );
1390
1431
return rs->sr_err;
1434
static int parsePreRead (
1439
return parseReadAttrs( op, rs, ctrl, 0 );
1442
static int parsePostRead (
1447
return parseReadAttrs( op, rs, ctrl, 1 );
1393
1450
static int parseValuesReturnFilter (
1906
1963
return slap_ctrl_session_tracking_add( op, rs, &ip, &name, &id, ctrl );
1967
#ifdef SLAP_CONTROL_X_WHATFAILED
1968
static int parseWhatFailed(
1973
if ( op->o_whatFailed != SLAP_CONTROL_NONE ) {
1974
rs->sr_text = "\"WHat Failed?\" control specified multiple times";
1975
return LDAP_PROTOCOL_ERROR;
1978
if ( !BER_BVISNULL( &ctrl->ldctl_value )) {
1979
rs->sr_text = "\"What Failed?\" control value not absent";
1980
return LDAP_PROTOCOL_ERROR;
1983
op->o_whatFailed = ctrl->ldctl_iscritical
1984
? SLAP_CONTROL_CRITICAL
1985
: SLAP_CONTROL_NONCRITICAL;
1987
return LDAP_SUCCESS;
1991
slap_ctrl_whatFailed_add(
1996
BerElementBuffer berbuf;
1997
BerElement *ber = (BerElement *) &berbuf;
1998
LDAPControl **ctrls = NULL;
1999
struct berval ctrlval;
2000
int i, rc = LDAP_SUCCESS;
2002
ber_init2( ber, NULL, LBER_USE_DER );
2003
ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx );
2004
ber_printf( ber, "[" /*]*/ );
2005
for ( i = 0; oids[ i ] != NULL; i++ ) {
2006
ber_printf( ber, "s", oids[ i ] );
2008
ber_printf( ber, /*[*/ "]" );
2010
if ( ber_flatten2( ber, &ctrlval, 0 ) == -1 ) {
2016
if ( rs->sr_ctrls != NULL ) {
2017
for ( ; rs->sr_ctrls[ i ] != NULL; i++ ) {
2018
if ( strcmp( rs->sr_ctrls[ i ]->ldctl_oid, LDAP_CONTROL_X_WHATFAILED ) != 0 ) {
2025
ctrls = op->o_tmprealloc( rs->sr_ctrls,
2026
sizeof(LDAPControl *)*( i + 2 )
2027
+ sizeof(LDAPControl)
2028
+ ctrlval.bv_len + 1,
2030
if ( ctrls == NULL ) {
2034
ctrls[ i + 1 ] = NULL;
2035
ctrls[ i ] = (LDAPControl *)&ctrls[ i + 2 ];
2036
ctrls[ i ]->ldctl_oid = LDAP_CONTROL_X_WHATFAILED;
2037
ctrls[ i ]->ldctl_iscritical = 0;
2038
ctrls[ i ]->ldctl_value.bv_val = (char *)&ctrls[ i ][ 1 ];
2039
AC_MEMCPY( ctrls[ i ]->ldctl_value.bv_val, ctrlval.bv_val, ctrlval.bv_len + 1 );
2040
ctrls[ i ]->ldctl_value.bv_len = ctrlval.bv_len;
2042
ber_free_buf( ber );
2044
rs->sr_ctrls = ctrls;