summaryrefslogtreecommitdiff
path: root/source3/passdb
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2003-04-15 16:01:14 +0000
committerJelmer Vernooij <jelmer@samba.org>2003-04-15 16:01:14 +0000
commit9c3cecbdac2ea888f95db2194bf9f5d2457aef09 (patch)
treed6cc4e5e34a32cd4a74e18c65f0794c68108f6a2 /source3/passdb
parenta0e8344a8d1e8fbbde4cc4ca5a5722ee1e2c2bcf (diff)
downloadsamba-9c3cecbdac2ea888f95db2194bf9f5d2457aef09.tar.gz
samba-9c3cecbdac2ea888f95db2194bf9f5d2457aef09.tar.bz2
samba-9c3cecbdac2ea888f95db2194bf9f5d2457aef09.zip
Use the new modules system for passdb (merge from HEAD)
(This used to be commit 1755d5f66221a910863cfc8a197f8d792e6b6e3d)
Diffstat (limited to 'source3/passdb')
-rw-r--r--source3/passdb/pdb_guest.c5
-rw-r--r--source3/passdb/pdb_interface.c110
-rw-r--r--source3/passdb/pdb_ldap.c20
-rw-r--r--source3/passdb/pdb_mysql.c17
-rw-r--r--source3/passdb/pdb_nisplus.c10
-rw-r--r--source3/passdb/pdb_smbpasswd.c7
-rw-r--r--source3/passdb/pdb_tdb.c20
-rw-r--r--source3/passdb/pdb_unix.c5
-rw-r--r--source3/passdb/pdb_xml.c12
9 files changed, 127 insertions, 79 deletions
diff --git a/source3/passdb/pdb_guest.c b/source3/passdb/pdb_guest.c
index 88a75aa667..f5a15057e0 100644
--- a/source3/passdb/pdb_guest.c
+++ b/source3/passdb/pdb_guest.c
@@ -122,3 +122,8 @@ NTSTATUS pdb_init_guestsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, c
return NT_STATUS_OK;
}
+int pdb_guest_init(void)
+{
+ return smb_register_passdb("guest", pdb_init_guestsam, PASSDB_INTERFACE_VERSION);
+}
+
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index 42be673d25..8adcd9dbfa 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -24,21 +24,57 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_PASSDB
-/** List of various built-in passdb modules */
-
-const struct pdb_init_function_entry builtin_pdb_init_functions[] = {
- { "smbpasswd", pdb_init_smbpasswd },
- { "smbpasswd_nua", pdb_init_smbpasswd_nua },
- { "tdbsam", pdb_init_tdbsam },
- { "tdbsam_nua", pdb_init_tdbsam_nua },
- { "ldapsam", pdb_init_ldapsam },
- { "ldapsam_nua", pdb_init_ldapsam_nua },
- { "unixsam", pdb_init_unixsam },
- { "guest", pdb_init_guestsam },
- { "nisplussam", pdb_init_nisplussam },
- { "plugin", pdb_init_plugin },
- { NULL, NULL}
-};
+static struct pdb_init_function_entry *backends = NULL;
+
+static void lazy_initialize_passdb(void)
+{
+ static BOOL initialized = False;
+ if(initialized)return;
+ static_init_pdb;
+ initialized = True;
+}
+
+BOOL smb_register_passdb(const char *name, pdb_init_function init, int version)
+{
+ struct pdb_init_function_entry *entry = backends;
+
+ if(version != PASSDB_INTERFACE_VERSION)
+ return False;
+
+ DEBUG(5,("Attempting to register passdb backend %s\n", name));
+
+ /* Check for duplicates */
+ while(entry) {
+ if(strcasecmp(name, entry->name) == 0) {
+ DEBUG(0,("There already is a passdb backend registered with the name %s!\n", name));
+ return False;
+ }
+ entry = entry->next;
+ }
+
+ entry = smb_xmalloc(sizeof(struct pdb_init_function_entry));
+ entry->name = smb_xstrdup(name);
+ entry->init = init;
+
+ DLIST_ADD(backends, entry);
+ DEBUG(5,("Successfully added passdb backend '%s'\n", name));
+ return True;
+}
+
+static struct pdb_init_function_entry *pdb_find_backend_entry(const char *name)
+{
+ struct pdb_init_function_entry *entry = backends;
+ pstring stripped;
+
+ module_path_get_name(name, stripped);
+
+ while(entry) {
+ if (strequal(entry->name, stripped)) return entry;
+ entry = entry->next;
+ }
+
+ return NULL;
+}
static NTSTATUS context_setsampwent(struct pdb_context *context, BOOL update)
{
@@ -372,8 +408,10 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c
{
char *module_name = smb_xstrdup(selected);
char *module_location = NULL, *p;
+ struct pdb_init_function_entry *entry;
NTSTATUS nt_status = NT_STATUS_UNSUCCESSFUL;
- int i;
+
+ lazy_initialize_passdb();
p = strchr(module_name, ':');
@@ -385,27 +423,37 @@ static NTSTATUS make_pdb_methods_name(struct pdb_methods **methods, struct pdb_c
trim_string(module_name, " ", " ");
+
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))
- {
- DEBUG(5,("Found pdb backend %s (at pos %d)\n", module_name, i));
- nt_status = builtin_pdb_init_functions[i].init(context, methods, module_location);
- if (NT_STATUS_IS_OK(nt_status)) {
- DEBUG(5,("pdb backend %s has a valid init\n", selected));
- } else {
- DEBUG(0,("pdb backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status)));
- }
+
+ entry = pdb_find_backend_entry(module_name);
+
+ /* Try to find a module that contains this module */
+ if (!entry) {
+ DEBUG(2,("No builtin backend found, trying to load plugin\n"));
+ if(smb_probe_module("passdb", module_name) && !(entry = pdb_find_backend_entry(module_name))) {
+ DEBUG(0,("Plugin is available, but doesn't register passdb backend %s\n", module_name));
SAFE_FREE(module_name);
- return nt_status;
- break; /* unreached */
+ return NT_STATUS_UNSUCCESSFUL;
}
}
-
+
/* No such backend found */
+ if(!entry) {
+ DEBUG(0,("No builtin nor plugin backend for %s found\n", module_name));
+ SAFE_FREE(module_name);
+ return NT_STATUS_INVALID_PARAMETER;
+ }
+
+ DEBUG(5,("Found pdb backend %s\n", module_name));
+ nt_status = entry->init(context, methods, module_location);
+ if (NT_STATUS_IS_OK(nt_status)) {
+ DEBUG(5,("pdb backend %s has a valid init\n", selected));
+ } else {
+ DEBUG(0,("pdb backend %s did not correctly init (error was %s)\n", selected, nt_errstr(nt_status)));
+ }
SAFE_FREE(module_name);
- return NT_STATUS_INVALID_PARAMETER;
+ return nt_status;
}
/******************************************************************
diff --git a/source3/passdb/pdb_ldap.c b/source3/passdb/pdb_ldap.c
index 361cb8638a..a0853e2102 100644
--- a/source3/passdb/pdb_ldap.c
+++ b/source3/passdb/pdb_ldap.c
@@ -28,7 +28,6 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_PASSDB
-#ifdef HAVE_LDAP
/* TODO:
* persistent connections: if using NSS LDAP, many connections are made
* however, using only one within Samba would be nice
@@ -2754,20 +2753,9 @@ NTSTATUS pdb_init_ldapsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method
return NT_STATUS_OK;
}
-
-#else
-
-NTSTATUS pdb_init_ldapsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
-{
- DEBUG(0, ("ldap not detected at configure time, ldapsam not availalble!\n"));
- return NT_STATUS_UNSUCCESSFUL;
-}
-
-NTSTATUS pdb_init_ldapsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
+int pdb_ldap_init(void)
{
- DEBUG(0, ("ldap not dectected at configure time, ldapsam_nua not available!\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ smb_register_passdb("ldapsam", pdb_init_ldapsam, PASSDB_INTERFACE_VERSION);
+ smb_register_passdb("ldapsam_nua", pdb_init_ldapsam_nua, PASSDB_INTERFACE_VERSION);
+ return True;
}
-
-
-#endif
diff --git a/source3/passdb/pdb_mysql.c b/source3/passdb/pdb_mysql.c
index d0f30c6394..8af16bd787 100644
--- a/source3/passdb/pdb_mysql.c
+++ b/source3/passdb/pdb_mysql.c
@@ -1,3 +1,4 @@
+
/*
* MySQL password backend for samba
* Copyright (C) Jelmer Vernooij 2002
@@ -63,12 +64,10 @@ static int mysqlsam_debug_level = DBGC_ALL;
#undef DBGC_CLASS
#define DBGC_CLASS mysqlsam_debug_level
-PDB_MODULE_VERSIONING_MAGIC
-
typedef struct pdb_mysql_data {
MYSQL *handle;
MYSQL_RES *pwent;
- char *location;
+ const char *location;
} pdb_mysql_data;
/* Used to construct insert and update queries */
@@ -947,8 +946,8 @@ static NTSTATUS mysqlsam_enum_group_mapping(struct pdb_methods *methods,
}
-NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
- char *location)
+static NTSTATUS mysqlsam_init(struct pdb_context * pdb_context, struct pdb_methods ** pdb_method,
+ const char *location)
{
NTSTATUS nt_status;
struct pdb_mysql_data *data;
@@ -1032,3 +1031,11 @@ NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
return NT_STATUS_OK;
}
+
+int pdb_mysql_init()
+{
+ if(smb_register_passdb("mysql", mysqlsam_init, PASSDB_INTERFACE_VERSION))
+ return 0;
+
+ return 1;
+}
diff --git a/source3/passdb/pdb_nisplus.c b/source3/passdb/pdb_nisplus.c
index 0a42c36ea0..73d65af1c6 100644
--- a/source3/passdb/pdb_nisplus.c
+++ b/source3/passdb/pdb_nisplus.c
@@ -24,8 +24,6 @@
#include "includes.h"
-#ifdef WITH_NISPLUS_SAM
-
#ifdef BROKEN_NISPLUS_INCLUDE_FILES
/*
@@ -1555,11 +1553,7 @@ NTSTATUS pdb_init_nisplussam (PDB_CONTEXT * pdb_context,
return NT_STATUS_OK;
}
-#else
-NTSTATUS pdb_init_nisplussam (PDB_CONTEXT * c, PDB_METHODS ** m,
- const char *l)
+int pdb_nisplus_init(void)
{
- DEBUG (0, ("nisplus sam not compiled in!\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ return smb_register_passdb("nisplussam", pdb_init_nisplussam, PASSDB_INTERFACE_VERSION);
}
-#endif /* WITH_NISPLUS_SAM */
diff --git a/source3/passdb/pdb_smbpasswd.c b/source3/passdb/pdb_smbpasswd.c
index b5a2bbbfe7..7f74196633 100644
--- a/source3/passdb/pdb_smbpasswd.c
+++ b/source3/passdb/pdb_smbpasswd.c
@@ -1579,3 +1579,10 @@ NTSTATUS pdb_init_smbpasswd_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_meth
return NT_STATUS_OK;
}
+
+int pdb_smbpasswd_init(void)
+{
+ smb_register_passdb("smbpasswd", pdb_init_smbpasswd, PASSDB_INTERFACE_VERSION);
+ smb_register_passdb("smbpasswd_nua", pdb_init_smbpasswd_nua, PASSDB_INTERFACE_VERSION);
+ return True;
+}
diff --git a/source3/passdb/pdb_tdb.c b/source3/passdb/pdb_tdb.c
index c48c9567b1..7e2f4b832f 100644
--- a/source3/passdb/pdb_tdb.c
+++ b/source3/passdb/pdb_tdb.c
@@ -37,8 +37,6 @@ static int tdbsam_debug_level = DBGC_ALL;
#endif
-#ifdef WITH_TDB_SAM
-
#define PDB_VERSION "20010830"
#define PASSDB_FILE_NAME "passdb.tdb"
#define TDB_FORMAT_STRING "ddddddBBBBBBBBBBBBddBBwdwdBdd"
@@ -988,20 +986,10 @@ NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method,
return NT_STATUS_OK;
}
-
-#else
-
-NTSTATUS pdb_init_tdbsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
+int pdb_tdbsam_init(void)
{
- DEBUG(0, ("tdbsam not compiled in!\n"));
- return NT_STATUS_UNSUCCESSFUL;
+ smb_register_passdb("tdbsam", pdb_init_tdbsam, PASSDB_INTERFACE_VERSION);
+ smb_register_passdb("tdbsam_nua", pdb_init_tdbsam_nua, PASSDB_INTERFACE_VERSION);
+ return True;
}
-NTSTATUS pdb_init_tdbsam_nua(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location)
-{
- DEBUG(0, ("tdbsam_nua not compiled in!\n"));
- return NT_STATUS_UNSUCCESSFUL;
-}
-
-
-#endif
diff --git a/source3/passdb/pdb_unix.c b/source3/passdb/pdb_unix.c
index 86a86d60d4..ed83024248 100644
--- a/source3/passdb/pdb_unix.c
+++ b/source3/passdb/pdb_unix.c
@@ -124,3 +124,8 @@ NTSTATUS pdb_init_unixsam(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, co
/* There's not very much to initialise here */
return NT_STATUS_OK;
}
+
+int pdb_unix_init(void)
+{
+ return smb_register_passdb("unixsam", pdb_init_unixsam, PASSDB_INTERFACE_VERSION);
+}
diff --git a/source3/passdb/pdb_xml.c b/source3/passdb/pdb_xml.c
index edf70250e2..add5b924b8 100644
--- a/source3/passdb/pdb_xml.c
+++ b/source3/passdb/pdb_xml.c
@@ -40,8 +40,6 @@ static int xmlsam_debug_level = DBGC_ALL;
#undef DBGC_CLASS
#define DBGC_CLASS xmlsam_debug_level
-PDB_MODULE_VERSIONING_MAGIC
-
static char * iota(int a) {
static char tmp[10];
@@ -514,7 +512,7 @@ static NTSTATUS xmlsam_add_sam_account(struct pdb_methods *methods, SAM_ACCOUNT
return NT_STATUS_OK;
}
-NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
+NTSTATUS xmlsam_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
const char *location)
{
NTSTATUS nt_status;
@@ -565,3 +563,11 @@ NTSTATUS pdb_init(PDB_CONTEXT * pdb_context, PDB_METHODS ** pdb_method,
return NT_STATUS_OK;
}
+
+int pdb_xml_init()
+{
+ if(smb_register_passdb("xml", xmlsam_init, PASSDB_INTERFACE_VERSION))
+ return 0;
+
+ return 1;
+}