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 (
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 ) {
540 *text = "authzId mapping failed";
541 return LDAP_PROXY_AUTHZ_FAILURE;
545 LDAP_LOG( OPERATION, RESULTS,
546 "parseProxyAuthz: conn=%lu \"%s\"\n",
548 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
550 Debug( LDAP_DEBUG_TRACE,
551 "parseProxyAuthz: conn=%lu \"%s\"\n",
553 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
556 rc = slap_sasl_authorized( conn, &op->o_ndn, &dn );
559 ch_free( dn.bv_val );
560 *text = "not authorized to assume identity";
561 return LDAP_PROXY_AUTHZ_FAILURE;
564 ch_free( op->o_dn.bv_val );
565 ch_free( op->o_ndn.bv_val );
567 op->o_dn.bv_val = NULL;
569 ber_dupbv( &op->o_dn, &dn );
574 static int parseNoOp (
580 if ( op->o_noop != SLAP_NO_CONTROL ) {
581 *text = "noop control specified multiple times";
582 return LDAP_PROTOCOL_ERROR;
585 if ( ctrl->ldctl_value.bv_len ) {
586 *text = "noop control value not empty";
587 return LDAP_PROTOCOL_ERROR;
590 op->o_noop = ctrl->ldctl_iscritical
591 ? SLAP_CRITICAL_CONTROL
592 : SLAP_NONCRITICAL_CONTROL;
597 static int parsePagedResults (
606 struct berval cookie = { 0, NULL };
608 if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
609 *text = "paged results control specified multiple times";
610 return LDAP_PROTOCOL_ERROR;
613 if ( ctrl->ldctl_value.bv_len == 0 ) {
614 *text = "paged results control value is empty (or absent)";
615 return LDAP_PROTOCOL_ERROR;
618 /* Parse the control value
619 * realSearchControlValue ::= SEQUENCE {
620 * size INTEGER (0..maxInt),
621 * -- requested page size from client
622 * -- result set size estimate from server
623 * cookie OCTET STRING
625 ber = ber_init( &ctrl->ldctl_value );
627 *text = "internal error";
631 tag = ber_scanf( ber, "{im}", &size, &cookie );
632 (void) ber_free( ber, 1 );
634 if( tag == LBER_ERROR ) {
635 *text = "paged results control could not be decoded";
636 return LDAP_PROTOCOL_ERROR;
640 *text = "paged results control size invalid";
641 return LDAP_PROTOCOL_ERROR;
644 if( cookie.bv_len ) {
645 PagedResultsCookie reqcookie;
646 if( cookie.bv_len != sizeof( reqcookie ) ) {
648 *text = "paged results cookie is invalid";
649 return LDAP_PROTOCOL_ERROR;
652 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
654 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
656 *text = "paged results cookie is invalid";
657 return LDAP_PROTOCOL_ERROR;
659 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
660 *text = "paged results cookie is invalid or old";
661 return LDAP_UNWILLING_TO_PERFORM;
664 /* Initial request. Initialize state. */
665 op->o_pagedresults_state.ps_cookie = 0;
666 op->o_pagedresults_state.ps_id = NOID;
669 op->o_pagedresults_size = size;
671 op->o_pagedresults = ctrl->ldctl_iscritical
672 ? SLAP_CRITICAL_CONTROL
673 : SLAP_NONCRITICAL_CONTROL;
678 int parseValuesReturnFilter (
686 struct berval fstr = { 0, NULL };
687 const char *err_msg = "";
689 if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
690 *text = "valuesReturnFilter control specified multiple times";
691 return LDAP_PROTOCOL_ERROR;
694 if ( ctrl->ldctl_value.bv_len == 0 ) {
695 *text = "valuesReturnFilter control value is empty (or absent)";
696 return LDAP_PROTOCOL_ERROR;
699 ber = ber_init( &(ctrl->ldctl_value) );
701 *text = "internal error";
705 rc = get_vrFilter( conn, ber, &(op->vrFilter), &err_msg);
707 if( rc != LDAP_SUCCESS ) {
709 if( rc == SLAPD_DISCONNECT ) {
710 send_ldap_disconnect( conn, op,
711 LDAP_PROTOCOL_ERROR, *text );
713 send_ldap_result( conn, op, rc,
714 NULL, *text, NULL, NULL );
716 if( fstr.bv_val != NULL) free( fstr.bv_val );
717 if( op->vrFilter != NULL) vrFilter_free( op->vrFilter );
720 vrFilter2bv( op->vrFilter, &fstr );
724 LDAP_LOG( OPERATION, ARGS,
725 "parseValuesReturnFilter: conn %d vrFilter: %s\n",
726 conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
728 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
729 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
732 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
733 ? SLAP_CRITICAL_CONTROL
734 : SLAP_NONCRITICAL_CONTROL;
739 #ifdef LDAP_CONTROL_SUBENTRIES
740 static int parseSubentries (
746 if ( op->o_subentries != SLAP_NO_CONTROL ) {
747 *text = "subentries control specified multiple times";
748 return LDAP_PROTOCOL_ERROR;
751 /* FIXME: should use BER library */
752 if( ( ctrl->ldctl_value.bv_len != 3 )
753 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
754 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
756 *text = "subentries control value encoding is bogus";
757 return LDAP_PROTOCOL_ERROR;
760 op->o_subentries = ctrl->ldctl_iscritical
761 ? SLAP_CRITICAL_CONTROL
762 : SLAP_NONCRITICAL_CONTROL;
764 op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
770 #ifdef LDAP_CONTROL_PERMITMODIFY
771 static int parsePermitModify (
777 if ( op->o_permitmodify != SLAP_NO_CONTROL ) {
778 *text = "permitmodify control specified multiple times";
779 return LDAP_PROTOCOL_ERROR;
782 if ( ctrl->ldctl_value.bv_len ) {
783 *text = "permitmodify control value not empty";
784 return LDAP_PROTOCOL_ERROR;
787 op->o_permitmodify = ctrl->ldctl_iscritical
788 ? SLAP_CRITICAL_CONTROL
789 : SLAP_NONCRITICAL_CONTROL;
795 #ifdef LDAP_CONTROL_NOREFERRALS
796 static int parseNoReferrals (
802 if ( op->o_noreferrals != SLAP_NO_CONTROL ) {
803 *text = "noreferrals control specified multiple times";
804 return LDAP_PROTOCOL_ERROR;
807 if ( ctrl->ldctl_value.bv_len ) {
808 *text = "noreferrals control value not empty";
809 return LDAP_PROTOCOL_ERROR;
812 op->o_noreferrals = ctrl->ldctl_iscritical
813 ? SLAP_CRITICAL_CONTROL
814 : SLAP_NONCRITICAL_CONTROL;
820 #ifdef LDAP_CLIENT_UPDATE
821 static int parseClientUpdate (
832 struct berval scheme = { 0, NULL };
833 struct berval cookie = { 0, NULL };
835 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
836 *text = "LCUP client update control specified multiple times";
837 return LDAP_PROTOCOL_ERROR;
841 if ( op->o_sync != SLAP_NO_CONTROL ) {
842 *text = "LDAP Client Update and Sync controls used together";
843 return LDAP_PROTOCOL_ERROR;
847 if ( ctrl->ldctl_value.bv_len == 0 ) {
848 *text = "LCUP client update control value is empty (or absent)";
849 return LDAP_PROTOCOL_ERROR;
852 /* Parse the control value
853 * ClientUpdateControlValue ::= SEQUENCE {
854 * updateType ENUMERATED {
855 * synchronizeOnly {0},
856 * synchronizeAndPersist {1},
858 * sendCookieInterval INTEGER OPTIONAL,
859 * cookie LCUPCookie OPTIONAL
863 ber = ber_init( &ctrl->ldctl_value );
865 *text = "internal error";
869 if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
870 *text = "LCUP client update control : decoding error";
871 return LDAP_PROTOCOL_ERROR;
875 case LDAP_CUP_SYNC_ONLY:
876 type = SLAP_LCUP_SYNC;
878 case LDAP_CUP_SYNC_AND_PERSIST:
879 type = SLAP_LCUP_SYNC_AND_PERSIST;
881 case LDAP_CUP_PERSIST_ONLY:
882 type = SLAP_LCUP_PERSIST;
885 *text = "LCUP client update control : unknown update type";
886 return LDAP_PROTOCOL_ERROR;
889 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
890 *text = "LCUP client update control : decoding error";
891 return LDAP_PROTOCOL_ERROR;
894 if ( tag == LDAP_TAG_INTERVAL ) {
895 if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
896 *text = "LCUP client update control : decoding error";
897 return LDAP_PROTOCOL_ERROR;
900 if ( interval <= 0 ) {
901 /* server chooses interval */
902 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
906 /* server chooses interval */
907 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
910 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
911 *text = "LCUP client update control : decoding error";
912 return LDAP_PROTOCOL_ERROR;
915 if ( tag == LDAP_LCUP_TAG_COOKIE ) {
916 if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
917 &scheme, &cookie )) == LBER_ERROR ) {
918 *text = "LCUP client update control : decoding error";
919 return LDAP_PROTOCOL_ERROR;
923 /* TODO : Cookie Scheme Validation */
925 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
926 *text = "Unsupported LCUP cookie scheme";
927 return LCUP_UNSUPPORTED_SCHEME;
930 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
931 *text = "Invalid LCUP cookie";
932 return LCUP_INVALID_COOKIE;
936 ber_dupbv( &op->o_clientupdate_state, &cookie );
938 (void) ber_free( ber, 1 );
940 op->o_clientupdate_type = (char) type;
941 op->o_clientupdate_interval = interval;
943 op->o_clientupdate = ctrl->ldctl_iscritical
944 ? SLAP_CRITICAL_CONTROL
945 : SLAP_NONCRITICAL_CONTROL;
952 static int parseLdupSync (
962 struct berval cookie = { 0, NULL };
964 if ( op->o_sync != SLAP_NO_CONTROL ) {
965 *text = "LDAP Sync control specified multiple times";
966 return LDAP_PROTOCOL_ERROR;
969 #ifdef LDAP_CLIENT_UPDATE
970 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
971 *text = "LDAP Sync and LDAP Client Update controls used together";
972 return LDAP_PROTOCOL_ERROR;
976 if ( ctrl->ldctl_value.bv_len == 0 ) {
977 *text = "LDAP Sync control value is empty (or absent)";
978 return LDAP_PROTOCOL_ERROR;
981 /* Parse the control value
982 * syncRequestValue ::= SEQUENCE {
987 * refreshAndPersist (3)
989 * cookie syncCookie OPTIONAL
993 ber = ber_init( &ctrl->ldctl_value );
995 *text = "internal error";
999 if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1000 *text = "LDAP Sync control : mode decoding error";
1001 return LDAP_PROTOCOL_ERROR;
1005 case LDAP_SYNC_REFRESH_ONLY:
1006 mode = SLAP_SYNC_REFRESH;
1008 case LDAP_SYNC_REFRESH_AND_PERSIST:
1009 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1012 *text = "LDAP Sync control : unknown update mode";
1013 return LDAP_PROTOCOL_ERROR;
1016 tag = ber_peek_tag( ber, &len );
1018 if ( tag == LDAP_SYNC_TAG_COOKIE ) {
1019 if (( ber_scanf( ber, /*{*/ "m}",
1020 &cookie )) == LBER_ERROR ) {
1021 *text = "LDAP Sync control : cookie decoding error";
1022 return LDAP_PROTOCOL_ERROR;
1025 if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1026 *text = "LDAP Sync control : decoding error";
1027 return LDAP_PROTOCOL_ERROR;
1030 cookie.bv_val = NULL;
1033 /* TODO : Cookie Scheme Validation */
1035 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1036 *text = "Unsupported LCUP cookie scheme";
1037 return LCUP_UNSUPPORTED_SCHEME;
1040 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1041 *text = "Invalid LCUP cookie";
1042 return LCUP_INVALID_COOKIE;
1046 ber_dupbv( &op->o_sync_state, &cookie );
1048 (void) ber_free( ber, 1 );
1050 op->o_sync_mode = (char) mode;
1052 op->o_sync = ctrl->ldctl_iscritical
1053 ? SLAP_CRITICAL_CONTROL
1054 : SLAP_NONCRITICAL_CONTROL;
1056 return LDAP_SUCCESS;