From 76a94de25197b88f8599cea2ff73962926b07614 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Thu, 2 Sep 1999 10:39:51 +0000 Subject: [PATCH] Fix: obey be->be_readonly. Also add & obey global_readonly. --- servers/slapd/add.c | 9 +++++++++ servers/slapd/config.c | 5 ++--- servers/slapd/delete.c | 9 +++++++++ servers/slapd/modify.c | 9 +++++++++ servers/slapd/modrdn.c | 9 +++++++++ servers/slapd/proto-slap.h | 1 + 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 1d37dad4e3..d02c9f4501 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -145,6 +145,15 @@ do_add( Connection *conn, Operation *op ) return rc; } + if ( global_readonly || be->be_readonly ) { + Debug( LDAP_DEBUG_ANY, "do_add: database is read-only\n", + 0, 0, 0 ); + entry_free( e ); + send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, + NULL, "database is read-only", NULL, NULL ); + return LDAP_UNWILLING_TO_PERFORM; + } + /* * do the add if 1 && (2 || 3) * 1) there is an add function implemented in this backend; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 9152336753..2da09086e6 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -28,6 +28,7 @@ int defsize = SLAPD_DEFAULT_SIZELIMIT; int deftime = SLAPD_DEFAULT_TIMELIMIT; AccessControl *global_acl = NULL; int global_default_access = ACL_READ; +int global_readonly = 0; char *replogfile; int global_lastmod = ON; int global_idletimeout = 0; @@ -366,9 +367,7 @@ read_config( const char *fname ) return( 1 ); } if ( be == NULL ) { - Debug( LDAP_DEBUG_ANY, -"%s: line %d: readonly line must appear inside a database definition (ignored)\n", - fname, lineno, 0 ); + global_readonly = (strcasecmp( cargv[1], "on" ) == 0); } else { if ( strcasecmp( cargv[1], "on" ) == 0 ) { be->be_readonly = 1; diff --git a/servers/slapd/delete.c b/servers/slapd/delete.c index 03d9c16ab5..2378475971 100644 --- a/servers/slapd/delete.c +++ b/servers/slapd/delete.c @@ -85,6 +85,15 @@ do_delete( return rc; } + if ( global_readonly || be->be_readonly ) { + Debug( LDAP_DEBUG_ANY, "do_delete: database is read-only\n", + 0, 0, 0 ); + free( ndn ); + send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, + NULL, "database is read-only", NULL, NULL ); + return LDAP_UNWILLING_TO_PERFORM; + } + /* deref suffix alias if appropriate */ ndn = suffix_alias( be, ndn ); diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 1316668523..f1e1a52a43 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -178,6 +178,14 @@ do_modify( return rc; } + if ( global_readonly || be->be_readonly ) { + Debug( LDAP_DEBUG_ANY, "do_modify: database is read-only\n", + 0, 0, 0 ); + send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, + NULL, "database is read-only", NULL, NULL ); + goto done; + } + /* deref suffix alias if appropriate */ ndn = suffix_alias( be, ndn ); @@ -235,6 +243,7 @@ do_modify( NULL, "Function not implemented", NULL, NULL ); } +done: free( ndn ); modlist_free( modlist ); return rc; diff --git a/servers/slapd/modrdn.c b/servers/slapd/modrdn.c index 5787516139..20c5249f89 100644 --- a/servers/slapd/modrdn.c +++ b/servers/slapd/modrdn.c @@ -181,6 +181,14 @@ do_modrdn( return rc; } + if ( global_readonly || be->be_readonly ) { + Debug( LDAP_DEBUG_ANY, "do_modrdn: database is read-only\n", + 0, 0, 0 ); + send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, + NULL, "database is read-only", NULL, NULL ); + goto done; + } + /* Make sure that the entry being changed and the newSuperior are in * the same backend, otherwise we return an error. */ @@ -247,6 +255,7 @@ do_modrdn( NULL, "Function not implemented", NULL, NULL ); } +done: free( ndn ); free( newrdn ); free( newSuperior ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 154d8b3bb1..feeabf5556 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -432,6 +432,7 @@ extern int defsize; extern int deftime; extern int g_argc; extern int global_default_access; +extern int global_readonly; extern int global_lastmod; extern int global_idletimeout; extern int global_schemacheck; -- 2.39.5