summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2003-05-29 19:08:40 +0000
committerJelmer Vernooij <jelmer@samba.org>2003-05-29 19:08:40 +0000
commit69b50029f4472d29e823e2b541a59a420ab706cb (patch)
treeaf912650e07b1f0b9f8f33131e8081cc12ae675f
parent44fa85fd60baf1dba4e4858ee23b9ebbd7e13ef9 (diff)
downloadsamba-69b50029f4472d29e823e2b541a59a420ab706cb.tar.gz
samba-69b50029f4472d29e823e2b541a59a420ab706cb.tar.bz2
samba-69b50029f4472d29e823e2b541a59a420ab706cb.zip
Add smb_register_idmap(). Based on a patch from metze
(This used to be commit 7e352f5c62c4889bdf2662dded1e74a354890dc7)
-rw-r--r--source3/Makefile.in33
-rw-r--r--source3/configure.in6
-rw-r--r--source3/include/idmap.h3
-rw-r--r--source3/sam/idmap.c85
-rw-r--r--source3/sam/idmap_tdb.c8
-rw-r--r--source3/sam/idmap_winbind.c9
6 files changed, 94 insertions, 50 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in
index 536d45bd1f..945953fe48 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -31,6 +31,7 @@ PRINTLIBS=@PRINTLIBS@
AUTHLIBS=@AUTHLIBS@
ACLLIBS=@ACLLIBS@
PASSDBLIBS=@PASSDBLIBS@
+IDMAP_LIBS=@IDMAP_LIBS@
ADSLIBS=@ADSLIBS@
KRB5LIBS=@KRB5_LIBS@
@@ -60,6 +61,7 @@ LIBDIR = @libdir@
VFSLIBDIR = $(LIBDIR)/vfs
PDBLIBDIR = $(LIBDIR)/pdb
RPCLIBDIR = $(LIBDIR)/rpc
+IDMAPLIBDIR = $(LIBDIR)/idmap
CHARSETLIBDIR = $(LIBDIR)/charset
AUTHLIBDIR = $(LIBDIR)/auth
CONFIGDIR = @configdir@
@@ -144,9 +146,10 @@ SCRIPTS = $(srcdir)/script/smbtar $(builddir)/script/findsmb
VFS_MODULES = @VFS_MODULES@
PDB_MODULES = @PDB_MODULES@
RPC_MODULES = @RPC_MODULES@
+IDMAP_MODULES = @IDMAP_MODULES@
CHARSET_MODULES = @CHARSET_MODULES@
AUTH_MODULES = @AUTH_MODULES@
-MODULES = $(VFS_MODULES) $(PDB_MODULES) $(RPC_MODULES) $(CHARSET_MODULES) $(AUTH_MODULES)
+MODULES = $(VFS_MODULES) $(PDB_MODULES) $(RPC_MODULES) $(IDMAP_MODULES) $(CHARSET_MODULES) $(AUTH_MODULES)
######################################################################
# object file lists
@@ -280,7 +283,7 @@ XML_OBJ = passdb/pdb_xml.o
MYSQL_OBJ = passdb/pdb_mysql.o
DEVEL_HELP_OBJ = modules/weird.o
-IDMAP_OBJ = sam/idmap.o sam/idmap_util.o sam/idmap_tdb.o sam/idmap_winbind.o
+IDMAP_OBJ = sam/idmap.o sam/idmap_util.o @IDMAP_STATIC@
GROUPDB_OBJ = groupdb/mapping.o
@@ -731,7 +734,7 @@ bin/.dummy:
bin/smbd@EXEEXT@: $(SMBD_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(SMBD_OBJ) $(ADSLIBS) $(LDFLAGS) $(DYNEXP) $(PRINTLIBS) \
- $(AUTHLIBS) $(ACLLIBS) $(PASSDBLIBS) $(LIBS) @POPTLIBS@
+ $(AUTHLIBS) $(ACLLIBS) $(PASSDBLIBS) $(IDMAP_LIBS) $(LIBS) @POPTLIBS@
bin/nmbd@EXEEXT@: $(NMBD_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@@ -744,11 +747,11 @@ bin/wrepld@EXEEXT@: $(WREPL_OBJ) @BUILD_POPT@ bin/.dummy
bin/swat@EXEEXT@: $(SWAT_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@$(CC) $(FLAGS) -o $@ $(SWAT_OBJ) $(LDFLAGS) $(DYNEXP) $(PRINTLIBS) \
- $(AUTHLIBS) $(LIBS) $(PASSDBLIBS) @POPTLIBS@ $(KRB5LIBS)
+ $(AUTHLIBS) $(LIBS) $(PASSDBLIBS) $(IDMAP_LIBS) @POPTLIBS@ $(KRB5LIBS)
bin/rpcclient@EXEEXT@: $(RPCCLIENT_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ $(PASSDBLIBS) $(RPCCLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(ADSLIBS)
+ @$(CC) $(FLAGS) -o $@ $(PASSDBLIBS) $(IDMAP_LIBS) $(RPCCLIENT_OBJ) $(LDFLAGS) $(DYNEXP) $(TERMLDFLAGS) $(TERMLIBS) $(LIBS) @POPTLIBS@ $(ADSLIBS)
bin/smbclient@EXEEXT@: $(CLIENT_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@@ -804,15 +807,15 @@ bin/smbtree@EXEEXT@: $(SMBTREE_OBJ) @BUILD_POPT@ bin/.dummy
bin/smbpasswd@EXEEXT@: $(SMBPASSWD_OBJ) bin/.dummy
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ $(SMBPASSWD_OBJ) $(PASSDBLIBS) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS)
+ @$(CC) $(FLAGS) -o $@ $(SMBPASSWD_OBJ) $(PASSDBLIBS) $(IDMAP_LIBS) $(LDFLAGS) $(DYNEXP) $(LIBS) $(KRB5LIBS)
bin/pdbedit@EXEEXT@: $(PDBEDIT_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ $(PASSDBLIBS) $(PDBEDIT_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@
+ @$(CC) $(FLAGS) -o $@ $(PASSDBLIBS) $(IDMAP_LIBS) $(PDBEDIT_OBJ) $(LDFLAGS) $(DYNEXP) $(LIBS) @POPTLIBS@
bin/samtest@EXEEXT@: $(SAMTEST_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
- @$(CC) $(FLAGS) -o $@ $(SAMTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDBLIBS) $(ADSLIBS)
+ @$(CC) $(FLAGS) -o $@ $(SAMTEST_OBJ) $(LDFLAGS) $(TERMLDFLAGS) $(TERMLIBS) $(DYNEXP) $(LIBS) @POPTLIBS@ $(PASSDBLIBS) $(IDMAP_LIBS) $(ADSLIBS)
bin/nmblookup@EXEEXT@: $(NMBLOOKUP_OBJ) @BUILD_POPT@ bin/.dummy
@echo Linking $@
@@ -905,7 +908,7 @@ bin/libsmbclient.a: $(LIBSMBCLIENT_PICOBJS)
bin/libbigballofmud.@SHLIBEXT@: $(LIBBIGBALLOFMUD_PICOBJS)
@echo Linking bigballofmud shared library $@
@$(SHLD) $(LDSHFLAGS) -o $@ $(LIBBIGBALLOFMUD_PICOBJS) $(LIBS) \
- @SONAMEFLAG@`basename $@`.$(LIBBIGBALLOFMUD_MAJOR) $(PASSDBLIBS) $(ADSLIBS)
+ @SONAMEFLAG@`basename $@`.$(LIBBIGBALLOFMUD_MAJOR) $(PASSDBLIBS) $(IDMAP_LIBS) $(ADSLIBS)
ln -snf libbigballofmud.so bin/libbigballofmud.so.0
# It would be nice to build a static bigballofmud too, but when I try
@@ -1042,6 +1045,11 @@ bin/xml.@SHLIBEXT@: $(XML_OBJ:.o=.po)
@$(SHLD) $(LDSHFLAGS) -o $@ $(XML_OBJ:.o=.po) @XML_LIBS@ \
@SONAMEFLAG@`basename $@`
+bin/winbind_idmap.@SHLIBEXT@: sam/idmap_winbind.po
+ @echo "Building plugin $@"
+ @$(SHLD) $(LDSHFLAGS) -o $@ sam/idmap_winbind.po \
+ @SONAMEFLAG@`basename $@`
+
bin/audit.@SHLIBEXT@: $(VFS_AUDIT_OBJ:.o=.po)
@echo "Building plugin $@"
@$(SHLD) $(LDSHFLAGS) -o $@ $(VFS_AUDIT_OBJ:.o=.po) \
@@ -1114,7 +1122,7 @@ install-everything: install installmodules
# is not used
installdirs:
- @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(VFSLIBDIR) $(DESTDIR)$(PDBLIBDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
+ @$(SHELL) $(srcdir)/script/installdirs.sh $(DESTDIR)$(BASEDIR) $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(DESTDIR)$(PRIVATEDIR) $(DESTDIR)$(PIDDIR) $(DESTDIR)$(LOCKDIR)
installservers: all installdirs
@$(SHELL) $(srcdir)/script/installbin.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(LIBDIR) $(DESTDIR)$(VARDIR) $(SBIN_PROGS)
@@ -1128,6 +1136,7 @@ installmodules: modules installdirs
@$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(VFSLIBDIR) $(VFS_MODULES)
@$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(PDBLIBDIR) $(PDB_MODULES)
@$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(RPCLIBDIR) $(RPC_MODULES)
+ @$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(IDMAPLIBDIR) $(IDMAP_MODULES)
@$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(CHARSETLIBDIR) $(CHARSET_MODULES)
@$(SHELL) $(srcdir)/script/installmodules.sh $(INSTALLPERMS) $(DESTDIR)$(BASEDIR) $(DESTDIR)$(AUTHLIBDIR) $(AUTH_MODULES)
@@ -1161,7 +1170,7 @@ python_ext: $(PYTHON_PICOBJS)
fi
PYTHON_OBJS="$(PYTHON_PICOBJS)" \
PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS) $(FLAGS)" \
- LIBS="$(LIBS) $(PASSDBLIBS) $(KRB5LIBS)" \
+ LIBS="$(LIBS) $(PASSDBLIBS) $(IDMAP_LIBS) $(KRB5LIBS)" \
$(PYTHON) python/setup.py build
python_install: $(PYTHON_PICOBJS)
@@ -1227,7 +1236,7 @@ clean: delheaders python_clean
# This is quite ugly actually.. But we need to make
# sure the changes to include/config.h are used.
modules_clean:
- @-rm -f @MODULES_CLEAN@ auth/auth.o passdb/pdb_interface.o rpc_server/srv_pipe_hnd.o lib/iconv.o smbd/vfs.o
+ @-rm -f @MODULES_CLEAN@ auth/auth.o passdb/pdb_interface.o smbd/server.o lib/iconv.o smbd/vfs.o sam/idmap.o
# Making this target will just make sure that the prototype files
# exist, not necessarily that they are up to date. Since they're
diff --git a/source3/configure.in b/source3/configure.in
index ebe0d44192..fb9ebe8248 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -154,6 +154,7 @@ AC_SUBST(AUTHLIBS)
AC_SUBST(ACLLIBS)
AC_SUBST(ADSLIBS)
AC_SUBST(PASSDBLIBS)
+AC_SUBST(IDMAP_LIBS)
AC_SUBST(KRB5_LIBS)
AC_SUBST(LDAP_LIBS)
AC_SUBST(LDAP_OBJ)
@@ -3698,6 +3699,7 @@ dnl Always built these modules static
MODULE_pdb_guest=STATIC
MODULE_rpc_spoolss=STATIC
MODULE_rpc_srv=STATIC
+MODULE_idmap_tdb=STATIC
AC_ARG_WITH(static-modules,
[ --with-static-modules=MODULES Comma-seperated list of names of modules to statically link in],
@@ -3747,6 +3749,10 @@ SMB_MODULE(rpc_samr, \$(RPC_SAMR_OBJ), "bin/librpc_samr.$SHLIBEXT", RPC)
SMB_MODULE(rpc_echo, \$(RPC_ECHO_OBJ), "bin/librpc_echo.$SHLIBEXT", RPC)
SMB_SUBSYSTEM(RPC)
+SMB_MODULE(idmap_winbind, sam/idmap_winbind.o, "bin/winbind_idmap.$SHLIBEXT", IDMAP)
+SMB_MODULE(idmap_tdb, sam/idmap_tdb.o, "bin/winbind_tdb.$SHLIBEXT", IDMAP)
+SMB_SUBSYSTEM(IDMAP)
+
SMB_MODULE(charset_weird, modules/weird.o, "bin/weird.$SHLIBEXT", CHARSET)
SMB_SUBSYSTEM(CHARSET)
diff --git a/source3/include/idmap.h b/source3/include/idmap.h
index 5d8e31a163..1267ac27bc 100644
--- a/source3/include/idmap.h
+++ b/source3/include/idmap.h
@@ -22,6 +22,9 @@
Boston, MA 02111-1307, USA.
*/
+#define SMB_IDMAP_INTERFACE_VERSION 1
+
+
#define ID_EMPTY 0x00
#define ID_USERID 0x01
#define ID_GROUPID 0x02
diff --git a/source3/sam/idmap.c b/source3/sam/idmap.c
index e2796e0864..62377a9228 100644
--- a/source3/sam/idmap.c
+++ b/source3/sam/idmap.c
@@ -24,50 +24,69 @@
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_IDMAP
-static struct {
-
+struct idmap_function_entry {
const char *name;
- /* Function to create a member of the idmap_methods list */
- NTSTATUS (*reg_meth)(struct idmap_methods **methods);
struct idmap_methods *methods;
-
-} remote_idmap_functions[] = {
- { "winbind", idmap_reg_winbind, NULL },
- { NULL, NULL, NULL }
+ struct idmap_function_entry *prev,*next;
};
+static struct idmap_function_entry *backends = NULL;
+
static struct idmap_methods *local_map;
static struct idmap_methods *remote_map;
static void lazy_initialize_idmap(void)
{
static BOOL initialized = False;
- if (initialized) return;
- idmap_init();
- initialized = True;
-}
-
+ if(!initialized) {
+ idmap_init();
+ initialized = True;
+ }
+}
static struct idmap_methods *get_methods(const char *name)
{
- int i = 0;
- struct idmap_methods *ret = NULL;
+ struct idmap_function_entry *entry = backends;
- while (remote_idmap_functions[i].name && strcmp(remote_idmap_functions[i].name, name)) {
- i++;
+ while(entry) {
+ if (strcmp(entry->name, name) == 0) return entry->methods;
+ entry = entry->next;
}
- if (remote_idmap_functions[i].name) {
+ return NULL;
+}
- if (!remote_idmap_functions[i].methods) {
- remote_idmap_functions[i].reg_meth(&remote_idmap_functions[i].methods);
- }
+NTSTATUS smb_register_idmap(int version, const char *name, struct idmap_methods *methods)
+{
+ struct idmap_function_entry *entry;
+
+ if ((version != SMB_IDMAP_INTERFACE_VERSION)) {
+ DEBUG(0, ("Failed to register idmap module.\n"
+ "The module was compiled against SMB_IDMAP_INTERFACE_VERSION %d,\n"
+ "current SMB_IDMAP_INTERFACE_VERSION is %d.\n"
+ "Please recompile against the current version of samba!\n",
+ version, SMB_IDMAP_INTERFACE_VERSION));
+ return NT_STATUS_OBJECT_TYPE_MISMATCH;
+ }
+
+ if (!name || !name[0] || !methods) {
+ DEBUG(0,("smb_register_idmap() called with NULL pointer or empty name!\n"));
+ return NT_STATUS_INVALID_PARAMETER;
+ }
- ret = remote_idmap_functions[i].methods;
+ if (get_methods(name)) {
+ DEBUG(0,("idmap module %s already registered!\n", name));
+ return NT_STATUS_OBJECT_NAME_COLLISION;
}
- return ret;
+ entry = smb_xmalloc(sizeof(struct idmap_function_entry));
+ entry->name = smb_xstrdup(name);
+ entry->methods = methods;
+
+ DLIST_ADD(backends, entry);
+ DEBUG(5, ("Successfully added idmap backend '%s'\n", name));
+ return NT_STATUS_OK;
}
/* Initialize backend */
@@ -75,8 +94,17 @@ BOOL idmap_init(void)
{
const char *remote_backend = lp_idmap_backend();
+ if (!backends)
+ static_init_idmap;
+
if (!local_map) {
- idmap_reg_tdb(&local_map);
+ local_map = get_methods("tdb");
+
+ if (!local_map) {
+ DEBUG(0, ("idmap_init: could not find tdb backend!\n"));
+ return False;
+ }
+
if (NT_STATUS_IS_ERR(local_map->init())) {
DEBUG(0, ("idmap_init: could not load or create local backend!\n"));
return False;
@@ -86,12 +114,15 @@ BOOL idmap_init(void)
if (!remote_map && remote_backend && *remote_backend != 0) {
DEBUG(3, ("idmap_init: using '%s' as remote backend\n", remote_backend));
- remote_map = get_methods(remote_backend);
- if (!remote_map) {
+ if((remote_map = get_methods(remote_backend)) ||
+ (NT_STATUS_IS_OK(smb_probe_module("idmap", remote_backend)) &&
+ (remote_map = get_methods(remote_backend)))) {
+ remote_map->init();
+ } else {
DEBUG(0, ("idmap_init: could not load remote backend '%s'\n", remote_backend));
return False;
}
- remote_map->init();
+
}
return True;
diff --git a/source3/sam/idmap_tdb.c b/source3/sam/idmap_tdb.c
index 31c12241bf..373fb66a1b 100644
--- a/source3/sam/idmap_tdb.c
+++ b/source3/sam/idmap_tdb.c
@@ -424,7 +424,7 @@ static void db_idmap_status(void)
/* Display complete mapping of users and groups to rids */
}
-struct idmap_methods db_methods = {
+static struct idmap_methods db_methods = {
db_idmap_init,
db_get_sid_from_id,
@@ -435,9 +435,7 @@ struct idmap_methods db_methods = {
};
-NTSTATUS idmap_reg_tdb(struct idmap_methods **meth)
+NTSTATUS idmap_tdb_init()
{
- *meth = &db_methods;
-
- return NT_STATUS_OK;
+ return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "tdb", &db_methods);
}
diff --git a/source3/sam/idmap_winbind.c b/source3/sam/idmap_winbind.c
index bc3c8ad60c..bff870b8fc 100644
--- a/source3/sam/idmap_winbind.c
+++ b/source3/sam/idmap_winbind.c
@@ -135,8 +135,7 @@ static void db_status(void) {
return;
}
-struct idmap_methods winbind_methods = {
-
+static struct idmap_methods winbind_methods = {
db_init,
db_get_sid_from_id,
db_get_id_from_sid,
@@ -146,10 +145,8 @@ struct idmap_methods winbind_methods = {
};
-NTSTATUS idmap_reg_winbind(struct idmap_methods **meth)
+NTSTATUS idmap_winbind_init(void)
{
- *meth = &winbind_methods;
-
- return NT_STATUS_OK;
+ return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "winbind", &winbind_methods);
}