]> git.sur5r.net Git - openldap/commitdiff
map attrs improvement
authorPierangelo Masarati <ando@openldap.org>
Sat, 5 Apr 2003 16:53:29 +0000 (16:53 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 5 Apr 2003 16:53:29 +0000 (16:53 +0000)
servers/slapd/back-ldap/back-ldap.h
servers/slapd/back-ldap/map.c
servers/slapd/back-ldap/search.c

index 77fdda68a27188958a9a00f31d06c71a55ded0bd..2436177c9bfb18adf1d3ec8918bc2cd2eb6912d5 100644 (file)
@@ -121,11 +121,13 @@ ldap_back_map_filter(
                struct berval *f,
                int remap
 );
-char **
+
+int
 ldap_back_map_attrs(
                struct ldapmap *at_map,
                AttributeName *a,
-               int remap
+               int remap,
+               char ***mapped_attrs
 );
 
 extern void mapping_free ( void *mapping );
index ff7a48b71dab81a76128d334d15eb302fd1d0f40..0896cc63422c8077a17c878ed6bf7768ecb5e119 100644 (file)
@@ -214,27 +214,32 @@ ldap_back_map_filter(
        return(nf);
 }
 
-char **
+int
 ldap_back_map_attrs(
                struct ldapmap *at_map,
                AttributeName *an,
-               int remap
+               int remap,
+               char ***mapped_attrs
 )
 {
        int i, j;
        char **na;
        struct berval mapped;
 
-       if (an == NULL)
-               return(NULL);
+       if (an == NULL) {
+               *mapped_attrs = NULL;
+               return LDAP_SUCCESS;
+       }
 
        for (i = 0; an[i].an_name.bv_val; i++) {
                /*  */
        }
 
        na = (char **)ch_calloc( i + 1, sizeof(char *) );
-       if (na == NULL)
-               return(NULL);
+       if (na == NULL) {
+               *mapped_attrs = NULL;
+               return LDAP_NO_MEMORY;
+       }
 
        for (i = j = 0; an[i].an_name.bv_val; i++) {
                ldap_back_map(at_map, &an[i].an_name, &mapped, remap);
@@ -245,7 +250,8 @@ ldap_back_map_attrs(
                na[j++] = LDAP_NO_ATTRS;
        na[j] = NULL;
 
-       return(na);
+       *mapped_attrs = na;
+       return LDAP_SUCCESS;
 }
 
 #ifdef ENABLE_REWRITE
index 92bd73c8a0d995ee7d3e065a3715799736a4e911..3bdaf1c2ad1e57831601752c1b76a4aea9d00fb7 100644 (file)
@@ -67,7 +67,7 @@ ldap_back_search(
        struct ldapconn *lc;
        struct timeval  tv;
        LDAPMessage             *res, *e;
-       int     count, rc = 0, msgid; 
+       int     rc = 0, msgid; 
        char *match = NULL;
        char **mapped_attrs = NULL;
        struct berval mbase;
@@ -107,7 +107,6 @@ ldap_back_search(
                /* positive hard limit means abort */
                } else if ( limit->lms_t_hard > 0 ) {
                        rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
-                       send_ldap_result( op, rs );
                        rc = 0;
                        goto finish;
                }
@@ -127,7 +126,6 @@ ldap_back_search(
                /* positive hard limit means abort */
                } else if ( limit->lms_s_hard > 0 ) {
                        rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
-                       send_ldap_result( op, rs );
                        rc = 0;
                        goto finish;
                }
@@ -168,14 +166,14 @@ ldap_back_search(
                break;
                
        case REWRITE_REGEXEC_UNWILLING:
-               send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
-                               "Operation not allowed" );
+               rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
+               rs->sr_text = "Operation not allowed";
                rc = -1;
                goto finish;
 
        case REWRITE_REGEXEC_ERR:
-               send_ldap_error( op, rs, LDAP_OTHER,
-                               "Rewrite error" );
+               rs->sr_err = LDAP_OTHER;
+               rs->sr_text = "Rewrite error";
                rc = -1;
                goto finish;
        }
@@ -194,12 +192,25 @@ ldap_back_search(
 #endif /* ! ENABLE_REWRITE */
 
        if ( rc ) {
+               rs->sr_err = LDAP_OTHER;
+               rs->sr_text = "Rewrite error";
                rc = -1;
                goto finish;
        }
 
-       mapped_attrs = ldap_back_map_attrs(&li->at_map, op->oq_search.rs_attrs, BACKLDAP_MAP);
+       rs->sr_err = ldap_back_map_attrs( &li->at_map, op->oq_search.rs_attrs,
+                       BACKLDAP_MAP, &mapped_attrs );
+       if ( rs->sr_err ) {
+               rc = -1;
+               goto finish;
+       }
+
+#if 0
        if ( mapped_attrs == NULL && op->oq_search.rs_attrs) {
+               int count;
+
+               /* this can happen only if ch_calloc() fails
+                * in ldap_back_map_attrs() */
                for (count=0; op->oq_search.rs_attrs[count].an_name.bv_val; count++);
                mapped_attrs = ch_malloc( (count+1) * sizeof(char *));
                for (count=0; op->oq_search.rs_attrs[count].an_name.bv_val; count++) {
@@ -207,10 +218,14 @@ ldap_back_search(
                }
                mapped_attrs[count] = NULL;
        }
+#endif
 
-       rs->sr_err = ldap_search_ext(lc->ld, mbase.bv_val, op->oq_search.rs_scope, mfilter.bv_val,
-                       mapped_attrs, op->oq_search.rs_attrsonly, op->o_ctrls, NULL, tv.tv_sec ? &tv
-                       : NULL, op->oq_search.rs_slimit, &msgid);
+       rs->sr_err = ldap_search_ext(lc->ld, mbase.bv_val,
+                       op->oq_search.rs_scope, mfilter.bv_val,
+                       mapped_attrs, op->oq_search.rs_attrsonly,
+                       op->o_ctrls, NULL,
+                       tv.tv_sec ? &tv : NULL, op->oq_search.rs_slimit,
+                       &msgid);
        if ( rs->sr_err != LDAP_SUCCESS ) {
 fail:;
                rc = ldap_back_op_result(lc, op, rs, msgid, 0);
@@ -361,9 +376,10 @@ fail:;
        if ( rs->sr_v2ref ) {
                rs->sr_err = LDAP_REFERRAL;
        }
-       send_ldap_result( op, rs );
 
 finish:;
+       send_ldap_result( op, rs );
+
        if ( match ) {
                if ( rs->sr_matched != match ) {
                        free( (char *)rs->sr_matched );