X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fcontrols.c;h=52fae3b09028f2797f8097eabb1568c08dc6cd23;hb=a5ee438c9394a19a241716d3d922299c20b0365d;hp=37361cb47cde7e2493b63fdea4aec6e0afb12cda;hpb=73276e84ae32e9e148197971d1d6729739980353;p=openldap diff --git a/servers/slapd/controls.c b/servers/slapd/controls.c index 37361cb47c..52fae3b090 100644 --- a/servers/slapd/controls.c +++ b/servers/slapd/controls.c @@ -1,5 +1,6 @@ +/* $OpenLDAP$ */ /* - * Copyright 1999 The OpenLDAP Foundation. + * Copyright 1999-2000 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms are permitted only @@ -10,6 +11,8 @@ #include "portable.h" #include + +#include #include #include "slap.h" @@ -18,6 +21,7 @@ char *supportedControls[] = { LDAP_CONTROL_MANAGEDSAIT, +/* LDAP_CONTROL_X_CHANGE_PASSWD, */ NULL }; @@ -26,7 +30,7 @@ int get_ctrls( Operation *op, int sendres ) { - int nctrls; + int nctrls = 0; ber_tag_t tag; ber_len_t len; char *opaque; @@ -40,26 +44,27 @@ int get_ctrls( if( len == 0) { /* no controls */ rc = LDAP_SUCCESS; - goto return_results; + return rc; } if(( tag = ber_peek_tag( ber, &len )) != LDAP_TAG_CONTROLS ) { if( tag == LBER_ERROR ) { - rc = -1; + rc = SLAPD_DISCONNECT; errmsg = "unexpected data in PDU"; } goto return_results; } + Debug( LDAP_DEBUG_TRACE, "=> get_ctrls\n", 0, 0, 0 ); + if( op->o_protocol < LDAP_VERSION3 ) { - rc = -1; + rc = SLAPD_DISCONNECT; errmsg = "controls require LDAPv3"; goto return_results; } /* set through each element */ - nctrls = 0; *ctrls = ch_malloc( 1 * sizeof(LDAPControl *) ); #if 0 @@ -70,7 +75,7 @@ int get_ctrls( } #endif - ctrls[nctrls] = NULL; + *ctrls[nctrls] = NULL; for( tag = ber_first_element( ber, &len, &opaque ); tag != LBER_ERROR; @@ -80,6 +85,8 @@ int get_ctrls( LDAPControl **tctrls; tctrl = ch_calloc( 1, sizeof(LDAPControl) ); + tctrl->ldctl_oid = NULL; + tctrl->ldctl_value.bv_val = NULL; /* allocate pointer space for current controls (nctrls) * + this control + extra NULL @@ -104,39 +111,58 @@ int get_ctrls( } #endif - tctrls[nctrls++] = tctrl; tctrls[nctrls] = NULL; tag = ber_scanf( ber, "{a" /*}*/, &tctrl->ldctl_oid ); - if( tag != LBER_ERROR ) { - tag = ber_peek_tag( ber, &len ); + if( tag == LBER_ERROR ) { + Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get oid failed.\n", + 0, 0, 0 ); + *ctrls = NULL; + ldap_controls_free( tctrls ); + rc = SLAPD_DISCONNECT; + errmsg = "decoding controls error"; + goto return_results; } + tag = ber_peek_tag( ber, &len ); + if( tag == LBER_BOOLEAN ) { ber_int_t crit; tag = ber_scanf( ber, "b", &crit ); - tctrl->ldctl_iscritical = crit ? (char) 0 : (char) ~0; - } - if( tag != LBER_ERROR ) { + if( tag == LBER_ERROR ) { + Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get crit failed.\n", + 0, 0, 0 ); + *ctrls = NULL; + ldap_controls_free( tctrls ); + rc = SLAPD_DISCONNECT; + errmsg = "decoding controls error"; + goto return_results; + } + + tctrl->ldctl_iscritical = (crit != 0); tag = ber_peek_tag( ber, &len ); } + Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: oid=\"%s\" (%scritical)\n", + tctrl->ldctl_oid, + tctrl->ldctl_iscritical ? "" : "non", + 0 ); + if( tag == LBER_OCTETSTRING ) { tag = ber_scanf( ber, "o", &tctrl->ldctl_value ); - } else { - tctrl->ldctl_value.bv_val = NULL; - } - - if( tag == LBER_ERROR ) { - *ctrls = NULL; - ldap_controls_free( tctrls ); - rc = -1; - errmsg = "decoding controls error"; - goto return_results; + if( tag == LBER_ERROR ) { + Debug( LDAP_DEBUG_TRACE, "=> get_ctrls: get value failed.\n", + 0, 0, 0 ); + *ctrls = NULL; + ldap_controls_free( tctrls ); + rc = SLAPD_DISCONNECT; + errmsg = "decoding controls error"; + goto return_results; + } } if( tctrl->ldctl_iscritical && @@ -151,8 +177,11 @@ int get_ctrls( } return_results: + Debug( LDAP_DEBUG_TRACE, "<= get_ctrls: %d %d %s\n", + nctrls, rc, errmsg ? errmsg : ""); + if( sendres && rc != LDAP_SUCCESS ) { - if( rc == -1 ) { + if( rc == SLAPD_DISCONNECT ) { send_ldap_disconnect( conn, op, rc, errmsg ); } else { send_ldap_result( conn, op, rc, @@ -180,4 +209,4 @@ int get_manageDSAit( Operation *op ) } return 0; -} \ No newline at end of file +}