]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/acl.c
Add reference to slapd.conf(5) and recommendation to avoid cleartext passwords.
[openldap] / servers / slapd / acl.c
index 10985533190df937542169770f0443e30b080c11..e94bfe3cd1f6ee356ba03b9c1afa8a016780d12c 100644 (file)
@@ -3,29 +3,16 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netdb.h>
-#include <regex.h>
 
-#include "slap.h"
-
-extern Attribute       *attr_find();
-extern struct acl      *global_acl;
-extern int             global_default_access;
-extern char            *access2str();
-extern char            *dn_normalize_case();
-
-int            acl_access_allowed();
-int            access_allowed();
-struct acl     *acl_get_applicable();
+#include <ac/regex.h>
+#include <ac/socket.h>
+#include <ac/string.h>
 
-static int     regex_matches();
+#include "slap.h"
 
-static string_expand(char *newbuf, int bufsiz, char *pattern,
-       char *match, regmatch_t *matches);
+static int     regex_matches(char *pat, char *str, char *buf, regmatch_t *matches);
+static void    string_expand(char *newbuf, int bufsiz, char *pattern,
+                             char *match, regmatch_t *matches);
 
 
 /*
@@ -63,7 +50,7 @@ access_allowed(
                return( 0 );
        }
 
-       edn = dn_normalize_case( strdup( e->e_dn ) );
+       edn = dn_normalize_case( ch_strdup( e->e_dn ) );
        Debug( LDAP_DEBUG_ACL, "\n=> access_allowed: entry (%s) attr (%s)\n",
                e->e_dn, attr, 0 );
 
@@ -85,8 +72,8 @@ access_allowed(
 
        if (a) {
                for (i = 0; i < MAXREMATCHES && matches[i].rm_so > 0; i++) {
-                       Debug( LDAP_DEBUG_ARGS, "=> match[%d]: %d %d ",
-                               i, matches[i].rm_so, matches[i].rm_eo );
+                       Debug( LDAP_DEBUG_ARGS, "=> match[%d]: %d %d ", i,
+                              (int)matches[i].rm_so, (int)matches[i].rm_eo );
 
                        if( matches[i].rm_so <= matches[0].rm_eo ) {
                                for ( n = matches[i].rm_so; n < matches[i].rm_eo; n++) {
@@ -142,7 +129,7 @@ acl_get_applicable(
        for ( i = 1, a = be->be_acl; a != NULL; a = a->acl_next, i++ ) {
                if (a->acl_dnpat != NULL) {
                        Debug( LDAP_DEBUG_TRACE, "=> dnpat: [%d] %s nsub: %d\n", 
-                               i, a->acl_dnpat, a->acl_dnre.re_nsub);
+                               i, a->acl_dnpat, (int) a->acl_dnre.re_nsub);
 
                        if (regexec(&a->acl_dnre, edn, nmatch, matches, 0))
                                continue;
@@ -173,7 +160,7 @@ acl_get_applicable(
        for ( i = 1, a = global_acl; a != NULL; a = a->acl_next, i++ ) {
                if (a->acl_dnpat != NULL) {
                        Debug( LDAP_DEBUG_TRACE, "=> dnpat: [%d] %s nsub: %d\n", 
-                               i, a->acl_dnpat, a->acl_dnre.re_nsub);
+                               i, a->acl_dnpat, (int) a->acl_dnre.re_nsub);
 
                        if (regexec(&a->acl_dnre, edn, nmatch, matches, 0)) {
                                continue;
@@ -263,7 +250,7 @@ acl_access_allowed(
 
        odn = NULL;
        if ( op->o_dn != NULL ) {
-               odn = dn_normalize_case( strdup( op->o_dn ) );
+               odn = dn_normalize_case( ch_strdup( op->o_dn ) );
                bv.bv_val = odn;
                bv.bv_len = strlen( odn );
        }
@@ -362,23 +349,20 @@ acl_access_allowed(
 
                        return( (b->a_access & ~ACL_SELF) >= access );
                }
-#ifdef ACLGROUP
+#ifdef SLAPD_ACLGROUPS
                if ( b->a_group != NULL && op->o_dn != NULL ) {
                        char buf[512];
 
                        /* b->a_group is an unexpanded entry name, expanded it should be an 
                         * entry with objectclass group* and we test to see if odn is one of
-                        * the values in the attribute uniquegroup
+                        * the values in the attribute group
                         */
-                       Debug( LDAP_DEBUG_ARGS, "<= check a_group: %s\n",
-                               b->a_group, 0, 0);
-                       Debug( LDAP_DEBUG_ARGS, "<= check a_group: odn: %s\n",
-                               odn, 0, 0);
-
                        /* see if asker is listed in dnattr */
                        string_expand(buf, sizeof(buf), b->a_group, edn, matches);
 
-                       if (be_group(be, buf, odn) == 0) {
+                       if (be_group(be, e, buf, odn,
+                               b->a_objectclassvalue, b->a_groupattrname) == 0)
+                       {
                                Debug( LDAP_DEBUG_ACL,
                                        "<= acl_access_allowed: matched by clause #%d (group) access granted\n",
                                        i, 0, 0 );
@@ -386,7 +370,7 @@ acl_access_allowed(
                                return( (b->a_access & ~ACL_SELF) >= access );
                        }
                }
-#endif /* ACLGROUP */
+#endif /* SLAPD_ACLGROUPS */
        }
 
        if ( odn ) free( odn );
