]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/config.c
ITS#3576 use actual backend (not glue instance) for restriction and
[openldap] / servers / slapd / back-sql / config.c
index 413bdf5f9fef20a075d501a133c247fa014aec43..9e82f0b3584fc15945b19c07e122a20cf347eef9 100644 (file)
@@ -291,35 +291,35 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "delentry_stmt=%s\n", bi->sql_delentry_stmt, 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_stmt" ) ||
-                       !strcasecmp( argv[ 0 ], "delobjclasses_query" ) )
+       } else if ( !strcasecmp( argv[ 0 ], "renentry_stmt" ) ||
+                       !strcasecmp( argv[ 0 ], "renentry_query" ) )
        {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
                                "missing SQL statement "
-                               "in \"delobjclasses_stmt\" directive\n",
+                               "in \"renentry_stmt\" directive\n",
                                fname, lineno, 0 );
                        return 1;
                }
-               bi->sql_delobjclasses_stmt = ch_strdup( argv[ 1 ] );
+               bi->sql_renentry_stmt = ch_strdup( argv[ 1 ] );
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
-                       "delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
+                       "renentry_stmt=%s\n", bi->sql_renentry_stmt, 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "delreferrals_stmt" ) ||
-                       !strcasecmp( argv[ 0 ], "delreferrals_query" ) )
+       } else if ( !strcasecmp( argv[ 0 ], "delobjclasses_stmt" ) ||
+                       !strcasecmp( argv[ 0 ], "delobjclasses_query" ) )
        {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
                                "missing SQL statement "
-                               "in \"delreferrals_stmt\" directive\n",
+                               "in \"delobjclasses_stmt\" directive\n",
                                fname, lineno, 0 );
                        return 1;
                }
