[PATCH] Updated pdb_plugin.diff

Jelmer Vernooij jelmer at nl.linux.org
Fri Feb 15 08:42:38 GMT 2002


Hi again!

Here's the updated version of my pdb_plugin patch. It includes some
more verbosity, bug fixes, copyright adjustment, and it's fully tested. It 
also adds a 'pdb' directory to examples/ with an example (very simple) 
pdb_test plugin.

The patch is currently compatible with gcc only. If you're using an
other C compiler, please tell me what flags to use to 'add all symbols 
to the dynamic symbol table' when linking an executable?

Here's my usage info I provided with the previous patch again:

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.

I'm working on a mysql pdb plugin right now.

Jelmer

-- 
Jelmer Vernooij <jelmer at nl.linux.org> - http://nl.linux.org/~jelmer/
Development And Underdevelopment: http://library.thinkquest.org/C0110231/
 17:21:54 up 7 days, 22:16,  9 users,  load average: 0.87, 1.30, 1.31
-------------- 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	Fri Feb 15 00:27:17 2002
@@ -0,0 +1,119 @@
+/*
+ * 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)
+{
+    DEBUG(0, ("test_setsampwent called\n"));
+    return True;
+}
+
+/***************************************************************
+ End enumeration of the passwd list.
+****************************************************************/
+
+static void testsam_endsampwent(struct pdb_context *context)
+{
+	DEBUG(0, ("test_endsampwent called\n"));
+}
+
+/*****************************************************************
+ Get one SAM_ACCOUNT from the list (next in line)
+*****************************************************************/
+
+static BOOL testsam_getsampwent(struct pdb_context *context, SAM_ACCOUNT *user)
+{
+    DEBUG(0, ("testsam_getsampwent called\n"));    
+	return False;
+}
+
+/******************************************************************
+ Lookup a name in the SAM database
+******************************************************************/
+
+static BOOL testsam_getsampwnam (struct pdb_context *context, SAM_ACCOUNT *user, const char *sname)
+{
+	DEBUG(0,("testsam_getsampwnam called\n"));
+	return False;
+}
+
+/***************************************************************************
+ Search by rid
+ **************************************************************************/
+
+static BOOL testsam_getsampwrid (struct pdb_context *context, SAM_ACCOUNT *user, uint32 rid)
+{
+    DEBUG(0,("testsam_getsampwrid called\n"));
+    return False;
+}
+
+/***************************************************************************
+ Delete a SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_delete_sam_account(struct pdb_context *context, const SAM_ACCOUNT *sam_pass)
+{
+    DEBUG(0,("testsam_delete_sam_account called\n"));
+	return False;
+}
+
+/***************************************************************************
+ Modifies an existing SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_update_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
+{
+    DEBUG(0,("testsam_update_sam_account called\n"));
+	return False;
+}
+
+/***************************************************************************
+ Adds an existing SAM_ACCOUNT
+****************************************************************************/
+
+static BOOL testsam_add_sam_account (struct pdb_context *context, const SAM_ACCOUNT *newpwd)
+{
+    DEBUG(0,("testsam_add_sam_account called\n"));
+	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)DEBUG(0,("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	Fri Feb 15 16:07:19 2002
@@ -1930,6 +1930,24 @@
 )
 
 #################################################
+# 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)
+    ;;
+  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 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	Thu Feb 14 23:54:43 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