rename 'winbind backend' to 'idmap backend'. Put paramter in security section.....
[Samba.git] / source / nsswitch / winbindd_idmap.c
blob0a17fcd87f08b6114e8300421515a546397fce29
1 /*
2 Unix SMB/CIFS implementation.
3 Winbind ID Mapping
4 Copyright (C) Tim Potter 2000
5 Copyright (C) Anthony Liguori <aliguor@us.ibm.com> 2003
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "winbindd.h"
24 static struct {
25 const char *name;
26 /* Function to create a member of the idmap_methods list */
27 BOOL (*reg_meth)(struct idmap_methods **methods);
28 struct idmap_methods *methods;
29 } builtin_idmap_functions[] = {
30 { "tdb", winbind_idmap_reg_tdb, NULL },
31 /* { "ldap", winbind_idmap_reg_ldap, NULL },*/
32 { NULL, NULL, NULL }
35 /* singleton pattern: uberlazy evaluation */
36 static struct idmap_methods *impl;
38 static struct idmap_methods *get_impl(const char *name)
40 int i = 0;
41 struct idmap_methods *ret = NULL;
43 while (builtin_idmap_functions[i].name &&
44 strcmp(builtin_idmap_functions[i].name, name)) {
45 i++;
48 if (builtin_idmap_functions[i].name) {
49 if (!builtin_idmap_functions[i].methods) {
50 builtin_idmap_functions[i].reg_meth(&builtin_idmap_functions[i].methods);
53 ret = builtin_idmap_functions[i].methods;
56 return ret;
59 /* Initialize backend */
60 BOOL winbindd_idmap_init(void)
62 BOOL ret = False;
64 DEBUG(3, ("winbindd_idmap_init: using '%s' as backend\n",
65 lp_idmap_backend()));
67 if (!impl) {
68 impl = get_impl(lp_idmap_backend());
69 if (!impl) {
70 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
71 lp_idmap_backend()));
75 if (impl) {
76 ret = impl->init();
79 DEBUG(3, ("winbind_idmap_init: returning %s\n", ret ? "true" : "false"));
81 return ret;
84 /* Get UID from SID */
85 BOOL winbindd_idmap_get_uid_from_sid(DOM_SID *sid, uid_t *uid)
87 BOOL ret = False;
89 if (!impl) {
90 impl = get_impl(lp_idmap_backend());
91 if (!impl) {
92 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
93 lp_idmap_backend()));
97 if (impl) {
98 ret = impl->get_uid_from_sid(sid, uid);
101 return ret;
104 /* Get GID from SID */
105 BOOL winbindd_idmap_get_gid_from_sid(DOM_SID *sid, gid_t *gid)
107 BOOL ret = False;
109 if (!impl) {
110 impl = get_impl(lp_idmap_backend());
111 if (!impl) {
112 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
113 lp_idmap_backend()));
117 if (impl) {
118 ret = impl->get_gid_from_sid(sid, gid);
121 return ret;
124 /* Get UID from RID */
125 BOOL winbindd_idmap_get_uid_from_rid(const char *dom_name, uint32 rid,
126 uid_t *uid)
128 BOOL ret = False;
130 if (!impl) {
131 impl = get_impl(lp_idmap_backend());
132 if (!impl) {
133 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
134 lp_idmap_backend()));
138 if (impl) {
139 ret = impl->get_uid_from_rid(dom_name, rid, uid);
142 return ret;
145 /* Get GID From RID */
146 BOOL winbindd_idmap_get_gid_from_rid(const char *dom_name, uint32 rid,
147 gid_t *gid)
149 BOOL ret = False;
151 if (!impl) {
152 impl = get_impl(lp_idmap_backend());
153 if (!impl) {
154 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
155 lp_idmap_backend()));
159 if (impl) {
160 ret = impl->get_gid_from_rid(dom_name, rid, gid);
163 return ret;
166 /* Get SID from UID */
167 BOOL winbindd_idmap_get_sid_from_uid(uid_t uid, DOM_SID *sid)
169 BOOL ret = False;
171 if (!impl) {
172 impl = get_impl(lp_idmap_backend());
173 if (!impl) {
174 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
175 lp_idmap_backend()));
179 if (impl) {
180 ret = impl->get_sid_from_uid(uid, sid);
183 return ret;
186 /* Get SID from GID */
187 BOOL winbindd_idmap_get_sid_from_gid(gid_t gid, DOM_SID *sid)
189 BOOL ret = False;
191 if (!impl) {
192 impl = get_impl(lp_idmap_backend());
195 if (impl) {
196 ret = impl->get_sid_from_gid(gid, sid);
197 } else {
198 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
199 lp_idmap_backend()));
202 return ret;
205 /* Get RID From UID */
206 BOOL winbindd_idmap_get_rid_from_uid(uid_t uid, uint32 *user_rid,
207 struct winbindd_domain **domain)
209 BOOL ret = False;
211 if (!impl) {
212 impl = get_impl(lp_idmap_backend());
215 if (impl) {
216 ret = impl->get_rid_from_uid(uid, user_rid, domain);
217 } else {
218 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
219 lp_idmap_backend()));
222 return ret;
225 /* Get RID from GID */
226 BOOL winbindd_idmap_get_rid_from_gid(gid_t gid, uint32 *group_rid,
227 struct winbindd_domain **domain)
229 BOOL ret = False;
231 if (!impl) {
232 impl = get_impl(lp_idmap_backend());
235 if (impl) {
236 ret = impl->get_rid_from_gid(gid, group_rid, domain);
237 } else {
238 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
239 lp_idmap_backend()));
242 return ret;
245 /* Close backend */
246 BOOL winbindd_idmap_close(void)
248 BOOL ret = False;
250 if (!impl) {
251 impl = get_impl(lp_idmap_backend());
254 if (impl) {
255 ret = impl->close();
256 } else {
257 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
258 lp_idmap_backend()));
261 return ret;
264 /* Dump backend status */
265 void winbindd_idmap_status(void)
267 if (!impl) {
268 impl = get_impl(lp_idmap_backend());
271 if (impl) {
272 impl->status();
273 } else {
274 DEBUG(0, ("winbindd_idmap_init: could not load backend '%s'\n",
275 lp_idmap_backend()));