s4:s3compat Add idmap_samba4 module that redirects to the Samba4 idmap
authorAndrew Bartlett <abartlet@samba.org>
Mon, 24 May 2010 05:01:44 +0000 (15:01 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 3 Jun 2010 11:57:33 +0000 (21:57 +1000)
This allows an existing idmap.ldb to be used with s3compat, and avoids
the need to set idmap uid and idmap gid in the smb.conf.

Andrew Bartlett

source4/s3compat/idmap_samba4.c [new file with mode: 0644]
source4/s3compat/s3compat.c
source4/s3compat/s3compat_names.c
source4/s3compat/wscript_build

diff --git a/source4/s3compat/idmap_samba4.c b/source4/s3compat/idmap_samba4.c
new file mode 100644 (file)
index 0000000..eb8762c
--- /dev/null
@@ -0,0 +1,97 @@
+/* 
+   Unix SMB/CIFS implementation.
+
+   idmap SAMBA4 backend
+
+   Copyright (C) Simo Sorce 2006
+   
+   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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "s3compat/s3compat_authenticate.h"
+#include "../winbind/idmap.h"
+
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_IDMAP
+
+/*****************************
+ Initialise idmap database. 
+*****************************/
+
+static NTSTATUS idmap_samba4_backend_init(struct idmap_domain *dom, const char *params)
+{      
+       dom->private_data = s3compat_idmap_init(dom);
+       if (!dom->private_data) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
+
+       return NT_STATUS_OK;
+}
+
+/**********************************
+ lookup a set of unix ids. 
+**********************************/
+
+static NTSTATUS idmap_samba4_unixids_to_sids(struct idmap_domain *dom, struct id_map **ids)
+{
+       struct idmap_context *idmap_ctx = talloc_get_type_abort(
+               dom->private_data, struct idmap_context);
+       NTSTATUS status;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
+
+       status = idmap_xids_to_sids(idmap_ctx, tmp_ctx, ids);
+       talloc_free(tmp_ctx);
+       return status;
+}
+
+/**********************************
+ lookup a set of sids. 
+**********************************/
+
+static NTSTATUS idmap_samba4_sids_to_unixids(struct idmap_domain *dom, struct id_map **ids)
+{
+       struct idmap_context *idmap_ctx = talloc_get_type_abort(
+               dom->private_data, struct idmap_context);
+       NTSTATUS status;
+       TALLOC_CTX *tmp_ctx = talloc_stackframe();
+       NT_STATUS_HAVE_NO_MEMORY(tmp_ctx);
+
+       status = idmap_sids_to_xids(idmap_ctx, tmp_ctx, ids);
+       talloc_free(tmp_ctx);
+       return status;
+}
+
+/**********************************
+ Close the idmap samba4 instance
+**********************************/
+
+static NTSTATUS idmap_samba4_close(struct idmap_domain *dom)
+{
+       talloc_free(dom->private_data);
+       return NT_STATUS_OK;
+}
+
+static struct idmap_methods samba4_methods = {
+       .init = idmap_samba4_backend_init,
+       .unixids_to_sids = idmap_samba4_unixids_to_sids,
+       .sids_to_unixids = idmap_samba4_sids_to_unixids,
+       .close_fn =idmap_samba4_close
+};
+
+NTSTATUS idmap_samba4_init(void)
+{
+       return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "samba4", &samba4_methods);
+}
index feb5aefbe30b460d3a2e822b008eff410d44b67a..326eda23e66eb98c683bfaabf14a124c5a25dea0 100644 (file)
@@ -52,9 +52,10 @@ void s3compat_initialise(const char *config_file, bool interactive)
        print_backend_init(smbd_messaging_context());
        share_info_db_init();
 
-       /* Register our 'imposter' auth module, which redirects to samba4 */
+       /* Register our 'imposter' modules, which redirect to samba4 */
        auth_samba4_init();
        pdb_samba4_init();
+       idmap_samba4_init();
 
        DEBUG(0,("s3compat: initialised samba3 version: %s\n",
                 samba_version_string()));
index 32ca3cd1acbeae3c3a9e9f2d5fd3133dc0748098..42e14d6d1cdebde6297ed689ae1b9c13982c008a 100644 (file)
@@ -78,3 +78,14 @@ const char *lp_passdb_backend(void)
 {
        return "samba4";
 }
+
+const char *lp_idmap_backend(void)
+{
+       return "samba4";
+}
+
+char *lp_idmap_alloc_backend(void)
+{
+       /* We don't provide the alloc functionality explicitly */
+       return NULL;
+}
index 0e6b01573b0107e17dd9d96f4624b9553c7c6a9e..68183fdd09c917fe0bb521701d69b0c1daca0d75 100644 (file)
@@ -850,7 +850,7 @@ bld.SAMBA_SUBSYSTEM('s3_winbind',
 bld.SAMBA_SUBSYSTEM('s3compat_wrapper',
                     includes=SAMBA3_INCLUDES,
                     autoproto='s3compat_wrapper_proto.h',
-                    source='s3compat.c s3compat_winbindd.c auth_samba4.c pdb_samba4.c',
+                    source='s3compat.c s3compat_winbindd.c auth_samba4.c pdb_samba4.c idmap_samba4.c',
                     deps='tdb tevent ldb SAMDB_COMMON',
                     hide_symbols=True)