2 Unix SMB/CIFS implementation.
4 Copyright (C) Tim Potter 2000
5 Copyright (C) Anthony Liguori <aliguor@us.ibm.com> 2003
6 Copyright (C) Simo Sorce 2003
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DBGC_CLASS DBGC_IDMAP
32 /* Function to create a member of the idmap_methods list */
33 NTSTATUS (*reg_meth
)(struct idmap_methods
**methods
);
34 struct idmap_methods
*methods
;
35 } builtin_idmap_functions
[] = {
36 { "tdb", idmap_reg_tdb
, NULL
},
37 /* { "ldap", idmap_reg_ldap, NULL },*/
41 /* singleton pattern: uberlazy evaluation */
42 static struct idmap_methods
*impl
;
44 static struct idmap_methods
*get_impl(const char *name
)
47 struct idmap_methods
*ret
= NULL
;
49 while (builtin_idmap_functions
[i
].name
&& strcmp(builtin_idmap_functions
[i
].name
, name
)) {
53 if (builtin_idmap_functions
[i
].name
) {
55 if (!builtin_idmap_functions
[i
].methods
) {
56 builtin_idmap_functions
[i
].reg_meth(&builtin_idmap_functions
[i
].methods
);
59 ret
= builtin_idmap_functions
[i
].methods
;
65 /* Load idmap backend functions */
69 DEBUG(3, ("idmap_init: using '%s' as backend\n", lp_idmap_backend()));
71 impl
= get_impl(lp_idmap_backend());
73 DEBUG(0, ("set_impl: could not load backend '%s'\n", lp_idmap_backend()));
80 /* Initialize backend */
81 NTSTATUS
idmap_init(void)
85 if (!set_impl()) return NT_STATUS_UNSUCCESSFUL
;
88 if (NT_STATUS_IS_ERR(ret
)) {
89 DEBUG(3, ("idmap_init: init failed!\n"));
96 NTSTATUS
idmap_get_id_from_sid(id_t
*id
, int *id_type
, DOM_SID
*sid
)
100 if (!set_impl()) return NT_STATUS_UNSUCCESSFUL
;
102 ret
= impl
->get_id_from_sid(id
, id_type
, sid
);
103 if (NT_STATUS_IS_ERR(ret
)) {
104 DEBUG(3, ("idmap_get_id_from_sid: error fetching id!\n"));
110 /* Get SID from ID */
111 NTSTATUS
idmap_get_sid_from_id(DOM_SID
*sid
, id_t id
, int id_type
)
115 if (!set_impl()) return NT_STATUS_UNSUCCESSFUL
;
117 ret
= impl
->get_sid_from_id(sid
, id
, id_type
);
118 if (NT_STATUS_IS_ERR(ret
)) {
119 DEBUG(3, ("idmap_get_sid_from_id: error fetching sid!\n"));
127 NTSTATUS
idmap_close(void)
131 if (!set_impl()) return NT_STATUS_UNSUCCESSFUL
;
134 if (NT_STATUS_IS_ERR(ret
)) {
135 DEBUG(3, ("idmap_close: close failed!\n"));
141 /* Dump backend status */
142 void idmap_status(void)
144 if (!set_impl()) return;