diff options
| author | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
|---|---|---|
| committer | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
| commit | b2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch) | |
| tree | cf58939393a9032182c4fbc4441164a9456e82f8 /ldap/servers/plugins/distrib | |
| download | ds-ldapserver7x.tar.gz ds-ldapserver7x.tar.xz ds-ldapserver7x.zip | |
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/servers/plugins/distrib')
20 files changed, 1016 insertions, 0 deletions
diff --git a/ldap/servers/plugins/distrib/Makefile b/ldap/servers/plugins/distrib/Makefile new file mode 100644 index 00000000..3144e8cb --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile @@ -0,0 +1,109 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# +# GNU Makefile for Directory Server distribution plugin +# + +LDAP_SRC = ../../.. +MCOM_ROOT = ../../../../.. + +NOSTDCLEAN=true # don't let nsconfig.mk define target clean +NOSTDSTRIP=true # don't let nsconfig.mk define target strip +NSPR20=true # probably should be defined somewhere else (not sure where) + +OBJDEST = $(OBJDIR)/lib/libdistrib +LIBDIR = $(LIB_RELDIR) + +include $(MCOM_ROOT)/ldapserver/nsconfig.mk +include $(LDAP_SRC)/nsldap.mk + +ifeq ($(ARCH), WINNT) +DEF_FILE:=./libdistrib.def +endif + +CFLAGS+=$(SLCFLAGS) + +INCLUDES += -I$(LDAP_SRC)/servers/slapd + +DIS_OBJS= \ + distrib.o + + +OBJS = $(addprefix $(OBJDEST)/, $(DIS_OBJS)) + +ifeq ($(ARCH), WINNT) +LIBDIS_DLL_OBJ = $(addprefix $(OBJDEST)/, dllmain.o) +endif + +# The sample distribution plugin is not part of DS. +# So we generate the shared library outside of $(LIBDIR) +# so that it's not retreived by the packaging makefiles. +#LIBDIS = $(addprefix $(LIBDIR)/, $(DIS_DLL).$(DLL_SUFFIX)) +LIBDIS = $(addprefix $(OBJDEST)/, $(DIS_DLL).$(DLL_SUFFIX)) + +ifeq ($(ARCH), WINNT) +EXTRA_LIBS_DEP += \ + $(LIBSLAPD_DEP) \ + $(LDAP_LIBUTIL_DEP) \ + $(LDAP_COMMON_LIBS_DEP) +EXTRA_LIBS_DEP += \ + $(LDAPSDK_DEP) \ + $(SECURITY_DEP) +EXTRA_LIBS += \ + $(LIBSLAPD) \ + $(LDAP_SDK_LIBLDAP_DLL) \ + $(LIBUTIL) \ + $(NSPRLINK) \ + $(LDAP_COMMON_LIBS) +endif +ifeq ($(ARCH), AIX) +EXTRA_LIBS_DEP += \ + $(LIBSLAPD_DEP) \ + $(LDAP_LIBUTIL_DEP) \ + $(LDAP_COMMON_LIBS_DEP) +EXTRA_LIBS_DEP += \ + $(LDAPSDK_DEP) +EXTRA_LIBS += \ + $(LIBSLAPDLINK) \ + $(LDAP_SDK_LIBLDAP_DLL) \ + $(LIBUTIL) \ + $(NSPRLINK) \ + $(LDAP_COMMON_LIBS) +endif + +ifeq ($(ARCH), HPUX) +EXTRA_LIBS_DEP += $(LIBSLAPD_DEP) $(LDAPSDK_DEP) $(NSPR_DEP) +EXTRA_LIBS += $(DYN_NSHTTPD) $(ADMINUTIL_LINK) $(LDAPLINK) $(NSPRLINK) $(ICULINK) +endif + +ifeq ($(ARCH), WINNT) +DLL_LDFLAGS += -def:"./libdistrib.def" +CFLAGS+= /WX +endif # WINNT + +ifeq ($(ARCH), AIX) +LD=ld +endif + +clientSDK: + +all: $(OBJDEST) $(LIBDIR) $(LIBDIS) + +$(LIBDIS): $(OBJS) $(LIBDIS_DLL_OBJ) $(DEF_FILE) + $(LINK_DLL) $(LIBDIS_DLL_OBJ) $(EXTRA_LIBS) + +veryclean: clean + +clean: + $(RM) $(OBJS) +ifeq ($(ARCH), WINNT) + $(RM) $(LIBDIS_DLL_OBJ) +endif + $(RM) $(LIBDIS) + +$(OBJDEST): + $(MKDIR) $(OBJDEST) diff --git a/ldap/servers/plugins/distrib/Makefile.AIX b/ldap/servers/plugins/distrib/Makefile.AIX new file mode 100644 index 00000000..d155626d --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.AIX @@ -0,0 +1,44 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# AIX Makefile for Directory Server plug-in examples +# NOTE: Make sure to set the DSLIB variable to the path +# to the libslapd_shr.a file (for example, +# DSLIB = /usr/netscape/suitespot/lib/libslapd_shr.a + +CC = xlC_r +LD = ld + +# Set this to the path to the libslapd_shr.a file +DSLIB = + +INCLUDE_FLAGS= -I../../include +CFLAGS= $(INCLUDE_FLAGS) -qarch=com +LIBPATH=/usr/lib/threads:/usr/lpp/xlC/lib:/usr/lib:/lib:..:../../../../lib +EXTRA_LIBS= -bI:/usr/lib/lowsys.exp -lC_r -lC -lpthreads -lc_r -lm \ + /usr/lib/libc.a $(DSLIB) +LDFLAGS= -bE:libtest-plugin_shr.exp -bM:SRE -bnoentry -blibpath:$(LIBPATH) \ + $(EXTRA_LIBS) + +OBJS = distrib + +all: libtest-plugin_shr.a + + +libtest-plugin_shr.a: $(OBJS) + rm -f libtest-plugin_shr.exp + echo "#!" > libtest-plugin_shr.exp + nm -B -C -g $(OBJS) | \ + awk '/ [B,T,D] / {print $$3}' | \ + sed -e 's/^\.//' | sort -u >> libtest-plugin_shr.exp + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin_shr.a + diff --git a/ldap/servers/plugins/distrib/Makefile.BSDI b/ldap/servers/plugins/distrib/Makefile.BSDI new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.BSDI @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.HPUX b/ldap/servers/plugins/distrib/Makefile.HPUX new file mode 100644 index 00000000..34c24521 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.HPUX @@ -0,0 +1,27 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# HPUX Makefile for Directory Server plug-in examples + +CC = cc +LD = ld + +INCLUDE = -I../../include +CFLAGS=$(INCLUDE) -D_HPUX_SOURCE -Aa +DA1.0 +z +LDFLAGS = -b + +OBJS = distrib.o + +all: libtest-plugin.sl + +libtest-plugin.sl: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.sl diff --git a/ldap/servers/plugins/distrib/Makefile.HPUX64 b/ldap/servers/plugins/distrib/Makefile.HPUX64 new file mode 100644 index 00000000..d6a09339 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.HPUX64 @@ -0,0 +1,27 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# HPUX Makefile for Directory Server plug-in examples + +CC = cc +LD = ld + +INCLUDE = -I../../include +CFLAGS=$(INCLUDE) -D_HPUX_SOURCE -Aa +DA2.0W +z +LDFLAGS = -b + +OBJS = distrib.o + +all: libtest-plugin.sl + +libtest-plugin.sl: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.sl diff --git a/ldap/servers/plugins/distrib/Makefile.IRIX b/ldap/servers/plugins/distrib/Makefile.IRIX new file mode 100644 index 00000000..f2ffc0c7 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.IRIX @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# IRIX Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_SGI_MP_SOURCE -fullwarn +LDFLAGS = -32 -shared + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.Linux b/ldap/servers/plugins/distrib/Makefile.Linux new file mode 100644 index 00000000..b5fe839f --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.Linux @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = gcc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.OSF1 b/ldap/servers/plugins/distrib/Makefile.OSF1 new file mode 100644 index 00000000..2c2c4660 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.OSF1 @@ -0,0 +1,29 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# OSF1 Makefile for Directory Server plug-in examples + +CC = cc +LD = ld + +INCLUDE = -I../../include +CFLAGS = $(INCLUDE) -DIS_64 -ieee_with_inexact -pthread -DOSF1 +LDFLAGS = -shared -all -expect_unresolved "*" -taso + + +OBJS = distrib.o + +all: libtest-plugin.so + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.ReliantUNIX b/ldap/servers/plugins/distrib/Makefile.ReliantUNIX new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.ReliantUNIX @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.SOLARIS b/ldap/servers/plugins/distrib/Makefile.SOLARIS new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.SOLARIS @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.SOLARIS64 b/ldap/servers/plugins/distrib/Makefile.SOLARIS64 new file mode 100644 index 00000000..170d2b47 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.SOLARIS64 @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC -xarch=v9 +LDFLAGS = -G -xarch=v9 + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.SOLARISx86 b/ldap/servers/plugins/distrib/Makefile.SOLARISx86 new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.SOLARISx86 @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.UnixWare b/ldap/servers/plugins/distrib/Makefile.UnixWare new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.UnixWare @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.UnixWareUDK b/ldap/servers/plugins/distrib/Makefile.UnixWareUDK new file mode 100644 index 00000000..c8016c9e --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.UnixWareUDK @@ -0,0 +1,30 @@ +# +# PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +# license terms. Copyright 2001 Sun Microsystems, Inc. +# Some preexisting portions Copyright 2001 Netscape Communications Corp. +# All rights reserved. +# +# SOLARIS Makefile for Directory Server plug-in examples +# + +CC = cc +LD = ld + +INCLUDE_FLAGS = -I../../include +CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC +LDFLAGS = -G + +OBJS = distrib.o + +all: libtest-plugin.so + + +libtest-plugin.so: $(OBJS) + $(LD) $(LDFLAGS) -o $@ $(OBJS) + +.c.o: + $(CC) $(CFLAGS) -c $< + +clean: + -rm -f $(OBJS) libtest-plugin.so + diff --git a/ldap/servers/plugins/distrib/Makefile.WINNT b/ldap/servers/plugins/distrib/Makefile.WINNT new file mode 100644 index 00000000..ddb02e29 --- /dev/null +++ b/ldap/servers/plugins/distrib/Makefile.WINNT @@ -0,0 +1,38 @@ +# Makefile for Directory Server plug-in +# + +CC = cl +LD = link + + +TARGET=libdistrib + +OBJS=distrib.obj + + +INC = ..\..\include +CFLAGS = /nologo -I $(INC) /c +LDFLAGS = /dll /nologo +LIBS=/DEFAULTLIB:kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ..\..\lib\libslapd.lib ..\..\lib\libnspr4.lib + + +all: \ + init \ + $(TARGET).dll + +init: + "c:\program files\microsoft visual studio\vc98\bin\vcvars32.bat" + + +$(TARGET).dll: $(OBJS) + $(LD) $(LDFLAGS) /def:$(TARGET).def /out:$(TARGET).dll $(LIBS) $(OBJS) + -rm -f $(OBJS2) *~ + +.c.obj: + $(CC) $(CFLAGS) $< + +clean: + del -f $(OBJS) $(TARGET).dll *~ + + + diff --git a/ldap/servers/plugins/distrib/README b/ldap/servers/plugins/distrib/README new file mode 100644 index 00000000..3ee6ff88 --- /dev/null +++ b/ldap/servers/plugins/distrib/README @@ -0,0 +1,23 @@ + ---------------------------- + Sample pluggable distribution logic + for Netscape Directory Server + ---------------------------- + +This directory contains code for some sample server plug-ins intended for +use with the Netscape Directory Server 7. + + NOTE: Before you compile and run these examples, make sure + to change any server-specific data in the examples to + values applicable to your Directory Server. + +distrib.c +---------- +This is an example of a distribution function that can be used +to distribute a flat namespace into several backends + +/** + * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to + * license terms. Copyright 2001 Sun Microsystems, Inc. + * Some preexisting portions Copyright 2001 Netscape Communications Corp. + * All rights reserved. + */ diff --git a/ldap/servers/plugins/distrib/distrib.c b/ldap/servers/plugins/distrib/distrib.c new file mode 100644 index 00000000..fd8ea5b6 --- /dev/null +++ b/ldap/servers/plugins/distrib/distrib.c @@ -0,0 +1,222 @@ +/** + * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to + * license terms. Copyright 2001 Sun Microsystems, Inc. + * Some preexisting portions Copyright 2001 Netscape Communications Corp. + * All rights reserved. + */ +#include <ctype.h> +#include <string.h> +#include "slapi-plugin.h" + +/* + * These are examples of distribution function as declared in mapping tree node + * This function will be called for every operations + * reaching this node, including subtree search operations that are started + * above this node + * + * Parameters : + * . pb is the pblock of the operation + * . target_dn is the target DN of the operation + * . mtn_be_names is the list of names of backends declared for this node + * . be_count is the number of backends declared + * . node_dn is the node where the distribution function is set + * + * The return value of the functions should be the indice of the backend + * in the mtn_be_names table + * For search operation, the value SLAPI_BE_ALL_BACKENDS can be used to + * specify that all backends must be searched + * The use of value SLAPI_BE_ALL_BACKENDS for operation other than search + * is not supported and may give random results + * + */ + +/* + * Distribute the entries based on the first letter of their rdn + * + * . Entries starting with anything other that a-z or A-Z will always + * go in backend 0 + * . Entries starting with letter (a-z or A-Z) will be shared between + * the backends depending following the alphabetic order + * Example : if 3 backends are used, entries starting with A-I will go + * in backend 0, entries starting with J-R will go in backend 1, entries + * starting with S-Z will go in backend 2 + * + * Of course this won't work for all locales... + * + * This example only works for a flat namespace below the node DN + */ +int alpha_distribution(Slapi_PBlock *pb, Slapi_DN * target_dn, + char **mtn_be_names, int be_count, Slapi_DN * node_dn) +{ + unsigned long op_type; + Slapi_Operation *op; + char *rdn_type; + char *rdn_value; + Slapi_RDN *rdn = NULL; + char c; + + /* first check the operation type + * searches at node level or above it should go in all backends + * searches below node level should go in only one backend + */ + slapi_pblock_get(pb, SLAPI_OPERATION, &op); + op_type = slapi_op_get_type(op); + if ((op_type == SLAPI_OPERATION_SEARCH) && + slapi_sdn_issuffix(node_dn, target_dn)) + return SLAPI_BE_ALL_BACKENDS; + + /* now choose the backend + * anything starting with a char different from a-z or A-Z will + * go in backend 0 + */ + + /* get the first char of first value of rdn */ + rdn = slapi_rdn_new(); + slapi_sdn_get_rdn(target_dn, rdn); + slapi_rdn_get_first(rdn, &rdn_type, &rdn_value); + c = rdn_value[0]; + + if (!(((c >= 'a') && (c <= 'z')) || + ((c >= 'A') && (c <= 'Z')) )) + { + return 0; + } + + slapi_rdn_free(&rdn); + + /* for entries with rdn starting with alphabetic characters + * use the formula : (c - 'A') * be_count/26 + * to calculate the backend number + */ + return (toupper(c) - 'A') * be_count/26; +} + +/* + * Distribute the entries based on a simple hash algorithme + */ +int hash_distribution(Slapi_PBlock *pb, Slapi_DN * target_dn, + char **mtn_be_names, int be_count, Slapi_DN * node_dn) +{ + unsigned long op_type; + Slapi_Operation *op; + char *rdn_type; + char *rdn_value; + Slapi_RDN *rdn = NULL; + int hash_value; + + /* first check the operation type + * searches at node level or above it should go in all backends + * searches below node level should go in only one backend + */ + slapi_pblock_get(pb, SLAPI_OPERATION, &op); + op_type = slapi_op_get_type(op); + if ((op_type == SLAPI_OPERATION_SEARCH) && + slapi_sdn_issuffix(node_dn, target_dn)) + return SLAPI_BE_ALL_BACKENDS; + + /* now choose the backend + */ + + /* get the rdn and hash it to compute the backend number + * use a simple hash for this example + */ + rdn = slapi_rdn_new(); + slapi_sdn_get_rdn(target_dn, rdn); + slapi_rdn_get_first(rdn, &rdn_type, &rdn_value); + + /* compute the hash value */ + hash_value = 0; + while (*rdn_value) + { + hash_value += *rdn_value; + rdn_value++; + } + hash_value = hash_value % be_count; + + slapi_rdn_free(&rdn); + + /* use the hash_value as the returned backend number */ + return hash_value; +} + +/* + * This plugin allows to use a local backend in conjonction with + * a chaining backend + * The ldbm backend is considered a read-only replica of the data + * The chaining backend point to a red-write replica of the data + * This distribution logic forward the update request to the chaining + * backend, and send the search request to the local dbm database + * + * The mechanism for updating the local read-only replica is not + * taken into account by this plugin + * + * To be able to use it one must define one ldbm backend and one chaining + * backend in the mapping tree node + * + */ +int chaining_distribution(Slapi_PBlock *pb, Slapi_DN * target_dn, + char **mtn_be_names, int be_count, Slapi_DN * node_dn) +{ + char * requestor_dn; + unsigned long op_type; + Slapi_Operation *op; + int repl_op = 0; + int local_backend = -1; + int chaining_backend = -1; + int i; + char * name; + + /* first, we have to decide which backend is the local backend + * and which is the chaining one + * For the purpose of this example use the backend name : + * the backend with name starting with ldbm is local + * the bakend with name starting with chaining is remote + */ + local_backend = -1; + chaining_backend = -1; + for (i=0; i<be_count; i++) + { + name = mtn_be_names[i]; + if ((0 == strncmp(name, "ldbm", 4)) || + (0 == strncmp(name, "user", 4))) + local_backend = i; + else if (0 == strncmp(name, "chaining", 8)) + chaining_backend = i; + } + + /* Check the operation type + * read-only operation will go to the local backend + * updates operation will go to the chaining backend + */ + slapi_pblock_get(pb, SLAPI_OPERATION, &op); + op_type = slapi_op_get_type(op); + if ((op_type == SLAPI_OPERATION_SEARCH) || + (op_type == SLAPI_OPERATION_BIND) || + (op_type == SLAPI_OPERATION_UNBIND) || + (op_type == SLAPI_OPERATION_COMPARE)) + return local_backend; + + /* if the operation is done by directory manager + * use local database even for updates because it is an administrative + * operation + * remarks : one could also use an update DN in the same way + * to let update operation go to the local backend when they are done + * by specific administrator user but let all the other user + * go to the read-write replica + */ + slapi_pblock_get( pb, SLAPI_REQUESTOR_DN, &requestor_dn ); + if (slapi_dn_isroot(requestor_dn)) + return local_backend; + + /* if the operation is a replicated operation + * use local database even for updates to avoid infinite loops + */ + slapi_pblock_get (pb, SLAPI_IS_REPLICATED_OPERATION, &repl_op); + if (repl_op) + return local_backend; + + /* all other case (update while not directory manager) : + * use the chaining backend + */ + return chaining_backend; +} diff --git a/ldap/servers/plugins/distrib/distrib.dsp b/ldap/servers/plugins/distrib/distrib.dsp new file mode 100644 index 00000000..ebf11f1e --- /dev/null +++ b/ldap/servers/plugins/distrib/distrib.dsp @@ -0,0 +1,116 @@ +# Microsoft Developer Studio Project File - Name="distrib" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=distrib - Win32 Release +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "distrib.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "distrib.mak" CFG="distrib - Win32 Release" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "distrib - Win32 Release" (based on\ + "Win32 (x86) Dynamic-Link Library") +!MESSAGE "distrib - Win32 Debug" (based on\ + "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "distrib - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir ".\Release" +# PROP BASE Intermediate_Dir ".\Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir ".\Release" +# PROP Intermediate_Dir ".\Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /YX /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_WIN32" /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ..\..\lib\libslapd.lib /nologo /subsystem:windows /dll /machine:I386 + +!ELSEIF "$(CFG)" == "distrib - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir ".\Debug" +# PROP BASE Intermediate_Dir ".\Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir ".\Debug" +# PROP Intermediate_Dir ".\Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /YX /c +# ADD CPP /nologo /MD /W3 /Gm /GX /Zi /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_WIN32" /YX /FD /c +# ADD BASE MTL /nologo /D "_DEBUG" /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /dll /debug /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib wsock32.lib ..\..\lib\libslapd.lib /nologo /subsystem:windows /dll /debug /machine:I386 + +!ENDIF + +# Begin Target + +# Name "distrib - Win32 Release" +# Name "distrib - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;hpj;bat;for;f90" +# Begin Source File + +SOURCE=.\dllmain.c +# End Source File +# Begin Source File + +SOURCE=.\distrib.c +# End Source File +# Begin Source File + +SOURCE=.\libdistrib.def +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl;fi;fd" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/ldap/servers/plugins/distrib/dllmain.c b/ldap/servers/plugins/distrib/dllmain.c new file mode 100644 index 00000000..bce5eed7 --- /dev/null +++ b/ldap/servers/plugins/distrib/dllmain.c @@ -0,0 +1,101 @@ +/** + * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to + * license terms. Copyright 2001 Sun Microsystems, Inc. + * Some preexisting portions Copyright 2001 Netscape Communications Corp. + * All rights reserved. + */ +/* + * Copyright (C) 2000 Sun Microsystems Inc. + * + * Use of this Source Code is subject to the terms of the applicable license + * agreement from Sun Microsystems Inc. + * + * The copyright notice(s) in this Source Code does not indicate actual or + * intended publication of this Source Code. + */ + + /* + * Microsoft Windows specifics + */ +#include "ldap.h" + + +#ifdef _WIN32 +/* Lifted from Q125688 + * How to Port a 16-bit DLL to a Win32 DLL + * on the MSVC 4.0 CD + */ +BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved) +{ + + switch (fdwReason) + { + case DLL_PROCESS_ATTACH: + /* Code from LibMain inserted here. Return TRUE to keep the + DLL loaded or return FALSE to fail loading the DLL. + + You may have to modify the code in your original LibMain to + account for the fact that it may be called more than once. + You will get one DLL_PROCESS_ATTACH for each process that + loads the DLL. This is different from LibMain which gets + called only once when the DLL is loaded. The only time this + is critical is when you are using shared data sections. + If you are using shared data sections for statically + allocated data, you will need to be careful to initialize it + only once. Check your code carefully. + + Certain one-time initializations may now need to be done for + each process that attaches. You may also not need code from + your original LibMain because the operating system may now + be doing it for you. + */ + /* + * 16 bit code calls UnlockData() + * which is mapped to UnlockSegment in windows.h + * in 32 bit world UnlockData is not defined anywhere + * UnlockSegment is mapped to GlobalUnfix in winbase.h + * and the docs for both UnlockSegment and GlobalUnfix say + * ".. function is oboslete. Segments have no meaning + * in the 32-bit environment". So we do nothing here. + */ + + break; + + case DLL_THREAD_ATTACH: + /* Called each time a thread is created in a process that has + already loaded (attached to) this DLL. Does not get called + for each thread that exists in the process before it loaded + the DLL. + + Do thread-specific initialization here. + */ + break; + + case DLL_THREAD_DETACH: + /* Same as above, but called when a thread in the process + exits. + + Do thread-specific cleanup here. + */ + break; + + case DLL_PROCESS_DETACH: + /* Code from _WEP inserted here. This code may (like the + LibMain) not be necessary. Check to make certain that the + operating system is not doing it for you. + */ + + break; + } + /* The return value is only used for DLL_PROCESS_ATTACH; all other + conditions are ignored. */ + return TRUE; /* successful DLL_PROCESS_ATTACH */ +} +#else +int CALLBACK +LibMain( HINSTANCE hinst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine ) +{ + /*UnlockData( 0 );*/ + return( 1 ); +} +#endif diff --git a/ldap/servers/plugins/distrib/libdistrib.def b/ldap/servers/plugins/distrib/libdistrib.def new file mode 100644 index 00000000..baef2027 --- /dev/null +++ b/ldap/servers/plugins/distrib/libdistrib.def @@ -0,0 +1,10 @@ +;------------------------------------------------------------------------- +; PROPRIETARY/CONFIDENTIAL. Use of this product is subject to +; license terms. Copyright 2001 Sun Microsystems, Inc. +; Some preexisting portions Copyright 2001 Netscape Communications Corp. +; All rights reserved. +;------------------------------------------------------------------------- +DESCRIPTION 'Netscape Directory Server 7 distribution logic example' +EXPORTS + alpha_distribution @1 + hash_distribution @2 |
