]> git.sur5r.net Git - openldap/commitdiff
ITS#5560
authorQuanah Gibson-Mount <quanah@openldap.org>
Wed, 9 Jul 2008 02:29:56 +0000 (02:29 +0000)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 9 Jul 2008 02:29:56 +0000 (02:29 +0000)
CHANGES
build/version.var
clients/tools/common.c
include/ldap.h
libraries/libldap/Makefile.in
libraries/libldap/assertion.c [new file with mode: 0644]
libraries/libldap_r/Makefile.in

diff --git a/CHANGES b/CHANGES
index f947e62af8cfdb848f8eb2983183e3dfc1650cb5..8cb9a7377cc22196609efe3a157d4f0eea9edd41 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,7 @@
 OpenLDAP 2.4 Change Log
 
 OpenLDAP 2.4.11 Engineering
+       Added libldap assertion control (ITS#5560)
        Fixed slapd sets memory leak (ITS#5557)
        Fixed slapd-sock, back-shell buffer count (ITS#5558)
        Added slapo-nssov contrib module
index 346b51712049808274848f07236acf3fb169db0a..6da7ae62f7602901ee04da31a4c6a60c822291d5 100644 (file)
@@ -18,6 +18,6 @@ ol_minor=4
 ol_patch=X
 ol_api_inc=20410
 ol_api_current=2
-ol_api_revision=6
+ol_api_revision=7
 ol_api_age=0
 ol_release_date="2008/06/10"
index 16293de9c0f3a5ed5ef99dd21e8bf5273540235c..c5e3e9db4276beef720d281a832f5fad9a1d0035 100644 (file)
@@ -93,6 +93,7 @@ char          *sasl_secprops = NULL;
 /* controls */
 int            assertctl;
 char           *assertion = NULL;
+struct berval  assertionvalue = BER_BVNULL;
 char           *authzid = NULL;
 /* support deprecated early version of proxyAuthz */
 #define LDAP_CONTROL_OBSOLETE_PROXY_AUTHZ      "2.16.840.1.113730.3.4.12"
@@ -1485,29 +1486,18 @@ tool_server_controls( LDAP *ld, LDAPControl *extra_c, int count )
        }
 
        if ( assertctl ) {
-               BerElementBuffer berbuf;
-               BerElement *ber = (BerElement *)&berbuf;
-               
-               if( assertion == NULL || *assertion == '\0' ) {
-                       fprintf( stderr, "Assertion=<empty>\n" );
-                       exit( EXIT_FAILURE );
-               }
-
-               ber_init2( ber, NULL, LBER_USE_DER );
-
-               err = ldap_pvt_put_filter( ber, assertion );
-               if( err < 0 ) {
-                       fprintf( stderr, "assertion encode failed (%d)\n", err );
-                       exit( EXIT_FAILURE );
-               }
-
-               err = ber_flatten2( ber, &c[i].ldctl_value, 0 );
-               if( err < 0 ) {
-                       fprintf( stderr, "assertion flatten failed (%d)\n", err );
-                       exit( EXIT_FAILURE );
+               if ( BER_BVISNULL( &assertionvalue ) ) {
+                       err = ldap_create_assertion_control_value( ld,
+                               assertion, &assertionvalue );
+                       if ( err ) {
+                               fprintf( stderr,
+                                       "Unable to create assertion value "
+                                       "\"%s\" (%d)\n", assertion, err );
+                       }
                }
 
                c[i].ldctl_oid = LDAP_CONTROL_ASSERT;
+               c[i].ldctl_value = assertionvalue;
                c[i].ldctl_iscritical = assertctl > 1;
                ctrls[i] = &c[i];
                i++;
index db4500d6944c39dd9fb6f1d330bd71091e6ff38d..fe2934366bad92276523a07945c03efa0e5472d9 100644 (file)
@@ -2343,5 +2343,21 @@ ldap_parse_session_tracking_control LDAP_P((
 
 #endif /* LDAP_CONTROL_X_SESSION_TRACKING */
 
+/*
+ * in assertion.c
+ */
+LDAP_F (int)
+ldap_create_assertion_control_value LDAP_P((
+       LDAP            *ld,
+       char            *assertion,
+       struct berval   *value ));
+
+LDAP_F( int )
+ldap_create_assertion_control LDAP_P((
+       LDAP            *ld,
+       char            *filter,
+       int             iscritical,
+       LDAPControl     **ctrlp ));
+
 LDAP_END_DECL
 #endif /* _LDAP_H */
index 2f9e76f54745916d82316b0407d324c382194a29..e0d0aabe2c9c22357f2b77359b3c699950ead982 100644 (file)
@@ -26,7 +26,8 @@ SRCS  = bind.c open.c result.c error.c compare.c search.c \
        request.c os-ip.c url.c pagectrl.c sortctrl.c vlvctrl.c \
        init.c options.c print.c string.c util-int.c schema.c \
        charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
-       turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c
+       turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c \
+       assertion.c
 
 OBJS   = bind.lo open.lo result.lo error.lo compare.lo search.lo \
        controls.lo messages.lo references.lo extended.lo cyrus.lo \
@@ -37,7 +38,8 @@ OBJS  = bind.lo open.lo result.lo error.lo compare.lo search.lo \
        request.lo os-ip.lo url.lo pagectrl.lo sortctrl.lo vlvctrl.lo \
        init.lo options.lo print.lo string.lo util-int.lo schema.lo \
        charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
-       turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo
+       turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo \
+       assertion.lo
 
 LDAP_INCDIR= ../../include       
 LDAP_LIBDIR= ../../libraries
diff --git a/libraries/libldap/assertion.c b/libraries/libldap/assertion.c
new file mode 100644 (file)
index 0000000..2228998
--- /dev/null
@@ -0,0 +1,98 @@
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2008 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+
+#include "portable.h"
+
+#include <stdio.h>
+#include <ac/stdlib.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
+#include "ldap-int.h"
+
+int
+ldap_create_assertion_control_value(
+       LDAP            *ld,
+       char            *assertion,
+       struct berval   *value )
+{
+       BerElement              *ber = NULL;
+       int                     err;
+
+       if ( assertion == NULL || assertion[ 0 ] == '\0' ) {
+               ld->ld_errno = LDAP_PARAM_ERROR;
+               return ld->ld_errno;
+       }
+
+       if ( value == NULL ) {
+               ld->ld_errno = LDAP_PARAM_ERROR;
+               return ld->ld_errno;
+       }
+
+       BER_BVZERO( value );
+
+       ber = ldap_alloc_ber_with_options( ld );
+       if ( ber == NULL ) {
+               ld->ld_errno = LDAP_NO_MEMORY;
+               return ld->ld_errno;
+       }
+
+       err = ldap_pvt_put_filter( ber, assertion );
+       if ( err < 0 ) {
+               ld->ld_errno = LDAP_ENCODING_ERROR;
+               goto done;
+       }
+
+       err = ber_flatten2( ber, value, 1 );
+       if ( err < 0 ) {
+               ld->ld_errno = LDAP_NO_MEMORY;
+               goto done;
+       }
+
+done:;
+       if ( ber != NULL ) {
+               ber_free( ber, 1 );
+       }
+
+       return ld->ld_errno;
+}
+
+int
+ldap_create_assertion_control(
+       LDAP            *ld,
+       char            *assertion,
+       int             iscritical,
+       LDAPControl     **ctrlp )
+{
+       struct berval   value;
+
+       if ( ctrlp == NULL ) {
+               ld->ld_errno = LDAP_PARAM_ERROR;
+               return ld->ld_errno;
+       }
+
+       ld->ld_errno = ldap_create_assertion_control_value( ld,
+               assertion, &value );
+       if ( ld->ld_errno == LDAP_SUCCESS ) {
+               ld->ld_errno = ldap_control_create( LDAP_CONTROL_ASSERT,
+                       iscritical, &value, 0, ctrlp );
+               if ( ld->ld_errno != LDAP_SUCCESS ) {
+                       LDAP_FREE( value.bv_val );
+               }
+       }
+
+       return ld->ld_errno;
+}
+
index 9d6f91c12c3620b16e4ee059b01eda9d818cb780..03b99d419764327425b979e1026062eeab5655f3 100644 (file)
@@ -28,7 +28,8 @@ XXSRCS    = apitest.c test.c \
        request.c os-ip.c url.c pagectrl.c sortctrl.c vlvctrl.c \
        init.c options.c print.c string.c util-int.c schema.c \
        charray.c tls.c os-local.c dnssrv.c utf-8.c utf-8-conv.c \
-       turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c
+       turn.c ppolicy.c dds.c txn.c ldap_sync.c stctrl.c \
+       assertion.c
 SRCS   = threads.c rdwr.c rmutex.c tpool.c rq.c \
        thr_posix.c thr_cthreads.c thr_thr.c thr_lwp.c thr_nt.c \
        thr_pth.c thr_stub.c thr_debug.c
@@ -44,7 +45,8 @@ OBJS  = threads.lo rdwr.lo rmutex.lo tpool.lo  rq.lo \
        request.lo os-ip.lo url.lo pagectrl.lo sortctrl.lo vlvctrl.lo \
        init.lo options.lo print.lo string.lo util-int.lo schema.lo \
        charray.lo tls.lo os-local.lo dnssrv.lo utf-8.lo utf-8-conv.lo \
-       turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo
+       turn.lo ppolicy.lo dds.lo txn.lo ldap_sync.lo stctrl.lo \
+       assertion.lo
 
 LDAP_INCDIR= ../../include       
 LDAP_LIBDIR= ../../libraries