]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/acl.c
Fix memory leak.
[openldap] / servers / slapd / acl.c
index e587ca7a750afefb0fc7a0989fb1671a966c0369..31b1b80e9ca256c638bb4a4ab3809d6f7529609d 100644 (file)
@@ -22,7 +22,7 @@ static AccessControl * acl_get(
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
        AttributeDescription *desc,
 #else
-       const char *attr,
+       const char *desc,
 #endif
        int nmatches, regmatch_t *matches );
 
@@ -33,7 +33,7 @@ static slap_control_t acl_mask(
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
        AttributeDescription *desc,
 #else
-       const char *attr,
+       const char *desc,
 #endif
        struct berval *val,
        regmatch_t *matches );
@@ -46,16 +46,13 @@ static int aci_mask(
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
        AttributeDescription *desc,
 #else
-       const char *attr,
+       const char *desc,
 #endif
-       struct berval *val, struct berval *aci,
-       regmatch_t *matches, slap_access_t *grant, slap_access_t *deny );
-
-char *supportedACIMechs[] = {
-       "1.3.6.1.4.1.4203.666.7.1",     /* experimental IETF aci family */
-       "1.3.6.1.4.1.4203.666.7.2",     /* experimental OpenLDAP aci family */
-       NULL
-};
+       struct berval *val,
+       struct berval *aci,
+       regmatch_t *matches,
+       slap_access_t *grant,
+       slap_access_t *deny );
 #endif
 
 static int     regex_matches(
@@ -87,9 +84,9 @@ access_allowed(
     Operation          *op,
     Entry              *e,
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       AttributeDescription    *attr,
+       AttributeDescription    *desc,
 #else
-    const char         *attr,
+    const char         *desc,
 #endif
     struct berval      *val,
     slap_access_t      access )
@@ -102,6 +99,12 @@ access_allowed(
        slap_access_mask_t mask;
        slap_control_t control;
 
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       const char *attr = desc ? desc->ad_cname->bv_val : NULL;
+#else
+    const char *attr = desc;
+#endif
+
        regmatch_t       matches[MAXREMATCHES];
 
        Debug( LDAP_DEBUG_ACL,
@@ -128,7 +131,7 @@ access_allowed(
         * by the user
         */
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       if ( access >= ACL_WRITE && is_at_no_user_mod( attr->ad_type ) )
+       if ( access >= ACL_WRITE && is_at_no_user_mod( desc->ad_type ) )
 #else
        if ( access >= ACL_WRITE && oc_check_op_no_usermod_attr( attr ) )
 #endif
@@ -168,7 +171,7 @@ access_allowed(
        a = NULL;
        count = 0;
 
-       while( a = acl_get( a, &count, be, op, e, attr, MAXREMATCHES, matches ) )
+       while( a = acl_get( a, &count, be, op, e, desc, MAXREMATCHES, matches ) )
        {
                int i;
 
@@ -186,7 +189,7 @@ access_allowed(
                }
 
                control = acl_mask( a, &mask, be, conn, op,
-                       e, attr, val, matches );
+                       e, desc, val, matches );
 
                if ( control != ACL_BREAK ) {
                        break;
@@ -241,6 +244,12 @@ acl_get(
        assert( e != NULL );
        assert( count != NULL );
 
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       attr = desc ? desc->ad_cname->bv_val : NULL;
+#else
+       attr = desc;
+#endif
+
        if( a == NULL ) {
                if( be == NULL ) {
                        a = global_acl;
@@ -254,12 +263,6 @@ acl_get(
                a = a->acl_next;
        }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-       attr = desc->ad_cname->bv_val;
-#else
-       attr = desc;
-#endif
-
        for ( ; a != NULL; a = a->acl_next ) {
                (*count) ++;
 
@@ -320,9 +323,9 @@ acl_mask(
     Operation  *op,
     Entry              *e,
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       AttributeDescription *attr,
+       AttributeDescription *desc,
 #else
-    const char *attr,
+    const char *desc,
 #endif
     struct berval      *val,
        regmatch_t      *matches
@@ -333,6 +336,11 @@ acl_mask(
 #ifdef LDAP_DEBUG
        char accessmaskbuf[ACCESSMASK_MAXLEN];
 #endif
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+       const char *attr = desc ? desc->ad_cname->bv_val : NULL;
+#else
+       const char *attr = desc;
+#endif
 
        assert( a != NULL );
        assert( mask != NULL );
@@ -441,6 +449,13 @@ acl_mask(
                if ( b->a_dn_at != NULL && op->o_ndn != NULL ) {
                        Attribute       *at;
                        struct berval   bv;
+#ifdef SLAPD_SCHEMA_NOT_COMPAT
+                       int match;
+                       const char *text;
+                       const char *desc = b->a_dn_at->ad_cname->bv_val;
+#else
+                       const char *desc = b->a_dn_at;
+#endif
 
                        Debug( LDAP_DEBUG_ACL, "<= check a_dn_at: %s\n",
                                b->a_dn_at, 0, 0);
@@ -448,38 +463,54 @@ acl_mask(
                        bv.bv_val = op->o_ndn;
                        bv.bv_len = strlen( bv.bv_val );
 
-                       /* see if asker is listed in dnattr */ 
-                       if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL
+                       /* see if asker is listed in dnattr */
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-                               /* not yet implemented */
-#else
-                               && value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0
-#endif
-                       )
+                       for( at = attrs_find( e->e_attrs, b->a_dn_at );
+                               at == NULL;
+                               at = attrs_find( e->e_attrs->a_next, b->a_dn_at ) )
                        {
-                               if ( b->a_dn_self && 
-                                       (val == NULL
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-                                       /* not yet implemented */
+                               if( value_find( b->a_dn_at, at->a_vals, &bv ) == 0 ) {
+                                       /* found it */
+                                       match = 1;
+                                       break;
+                               }
+                       }
+
+                       if( match ) {
+                               if ( b->a_dn_self && (val == NULL
+                                       || value_match( &match, b->a_dn_at,
+                                               b->a_dn_at->ad_type->sat_equality, val, &bv, &text ) )
+                                               != LDAP_SUCCESS
+                                       || match )
+                               {
+                                       continue;
+                               }
+                       } else if ( ! b->a_dn_self || val == NULL
+                               || value_match( &match, b->a_dn_at,
+                                       b->a_dn_at->ad_type->sat_equality, val, &bv, &text )
+                                       != LDAP_SUCCESS
+                               || match )
+                       {
+                               continue;
+                       }
 #else
-                                       || value_cmp( &bv, val, at->a_syntax, 2 )
-#endif
-                                       ) )
+                       /* see if asker is listed in dnattr */
+                       if ( (at = attr_find( e->e_attrs, b->a_dn_at )) != NULL &&
+                               value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
+                       {
+                               if ( b->a_dn_self && (val == NULL
+                                       || value_cmp( &bv, val, at->a_syntax, 2 ) ) )
                                {
                                        continue;
                                }
 
                        /* asker not listed in dnattr - check for self access */
                        } else if ( ! b->a_dn_self || val == NULL
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-                                       /* not yet implemented */
-#else
-                               || value_cmp( &bv, val, at->a_syntax, 2 ) != 0
-#endif
-                       )
+                               || value_cmp( &bv, val, at->a_syntax, 2 ) != 0 )
                        {
                                continue;
                        }
+#endif
                }
 
                if ( b->a_group_pat != NULL && op->o_ndn != NULL ) {
@@ -544,7 +575,7 @@ acl_mask(
                         */
                        for ( i = 0; at->a_vals[i] != NULL; i++ ) {
                                if (aci_mask( be, op,
-                                       e, attr, val, at->a_vals[i],
+                                       e, desc, val, at->a_vals[i],
                                        matches, &grant, &deny ) != 0)
                                {
                                        tgrant |= grant;
@@ -695,10 +726,15 @@ acl_check_modlist(
                 * by the user
                 */
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-               /* not yet implemented */
+               if ( is_at_no_user_mod( mlist->sml_desc->ad_type ) ) {
+                       Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
+                               " modify access granted\n",
+                               mlist->sml_desc->ad_cname->bv_val, 0, 0 );
+                       continue;
+               }
 #else
                if ( oc_check_op_no_usermod_attr( mlist->sml_type ) ) {
-                       Debug( LDAP_DEBUG_ACL, "NoUserMod Operational attribute:"
+                       Debug( LDAP_DEBUG_ACL, "acl: no-user-mod %s:"
                                " modify access granted\n",
                                mlist->sml_type, 0, 0 );
                        continue;
@@ -984,10 +1020,12 @@ aci_group_member (
        char *grpoc;
        char *grpat;
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       AttributeDescription *grpad;
+       ObjectClass *grp_oc = NULL;
+       AttributeDescription *grp_ad = NULL;
        char *text;
 #else
-       char *grpad;
+       char *grp_oc;
+       char *grp_ad;
 #endif
        int rc;
 
@@ -1014,28 +1052,28 @@ aci_group_member (
        }
 
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       rc = slap_str2ad( grpat, &grpad, &text );
+       rc = slap_str2ad( grpat, &grp_ad, &text );
        if( rc != LDAP_SUCCESS ) {
                rc = 0;
                goto done;
        }
 #else
-       grpad = grpat;
+       grp_ad = grpat;
 #endif
        rc = 0;
 
        grpdn = (char *)ch_malloc(1024);
 
-       if (grpoc != NULL && grpad != NULL && grpdn != NULL) {
+       if (grp_oc != NULL && grp_ad != NULL && grpdn != NULL) {
                string_expand(grpdn, 1024, subjdn, e->e_ndn, matches);
                if ( dn_normalize(grpdn) != NULL ) {
-                       rc = (backend_group(be, e, grpdn, op->o_ndn, grpoc, grpad) == 0);
+                       rc = (backend_group(be, e, grpdn, op->o_ndn, grp_oc, grp_ad) == 0);
                }
        }
 
-done:
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-       if( grpad != NULL ) ad_free( grpad, 1 );
+done:
+       if( grp_ad != NULL ) ad_free( grp_ad, 1 );
 #endif
        ch_free(grpdn);
        ch_free(grpat);
@@ -1084,12 +1122,6 @@ aci_mask(
        /* check that the aci family is supported */
        if (aci_get_part(aci, 0, '#', &bv) < 0)
                return(0);
-       for (i = 0; supportedACIMechs[i] != NULL; i++) {
-               if (aci_strbvcmp( supportedACIMechs[i], &bv ) == 0)
-                       break;
-       }
-       if (supportedACIMechs[i] == NULL)
-               return(0);
 
        /* check that the scope is "entry" */
        if (aci_get_part(aci, 1, '#', &bv) < 0
@@ -1130,62 +1162,63 @@ aci_mask(
                        return(1);
 
        } else if (aci_strbvcmp( "dnattr", &bv ) == 0) {
-               Attribute *at;
                char *dnattr = aci_bvstrdup(&sdn);
 #ifdef SLAPD_SCHEMA_NOT_COMPAT
-               AttributeDescription *dnad;
-               char *text;
-               rc = slap_str2ad( dnattr, &dnad, &text );
+               Attribute *at;
+               AttributeDescription *ad = NULL;
+               const char *text;
+
+               rc = slap_str2ad( dnattr, &ad, &text );
                ch_free( dnattr );
 
-               if ( rc == LDAP_SUCCESS ) {
-#else
-                       char *dnad = dnattr;
-#endif
-                       at = attr_find( e->e_attrs, dnad );
-#ifdef SLAPD_SCHEMA_NOT_COMAT
-                       ad_free( dnad, 1 );
-#else
-                       ch_free( dnad );
-#endif
-                       if (at != NULL) {
-                               bv.bv_val = op->o_ndn;
-                               bv.bv_len = strlen( bv.bv_val );
+               if( rc != LDAP_SUCCESS ) {
+                       return 0;
+               }
 
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-                               /* not yet implemented */
-#else
-                               if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
-                                       return(1);
-#endif
+               rc = 0;
+
+               bv.bv_val = op->o_ndn;
+               bv.bv_len = strlen( bv.bv_val );
+
+               for(at = attrs_find( e->e_attrs, ad );
+                       at != NULL;
+                       at = attrs_find( at->a_next, ad ) )
+               {
+                       if (value_find( ad, at->a_vals, &bv) == 0 ) {
+                               rc = 1;
+                               break;
                        }
-#ifdef SLAPD_SCHEMA_NOT_COMPAT
-               } else {
-                       ad_free( dnad, 1 );
-#endif
                }
 
+               ad_free( ad, 1 );
+               return rc;
+
+#else
+               Attribute *at;
+               at = attr_find( e->e_attrs, dnattr );
+               ch_free( dnattr );
+
+               if (at != NULL) {
+                       bv.bv_val = op->o_ndn;
+                       bv.bv_len = strlen( bv.bv_val );
+
+                       if (value_find( at->a_vals, &bv, at->a_syntax, 3 ) == 0 )
+                               return(1);
+               }
+#endif
+
        } else if (aci_strbvcmp( "group", &bv ) == 0) {
-               if (aci_group_member(&sdn, "groupOfNames", "member", be, e, op, matches))
+               if (aci_group_member(&sdn, SLAPD_GROUP_CLASS, SLAPD_GROUP_ATTR, be, e, op, matches))
                        return(1);
 
        } else if (aci_strbvcmp( "role", &bv ) == 0) {
-               if (aci_group_member(&sdn, "organizationalRole", "roleOccupant", be, e, op, matches))
+               if (aci_group_member(&sdn, SLAPD_ROLE_CLASS, SLAPD_ROLE_ATTR, be, e, op, matches))
                        return(1);
        }
 
        return(0);
 }
 
-char *
-get_supported_acimech(
-       int index )
-{
-       if (index < 0 || index >= (sizeof(supportedACIMechs) / sizeof(char *)))
-               return(NULL);
-       return(supportedACIMechs[index]);
-}
-
 #endif /* SLAPD_ACI_ENABLED */
 
 static void