summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2003-03-07 23:47:59 +0000
committerSimo Sorce <idra@samba.org>2003-03-07 23:47:59 +0000
commit64e49aa3c5392fd0ba5fc33ea21eff87c548995e (patch)
tree158b1a0bdd2e71ba348d6daa256ea1fde9ec66ff /source3
parenteed8772da109ecc6e9f35fd27b719795b28a47fb (diff)
downloadsamba-64e49aa3c5392fd0ba5fc33ea21eff87c548995e.tar.gz
samba-64e49aa3c5392fd0ba5fc33ea21eff87c548995e.tar.bz2
samba-64e49aa3c5392fd0ba5fc33ea21eff87c548995e.zip
initial work for the new idmpa interface
(This used to be commit 8338e74ac4e5f31150c96f459a67e52090dc6013)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/idmap.h49
-rw-r--r--source3/sam/idmap.c145
2 files changed, 194 insertions, 0 deletions
diff --git a/source3/include/idmap.h b/source3/include/idmap.h
new file mode 100644
index 0000000000..0d358d3fbe
--- /dev/null
+++ b/source3/include/idmap.h
@@ -0,0 +1,49 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Idmap headers
+
+ Copyright (C) Anthony Liguori 2003
+ Copyright (C) Simo Sorce 2003
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#define ID_USERID 1
+#define ID_GROUPID 2
+#define ID_OTHER 3
+
+typedef union id_t {
+ uid_t uid;
+ gid_t gid;
+} id_t;
+
+/* Filled out by IDMAP backends */
+struct idmap_methods {
+
+ /* Called when backend is first loaded */
+ NTSTATUS (*init)(void);
+
+ NTSTATUS (*get_sid_from_id)(DOM_SID *sid, id_t id, int id_type);
+ NTSTATUS (*get_id_from_sid)(id_t *id, int *id_type, DOM_SID *sid);
+
+ /* Called when backend is unloaded */
+ NTSTATUS (*close)(void);
+
+ /* Called to dump backend status */
+ void (*status)(void);
+};
+
diff --git a/source3/sam/idmap.c b/source3/sam/idmap.c
new file mode 100644
index 0000000000..617cbc9d28
--- /dev/null
+++ b/source3/sam/idmap.c
@@ -0,0 +1,145 @@
+/*
+ Unix SMB/CIFS implementation.
+ Winbind ID Mapping
+ Copyright (C) Tim Potter 2000
+ Copyright (C) Anthony Liguori <aliguor@us.ibm.com> 2003
+ Copyright (C) Simo Sorce 2003
+
+ 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"
+#include "idmap.h"
+
+static struct {
+
+ const char *name;
+ /* Function to create a member of the idmap_methods list */
+ NTSTATUS (*reg_meth)(struct idmap_methods **methods);
+ struct idmap_methods *methods;
+} builtin_idmap_functions[] = {
+ { "tdb", idmap_reg_tdb, NULL },
+ /* { "ldap", idmap_reg_ldap, NULL },*/
+ { NULL, NULL, NULL }
+};
+
+/* singleton pattern: uberlazy evaluation */
+static struct idmap_methods *impl;
+
+static struct idmap_methods *get_impl(const char *name)
+{
+ int i = 0;
+ struct idmap_methods *ret = NULL;
+
+ while (builtin_idmap_functions[i].name && strcmp(builtin_idmap_functions[i].name, name)) {
+ i++;
+ }
+
+ if (builtin_idmap_functions[i].name) {
+
+ if (!builtin_idmap_functions[i].methods) {
+ builtin_idmap_functions[i].reg_meth(&builtin_idmap_functions[i].methods);
+ }
+
+ ret = builtin_idmap_functions[i].methods;
+ }
+
+ return ret;
+}
+
+/* Load idmap backend functions */
+BOOL set_impl(void)
+{
+ if (!impl) {
+ DEBUG(3, ("idmap_init: using '%s' as backend\n", lp_idmap_backend()));
+
+ impl = get_impl(lp_idmap_backend());
+ if (!impl) {
+ DEBUG(0, ("set_impl: could not load backend '%s'\n", lp_idmap_backend()));
+ return False;
+ }
+ }
+ return True;
+}
+
+/* Initialize backend */
+NTSTATUS idmap_init(void)
+{
+ NTSTATUS ret;
+
+ if (!set_impl()) return NT_STATUS_UNSUCCESSFUL;
+
+ ret = impl->init();
+ if (NT_STATUS_IS_ERR(ret)) {
+ DEBUG(3, ("idmap_init: init failed!\n"));
+ }
+
+ return ret;
+}
+
+/* Get ID from SID */
+NTSTATUS idmap_get_id_from_sid(id_t *id, int *id_type, DOM_SID *sid)
+{
+ NTSTATUS ret;
+
+ if (!set_impl()) return NT_STATUS_UNSUCCESSFUL;
+
+ ret = impl->get_id_from_sid(id, id_type, sid);
+ if (NT_STATUS_IS_ERR(ret)) {
+ DEBUG(3, ("idmap_get_id_from_sid: error fetching id!\n"));
+ }
+
+ return ret;
+}
+
+/* Get SID from ID */
+NTSTATUS idmap_get_sid_from_id(DOM_SID *sid, id_t id, int id_type)
+{
+ NTSTATUS ret;
+
+ if (!set_impl()) return NT_STATUS_UNSUCCESSFUL;
+
+ ret = impl->get_sid_from_id(sid, id, id_type);
+ if (NT_STATUS_IS_ERR(ret)) {
+ DEBUG(3, ("idmap_get_sid_from_id: error fetching sid!\n"));
+ }
+
+ return ret;
+}
+
+
+/* Close backend */
+NTSTATUS idmap_close(void)
+{
+ NTSTATUS ret;
+
+ if (!set_impl()) return NT_STATUS_UNSUCCESSFUL;
+
+ ret = impl->close();
+ if (NT_STATUS_IS_ERR(ret)) {
+ DEBUG(3, ("idmap_close: close failed!\n"));
+ }
+
+ return ret;
+}
+
+/* Dump backend status */
+void idmap_status(void)
+{
+ if (!set_impl()) return;
+
+ impl->status();
+}
+