]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-sql/config.c
ITS#4384 rework entryCSN handling, retrieve from incoming request
[openldap] / servers / slapd / back-sql / config.c
index c45c70716eb84d2bbf2f6707d935a09371cd959c..817435f94c538ddce3a43db78f5553a2e5a0180e 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1999-2005 The OpenLDAP Foundation.
+ * Copyright 1999-2006 The OpenLDAP Foundation.
  * Portions Copyright 1999 Dmitry Kovalev.
  * Portions Copyright 2002 Pierangelo Masarati.
  * Portions Copyright 2004 Mark Adamson.
@@ -53,7 +53,7 @@ backsql_db_config(
        backsql_info    *bi = (backsql_info *)be->be_private;
 
        Debug( LDAP_DEBUG_TRACE, "==>backsql_db_config()\n", 0, 0, 0 );
-       assert( bi );
+       assert( bi != NULL );
   
        if ( !strcasecmp( argv[ 0 ], "dbhost" ) ) {
                if ( argc < 2 ) {
@@ -291,37 +291,37 @@ 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") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "has_ldapinfo_dn_ru" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -352,7 +352,7 @@ backsql_db_config(
                        "has_ldapinfo_dn_ru=%s\n", 
                        BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ? "yes" : "no", 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fail_if_no_mapping" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -381,7 +381,7 @@ backsql_db_config(
                        "fail_if_no_mapping=%s\n", 
                        BACKSQL_FAIL_IF_NO_MAPPING( bi ) ? "yes" : "no", 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "allow_orphans") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "allow_orphans" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -443,7 +443,7 @@ backsql_db_config(
                        return 1;
                }
 
-       } else if ( !strcasecmp( argv[ 0 ], "sqllayer") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "sqllayer" ) ) {
                if ( backsql_api_config( bi, argv[ 1 ], argc - 2, &argv[ 2 ] ) )
                {
                        Debug( LDAP_DEBUG_TRACE,
@@ -466,7 +466,7 @@ backsql_db_config(
                Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
                        "id_query=%s\n", bi->sql_id_query, 0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "use_subtree_shortcut" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -496,7 +496,7 @@ backsql_db_config(
                        BACKSQL_USE_SUBTREE_SHORTCUT( bi ) ? "yes" : "no",
                        0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_all_attrs" ) ) {
                if ( argc < 2 ) {
                        Debug( LDAP_DEBUG_TRACE,
                                "<==backsql_db_config (%s line %d): "
@@ -526,7 +526,7 @@ backsql_db_config(
                        BACKSQL_FETCH_ALL_ATTRS( bi ) ? "yes" : "no",
                        0, 0 );
 
-       } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs") ) {
+       } else if ( !strcasecmp( argv[ 0 ], "fetch_attrs" ) ) {
                char    *str, *s, *next;
                char    delimstr[] = ",";
 
@@ -561,6 +561,71 @@ backsql_db_config(
                        return -1;
                }
 
+       } else if ( !strcasecmp( argv[ 0 ], "check_schema" ) ) {
+               if ( argc != 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing { yes | no }"
+                               "in \"check_schema\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( strcasecmp( argv[ 1 ], "yes" ) == 0 ) {
+                       bi->sql_flags |= BSQLF_CHECK_SCHEMA;
+
+               } else if ( strcasecmp( argv[ 1 ], "no" ) == 0 ) {
+                       bi->sql_flags &= ~BSQLF_CHECK_SCHEMA;
+
+               } else {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "\"check_schema\" directive arg "
+                               "must be \"yes\" or \"no\"\n",
+                               fname, lineno, 0 );
+                       return 1;
+
+               }
+               Debug( LDAP_DEBUG_TRACE, "<==backsql_db_config(): "
+                       "check_schema=%s\n", 
+                       BACKSQL_CHECK_SCHEMA( bi ) ? "yes" : "no",
+                       0, 0 );
+
+       } else if ( !strcasecmp( argv[ 0 ], "aliasing_keyword" ) ) {
+               if ( argc != 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing arg "
+                               "in \"aliasing_keyword <string>\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( ! BER_BVISNULL( &bi->sql_aliasing ) ) {
+                       ch_free( bi->sql_aliasing.bv_val );
+               }
+
+               ber_str2bv( argv[ 1 ], strlen( argv[ 1 ] ) + 1, 1,
+                       &bi->sql_aliasing );
+               /* add a trailing space... */
+               bi->sql_aliasing.bv_val[ bi->sql_aliasing.bv_len - 1] = ' ';
+
+       } else if ( !strcasecmp( argv[ 0 ], "aliasing_quote" ) ) {
+               if ( argc != 2 ) {
+                       Debug( LDAP_DEBUG_TRACE,
+                               "<==backsql_db_config (%s line %d): "
+                               "missing arg "
+                               "in \"aliasing_quote <string>\" directive\n",
+                               fname, lineno, 0 );
+                       return 1;
+               }
+
+               if ( ! BER_BVISNULL( &bi->sql_aliasing_quote ) ) {
+                       ch_free( bi->sql_aliasing_quote.bv_val );
+               }
+
+               ber_str2bv( argv[ 1 ], 0, 1, &bi->sql_aliasing_quote );
+
        } else {
                return SLAP_CONF_UNKNOWN;
        }
@@ -580,13 +645,13 @@ read_baseObject(
        const char      *fname )
 {
        backsql_info    *bi = (backsql_info *)be->be_private;
-       FILE            *fp;
+       LDIFFP          *fp;
        int             rc = 0, lineno = 0, lmax = 0;
        char            *buf = NULL;
 
-       assert( fname );
+       assert( fname != NULL );
 
-       fp = fopen( fname, "r" );
+       fp = ldif_open( fname, "r" );
        if ( fp == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "could not open back-sql baseObject "
@@ -600,7 +665,7 @@ read_baseObject(
        if ( bi->sql_baseObject == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "read_baseObject_file: SLAP_CALLOC failed", 0, 0, 0 );
-               fclose( fp );
+               ldif_close( fp );
                return LDAP_NO_MEMORY;
        }
        bi->sql_baseObject->e_name = be->be_suffix[0];
@@ -658,7 +723,7 @@ read_baseObject(
 
        ch_free( buf );
 
-       fclose( fp );
+       ldif_close( fp );
 
        Debug( LDAP_DEBUG_CONFIG, "back-sql baseObject file \"%s\" read.\n",
                        fname, 0, 0 );
@@ -723,7 +788,7 @@ create_baseObject(
                struct berval                   bv = BER_BVNULL;
                const char                      *text = NULL;
 
-               assert( ava );
+               assert( ava != NULL );
 
                rc = slap_bv2ad( &ava->la_attr, &ad, &text );
                if ( rc != LDAP_SUCCESS ) {