summaryrefslogtreecommitdiffstats
path: root/ldap/servers/slapd/test-plugins
diff options
context:
space:
mode:
authorcvsadm <cvsadm>2005-01-21 00:44:34 +0000
committercvsadm <cvsadm>2005-01-21 00:44:34 +0000
commitb2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch)
treecf58939393a9032182c4fbc4441164a9456e82f8 /ldap/servers/slapd/test-plugins
downloadds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.gz
ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.xz
ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.zip
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/servers/slapd/test-plugins')
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile51
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.AIX36
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.BSDI31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.HPUX25
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.HPUX6424
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.IRIX31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.Linux31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.OSF130
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.ReliantUNIX31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.SOLARIS28
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.SOLARIS6428
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.SOLARISx8631
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.UnixWare31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.UnixWareUDK31
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.WINNT45
-rw-r--r--ldap/servers/slapd/test-plugins/Makefile.server107
-rw-r--r--ldap/servers/slapd/test-plugins/README149
-rw-r--r--ldap/servers/slapd/test-plugins/clients/README45
-rw-r--r--ldap/servers/slapd/test-plugins/clients/ReqExtOp.java77
-rw-r--r--ldap/servers/slapd/test-plugins/clients/reqextop.c85
-rw-r--r--ldap/servers/slapd/test-plugins/dllmain.c109
-rwxr-xr-xldap/servers/slapd/test-plugins/installDse.pl129
-rw-r--r--ldap/servers/slapd/test-plugins/nicknames10
-rw-r--r--ldap/servers/slapd/test-plugins/testbind.c252
-rw-r--r--ldap/servers/slapd/test-plugins/testdatainterop.c312
-rw-r--r--ldap/servers/slapd/test-plugins/testdbinterop.c102
-rw-r--r--ldap/servers/slapd/test-plugins/testdbinterop.h22
-rw-r--r--ldap/servers/slapd/test-plugins/testentry.c133
-rw-r--r--ldap/servers/slapd/test-plugins/testextendedop.c188
-rw-r--r--ldap/servers/slapd/test-plugins/testgetip.c141
-rw-r--r--ldap/servers/slapd/test-plugins/testplugin.def16
-rw-r--r--ldap/servers/slapd/test-plugins/testplugin.dsp143
-rw-r--r--ldap/servers/slapd/test-plugins/testplugin.mak431
-rw-r--r--ldap/servers/slapd/test-plugins/testpostop.c386
-rw-r--r--ldap/servers/slapd/test-plugins/testpreop.c215
-rw-r--r--ldap/servers/slapd/test-plugins/testsaslbind.c145
36 files changed, 3681 insertions, 0 deletions
diff --git a/ldap/servers/slapd/test-plugins/Makefile b/ldap/servers/slapd/test-plugins/Makefile
new file mode 100644
index 00000000..8b78aada
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile
@@ -0,0 +1,51 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+#
+# GNU Makefile for Directory Server test-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)/servers/obj
+BINDIR = $(OBJDIR)/bin
+LIBDIR = $(OBJDIR)/lib
+
+include $(MCOM_ROOT)/ldapserver/nsdefs.mk
+include $(MCOM_ROOT)/ldapserver/nsconfig.mk
+include $(LDAP_SRC)/nsldap.mk
+include $(MCOM_ROOT)/ldapserver/ns_usepurify.mk
+include $(MCOM_ROOT)/ldapserver/ns_usedb.mk
+
+
+EXTRA_INCLUDES=-I.. -I../../../include $(NSPR_INCLUDE) -I$(LDAP_INCLUDE) -I$(DB_INCLUDE) -I../../../servers/slapd -g
+INCLUDE_FLAGS=-I../include $(EXTRA_INCLUDES)
+EXTRA_LIBS = $(DB_LIB)
+
+ifdef USE_64
+MAKEFILE_FILE=Makefile.$(BUILD_ARCH)64
+else
+MAKEFILE_FILE=Makefile.$(BUILD_ARCH)
+endif
+
+all:
+ $(MAKE) -f $(MAKEFILE_FILE) all INCLUDE_FLAGS="$(INCLUDE_FLAGS)" EXTRA_LIBS="$(EXTRA_LIBS)"
+
+libtest-plugin.so:
+ $(MAKE) -f $(MAKEFILE_FILE) libtest-plugin.so \
+ INCLUDE_FLAGS="$(INCLUDE_FLAGS)"
+
+clean:
+ $(MAKE) -f $(MAKEFILE_FILE) clean INCLUDE_FLAGS="$(INCLUDE_FLAGS)"
+
+veryclean: clean
+
diff --git a/ldap/servers/slapd/test-plugins/Makefile.AIX b/ldap/servers/slapd/test-plugins/Makefile.AIX
new file mode 100644
index 00000000..31a64146
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.AIX
@@ -0,0 +1,36 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# AIX Makefile for Directory Server plug-in examples
+
+INCLUDE_FLAGS= -I../include
+CFLAGS= $(INCLUDE_FLAGS) -D_THREAD_SAFE -qansialias -langlvl=ansi -qro -qroconst -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
+LDFLAGS= -bE:libtest-plugin_shr.exp -G -bnoentry -blibpath:$(LIBPATH) \
+ $(EXTRA_LIBS)
+
+OBJS = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.o
+
+all: libtest-plugin.so
+
+
+libtest-plugin.so: $(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.so libtest-plugin_shr.exp
+
diff --git a/ldap/servers/slapd/test-plugins/Makefile.BSDI b/ldap/servers/slapd/test-plugins/Makefile.BSDI
new file mode 100644
index 00000000..0433e752
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.BSDI
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.HPUX b/ldap/servers/slapd/test-plugins/Makefile.HPUX
new file mode 100644
index 00000000..06df5a21
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.HPUX
@@ -0,0 +1,25 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# HPUX Makefile for Directory Server plug-in examples
+
+INCLUDE = -I../include
+CFLAGS=$(INCLUDE) -D_HPUX_SOURCE -Aa +z +DAportable -Ae
+LDFLAGS = -b
+
+OBJS = testsaslbind.o testpreop.o testpostop.o testextendedop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.HPUX64 b/ldap/servers/slapd/test-plugins/Makefile.HPUX64
new file mode 100644
index 00000000..2e9fc329
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.HPUX64
@@ -0,0 +1,24 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# HPUX Makefile for Directory Server plug-in examples
+
+CFLAGS=$(INCLUDE_FLAGS) -D_HPUX_SOURCE -Aa +z +DA2.0W -Ae
+LDFLAGS = +k -b +s $(EXTRA_LIBS)
+
+OBJS = testsaslbind.o testpreop.o testpostop.o testextendedop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.IRIX b/ldap/servers/slapd/test-plugins/Makefile.IRIX
new file mode 100644
index 00000000..820e5d1b
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.IRIX
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.Linux b/ldap/servers/slapd/test-plugins/Makefile.Linux
new file mode 100644
index 00000000..1e3de457
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.Linux
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# Linux Makefile for Directory Server plug-in examples
+#
+
+CC = gcc
+LD = ld
+
+INCLUDE_FLAGS = -I../include
+CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -fPIC
+LDFLAGS = -G
+
+OBJS = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.OSF1 b/ldap/servers/slapd/test-plugins/Makefile.OSF1
new file mode 100644
index 00000000..a1765d2e
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.OSF1
@@ -0,0 +1,30 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testpreop.o testpostop.o testextendedop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.ReliantUNIX b/ldap/servers/slapd/test-plugins/Makefile.ReliantUNIX
new file mode 100644
index 00000000..0433e752
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.ReliantUNIX
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.SOLARIS b/ldap/servers/slapd/test-plugins/Makefile.SOLARIS
new file mode 100644
index 00000000..1914f3b2
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.SOLARIS
@@ -0,0 +1,28 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# SOLARIS Makefile for Directory Server plug-in examples
+#
+
+INCLUDE_FLAGS = -I../include
+CFLAGS = $(INCLUDE_FLAGS) -D_REENTRANT -KPIC
+LDFLAGS = -G
+
+OBJS = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.SOLARIS64 b/ldap/servers/slapd/test-plugins/Makefile.SOLARIS64
new file mode 100644
index 00000000..151ea5b1
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.SOLARIS64
@@ -0,0 +1,28 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# SOLARIS Makefile for Directory Server plug-in examples
+#
+
+INCLUDE_FLAGS = -I../include
+CFLAGS = $(INCLUDE_FLAGS) -xarch=v9 -D_REENTRANT -KPIC
+LDFLAGS = -G -xarch=v9
+
+OBJS = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.SOLARISx86 b/ldap/servers/slapd/test-plugins/Makefile.SOLARISx86
new file mode 100644
index 00000000..0433e752
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.SOLARISx86
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.UnixWare b/ldap/servers/slapd/test-plugins/Makefile.UnixWare
new file mode 100644
index 00000000..0433e752
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.UnixWare
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.UnixWareUDK b/ldap/servers/slapd/test-plugins/Makefile.UnixWareUDK
new file mode 100644
index 00000000..0433e752
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.UnixWareUDK
@@ -0,0 +1,31 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# 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 = testsaslbind.o testextendedop.o testpreop.o testpostop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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/slapd/test-plugins/Makefile.WINNT b/ldap/servers/slapd/test-plugins/Makefile.WINNT
new file mode 100644
index 00000000..d18d7ea7
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.WINNT
@@ -0,0 +1,45 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# Makefile for Directory Server plug-in
+#
+
+CC = cl
+LD = link
+
+
+TARGET=testplugin
+
+OBJS=testsaslbind.obj testextendedop.obj testpreop.obj testpostop.obj testentry.obj testbind.obj testgetip.obj testdatainterop.obj testdbinterop.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 ./lib/libdb42.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 $(EXTRA_LIBS) $(LIBS) $(OBJS)
+ -rm -f $(OBJS2) *~
+
+%.obj:%.c
+ $(CC) $(CFLAGS) $<
+
+clean:
+ del -f $(OBJS) $(TARGET).dll *~
+
+
+
diff --git a/ldap/servers/slapd/test-plugins/Makefile.server b/ldap/servers/slapd/test-plugins/Makefile.server
new file mode 100644
index 00000000..4923aa38
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/Makefile.server
@@ -0,0 +1,107 @@
+#
+# 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/libtestplug
+LIBDIR = $(LIB_RELDIR)
+
+include $(MCOM_ROOT)/ldapserver/nsconfig.mk
+include $(LDAP_SRC)/nsldap.mk
+include $(MCOM_ROOT)/ldapserver/ns_usedb.mk
+
+ifeq ($(ARCH), WINNT)
+DEF_FILE:=./libdistrib.def
+endif
+
+CFLAGS+=$(SLCFLAGS)
+
+INCLUDES += -I$(LDAP_SRC)/servers/slapd -I$(DB_INCLUDE)
+
+DIS_OBJS= \
+ testsaslbind.o testpreop.o testpostop.o testextendedop.o testentry.o testbind.o testgetip.o testdatainterop.o testdbinterop.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)/, $(TEST_PLUGIN_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
+
+EXTRA_LIBS_DEP += $(LIBSLAPD_DEP) $(LDAPSDK_DEP) $(NSPR_DEP) $(DB_LIB_DEP)
+EXTRA_LIBS += $(DYN_NSHTTPD) $(ADMINUTIL_LINK) $(LDAPLINK) $(NSPRLINK) $(ICULINK) $(DB_LIB)
+
+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/slapd/test-plugins/README b/ldap/servers/slapd/test-plugins/README
new file mode 100644
index 00000000..ecdcac58
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/README
@@ -0,0 +1,149 @@
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+
+ ----------------------------
+ Sample Server Plug-Ins
+ for Directory Server 7
+ ----------------------------
+
+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.
+
+testbind.c
+----------
+This is an example of a pre-operation bind plug-in function that
+handles authentication. When processing an LDAP bind request, the
+server calls this plug-in function before calling the database bind
+function.
+
+testentry.c
+-----------
+This is an example of an entry store plug-in function and an entry fetch
+plug-in function. You must be using the default database (not your own
+back-end database) in order for these plug-in functions to work.
+
+testextendedop.c
+----------------
+This is an example of an extended operation plug-in function that
+handles requests for the extended operation with the OID 1.2.3.4.
+The example should be used in conjunction with the reqextop.c and
+ReqExtOp.java clients (the source code for these clients is located
+in the clients subdirectory). These clients are capable of requesting
+the extended operation with the OID 1.2.3.4.
+
+testpostop.c
+------------
+This contains examples of post-operation plug-in functions. These
+functions are called after the server processes LDAP operations.
+The functions log changes to the directory in a change log file.
+
+testpreop.c
+-----------
+This contains examples of pre-operation plug-in functions. These
+functions are called before the server processes LDAP operations.
+
+testsaslbind.c
+--------------
+This is an example of a pre-operation plug-in function that
+implements a SASL mechanism.
+
+clients
+-------
+This directory contains the C and Java source code for clients
+that you can use to test the server plug-ins. See the README
+file in that directory for details.
+
+
+ ----------------------------
+ How To Create
+ A Server Plug-In
+ ----------------------------
+
+Text between brackets ([]) should be replaced with values specific to
+your situation.
+
+
+Creating the Plug-In Library
+----------------------------
+Server plug-ins are built as libraries available to the server.
+
+1. Include the Plug-In API. For example:
+
+ #include "[serverRoot]/plugins/slapd/slapi/include/slapi-plugin.h"
+
+2. Write your plug-in, including a top level initialization function
+ used by the server to start the plug-in. For example:
+
+ /* Plug-in functions defined here */
+
+ int my_plugin_init( Slapi_PBlock *pb ) /* initialize param. block */
+ {
+ /* Set or get the parameters in pb */
+ slapi_pblock_set();
+ slapi_pblock_get();
+
+ /* Plug-in functions registered here */
+
+ if (error)
+ {
+ slapi_log_error();
+ return error_code;
+ }
+ else return 0;
+
+ } /* my_plugin_init() */
+
+ See the Parameter Block Reference in the Netscape Directory Server
+ Plug-In Programmer's Guide for hints on plug-in types.
+
+3. Build the plug-in as a library.
+
+ We recommend you copy and adapt the Makefile in
+ [serverRoot]/plugins/slapd/slapi/examples.
+
+
+Plugging the Library Into the Server
+------------------------------------
+When started, the server loads plug-ins.
+
+1. Stop the server.
+
+ Console: Select the server; Object > Stop Server
+ Command Line: cd [serverRoot]/slapd-[serverID] ; ./stop-slapd
+
+2. Add the entry for the server plug-in to
+ [serverRoot]/slapd-[serverID]/config/dse.ldif. For example:
+
+ dn: cn=[My Server Plugin],cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: [My Server Plugin]
+ nsslapd-pluginPath: [[serverRoot]/myPlugins/myveryown-plugin.so]
+ nsslapd-pluginInitfunc: [my_plugin_init]
+ nsslapd-pluginType: [myPluginType]
+ nsslapd-pluginEnabled: on
+ nsslapd-pluginarg0: [uid]
+ nsslapd-pluginarg1: [mail]
+ nsslapd-pluginarg2: [...]
+ nsslapd-plugin-depends-on-type: [anotherPluginType]
+ nsslapd-pluginId: [MyFirstServerPlugin]
+ nsslapd-pluginVersion: [0.1]
+ nsslapd-pluginVendor: [Fictional Software Company Incorporated]
+ nsslapd-pluginDescription: [Add lots of cool functionality]
+
+ See the Parameter Block Reference in the Netscape Directory Server
+ Plug-In Programmer's Guide for hints on plug-in types.
+
+3. Restart the server.
+
+ Console: Object > Start Server
+ Command Line: cd [serverRoot]/slapd-[serverID] ; ./restart-slapd
diff --git a/ldap/servers/slapd/test-plugins/clients/README b/ldap/servers/slapd/test-plugins/clients/README
new file mode 100644
index 00000000..a2aac49d
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/clients/README
@@ -0,0 +1,45 @@
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+ ---------------------------
+ Sample LDAP Clients That
+ Work with Server Plug-Ins
+ ---------------------------
+
+This directory contains code for some sample LDAP clients intended for
+use with the sample server plug-ins. For example, one of the server
+plug-ins handles requests for an extended operation with the OID 1.2.3.4.
+In order to test this sample plug-in, you need an LDAP v3 client that is
+capable of requesting this extended operation.
+
+ NOTE: Before you compile and run these examples, make sure
+ to change the server name, port number, root DN, and root DN
+ password to values applicable to your Directory Server.
+
+reqextop.c
+----------
+This is an example of an LDAP client that requests extended operations.
+The example should be used in conjunction with the testexop.c server
+plug-in, which handles the extended operation with the OID 1.2.3.4.
+
+This example requires a version of the Netscape Directory SDK that supports
+the LDAP v3 protocol. The 3.0 Beta version of the Directory SDK for C
+supports LDAP v3 and is available at the following location:
+
+ http://developer.netscape.com/tech/directory/
+
+ReqExtOp.java
+-------------
+This is an example of an LDAP client that requests extended operations.
+The example should be used in conjunction with the testexop.c server
+plug-in, which handles the extended operation with the OID 1.2.3.4.
+
+This example requires a version of the Netscape Directory SDK that supports
+the LDAP v3 protocol. The Netscape Directory SDK for Java 3.0 supports
+LDAP v3 and is available at the following location:
+
+ http://developer.netscape.com/tech/directory/
+
diff --git a/ldap/servers/slapd/test-plugins/clients/ReqExtOp.java b/ldap/servers/slapd/test-plugins/clients/ReqExtOp.java
new file mode 100644
index 00000000..cf29ea21
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/clients/ReqExtOp.java
@@ -0,0 +1,77 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/*
+ *
+ * Requests an extended operation with the OID 1.2.3.4.
+ * Use this client in conjunction with a server that can process
+ * this extended operation.
+ *
+ */
+
+import netscape.ldap.*;
+import java.util.*;
+import java.io.*;
+
+public class ReqExtOp {
+ public static void main( String[] args )
+ {
+ LDAPConnection ld = null;
+ int status = -1;
+ try {
+ ld = new LDAPConnection();
+
+ /* Connect to server */
+ String MY_HOST = "localhost";
+ int MY_PORT = 389;
+ ld.connect( MY_HOST, MY_PORT );
+ System.out.println( "Connected to server." );
+
+ /* Authenticate to the server as directory manager */
+ String MGR_DN = "cn=Directory Manager";
+ String MGR_PW = "23skidoo";
+ if ( ld.LDAP_VERSION < 3 ) {
+ ld.authenticate( 3, MGR_DN, MGR_PW );
+ } else {
+ System.out.println( "Specified LDAP server does not support v3 of the LDAP protocol." );
+ ld.disconnect();
+ System.exit(1);
+ }
+ System.out.println( "Authenticated to directory." );
+
+ /* Create an extended operation object */
+ String myval = "My Value";
+ byte vals[] = myval.getBytes( "UTF8" );
+ LDAPExtendedOperation exop = new LDAPExtendedOperation( "1.2.3.4", vals );
+ System.out.println( "Created LDAPExtendedOperation object." );
+
+ /* Request the extended operation from the server. */
+ LDAPExtendedOperation exres = ld.extendedOperation( exop );
+
+ System.out.println( "Performed extended operation." );
+
+ /* Get data from the response sent by the server. */
+ System.out.println( "OID: " + exres.getID() );
+ String retValue = new String( exres.getValue(), "UTF8" );
+ System.out.println( "Value: " + retValue );
+ }
+ catch( LDAPException e ) {
+ System.out.println( "Error: " + e.toString() );
+ }
+ catch( UnsupportedEncodingException e ) {
+ System.out.println( "Error: UTF8 not supported" );
+ }
+
+ /* Done, so disconnect */
+ if ( (ld != null) && ld.isConnected() ) {
+ try {
+ ld.disconnect();
+ } catch ( LDAPException e ) {
+ System.out.println( "Error: " + e.toString() );
+ }
+ }
+ System.exit(status);
+ }
+}
diff --git a/ldap/servers/slapd/test-plugins/clients/reqextop.c b/ldap/servers/slapd/test-plugins/clients/reqextop.c
new file mode 100644
index 00000000..f23bcf38
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/clients/reqextop.c
@@ -0,0 +1,85 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/*
+ * Requests an extended operation with the OID 1.2.3.4.
+ * Use this client in conjunction with a server that can process
+ * this extended operation.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include <ldap.h>
+
+/* Name and port of the LDAP server you want to connect to. */
+#define MY_HOST "localhost"
+#define MY_PORT 389
+
+/* DN of user (and password of user) who you want to authenticate as */
+#define MGR_DN "cn=Directory Manager"
+#define MGR_PW "23skidoo"
+
+int
+main( int argc, char **argv )
+{
+
+ /* OID of the extended operation that you are requesting */
+ const char *oidrequest = "1.2.3.4";
+ char *oidresult;
+ struct berval valrequest;
+ struct berval *valresult;
+ LDAP *ld;
+ int rc, version;
+
+ /* Set up the value that you want to pass to the server */
+ printf( "Setting up value to pass to server...\n" );
+ valrequest.bv_val = "My Value";
+ valrequest.bv_len = strlen( "My Value" );
+
+ /* Get a handle to an LDAP connection */
+ printf( "Getting the handle to the LDAP connection...\n" );
+ if ( (ld = ldap_init( MY_HOST, MY_PORT )) == NULL ) {
+ perror( "ldap_init" );
+ ldap_unbind( ld );
+ return( 1 );
+ }
+
+ /* Set the LDAP protocol version supported by the client
+ to 3. (By default, this is set to 2. Extended operations
+ are part of version 3 of the LDAP protocol.) */
+ ldap_get_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
+ printf( "Resetting version %d to 3.0...\n", version );
+ version = LDAP_VERSION3;
+ ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
+
+ /* Authenticate to the directory as the Directory Manager */
+ printf( "Binding to the directory...\n" );
+ if ( ldap_simple_bind_s( ld, MGR_DN, MGR_PW ) != LDAP_SUCCESS ) {
+ ldap_perror( ld, "ldap_simple_bind_s" );
+ ldap_unbind( ld );
+ return( 1 );
+ }
+
+ /* Initiate the extended operation */
+ printf( "Initiating the extended operation...\n" );
+ if ( ( rc = ldap_extended_operation_s( ld, oidrequest, &valrequest, NULL, NULL, &oidresult, &valresult ) ) != LDAP_SUCCESS ) {
+ ldap_perror( ld, "ldap_extended failed: " );
+ ldap_unbind( ld );
+ return( 1 );
+ }
+
+ /* Get the OID and the value from the result returned by the server. */
+ printf( "Operation successful.\n" );
+ printf( "\tReturned OID: %s\n", oidresult );
+ printf( "\tReturned value: %s\n", valresult->bv_val );
+
+ /* Disconnect from the server. */
+ ldap_unbind( ld );
+ return 0;
+}
+
diff --git a/ldap/servers/slapd/test-plugins/dllmain.c b/ldap/servers/slapd/test-plugins/dllmain.c
new file mode 100644
index 00000000..f50f3595
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/dllmain.c
@@ -0,0 +1,109 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/*
+ * Microsoft Windows specifics for sample plug-ins DLL
+ */
+#include "ldap.h"
+#include "lber.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)
+{
+ WSADATA wsadata;
+
+ 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.
+ */
+
+ if( errno = WSAStartup(0x0101, &wsadata ) != 0 )
+ return FALSE;
+
+ 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.
+ */
+ WSACleanup();
+
+ 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
+
+#ifndef _WIN32
+/* The 16-bit version of the RTL does not implement perror() */
+#include <stdio.h>
+
+void perror( const char *msg )
+{
+ char buf[128];
+ wsprintf( buf, "%s: error %d\n", msg, WSAGetLastError()) ;
+ OutputDebugString( buf );
+}
+
+#endif
diff --git a/ldap/servers/slapd/test-plugins/installDse.pl b/ldap/servers/slapd/test-plugins/installDse.pl
new file mode 100755
index 00000000..6b827ab4
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/installDse.pl
@@ -0,0 +1,129 @@
+# The script is used to load the config mapping tree node for the null suffix
+# and to load the test sample plugin node into the Directory Server used to
+# demonstrate the Data Interoperability feature for Verisign.
+
+# The dse.ldif configuration file used as the default configuration by the
+# Server gets edited for adding the above mentioned two config nodes and the
+# server is restarted to load the plugin.
+
+# The loading of the DataInterop test plugin is only to demostrate the use
+# of the test plugin and can be replaced with Verisign's database plugin for use.
+
+# Written by binduk@netscape.com
+
+# Edits to be done for use
+# $host = Hostname of the Directory Server
+# $port = port used by the Server
+# $mgrdn = Bind Dn
+# $mgrpass = Password
+# $installDir = Installation root of the Server <server-root>
+
+
+###### Begin Edits ##################################
+
+$host = "trika.nscp.aoltw.net";
+$instance = "trika2";
+$port = "7775";
+$mgrdn = "cn=directory manager";
+$mgrpass = "password";
+$installDir = "/export/msyBuild/install"; # Installation root of the Server <server-root>
+
+###### End of Edits ##################################
+
+
+$dseOrgFile = "$installDir/slapd-$instance/config/dse.ldif"; # default configuration file to be edited
+$dseFile = "$installDir/slapd-$instance/config/load_dse.ldif"; # additional configuration file to be added
+$pidFile = "$installDir/slapd-$instance/logs/pid"; # pid file for the running server
+my $editedNode = 0;
+my $editedPlugin = 0;
+my $serverStatus = 1;
+
+
+ if(!(-e $pidFile)){
+ open( START_SERVER, "| $installDir/slapd-$instance/start-slapd ") || die "Can't Start the Server \n";
+ close(START_SERVER);
+
+ if(-e $pidFile){
+ print " ######## Started the Server \n";
+ }
+ else {
+ print " ######## Unable to Start the Server \n";
+ $serverStatus = 0;
+ }
+ }
+
+
+open(DSE_ORG, "$dseOrgFile") || die "Can't open $dseOrgFile for checks \n";
+ while(<DSE_ORG>){
+ $isEditedNode = 1 if (/^dn: cn=\"\",cn=mapping tree,cn=config/);
+ $isEditedPlugin = 1 if (/^dn: cn=datainterop,cn=plugins,cn=config/);
+ }
+close(DSE_ORG);
+
+open(DSE, ">$dseFile") || die "Can't open $dseFile for editing \n";
+
+ my $changesMade = 0;
+ unless($isEditedNode){
+ print DSE "dn: cn=\"\",cn=mapping tree,cn=config\n";
+ print DSE "objectClass: top\n";
+ print DSE "objectClass: extensibleObject\n";
+ print DSE "objectClass: nsMappingTree\n";
+ print DSE "cn: \"\"\n";
+ print DSE "nsslapd-state: container\n";
+ print DSE "\n";
+ $changesMade = 1;
+ }
+
+ unless($isEditedPlugin){
+ print DSE "dn: cn=datainterop,cn=plugins,cn=config\n";
+ print DSE "objectClass: top\n";
+ print DSE "objectClass: nsSlapdPlugin\n";
+ print DSE "cn: datainterop\n";
+ print DSE "nsslapd-pluginPath: $installDir/plugins/slapd/slapi/examples/libtest-plugin.so\n";
+ print DSE "nsslapd-pluginInitfunc: nullsuffix_init\n";
+ print DSE "nsslapd-pluginType: preoperation\n";
+ print DSE "nsslapd-pluginEnabled: on\n";
+ print DSE "nsslapd-pluginId: nullsuffix-preop\n";
+ print DSE "nsslapd-pluginVersion: 6.2\n";
+ print DSE "nsslapd-pluginVendor: Netscape\n";
+ print DSE "nsslapd-pluginDescription: sample pre-operation null suffix search plugin\n";
+ $changesMade = 1;
+ }
+close(DSE);
+
+
+if($changesMade){
+ chdir "$installDir/shared/bin" or die "cannot cd over error=$! \n";
+
+ open(LDAPMODIFY, "|ldapmodify -p \"${port}\" -h \"${host}\" -D \"${mgrdn}\" -w \"${mgrpass}\" -v -c -a -f $dseFile " ) || die "Can't modify the configuration of the Server \n";
+
+ close(LDAPMODIFY);
+
+ print " Modifications to the dse.ldif file have been done....restarting the server to load plugin \n";
+
+ open( STOP_SERVER, "| $installDir/slapd-$instance/stop-slapd ") || die "Can't Stop the Server \n";;
+ close(STOP_SERVER);
+
+ print " Now stopped the Server to load the plugin \n";
+
+ open( START_SERVER, "| $installDir/slapd-$instance/start-slapd ") || die "Can't Start the Server \n";
+ close(START_SERVER);
+
+ if(-e $pidFile){
+ print " Started the Server Successfully\n";
+ }
+ else{
+ $serverStatus = 0;
+ print "Failure in starting the Server - Check to see if the sample plugin has been compiled \n";
+ }
+
+}
+else {
+ if($serverStatus){
+ print " Nothing needs to be done \n";
+ }
+ else {
+ print " The Server did not Start Successfully \n";
+ }
+
+}
diff --git a/ldap/servers/slapd/test-plugins/nicknames b/ldap/servers/slapd/test-plugins/nicknames
new file mode 100644
index 00000000..1d7a2515
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/nicknames
@@ -0,0 +1,10 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+Timothy Tim Timbo Timmy
+Barbara Babs Buddah
+Robert Rob Bob Rob-bob Robby Bobby
diff --git a/ldap/servers/slapd/test-plugins/testbind.c b/ldap/servers/slapd/test-plugins/testbind.c
new file mode 100644
index 00000000..4d080a0f
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testbind.c
@@ -0,0 +1,252 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/************************************************************
+
+ testbind.c
+
+ This source file provides an example of a pre-operation plug-in
+ function that handles authentication.
+
+ Note that the Directory Server front-end handles bind
+ operations requested by the root DN. The server does not
+ invoke your plug-in function if the client is authenicating
+ as the root DN.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn=Test Bind,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: Test Bind
+ nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: testbind_init
+ nsslapd-pluginType: preoperation
+ nsslapd-pluginEnabled: on
+ nsslapd-plugin-depends-on-type: database
+ nsslapd-pluginId: test-bind
+
+ ************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+Slapi_PluginDesc bindpdesc = { "test-bind", "Netscape", "0.5",
+ "sample bind pre-operation plugin" };
+
+static Slapi_ComponentId *plugin_id = NULL;
+
+
+
+
+/* Pre-operation plug-in function */
+int
+test_bind( Slapi_PBlock *pb )
+{
+ char *dn, *attrs[2] = { SLAPI_USERPWD_ATTR, NULL };
+ int method, rc = LDAP_SUCCESS;
+ struct berval *credentials;
+ struct berval **pwvals;
+ Slapi_DN *sdn = NULL;
+ Slapi_Entry *e = NULL;
+ Slapi_Attr *attr = NULL;
+
+ /* Log a message to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Pre-operation bind function called.\n" );
+
+ /* Gets parameters available when processing an LDAP bind
+ operation. */
+ if ( slapi_pblock_get( pb, SLAPI_BIND_TARGET, &dn ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_METHOD, &method ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_CREDENTIALS, &credentials ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Could not get parameters for bind operation\n" );
+ slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR,
+ NULL, NULL, 0, NULL );
+ return( 1 );
+ }
+
+ /* Check the authentication method */
+ switch( method ) {
+ case LDAP_AUTH_SIMPLE:
+ /* First, get the entry specified by the DN. */
+ sdn = slapi_sdn_new_dn_byref( dn );
+ rc = slapi_search_internal_get_entry( sdn, attrs, &e,
+ plugin_id );
+ slapi_sdn_free( &sdn );
+
+ if ( rc != LDAP_SUCCESS ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Could not find entry %s (error %d)\n",
+ dn, rc );
+ break;
+ }
+
+ /* Next, check credentials against the userpassword attribute
+ of that entry. */
+ if ( e != NULL ) {
+ Slapi_Value *credval, **pwvals;
+ int i, hint, valcount;
+
+
+ if ( slapi_entry_attr_find( e, SLAPI_USERPWD_ATTR,
+ &attr ) != 0 || slapi_attr_get_numvalues( attr,
+ &valcount ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Entry has no %s attribute values\n",
+ SLAPI_USERPWD_ATTR );
+ rc = LDAP_INAPPROPRIATE_AUTH;
+ break;
+ }
+
+ credval = slapi_value_new_berval( credentials );
+ pwvals = (Slapi_Value **)slapi_ch_calloc( valcount,
+ sizeof( Slapi_Value * ));
+ i = 0;
+ for ( hint = slapi_attr_first_value( attr, &pwvals[i] );
+ hint != -1; hint = slapi_attr_next_value( attr,
+ hint, &pwvals[i] )) {
+ ++i;
+ }
+
+ if ( slapi_pw_find_sv( pwvals, credval ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Credentials are not correct\n" );
+ rc = LDAP_INVALID_CREDENTIALS;
+ }
+
+ slapi_value_free( &credval );
+ slapi_ch_free( (void **)&pwvals );
+
+ if ( LDAP_SUCCESS != rc ) {
+ break;
+ }
+ } else {
+ /* This should not happen. The previous section of code
+ already checks for this case. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Could find entry for %s\n", dn );
+ rc = LDAP_NO_SUCH_OBJECT;
+ break;
+ }
+
+ /* Set the DN and authentication method for the connection. */
+ if ( slapi_pblock_set( pb, SLAPI_CONN_DN,
+ slapi_ch_strdup( dn ) ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_CONN_AUTHMETHOD,
+ SLAPD_AUTH_SIMPLE ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Failed to set DN and method for connection\n" );
+ rc = LDAP_OPERATIONS_ERROR;
+ break;
+ }
+
+ /* Send a "success" result code back to the client. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Authenticated: %s\n", dn );
+ rc = LDAP_SUCCESS;
+ break;
+
+ /* If NONE is specified, the client is requesting to bind anonymously.
+ Normally, this case should be handled by the server's front-end
+ before it calls this plug-in function. Just in case this does
+ get through to the plug-in function, you can handle this by
+ sending a successful result code back to the client and returning
+ 1.
+ */
+ case LDAP_AUTH_NONE:
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Authenticating anonymously\n" );
+ rc = LDAP_SUCCESS;
+ break;
+
+ /* This plug-in does not support any other method of authentication */
+ case LDAP_AUTH_SASL:
+ default:
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_bind",
+ "Unsupported authentication method requested: %d\n",
+ method );
+ rc = LDAP_AUTH_METHOD_NOT_SUPPORTED;
+ break;
+ }
+
+ slapi_send_ldap_result( pb, rc, NULL, NULL, 0, NULL );
+ return( 1 );
+}
+
+/* Pre-operation plug-in function */
+int
+test_search( Slapi_PBlock *pb )
+{
+ char *reqdn;
+
+ /* Log a message to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_search",
+ "Pre-operation search function called.\n" );
+
+ /* Get requestor of search operation. This is not critical
+ to performing the search (this plug-in just serves as
+ confirmation that the bind plug-in works), so return 0
+ if this fails. */
+ if ( slapi_pblock_get( pb, SLAPI_REQUESTOR_DN, &reqdn ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_search",
+ "Could not get requestor parameter for search operation\n" );
+ return( 0 );
+ }
+
+ /* Indicate who is requesting the search */
+ if ( reqdn != NULL && *reqdn != '\0' ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_search",
+ "Search requested by %s\n", reqdn );
+ } else {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "test_search",
+ "Search requested by anonymous client\n" );
+ }
+ return( 0 );
+}
+
+/* Initialization function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testbind_init( Slapi_PBlock *pb )
+{
+
+ /* Retrieve and save the plugin identity to later pass to
+ internal operations */
+ if ( slapi_pblock_get( pb, SLAPI_PLUGIN_IDENTITY, &plugin_id ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testbind_init",
+ "Failed to retrieve SLAPI_PLUGIN_IDENTITY\n" );
+ return( -1 );
+ }
+
+ /* Register the pre-operation bind function and specify
+ the server plug-in version. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&bindpdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN,
+ (void *) test_bind ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN,
+ (void *) test_search ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testbind_init",
+ "Failed to set version and functions\n" );
+ return( -1 );
+ }
+
+ return( 0 );
+}
+
diff --git a/ldap/servers/slapd/test-plugins/testdatainterop.c b/ldap/servers/slapd/test-plugins/testdatainterop.c
new file mode 100644
index 00000000..19b171c1
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testdatainterop.c
@@ -0,0 +1,312 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2002 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/******** testdatainterop.c *******************
+
+ This source file provides an example of a plug-in function
+ that implements an datainteroprability functionality.
+ The plug-in function is called by the server
+ when the server is configured to use the null dn.
+ meaning dn:
+ The server uses the null dn or the root suffix opnly when
+ the configuration for the server has the following
+ node in the dse.ldif of the server instance
+ (in the <server_root>/slapd-<server_id>/config directory).
+
+ dn: cn="",cn=mapping tree,cn=config
+ objectClass: top
+ objectClass: extensibleObject
+ objectClass: nsMappingTree
+ cn: ""
+ nsslapd-state: container
+
+ The plugin below is a pre-operation plugin which
+ provides alternate functionality for the LDAP operations
+ of search, modify, add etc. that are targeted at the root-suffix
+ or the null-dn to be serviced by an alternate data source or
+ alternate access methods allowing datainteroperability.
+
+ The example below creates a berkely db and modifies or adds data
+ to the db demonstarting the use of an alternate data source seperate
+ from the Directory Server. Also, the results of a search operation
+ are completely in the control of the pre-operation plugin. In this
+ example a fake entry is returned to express the functionality
+
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn="",cn=mapping tree,cn=config
+ objectClass: top
+ objectClass: extensibleObject
+ objectClass: nsMappingTree
+ cn: ""
+ nsslapd-state: container
+
+
+ dn: cn=datainterop,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ cn: datainterop
+ nsslapd-pluginPath: <server-root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: nullsuffix_init
+ nsslapd-pluginType: preoperation
+ nsslapd-pluginEnabled: on
+ nsslapd-pluginId: nullsuffix-preop
+ nsslapd-pluginVersion: 6.2
+ nsslapd-pluginVendor: Netscape
+ nsslapd-pluginDescription: sample pre-operation null suffix plugin
+
+ ******************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+/*
+ * Macros.
+ */
+#define PLUGIN_NAME "nullsuffix-preop"
+
+#define PLUGIN_OPERATION_HANDLED 1
+#define PLUGIN_OPERATION_IGNORED 0
+
+#define SEARCH_SCOPE_ANY (-1)
+
+
+
+/*
+ * Static variables.
+ */
+static Slapi_PluginDesc plugindesc = { PLUGIN_NAME, "Netscape", "0.5",
+ "sample pre-operation null suffix plugin" };
+
+static Slapi_ComponentId *plugin_id = NULL;
+
+
+/*
+ * Function prototypes.
+ */
+static int nullsuffix_search( Slapi_PBlock *pb );
+static int nullsuffix_add( Slapi_PBlock *pb );
+static int nullsuffix_close( Slapi_PBlock *pb );
+static int nullsuffix_modify( Slapi_PBlock *pb );
+static int nullsuffix_delete( Slapi_PBlock *pb );
+static int nullsuffix_modrdn( Slapi_PBlock *pb );
+static int nullsuffix_bind( Slapi_PBlock *pb );
+
+
+/*
+ * Initialization function.
+ */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+nullsuffix_init( Slapi_PBlock *pb )
+{
+ int i;
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_init\n" );
+
+ /* retrieve plugin identity to later pass to internal operations */
+ if ( slapi_pblock_get( pb, SLAPI_PLUGIN_IDENTITY, &plugin_id ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "unable to get SLAPI_PLUGIN_IDENTITY\n" );
+ return -1;
+ }
+
+ /* register the pre-operation search function, etc. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01
+ ) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&plugindesc ) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN,
+ (void *)nullsuffix_search ) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_CLOSE_FN,
+ (void *)nullsuffix_close ) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN,
+ (void *)nullsuffix_add) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODIFY_FN,
+ (void *)nullsuffix_modify) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_DELETE_FN,
+ (void *)nullsuffix_delete) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN,
+ (void *)nullsuffix_bind) != 0
+ || slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_MODRDN_FN,
+ (void *)nullsuffix_modrdn) != 0) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "failed to set version and function\n" );
+ return -1;
+ }
+
+
+
+ return 0;
+}
+
+static int
+nullsuffix_bind( Slapi_PBlock *pb )
+{
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_bind\n" );
+ send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+ return PLUGIN_OPERATION_HANDLED;
+
+}
+
+static int
+nullsuffix_add( Slapi_PBlock *pb )
+{
+ char *dn;
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_add\n" );
+ slapi_pblock_get( pb, SLAPI_ADD_TARGET, &dn );
+ db_put_dn(dn);
+ send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+ return PLUGIN_OPERATION_HANDLED;
+}
+
+static int
+nullsuffix_modify( Slapi_PBlock *pb )
+{
+ Slapi_Entry *entry;
+ int i;
+ int j;
+ char *dn;
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+ slapi_pblock_get( pb, SLAPI_MODIFY_TARGET, &dn );
+ slapi_pblock_get( pb, SLAPI_ENTRY_PRE_OP, &entry);
+ db_put_dn(dn);
+ send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_modify\n" );
+ return PLUGIN_OPERATION_HANDLED;
+
+}
+
+static int
+nullsuffix_delete( Slapi_PBlock *pb )
+{
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_delete\n" );
+ send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+ return PLUGIN_OPERATION_HANDLED;
+}
+
+static int
+nullsuffix_modrdn( Slapi_PBlock *pb )
+{
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_modrdn\n" );
+ send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+ return PLUGIN_OPERATION_HANDLED;
+}
+
+static int
+nullsuffix_search( Slapi_PBlock *pb )
+{
+ char *dn_base, **attrs, *newStr;
+ int scope, sizelimit, timelimit, deref, attrsonly;
+ Slapi_Filter *filter;
+ Slapi_DN *sdn_base;
+ int ldaperr = LDAP_SUCCESS; /* optimistic */
+ int nentries = 0; /* entry count */
+ int i;
+ Slapi_Operation *op;
+ Slapi_Entry *e;
+
+ const char *entrystr =
+ "dn:cn=Joe Smith,o=Example\n"
+ "objectClass: top\n"
+ "objectClass: person\n"
+ "objectClass: organizationalPerson\n"
+ "objectClass: inetOrgPerson\n"
+ "cn:Joe Smith\n"
+ "sn:Smith\n"
+ "uid:jsmith\n"
+ "mail:jsmith@example.com\n";
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_search\n" );
+ if( slapi_op_reserved(pb) ){
+ return PLUGIN_OPERATION_IGNORED;
+ }
+
+ /* get essential search parameters */
+ if ( slapi_pblock_get( pb, SLAPI_SEARCH_TARGET, &dn_base ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_SCOPE, &scope ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "could not get base DN and scope search parameters\n" );
+ }
+ if ( dn_base == NULL ) {
+ dn_base = "";
+ }
+ sdn_base = slapi_sdn_new_dn_byval( dn_base );
+ slapi_pblock_get(pb, SLAPI_OPERATION, &op);
+
+ /* get remaining search parameters */
+ if ( slapi_pblock_get( pb, SLAPI_SEARCH_DEREF, &deref ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_TIMELIMIT, &timelimit ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_FILTER, &filter ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, &attrs ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "could not get remaining search parameters\n" );
+ }
+
+ if ( slapi_pblock_get( pb, SLAPI_OPERATION, &op ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "could not get operation\n" );
+ } else {
+ slapi_operation_set_flag(op, SLAPI_OP_FLAG_NO_ACCESS_CHECK );
+ }
+
+ /* create a fake entry and send it along */
+ newStr = slapi_ch_strdup( entrystr );
+ if ( NULL == ( e = slapi_str2entry( newStr,
+ SLAPI_STR2ENTRY_ADDRDNVALS
+ | SLAPI_STR2ENTRY_EXPAND_OBJECTCLASSES ))) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
+ "nullsuffix_search: slapi_str2entry() failed\n" );
+ } else {
+ slapi_send_ldap_search_entry( pb, e, NULL /* controls */,
+ attrs, attrsonly );
+ ++nentries;
+ slapi_entry_free( e );
+ }
+
+ slapi_send_ldap_result( pb, ldaperr, NULL, "kilroy was here",
+ nentries, NULL );
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_search:"
+ " handled search based at %s with scope %d; ldaperr=%d\n",
+ dn_base, scope, ldaperr );
+
+ slapi_ch_free_string(&newStr);
+ slapi_sdn_free(&sdn_base);
+
+ return PLUGIN_OPERATION_HANDLED;
+}
+
+
+/*
+ * Shutdown function.
+ */
+static int
+nullsuffix_close( Slapi_PBlock *pb )
+{
+ slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_close\n" );
+ return 0;
+}
diff --git a/ldap/servers/slapd/test-plugins/testdbinterop.c b/ldap/servers/slapd/test-plugins/testdbinterop.c
new file mode 100644
index 00000000..7da3e72f
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testdbinterop.c
@@ -0,0 +1,102 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include "db.h"
+#include "testdbinterop.h"
+#include "slapi-plugin.h"
+
+#define DATABASE "access.db"
+static int number_of_keys=100;
+static int key_buffer_size = 8000;
+
+#define DB_PLUGIN_NAME "nullsuffix-preop"
+
+static PRLock *db_lock=NULL;
+
+#if 1000*DB_VERSION_MAJOR + 100*DB_VERSION_MINOR >= 4100
+#define DB_OPEN(db, txnid, file, database, type, flags, mode) \
+ (db)->open((db), (txnid), (file), (database), (type), (flags), (mode))
+#else
+ (db)->open((db), (file), (database), (type), (flags), (mode))
+#endif
+
+
+DB *dbp=NULL;
+
+void
+create_db()
+{
+ int ret;
+ DBT key, data;
+
+ if ((ret = db_create(&dbp, NULL, 0)) != 0) {
+ fprintf(stderr, "db_create: %s\n", db_strerror(ret));
+ exit (1);
+ }
+
+}
+
+void make_key(DBT *key)
+{
+ char *key_string = (char*)(key->data);
+ unsigned int seed = (unsigned int)time( (time_t*) 0);
+ long int key_long = slapi_rand_r(&seed) % number_of_keys;
+ sprintf(key_string,"key%ld",key_long);
+ slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME,"generated key: %s\n", key_string);
+ key->size = strlen(key_string);
+}
+
+
+void
+db_put_dn(char *data_dn)
+{
+ int ret;
+ DBT key = {0};
+ DBT data = {0};
+
+ if(db_lock == NULL){
+ db_lock = PR_NewLock();
+ }
+ PR_Lock(db_lock);
+ create_db();
+
+ if ((ret = DB_OPEN(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
+ dbp->err(dbp, ret, "%s", DATABASE);
+ }
+ memset(&key, 0, sizeof(key));
+ memset(&data, 0, sizeof(data));
+
+
+ key.data = (char *)malloc(key_buffer_size);
+ /* make_key will set up the key and the data */
+ make_key(&key);
+
+ data.data = slapi_ch_strdup(data_dn);
+ data.size = strlen(data_dn);
+
+
+ switch (ret =
+ dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE)) {
+ case 0:
+ slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: %s: key stored.\n", (char *)key.data);
+ break;
+ case DB_KEYEXIST:
+ slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: %s: key previously stored.\n",
+ (char *)key.data);
+ break;
+ default:
+ dbp->err(dbp, ret, "DB->put");
+ goto err;
+ }
+
+ err:
+ if(ret){
+ slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: Error detected in db_put \n");
+ }
+ free(key.data);
+ if (dbp){
+ dbp->close(dbp,0);
+ dbp=NULL;
+ }
+ PR_Unlock(db_lock);
+
+}
diff --git a/ldap/servers/slapd/test-plugins/testdbinterop.h b/ldap/servers/slapd/test-plugins/testdbinterop.h
new file mode 100644
index 00000000..4fe46347
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testdbinterop.h
@@ -0,0 +1,22 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2002 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/******** testdbinterop.h *******************
+
+ The header file is for access to a Berkeley DB
+ that is being created by the testdbinterop.c
+ and used by testdatainterop.c ( plugin ); to allow
+ creation of a DB and adding DN's to the DB.
+ A simple example to show how external databases can
+ be accessed through the datainterop plugin of
+ testdatainterop.c
+
+**********************************************/
+
+#include "nspr.h"
+
+void create_db();
+void db_put_dn(char *data);
+
diff --git a/ldap/servers/slapd/test-plugins/testentry.c b/ldap/servers/slapd/test-plugins/testentry.c
new file mode 100644
index 00000000..893c6955
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testentry.c
@@ -0,0 +1,133 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/************************************************************
+
+ testentry.c
+
+ This source file provides examples of entry store and
+ entry fetch plug-in functions. These plug-in functions are
+ called by the server before writing an entry to disk and
+ after reading an entry from disk.
+
+ Entry store and entry fetch plug-in functions are passed
+ the string representation (in LDIF -- LDAP Data Interchange
+ Format) of the entry.
+
+ In this example, the entry store function performs a bitwise
+ exclusive-OR operation on each character in the entry
+ against the value 0xaa (10101010). The entry fetch
+ function performs this again to revert each character
+ back to its initial value.
+
+ NOTE: The Directory Server caches recently added and retrieved
+ entries in memory. The entry fetch plug-in function is called
+ only when reading the entry from the disk, *not* when reading
+ the entry from the cache.
+
+ For example, if you add an entry and search for it, you will
+ not see a message in the server error log indicating that
+ the entry fetch plug-in function was called. In the process
+ of adding the entry to the directory, the server also added
+ the entry to the cache; the server then reads the entry from
+ the cache instead of from the disk and does not need to call
+ the entry fetch plug-in function.
+
+ You can flush the cache by shutting down the server.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+dn: cn=Test entry,cn=plugins,cn=config
+objectClass: top
+objectClass: nsSlapdPlugin
+objectClass: extensibleObject
+cn: Test entry
+nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+nsslapd-pluginInitfunc: testentry_init
+nsslapd-pluginType: ldbmentryfetchstore
+nsslapd-pluginEnabled: on
+nsslapd-pluginId: test-entry
+
+ ************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+Slapi_PluginDesc entrypdesc = { "test-entry", "Netscape", "0.5",
+ "sample entry modification plugin" };
+
+/* Entry store plug-in function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testentry_scramble( char **entry, unsigned long *len )
+{
+ unsigned long i;
+
+ /* Log an entry to the server's error log file whenever
+ this function is called. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testentry_scramble",
+ "Entry data scrambled.\n" );
+
+ /* Perform a bitwise exclusive-OR operation on each
+ character in the entry. */
+ for ( i = 0; i < *len - 1; i++ ) {
+ (*entry)[i] ^= 0xaa;
+ }
+
+ return( 0 );
+}
+
+/* Entry fetch plug-in function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testentry_unscramble( char **entry, unsigned long *len )
+{
+ unsigned long i;
+
+ /* Some entries will not be scrambled, so check if the entry is
+ scrambled before attempting to unscramble the entry. */
+ if ( !strncmp( *entry, "dn:", 3 ) ) {
+ return( 0 );
+ }
+
+ /* Perform a bitwise exclusive-OR operation on each
+ character in the entry. */
+ for ( i = 0; i < *len - 1; i++ ) {
+ (*entry)[i] ^= 0xaa;
+ }
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testentry_unscramble",
+ "Entry data unscrambled.\n");
+ return( 0 );
+}
+
+int
+testentry_init(Slapi_PBlock *pb)
+{
+ /* Register the store/fetch functions and specify
+ the server plug-in version. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&entrypdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_ENTRY_FETCH_FUNC,
+ (void *) testentry_unscramble ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_ENTRY_STORE_FUNC,
+ (void *) testentry_scramble ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testentry_init",
+ "Failed to set version and functions\n" );
+ return( -1 );
+ }
+
+ return 0;
+}
diff --git a/ldap/servers/slapd/test-plugins/testextendedop.c b/ldap/servers/slapd/test-plugins/testextendedop.c
new file mode 100644
index 00000000..fad462a7
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testextendedop.c
@@ -0,0 +1,188 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/************************************************************
+
+ testextendedop.c
+
+ This source file provides an example of a plug-in function
+ that implements an extended operation. The plug-in function
+ is called by the server if an LDAP client request contains
+ the OID "1.2.3.4" (which identifies this operation).
+
+ To test this plug-in function, you need to write an LDAP
+ v3 client that can send requests for extended operations.
+ You can use the Netscape Directory SDK for C 3.0 or the
+ Netscape Directory SDK for Java 3.0 to build these clients.
+ (These SDKs are available from DevEdge Online at
+ http://developer.netscape.com/tech/directory/)
+
+ The LDAP client should send an extended operation request
+ with the OID 1.2.3.4. To verify that the operation completed
+ successfully, your client should check the OID and value
+ returned in the LDAP response.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn=Test ExtendedOp,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: Test ExtendedOp
+ nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: testexop_init
+ nsslapd-pluginType: extendedop
+ nsslapd-pluginEnabled: on
+ nsslapd-plugin-depends-on-type: database
+ nsslapd-pluginId: test-extendedop
+ nsslapd-pluginarg0: 1.2.3.4
+
+ ************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+/* OID of the extended operation handled by this plug-in */
+#define MY_OID "1.2.3.4"
+
+Slapi_PluginDesc expdesc = { "test-extendedop", "Netscape", "0.5",
+ "sample extended operation plugin" };
+
+
+/* Extended operation plug-in */
+int
+testexop_babs( Slapi_PBlock *pb )
+{
+ char *oid;
+ struct berval *bval;
+ char *retval, *msg;
+ struct berval retbval;
+
+ /* Get the OID and the value included in the request */
+ if ( slapi_pblock_get( pb, SLAPI_EXT_OP_REQ_OID, &oid ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_EXT_OP_REQ_VALUE, &bval ) != 0 ) {
+ msg = "Could not get OID and value from request.";
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs", "%s\n",
+ msg );
+ slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
+ msg, 0, NULL );
+ return( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );
+ } else {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs",
+ "Received extended operation request with OID %s\n",
+ oid );
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs",
+ "Value from client: %s\n", bval->bv_val );
+ }
+
+ /* Set up the value that you want returned to the client.
+ In this case, it's just the value sent from the client,
+ preceded by the string "Value from client: " */
+
+ msg = "Value from client: ";
+ retval = ( char * )slapi_ch_malloc( bval->bv_len + strlen( msg ) + 1 );
+ sprintf( retval, "%s%s", msg, bval->bv_val );
+ retbval.bv_val = retval;
+ retbval.bv_len = strlen( retbval.bv_val );
+
+ /* Prepare to return the OID and value back to the client.
+ Note that if you want, you can return a different OID to
+ the client (for example, if you want to use the OID as
+ an indicator of something). */
+ if ( slapi_pblock_set( pb, SLAPI_EXT_OP_RET_OID, "5.6.7.8" ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_EXT_OP_RET_VALUE, &retbval ) != 0 ) {
+ slapi_ch_free( ( void ** ) &retval );
+ msg = "Could not set return values";
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs", "%s\n",
+ msg );
+ slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
+ msg, 0, NULL );
+ return( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );
+ }
+
+ /* Send the response (containing the OID and value you set)
+ back to the client. */
+ slapi_send_ldap_result( pb, LDAP_SUCCESS, NULL,
+ "operation babs successful!", 0, NULL );
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs",
+ "OID sent to client: %s\n", "5.6.7.8" );
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_babs",
+ "Value sent to client: %s\n", retval );
+
+ /* Free any memory allocated by this plug-in. */
+ slapi_ch_free( ( void ** ) &retval );
+
+ /* Let front end know we sent the result */
+ return( SLAPI_PLUGIN_EXTENDED_SENT_RESULT );
+}
+
+/* Initialization function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testexop_init( Slapi_PBlock *pb )
+{
+ char **argv;
+ char *oid;
+ char **oidlist, **namelist;
+
+ /* Get the arguments appended to the plugin extendedop directive
+ in the plugin entry. The first argument
+ (after the standard arguments for the directive) should
+ contain the OID of the extended op.
+ */
+
+ if ( slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testexop_init", "Could not get argv\n" );
+ return( -1 );
+ }
+
+ /* Compare the OID specified in the configuration file
+ against the OID supported by this plug-in function. */
+
+ if ( argv == NULL || strcmp( argv[0], MY_OID ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testexop_init", "OID is missing or is not %s\n", MY_OID );
+ return( -1 );
+ } else {
+ oid = slapi_ch_strdup( argv[0] );
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_init",
+ "Registering plug-in for extended op %s.\n", oid );
+ }
+
+ oidlist = (char **) slapi_ch_malloc( 2 * sizeof( char * ) );
+ oidlist[0] = oid;
+ oidlist[1] = NULL;
+ namelist = (char **) slapi_ch_malloc( 2 * sizeof( char * ) );
+ namelist[0] = "test extended op";
+ namelist[1] = NULL;
+
+ /* Register the plug-in function as an extended operation
+ plug-in function that handles the operation identified by
+ OID 1.2.3.4. Also specify the version of the server
+ plug-in */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&expdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_FN,
+ (void *) testexop_babs ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_OIDLIST, oidlist ) ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_EXT_OP_NAMELIST, namelist ) != 0 ) {
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testexop_init",
+ "Failed to set plug-in version, function, and OID.\n" );
+ return( -1 );
+ }
+
+ return( 0 );
+}
+
diff --git a/ldap/servers/slapd/test-plugins/testgetip.c b/ldap/servers/slapd/test-plugins/testgetip.c
new file mode 100644
index 00000000..b8d08a52
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testgetip.c
@@ -0,0 +1,141 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/************************************************************
+
+ testgetip.c
+
+ This source file provides an example of a pre-operation plug-in
+ function that gets the IP address of the client and the IP
+ address of the server.
+
+ testgetip logs this information to the server error log.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn=Test GetIP,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: Test GetIP
+ nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: testgetip_init
+ nsslapd-pluginType: preoperation
+ nsslapd-pluginEnabled: on
+ nsslapd-plugin-depends-on-type: database
+ nsslapd-pluginId: test-getip
+
+ ************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#ifndef _WIN32
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#endif
+#include "slapi-plugin.h"
+#include "nspr.h"
+
+Slapi_PluginDesc getippdesc = { "test-getip", "Netscape", "0.5",
+ "sample pre-operation plugin" };
+
+static char *netaddr2str( PRNetAddr *addrp, char *buf, size_t buflen );
+
+int
+testgetip( Slapi_PBlock *pb )
+{
+ void *conn;
+ PRNetAddr client_addr, server_addr;
+ char addrbuf[ 512 ], *addrstr;
+
+ /*
+ * Don't do anything for internal operations (NULL connection).
+ */
+ if ( slapi_pblock_get( pb, SLAPI_CONNECTION, &conn ) != 0 ||
+ ( conn == NULL )) {
+ return( 0 );
+ }
+
+ /*
+ * Get the client's IP address and log it
+ */
+ if ( slapi_pblock_get( pb, SLAPI_CONN_CLIENTNETADDR, &client_addr )
+ != 0 || ( client_addr.raw.family == 0 )) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip",
+ "Could not get client IP.\n" );
+ } else if (( addrstr = netaddr2str( &client_addr, addrbuf,
+ sizeof(addrbuf))) != NULL ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip",
+ "Client's IP address is %s\n", addrstr );
+ }
+
+ /*
+ * Get the destination (server) IP address and log it
+ */
+ if ( slapi_pblock_get( pb, SLAPI_CONN_SERVERNETADDR, &server_addr )
+ != 0 || ( server_addr.raw.family == 0 )) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip",
+ "Could not get server IP.\n" );
+ } else if (( addrstr = netaddr2str( &server_addr, addrbuf,
+ sizeof(addrbuf))) != NULL ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip",
+ "Client sent request to server IP %s\n", addrstr );
+ }
+
+ return( 0 );
+}
+
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testgetip_init( Slapi_PBlock *pb )
+{
+ /* Register the pre-operation plug-in function. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&getippdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_SEARCH_FN,
+ (void *) testgetip ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_FATAL, "testgetip_init",
+ "Failed to set version and functions.\n" );
+ return( -1 );
+ }
+
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip_init",
+ "Registered preop plugins.\n" );
+ return( 0 );
+}
+
+
+/*
+ * Utility function to convert a PRNetAddr to a human readable string.
+ */
+static char *
+netaddr2str( PRNetAddr *addrp, char *buf, size_t buflen )
+{
+ char *addrstr;
+
+ *buf = '\0';
+ if ( PR_NetAddrToString( addrp, buf, buflen ) != PR_SUCCESS ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testgetip",
+ "PR_NetAddrToString failed.\n" );
+ return( NULL );
+ }
+
+ /* skip past leading ::ffff: if IPv4 address */
+ if ( strlen( buf ) > 7 && strncmp( buf, "::ffff:", 7 ) == 0 ) {
+ addrstr = buf + 7;
+ } else {
+ addrstr = buf;
+ }
+
+ return( addrstr );
+}
diff --git a/ldap/servers/slapd/test-plugins/testplugin.def b/ldap/servers/slapd/test-plugins/testplugin.def
new file mode 100644
index 00000000..b14c082e
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testplugin.def
@@ -0,0 +1,16 @@
+; BEGIN COPYRIGHT BLOCK
+; Copyright 2001 Sun Microsystems, Inc.
+; Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+; All rights reserved.
+; END COPYRIGHT BLOCK
+;
+DESCRIPTION 'Netscape Directory Server 7 test plugin'
+EXPORTS
+ testentry_scramble @2
+ testentry_unscramble @3
+ testexop_init @4
+ testpostop_init @5
+ testpreop_init @6
+ testsasl_init @7
+ testbind_init @8
+ nullsuffix_init @9
diff --git a/ldap/servers/slapd/test-plugins/testplugin.dsp b/ldap/servers/slapd/test-plugins/testplugin.dsp
new file mode 100644
index 00000000..d956bcd3
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testplugin.dsp
@@ -0,0 +1,143 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# Microsoft Developer Studio Project File - Name="testplugin" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 5.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=testplugin - 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 "testplugin.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 "testplugin.mak" CFG="testplugin - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "testplugin - Win32 Release" (based on\
+ "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "testplugin - 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)" == "testplugin - 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)" == "testplugin - 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 "testplugin - Win32 Release"
+# Name "testplugin - 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=.\testbind.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\testentry.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\testextendedop.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\testplugin.def
+# End Source File
+# Begin Source File
+
+SOURCE=.\testpostop.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\testpreop.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\testsaslbind.c
+# 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/slapd/test-plugins/testplugin.mak b/ldap/servers/slapd/test-plugins/testplugin.mak
new file mode 100644
index 00000000..ca48774c
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testplugin.mak
@@ -0,0 +1,431 @@
+#
+# BEGIN COPYRIGHT BLOCK
+# Copyright 2001 Sun Microsystems, Inc.
+# Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+# All rights reserved.
+# END COPYRIGHT BLOCK
+#
+# Microsoft Developer Studio Generated NMAKE File, Based on testplugin.dsp
+!IF "$(CFG)" == ""
+CFG=testplugin - Win32 Release
+!MESSAGE No configuration specified. Defaulting to testplugin - Win32 Release.
+!ENDIF
+
+!IF "$(CFG)" != "testplugin - Win32 Release" && "$(CFG)" !=\
+ "testplugin - Win32 Debug"
+!MESSAGE Invalid configuration "$(CFG)" specified.
+!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 "testplugin.mak" CFG="testplugin - Win32 Release"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "testplugin - Win32 Release" (based on\
+ "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "testplugin - Win32 Debug" (based on\
+ "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+!ERROR An invalid configuration is specified.
+!ENDIF
+
+!IF "$(OS)" == "Windows_NT"
+NULL=
+!ELSE
+NULL=nul
+!ENDIF
+
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+OUTDIR=.\Release
+INTDIR=.\Release
+# Begin Custom Macros
+OutDir=.\.\Release
+# End Custom Macros
+
+!IF "$(RECURSE)" == "0"
+
+ALL : "$(OUTDIR)\testplugin.dll"
+
+!ELSE
+
+ALL : "$(OUTDIR)\testplugin.dll"
+
+!ENDIF
+
+CLEAN :
+ -@erase "$(INTDIR)\dllmain.obj"
+ -@erase "$(INTDIR)\testbind.obj"
+ -@erase "$(INTDIR)\testentry.obj"
+ -@erase "$(INTDIR)\testextendedop.obj"
+ -@erase "$(INTDIR)\testpostop.obj"
+ -@erase "$(INTDIR)\testpreop.obj"
+ -@erase "$(INTDIR)\testsaslbind.obj"
+ -@erase "$(INTDIR)\vc50.idb"
+ -@erase "$(OUTDIR)\testplugin.dll"
+ -@erase "$(OUTDIR)\testplugin.exp"
+ -@erase "$(OUTDIR)\testplugin.lib"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MD /W3 /GX /O2 /I "..\include" /D "WIN32" /D "NDEBUG" /D\
+ "_WINDOWS" /D "_WIN32" /Fp"$(INTDIR)\testplugin.pch" /YX /Fo"$(INTDIR)\\"\
+ /Fd"$(INTDIR)\\" /FD /c
+CPP_OBJS=.\Release/
+CPP_SBRS=.
+MTL_PROJ=/nologo /D "NDEBUG" /mktyplib203 /win32
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\testplugin.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+LINK32_FLAGS=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\
+ /incremental:no /pdb:"$(OUTDIR)\testplugin.pdb" /machine:I386\
+ /def:".\testplugin.def" /out:"$(OUTDIR)\testplugin.dll"\
+ /implib:"$(OUTDIR)\testplugin.lib"
+DEF_FILE= \
+ ".\testplugin.def"
+LINK32_OBJS= \
+ "$(INTDIR)\dllmain.obj" \
+ "$(INTDIR)\testbind.obj" \
+ "$(INTDIR)\testentry.obj" \
+ "$(INTDIR)\testextendedop.obj" \
+ "$(INTDIR)\testpostop.obj" \
+ "$(INTDIR)\testpreop.obj" \
+ "$(INTDIR)\testsaslbind.obj"
+
+"$(OUTDIR)\testplugin.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+OUTDIR=.\Debug
+INTDIR=.\Debug
+# Begin Custom Macros
+OutDir=.\.\Debug
+# End Custom Macros
+
+!IF "$(RECURSE)" == "0"
+
+ALL : "$(OUTDIR)\testplugin.dll"
+
+!ELSE
+
+ALL : "$(OUTDIR)\testplugin.dll"
+
+!ENDIF
+
+CLEAN :
+ -@erase "$(INTDIR)\dllmain.obj"
+ -@erase "$(INTDIR)\testbind.obj"
+ -@erase "$(INTDIR)\testentry.obj"
+ -@erase "$(INTDIR)\testextendedop.obj"
+ -@erase "$(INTDIR)\testpostop.obj"
+ -@erase "$(INTDIR)\testpreop.obj"
+ -@erase "$(INTDIR)\testsaslbind.obj"
+ -@erase "$(INTDIR)\vc50.idb"
+ -@erase "$(INTDIR)\vc50.pdb"
+ -@erase "$(OUTDIR)\testplugin.dll"
+ -@erase "$(OUTDIR)\testplugin.exp"
+ -@erase "$(OUTDIR)\testplugin.ilk"
+ -@erase "$(OUTDIR)\testplugin.lib"
+ -@erase "$(OUTDIR)\testplugin.pdb"
+
+"$(OUTDIR)" :
+ if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
+
+CPP_PROJ=/nologo /MD /W3 /Gm /GX /Zi /Od /I "..\include" /D "WIN32" /D "_DEBUG"\
+ /D "_WINDOWS" /D "_WIN32" /Fp"$(INTDIR)\testplugin.pch" /YX /Fo"$(INTDIR)\\"\
+ /Fd"$(INTDIR)\\" /FD /c
+CPP_OBJS=.\Debug/
+CPP_SBRS=.
+MTL_PROJ=/nologo /D "_DEBUG" /mktyplib203 /win32
+BSC32=bscmake.exe
+BSC32_FLAGS=/nologo /o"$(OUTDIR)\testplugin.bsc"
+BSC32_SBRS= \
+
+LINK32=link.exe
+LINK32_FLAGS=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\
+ /incremental:yes /pdb:"$(OUTDIR)\testplugin.pdb" /debug /machine:I386\
+ /def:".\testplugin.def" /out:"$(OUTDIR)\testplugin.dll"\
+ /implib:"$(OUTDIR)\testplugin.lib"
+DEF_FILE= \
+ ".\testplugin.def"
+LINK32_OBJS= \
+ "$(INTDIR)\dllmain.obj" \
+ "$(INTDIR)\testbind.obj" \
+ "$(INTDIR)\testentry.obj" \
+ "$(INTDIR)\testextendedop.obj" \
+ "$(INTDIR)\testpostop.obj" \
+ "$(INTDIR)\testpreop.obj" \
+ "$(INTDIR)\testsaslbind.obj"
+
+"$(OUTDIR)\testplugin.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+ $(LINK32) @<<
+ $(LINK32_FLAGS) $(LINK32_OBJS)
+<<
+
+!ENDIF
+
+.c{$(CPP_OBJS)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cpp{$(CPP_OBJS)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cxx{$(CPP_OBJS)}.obj::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.c{$(CPP_SBRS)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cpp{$(CPP_SBRS)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+.cxx{$(CPP_SBRS)}.sbr::
+ $(CPP) @<<
+ $(CPP_PROJ) $<
+<<
+
+
+!IF "$(CFG)" == "testplugin - Win32 Release" || "$(CFG)" ==\
+ "testplugin - Win32 Debug"
+SOURCE=.\dllmain.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_DLLMA=\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\dllmain.obj" : $(SOURCE) $(DEP_CPP_DLLMA) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_DLLMA=\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_DLLMA=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\dllmain.obj" : $(SOURCE) $(DEP_CPP_DLLMA) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testbind.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTB=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testbind.obj" : $(SOURCE) $(DEP_CPP_TESTB) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTB=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTB=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testbind.obj" : $(SOURCE) $(DEP_CPP_TESTB) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testentry.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTE=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testentry.obj" : $(SOURCE) $(DEP_CPP_TESTE) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTE=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTE=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testentry.obj" : $(SOURCE) $(DEP_CPP_TESTE) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testextendedop.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTEX=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testextendedop.obj" : $(SOURCE) $(DEP_CPP_TESTEX) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTEX=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTEX=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testextendedop.obj" : $(SOURCE) $(DEP_CPP_TESTEX) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testpostop.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTP=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testpostop.obj" : $(SOURCE) $(DEP_CPP_TESTP) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTP=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTP=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testpostop.obj" : $(SOURCE) $(DEP_CPP_TESTP) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testpreop.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTPR=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testpreop.obj" : $(SOURCE) $(DEP_CPP_TESTPR) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTPR=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTPR=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testpreop.obj" : $(SOURCE) $(DEP_CPP_TESTPR) "$(INTDIR)"
+
+
+!ENDIF
+
+SOURCE=.\testsaslbind.c
+
+!IF "$(CFG)" == "testplugin - Win32 Release"
+
+DEP_CPP_TESTS=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+
+
+"$(INTDIR)\testsaslbind.obj" : $(SOURCE) $(DEP_CPP_TESTS) "$(INTDIR)"
+
+
+!ELSEIF "$(CFG)" == "testplugin - Win32 Debug"
+
+DEP_CPP_TESTS=\
+ "..\include\slapi-plugin.h"\
+ {$(INCLUDE)}"lber.h"\
+ {$(INCLUDE)}"ldap.h"\
+ {$(INCLUDE)}"sys\types.h"\
+
+NODEP_CPP_TESTS=\
+ "..\include\macsock.h"\
+ "..\include\os2sock.h"\
+
+
+"$(INTDIR)\testsaslbind.obj" : $(SOURCE) $(DEP_CPP_TESTS) "$(INTDIR)"
+
+
+!ENDIF
+
+
+!ENDIF
+
diff --git a/ldap/servers/slapd/test-plugins/testpostop.c b/ldap/servers/slapd/test-plugins/testpostop.c
new file mode 100644
index 00000000..5dbf18d1
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testpostop.c
@@ -0,0 +1,386 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/************************************************************
+
+ testpostop.c
+
+ This source file provides examples of post-operation plug-in
+ functions. The server calls these plug-in functions after
+ executing certain LDAP operations:
+
+ * testpostop_add (called after an LDAP add operation)
+ * testpostop_mod (called after an LDAP modify operation)
+ * testpostop_del (called after an LDAP delete operation)
+ * testpostop_modrdn (called after an LDAP modify RDN operation)
+ * testpostop_abandon (called after an LDAP abandon operation)
+
+ After the server processes an LDAP add, modify, delete, or
+ modify RDN operation, these post-operation plug-in functions
+ log information about the operation to a change log file.
+
+ The post-abandon plugin simply logs some information to the error
+ log to demonstrate that it was called.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn=Test PostOp,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: Test PostOp
+ nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: testpostop_init
+ nsslapd-pluginType: postoperation
+ nsslapd-pluginEnabled: on
+ nsslapd-plugin-depends-on-type: database
+ nsslapd-pluginId: test-postop
+
+ ************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <time.h>
+#include "slapi-plugin.h"
+
+#define SLAPD_LOGGING 1
+#define _ADD 0
+#define _MOD 1
+#define _DEL 2
+#define _MODRDN 3
+
+#ifdef _WIN32
+static char changelogfile[MAX_PATH+1];
+#else
+static char *changelogfile = "/tmp/changelog";
+#endif
+
+Slapi_PluginDesc postoppdesc = { "test-postop", "Netscape", "0.5",
+ "sample post-operation plugin" };
+
+static void write_changelog( int optype, char *dn, void *change, int flag );
+
+/* Current time is a function defined in the server. */
+time_t current_time( void );
+
+/* Post-operation plug-in function */
+int
+testpostop_add( Slapi_PBlock *pb )
+{
+ Slapi_Entry *e;
+ char *dn;
+
+ /* Get the entry that has been added and the DN of
+ that entry. */
+ if ( slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &e ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_ADD_TARGET, &dn ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpostop_add", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log the DN of the newly added entry in the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_add",
+ "Added entry (%s)\n", dn );
+
+ /* Log the DN and the entry to the change log file. */
+ write_changelog( _ADD, dn, (void *) e, 0 );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Post-operation plug-in function. */
+int
+testpostop_mod( Slapi_PBlock *pb )
+{
+ char *dn;
+ LDAPMod **mods;
+
+ /* Get the DN of the modified entry and the modifications made. */
+ if ( slapi_pblock_get( pb, SLAPI_MODIFY_TARGET, &dn ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_MODIFY_MODS, &mods ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpostop_mod", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log the DN of the modified entry to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_mod",
+ "Modified entry (%s)\n", dn );
+
+ /* Log the DN and the modifications made to the change log file. */
+ write_changelog( _MOD, dn, (void *) mods, 0 );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Post-operation plug-in function */
+int
+testpostop_del( Slapi_PBlock *pb )
+{
+ char *dn;
+
+ /* Get the DN of the entry that was removed from the directory. */
+ if ( slapi_pblock_get( pb, SLAPI_DELETE_TARGET, &dn ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpostop_del", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log the DN of the deleted entry to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_del",
+ "Deleted entry (%s)\n", dn );
+
+ /* Log the DN of the deleted entry to the change log. */
+ write_changelog( _DEL, dn, NULL, 0 );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Post-operation plug-in function */
+int
+testpostop_modrdn( Slapi_PBlock *pb )
+{
+ char *dn;
+ char *newrdn;
+ int dflag;
+
+ /* Get the DN of the renamed entry, the new RDN of the entry,
+ and the flag indicating whether or not the old RDN was
+ removed from the entry. */
+ if ( slapi_pblock_get( pb, SLAPI_MODRDN_TARGET, &dn ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_MODRDN_NEWRDN, &newrdn ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_MODRDN_DELOLDRDN, &dflag ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpostop_modrdn", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log the DN of the renamed entry to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_modrdn",
+ "modrdn entry (%s)\n", dn );
+
+ /* Log the DN of the renamed entry, its new RDN, and the
+ flag (the one indicating whether or not the old RDN was
+ removed from the entry) to the change log. */
+ write_changelog( _MODRDN, dn, (void *) newrdn, dflag );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Post-operation plug-in function */
+int
+testpostop_abandon( Slapi_PBlock *pb )
+{
+ int msgid;
+
+ /* Get the LDAP message ID of the abandoned operation */
+ if ( slapi_pblock_get( pb, SLAPI_ABANDON_MSGID, &msgid ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpostop_abandon", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log information about the abandon operation to the
+ server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_abandon",
+ "Postoperation abandon function called.\n"
+ "\tTarget MsgID: %d\n",
+ msgid );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Initialization function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testpostop_init( Slapi_PBlock *pb )
+{
+ /* Register the four post-operation plug-in functions,
+ and specify the server plug-in version. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&postoppdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ADD_FN,
+ (void *) testpostop_add ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODIFY_FN,
+ (void *) testpostop_mod ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_POST_DELETE_FN,
+ (void *) testpostop_del ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_POST_MODRDN_FN,
+ (void *) testpostop_modrdn ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_POST_ABANDON_FN,
+ (void *) testpostop_abandon ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpostop_init",
+ "Failed to set version and functions\n" );
+ return( -1 );
+ }
+ return( 0 );
+}
+
+/* Function for generating a newly allocated string that contains the
+ specified time. The time is expressed as generalizedTime, except
+ without the time zone. */
+static char*
+format_localTime( time_t timeval )
+{
+ char* into;
+ struct tm t;
+#ifdef _WIN32
+ memcpy (&t, localtime (&timeval), sizeof(t));
+#else
+ localtime_r (&timeval, &t);
+#endif
+
+ /* Allocate memory for the formatted string. (slapi_ch_malloc()
+ should be used in server plug-ins instead of malloc().)
+ This string is freed by the calling function write_changelog(). */
+ into = slapi_ch_malloc(15);
+ sprintf (into, "%.4li%.2i%.2i%.2i%.2i%.2i",
+ 1900L + t.tm_year, 1 + t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+ return into;
+}
+
+/* Logs information on an operation to a change log file.
+ Parameters;
+ - optype is type of LDAP operation to record:
+ - _ADD for LDAP add operations
+ - _MOD for LDAP modify operations
+ - _DEL for LDAP delete operations
+ - _MODRDN for LDAP modify RDN operations
+ - dn is DN of the entry affected by the operation.
+ - change is information about the operation performed.
+ The type of information depends on the value of optype:
+ - For _ADD, it is the newly added entry (Slapi_Entry).
+ - For _MOD, it is the list of modifications made (array of
+ LDAPMod).
+ - For _DEL, it is NULL.
+ - For _MODRDN, it is the new RDN of the entry.
+ - flag is only used for LDAP modify RDN operations.
+ It represents the flag that indicates whether or not
+ the old RDN has been removed.
+*/
+static void
+write_changelog(
+ int optype,
+ char *dn,
+ void *change,
+ int flag
+)
+{
+ LDAPMod **mods;
+ Slapi_Entry *e;
+ char *newrdn, *tmp, *tmpsave;
+ FILE *fp;
+ int len, i, j;
+ char* timestr;
+#ifdef _WIN32
+ char szTmpPath[MAX_PATH+1];
+#endif
+
+ /* Open the change log file */
+#ifdef _WIN32
+ GetTempPath( MAX_PATH, szTmpPath );
+ strcpy( changelogfile, szTmpPath );
+ strcat( changelogfile, "\\" );
+ strcat( changelogfile, "changelog.txt" );
+#endif
+ if ( changelogfile == NULL ) {
+ return;
+ }
+ if ( (fp = fopen( changelogfile, "ab" )) == NULL ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "write_changelog",
+ "Could not open log file %s\n", changelogfile );
+ return;
+ }
+
+ /* Log the current time of the operation in generalizedTime form */
+ timestr = format_localTime( current_time() );
+ fprintf( fp, "time: %s\n", timestr );
+ slapi_ch_free( ( void ** ) &timestr);
+ timestr = NULL;
+
+ /* Print the DN of the entry affected by the operation. */
+ fprintf( fp, "dn: %s\n", dn );
+
+ /* Log information about the operation */
+ switch ( optype ) {
+ case _MOD:
+ /* For modify operations, log the attribute type
+ that has been added, replaced, or deleted. */
+ fprintf( fp, "changetype: modify\n" );
+ mods = (LDAPMod **)change;
+ for ( j = 0; mods[j] != NULL; j++ ) {
+ switch ( mods[j]->mod_op & ~LDAP_MOD_BVALUES ) {
+ case LDAP_MOD_ADD:
+ fprintf( fp, "add: %s\n", mods[j]->mod_type );
+ break;
+
+ case LDAP_MOD_DELETE:
+ fprintf( fp, "delete: %s\n", mods[j]->mod_type );
+ break;
+
+ case LDAP_MOD_REPLACE:
+ fprintf( fp, "replace: %s\n", mods[j]->mod_type );
+ break;
+ }
+
+ for ( i = 0; mods[j]->mod_bvalues != NULL &&
+ mods[j]->mod_bvalues[i] != NULL; i++ ) {
+ /* XXX should handle binary values XXX */
+ fprintf( fp, "%s: %s\n", mods[j]->mod_type,
+ mods[j]->mod_bvalues[i]->bv_val );
+ }
+ fprintf( fp, "-\n" );
+ }
+ break;
+
+ case _ADD:
+ /* For LDAP add operations, log the newly added entry. */
+ e = (Slapi_Entry *)change;
+ fprintf( fp, "changetype: add\n" );
+ /* Get the LDIF string representation of the entry. */
+ tmp = slapi_entry2str( e, &len );
+ tmpsave = tmp;
+ /* Skip the first line, which is the dn: line */
+ while (( tmp = strchr( tmp, '\n' )) != NULL ) {
+ tmp++;
+ if ( !isspace( *tmp )) {
+ break;
+ }
+ }
+ fprintf( fp, "%s", tmp );
+ slapi_ch_free( (void **)&tmpsave );
+ break;
+
+ case _DEL:
+ /* For the LDAP delete operation, log the DN of the
+ removed entry. (Since this is already done earlier,
+ the plug-in just needs to note the type of operation
+ performed. */
+ fprintf( fp, "changetype: delete\n" );
+ break;
+
+ case _MODRDN:
+ /* For the LDAP modify RDN operation, log the new RDN
+ and the flag indicating whether or not the old RDN
+ was removed. */
+ newrdn = (char *)change;
+ fprintf( fp, "changetype: modrdn\n" );
+ fprintf( fp, "newrdn: %s\n", newrdn );
+ fprintf( fp, "deleteoldrdn: %d\n", flag ? 1 : 0 );
+ }
+ fprintf( fp, "\n" );
+
+ fclose( fp );
+}
+
diff --git a/ldap/servers/slapd/test-plugins/testpreop.c b/ldap/servers/slapd/test-plugins/testpreop.c
new file mode 100644
index 00000000..54a08b53
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testpreop.c
@@ -0,0 +1,215 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+/************************************************************
+
+ testpreop.c
+
+ This source file provides examples of pre-operation plug-in
+ functions. The server calls these plug-in functions before
+ executing certain LDAP operations:
+
+ * testpreop_bind (called before an LDAP bind operation)
+ * testpreop_add (called before an LDAP add operation)
+ * testpreop_abandon (called before an LDAP abandon operation)
+
+ testpreop_bind logs information about the LDAP bind operation
+ to the server error log. testpreop_add prepends the name "BOB"
+ to the value of the cn attribute before an entry is added.
+
+ Note that the Directory Server front-end handles bind
+ operations requested by the root DN. The server does not
+ invoke your plug-in function if the client is authenticating
+ as the root DN.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+ dn: cn=Test Preop,cn=plugins,cn=config
+ objectClass: top
+ objectClass: nsSlapdPlugin
+ objectClass: extensibleObject
+ cn: Test Preop
+ nsslapd-pluginPath: <server_root>/plugins/slapd/slapi/examples/libtest-plugin.so
+ nsslapd-pluginInitfunc: testpreop_init
+ nsslapd-pluginType: preoperation
+ nsslapd-pluginEnabled: on
+ nsslapd-plugin-depends-on-type: database
+ nsslapd-pluginId: test-preop
+
+ ************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+Slapi_PluginDesc preoppdesc = { "test-preop", "Netscape", "0.5",
+ "sample pre-operation plugin" };
+
+/* Pre-operation plug-in function */
+int
+testpreop_bind( Slapi_PBlock *pb )
+{
+ char *dn;
+ int method;
+ char *auth;
+
+ /* Get the DN that the client is binding as and the method
+ of authentication used. */
+ if ( slapi_pblock_get( pb, SLAPI_BIND_TARGET, &dn ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_METHOD, &method ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpreop_bind", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ switch( method ) {
+ case LDAP_AUTH_NONE:
+ auth = "No authentication";
+ break;
+ case LDAP_AUTH_SIMPLE:
+ auth = "Simple authentication";
+ break;
+ case LDAP_AUTH_SASL:
+ auth = "SASL authentication";
+ break;
+ default:
+ auth = "Unknown method of authentication";
+ break;
+ }
+
+ /* Log information about the bind operation to the
+ server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpreop_bind",
+ "Preoperation bind function called.\n"
+ "\tTarget DN: %s\n\tAuthentication method: %s\n",
+ dn, auth );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+/* Pre-operation plug-in function */
+int
+testpreop_add( Slapi_PBlock *pb )
+{
+ Slapi_Entry *e;
+ Slapi_Attr *a;
+ Slapi_Value *v;
+ struct berval **bvals;
+ int i, hint;
+ char *tmp;
+ const char *s;
+
+ /* Get the entry that is about to be added. */
+ if ( slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &e ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpreop_add", "Could not get entry\n" );
+ return( -1 );
+ }
+
+ /* Prepend the name "BOB" to the value of the cn attribute
+ in the entry. */
+ if ( slapi_entry_attr_find( e, "cn", &a ) == 0 ) {
+ for ( hint = slapi_attr_first_value( a, &v ); hint != -1;
+ hint = slapi_attr_next_value( a, hint, &v )) {
+ s = slapi_value_get_string( v );
+ tmp = (char *) malloc( 5 + strlen( s ));
+ strcpy( tmp, "BOB " );
+ strcat( tmp + 4, s );
+ slapi_value_set_string( v, tmp );
+ free( tmp );
+ }
+ }
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+
+/* Pre-operation plug-in function */
+int
+testpreop_abandon( Slapi_PBlock *pb )
+{
+ int msgid;
+
+ /* Get the LDAP message ID of the abandon target */
+ if ( slapi_pblock_get( pb, SLAPI_ABANDON_MSGID, &msgid ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN,
+ "testpreop_abandon", "Could not get parameters\n" );
+ return( -1 );
+ }
+
+ /* Log information about the abandon operation to the
+ server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpreop_bind",
+ "Preoperation abandon function called.\n"
+ "\tTarget MsgID: %d\n",
+ msgid );
+
+ return( 0 ); /* allow the operation to continue */
+}
+
+
+static void
+get_plugin_config_dn_and_entry( char *msg, Slapi_PBlock *pb )
+{
+ char *dn = NULL;
+ Slapi_Entry *e = NULL;
+ int loglevel = SLAPI_LOG_PLUGIN;
+
+ if ( slapi_pblock_get( pb, SLAPI_TARGET_DN, &dn ) != 0 || dn == NULL ) {
+ slapi_log_error( loglevel, msg, "failed to get plugin config DN\n" );
+ } else {
+ slapi_log_error( loglevel, msg, "this plugin's config DN is \"%s\"\n",
+ dn );
+ }
+
+ if ( slapi_pblock_get( pb, SLAPI_ADD_ENTRY, &e ) != 0 || e == NULL ) {
+ slapi_log_error( loglevel, msg, "failed to get plugin config entry\n" );
+ } else {
+ char *ldif;
+
+ ldif = slapi_entry2str_with_options( e, NULL, 0 );
+ slapi_log_error( loglevel, msg,
+ "this plugin's config entry is \"\n%s\"\n", ldif );
+ slapi_ch_free_string( &ldif );
+ }
+}
+
+static int
+testpreop_start( Slapi_PBlock *pb )
+{
+ get_plugin_config_dn_and_entry( "testpreop_start", pb );
+ return( 0 );
+}
+
+/* Initialization function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testpreop_init( Slapi_PBlock *pb )
+{
+ /* Register the two pre-operation plug-in functions,
+ and specify the server plug-in version. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION,
+ SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION,
+ (void *)&preoppdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_START_FN,
+ (void *) testpreop_start ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN,
+ (void *) testpreop_bind ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ADD_FN,
+ (void *) testpreop_add ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_ABANDON_FN,
+ (void *) testpreop_abandon ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testpreop_init",
+ "Failed to set version and function\n" );
+ return( -1 );
+ }
+
+ return( 0 );
+}
diff --git a/ldap/servers/slapd/test-plugins/testsaslbind.c b/ldap/servers/slapd/test-plugins/testsaslbind.c
new file mode 100644
index 00000000..3d265f4d
--- /dev/null
+++ b/ldap/servers/slapd/test-plugins/testsaslbind.c
@@ -0,0 +1,145 @@
+/** BEGIN COPYRIGHT BLOCK
+ * Copyright 2001 Sun Microsystems, Inc.
+ * Portions copyright 1999, 2001-2003 Netscape Communications Corporation.
+ * All rights reserved.
+ * END COPYRIGHT BLOCK **/
+
+/************************************************************
+
+ testsaslbind.c
+
+ This source file provides an example of a pre-operation plug-in
+ function for SASL authentication with LDAP bind operations.
+ The function demonstrates how to send credentials back to the
+ client in cases where mutual authentication is required.
+
+ This plugin responds to SASL bind requests with a mechanism
+ name of "babsmechanism". Simple binds and other SASL mechanisms
+ should not be affected by the presence of this plugin.
+
+ Binds with our mechanism always succeed (which is not very secure!)
+
+ Note that the Directory Server front-end handles bind
+ operations requested by the root DN. The server does not
+ invoke your plug-in function if the client is authenticating
+ as the root DN.
+
+ To test this plug-in function, stop the server, edit the dse.ldif file
+ (in the <server_root>/slapd-<server_id>/config directory)
+ and add the following lines before restarting the server :
+
+dn: cn=test-saslbind,cn=plugins,cn=config
+objectclass: top
+objectclass: nsSlapdPlugin
+objectclass: extensibleObject
+cn: test-saslbind
+nsslapd-pluginpath: /usr/netscape/servers/plugins/slapd/slapi/examples/libtest-plugin.so
+nsslapd-plugininitfunc: testsasl_init
+nsslapd-plugintype: preoperation
+nsslapd-pluginenabled: on
+nsslapd-pluginid: test-saslbind
+nsslapd-pluginversion: 5.0
+nsslapd-pluginvendor: Netscape Communications Corp.
+nsslapd-plugindescription: sample SASL bind pre-operation plugin
+
+
+ ************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include "slapi-plugin.h"
+
+Slapi_PluginDesc saslpdesc = { "test-saslbind", "Netscape Communications Corp.", "7.0",
+ "sample SASL bind pre-operation plugin" };
+
+
+#define TEST_SASL_MECHANISM "babsmechanism"
+#define TEST_SASL_AUTHMETHOD SLAPD_AUTH_SASL TEST_SASL_MECHANISM
+
+/* Pre-operation plug-in function */
+int
+testsasl_bind( Slapi_PBlock *pb )
+{
+ char *target;
+ int method;
+ char *mechanism;
+ struct berval *credentials;
+ struct berval svrcreds;
+
+ /* Log a message to the server error log. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testsasl_bind",
+ "Pre-operation bind function called.\n" );
+
+ /* Gets parameters available when processing an LDAP bind
+ operation. */
+ if ( slapi_pblock_get( pb, SLAPI_BIND_TARGET, &target ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_METHOD, &method ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_CREDENTIALS, &credentials ) != 0 ||
+ slapi_pblock_get( pb, SLAPI_BIND_SASLMECHANISM, &mechanism )
+ != 0 ) {
+ slapi_log_error( SLAPI_LOG_FATAL, "testsasl_bind",
+ "Could not get parameters for bind operation\n" );
+ return( 0 ); /* let the server try other mechanisms */
+ }
+
+ /* Check to see if the mechanism being used is ours. */
+ if ( mechanism == NULL
+ || strcmp( mechanism, TEST_SASL_MECHANISM ) != 0 ) {
+ return( 0 ); /* let the server try other mechanisms */
+ }
+
+ /*
+ * Set the DN and authentication method for the connection.
+ * Binds with our mechanism always succeed (which is not very secure!)
+ */
+ if ( slapi_pblock_set( pb, SLAPI_CONN_DN, slapi_ch_strdup( target ) )
+ != 0 || slapi_pblock_set( pb, SLAPI_CONN_AUTHMETHOD,
+ TEST_SASL_AUTHMETHOD ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_FATAL, "testsasl_bind",
+ "Failed to set DN and method for connection\n" );
+ slapi_send_ldap_result( pb, LDAP_OPERATIONS_ERROR, NULL,
+ NULL, 0, NULL );
+ return( 1 ); /* done -- sent result to client */
+ }
+
+ /* Set the credentials that should be returned to the client. */
+ svrcreds.bv_val = "my credentials";
+ svrcreds.bv_len = sizeof("my credentials") - 1;
+ if ( slapi_pblock_set( pb, SLAPI_BIND_RET_SASLCREDS, &svrcreds )
+ != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testsasl_bind",
+ "Could not set credentials to return to client\n" );
+ slapi_pblock_set( pb, SLAPI_CONN_DN, NULL );
+ slapi_pblock_set( pb, SLAPI_CONN_AUTHMETHOD, SLAPD_AUTH_NONE );
+ return( 0 ); /* let the server try other mechanisms */
+ }
+
+ /* Send the credentials back to the client. */
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testsasl_bind",
+ "Authenticated: %s\n", target );
+ slapi_send_ldap_result( pb, LDAP_SUCCESS, NULL, NULL, 0, NULL );
+
+ return( 1 ); /* done -- sent result to client */
+}
+
+/* Initialization function */
+#ifdef _WIN32
+__declspec(dllexport)
+#endif
+int
+testsasl_init( Slapi_PBlock *pb )
+{
+ /* Register the pre-operation bind function and specify
+ the server plug-in version. */
+ if ( slapi_pblock_set( pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01 ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_DESCRIPTION, (void *)&saslpdesc ) != 0 ||
+ slapi_pblock_set( pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *) testsasl_bind ) != 0 ) {
+ slapi_log_error( SLAPI_LOG_PLUGIN, "testsasl_init",
+ "Failed to set version and function\n" );
+ return( -1 );
+ }
+
+ /* Register the SASL mechanism. */
+ slapi_register_supported_saslmechanism( TEST_SASL_MECHANISM );
+ return( 0 );
+}
+