The NULL backend (for the cvs HEAD source as of 2002-04-04) ================ Written by Hallvard B. Furuseth and placed into the public domain. This software is not subject to any license of the University of Oslo. ================ The Null backend will surely be the most useful part of slapd: - Searches return success but no entries. - Compares return compareFalse. - Updates return success (unless readonly is on) but do nothing. - Binds fail unless the database option "bind on" is given. The "bind" option is "off" by default. Inspired by the /dev/null device. Hallvard B. Furuseth , April 2002. diff -u2 -r -N configure.in~ configure.in --- configure.in~ Thu Apr 4 11:15:40 2002 +++ configure.in Fri Apr 5 18:08:58 2002 @@ -200,4 +200,7 @@ OL_ARG_WITH(monitor_module,[ --with-monitor-module module type], static, [static dynamic]) +OL_ARG_ENABLE(null,[ --enable-null enable null backend], no)dnl +OL_ARG_WITH(null_module,[ --with-null-module module type], static, + [static dynamic]) OL_ARG_ENABLE(passwd,[ --enable-passwd enable passwd backend], no)dnl OL_ARG_WITH(passwd_module,[ --with-passwd-module module type], static, @@ -253,4 +256,7 @@ AC_MSG_WARN([slapd disabled, ignoring --enable-monitor argument]) fi + if test $ol_enable_null = yes ; then + AC_MSG_WARN([slapd disabled, ignoring --enable-null argument]) + fi if test $ol_enable_passwd = yes ; then AC_MSG_WARN([slapd disabled, ignoring --enable-passwd argument]) @@ -310,4 +316,7 @@ AC_MSG_WARN([slapd disabled, ignoring --with-monitor-module argument]) fi + if test $ol_with_null_module != static ; then + AC_MSG_WARN([slapd disabled, ignoring --with-null-module argument]) + fi if test $ol_with_passwd_module != static ; then AC_MSG_WARN([slapd disabled, ignoring --with-passwd-module argument]) @@ -339,4 +348,5 @@ ol_enable_meta=no ol_enable_monitor=no + ol_enable_null=no ol_enable_passwd=no ol_enable_perl=no @@ -362,4 +372,5 @@ ol_with_meta_module=static ol_with_monitor_module=static + ol_with_null_module=static ol_with_passwd_module=static ol_with_perl_module=static @@ -393,4 +404,5 @@ $ol_enable_meta = no -a \ $ol_enable_monitor = no -a \ + $ol_enable_null = no -a \ $ol_enable_passwd = no -a \ $ol_enable_perl = no -a \ @@ -507,4 +519,5 @@ BUILD_META=no BUILD_MONITOR=no +BUILD_NULL=no BUILD_PASSWD=no BUILD_PERL=no @@ -519,4 +532,5 @@ BUILD_META_DYNAMIC=static BUILD_MONITOR_DYNAMIC=static +BUILD_NULL_DYNAMIC=static BUILD_PASSWD_DYNAMIC=static BUILD_PERL_DYNAMIC=static @@ -735,4 +749,5 @@ ol_with_meta_module=static ol_with_monitor_module=static + ol_with_null_module=static ol_with_passwd_module=static ol_with_perl_module=static @@ -2600,4 +2615,20 @@ fi +if test "$ol_enable_null" != no ; then + AC_DEFINE(SLAPD_NULL,1,[define to support NULL backend]) + BUILD_SLAPD=yes + BUILD_NULL=yes + if test "$ol_with_null_module" != static ; then + AC_DEFINE(SLAPD_NULL_DYNAMIC,1, + [define to support dynamic NULL backend]) + BUILD_NULL=mod + BUILD_NULL_DYNAMIC=shared + SLAPD_MODULES_LIST="$SLAPD_MODULES_LIST -dlopen \$(SLAP_DIR)back-null/back_null.la" + SLAPD_DYNAMIC_BACKENDS="$SLAPD_DYNAMIC_BACKENDS back-null" + else + SLAPD_STATIC_BACKENDS="$SLAPD_STATIC_BACKENDS back-null" + fi +fi + if test "$ol_enable_passwd" != no ; then AC_DEFINE(SLAPD_PASSWD,1,[define to support PASSWD backend]) @@ -2716,4 +2747,5 @@ AC_SUBST(BUILD_META) AC_SUBST(BUILD_MONITOR) + AC_SUBST(BUILD_NULL) AC_SUBST(BUILD_PASSWD) AC_SUBST(BUILD_PERL) @@ -2727,4 +2759,5 @@ AC_SUBST(BUILD_META_DYNAMIC) AC_SUBST(BUILD_MONITOR_DYNAMIC) + AC_SUBST(BUILD_NULL_DYNAMIC) AC_SUBST(BUILD_PASSWD_DYNAMIC) AC_SUBST(BUILD_PERL_DYNAMIC) @@ -2814,4 +2847,5 @@ servers/slapd/back-meta/Makefile:build/top.mk:servers/slapd/back-meta/Makefile.in:build/mod.mk \ servers/slapd/back-monitor/Makefile:build/top.mk:servers/slapd/back-monitor/Makefile.in:build/mod.mk \ +servers/slapd/back-null/Makefile:build/top.mk:servers/slapd/back-null/Makefile.in:build/mod.mk \ servers/slapd/back-passwd/Makefile:build/top.mk:servers/slapd/back-passwd/Makefile.in:build/mod.mk \ servers/slapd/back-perl/Makefile:build/top.mk:servers/slapd/back-perl/Makefile.in:build/mod.mk \ diff -u2 -r -N include/portable.h.in~ include/portable.h.in --- include/portable.h.in~ Mon Feb 11 20:17:14 2002 +++ include/portable.h.in Fri Apr 5 18:10:50 2002 @@ -948,4 +948,10 @@ #undef SLAPD_MONITOR_DYNAMIC +/* define to support NULL backend */ +#undef SLAPD_NULL + +/* define to support dynamic NULL backend */ +#undef SLAPD_NULL_DYNAMIC + /* define to support PASSWD backend */ #undef SLAPD_PASSWD diff -u2 -r -N include/portable.nt~ include/portable.nt --- include/portable.nt~ Wed Jan 30 04:06:31 2002 +++ include/portable.nt Fri Apr 5 18:11:33 2002 @@ -961,4 +961,10 @@ /* #undef SLAPD_MONITOR_DYNAMIC */ +/* define to support NULL backend */ +/* #undef SLAPD_NULL */ + +/* define to support dynamic NULL backend */ +/* #undef SLAPD_NULL_DYNAMIC */ + /* define to support PASSWD backend */ /* #undef SLAPD_PASSWD */ diff -u2 -r -N servers/slapd/back-null/Makefile.in~ servers/slapd/back-null/Makefile.in --- servers/slapd/back-null/Makefile.in~ Thu Jan 1 01:00:00 1970 +++ servers/slapd/back-null/Makefile.in Fri Apr 5 18:36:38 2002 @@ -0,0 +1,26 @@ +SRCS = null.c +OBJS = null.lo + +LDAP_INCDIR= ../../../include +LDAP_LIBDIR= ../../../libraries + +BUILD_OPT = "--enable-null" +BUILD_MOD = @BUILD_NULL@ +BUILD_MOD_DYNAMIC = @BUILD_NULL_DYNAMIC@ + +mod_DEFS = -DSLAPD_IMPORT +MOD_DEFS = $(@BUILD_NULL@_DEFS) + +shared_LDAP_LIBS = $(LDAP_LIBPATH) -lldap_r -llber +NT_LINK_LIBS = -L.. -lslapd $(@BUILD_LIBS_DYNAMIC@_LDAP_LIBS) + +LIBBASE = back_null + +XINCPATH = -I.. -I$(srcdir)/.. +XDEFS = $(MODULES_CPPFLAGS) + +all-local-lib: ../.backend + +../.backend: lib$(LIBBASE).a + @touch $@ + diff -u2 -r -N servers/slapd/back-null/README~ servers/slapd/back-null/README --- servers/slapd/back-null/README~ Thu Jan 1 01:00:00 1970 +++ servers/slapd/back-null/README Fri Apr 5 19:23:35 2002 @@ -0,0 +1,14 @@ +Null Backend Interface for OpenLDAP + +The Null backend is surely the most useful part of slapd: +- Searches return success but no entries. +- Compares return compareFalse. +- Updates return success (unless readonly is on) but do nothing. +- Binds fail unless the database option "bind on" is given. + The "bind" option is "off" by default. +Inspired by the /dev/null device. + +slapd.conf example: + database null + suffix "cn=Nothing" + bind on diff -u2 -r -N servers/slapd/back-null/external.h~ servers/slapd/back-null/external.h --- servers/slapd/back-null/external.h~ Thu Jan 1 01:00:00 1970 +++ servers/slapd/back-null/external.h Fri Apr 5 15:40:13 2002 @@ -0,0 +1,33 @@ +/* + * Copyright 2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ +#ifndef _NULL_EXTERNAL_H +#define _NULL_EXTERNAL_H + +LDAP_BEGIN_DECL + +extern BI_init null_back_initialize; + +extern BI_db_init null_back_db_init; +extern BI_db_destroy null_back_db_destroy; + +extern BI_db_config null_back_db_config; + +extern BI_op_bind null_back_bind; + +extern BI_op_search null_back_search; + +extern BI_op_compare null_back_compare; + +extern BI_op_modify null_back_modify; + +extern BI_op_modrdn null_back_modrdn; + +extern BI_op_add null_back_add; + +extern BI_op_delete null_back_delete; + +LDAP_END_DECL + +#endif /* _NULL_EXTERNAL_H */ diff -u2 -r -N servers/slapd/back-null/null.c~ servers/slapd/back-null/null.c --- servers/slapd/back-null/null.c~ Thu Jan 1 01:00:00 1970 +++ servers/slapd/back-null/null.c Fri Apr 5 15:42:49 2002 @@ -0,0 +1,236 @@ +/* null.c - the null backend */ +/* + * Copyright 2002 The OpenLDAP Foundation, All Rights Reserved. + * COPYING RESTRICTIONS APPLY, see COPYRIGHT file + */ + +#include "portable.h" + +#include +#include + +#include "slap.h" +#include "external.h" + +struct null_info { + int bind_allowed; +}; + +int +null_back_bind( + Backend *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn, + int method, + struct berval *cred, + struct berval *edn +) +{ + struct null_info *ni = (struct null_info *) be->be_private; + + if( ni->bind_allowed ) + /* front end will send result on success (0) */ + return 0; + send_ldap_result( conn, op, LDAP_INVALID_CREDENTIALS, + NULL, NULL, NULL, NULL ); + return LDAP_INVALID_CREDENTIALS; +} + +int +null_back_add( + BackendDB *be, + Connection *conn, + Operation *op, + Entry *e ) +{ + send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL ); + return 0; +} + +int +null_back_compare( + BackendDB *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn, + AttributeAssertion *ava +) +{ + send_ldap_result( conn, op, LDAP_COMPARE_FALSE, NULL, NULL, NULL, NULL ); + return 0; +} + +int +null_back_delete( + BackendDB *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn +) +{ + send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL ); + return 0; +} + +int +null_back_modify( + BackendDB *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn, + Modifications *modlist ) +{ + send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL ); + return 0; +} + +int +null_back_modrdn( + Backend *be, + Connection *conn, + Operation *op, + struct berval *dn, + struct berval *ndn, + struct berval *newrdn, + struct berval *nnewrdn, + int deleteoldrdn, + struct berval *newSuperior, + struct berval *nnewSuperior ) +{ + send_ldap_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL ); + return 0; +} + +int +null_back_search( + BackendDB *be, + Connection *conn, + Operation *op, + struct berval *base, + struct berval *nbase, + int scope, + int deref, + int slimit, + int tlimit, + Filter *filter, + struct berval *filterstr, + AttributeName *attrs, + int attrsonly ) +{ + send_search_result( conn, op, LDAP_SUCCESS, NULL, NULL, NULL, NULL, 0 ); + return 1; +} + + +int +null_back_db_config( + BackendDB *be, + const char *fname, + int lineno, + int argc, + char **argv ) +{ + struct null_info *ni = (struct null_info *) be->be_private; + + if ( ni == NULL ) { + fprintf( stderr, "%s: line %d: null database info is null!\n", + fname, lineno ); + return 1; + } + + /* bind requests allowed */ + if ( strcasecmp( argv[0], "bind" ) == 0 ) { + if ( argc < 2 ) { + fprintf( stderr, + "%s: line %d: missing in \"bind \" line\n", + fname, lineno ); + return 1; + } + ni->bind_allowed = strcasecmp( argv[1], "off" ); + + /* anything else */ + } else { + fprintf( stderr, +"%s: line %d: unknown directive \"%s\" in null database definition (ignored)\n", + fname, lineno, argv[0] ); + } + + return 0; +} + + +int +null_back_db_init( BackendDB *be ) +{ + be->be_private = ch_calloc( 1, sizeof(struct null_info) ); + return 0; +} + +int +null_back_db_destroy( + Backend *be +) +{ + free( be->be_private ); + return 0; +} + + +int +null_back_initialize( + BackendInfo *bi +) +{ + bi->bi_open = 0; + bi->bi_close = 0; + bi->bi_config = 0; + bi->bi_destroy = 0; + + bi->bi_db_init = null_back_db_init; + bi->bi_db_config = null_back_db_config; + bi->bi_db_open = 0; + bi->bi_db_close = 0; + bi->bi_db_destroy = null_back_db_destroy; + + bi->bi_op_bind = null_back_bind; + bi->bi_op_unbind = 0; + bi->bi_op_search = null_back_search; + bi->bi_op_compare = null_back_compare; + bi->bi_op_modify = null_back_modify; + bi->bi_op_modrdn = null_back_modrdn; + bi->bi_op_add = null_back_add; + bi->bi_op_delete = null_back_delete; + bi->bi_op_abandon = 0; + + bi->bi_extended = 0; + + bi->bi_acl_group = 0; + bi->bi_acl_attribute = 0; + bi->bi_chk_referrals = 0; + + bi->bi_connection_init = 0; + bi->bi_connection_destroy = 0; + + return 0; +} + +#ifdef SLAPD_NULL_DYNAMIC +int back_null_LTX_init_module( + int argc, + char *argv[] ) +{ + BackendInfo bi; + + memset( &bi, '\0', sizeof(bi) ); + bi.bi_type = "null"; + bi.bi_init = null_back_initialize; + + backend_add(&bi); + return 0; +} +#endif /* SLAPD_NULL_DYNAMIC */ diff -u2 -r -N servers/slapd/backend.c~ servers/slapd/backend.c --- servers/slapd/backend.c~ Mon Mar 18 08:59:02 2002 +++ servers/slapd/backend.c Fri Apr 5 15:34:43 2002 @@ -45,4 +45,7 @@ #include "back-monitor/external.h" #endif +#if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC) +#include "back-null/external.h" +#endif #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC) #include "back-passwd/external.h" @@ -82,4 +85,7 @@ #if defined(SLAPD_MONITOR) && !defined(SLAPD_MONITOR_DYNAMIC) {"monitor", monitor_back_initialize}, +#endif +#if defined(SLAPD_NULL) && !defined(SLAPD_NULL_DYNAMIC) + {"null", null_back_initialize}, #endif #if defined(SLAPD_PASSWD) && !defined(SLAPD_PASSWD_DYNAMIC)