]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-meta/cache-search.c
Fix prev commit, return generated passwd
[openldap] / servers / slapd / back-meta / cache-search.c
index 97230dfc94cb7af67e38b42a800e2e647ed9b908..e31b1c18119838fe2c091a72c027385fd4eca6fd 100644 (file)
@@ -1,22 +1,25 @@
-/*
- * Copyright (c) 2003 by International Business Machines, Inc.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * International Business Machines, Inc. (hereinafter called IBM) grants
- * permission under its copyrights to use, copy, modify, and distribute this
- * Software with or without fee, provided that the above copyright notice and
- * all paragraphs of this notice appear in all copies, and that the name of IBM
- * not be used in connection with the marketing of any product incorporating
- * the Software or modifications thereof, without specific, written prior
- * permission.
+ * Copyright 1999-2003 The OpenLDAP Foundation.
+ * Portions Copyright 2003 IBM Corporation.
+ * All rights reserved.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
- * PARTICULAR PURPOSE.  IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
- * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
- * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * 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>.
+ */
+/* ACKNOWLEDGEMENTS:
+ * This work was initially developed by the Howard Chu for inclusion
+ * in OpenLDAP Software and subsequently enhanced by Pierangelo
+ * Masarati and Apurva Kumar.
+ */
+/* This is an altered version */
+/*
  * This software is based on the backends back-ldap and back-meta, implemented
  * by Howard Chu <hyc@highlandsun.com>, Mark Valence
  * <kurash@sassafras.com>, Pierangelo Masarati <ando@sys-net.it> and other
 #include "ldap_log.h"
 #include "../../../libraries/libldap/ldap-int.h"
 
-#ifdef LDAP_CACHING 
 static Entry* 
 meta_create_entry(
        Backend         *be,
@@ -274,8 +276,8 @@ meta_back_cache_search(
        int             num_entries = 0;
        int             curr_limit;
        int             fattr_cnt=0; 
+       int             oc_attr_absent = 1;
 
-   
        struct exception result[1]; 
 
        Filter* filter = str2filter(op->ors_filterstr.bv_val); 
@@ -284,10 +286,12 @@ meta_back_cache_search(
        cb.sc_private = op->o_bd; 
 
        if (op->ors_attrs) {
-               for ( count=0; op->ors_attrs[ count ].an_name.bv_val; count++ )
-                       ;
-               attrs = (AttributeName*)malloc( ( count + 1 ) *
-                                               sizeof(AttributeName));
+               for ( count=0; op->ors_attrs[ count ].an_name.bv_val; count++ ) {
+                       if ( op->ors_attrs[count].an_desc == slap_schema.si_ad_objectClass )
+                               oc_attr_absent = 0;
+               }
+               attrs = (AttributeName*)malloc( ( count + 1 + oc_attr_absent )
+                                                               *sizeof(AttributeName));
                for ( count=0; op->ors_attrs[ count ].an_name.bv_val; count++ ) {
                        ber_dupbv(&attrs[ count ].an_name,
                                                &op->ors_attrs[ count ].an_name);
@@ -297,7 +301,6 @@ meta_back_cache_search(
                attrs[ count ].an_name.bv_len = 0;
        }
 
-
        result->type = SUCCESS; 
        result->rc = 0; 
        ldap_pvt_thread_mutex_lock(&cm->cache_mutex); 
@@ -364,6 +367,15 @@ meta_back_cache_search(
                }
        }
 
+       if ( attrs && oc_attr_absent ) {
+               for ( count = 0; attrs[count].an_name.bv_val; count++) ;
+               attrs[ count ].an_name.bv_val = "objectClass";
+               attrs[ count ].an_name.bv_len = strlen( "objectClass" );
+               attrs[ count ].an_desc = slap_schema.si_ad_objectClass;
+               attrs[ count + 1 ].an_name.bv_val = NULL;
+               attrs[ count + 1 ].an_name.bv_len = 0;
+       }
+
        if (answerable) {
                Operation       op_tmp;
 
@@ -394,7 +406,6 @@ meta_back_cache_search(
                op_tmp.o_req_dn = cachebase;
                op_tmp.o_req_ndn = ncachebase;
 
-               op_tmp.o_caching_on = 1; 
                op_tmp.o_callback = &cb; 
 
                li->glue_be->be_search(&op_tmp, rs);
@@ -614,7 +625,7 @@ meta_back_cache_search(
                         */
                        msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
                                                mapped_filter, mapped_attrs,