-               bi->sql_delreferrals_stmt = ch_strdup( argv[ 1 ] );
+               bi->sql_delobjclasses_stmt = ch_strdup( argv[ 1 ] );
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
-                       "delreferrals_stmt=%s\n", bi->sql_delreferrals_stmt, 0, 0 );
+                       "delobjclasses_stmt=%s\n", bi->sql_delobjclasses_stmt, 0, 0 );
 
        } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru") ) {
                if ( argc < 2 ) {
@@ -493,7 +493,73 @@ backsql_db_config(
                }
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "use_subtree_shortcut=%s\n", 
-                       BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no", 0, 0 );
+                       BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no",
+                       0, 0 );
+
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs") ) {
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing { yes | no }"
+                               "in \"fetch_all_attrs\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
+                       bi->sql_flags |= BSQLF_FETCH_ALL_ATTRS;
+
+               } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
+                       bi->sql_flags &= ~BSQLF_FETCH_ALL_ATTRS;
+
+               } else {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "\"fetch_all_attrs\" directive arg "
+                               "must be \"yes\" or \"no\"\n",
+                               fname, lineno, 0 );
+                       return 1;
+
+               }
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "fetch_all_attrs=%s\n", 
+                       BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no",
+                       0, 0 );
+
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs") ) {
+               char    *str, *s, *next;
+               char    delimstr[] = ",";
+
+               if ( argc < 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing <attrlist>"
+                               "in \"fetch_all_attrs <attrlist>\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               str = ch_strdup( argv[ 1 ] );
+               for ( s = ldap_pvt_strtok( str, delimstr, &next );
+                               s != NULL;
+                               s = ldap_pvt_strtok( NULL, delimstr, &next ) )
+               {
+                       if ( strlen( s ) == 1 ) {
+                               if ( *s == '*' ) {
+                                       bi->sql_flags |= BSQLF_FETCH_ALL_USERATTRS;
+                                       argv[ 1 ][ s - str ] = ',';
+
+                               } else if ( *s == '+' ) {
+                                       bi->sql_flags |= BSQLF_FETCH_ALL_OPATTRS;
+                                       argv[ 1 ][ s - str ] = ',';
+                               }
+                       }
+               }
+               ch_free( str );
+               bi->sql_anlist = str2anlist( bi->sql_anlist, argv[ 1 ], delimstr );
+               if ( bi->sql_anlist == NULL ) {
+                       return -1;
+               }
 
        } else {
                return SLAP_CONF_UNKNOWN;
@@ -523,7 +589,8 @@ read_baseObject(
        fp = fopen( fname, "r" );
        if ( fp == NULL ) {
                Debug( LDAP_DEBUG_ANY,
-                       "could not open back-sql baseObject attr file \"%s\" - absolute path?\n",
+                       "could not open back-sql baseObject "
+                       "attr file \"%s\" - absolute path?\n",
                        fname, 0, 0 );
                perror( fname );
                return LDAP_OTHER;
@@ -545,8 +612,9 @@ read_baseObject(
                Attribute       *a;
 
                if( e == NULL ) {
-                       fprintf( stderr, "back-sql baseObject: could not parse entry (line=%d)\n",
-                               lineno );
+                       fprintf( stderr, "back-sql baseObject: "
+                                       "could not parse entry (line=%d)\n",
+                                       lineno );
                        rc = LDAP_OTHER;
                        break;
                }
@@ -554,8 +622,9 @@ read_baseObject(
                /* make sure the DN is the database's suffix */
                if ( !be_issuffix( be, &e->e_nname ) ) {
                        fprintf( stderr,
-                               "back-sql: invalid baseObject - dn=\"%s\" (line=%d)\n",
-                               e->e_dn, lineno );
+                               "back-sql: invalid baseObject - "
+                               "dn=\"%s\" (line=%d)\n",
+                               e->e_name.bv_val, lineno );
                        entry_free( e );
                        rc = EXIT_FAILURE;
                        break;
@@ -566,8 +635,10 @@ read_baseObject(
                 * entry, and add each attribute type and description to baseObject
                 */
                for ( a = e->e_attrs; a != NULL; a = a->a_next ) {
-                       if ( attr_merge( bi->sql_baseObject, a->a_desc, a->a_vals,
-                               ( a->a_nvals == a->a_vals ) ? NULL : a->a_nvals ) )
+                       if ( attr_merge( bi->sql_baseObject, a->a_desc,
+                                               a->a_vals,
+                                               ( a->a_nvals == a->a_vals ) ?
+                                               NULL : a->a_nvals ) )
                        {
                                rc = LDAP_OTHER;
                                break;
@@ -589,7 +660,8 @@ read_baseObject(
 
        fclose( fp );
 
-       Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n", fname, 0, 0 );
+       Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n",
+                       fname, 0, 0 );
 
        return rc;
 }
@@ -610,9 +682,11 @@ create_baseObject(
                        "dn: %s\n"
                        "objectClass: extensibleObject\n"
                        "description: builtin baseObject for back-sql\n"
-                       "description: all entries mapped in the \"ldap_entries\" table\n"
-                       "description: must have \"" BACKSQL_BASEOBJECT_IDSTR "\" "
-                               "in the \"parent\" column",
+                       "description: all entries mapped "
+                       "in the \"ldap_entries\" table\n"
+                       "description: must have "
+                       "\"" BACKSQL_BASEOBJECT_IDSTR "\" "
+                       "in the \"parent\" column",
                        be->be_suffix[0].bv_val );
 
        bi->sql_baseObject = str2entry( buf );
@@ -628,11 +702,14 @@ create_baseObject(
                return 0;
        }
 
-       rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **) &p, LDAP_DN_FORMAT_LDAP );
+       rc = ldap_bv2rdn( &be->be_suffix[ 0 ], &rdn, (char **)&p,
+                       LDAP_DN_FORMAT_LDAP );
        if ( rc != LDAP_SUCCESS ) {
                snprintf( buf, sizeof(buf),
-                       "unable to extract RDN from baseObject DN \"%s\" (%d: %s)",
-                       be->be_suffix[ 0 ].bv_val, rc, ldap_err2string( rc ) );
+                       "unable to extract RDN "
+                       "from baseObject DN \"%s\" (%d: %s)",
+                       be->be_suffix[ 0 ].bv_val,
+                       rc, ldap_err2string( rc ) );
                Debug( LDAP_DEBUG_TRACE,
                        "<==backsql_db_config (%s line %d): %s\n",
                        fname, lineno, buf );
@@ -676,12 +753,14 @@ create_baseObject(
        
                        if ( rc != LDAP_SUCCESS ) {
                                snprintf( buf, sizeof(buf),
-                                       "prettying of attribute #%d from baseObject "
+                                       "prettying of attribute #%d "
+                                       "from baseObject "
                                        "DN \"%s\" failed: %d: %s",
                                        iAVA, be->be_suffix[ 0 ].bv_val,
                                        rc, ldap_err2string( rc ) );
                                Debug( LDAP_DEBUG_TRACE,
-                                       "<==backsql_db_config (%s line %d): %s\n",
+                                       "<==backsql_db_config (%s line %d): "
+                                       "%s\n",
                                        fname, lineno, buf );
                                return 1;
                        }