]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/slapacl.c
ITS#7588 fix double-free for sorted paged search
[openldap] / servers / slapd / slapacl.c
index d70c709c0066541b902f65ff6d53cbb89e6b50b8..c488518f9896edc7a9153c2b16d336c1699e7a55 100644 (file)
@@ -1,6 +1,7 @@
+/* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2004-2005 The OpenLDAP Foundation.
+ * Copyright 2004-2013 The OpenLDAP Foundation.
  * Portions Copyright 2004 Pierangelo Masarati.
  * All rights reserved.
  *
@@ -52,7 +53,8 @@ print_access(
                        desc->ad_cname.bv_val,
                        ( val && !BER_BVISNULL( val ) ) ? "=" : "",
                        ( val && !BER_BVISNULL( val ) ) ?
-                               ( desc == slap_schema.si_ad_userPassword ? "****" : val->bv_val ) : "",
+                               ( desc == slap_schema.si_ad_userPassword ?
+                                       "****" : val->bv_val ) : "",
                        accessmask2str( mask, accessmaskbuf, 1 ) );
 
        return rc;
@@ -65,12 +67,13 @@ slapacl( int argc, char **argv )
        const char              *progname = "slapacl";
        Connection              conn = { 0 };
        Listener                listener;
-       char                    opbuf[OPERATION_BUFFER_SIZE];
-       Operation               *op;
+       OperationBuffer opbuf;
+       Operation               *op = NULL;
        Entry                   e = { 0 }, *ep = &e;
        char                    *attr = NULL;
        int                     doclose = 0;
        BackendDB               *bd;
+       void                    *thrctx;
 
        slap_tool_init( progname, SLAPACL, argc, argv );
 
@@ -94,8 +97,10 @@ slapacl( int argc, char **argv )
        argv = &argv[ optind ];
        argc -= optind;
 
-       op = (Operation *)opbuf;
-       connection_fake_init( &conn, op, &conn );
+       thrctx = ldap_pvt_thread_pool_context();
+       connection_fake_init( &conn, &opbuf, thrctx );
+       op = &opbuf.ob_op;
+       op->o_tmpmemctx = NULL;
 
        conn.c_listener = &listener;
        conn.c_listener_url = listener_url;
@@ -222,9 +227,18 @@ slapacl( int argc, char **argv )
                op->o_bd = frontendDB;
        }
 
-       if ( !dryrun && be ) {
+       if ( !dryrun ) {
                ID      id;
 
+               if ( be == NULL ) {
+                       fprintf( stderr, "%s: no target database "
+                               "has been found for baseDN=\"%s\"; "
+                               "you may try with \"-u\" (dry run).\n",
+                               baseDN.bv_val, progname );
+                       rc = 1;
+                       goto destroy;
+               }
+
                if ( !be->be_entry_open ||
                        !be->be_entry_close ||
                        !be->be_dn2id_get ||
@@ -254,7 +268,8 @@ slapacl( int argc, char **argv )
                        rc = 1;
                        goto destroy;
                }
-               if ( be->be_id2entry_get( be, id, &ep ) != 0 ) {
+               ep = be->be_entry_get( be, id );
+               if ( ep == NULL ) {
                        fprintf( stderr, "%s: unable to fetch entry \"%s\" (%lu)\n",
                                progname, e.e_nname.bv_val, id );
                        rc = 1;
@@ -304,12 +319,29 @@ slapacl( int argc, char **argv )
 
                accessstr = strchr( attr, '/' );
                if ( accessstr != NULL ) {
+                       int     invalid = 0;
+
                        accessstr[0] = '\0';
                        accessstr++;
                        access = str2access( accessstr );
-                       if ( access == ACL_INVALID_ACCESS ) {
+                       switch ( access ) {
+                       case ACL_INVALID_ACCESS:
                                fprintf( stderr, "unknown access \"%s\" for attribute \"%s\"\n",
                                                accessstr, attr );
+                               invalid = 1;
+                               break;
+
+                       case ACL_NONE:
+                               fprintf( stderr, "\"none\" not allowed for attribute \"%s\"\n",
+                                               attr );
+                               invalid = 1;
+                               break;
+
+                       default:
+                               break;
+                       }
+
+                       if ( invalid ) {
                                if ( continuemode ) {
                                        continue;
                                }
@@ -357,7 +389,7 @@ destroy:;
                ber_memfree( e.e_nname.bv_val );
        }
        if ( !dryrun && be ) {
-               if ( ep != &e ) {
+               if ( ep && ep != &e ) {
                        be_entry_release_r( op, ep );
                }
                if ( doclose ) {
@@ -371,7 +403,8 @@ destroy:;
                }
        }
 
-       slap_tool_destroy();
+       if ( slap_tool_destroy())
+               rc = EXIT_FAILURE;
 
        return rc;
 }