[PATCH] pdb_plugin final(?)

Jelmer Vernooij jelmer at nl.linux.org
Sat Feb 16 09:08:09 GMT 2002


Hi!

Here's an update of my pdb_plugin patch. New to this version is the
addition of correct LDFLAGS to enable exporting the whole symbol
table(so that samba functions like DEBUG() or the pdb_* functions can
be called from within a plugin).

See my previous emails for more info about the patch.

Jelmer

-- 
Jelmer Vernooij <jelmer at nl.linux.org> - http://nl.linux.org/~jelmer/
Development And Underdevelopment: http://library.thinkquest.org/C0110231/
Listening to 03
 17:53:17 up 8 days, 22:48,  6 users,  load average: 0.23, 0.09, 0.02
-------------- next part --------------
diff -Nru samba/examples/pdb/Makefile samba2/examples/pdb/Makefile
--- samba/examples/pdb/Makefile	Thu Jan  1 01:00:00 1970
+++ samba2/examples/pdb/Makefile	Fri Feb 15 00:15:16 2002
@@ -0,0 +1,31 @@
+# Makefile for samba-pdb examples
+# Variables
+
+CC = gcc
+LIBTOOL = libtool
+
+SAMBA_SRC = ../../source
+SAMBA_INCL = ../../source/include
+UBIQX_SRC = ../../source/ubiqx
+SMBWR_SRC = ../../source/smbwrapper
+CFLAGS = -I$(SAMBA_SRC) -I$(SAMBA_INCL) -I$(UBIQX_SRC) -I$(SMBWR_SRC) -Wall -g
+PDB_OBJS = pdb_test.so
+
+# Default target
+
+default: $(PDB_OBJS)
+
+# Pattern rules
+
+%.so: %.lo
+	$(LIBTOOL) $(CC) -shared -o $@ $< $(LDFLAGS)
+
+%.lo: %.c
+	$(LIBTOOL) $(CC) $(CPPFLAGS) $(CFLAGS) -c $<
+
+# Misc targets
+
+clean:
+	rm -rf .libs
+	rm -f core *~ *% *.bak \
+		$(PDB_OBJS) $(PDB_OBJS:.so=.o) $(PDB_OBJS:.so=.lo) 
diff -Nru samba/examples/pdb/README samba2/examples/pdb/README
--- samba/examples/pdb/README	Thu Jan  1 01:00:00 1970
+++ samba2/examples/pdb/README	Fri Feb 15 16:15:19 2002
@@ -0,0 +1,9 @@
+README for Samba Password Database (PDB) examples
+====================================================
+15-2-2002 Jelmer Vernooij <jelmer at nl.linux.org>
+
+The pdb_test.c file in this directory contains a very basic example of 
+a pdb plugin. It just prints the name of the function that is executed using
+DEBUG. Maybe it's nice to include some of the arguments to the function in the 
+future too..
+
diff -Nru samba/examples/pdb/pdb_test.c samba2/examples/pdb/pdb_test.c
--- samba/examples/pdb/pdb_test.c	Thu Jan  1 01:00:00 1970
+++ samba2/examples/pdb/pdb_test.c	Sat Feb 16 00:48:11 2002
@@ -0,0 +1,111 @@
+/*
+ * Test password backend for samba
+ * Copyright (C) Jelmer Vernooij 2002
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 675
+ * Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "includes.h"
+
+static BOOL testsam_setsampwent(struct pdb_context *context, BOOL update)
+{
+    return True;
+}
+
+/***************************************************************
+ End enumeration of the passwd list.
+****************************************************************/
+
+static void testsam_endsampwent(struct pdb_context *context)
+{
+}
+
+/*****************************************************************
+ Get one SAM_ACCOUNT from the list (next in line)
+*****************************************************************/
+
+static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
+{
+	return False;
+}
+
+/******************************************************************
+ Lookup a name in the SAM database
+******************************************************************/
+
+static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname)
+{
+	return False;
+}
+
+/***************************************************************************
+ Search by rid
+ **************************************************************************/
+
+static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid)
+{
+    return False;
+}
+
+/***************************************************************************
+ Delete a SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass)
+{
+	return False;
+}
+
+/***************************************************************************
+ Modifies an existing SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
+{
+	return False;
+}
+
+/***************************************************************************
+ Adds an existing SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
+{
+	return False;
+}
+
+NTSTATUS pdb_init(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
+{
+	NTSTATUS nt_status;
+
+	if (!NT_STATUS_IS_OK(nt_status = make_pdb_methods(pdb_context->mem_ctx, pdb_method))) {
+		return nt_status;
+	}
+
+	(*pdb_method)->name = "testsam";
+
+	(*pdb_method)->setsampwent = testsam_setsampwent;
+	(*pdb_method)->endsampwent = testsam_endsampwent;
+	(*pdb_method)->getsampwent = testsam_getsampwent;
+	(*pdb_method)->getsampwnam = testsam_getsampwnam;
+	(*pdb_method)->getsampwrid = testsam_getsampwrid;
+	(*pdb_method)->add_sam_account = testsam_add_sam_account;
+	(*pdb_method)->update_sam_account = testsam_update_sam_account;
+	(*pdb_method)->delete_sam_account = testsam_delete_sam_account;
+
+	if(location)printf("Location: %s\n", location);
+
+	return NT_STATUS_OK;
+}
diff -Nru samba/source/Makefile.in samba2/source/Makefile.in
--- samba/source/Makefile.in	Thu Feb  7 21:20:05 2002
+++ samba2/source/Makefile.in	Fri Feb 15 00:14:09 2002
@@ -188,7 +188,7 @@
 
 PASSDB_OBJ = passdb/passdb.o passdb/pdb_interface.o passdb/pdb_get_set.o \
 		passdb/machine_sid.o passdb/pdb_smbpasswd.o \
-		passdb/pdb_tdb.o passdb/pdb_ldap.o \
+		passdb/pdb_tdb.o passdb/pdb_ldap.o passdb/pdb_plugin.o \
 		passdb/pdb_nisplus.o
 
 GROUPDB_OBJ = groupdb/mapping.o
diff -Nru samba/source/acconfig.h samba2/source/acconfig.h
--- samba/source/acconfig.h	Sun Jan 20 15:30:38 2002
+++ samba2/source/acconfig.h	Thu Feb 14 22:53:23 2002
@@ -167,6 +167,7 @@
 #undef WITH_LDAP_SAM
 #undef WITH_NISPLUS_SAM
 #undef WITH_TDB_SAM
+#undef WITH_PLUGIN_SAM
 #undef LINUX_QUOTAS_1
 #undef LINUX_QUOTAS_2
 #undef PACKAGE
diff -Nru samba/source/configure.in samba2/source/configure.in
--- samba/source/configure.in	Wed Feb  6 01:53:00 2002
+++ samba2/source/configure.in	Sat Feb 16 13:16:28 2002
@@ -84,6 +84,12 @@
 
 AC_VALIDATE_CACHE_SYSTEM_TYPE
 
+# I'm sure gcc supports -rdynamic
+if test "$ac_cv_prog_gcc" = yes; then
+    LDFLAGS="$LDFLAGS -rdynamic"
+    WL="-Wl,"
+fi
+
 #
 # Config CPPFLAG settings for strange OS's that must be set
 # before other tests.
@@ -91,6 +97,7 @@
 case "$host_os" in
 # Try to work out if this is the native HPUX compiler that uses the -Ae flag.
     *hpux*)
+    
       AC_PROG_CC_FLAG(Ae)
       # mmap on HPUX is completely broken...
       AC_DEFINE(MMAP_BLACKLIST)
@@ -112,6 +119,7 @@
 		   		AC_DEFINE(USE_BOTH_CRYPT_CALLS)
 				;;
       esac
+      LDFLAGS="$LDFLAGS -Wl,-E"
       ;;
 
 #
@@ -157,6 +165,7 @@
 						;;
 				esac
 			else
+                LDFLAGS="$LDFLAGS -dc -dp"
 				CPPFLAGS="$CPPFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 			fi
 			;;
@@ -694,10 +703,12 @@
 		*linux*)   AC_DEFINE(LINUX)
 			BLDSHARED="true"
 			LDSHFLAGS="-shared" 
+            LDFLAGS="$LDFLAGS -Wl,--export-dynamic"
 			PICFLAG="-fPIC"
 			AC_DEFINE(STAT_ST_BLOCKSIZE,512)
 		;;
-		*solaris*) AC_DEFINE(SUNOS5)
+		*solaris*) 
+        AC_DEFINE(SUNOS5)
 			BLDSHARED="true"
 			LDSHFLAGS="-h \$@ -G"
 			if test "${ac_cv_prog_CC}" = "gcc"; then
@@ -710,6 +721,7 @@
 			AC_DEFINE(STAT_ST_BLOCKSIZE,512)
 		;;
 		*sunos*) AC_DEFINE(SUNOS4)
+#            WL="-Qoption ld "
 			BLDSHARED="true"
 			LDSHFLAGS="-Wl,-h,\$@ -G"
 			PICFLAG="-KPIC"   # Is this correct for SunOS
@@ -749,15 +761,20 @@
 				LDSHFLAGS="-b -z +h \$@"
 				PICFLAG="+z"
 			fi
+            LDFLAGS="-Wl,-E"
 			AC_DEFINE(STAT_ST_BLOCKSIZE,8192)
 		;;
 		*qnx*) AC_DEFINE(QNX);;
 		*osf*) AC_DEFINE(OSF1)
+            WL="-Wl,"
 			BLDSHARED="true"
 			LDSHFLAGS="-Wl,-soname,\$@ -shared"
 			PICFLAG="-fPIC"
 		;;
-		*sco*) AC_DEFINE(SCO);;
+		*sco*) 
+        LDFLAGS="$LDFLAGS -Wl,-Bexport"
+        AC_DEFINE(SCO)
+        ;;
 		*unixware*) AC_DEFINE(UNIXWARE)
 			BLDSHARED="true"
 			LDSHFLAGS="-Wl,-soname,\$@ -shared"
@@ -771,11 +788,17 @@
 									AC_DEFINE(HAVE_MEMSET)
 								fi
 								LDSHFLAGS="-G"
+                                LDFLAGS="-Bexport"
 				;;
-				*mips-sni-sysv4*) AC_DEFINE(RELIANTUNIX);;
+				*mips-sni-sysv4*) 
+                    AC_DEFINE(RELIANTUNIX)
+                    WL="-LD"
+                    ;;
 			esac
 			;;
+
 		*sysv5*)
+            WL="-Wl,"
 			if [ test "$GCC" != yes ]; then
 				AC_DEFINE(HAVE_MEMSET)
 			fi
@@ -1921,6 +1944,24 @@
   yes)
     AC_MSG_RESULT(yes)
     AC_DEFINE(WITH_TDB_SAM)
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
+
+#################################################
+# check for a plugin password database
+AC_MSG_CHECKING(whether to use database plugin support)
+AC_ARG_WITH(pluginsam,
+[  --with-pluginsam        Use database plugin support (default=no)],
+[ case "$withval" in
+  yes)
+#    LDFLAGS="$LDFLAGS -rdynamic"
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_PLUGIN_SAM)
     ;;
   *)
     AC_MSG_RESULT(no)
diff -Nru samba/source/include/config.h.in samba2/source/include/config.h.in
--- samba/source/include/config.h.in	Sat Feb 16 13:17:38 2002
+++ samba2/source/include/config.h.in	Sat Feb 16 00:44:03 2002
@@ -1,4 +1,4 @@
-/* include/config.h.in.  Generated automatically from configure.in by autoheader.  */
+/* include/config.h.in.  Generated automatically from configure.in by autoheader 2.13.  */
 
 /* Define if on AIX 3.
    System headers sometimes define this.
@@ -233,6 +233,7 @@
 #undef WITH_LDAP_SAM
 #undef WITH_NISPLUS_SAM
 #undef WITH_TDB_SAM
+#undef WITH_PLUGIN_SAM
 #undef LINUX_QUOTAS_1
 #undef LINUX_QUOTAS_2
 #undef PACKAGE
diff -Nru samba/source/passdb/pdb_interface.c samba2/source/passdb/pdb_interface.c
--- samba/source/passdb/pdb_interface.c	Wed Jan 30 07:08:25 2002
+++ samba2/source/passdb/pdb_interface.c	Thu Feb 14 23:39:03 2002
@@ -27,11 +27,7 @@
 	{ "smbpasswd_nua", pdb_init_smbpasswd_nua },
 	{ "tdbsam", pdb_init_tdbsam },
 	{ "tdbsam_nua", pdb_init_tdbsam_nua },
-#if 0
-	{ "ldap", pdb_init_ldap },
-	{ "nisplus", pdb_init_nisplus },	
-	{ "unix", pdb_init_unix },
-#endif
+    { "plugin", pdb_init_plugin },
 	{ NULL, NULL}
 };
 
@@ -198,7 +194,7 @@
 		return nt_status;
 	}
 	
-	DEBUG(5,("Attempting to find an passdb backend to match %s\n", selected));
+	DEBUG(5,("Attempting to find an passdb backend to match %s(%s)\n", selected, module_name));
 	for (i = 0; builtin_pdb_init_functions[i].name; i++)
 	{
 		if (strequal(builtin_pdb_init_functions[i].name, module_name))
@@ -214,7 +210,7 @@
 			break;
 		}
 	}
-	
+    
 	if (!(*context)->pdb_selected) {
 		DEBUG(0,("failed to select passdb backed!\n"));
 		talloc_destroy((*context)->mem_ctx);
diff -Nru samba/source/passdb/pdb_plugin.c samba2/source/passdb/pdb_plugin.c
--- samba/source/passdb/pdb_plugin.c	Thu Jan  1 01:00:00 1970
+++ samba2/source/passdb/pdb_plugin.c	Sat Feb 16 01:43:48 2002
@@ -0,0 +1,73 @@
+/*
+ * Unix SMB/CIFS implementation. 
+ * SMB parameters and setup
+ * Copyright (C) Jelmer Vernooij 2002
+ * 
+ * Based on an idea by Stefan (metze) Metzmacher
+ * 
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 675
+ * Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "includes.h"
+
+#ifdef WITH_PLUGIN_SAM
+
+NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
+{
+    void * dl_handle;
+    char *dl_error;
+    char *plugin_location, *plugin_name, *p;
+    NTSTATUS (*plugin_init)( PDB_CONTEXT *pdb_context, PDB_METHODS 
+                             **pdb_method, const char *location);
+
+    if(location == NULL){
+	DEBUG(0, ("The plugin module needs an argument!\n"));
+	return NT_STATUS_UNSUCCESSFUL;
+    }
+    plugin_name = smb_xstrdup(location);
+    p = strchr(plugin_name, ':');
+    if (p) {
+        *p = 0;
+        plugin_location = p+1;
+        trim_string(plugin_location, " ", " ");
+    }else plugin_location = NULL;
+    trim_string(plugin_name, " ", " ");
+
+    DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name));
+    dl_handle = sys_dlopen(plugin_name, RTLD_NOW | RTLD_GLOBAL );
+    if (!dl_handle) {
+	    DEBUG(0, ("Failed to load sam plugin %s using sys_dlopen (%s)\n", plugin_name, sys_dlerror()));
+	    return NT_STATUS_UNSUCCESSFUL;
+    }
+    
+    plugin_init = sys_dlsym(dl_handle, "pdb_init");
+    if (!plugin_init){
+	    DEBUG(0, ("Failed to find function 'init' using sys_dlsym in sam plugin %s(%s)\n", plugin_name, sys_dlerror()));	    
+	    return NT_STATUS_UNSUCCESSFUL;
+    }
+
+    DEBUG(5, ("Starting sam plugin %s with location %s\n", plugin_name, plugin_location));
+    return plugin_init(pdb_context,pdb_method,plugin_location);
+}
+
+#else
+
+NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
+{
+	DEBUG(0, ("sam plugin not compiled in!\n"));
+	return NT_STATUS_UNSUCCESSFUL;
+}
+
+#endif


More information about the samba-technical mailing list