3 * Copyright 1999-2003 The OpenLDAP Foundation.
6 * Redistribution and use in source and binary forms are permitted only
7 * as authorized by the OpenLDAP Public License. A copy of this
8 * license is available at http://www.OpenLDAP.org/license.html or
9 * in file LICENSE in the top-level directory of the distribution.
15 #include <ac/string.h>
16 #include <ac/socket.h>
20 #include "../../libraries/liblber/lber-int.h"
22 #define SLAP_CTRL_FRONTEND 0x80000000U
23 #define SLAP_CTRL_FRONTEND_SEARCH 0x01000000U /* for NOOP */
25 #define SLAP_CTRL_OPFLAGS 0x0000FFFFU
26 #define SLAP_CTRL_ABANDON 0x00000001U
27 #define SLAP_CTRL_ADD 0x00002002U
28 #define SLAP_CTRL_BIND 0x00000004U
29 #define SLAP_CTRL_COMPARE 0x00001008U
30 #define SLAP_CTRL_DELETE 0x00002010U
31 #define SLAP_CTRL_MODIFY 0x00002020U
32 #define SLAP_CTRL_RENAME 0x00002040U
33 #define SLAP_CTRL_SEARCH 0x00001080U
34 #define SLAP_CTRL_UNBIND 0x00000100U
36 #define SLAP_CTRL_INTROGATE (SLAP_CTRL_COMPARE|SLAP_CTRL_SEARCH)
37 #define SLAP_CTRL_UPDATE \
38 (SLAP_CTRL_ADD|SLAP_CTRL_DELETE|SLAP_CTRL_MODIFY|SLAP_CTRL_RENAME)
39 #define SLAP_CTRL_ACCESS (SLAP_CTRL_INTROGATE|SLAP_CTRL_UPDATE)
41 typedef int (SLAP_CTRL_PARSE_FN) LDAP_P((
47 static SLAP_CTRL_PARSE_FN parseProxyAuthz;
48 static SLAP_CTRL_PARSE_FN parseManageDSAit;
49 static SLAP_CTRL_PARSE_FN parseNoOp;
50 static SLAP_CTRL_PARSE_FN parsePagedResults;
51 static SLAP_CTRL_PARSE_FN parseValuesReturnFilter;
52 static SLAP_CTRL_PARSE_FN parsePermitModify;
53 static SLAP_CTRL_PARSE_FN parseNoReferrals;
55 #ifdef LDAP_CONTROL_SUBENTRIES
56 static SLAP_CTRL_PARSE_FN parseSubentries;
58 #ifdef LDAP_CLIENT_UPDATE
59 static SLAP_CTRL_PARSE_FN parseClientUpdate;
62 static SLAP_CTRL_PARSE_FN parseLdupSync;
65 #undef sc_mask /* avoid conflict with Irix 6.5 <sys/signal.h> */
67 static char *proxy_authz_extops[] = {
68 LDAP_EXOP_MODIFY_PASSWD,
73 static struct slap_control {
76 char **sc_extendedops;
77 SLAP_CTRL_PARSE_FN *sc_parse;
79 } supportedControls[] = {
80 { LDAP_CONTROL_PROXY_AUTHZ,
81 SLAP_CTRL_FRONTEND|SLAP_CTRL_ACCESS, proxy_authz_extops,
83 { LDAP_CONTROL_MANAGEDSAIT,
84 SLAP_CTRL_ACCESS, NULL,
87 SLAP_CTRL_ACCESS, NULL,
89 { LDAP_CONTROL_PAGEDRESULTS,
90 SLAP_CTRL_SEARCH, NULL,
92 { LDAP_CONTROL_VALUESRETURNFILTER,
93 SLAP_CTRL_SEARCH, NULL,
94 parseValuesReturnFilter },
95 #ifdef LDAP_CONTROL_SUBENTRIES
96 { LDAP_CONTROL_SUBENTRIES,
97 SLAP_CTRL_SEARCH, NULL,
100 #ifdef LDAP_CONTROL_PERMITMODIFY
101 { LDAP_CONTROL_PERMITMODIFY,
102 SLAP_CTRL_UPDATE, NULL,
105 #ifdef LDAP_CONTROL_NOREFERRALS
106 { LDAP_CONTROL_NOREFERRALS,
107 SLAP_CTRL_SEARCH, NULL,
110 #ifdef LDAP_CLIENT_UPDATE
111 { LDAP_CONTROL_CLIENT_UPDATE,
112 SLAP_CTRL_SEARCH, NULL,
117 SLAP_CTRL_SEARCH, NULL,
124 get_supported_ctrl(int index)
126 return supportedControls[index].sc_oid;
130 get_supported_ctrl_mask(int index)
132 return supportedControls[index].sc_mask;
135 static struct slap_control *
136 find_ctrl( const char *oid )
139 for( i=0; supportedControls[i].sc_oid; i++ ) {
140 if( strcmp( oid, supportedControls[i].sc_oid ) == 0 ) {
141 return &supportedControls[i];
156 BerElement *ber = op->o_ber;
157 struct slap_control *sc;
158 int rc = LDAP_SUCCESS;
159 const char *errmsg = NULL;
161 len = ber_pvt_ber_remaining(ber);
169 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
170 if( tag == LBER_ERROR ) {
171 rc = SLAPD_DISCONNECT;
172 errmsg = "unexpected data in PDU";
179 LDAP_LOG( OPERATION, ENTRY,
180 "get_ctrls: conn %lu\n", conn->c_connid, 0, 0 );
182 Debug( LDAP_DEBUG_TRACE,
183 "=> get_ctrls\n", 0, 0, 0 );
186 if( op->o_protocol < LDAP_VERSION3 ) {
187 rc = SLAPD_DISCONNECT;
188 errmsg = "controls require LDAPv3";
192 /* one for first control, one for termination */
193 op->o_ctrls = ch_malloc( 2 * sizeof(LDAPControl *) );
196 if( op->ctrls == NULL ) {
198 errmsg = "no memory";
203 op->o_ctrls[nctrls] = NULL;
205 /* step through each element */
206 for( tag = ber_first_element( ber, &len, &opaque );
208 tag = ber_next_element( ber, &len, opaque ) )
211 LDAPControl **tctrls;
213 c = ch_calloc( 1, sizeof(LDAPControl) );
217 ldap_controls_free(op->o_ctrls);
221 errmsg = "no memory";
226 /* allocate pointer space for current controls (nctrls)
227 * + this control + extra NULL
229 tctrls = ch_realloc( op->o_ctrls,
230 (nctrls+2) * sizeof(LDAPControl *));
233 if( tctrls == NULL ) {
235 ldap_controls_free(op->o_ctrls);
239 errmsg = "no memory";
243 op->o_ctrls = tctrls;
245 op->o_ctrls[nctrls++] = c;
246 op->o_ctrls[nctrls] = NULL;
248 tag = ber_scanf( ber, "{a" /*}*/, &c->ldctl_oid );
250 if( tag == LBER_ERROR ) {
252 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu get OID failed.\n",
253 conn->c_connid, 0, 0 );
255 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
259 ldap_controls_free( op->o_ctrls );
261 rc = SLAPD_DISCONNECT;
262 errmsg = "decoding controls error";
265 } else if( c->ldctl_oid == NULL ) {
267 LDAP_LOG( OPERATION, INFO,
268 "get_ctrls: conn %lu got emtpy OID.\n",
269 conn->c_connid, 0, 0 );
271 Debug( LDAP_DEBUG_TRACE,
272 "get_ctrls: conn %lu got emtpy OID.\n",
273 conn->c_connid, 0, 0 );
276 ldap_controls_free( op->o_ctrls );
278 rc = LDAP_PROTOCOL_ERROR;
279 errmsg = "OID field is empty";
283 tag = ber_peek_tag( ber, &len );
285 if( tag == LBER_BOOLEAN ) {
287 tag = ber_scanf( ber, "b", &crit );
289 if( tag == LBER_ERROR ) {
291 LDAP_LOG( OPERATION, INFO,
292 "get_ctrls: conn %lu get crit failed.\n",
293 conn->c_connid, 0, 0 );
295 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
298 ldap_controls_free( op->o_ctrls );
300 rc = SLAPD_DISCONNECT;
301 errmsg = "decoding controls error";
305 c->ldctl_iscritical = (crit != 0);
306 tag = ber_peek_tag( ber, &len );
309 if( tag == LBER_OCTETSTRING ) {
310 tag = ber_scanf( ber, "o", &c->ldctl_value );
312 if( tag == LBER_ERROR ) {
314 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu: "
315 "%s (%scritical): get value failed.\n",
316 conn->c_connid, c->ldctl_oid,
317 c->ldctl_iscritical ? "" : "non" );
319 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
320 "%s (%scritical): get value failed.\n",
321 conn->c_connid, c->ldctl_oid,
322 c->ldctl_iscritical ? "" : "non" );
324 ldap_controls_free( op->o_ctrls );
326 rc = SLAPD_DISCONNECT;
327 errmsg = "decoding controls error";
333 LDAP_LOG( OPERATION, INFO,
334 "get_ctrls: conn %lu oid=\"%s\" (%scritical)\n",
335 conn->c_connid, c->ldctl_oid, c->ldctl_iscritical ? "" : "non" );
337 Debug( LDAP_DEBUG_TRACE,
338 "=> get_ctrls: oid=\"%s\" (%scritical)\n",
339 c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
342 sc = find_ctrl( c->ldctl_oid );
344 /* recognized control */
346 switch( op->o_tag ) {
348 tagmask = SLAP_CTRL_ADD;
351 tagmask = SLAP_CTRL_BIND;
353 case LDAP_REQ_COMPARE:
354 tagmask = SLAP_CTRL_COMPARE;
356 case LDAP_REQ_DELETE:
357 tagmask = SLAP_CTRL_DELETE;
359 case LDAP_REQ_MODIFY:
360 tagmask = SLAP_CTRL_MODIFY;
362 case LDAP_REQ_RENAME:
363 tagmask = SLAP_CTRL_RENAME;
365 case LDAP_REQ_SEARCH:
366 tagmask = SLAP_CTRL_SEARCH;
368 case LDAP_REQ_UNBIND:
369 tagmask = SLAP_CTRL_UNBIND;
371 case LDAP_REQ_ABANDON:
372 tagmask = SLAP_CTRL_ABANDON;
374 case LDAP_REQ_EXTENDED:
376 assert( op->o_extendedop != NULL );
377 if( sc->sc_extendedops != NULL ) {
379 for( i=0; sc->sc_extendedops[i] != NULL; i++ ) {
380 if( strcmp( op->o_extendedop, sc->sc_extendedops[i] )
391 errmsg = "controls internal error";
395 if (( sc->sc_mask & tagmask ) == tagmask ) {
396 /* available extension */
398 if( !sc->sc_parse ) {
400 errmsg = "not yet implemented";
404 rc = sc->sc_parse( conn, op, c, &errmsg );
406 if( rc != LDAP_SUCCESS ) goto return_results;
408 if ( sc->sc_mask & SLAP_CTRL_FRONTEND ) {
409 /* kludge to disable backend_control() check */
410 c->ldctl_iscritical = 0;
412 } else if ( tagmask == SLAP_CTRL_SEARCH &&
413 sc->sc_mask & SLAP_CTRL_FRONTEND_SEARCH )
415 /* kludge to disable backend_control() check */
416 c->ldctl_iscritical = 0;
419 } else if( c->ldctl_iscritical ) {
420 /* unavailable CRITICAL control */
421 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
422 errmsg = "critical extension is unavailable";
426 } else if( c->ldctl_iscritical ) {
427 /* unrecognized CRITICAL control */
428 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
429 errmsg = "critical extension is not recognized";
436 LDAP_LOG( OPERATION, RESULTS,
437 "get_ctrls: n=%d rc=%d err=\"%s\"\n",
438 nctrls, rc, errmsg ? errmsg : "" );
440 Debug( LDAP_DEBUG_TRACE,
441 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
442 nctrls, rc, errmsg ? errmsg : "");
445 if( sendres && rc != LDAP_SUCCESS ) {
446 if( rc == SLAPD_DISCONNECT ) {
447 send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
449 send_ldap_result( conn, op, rc,
450 NULL, errmsg, NULL, NULL );
457 static int parseManageDSAit (
463 if ( op->o_managedsait != SLAP_NO_CONTROL ) {
464 *text = "manageDSAit control specified multiple times";
465 return LDAP_PROTOCOL_ERROR;
468 if ( ctrl->ldctl_value.bv_len ) {
469 *text = "manageDSAit control value not empty";
470 return LDAP_PROTOCOL_ERROR;
473 op->o_managedsait = ctrl->ldctl_iscritical
474 ? SLAP_CRITICAL_CONTROL
475 : SLAP_NONCRITICAL_CONTROL;
480 static int parseProxyAuthz (
487 struct berval dn = { 0, NULL };
489 if ( op->o_proxy_authz != SLAP_NO_CONTROL ) {
490 *text = "proxy authorization control specified multiple times";
491 return LDAP_PROTOCOL_ERROR;
494 op->o_proxy_authz = ctrl->ldctl_iscritical
495 ? SLAP_CRITICAL_CONTROL
496 : SLAP_NONCRITICAL_CONTROL;
499 LDAP_LOG( OPERATION, ARGS,
500 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
502 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
505 Debug( LDAP_DEBUG_ARGS,
506 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
508 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
512 if( ctrl->ldctl_value.bv_len == 0 ) {
514 LDAP_LOG( OPERATION, RESULTS,
515 "parseProxyAuthz: conn=%lu anonymous\n",
516 conn->c_connid, 0, 0 );
518 Debug( LDAP_DEBUG_TRACE,
519 "parseProxyAuthz: conn=%lu anonymous\n",
520 conn->c_connid, 0, 0 );
524 free( op->o_dn.bv_val );
526 op->o_dn.bv_val = ch_strdup( "" );
528 free( op->o_ndn.bv_val );
529 op->o_ndn.bv_len = 0;
530 op->o_ndn.bv_val = ch_strdup( "" );
535 rc = slap_sasl_getdn( conn,
536 ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len,
537 NULL, &dn, SLAP_GETDN_AUTHZID );
539 if( rc != LDAP_SUCCESS || !dn.bv_len ) {
541 ch_free( dn.bv_val );
543 *text = "authzId mapping failed";
544 return LDAP_PROXY_AUTHZ_FAILURE;
548 LDAP_LOG( OPERATION, RESULTS,
549 "parseProxyAuthz: conn=%lu \"%s\"\n",
551 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
553 Debug( LDAP_DEBUG_TRACE,
554 "parseProxyAuthz: conn=%lu \"%s\"\n",
556 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
559 rc = slap_sasl_authorized( conn, &op->o_ndn, &dn );
562 ch_free( dn.bv_val );
563 *text = "not authorized to assume identity";
564 return LDAP_PROXY_AUTHZ_FAILURE;
567 ch_free( op->o_dn.bv_val );
568 ch_free( op->o_ndn.bv_val );
570 op->o_dn.bv_val = NULL;
574 * NOTE: since slap_sasl_getdn() returns a normalized dn,
575 * from now on op->o_dn is normalized
577 ber_dupbv( &op->o_dn, &dn );
582 static int parseNoOp (
588 if ( op->o_noop != SLAP_NO_CONTROL ) {
589 *text = "noop control specified multiple times";
590 return LDAP_PROTOCOL_ERROR;
593 if ( ctrl->ldctl_value.bv_len ) {
594 *text = "noop control value not empty";
595 return LDAP_PROTOCOL_ERROR;
598 op->o_noop = ctrl->ldctl_iscritical
599 ? SLAP_CRITICAL_CONTROL
600 : SLAP_NONCRITICAL_CONTROL;
605 static int parsePagedResults (
614 struct berval cookie = { 0, NULL };
616 if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
617 *text = "paged results control specified multiple times";
618 return LDAP_PROTOCOL_ERROR;
621 if ( ctrl->ldctl_value.bv_len == 0 ) {
622 *text = "paged results control value is empty (or absent)";
623 return LDAP_PROTOCOL_ERROR;
626 /* Parse the control value
627 * realSearchControlValue ::= SEQUENCE {
628 * size INTEGER (0..maxInt),
629 * -- requested page size from client
630 * -- result set size estimate from server
631 * cookie OCTET STRING
633 ber = ber_init( &ctrl->ldctl_value );
635 *text = "internal error";
639 tag = ber_scanf( ber, "{im}", &size, &cookie );
640 (void) ber_free( ber, 1 );
642 if( tag == LBER_ERROR ) {
643 *text = "paged results control could not be decoded";
644 return LDAP_PROTOCOL_ERROR;
648 *text = "paged results control size invalid";
649 return LDAP_PROTOCOL_ERROR;
652 if( cookie.bv_len ) {
653 PagedResultsCookie reqcookie;
654 if( cookie.bv_len != sizeof( reqcookie ) ) {
656 *text = "paged results cookie is invalid";
657 return LDAP_PROTOCOL_ERROR;
660 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
662 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
664 *text = "paged results cookie is invalid";
665 return LDAP_PROTOCOL_ERROR;
667 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
668 *text = "paged results cookie is invalid or old";
669 return LDAP_UNWILLING_TO_PERFORM;
672 /* Initial request. Initialize state. */
673 op->o_pagedresults_state.ps_cookie = 0;
674 op->o_pagedresults_state.ps_id = NOID;
677 op->o_pagedresults_size = size;
679 op->o_pagedresults = ctrl->ldctl_iscritical
680 ? SLAP_CRITICAL_CONTROL
681 : SLAP_NONCRITICAL_CONTROL;
686 int parseValuesReturnFilter (
694 struct berval fstr = { 0, NULL };
695 const char *err_msg = "";
697 if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
698 *text = "valuesReturnFilter control specified multiple times";
699 return LDAP_PROTOCOL_ERROR;
702 if ( ctrl->ldctl_value.bv_len == 0 ) {
703 *text = "valuesReturnFilter control value is empty (or absent)";
704 return LDAP_PROTOCOL_ERROR;
707 ber = ber_init( &(ctrl->ldctl_value) );
709 *text = "internal error";
713 rc = get_vrFilter( conn, ber, &(op->vrFilter), &err_msg);
715 if( rc != LDAP_SUCCESS ) {
717 if( rc == SLAPD_DISCONNECT ) {
718 send_ldap_disconnect( conn, op,
719 LDAP_PROTOCOL_ERROR, *text );
721 send_ldap_result( conn, op, rc,
722 NULL, *text, NULL, NULL );
724 if( fstr.bv_val != NULL) free( fstr.bv_val );
725 if( op->vrFilter != NULL) vrFilter_free( op->vrFilter );
728 vrFilter2bv( op->vrFilter, &fstr );
732 LDAP_LOG( OPERATION, ARGS,
733 "parseValuesReturnFilter: conn %d vrFilter: %s\n",
734 conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
736 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
737 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
740 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
741 ? SLAP_CRITICAL_CONTROL
742 : SLAP_NONCRITICAL_CONTROL;
747 #ifdef LDAP_CONTROL_SUBENTRIES
748 static int parseSubentries (
754 if ( op->o_subentries != SLAP_NO_CONTROL ) {
755 *text = "subentries control specified multiple times";
756 return LDAP_PROTOCOL_ERROR;
759 /* FIXME: should use BER library */
760 if( ( ctrl->ldctl_value.bv_len != 3 )
761 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
762 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
764 *text = "subentries control value encoding is bogus";
765 return LDAP_PROTOCOL_ERROR;
768 op->o_subentries = ctrl->ldctl_iscritical
769 ? SLAP_CRITICAL_CONTROL
770 : SLAP_NONCRITICAL_CONTROL;
772 op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
778 #ifdef LDAP_CONTROL_PERMITMODIFY
779 static int parsePermitModify (
785 if ( op->o_permitmodify != SLAP_NO_CONTROL ) {
786 *text = "permitmodify control specified multiple times";
787 return LDAP_PROTOCOL_ERROR;
790 if ( ctrl->ldctl_value.bv_len ) {
791 *text = "permitmodify control value not empty";
792 return LDAP_PROTOCOL_ERROR;
795 op->o_permitmodify = ctrl->ldctl_iscritical
796 ? SLAP_CRITICAL_CONTROL
797 : SLAP_NONCRITICAL_CONTROL;
803 #ifdef LDAP_CONTROL_NOREFERRALS
804 static int parseNoReferrals (
810 if ( op->o_noreferrals != SLAP_NO_CONTROL ) {
811 *text = "noreferrals control specified multiple times";
812 return LDAP_PROTOCOL_ERROR;
815 if ( ctrl->ldctl_value.bv_len ) {
816 *text = "noreferrals control value not empty";
817 return LDAP_PROTOCOL_ERROR;
820 op->o_noreferrals = ctrl->ldctl_iscritical
821 ? SLAP_CRITICAL_CONTROL
822 : SLAP_NONCRITICAL_CONTROL;
828 #ifdef LDAP_CLIENT_UPDATE
829 static int parseClientUpdate (
840 struct berval scheme = { 0, NULL };
841 struct berval cookie = { 0, NULL };
843 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
844 *text = "LCUP client update control specified multiple times";
845 return LDAP_PROTOCOL_ERROR;
849 if ( op->o_sync != SLAP_NO_CONTROL ) {
850 *text = "LDAP Client Update and Sync controls used together";
851 return LDAP_PROTOCOL_ERROR;
855 if ( ctrl->ldctl_value.bv_len == 0 ) {
856 *text = "LCUP client update control value is empty (or absent)";
857 return LDAP_PROTOCOL_ERROR;
860 /* Parse the control value
861 * ClientUpdateControlValue ::= SEQUENCE {
862 * updateType ENUMERATED {
863 * synchronizeOnly {0},
864 * synchronizeAndPersist {1},
866 * sendCookieInterval INTEGER OPTIONAL,
867 * cookie LCUPCookie OPTIONAL
871 ber = ber_init( &ctrl->ldctl_value );
873 *text = "internal error";
877 if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
878 *text = "LCUP client update control : decoding error";
879 return LDAP_PROTOCOL_ERROR;
883 case LDAP_CUP_SYNC_ONLY:
884 type = SLAP_LCUP_SYNC;
886 case LDAP_CUP_SYNC_AND_PERSIST:
887 type = SLAP_LCUP_SYNC_AND_PERSIST;
889 case LDAP_CUP_PERSIST_ONLY:
890 type = SLAP_LCUP_PERSIST;
893 *text = "LCUP client update control : unknown update type";
894 return LDAP_PROTOCOL_ERROR;
897 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
898 *text = "LCUP client update control : decoding error";
899 return LDAP_PROTOCOL_ERROR;
902 if ( tag == LDAP_TAG_INTERVAL ) {
903 if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
904 *text = "LCUP client update control : decoding error";
905 return LDAP_PROTOCOL_ERROR;
908 if ( interval <= 0 ) {
909 /* server chooses interval */
910 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
914 /* server chooses interval */
915 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
918 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
919 *text = "LCUP client update control : decoding error";
920 return LDAP_PROTOCOL_ERROR;
923 if ( tag == LDAP_LCUP_TAG_COOKIE ) {
924 if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
925 &scheme, &cookie )) == LBER_ERROR ) {
926 *text = "LCUP client update control : decoding error";
927 return LDAP_PROTOCOL_ERROR;
931 /* TODO : Cookie Scheme Validation */
933 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
934 *text = "Unsupported LCUP cookie scheme";
935 return LCUP_UNSUPPORTED_SCHEME;
938 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
939 *text = "Invalid LCUP cookie";
940 return LCUP_INVALID_COOKIE;
944 ber_dupbv( &op->o_clientupdate_state, &cookie );
946 (void) ber_free( ber, 1 );
948 op->o_clientupdate_type = (char) type;
949 op->o_clientupdate_interval = interval;
951 op->o_clientupdate = ctrl->ldctl_iscritical
952 ? SLAP_CRITICAL_CONTROL
953 : SLAP_NONCRITICAL_CONTROL;
960 static int parseLdupSync (
970 struct berval cookie = { 0, NULL };
972 if ( op->o_sync != SLAP_NO_CONTROL ) {
973 *text = "LDAP Sync control specified multiple times";
974 return LDAP_PROTOCOL_ERROR;
977 #ifdef LDAP_CLIENT_UPDATE
978 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
979 *text = "LDAP Sync and LDAP Client Update controls used together";
980 return LDAP_PROTOCOL_ERROR;
984 if ( ctrl->ldctl_value.bv_len == 0 ) {
985 *text = "LDAP Sync control value is empty (or absent)";
986 return LDAP_PROTOCOL_ERROR;
989 /* Parse the control value
990 * syncRequestValue ::= SEQUENCE {
995 * refreshAndPersist (3)
997 * cookie syncCookie OPTIONAL
1001 ber = ber_init( &ctrl->ldctl_value );
1003 *text = "internal error";
1007 if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1008 *text = "LDAP Sync control : mode decoding error";
1009 return LDAP_PROTOCOL_ERROR;
1013 case LDAP_SYNC_REFRESH_ONLY:
1014 mode = SLAP_SYNC_REFRESH;
1016 case LDAP_SYNC_REFRESH_AND_PERSIST:
1017 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1020 *text = "LDAP Sync control : unknown update mode";
1021 return LDAP_PROTOCOL_ERROR;
1024 tag = ber_peek_tag( ber, &len );
1026 if ( tag == LDAP_SYNC_TAG_COOKIE ) {
1027 if (( ber_scanf( ber, /*{*/ "m}",
1028 &cookie )) == LBER_ERROR ) {
1029 *text = "LDAP Sync control : cookie decoding error";
1030 return LDAP_PROTOCOL_ERROR;
1033 if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1034 *text = "LDAP Sync control : decoding error";
1035 return LDAP_PROTOCOL_ERROR;
1038 cookie.bv_val = NULL;
1041 /* TODO : Cookie Scheme Validation */
1043 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1044 *text = "Unsupported LCUP cookie scheme";
1045 return LCUP_UNSUPPORTED_SCHEME;
1048 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1049 *text = "Invalid LCUP cookie";
1050 return LCUP_INVALID_COOKIE;
1054 ber_dupbv( &op->o_sync_state, &cookie );
1056 (void) ber_free( ber, 1 );
1058 op->o_sync_mode = (char) mode;
1060 op->o_sync = ctrl->ldctl_iscritical
1061 ? SLAP_CRITICAL_CONTROL
1062 : SLAP_NONCRITICAL_CONTROL;
1064 return LDAP_SUCCESS;