@@ -398,7 +382,7 @@ acl_access_allowed(
 }
 
 /*
- * acl_check_mods - check access control on the given entry to see if
+ * acl_check_modlist - check access control on the given entry to see if
  * it allows the given modifications by the user associated with op.
  * returns     LDAP_SUCCESS    mods allowed ok
  *             anything else   mods not allowed - return is an error
@@ -406,45 +390,45 @@ acl_access_allowed(
  */
 
 int
-acl_check_mods(
+acl_check_modlist(
     Backend    *be,
     Connection *conn,
     Operation  *op,
     Entry      *e,
-    LDAPMod    *mods
+    LDAPModList        *mlist
 )
 {
        int             i;
        struct acl      *a;
        char            *edn;
 
-       edn = dn_normalize_case( strdup( e->e_dn ) );
+       edn = dn_normalize_case( ch_strdup( e->e_dn ) );
 
-       for ( ; mods != NULL; mods = mods->mod_next ) {
+       for ( ; mlist != NULL; mlist = mlist->ml_next ) {
                regmatch_t       matches[MAXREMATCHES];
 
                /* the lastmod attributes are ignored by ACL checking */
-               if ( strcasecmp( mods->mod_type, "modifiersname" ) == 0 ||
-                       strcasecmp( mods->mod_type, "modifytimestamp" ) == 0 ||
-                       strcasecmp( mods->mod_type, "creatorsname" ) == 0 ||
-                       strcasecmp( mods->mod_type, "createtimestamp" ) == 0 ) 
+               if ( strcasecmp( mlist->ml_type, "modifiersname" ) == 0 ||
+                       strcasecmp( mlist->ml_type, "modifytimestamp" ) == 0 ||
+                       strcasecmp( mlist->ml_type, "creatorsname" ) == 0 ||
+                       strcasecmp( mlist->ml_type, "createtimestamp" ) == 0 ) 
                {
                        Debug( LDAP_DEBUG_ACL, "LASTMOD attribute: %s access allowed\n",
-                               mods->mod_type, 0, 0 );
+                               mlist->ml_type, 0, 0 );
                        continue;
                }
 
-               a = acl_get_applicable( be, op, e, mods->mod_type, edn,
+               a = acl_get_applicable( be, op, e, mlist->ml_type, edn,
                        MAXREMATCHES, matches );
 
-               switch ( mods->mod_op & ~LDAP_MOD_BVALUES ) {
+               switch ( mlist->ml_op & ~LDAP_MOD_BVALUES ) {
                case LDAP_MOD_REPLACE:
                case LDAP_MOD_ADD:
-                       if ( mods->mod_bvalues == NULL ) {
+                       if ( mlist->ml_bvalues == NULL ) {
                                break;
                        }
-                       for ( i = 0; mods->mod_bvalues[i] != NULL; i++ ) {
-                               if ( ! acl_access_allowed( a, be, conn, e, mods->mod_bvalues[i], 
+                       for ( i = 0; mlist->ml_bvalues[i] != NULL; i++ ) {
+                               if ( ! acl_access_allowed( a, be, conn, e, mlist->ml_bvalues[i], 
                                        op, ACL_WRITE, edn, matches) ) 
                                {
                                        free(edn);
@@ -454,7 +438,7 @@ acl_check_mods(
                        break;
 
                case LDAP_MOD_DELETE:
-                       if ( mods->mod_bvalues == NULL ) {
+                       if ( mlist->ml_bvalues == NULL ) {
                                if ( ! acl_access_allowed( a, be, conn, e,
                                        NULL, op, ACL_WRITE, edn, matches) ) 
                                {
@@ -463,8 +447,8 @@ acl_check_mods(
                                }
                                break;
                        }
-                       for ( i = 0; mods->mod_bvalues[i] != NULL; i++ ) {
-                               if ( ! acl_access_allowed( a, be, conn, e, mods->mod_bvalues[i], 
+                       for ( i = 0; mlist->ml_bvalues[i] != NULL; i++ ) {
+                               if ( ! acl_access_allowed( a, be, conn, e, mlist->ml_bvalues[i], 
                                        op, ACL_WRITE, edn, matches) ) 
                                {
                                        free(edn);
@@ -479,7 +463,8 @@ acl_check_mods(
        return( LDAP_SUCCESS );
 }
 
-static string_expand(
+static void
+string_expand(
        char *newbuf,
        int bufsiz,
        char *pat,
@@ -495,7 +480,7 @@ static string_expand(
        newbuf[0] = '\0';
 
        flag = 0;
-       for ( dp = newbuf, sp = pat; size < 512 && *sp ; sp++) {
+       for ( dp = newbuf, sp = pat; size < bufsiz && *sp ; sp++) {
                /* did we previously see a $ */
                if (flag) {
                        if (*sp == '$') {