]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/result.c
ACIs from Mark Valence <kurash@sassafras.com> (ITS#261)
[openldap] / servers / slapd / result.c
index 4f2848e8dee7ef9a2f45f0944869a7c259f41367..9ec57f76264ae8b77beca8cf0f3ede3fef115710 100644 (file)
@@ -8,6 +8,7 @@
 #include <ac/errno.h>
 #include <ac/signal.h>
 #include <ac/string.h>
+#include <ac/ctype.h>
 #include <ac/time.h>
 #include <ac/unistd.h>
 
@@ -183,7 +184,7 @@ static long send_ldap_ber(
                 * it's a hard error and return.
                 */
 
-               Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno %d msg (%s)\n",
+               Debug( LDAP_DEBUG_CONNS, "ber_flush failed errno=%d reason=\"%s\"\n",
                    err, err > -1 && err < sys_nerr ? sys_errlist[err]
                    : "unknown", 0 );
 
@@ -216,10 +217,10 @@ send_ldap_response(
        ber_tag_t       tag,
        ber_int_t       msgid,
     ber_int_t  err,
-    char       *matched,
-    char       *text,
+    const char *matched,
+    const char *text,
        struct berval   **ref,
-       char    *resoid,
+       const char      *resoid,
        struct berval   *resdata,
        LDAPControl **ctrls
 )
@@ -232,8 +233,8 @@ send_ldap_response(
 
        ber = ber_alloc_t( LBER_USE_DER );
 
-       Debug( LDAP_DEBUG_TRACE, "send_ldap_response: tag=%ld msgid=%ld err=%ld\n",
-               (long) tag, (long) msgid, (long) err );
+       Debug( LDAP_DEBUG_TRACE, "send_ldap_response: msgid=%ld tag=%ld err=%ld\n",
+               (long) msgid, (long) tag, (long) err );
 
        if ( ber == NULL ) {
                Debug( LDAP_DEBUG_ANY, "ber_alloc failed\n", 0, 0, 0 );
@@ -298,7 +299,7 @@ send_ldap_disconnect(
     Connection *conn,
     Operation  *op,
     ber_int_t  err,
-    char       *text
+    const char *text
 )
 {
        ber_tag_t tag;
@@ -344,7 +345,7 @@ send_ldap_disconnect(
        Statslog( LDAP_DEBUG_STATS,
            "conn=%ld op=%ld DISCONNECT err=%ld tag=%lu text=%s\n",
                (long) op->o_connid, (long) op->o_opid,
-               (long) tag, (long) err, text );
+               (long) tag, (long) err, text ? text : "" );
 }
 
 void
@@ -352,8 +353,8 @@ send_ldap_result(
     Connection *conn,
     Operation  *op,
     ber_int_t  err,
-    char       *matched,
-    char       *text,
+    const char *matched,
+    const char *text,
        struct berval **ref,
        LDAPControl **ctrls
 )
@@ -380,7 +381,8 @@ send_ldap_result(
                        err = LDAP_NO_SUCH_OBJECT;
                } else if ( op->o_protocol < LDAP_VERSION3 ) {
                        err = LDAP_PARTIAL_RESULTS;
-                       tmp = text = v2ref( ref );
+                       tmp = v2ref( ref );
+                       text = tmp;
                        ref = NULL;
                }
        }
@@ -404,9 +406,9 @@ send_ldap_result(
                NULL, NULL, ctrls );
 
        Statslog( LDAP_DEBUG_STATS,
-           "conn=%ld op=%ld RESULT err=%ld tag=%lu text=%s\n",
+           "conn=%ld op=%ld RESULT tag=%lu err=%ld text=%s\n",
                (long) op->o_connid, (long) op->o_opid,
-               (long) err, (long) tag, text );
+               (long) tag, (long) err, text ? text : "" );
 
        if( tmp != NULL ) {
                free(tmp);
@@ -419,8 +421,8 @@ send_search_result(
     Connection *conn,
     Operation  *op,
     ber_int_t  err,
-    char       *matched,
-       char    *text,
+    const char *matched,
+       const char      *text,
     struct berval **refs,
        LDAPControl **ctrls,
     int                nentries
@@ -444,7 +446,8 @@ send_search_result(
                        err = LDAP_PARTIAL_RESULTS;
                }
 
-               tmp = text = v2ref( refs );
+               tmp = v2ref( refs );
+               text = tmp;
                refs = NULL;
 
        } else {
@@ -476,9 +479,9 @@ send_search_result(
                NULL, NULL, ctrls );
 
        Statslog( LDAP_DEBUG_STATS,
-           "conn=%ld op=%ld SEARCH RESULT err=%ld tag=%lu text=%s\n",
+           "conn=%ld op=%ld SEARCH RESULT tag=%lu err=%ld text=%s\n",
                (long) op->o_connid, (long) op->o_opid,
-               (long) err, (long) tag, text );
+               (long) tag, (long) err, text ? text : "" );
 
 }
 
@@ -491,7 +494,6 @@ send_search_entry(
     Entry      *e,
     char       **attrs,
     int                attrsonly,
-       int             opattrs,
        LDAPControl **ctrls
 )
 {
@@ -500,7 +502,8 @@ send_search_entry(
        int             i, rc=-1, bytes;
        AccessControl   *acl;
        char            *edn;
-       int             allattrs;
+       int             userattrs;
+       int             opattrs;
 
        Debug( LDAP_DEBUG_TRACE, "=> send_search_entry: \"%s\"\n", e->e_dn, 0, 0 );
 
@@ -534,10 +537,14 @@ send_search_entry(
                goto error_return;
        }
 
-       /* check for special all user attributes ("*") attribute */
-       allattrs = ( attrs == NULL ) ? 1
+       /* check for special all user attributes ("*") type */
+       userattrs = ( attrs == NULL ) ? 1
                : charray_inlist( attrs, LDAP_ALL_USER_ATTRIBUTES );
 
+       /* check for special all operational attributes ("+") type */
+       opattrs = ( attrs == NULL ) ? 0
+               : charray_inlist( attrs, LDAP_ALL_OPERATIONAL_ATTRIBUTES );
+
        for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
                regmatch_t       matches[MAXREMATCHES];
 
@@ -549,25 +556,23 @@ send_search_entry(
 
                } else {
                        /* specific addrs requested */
-                       if ( allattrs ) {
-                               /* user requested all user attributes */
-                               /* if operational, make sure it's in list */
-
-                               if( oc_check_operational_attr( a->a_type )
-                                       && !charray_inlist( attrs, a->a_type ) )
+                       if (  oc_check_operational_attr( a->a_type ) ) {
+                               if( !opattrs && !charray_inlist( attrs, a->a_type ) )
+                               {
+                                       continue;
+                               }
+                       } else {
+                               if (!userattrs && !charray_inlist( attrs, a->a_type ) )
                                {
                                        continue;
                                }
-
-                       } else if ( !charray_inlist( attrs, a->a_type ) ) {
-                               continue;
                        }
                }
 
                acl = acl_get_applicable( be, op, e, a->a_type,
                        MAXREMATCHES, matches );
 
-               if ( ! acl_access_allowed( acl, be, conn, e,
+               if ( ! acl_access_allowed( acl, a->a_type, be, conn, e,
                        NULL, op, ACL_READ, edn, matches ) ) 
                {
                        continue;
@@ -584,7 +589,7 @@ send_search_entry(
                if ( ! attrsonly ) {
                        for ( i = 0; a->a_vals[i] != NULL; i++ ) {
                                if ( a->a_syntax & SYNTAX_DN && 
-                                       ! acl_access_allowed( acl, be, conn, e, a->a_vals[i], op,
+                                       ! acl_access_allowed( acl, a->a_type, be, conn, e, a->a_vals[i], op,
                                                ACL_READ, edn, matches) )
                                {
                                        continue;
@@ -611,6 +616,8 @@ send_search_entry(
        }
 
 #ifdef SLAPD_SCHEMA_DN
+       /* eventually will loop through generated operational attributes */
+       /* only have subschemaSubentry implemented */
        a = backend_subschemasubentry( be );
        
        do {
@@ -624,25 +631,23 @@ send_search_entry(
 
                } else {
                        /* specific addrs requested */
-                       if ( allattrs ) {
-                               /* user requested all user attributes */
-                               /* if operational, make sure it's in list */
-
-                               if( oc_check_operational_attr( a->a_type )
-                                       && !charray_inlist( attrs, a->a_type ) )
+                       if (  oc_check_operational_attr( a->a_type ) ) {
+                               if( !opattrs && !charray_inlist( attrs, a->a_type ) )
+                               {
+                                       continue;
+                               }
+                       } else {
+                               if (!userattrs && !charray_inlist( attrs, a->a_type ) )
                                {
                                        continue;
                                }
-
-                       } else if ( !charray_inlist( attrs, a->a_type ) ) {
-                               continue;
                        }
                }
 
                acl = acl_get_applicable( be, op, e, a->a_type,
                        MAXREMATCHES, matches );
 
-               if ( ! acl_access_allowed( acl, be, conn, e,
+               if ( ! acl_access_allowed( acl, a->a_type, be, conn, e,
                        NULL, op, ACL_READ, edn, matches ) ) 
                {
                        continue;
@@ -659,7 +664,7 @@ send_search_entry(
                if ( ! attrsonly ) {
                        for ( i = 0; a->a_vals[i] != NULL; i++ ) {
                                if ( a->a_syntax & SYNTAX_DN && 
-                                       ! acl_access_allowed( acl, be, conn, e, a->a_vals[i], op,
+                                       ! acl_access_allowed( acl, a->a_type, be, conn, e, a->a_vals[i], op,
                                                ACL_READ, edn, matches) )
                                {
                                        continue;
@@ -738,7 +743,7 @@ send_search_reference(
        int rc;
        int bytes;
 
-       Debug( LDAP_DEBUG_TRACE, "=> send_search_entry (%s)\n", e->e_dn, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "=> send_search_reference (%s)\n", e->e_dn, 0, 0 );
 
        if ( ! access_allowed( be, conn, op, e,
                "entry", NULL, ACL_READ ) )
@@ -806,7 +811,7 @@ send_search_reference(
        Statslog( LDAP_DEBUG_STATS2, "conn=%ld op=%ld ENTRY dn=\"%s\"\n",
            (long) conn->c_connid, (long) op->o_opid, e->e_dn, 0, 0 );
 
-       Debug( LDAP_DEBUG_TRACE, "<= send_search_entry\n", 0, 0, 0 );
+       Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
 
        return 0;
 }