[PATCH] pdb plugin support

Jelmer Vernooij jelmer at nl.linux.org
Thu Feb 14 09:38:46 GMT 2002


Hi !

Here's the first version of my pdb plugin support patch. It adds a new
pdb database type named 'plugin'. It's based upon Stefan Metzmacher's
idea he wrote about on january 22.

A configure option is provided to choose whether the plugin support
should (not) be compiled in.

To use this pdb backend, use this line in smb.conf:

passdb backend = plugin:<path-to-plugin>:<arguments-to-plugin>

In order to compile with the patch, one needs to regenerate configure
and include/proto.h.

The patch isn't very usefull at the moment, but I'll try to make
plugins of some of the currently available pdb modules(tdb and
smbpasswd).

Feedback please :)

Jelmer

-- 
Jelmer Vernooij <jelmer at nl.linux.org> - http://nl.linux.org/~jelmer/
Development And Underdevelopment: http://library.thinkquest.org/C0110231/
Listening to Guano Apes: Lord of the boards
 18:19:42 up 6 days, 23:14,  8 users,  load average: 2.44, 1.66, 1.45
-------------- next part --------------
diff -Nru samba2/source/Makefile.in samba/source/Makefile.in
--- samba2/source/Makefile.in	Thu Feb  7 21:20:05 2002
+++ samba/source/Makefile.in	Thu Feb 14 16:55:16 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 samba2/source/acconfig.h samba/source/acconfig.h
--- samba2/source/acconfig.h	Sun Jan 20 15:30:38 2002
+++ samba/source/acconfig.h	Thu Feb 14 16:59:05 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
Binary files samba2/source/bin/libsmbclient.a and samba/source/bin/libsmbclient.a differ
diff -Nru samba2/source/configure.in samba/source/configure.in
--- samba2/source/configure.in	Wed Feb  6 01:53:00 2002
+++ samba/source/configure.in	Thu Feb 14 16:55:08 2002
@@ -1930,6 +1930,23 @@
 )
 
 #################################################
+# 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)
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(WITH_PLUGIN_SAM)
+    ;;
+  *)
+    AC_MSG_RESULT(no)
+    ;;
+  esac ],
+  AC_MSG_RESULT(no)
+)
+
+#################################################
 # check for a LDAP password database
 AC_MSG_CHECKING(whether to use LDAP SAM database)
 AC_ARG_WITH(ldapsam,
diff -Nru samba2/source/passdb/pdb_interface.c samba/source/passdb/pdb_interface.c
--- samba2/source/passdb/pdb_interface.c	Wed Jan 30 07:08:25 2002
+++ samba/source/passdb/pdb_interface.c	Thu Feb 14 16:56:48 2002
@@ -27,6 +27,7 @@
 	{ "smbpasswd_nua", pdb_init_smbpasswd_nua },
 	{ "tdbsam", pdb_init_tdbsam },
 	{ "tdbsam_nua", pdb_init_tdbsam_nua },
+    { "plugin", pdb_init_plugin },
 #if 0
 	{ "ldap", pdb_init_ldap },
 	{ "nisplus", pdb_init_nisplus },	
@@ -214,7 +215,7 @@
 			break;
 		}
 	}
-	
+    
 	if (!(*context)->pdb_selected) {
 		DEBUG(0,("failed to select passdb backed!\n"));
 		talloc_destroy((*context)->mem_ctx);
diff -Nru samba2/source/passdb/pdb_plugin.c samba/source/passdb/pdb_plugin.c
--- samba2/source/passdb/pdb_plugin.c	Thu Jan  1 01:00:00 1970
+++ samba/source/passdb/pdb_plugin.c	Thu Feb 14 16:58:32 2002
@@ -0,0 +1,78 @@
+/*
+ * Unix SMB/CIFS implementation. 
+ * SMB parameters and setup
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Simo Sorce 2000
+ * Copyright (C) Gerald Carter 2000
+ * Copyright (C) Jeremy Allison 2001
+ * Copyright (C) Andrew Bartlett 2002
+ * 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\n", plugin_name));
+	    return NT_STATUS_UNSUCCESSFUL;
+    }
+    
+    plugin_init = sys_dlsym(dl_handle, "init");
+    if ((dl_error = dlerror()) != NULL) {
+	    DEBUG(0, ("Failed to find function 'init' using sys_dlsym in sam plugin %s\n", plugin_name));	    
+	    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