-                                               op->ors_attrsonly ); 
+                                               op->ors_attrsonly );
 
                        if ( msgid[ i ] == -1 ) {
                                result->type = CONN_ERR; 
@@ -660,8 +671,7 @@ meta_back_cache_search(
                        Debug( LDAP_DEBUG_ANY, "QUERY CACHEABLE\n", 0, 0, 0 );
 #endif /* !NEW_LOGGING */
                        op_tmp.o_bd = li->glue_be;
-                       uuid = cache_entries(&op_tmp, rs, entry_array,
-                                       cm, result); 
+                       uuid = cache_entries(&op_tmp, rs, entry_array, cm, result); 
 #ifdef NEW_LOGGING
                        LDAP_LOG( BACK_META, DETAIL1,
                                        "Added query %s UUID %s ENTRIES %d\n",
@@ -681,6 +691,19 @@ meta_back_cache_search(
                                goto Catch; 
                        filter = 0; 
                        attrs = 0; 
+
+                       /* FIXME : launch do_syncrepl() threads around here
+                        *
+                        * entryUUID and entryCSN need also to be requested by :
+                        */
+                       /*
+                       msgid[ i ] = ldap_search( lsc->ld, mbase, realscope,
+                                               mapped_filter, mapped_attrs, op->ors_attrsonly );
+                       */
+                       /* Also, mbase, realscope, mapped_filter, mapped_attrs need
+                        * be managed as arrays. Each element needs to be retained by this point.
+                        */
+
                } else {
 #ifdef NEW_LOGGING
                        LDAP_LOG( BACK_META, DETAIL1,
@@ -824,11 +847,15 @@ meta_create_entry (
        struct berval           a, mapped;
        Entry*                  ent;
        BerElement              ber = *e->lm_ber;
-       Attribute               *attr, **attrp;
-       struct berval           dummy = { 0, NULL };
-       struct berval           *bv, bdn;
-       const char              *text;
-        char*                  ename = NULL; 
+       Attribute               *attr, *soc_attr, **attrp;
+       struct berval   dummy = { 0, NULL };
+       struct berval   *bv, bdn;
+       const char              *text = NULL;
+       char*                   ename = NULL; 
+       struct berval   sc = { 0, NULL };
+       char                    textbuf[SLAP_TEXT_BUFLEN];
+       size_t                  textlen = sizeof(textbuf);
+
        if ( ber_scanf( &ber, "{m{", &bdn ) == LBER_ERROR ) {
                result->type = CREATE_ENTRY_ERR;        
                return NULL; 
@@ -930,9 +957,13 @@ meta_create_entry (
                if ( ber_scanf( &ber, "[W]", &attr->a_vals ) == LBER_ERROR 
                                || attr->a_vals == NULL ) {
                        attr->a_vals = &dummy;
+#if 0
                } else if ( attr->a_desc == slap_schema.si_ad_objectClass ||
                                attr->a_desc ==
                                slap_schema.si_ad_structuralObjectClass) {
+#else
+               } else if ( attr->a_desc == slap_schema.si_ad_objectClass ) {
+#endif
                        int i, last;
                        for ( last = 0; attr->a_vals[ last ].bv_val; ++last )
                                ;
@@ -953,6 +984,22 @@ meta_create_entry (
                                        ber_dupbv( bv, &mapped );
                                }
                        }
+
+                       structural_class( attr->a_vals, &sc, NULL, &text, textbuf, textlen );
+                       soc_attr = (Attribute*) ch_malloc( sizeof( Attribute ));
+                       soc_attr->a_desc = slap_schema.si_ad_structuralObjectClass;
+                       soc_attr->a_vals = (BerVarray) ch_malloc( 2* sizeof( BerValue ));
+                       ber_dupbv( &soc_attr->a_vals[0], &sc );
+                       soc_attr->a_vals[1].bv_len = 0;
+                       soc_attr->a_vals[1].bv_val = NULL;
+                       soc_attr->a_nvals = (BerVarray) ch_malloc( 2* sizeof( BerValue ));
+                       ber_dupbv( &soc_attr->a_nvals[0], &sc );
+                       soc_attr->a_nvals[1].bv_len = 0;
+                       soc_attr->a_nvals[1].bv_val = NULL;
+
+                       *attrp = soc_attr;
+                       attrp = &soc_attr->a_next;
+
                /*
                 * It is necessary to try to rewrite attributes with
                 * dn syntax because they might be used in ACLs as
@@ -1004,6 +1051,7 @@ meta_create_entry (
                *attrp = attr;
                attrp = &attr->a_next;
        }
+
        return ent; 
 }
 
@@ -1787,11 +1835,13 @@ cache_back_sentry(
                rs->sr_entry->e_nname = ndn; 
 
                op->o_callback = cb; 
-               return 0; 
+               return LDAP_SUCCESS; 
+
        } else if (rs->sr_type == REP_RESULT) { 
                op->o_callback = NULL; 
                send_ldap_result( op, rs ); 
-               return 0
+               return LDAP_SUCCESS
        }
+
+       return LDAP_SUCCESS;
 }
-#endif