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 parsePermissiveModify;
53 static SLAP_CTRL_PARSE_FN parseDomainScope;
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,
74 * all known request control OIDs should be added to this list
76 char *slap_known_controls[] = {
77 LDAP_CONTROL_MANAGEDSAIT,
78 LDAP_CONTROL_PROXY_AUTHZ,
80 #ifdef LDAP_CONTROL_SUBENTRIES
81 LDAP_CONTROL_SUBENTRIES,
82 #endif /* LDAP_CONTROL_SUBENTRIES */
86 #ifdef LDAP_CONTROL_DUPENT_REQUEST
87 LDAP_CONTROL_DUPENT_REQUEST,
88 #endif /* LDAP_CONTROL_DUPENT_REQUEST */
90 #ifdef LDAP_CONTROL_PAGEDRESULTS
91 LDAP_CONTROL_PAGEDRESULTS,
94 #ifdef LDAP_CONTROL_SORTREQUEST
95 LDAP_CONTROL_SORTREQUEST,
96 #endif /* LDAP_CONTROL_SORTREQUEST */
98 #ifdef LDAP_CONTROL_VLVREQUEST
99 LDAP_CONTROL_VLVREQUEST,
100 #endif /* LDAP_CONTROL_VLVREQUEST */
102 LDAP_CONTROL_VALUESRETURNFILTER,
106 static struct slap_control {
109 char **sc_extendedops;
110 SLAP_CTRL_PARSE_FN *sc_parse;
112 } supportedControls[] = {
113 { LDAP_CONTROL_VALUESRETURNFILTER,
114 SLAP_CTRL_SEARCH, NULL,
115 parseValuesReturnFilter },
116 #ifdef LDAP_CONTROL_PAGEDRESULTS
117 { LDAP_CONTROL_PAGEDRESULTS,
118 SLAP_CTRL_SEARCH, NULL,
121 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
122 { LDAP_CONTROL_X_DOMAIN_SCOPE,
123 SLAP_CTRL_FRONTEND|SLAP_CTRL_SEARCH, NULL,
126 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
127 { LDAP_CONTROL_X_PERMISSIVE_MODIFY,
128 SLAP_CTRL_MODIFY, NULL,
129 parsePermissiveModify },
131 #ifdef LDAP_CONTROL_SUBENTRIES
132 { LDAP_CONTROL_SUBENTRIES,
133 SLAP_CTRL_SEARCH, NULL,
137 SLAP_CTRL_ACCESS, NULL,
139 #ifdef LDAP_CLIENT_UPDATE
140 { LDAP_CONTROL_CLIENT_UPDATE,
141 SLAP_CTRL_SEARCH, NULL,
146 SLAP_CTRL_SEARCH, NULL,
149 { LDAP_CONTROL_MANAGEDSAIT,
150 SLAP_CTRL_ACCESS, NULL,
152 { LDAP_CONTROL_PROXY_AUTHZ,
153 SLAP_CTRL_FRONTEND|SLAP_CTRL_ACCESS, proxy_authz_extops,
159 get_supported_ctrl(int index)
161 return supportedControls[index].sc_oid;
165 get_supported_ctrl_mask(int index)
167 return supportedControls[index].sc_mask;
170 static struct slap_control *
171 find_ctrl( const char *oid )
174 for( i=0; supportedControls[i].sc_oid; i++ ) {
175 if( strcmp( oid, supportedControls[i].sc_oid ) == 0 ) {
176 return &supportedControls[i];
191 BerElement *ber = op->o_ber;
192 struct slap_control *sc;
193 int rc = LDAP_SUCCESS;
194 const char *errmsg = NULL;
196 len = ber_pvt_ber_remaining(ber);
204 if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) {
205 if( tag == LBER_ERROR ) {
206 rc = SLAPD_DISCONNECT;
207 errmsg = "unexpected data in PDU";
214 LDAP_LOG( OPERATION, ENTRY,
215 "get_ctrls: conn %lu\n", conn->c_connid, 0, 0 );
217 Debug( LDAP_DEBUG_TRACE,
218 "=> get_ctrls\n", 0, 0, 0 );
221 if( op->o_protocol < LDAP_VERSION3 ) {
222 rc = SLAPD_DISCONNECT;
223 errmsg = "controls require LDAPv3";
227 /* one for first control, one for termination */
228 op->o_ctrls = ch_malloc( 2 * sizeof(LDAPControl *) );
231 if( op->ctrls == NULL ) {
233 errmsg = "no memory";
238 op->o_ctrls[nctrls] = NULL;
240 /* step through each element */
241 for( tag = ber_first_element( ber, &len, &opaque );
243 tag = ber_next_element( ber, &len, opaque ) )
246 LDAPControl **tctrls;
248 c = ch_calloc( 1, sizeof(LDAPControl) );
252 ldap_controls_free(op->o_ctrls);
256 errmsg = "no memory";
261 /* allocate pointer space for current controls (nctrls)
262 * + this control + extra NULL
264 tctrls = ch_realloc( op->o_ctrls,
265 (nctrls+2) * sizeof(LDAPControl *));
268 if( tctrls == NULL ) {
270 ldap_controls_free(op->o_ctrls);
274 errmsg = "no memory";
278 op->o_ctrls = tctrls;
280 op->o_ctrls[nctrls++] = c;
281 op->o_ctrls[nctrls] = NULL;
283 tag = ber_scanf( ber, "{a" /*}*/, &c->ldctl_oid );
285 if( tag == LBER_ERROR ) {
287 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu get OID failed.\n",
288 conn->c_connid, 0, 0 );
290 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n",
294 ldap_controls_free( op->o_ctrls );
296 rc = SLAPD_DISCONNECT;
297 errmsg = "decoding controls error";
300 } else if( c->ldctl_oid == NULL ) {
302 LDAP_LOG( OPERATION, INFO,
303 "get_ctrls: conn %lu got emtpy OID.\n",
304 conn->c_connid, 0, 0 );
306 Debug( LDAP_DEBUG_TRACE,
307 "get_ctrls: conn %lu got emtpy OID.\n",
308 conn->c_connid, 0, 0 );
311 ldap_controls_free( op->o_ctrls );
313 rc = LDAP_PROTOCOL_ERROR;
314 errmsg = "OID field is empty";
318 tag = ber_peek_tag( ber, &len );
320 if( tag == LBER_BOOLEAN ) {
322 tag = ber_scanf( ber, "b", &crit );
324 if( tag == LBER_ERROR ) {
326 LDAP_LOG( OPERATION, INFO,
327 "get_ctrls: conn %lu get crit failed.\n",
328 conn->c_connid, 0, 0 );
330 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n",
333 ldap_controls_free( op->o_ctrls );
335 rc = SLAPD_DISCONNECT;
336 errmsg = "decoding controls error";
340 c->ldctl_iscritical = (crit != 0);
341 tag = ber_peek_tag( ber, &len );
344 if( tag == LBER_OCTETSTRING ) {
345 tag = ber_scanf( ber, "o", &c->ldctl_value );
347 if( tag == LBER_ERROR ) {
349 LDAP_LOG( OPERATION, INFO, "get_ctrls: conn %lu: "
350 "%s (%scritical): get value failed.\n",
351 conn->c_connid, c->ldctl_oid,
352 c->ldctl_iscritical ? "" : "non" );
354 Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: conn %lu: "
355 "%s (%scritical): get value failed.\n",
356 conn->c_connid, c->ldctl_oid,
357 c->ldctl_iscritical ? "" : "non" );
359 ldap_controls_free( op->o_ctrls );
361 rc = SLAPD_DISCONNECT;
362 errmsg = "decoding controls error";
368 LDAP_LOG( OPERATION, INFO,
369 "get_ctrls: conn %lu oid=\"%s\" (%scritical)\n",
370 conn->c_connid, c->ldctl_oid, c->ldctl_iscritical ? "" : "non" );
372 Debug( LDAP_DEBUG_TRACE,
373 "=> get_ctrls: oid=\"%s\" (%scritical)\n",
374 c->ldctl_oid, c->ldctl_iscritical ? "" : "non", 0 );
377 sc = find_ctrl( c->ldctl_oid );
379 /* recognized control */
381 switch( op->o_tag ) {
383 tagmask = SLAP_CTRL_ADD;
386 tagmask = SLAP_CTRL_BIND;
388 case LDAP_REQ_COMPARE:
389 tagmask = SLAP_CTRL_COMPARE;
391 case LDAP_REQ_DELETE:
392 tagmask = SLAP_CTRL_DELETE;
394 case LDAP_REQ_MODIFY:
395 tagmask = SLAP_CTRL_MODIFY;
397 case LDAP_REQ_RENAME:
398 tagmask = SLAP_CTRL_RENAME;
400 case LDAP_REQ_SEARCH:
401 tagmask = SLAP_CTRL_SEARCH;
403 case LDAP_REQ_UNBIND:
404 tagmask = SLAP_CTRL_UNBIND;
406 case LDAP_REQ_ABANDON:
407 tagmask = SLAP_CTRL_ABANDON;
409 case LDAP_REQ_EXTENDED:
411 assert( op->o_extendedop != NULL );
412 if( sc->sc_extendedops != NULL ) {
414 for( i=0; sc->sc_extendedops[i] != NULL; i++ ) {
415 if( strcmp( op->o_extendedop, sc->sc_extendedops[i] )
426 errmsg = "controls internal error";
430 if (( sc->sc_mask & tagmask ) == tagmask ) {
431 /* available extension */
433 if( !sc->sc_parse ) {
435 errmsg = "not yet implemented";
439 rc = sc->sc_parse( conn, op, c, &errmsg );
441 if( rc != LDAP_SUCCESS ) goto return_results;
443 if ( sc->sc_mask & SLAP_CTRL_FRONTEND ) {
444 /* kludge to disable backend_control() check */
445 c->ldctl_iscritical = 0;
447 } else if ( tagmask == SLAP_CTRL_SEARCH &&
448 sc->sc_mask & SLAP_CTRL_FRONTEND_SEARCH )
450 /* kludge to disable backend_control() check */
451 c->ldctl_iscritical = 0;
454 } else if( c->ldctl_iscritical ) {
455 /* unavailable CRITICAL control */
456 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
457 errmsg = "critical extension is unavailable";
461 } else if( c->ldctl_iscritical ) {
462 /* unrecognized CRITICAL control */
463 rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
464 errmsg = "critical extension is not recognized";
471 LDAP_LOG( OPERATION, RESULTS,
472 "get_ctrls: n=%d rc=%d err=\"%s\"\n",
473 nctrls, rc, errmsg ? errmsg : "" );
475 Debug( LDAP_DEBUG_TRACE,
476 "<= get_ctrls: n=%d rc=%d err=\"%s\"\n",
477 nctrls, rc, errmsg ? errmsg : "");
480 if( sendres && rc != LDAP_SUCCESS ) {
481 if( rc == SLAPD_DISCONNECT ) {
482 send_ldap_disconnect( conn, op, LDAP_PROTOCOL_ERROR, errmsg );
484 send_ldap_result( conn, op, rc,
485 NULL, errmsg, NULL, NULL );
492 static int parseManageDSAit (
498 if ( op->o_managedsait != SLAP_NO_CONTROL ) {
499 *text = "manageDSAit control specified multiple times";
500 return LDAP_PROTOCOL_ERROR;
503 if ( ctrl->ldctl_value.bv_len ) {
504 *text = "manageDSAit control value not empty";
505 return LDAP_PROTOCOL_ERROR;
508 op->o_managedsait = ctrl->ldctl_iscritical
509 ? SLAP_CRITICAL_CONTROL
510 : SLAP_NONCRITICAL_CONTROL;
515 static int parseProxyAuthz (
522 struct berval dn = { 0, NULL };
524 if ( op->o_proxy_authz != SLAP_NO_CONTROL ) {
525 *text = "proxy authorization control specified multiple times";
526 return LDAP_PROTOCOL_ERROR;
529 op->o_proxy_authz = ctrl->ldctl_iscritical
530 ? SLAP_CRITICAL_CONTROL
531 : SLAP_NONCRITICAL_CONTROL;
534 LDAP_LOG( OPERATION, ARGS,
535 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
537 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
540 Debug( LDAP_DEBUG_ARGS,
541 "parseProxyAuthz: conn %lu authzid=\"%s\"\n",
543 ctrl->ldctl_value.bv_len ? ctrl->ldctl_value.bv_val : "anonymous",
547 if( ctrl->ldctl_value.bv_len == 0 ) {
549 LDAP_LOG( OPERATION, RESULTS,
550 "parseProxyAuthz: conn=%lu anonymous\n",
551 conn->c_connid, 0, 0 );
553 Debug( LDAP_DEBUG_TRACE,
554 "parseProxyAuthz: conn=%lu anonymous\n",
555 conn->c_connid, 0, 0 );
559 free( op->o_dn.bv_val );
561 op->o_dn.bv_val = ch_strdup( "" );
563 free( op->o_ndn.bv_val );
564 op->o_ndn.bv_len = 0;
565 op->o_ndn.bv_val = ch_strdup( "" );
570 rc = slap_sasl_getdn( conn,
571 ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len,
572 NULL, &dn, SLAP_GETDN_AUTHZID );
574 if( rc != LDAP_SUCCESS || !dn.bv_len ) {
576 ch_free( dn.bv_val );
578 *text = "authzId mapping failed";
579 return LDAP_PROXY_AUTHZ_FAILURE;
583 LDAP_LOG( OPERATION, RESULTS,
584 "parseProxyAuthz: conn=%lu \"%s\"\n",
586 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
588 Debug( LDAP_DEBUG_TRACE,
589 "parseProxyAuthz: conn=%lu \"%s\"\n",
591 dn.bv_len ? dn.bv_val : "(NULL)", 0 );
594 rc = slap_sasl_authorized( conn, &op->o_ndn, &dn );
597 ch_free( dn.bv_val );
598 *text = "not authorized to assume identity";
599 return LDAP_PROXY_AUTHZ_FAILURE;
602 ch_free( op->o_dn.bv_val );
603 ch_free( op->o_ndn.bv_val );
605 op->o_dn.bv_val = NULL;
609 * NOTE: since slap_sasl_getdn() returns a normalized dn,
610 * from now on op->o_dn is normalized
612 ber_dupbv( &op->o_dn, &dn );
617 static int parseNoOp (
623 if ( op->o_noop != SLAP_NO_CONTROL ) {
624 *text = "noop control specified multiple times";
625 return LDAP_PROTOCOL_ERROR;
628 if ( ctrl->ldctl_value.bv_len ) {
629 *text = "noop control value not empty";
630 return LDAP_PROTOCOL_ERROR;
633 op->o_noop = ctrl->ldctl_iscritical
634 ? SLAP_CRITICAL_CONTROL
635 : SLAP_NONCRITICAL_CONTROL;
640 #ifdef LDAP_CONTROL_PAGEDRESULTS
641 static int parsePagedResults (
650 struct berval cookie = { 0, NULL };
652 if ( op->o_pagedresults != SLAP_NO_CONTROL ) {
653 *text = "paged results control specified multiple times";
654 return LDAP_PROTOCOL_ERROR;
657 if ( ctrl->ldctl_value.bv_len == 0 ) {
658 *text = "paged results control value is empty (or absent)";
659 return LDAP_PROTOCOL_ERROR;
662 /* Parse the control value
663 * realSearchControlValue ::= SEQUENCE {
664 * size INTEGER (0..maxInt),
665 * -- requested page size from client
666 * -- result set size estimate from server
667 * cookie OCTET STRING
670 ber = ber_init( &ctrl->ldctl_value );
672 *text = "internal error";
676 tag = ber_scanf( ber, "{im}", &size, &cookie );
677 (void) ber_free( ber, 1 );
679 if( tag == LBER_ERROR ) {
680 *text = "paged results control could not be decoded";
681 return LDAP_PROTOCOL_ERROR;
685 *text = "paged results control size invalid";
686 return LDAP_PROTOCOL_ERROR;
689 if( cookie.bv_len ) {
690 PagedResultsCookie reqcookie;
691 if( cookie.bv_len != sizeof( reqcookie ) ) {
693 *text = "paged results cookie is invalid";
694 return LDAP_PROTOCOL_ERROR;
697 AC_MEMCPY( &reqcookie, cookie.bv_val, sizeof( reqcookie ));
699 if( reqcookie > op->o_pagedresults_state.ps_cookie ) {
701 *text = "paged results cookie is invalid";
702 return LDAP_PROTOCOL_ERROR;
704 } else if( reqcookie < op->o_pagedresults_state.ps_cookie ) {
705 *text = "paged results cookie is invalid or old";
706 return LDAP_UNWILLING_TO_PERFORM;
709 /* Initial request. Initialize state. */
710 op->o_pagedresults_state.ps_cookie = 0;
711 op->o_pagedresults_state.ps_id = NOID;
714 op->o_pagedresults_size = size;
716 op->o_pagedresults = ctrl->ldctl_iscritical
717 ? SLAP_CRITICAL_CONTROL
718 : SLAP_NONCRITICAL_CONTROL;
724 int parseValuesReturnFilter (
732 struct berval fstr = { 0, NULL };
733 const char *err_msg = "";
735 if ( op->o_valuesreturnfilter != SLAP_NO_CONTROL ) {
736 *text = "valuesReturnFilter control specified multiple times";
737 return LDAP_PROTOCOL_ERROR;
740 if ( ctrl->ldctl_value.bv_len == 0 ) {
741 *text = "valuesReturnFilter control value is empty (or absent)";
742 return LDAP_PROTOCOL_ERROR;
745 ber = ber_init( &(ctrl->ldctl_value) );
747 *text = "internal error";
751 rc = get_vrFilter( conn, ber, &(op->vrFilter), &err_msg);
753 if( rc != LDAP_SUCCESS ) {
755 if( rc == SLAPD_DISCONNECT ) {
756 send_ldap_disconnect( conn, op,
757 LDAP_PROTOCOL_ERROR, *text );
759 send_ldap_result( conn, op, rc,
760 NULL, *text, NULL, NULL );
762 if( fstr.bv_val != NULL) free( fstr.bv_val );
763 if( op->vrFilter != NULL) vrFilter_free( op->vrFilter );
766 vrFilter2bv( op->vrFilter, &fstr );
770 LDAP_LOG( OPERATION, ARGS,
771 "parseValuesReturnFilter: conn %d vrFilter: %s\n",
772 conn->c_connid, fstr.bv_len ? fstr.bv_val : "empty" , 0 );
774 Debug( LDAP_DEBUG_ARGS, " vrFilter: %s\n",
775 fstr.bv_len ? fstr.bv_val : "empty", 0, 0 );
778 op->o_valuesreturnfilter = ctrl->ldctl_iscritical
779 ? SLAP_CRITICAL_CONTROL
780 : SLAP_NONCRITICAL_CONTROL;
785 #ifdef LDAP_CONTROL_SUBENTRIES
786 static int parseSubentries (
792 if ( op->o_subentries != SLAP_NO_CONTROL ) {
793 *text = "subentries control specified multiple times";
794 return LDAP_PROTOCOL_ERROR;
797 /* FIXME: should use BER library */
798 if( ( ctrl->ldctl_value.bv_len != 3 )
799 && ( ctrl->ldctl_value.bv_val[0] != 0x01 )
800 && ( ctrl->ldctl_value.bv_val[1] != 0x01 ))
802 *text = "subentries control value encoding is bogus";
803 return LDAP_PROTOCOL_ERROR;
806 op->o_subentries = ctrl->ldctl_iscritical
807 ? SLAP_CRITICAL_CONTROL
808 : SLAP_NONCRITICAL_CONTROL;
810 op->o_subentries_visibility = (ctrl->ldctl_value.bv_val[2] != 0x00);
816 #ifdef LDAP_CONTROL_X_PERMISSIVE_MODIFY
817 static int parsePermissiveModify (
823 if ( op->o_permissive_modify != SLAP_NO_CONTROL ) {
824 *text = "permissiveModify control specified multiple times";
825 return LDAP_PROTOCOL_ERROR;
828 if ( ctrl->ldctl_value.bv_len ) {
829 *text = "permissiveModify control value not empty";
830 return LDAP_PROTOCOL_ERROR;
833 op->o_permissive_modify = ctrl->ldctl_iscritical
834 ? SLAP_CRITICAL_CONTROL
835 : SLAP_NONCRITICAL_CONTROL;
841 #ifdef LDAP_CONTROL_X_DOMAIN_SCOPE
842 static int parseDomainScope (
848 if ( op->o_domain_scope != SLAP_NO_CONTROL ) {
849 *text = "domainScope control specified multiple times";
850 return LDAP_PROTOCOL_ERROR;
853 if ( ctrl->ldctl_value.bv_len ) {
854 *text = "domainScope control value not empty";
855 return LDAP_PROTOCOL_ERROR;
858 op->o_domain_scope = ctrl->ldctl_iscritical
859 ? SLAP_CRITICAL_CONTROL
860 : SLAP_NONCRITICAL_CONTROL;
866 #ifdef LDAP_CLIENT_UPDATE
867 static int parseClientUpdate (
878 struct berval scheme = { 0, NULL };
879 struct berval cookie = { 0, NULL };
881 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
882 *text = "LCUP client update control specified multiple times";
883 return LDAP_PROTOCOL_ERROR;
887 if ( op->o_sync != SLAP_NO_CONTROL ) {
888 *text = "LDAP Client Update and Sync controls used together";
889 return LDAP_PROTOCOL_ERROR;
893 if ( ctrl->ldctl_value.bv_len == 0 ) {
894 *text = "LCUP client update control value is empty (or absent)";
895 return LDAP_PROTOCOL_ERROR;
898 /* Parse the control value
899 * ClientUpdateControlValue ::= SEQUENCE {
900 * updateType ENUMERATED {
901 * synchronizeOnly {0},
902 * synchronizeAndPersist {1},
904 * sendCookieInterval INTEGER OPTIONAL,
905 * cookie LCUPCookie OPTIONAL
909 ber = ber_init( &ctrl->ldctl_value );
911 *text = "internal error";
915 if ( (tag = ber_scanf( ber, "{i" /*}*/, &type )) == LBER_ERROR ) {
916 *text = "LCUP client update control : decoding error";
917 return LDAP_PROTOCOL_ERROR;
921 case LDAP_CUP_SYNC_ONLY:
922 type = SLAP_LCUP_SYNC;
924 case LDAP_CUP_SYNC_AND_PERSIST:
925 type = SLAP_LCUP_SYNC_AND_PERSIST;
927 case LDAP_CUP_PERSIST_ONLY:
928 type = SLAP_LCUP_PERSIST;
931 *text = "LCUP client update control : unknown update type";
932 return LDAP_PROTOCOL_ERROR;
935 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
936 *text = "LCUP client update control : decoding error";
937 return LDAP_PROTOCOL_ERROR;
940 if ( tag == LDAP_CUP_TAG_INTERVAL ) {
941 if ( (tag = ber_scanf( ber, "i", &interval )) == LBER_ERROR ) {
942 *text = "LCUP client update control : decoding error";
943 return LDAP_PROTOCOL_ERROR;
946 if ( interval <= 0 ) {
947 /* server chooses interval */
948 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
952 /* server chooses interval */
953 interval = LDAP_CUP_DEFAULT_SEND_COOKIE_INTERVAL;
956 if ( (tag = ber_peek_tag( ber, &len )) == LBER_DEFAULT ) {
957 *text = "LCUP client update control : decoding error";
958 return LDAP_PROTOCOL_ERROR;
961 if ( tag == LDAP_CUP_TAG_COOKIE ) {
962 if ( (tag = ber_scanf( ber, /*{*/ "{mm}}",
963 &scheme, &cookie )) == LBER_ERROR )
965 *text = "LCUP client update control : decoding error";
966 return LDAP_PROTOCOL_ERROR;
970 /* TODO : Cookie Scheme Validation */
972 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
973 *text = "Unsupported LCUP cookie scheme";
974 return LCUP_UNSUPPORTED_SCHEME;
977 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
978 *text = "Invalid LCUP cookie";
979 return LCUP_INVALID_COOKIE;
983 ber_dupbv( &op->o_clientupdate_state, &cookie );
985 (void) ber_free( ber, 1 );
987 op->o_clientupdate_type = (char) type;
988 op->o_clientupdate_interval = interval;
990 op->o_clientupdate = ctrl->ldctl_iscritical
991 ? SLAP_CRITICAL_CONTROL
992 : SLAP_NONCRITICAL_CONTROL;
999 static int parseLdupSync (
1009 struct berval cookie = { 0, NULL };
1011 if ( op->o_sync != SLAP_NO_CONTROL ) {
1012 *text = "LDAP Sync control specified multiple times";
1013 return LDAP_PROTOCOL_ERROR;
1016 #ifdef LDAP_CLIENT_UPDATE
1017 if ( op->o_clientupdate != SLAP_NO_CONTROL ) {
1018 *text = "LDAP Sync and LDAP Client Update controls used together";
1019 return LDAP_PROTOCOL_ERROR;
1023 if ( ctrl->ldctl_value.bv_len == 0 ) {
1024 *text = "LDAP Sync control value is empty (or absent)";
1025 return LDAP_PROTOCOL_ERROR;
1028 /* Parse the control value
1029 * syncRequestValue ::= SEQUENCE {
1034 * refreshAndPersist (3)
1036 * cookie syncCookie OPTIONAL
1040 ber = ber_init( &ctrl->ldctl_value );
1042 *text = "internal error";
1046 if ( (tag = ber_scanf( ber, "{i" /*}*/, &mode )) == LBER_ERROR ) {
1047 *text = "LDAP Sync control : mode decoding error";
1048 return LDAP_PROTOCOL_ERROR;
1052 case LDAP_SYNC_REFRESH_ONLY:
1053 mode = SLAP_SYNC_REFRESH;
1055 case LDAP_SYNC_REFRESH_AND_PERSIST:
1056 mode = SLAP_SYNC_REFRESH_AND_PERSIST;
1059 *text = "LDAP Sync control : unknown update mode";
1060 return LDAP_PROTOCOL_ERROR;
1063 tag = ber_peek_tag( ber, &len );
1065 if ( tag == LDAP_SYNC_TAG_COOKIE ) {
1066 if (( ber_scanf( ber, /*{*/ "m}",
1067 &cookie )) == LBER_ERROR ) {
1068 *text = "LDAP Sync control : cookie decoding error";
1069 return LDAP_PROTOCOL_ERROR;
1072 if (( ber_scanf( ber, /*{*/ "}")) == LBER_ERROR ) {
1073 *text = "LDAP Sync control : decoding error";
1074 return LDAP_PROTOCOL_ERROR;
1077 cookie.bv_val = NULL;
1080 /* TODO : Cookie Scheme Validation */
1082 if ( lcup_cookie_scheme_validate(scheme) != LDAP_SUCCESS ) {
1083 *text = "Unsupported LCUP cookie scheme";
1084 return LCUP_UNSUPPORTED_SCHEME;
1087 if ( lcup_cookie_validate(scheme, cookie) != LDAP_SUCCESS ) {
1088 *text = "Invalid LCUP cookie";
1089 return LCUP_INVALID_COOKIE;
1093 ber_dupbv( &op->o_sync_state, &cookie );
1095 (void) ber_free( ber, 1 );
1097 op->o_sync_mode = (char) mode;
1099 op->o_sync = ctrl->ldctl_iscritical
1100 ? SLAP_CRITICAL_CONTROL
1101 : SLAP_NONCRITICAL_CONTROL;
1103 return LDAP_SUCCESS;