objectclass -> objectClass
[Samba/gebeck_regimport.git] / source3 / winbindd / idmap_ldap.c
blobfa80fae5d840c7463e586d09f08b8fbfa6c7a2f7
1 /*
2 Unix SMB/CIFS implementation.
4 idmap LDAP backend
6 Copyright (C) Tim Potter 2000
7 Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2003
8 Copyright (C) Gerald Carter 2003
9 Copyright (C) Simo Sorce 2003-2007
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "includes.h"
26 #include "winbindd.h"
28 #undef DBGC_CLASS
29 #define DBGC_CLASS DBGC_IDMAP
31 #include <lber.h>
32 #include <ldap.h>
34 #include "smbldap.h"
36 struct idmap_ldap_context {
37 struct smbldap_state *smbldap_state;
38 char *url;
39 char *suffix;
40 char *user_dn;
41 uint32_t filter_low_id, filter_high_id; /* Filter range */
42 bool anon;
45 struct idmap_ldap_alloc_context {
46 struct smbldap_state *smbldap_state;
47 char *url;
48 char *suffix;
49 char *user_dn;
50 uid_t low_uid, high_uid; /* Range of uids */
51 gid_t low_gid, high_gid; /* Range of gids */
55 #define CHECK_ALLOC_DONE(mem) do { \
56 if (!mem) { \
57 DEBUG(0, ("Out of memory!\n")); \
58 ret = NT_STATUS_NO_MEMORY; \
59 goto done; \
60 } } while (0)
62 /**********************************************************************
63 IDMAP ALLOC TDB BACKEND
64 **********************************************************************/
66 static struct idmap_ldap_alloc_context *idmap_alloc_ldap;
68 /*********************************************************************
69 ********************************************************************/
71 static NTSTATUS get_credentials( TALLOC_CTX *mem_ctx,
72 struct smbldap_state *ldap_state,
73 const char *config_option,
74 struct idmap_domain *dom,
75 char **dn )
77 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
78 char *secret = NULL;
79 const char *tmp = NULL;
80 char *user_dn = NULL;
81 bool anon = False;
83 /* assume anonymous if we don't have a specified user */
85 tmp = lp_parm_const_string(-1, config_option, "ldap_user_dn", NULL);
87 if ( tmp ) {
88 if (!dom) {
89 /* only the alloc backend can pass in a NULL dom */
90 secret = idmap_fetch_secret("ldap", True,
91 NULL, tmp);
92 } else {
93 secret = idmap_fetch_secret("ldap", False,
94 dom->name, tmp);
97 if (!secret) {
98 DEBUG(0, ("get_credentials: Unable to fetch "
99 "auth credentials for %s in %s\n",
100 tmp, (dom==NULL)?"ALLOC":dom->name));
101 ret = NT_STATUS_ACCESS_DENIED;
102 goto done;
104 *dn = talloc_strdup(mem_ctx, tmp);
105 CHECK_ALLOC_DONE(*dn);
106 } else {
107 if (!fetch_ldap_pw(&user_dn, &secret)) {
108 DEBUG(2, ("get_credentials: Failed to lookup ldap "
109 "bind creds. Using anonymous connection.\n"));
110 anon = True;
111 } else {
112 *dn = talloc_strdup(mem_ctx, user_dn);
113 SAFE_FREE( user_dn );
114 CHECK_ALLOC_DONE(*dn);
118 smbldap_set_creds(ldap_state, anon, *dn, secret);
119 ret = NT_STATUS_OK;
121 done:
122 SAFE_FREE(secret);
124 return ret;
128 /**********************************************************************
129 Verify the sambaUnixIdPool entry in the directory.
130 **********************************************************************/
132 static NTSTATUS verify_idpool(void)
134 NTSTATUS ret;
135 TALLOC_CTX *ctx;
136 LDAPMessage *result = NULL;
137 LDAPMod **mods = NULL;
138 const char **attr_list;
139 char *filter;
140 int count;
141 int rc;
143 if ( ! idmap_alloc_ldap) {
144 return NT_STATUS_UNSUCCESSFUL;
147 ctx = talloc_new(idmap_alloc_ldap);
148 if ( ! ctx) {
149 DEBUG(0, ("Out of memory!\n"));
150 return NT_STATUS_NO_MEMORY;
153 filter = talloc_asprintf(ctx, "(objectclass=%s)", LDAP_OBJ_IDPOOL);
154 CHECK_ALLOC_DONE(filter);
156 attr_list = get_attr_list(ctx, idpool_attr_list);
157 CHECK_ALLOC_DONE(attr_list);
159 rc = smbldap_search(idmap_alloc_ldap->smbldap_state,
160 idmap_alloc_ldap->suffix,
161 LDAP_SCOPE_SUBTREE,
162 filter,
163 attr_list,
165 &result);
167 if (rc != LDAP_SUCCESS) {
168 DEBUG(1, ("Unable to verify the idpool, "
169 "cannot continue initialization!\n"));
170 return NT_STATUS_UNSUCCESSFUL;
173 count = ldap_count_entries(idmap_alloc_ldap->smbldap_state->ldap_struct,
174 result);
176 ldap_msgfree(result);
178 if ( count > 1 ) {
179 DEBUG(0,("Multiple entries returned from %s (base == %s)\n",
180 filter, idmap_alloc_ldap->suffix));
181 ret = NT_STATUS_UNSUCCESSFUL;
182 goto done;
184 else if (count == 0) {
185 char *uid_str, *gid_str;
187 uid_str = talloc_asprintf(ctx, "%lu",
188 (unsigned long)idmap_alloc_ldap->low_uid);
189 gid_str = talloc_asprintf(ctx, "%lu",
190 (unsigned long)idmap_alloc_ldap->low_gid);
192 smbldap_set_mod(&mods, LDAP_MOD_ADD,
193 "objectClass", LDAP_OBJ_IDPOOL);
194 smbldap_set_mod(&mods, LDAP_MOD_ADD,
195 get_attr_key2string(idpool_attr_list,
196 LDAP_ATTR_UIDNUMBER),
197 uid_str);
198 smbldap_set_mod(&mods, LDAP_MOD_ADD,
199 get_attr_key2string(idpool_attr_list,
200 LDAP_ATTR_GIDNUMBER),
201 gid_str);
202 if (mods) {
203 rc = smbldap_modify(idmap_alloc_ldap->smbldap_state,
204 idmap_alloc_ldap->suffix,
205 mods);
206 ldap_mods_free(mods, True);
207 } else {
208 ret = NT_STATUS_UNSUCCESSFUL;
209 goto done;
213 ret = (rc == LDAP_SUCCESS)?NT_STATUS_OK:NT_STATUS_UNSUCCESSFUL;
214 done:
215 talloc_free(ctx);
216 return ret;
219 /*****************************************************************************
220 Initialise idmap database.
221 *****************************************************************************/
223 static NTSTATUS idmap_ldap_alloc_init(const char *params)
225 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
226 const char *range;
227 const char *tmp;
228 uid_t low_uid = 0;
229 uid_t high_uid = 0;
230 gid_t low_gid = 0;
231 gid_t high_gid = 0;
233 /* Only do init if we are online */
234 if (idmap_is_offline()) {
235 return NT_STATUS_FILE_IS_OFFLINE;
238 idmap_alloc_ldap = TALLOC_ZERO_P(NULL, struct idmap_ldap_alloc_context);
239 CHECK_ALLOC_DONE( idmap_alloc_ldap );
241 /* load ranges */
243 idmap_alloc_ldap->low_uid = 0;
244 idmap_alloc_ldap->high_uid = 0;
245 idmap_alloc_ldap->low_gid = 0;
246 idmap_alloc_ldap->high_gid = 0;
248 range = lp_parm_const_string(-1, "idmap alloc config", "range", NULL);
249 if (range && range[0]) {
250 unsigned low_id, high_id;
252 if (sscanf(range, "%u - %u", &low_id, &high_id) == 2) {
253 if (low_id < high_id) {
254 idmap_alloc_ldap->low_gid = low_id;
255 idmap_alloc_ldap->low_uid = low_id;
256 idmap_alloc_ldap->high_gid = high_id;
257 idmap_alloc_ldap->high_uid = high_id;
258 } else {
259 DEBUG(1, ("ERROR: invalid idmap alloc range "
260 "[%s]", range));
262 } else {
263 DEBUG(1, ("ERROR: invalid syntax for idmap alloc "
264 "config:range [%s]", range));
268 if (lp_idmap_uid(&low_uid, &high_uid)) {
269 idmap_alloc_ldap->low_uid = low_uid;
270 idmap_alloc_ldap->high_uid = high_uid;
273 if (lp_idmap_gid(&low_gid, &high_gid)) {
274 idmap_alloc_ldap->low_gid = low_gid;
275 idmap_alloc_ldap->high_gid= high_gid;
278 if (idmap_alloc_ldap->high_uid <= idmap_alloc_ldap->low_uid) {
279 DEBUG(1, ("idmap uid range missing or invalid\n"));
280 DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
281 ret = NT_STATUS_UNSUCCESSFUL;
282 goto done;
285 if (idmap_alloc_ldap->high_gid <= idmap_alloc_ldap->low_gid) {
286 DEBUG(1, ("idmap gid range missing or invalid\n"));
287 DEBUGADD(1, ("idmap will be unable to map foreign SIDs\n"));
288 ret = NT_STATUS_UNSUCCESSFUL;
289 goto done;
292 if (params && *params) {
293 /* assume location is the only parameter */
294 idmap_alloc_ldap->url = talloc_strdup(idmap_alloc_ldap, params);
295 } else {
296 tmp = lp_parm_const_string(-1, "idmap alloc config",
297 "ldap_url", NULL);
299 if ( ! tmp) {
300 DEBUG(1, ("ERROR: missing idmap ldap url\n"));
301 ret = NT_STATUS_UNSUCCESSFUL;
302 goto done;
305 idmap_alloc_ldap->url = talloc_strdup(idmap_alloc_ldap, tmp);
307 CHECK_ALLOC_DONE( idmap_alloc_ldap->url );
309 tmp = lp_parm_const_string(-1, "idmap alloc config",
310 "ldap_base_dn", NULL);
311 if ( ! tmp || ! *tmp) {
312 tmp = lp_ldap_idmap_suffix();
313 if ( ! tmp) {
314 DEBUG(1, ("ERROR: missing idmap ldap suffix\n"));
315 ret = NT_STATUS_UNSUCCESSFUL;
316 goto done;
320 idmap_alloc_ldap->suffix = talloc_strdup(idmap_alloc_ldap, tmp);
321 CHECK_ALLOC_DONE( idmap_alloc_ldap->suffix );
323 ret = smbldap_init(idmap_alloc_ldap, winbind_event_context(),
324 idmap_alloc_ldap->url,
325 &idmap_alloc_ldap->smbldap_state);
326 if (!NT_STATUS_IS_OK(ret)) {
327 DEBUG(1, ("ERROR: smbldap_init (%s) failed!\n",
328 idmap_alloc_ldap->url));
329 goto done;
332 ret = get_credentials( idmap_alloc_ldap,
333 idmap_alloc_ldap->smbldap_state,
334 "idmap alloc config", NULL,
335 &idmap_alloc_ldap->user_dn );
336 if ( !NT_STATUS_IS_OK(ret) ) {
337 DEBUG(1,("idmap_ldap_alloc_init: Failed to get connection "
338 "credentials (%s)\n", nt_errstr(ret)));
339 goto done;
342 /* see if the idmap suffix and sub entries exists */
344 ret = verify_idpool();
346 done:
347 if ( !NT_STATUS_IS_OK( ret ) )
348 TALLOC_FREE( idmap_alloc_ldap );
350 return ret;
353 /********************************
354 Allocate a new uid or gid
355 ********************************/
357 static NTSTATUS idmap_ldap_allocate_id(struct unixid *xid)
359 TALLOC_CTX *ctx;
360 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
361 int rc = LDAP_SERVER_DOWN;
362 int count = 0;
363 LDAPMessage *result = NULL;
364 LDAPMessage *entry = NULL;
365 LDAPMod **mods = NULL;
366 char *id_str;
367 char *new_id_str;
368 char *filter = NULL;
369 const char *dn = NULL;
370 const char **attr_list;
371 const char *type;
373 /* Only do query if we are online */
374 if (idmap_is_offline()) {
375 return NT_STATUS_FILE_IS_OFFLINE;
378 if ( ! idmap_alloc_ldap) {
379 return NT_STATUS_UNSUCCESSFUL;
382 ctx = talloc_new(idmap_alloc_ldap);
383 if ( ! ctx) {
384 DEBUG(0, ("Out of memory!\n"));
385 return NT_STATUS_NO_MEMORY;
388 /* get type */
389 switch (xid->type) {
391 case ID_TYPE_UID:
392 type = get_attr_key2string(idpool_attr_list,
393 LDAP_ATTR_UIDNUMBER);
394 break;
396 case ID_TYPE_GID:
397 type = get_attr_key2string(idpool_attr_list,
398 LDAP_ATTR_GIDNUMBER);
399 break;
401 default:
402 DEBUG(2, ("Invalid ID type (0x%x)\n", xid->type));
403 return NT_STATUS_INVALID_PARAMETER;
406 filter = talloc_asprintf(ctx, "(objectClass=%s)", LDAP_OBJ_IDPOOL);
407 CHECK_ALLOC_DONE(filter);
409 attr_list = get_attr_list(ctx, idpool_attr_list);
410 CHECK_ALLOC_DONE(attr_list);
412 DEBUG(10, ("Search of the id pool (filter: %s)\n", filter));
414 rc = smbldap_search(idmap_alloc_ldap->smbldap_state,
415 idmap_alloc_ldap->suffix,
416 LDAP_SCOPE_SUBTREE, filter,
417 attr_list, 0, &result);
419 if (rc != LDAP_SUCCESS) {
420 DEBUG(0,("%s object not found\n", LDAP_OBJ_IDPOOL));
421 goto done;
424 talloc_autofree_ldapmsg(ctx, result);
426 count = ldap_count_entries(idmap_alloc_ldap->smbldap_state->ldap_struct,
427 result);
428 if (count != 1) {
429 DEBUG(0,("Single %s object not found\n", LDAP_OBJ_IDPOOL));
430 goto done;
433 entry = ldap_first_entry(idmap_alloc_ldap->smbldap_state->ldap_struct,
434 result);
436 dn = smbldap_talloc_dn(ctx,
437 idmap_alloc_ldap->smbldap_state->ldap_struct,
438 entry);
439 if ( ! dn) {
440 goto done;
443 if ( ! (id_str = smbldap_talloc_single_attribute(idmap_alloc_ldap->smbldap_state->ldap_struct,
444 entry, type, ctx))) {
445 DEBUG(0,("%s attribute not found\n", type));
446 goto done;
448 if ( ! id_str) {
449 DEBUG(0,("Out of memory\n"));
450 ret = NT_STATUS_NO_MEMORY;
451 goto done;
454 xid->id = strtoul(id_str, NULL, 10);
456 /* make sure we still have room to grow */
458 switch (xid->type) {
459 case ID_TYPE_UID:
460 if (xid->id > idmap_alloc_ldap->high_uid) {
461 DEBUG(0,("Cannot allocate uid above %lu!\n",
462 (unsigned long)idmap_alloc_ldap->high_uid));
463 goto done;
465 break;
467 case ID_TYPE_GID:
468 if (xid->id > idmap_alloc_ldap->high_gid) {
469 DEBUG(0,("Cannot allocate gid above %lu!\n",
470 (unsigned long)idmap_alloc_ldap->high_uid));
471 goto done;
473 break;
475 default:
476 /* impossible */
477 goto done;
480 new_id_str = talloc_asprintf(ctx, "%lu", (unsigned long)xid->id + 1);
481 if ( ! new_id_str) {
482 DEBUG(0,("Out of memory\n"));
483 ret = NT_STATUS_NO_MEMORY;
484 goto done;
487 smbldap_set_mod(&mods, LDAP_MOD_DELETE, type, id_str);
488 smbldap_set_mod(&mods, LDAP_MOD_ADD, type, new_id_str);
490 if (mods == NULL) {
491 DEBUG(0,("smbldap_set_mod() failed.\n"));
492 goto done;
495 DEBUG(10, ("Try to atomically increment the id (%s -> %s)\n",
496 id_str, new_id_str));
498 rc = smbldap_modify(idmap_alloc_ldap->smbldap_state, dn, mods);
500 ldap_mods_free(mods, True);
502 if (rc != LDAP_SUCCESS) {
503 DEBUG(1,("Failed to allocate new %s. "
504 "smbldap_modify() failed.\n", type));
505 goto done;
508 ret = NT_STATUS_OK;
510 done:
511 talloc_free(ctx);
512 return ret;
515 /**********************************
516 Get current highest id.
517 **********************************/
519 static NTSTATUS idmap_ldap_get_hwm(struct unixid *xid)
521 TALLOC_CTX *memctx;
522 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
523 int rc = LDAP_SERVER_DOWN;
524 int count = 0;
525 LDAPMessage *result = NULL;
526 LDAPMessage *entry = NULL;
527 char *id_str;
528 char *filter = NULL;
529 const char **attr_list;
530 const char *type;
532 /* Only do query if we are online */
533 if (idmap_is_offline()) {
534 return NT_STATUS_FILE_IS_OFFLINE;
537 if ( ! idmap_alloc_ldap) {
538 return NT_STATUS_UNSUCCESSFUL;
541 memctx = talloc_new(idmap_alloc_ldap);
542 if ( ! memctx) {
543 DEBUG(0, ("Out of memory!\n"));
544 return NT_STATUS_NO_MEMORY;
547 /* get type */
548 switch (xid->type) {
550 case ID_TYPE_UID:
551 type = get_attr_key2string(idpool_attr_list,
552 LDAP_ATTR_UIDNUMBER);
553 break;
555 case ID_TYPE_GID:
556 type = get_attr_key2string(idpool_attr_list,
557 LDAP_ATTR_GIDNUMBER);
558 break;
560 default:
561 DEBUG(2, ("Invalid ID type (0x%x)\n", xid->type));
562 return NT_STATUS_INVALID_PARAMETER;
565 filter = talloc_asprintf(memctx, "(objectClass=%s)", LDAP_OBJ_IDPOOL);
566 CHECK_ALLOC_DONE(filter);
568 attr_list = get_attr_list(memctx, idpool_attr_list);
569 CHECK_ALLOC_DONE(attr_list);
571 rc = smbldap_search(idmap_alloc_ldap->smbldap_state,
572 idmap_alloc_ldap->suffix,
573 LDAP_SCOPE_SUBTREE, filter,
574 attr_list, 0, &result);
576 if (rc != LDAP_SUCCESS) {
577 DEBUG(0,("%s object not found\n", LDAP_OBJ_IDPOOL));
578 goto done;
581 talloc_autofree_ldapmsg(memctx, result);
583 count = ldap_count_entries(idmap_alloc_ldap->smbldap_state->ldap_struct,
584 result);
585 if (count != 1) {
586 DEBUG(0,("Single %s object not found\n", LDAP_OBJ_IDPOOL));
587 goto done;
590 entry = ldap_first_entry(idmap_alloc_ldap->smbldap_state->ldap_struct,
591 result);
593 id_str = smbldap_talloc_single_attribute(idmap_alloc_ldap->smbldap_state->ldap_struct,
594 entry, type, memctx);
595 if ( ! id_str) {
596 DEBUG(0,("%s attribute not found\n", type));
597 goto done;
599 if ( ! id_str) {
600 DEBUG(0,("Out of memory\n"));
601 ret = NT_STATUS_NO_MEMORY;
602 goto done;
605 xid->id = strtoul(id_str, NULL, 10);
607 ret = NT_STATUS_OK;
608 done:
609 talloc_free(memctx);
610 return ret;
612 /**********************************
613 Set highest id.
614 **********************************/
616 static NTSTATUS idmap_ldap_set_hwm(struct unixid *xid)
618 TALLOC_CTX *ctx;
619 NTSTATUS ret = NT_STATUS_UNSUCCESSFUL;
620 int rc = LDAP_SERVER_DOWN;
621 int count = 0;
622 LDAPMessage *result = NULL;
623 LDAPMessage *entry = NULL;
624 LDAPMod **mods = NULL;
625 char *new_id_str;
626 char *filter = NULL;
627 const char *dn = NULL;
628 const char **attr_list;
629 const char *type;
631 /* Only do query if we are online */
632 if (idmap_is_offline()) {
633 return NT_STATUS_FILE_IS_OFFLINE;
636 if ( ! idmap_alloc_ldap) {
637 return NT_STATUS_UNSUCCESSFUL;
640 ctx = talloc_new(idmap_alloc_ldap);
641 if ( ! ctx) {
642 DEBUG(0, ("Out of memory!\n"));
643 return NT_STATUS_NO_MEMORY;
646 /* get type */
647 switch (xid->type) {
649 case ID_TYPE_UID:
650 type = get_attr_key2string(idpool_attr_list,
651 LDAP_ATTR_UIDNUMBER);
652 break;
654 case ID_TYPE_GID:
655 type = get_attr_key2string(idpool_attr_list,
656 LDAP_ATTR_GIDNUMBER);
657 break;
659 default:
660 DEBUG(2, ("Invalid ID type (0x%x)\n", xid->type));
661 return NT_STATUS_INVALID_PARAMETER;
664 filter = talloc_asprintf(ctx, "(objectClass=%s)", LDAP_OBJ_IDPOOL);
665 CHECK_ALLOC_DONE(filter);
667 attr_list = get_attr_list(ctx, idpool_attr_list);
668 CHECK_ALLOC_DONE(attr_list);
670 rc = smbldap_search(idmap_alloc_ldap->smbldap_state,
671 idmap_alloc_ldap->suffix,
672 LDAP_SCOPE_SUBTREE, filter,
673 attr_list, 0, &result);
675 if (rc != LDAP_SUCCESS) {
676 DEBUG(0,("%s object not found\n", LDAP_OBJ_IDPOOL));
677 goto done;
680 talloc_autofree_ldapmsg(ctx, result);
682 count = ldap_count_entries(idmap_alloc_ldap->smbldap_state->ldap_struct,
683 result);
684 if (count != 1) {
685 DEBUG(0,("Single %s object not found\n", LDAP_OBJ_IDPOOL));
686 goto done;
689 entry = ldap_first_entry(idmap_alloc_ldap->smbldap_state->ldap_struct,
690 result);
692 dn = smbldap_talloc_dn(ctx,
693 idmap_alloc_ldap->smbldap_state->ldap_struct,
694 entry);
695 if ( ! dn) {
696 goto done;
699 new_id_str = talloc_asprintf(ctx, "%lu", (unsigned long)xid->id);
700 if ( ! new_id_str) {
701 DEBUG(0,("Out of memory\n"));
702 ret = NT_STATUS_NO_MEMORY;
703 goto done;
706 smbldap_set_mod(&mods, LDAP_MOD_REPLACE, type, new_id_str);
708 if (mods == NULL) {
709 DEBUG(0,("smbldap_set_mod() failed.\n"));
710 goto done;
713 rc = smbldap_modify(idmap_alloc_ldap->smbldap_state, dn, mods);
715 ldap_mods_free(mods, True);
717 if (rc != LDAP_SUCCESS) {
718 DEBUG(1,("Failed to allocate new %s. "
719 "smbldap_modify() failed.\n", type));
720 goto done;
723 ret = NT_STATUS_OK;
725 done:
726 talloc_free(ctx);
727 return ret;
730 /**********************************
731 Close idmap ldap alloc
732 **********************************/
734 static NTSTATUS idmap_ldap_alloc_close(void)
736 if (idmap_alloc_ldap) {
737 smbldap_free_struct(&idmap_alloc_ldap->smbldap_state);
738 DEBUG(5,("The connection to the LDAP server was closed\n"));
739 /* maybe free the results here --metze */
740 TALLOC_FREE(idmap_alloc_ldap);
742 return NT_STATUS_OK;
746 /**********************************************************************
747 IDMAP MAPPING LDAP BACKEND
748 **********************************************************************/
750 static int idmap_ldap_close_destructor(struct idmap_ldap_context *ctx)
752 smbldap_free_struct(&ctx->smbldap_state);
753 DEBUG(5,("The connection to the LDAP server was closed\n"));
754 /* maybe free the results here --metze */
756 return 0;
759 /********************************
760 Initialise idmap database.
761 ********************************/
763 static NTSTATUS idmap_ldap_db_init(struct idmap_domain *dom)
765 NTSTATUS ret;
766 struct idmap_ldap_context *ctx = NULL;
767 char *config_option = NULL;
768 const char *range = NULL;
769 const char *tmp = NULL;
771 /* Only do init if we are online */
772 if (idmap_is_offline()) {
773 return NT_STATUS_FILE_IS_OFFLINE;
776 ctx = TALLOC_ZERO_P(dom, struct idmap_ldap_context);
777 if ( ! ctx) {
778 DEBUG(0, ("Out of memory!\n"));
779 return NT_STATUS_NO_MEMORY;
782 config_option = talloc_asprintf(ctx, "idmap config %s", dom->name);
783 if ( ! config_option) {
784 DEBUG(0, ("Out of memory!\n"));
785 ret = NT_STATUS_NO_MEMORY;
786 goto done;
789 /* load ranges */
790 range = lp_parm_const_string(-1, config_option, "range", NULL);
791 if (range && range[0]) {
792 if ((sscanf(range, "%u - %u", &ctx->filter_low_id,
793 &ctx->filter_high_id) != 2) ||
794 (ctx->filter_low_id > ctx->filter_high_id)) {
795 DEBUG(1, ("ERROR: invalid filter range [%s]", range));
796 ctx->filter_low_id = 0;
797 ctx->filter_high_id = 0;
801 if (dom->params && *(dom->params)) {
802 /* assume location is the only parameter */
803 ctx->url = talloc_strdup(ctx, dom->params);
804 } else {
805 tmp = lp_parm_const_string(-1, config_option, "ldap_url", NULL);
807 if ( ! tmp) {
808 DEBUG(1, ("ERROR: missing idmap ldap url\n"));
809 ret = NT_STATUS_UNSUCCESSFUL;
810 goto done;
813 ctx->url = talloc_strdup(ctx, tmp);
815 CHECK_ALLOC_DONE(ctx->url);
817 tmp = lp_parm_const_string(-1, config_option, "ldap_base_dn", NULL);
818 if ( ! tmp || ! *tmp) {
819 tmp = lp_ldap_idmap_suffix();
820 if ( ! tmp) {
821 DEBUG(1, ("ERROR: missing idmap ldap suffix\n"));
822 ret = NT_STATUS_UNSUCCESSFUL;
823 goto done;
827 ctx->suffix = talloc_strdup(ctx, tmp);
828 CHECK_ALLOC_DONE(ctx->suffix);
830 ret = smbldap_init(ctx, winbind_event_context(), ctx->url,
831 &ctx->smbldap_state);
832 if (!NT_STATUS_IS_OK(ret)) {
833 DEBUG(1, ("ERROR: smbldap_init (%s) failed!\n", ctx->url));
834 goto done;
837 ret = get_credentials( ctx, ctx->smbldap_state, config_option,
838 dom, &ctx->user_dn );
839 if ( !NT_STATUS_IS_OK(ret) ) {
840 DEBUG(1,("idmap_ldap_db_init: Failed to get connection "
841 "credentials (%s)\n", nt_errstr(ret)));
842 goto done;
845 /* set the destructor on the context, so that resource are properly
846 freed if the contexts is released */
848 talloc_set_destructor(ctx, idmap_ldap_close_destructor);
850 dom->private_data = ctx;
851 dom->initialized = True;
853 talloc_free(config_option);
854 return NT_STATUS_OK;
856 /*failed */
857 done:
858 talloc_free(ctx);
859 return ret;
862 /* max number of ids requested per batch query */
863 #define IDMAP_LDAP_MAX_IDS 30
865 /**********************************
866 lookup a set of unix ids.
867 **********************************/
869 /* this function searches up to IDMAP_LDAP_MAX_IDS entries
870 * in maps for a match */
871 static struct id_map *find_map_by_id(struct id_map **maps,
872 enum id_type type,
873 uint32_t id)
875 int i;
877 for (i = 0; i < IDMAP_LDAP_MAX_IDS; i++) {
878 if (maps[i] == NULL) { /* end of the run */
879 return NULL;
881 if ((maps[i]->xid.type == type) && (maps[i]->xid.id == id)) {
882 return maps[i];
886 return NULL;
889 static NTSTATUS idmap_ldap_unixids_to_sids(struct idmap_domain *dom,
890 struct id_map **ids)
892 NTSTATUS ret;
893 TALLOC_CTX *memctx;
894 struct idmap_ldap_context *ctx;
895 LDAPMessage *result = NULL;
896 const char *uidNumber;
897 const char *gidNumber;
898 const char **attr_list;
899 char *filter = NULL;
900 bool multi = False;
901 int idx = 0;
902 int bidx = 0;
903 int count;
904 int rc;
905 int i;
907 /* Only do query if we are online */
908 if (idmap_is_offline()) {
909 return NT_STATUS_FILE_IS_OFFLINE;
912 /* Initilization my have been deferred because we were offline */
913 if ( ! dom->initialized) {
914 ret = idmap_ldap_db_init(dom);
915 if ( ! NT_STATUS_IS_OK(ret)) {
916 return ret;
920 ctx = talloc_get_type(dom->private_data, struct idmap_ldap_context);
922 memctx = talloc_new(ctx);
923 if ( ! memctx) {
924 DEBUG(0, ("Out of memory!\n"));
925 return NT_STATUS_NO_MEMORY;
928 uidNumber = get_attr_key2string(idpool_attr_list, LDAP_ATTR_UIDNUMBER);
929 gidNumber = get_attr_key2string(idpool_attr_list, LDAP_ATTR_GIDNUMBER);
931 attr_list = get_attr_list(memctx, sidmap_attr_list);
933 if ( ! ids[1]) {
934 /* if we are requested just one mapping use the simple filter */
936 filter = talloc_asprintf(memctx, "(&(objectClass=%s)(%s=%lu))",
937 LDAP_OBJ_IDMAP_ENTRY,
938 (ids[0]->xid.type==ID_TYPE_UID)?uidNumber:gidNumber,
939 (unsigned long)ids[0]->xid.id);
940 CHECK_ALLOC_DONE(filter);
941 DEBUG(10, ("Filter: [%s]\n", filter));
942 } else {
943 /* multiple mappings */
944 multi = True;
947 again:
948 if (multi) {
950 talloc_free(filter);
951 filter = talloc_asprintf(memctx,
952 "(&(objectClass=%s)(|",
953 LDAP_OBJ_IDMAP_ENTRY);
954 CHECK_ALLOC_DONE(filter);
956 bidx = idx;
957 for (i = 0; (i < IDMAP_LDAP_MAX_IDS) && ids[idx]; i++, idx++) {
958 filter = talloc_asprintf_append_buffer(filter, "(%s=%lu)",
959 (ids[idx]->xid.type==ID_TYPE_UID)?uidNumber:gidNumber,
960 (unsigned long)ids[idx]->xid.id);
961 CHECK_ALLOC_DONE(filter);
963 filter = talloc_asprintf_append_buffer(filter, "))");
964 CHECK_ALLOC_DONE(filter);
965 DEBUG(10, ("Filter: [%s]\n", filter));
966 } else {
967 bidx = 0;
968 idx = 1;
971 rc = smbldap_search(ctx->smbldap_state, ctx->suffix, LDAP_SCOPE_SUBTREE,
972 filter, attr_list, 0, &result);
974 if (rc != LDAP_SUCCESS) {
975 DEBUG(3,("Failure looking up ids (%s)\n", ldap_err2string(rc)));
976 ret = NT_STATUS_UNSUCCESSFUL;
977 goto done;
980 count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
982 if (count == 0) {
983 DEBUG(10, ("NO SIDs found\n"));
986 for (i = 0; i < count; i++) {
987 LDAPMessage *entry = NULL;
988 char *sidstr = NULL;
989 char *tmp = NULL;
990 enum id_type type;
991 struct id_map *map;
992 uint32_t id;
994 if (i == 0) { /* first entry */
995 entry = ldap_first_entry(ctx->smbldap_state->ldap_struct,
996 result);
997 } else { /* following ones */
998 entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
999 entry);
1001 if ( ! entry) {
1002 DEBUG(2, ("ERROR: Unable to fetch ldap entries "
1003 "from results\n"));
1004 break;
1007 /* first check if the SID is present */
1008 sidstr = smbldap_talloc_single_attribute(
1009 ctx->smbldap_state->ldap_struct,
1010 entry, LDAP_ATTRIBUTE_SID, memctx);
1011 if ( ! sidstr) { /* no sid, skip entry */
1012 DEBUG(2, ("WARNING SID not found on entry\n"));
1013 continue;
1016 /* now try to see if it is a uid, if not try with a gid
1017 * (gid is more common, but in case both uidNumber and
1018 * gidNumber are returned the SID is mapped to the uid
1019 *not the gid) */
1020 type = ID_TYPE_UID;
1021 tmp = smbldap_talloc_single_attribute(
1022 ctx->smbldap_state->ldap_struct,
1023 entry, uidNumber, memctx);
1024 if ( ! tmp) {
1025 type = ID_TYPE_GID;
1026 tmp = smbldap_talloc_single_attribute(
1027 ctx->smbldap_state->ldap_struct,
1028 entry, gidNumber, memctx);
1030 if ( ! tmp) { /* wow very strange entry, how did it match ? */
1031 DEBUG(5, ("Unprobable match on (%s), no uidNumber, "
1032 "nor gidNumber returned\n", sidstr));
1033 TALLOC_FREE(sidstr);
1034 continue;
1037 id = strtoul(tmp, NULL, 10);
1038 if ((id == 0) ||
1039 (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
1040 (ctx->filter_high_id && (id > ctx->filter_high_id))) {
1041 DEBUG(5, ("Requested id (%u) out of range (%u - %u). "
1042 "Filtered!\n", id,
1043 ctx->filter_low_id, ctx->filter_high_id));
1044 TALLOC_FREE(sidstr);
1045 TALLOC_FREE(tmp);
1046 continue;
1048 TALLOC_FREE(tmp);
1050 map = find_map_by_id(&ids[bidx], type, id);
1051 if (!map) {
1052 DEBUG(2, ("WARNING: couldn't match sid (%s) "
1053 "with requested ids\n", sidstr));
1054 TALLOC_FREE(sidstr);
1055 continue;
1058 if ( ! string_to_sid(map->sid, sidstr)) {
1059 DEBUG(2, ("ERROR: Invalid SID on entry\n"));
1060 TALLOC_FREE(sidstr);
1061 continue;
1063 TALLOC_FREE(sidstr);
1065 /* mapped */
1066 map->status = ID_MAPPED;
1068 DEBUG(10, ("Mapped %s -> %lu (%d)\n", sid_string_dbg(map->sid),
1069 (unsigned long)map->xid.id, map->xid.type));
1072 /* free the ldap results */
1073 if (result) {
1074 ldap_msgfree(result);
1075 result = NULL;
1078 if (multi && ids[idx]) { /* still some values to map */
1079 goto again;
1082 ret = NT_STATUS_OK;
1084 /* mark all unknwon/expired ones as unmapped */
1085 for (i = 0; ids[i]; i++) {
1086 if (ids[i]->status != ID_MAPPED)
1087 ids[i]->status = ID_UNMAPPED;
1090 done:
1091 talloc_free(memctx);
1092 return ret;
1095 /**********************************
1096 lookup a set of sids.
1097 **********************************/
1099 /* this function searches up to IDMAP_LDAP_MAX_IDS entries
1100 * in maps for a match */
1101 static struct id_map *find_map_by_sid(struct id_map **maps, DOM_SID *sid)
1103 int i;
1105 for (i = 0; i < IDMAP_LDAP_MAX_IDS; i++) {
1106 if (maps[i] == NULL) { /* end of the run */
1107 return NULL;
1109 if (sid_equal(maps[i]->sid, sid)) {
1110 return maps[i];
1114 return NULL;
1117 static NTSTATUS idmap_ldap_sids_to_unixids(struct idmap_domain *dom,
1118 struct id_map **ids)
1120 LDAPMessage *entry = NULL;
1121 NTSTATUS ret;
1122 TALLOC_CTX *memctx;
1123 struct idmap_ldap_context *ctx;
1124 LDAPMessage *result = NULL;
1125 const char *uidNumber;
1126 const char *gidNumber;
1127 const char **attr_list;
1128 char *filter = NULL;
1129 bool multi = False;
1130 int idx = 0;
1131 int bidx = 0;
1132 int count;
1133 int rc;
1134 int i;
1136 /* Only do query if we are online */
1137 if (idmap_is_offline()) {
1138 return NT_STATUS_FILE_IS_OFFLINE;
1141 /* Initilization my have been deferred because we were offline */
1142 if ( ! dom->initialized) {
1143 ret = idmap_ldap_db_init(dom);
1144 if ( ! NT_STATUS_IS_OK(ret)) {
1145 return ret;
1149 ctx = talloc_get_type(dom->private_data, struct idmap_ldap_context);
1151 memctx = talloc_new(ctx);
1152 if ( ! memctx) {
1153 DEBUG(0, ("Out of memory!\n"));
1154 return NT_STATUS_NO_MEMORY;
1157 uidNumber = get_attr_key2string(idpool_attr_list, LDAP_ATTR_UIDNUMBER);
1158 gidNumber = get_attr_key2string(idpool_attr_list, LDAP_ATTR_GIDNUMBER);
1160 attr_list = get_attr_list(memctx, sidmap_attr_list);
1162 if ( ! ids[1]) {
1163 /* if we are requested just one mapping use the simple filter */
1165 filter = talloc_asprintf(memctx, "(&(objectClass=%s)(%s=%s))",
1166 LDAP_OBJ_IDMAP_ENTRY,
1167 LDAP_ATTRIBUTE_SID,
1168 sid_string_talloc(memctx, ids[0]->sid));
1169 CHECK_ALLOC_DONE(filter);
1170 DEBUG(10, ("Filter: [%s]\n", filter));
1171 } else {
1172 /* multiple mappings */
1173 multi = True;
1176 again:
1177 if (multi) {
1179 TALLOC_FREE(filter);
1180 filter = talloc_asprintf(memctx,
1181 "(&(objectClass=%s)(|",
1182 LDAP_OBJ_IDMAP_ENTRY);
1183 CHECK_ALLOC_DONE(filter);
1185 bidx = idx;
1186 for (i = 0; (i < IDMAP_LDAP_MAX_IDS) && ids[idx]; i++, idx++) {
1187 filter = talloc_asprintf_append_buffer(filter, "(%s=%s)",
1188 LDAP_ATTRIBUTE_SID,
1189 sid_string_talloc(memctx,
1190 ids[idx]->sid));
1191 CHECK_ALLOC_DONE(filter);
1193 filter = talloc_asprintf_append_buffer(filter, "))");
1194 CHECK_ALLOC_DONE(filter);
1195 DEBUG(10, ("Filter: [%s]", filter));
1196 } else {
1197 bidx = 0;
1198 idx = 1;
1201 rc = smbldap_search(ctx->smbldap_state, ctx->suffix, LDAP_SCOPE_SUBTREE,
1202 filter, attr_list, 0, &result);
1204 if (rc != LDAP_SUCCESS) {
1205 DEBUG(3,("Failure looking up sids (%s)\n",
1206 ldap_err2string(rc)));
1207 ret = NT_STATUS_UNSUCCESSFUL;
1208 goto done;
1211 count = ldap_count_entries(ctx->smbldap_state->ldap_struct, result);
1213 if (count == 0) {
1214 DEBUG(10, ("NO SIDs found\n"));
1217 for (i = 0; i < count; i++) {
1218 char *sidstr = NULL;
1219 char *tmp = NULL;
1220 enum id_type type;
1221 struct id_map *map;
1222 DOM_SID sid;
1223 uint32_t id;
1225 if (i == 0) { /* first entry */
1226 entry = ldap_first_entry(ctx->smbldap_state->ldap_struct,
1227 result);
1228 } else { /* following ones */
1229 entry = ldap_next_entry(ctx->smbldap_state->ldap_struct,
1230 entry);
1232 if ( ! entry) {
1233 DEBUG(2, ("ERROR: Unable to fetch ldap entries "
1234 "from results\n"));
1235 break;
1238 /* first check if the SID is present */
1239 sidstr = smbldap_talloc_single_attribute(
1240 ctx->smbldap_state->ldap_struct,
1241 entry, LDAP_ATTRIBUTE_SID, memctx);
1242 if ( ! sidstr) { /* no sid ??, skip entry */
1243 DEBUG(2, ("WARNING SID not found on entry\n"));
1244 continue;
1247 if ( ! string_to_sid(&sid, sidstr)) {
1248 DEBUG(2, ("ERROR: Invalid SID on entry\n"));
1249 TALLOC_FREE(sidstr);
1250 continue;
1253 map = find_map_by_sid(&ids[bidx], &sid);
1254 if (!map) {
1255 DEBUG(2, ("WARNING: couldn't find entry sid (%s) "
1256 "in ids", sidstr));
1257 TALLOC_FREE(sidstr);
1258 continue;
1261 TALLOC_FREE(sidstr);
1263 /* now try to see if it is a uid, if not try with a gid
1264 * (gid is more common, but in case both uidNumber and
1265 * gidNumber are returned the SID is mapped to the uid
1266 * not the gid) */
1267 type = ID_TYPE_UID;
1268 tmp = smbldap_talloc_single_attribute(
1269 ctx->smbldap_state->ldap_struct,
1270 entry, uidNumber, memctx);
1271 if ( ! tmp) {
1272 type = ID_TYPE_GID;
1273 tmp = smbldap_talloc_single_attribute(
1274 ctx->smbldap_state->ldap_struct,
1275 entry, gidNumber, memctx);
1277 if ( ! tmp) { /* no ids ?? */
1278 DEBUG(5, ("no uidNumber, "
1279 "nor gidNumber attributes found\n"));
1280 continue;
1283 id = strtoul(tmp, NULL, 10);
1284 if ((id == 0) ||
1285 (ctx->filter_low_id && (id < ctx->filter_low_id)) ||
1286 (ctx->filter_high_id && (id > ctx->filter_high_id))) {
1287 DEBUG(5, ("Requested id (%u) out of range (%u - %u). "
1288 "Filtered!\n", id,
1289 ctx->filter_low_id, ctx->filter_high_id));
1290 TALLOC_FREE(tmp);
1291 continue;
1293 TALLOC_FREE(tmp);
1295 /* mapped */
1296 map->xid.type = type;
1297 map->xid.id = id;
1298 map->status = ID_MAPPED;
1300 DEBUG(10, ("Mapped %s -> %lu (%d)\n", sid_string_dbg(map->sid),
1301 (unsigned long)map->xid.id, map->xid.type));
1304 /* free the ldap results */
1305 if (result) {
1306 ldap_msgfree(result);
1307 result = NULL;
1310 if (multi && ids[idx]) { /* still some values to map */
1311 goto again;
1314 ret = NT_STATUS_OK;
1316 /* mark all unknwon/expired ones as unmapped */
1317 for (i = 0; ids[i]; i++) {
1318 if (ids[i]->status != ID_MAPPED)
1319 ids[i]->status = ID_UNMAPPED;
1322 done:
1323 talloc_free(memctx);
1324 return ret;
1327 /**********************************
1328 set a mapping.
1329 **********************************/
1331 /* TODO: change this: This function cannot be called to modify a mapping,
1332 * only set a new one */
1334 static NTSTATUS idmap_ldap_set_mapping(struct idmap_domain *dom,
1335 const struct id_map *map)
1337 NTSTATUS ret;
1338 TALLOC_CTX *memctx;
1339 struct idmap_ldap_context *ctx;
1340 LDAPMessage *entry = NULL;
1341 LDAPMod **mods = NULL;
1342 const char *type;
1343 char *id_str;
1344 char *sid;
1345 char *dn;
1346 int rc = -1;
1348 /* Only do query if we are online */
1349 if (idmap_is_offline()) {
1350 return NT_STATUS_FILE_IS_OFFLINE;
1353 /* Initilization my have been deferred because we were offline */
1354 if ( ! dom->initialized) {
1355 ret = idmap_ldap_db_init(dom);
1356 if ( ! NT_STATUS_IS_OK(ret)) {
1357 return ret;
1361 ctx = talloc_get_type(dom->private_data, struct idmap_ldap_context);
1363 switch(map->xid.type) {
1364 case ID_TYPE_UID:
1365 type = get_attr_key2string(sidmap_attr_list,
1366 LDAP_ATTR_UIDNUMBER);
1367 break;
1369 case ID_TYPE_GID:
1370 type = get_attr_key2string(sidmap_attr_list,
1371 LDAP_ATTR_GIDNUMBER);
1372 break;
1374 default:
1375 return NT_STATUS_INVALID_PARAMETER;
1378 memctx = talloc_new(ctx);
1379 if ( ! memctx) {
1380 DEBUG(0, ("Out of memory!\n"));
1381 return NT_STATUS_NO_MEMORY;
1384 id_str = talloc_asprintf(memctx, "%lu", (unsigned long)map->xid.id);
1385 CHECK_ALLOC_DONE(id_str);
1387 sid = talloc_strdup(memctx, sid_string_talloc(memctx, map->sid));
1388 CHECK_ALLOC_DONE(sid);
1390 dn = talloc_asprintf(memctx, "%s=%s,%s",
1391 get_attr_key2string(sidmap_attr_list, LDAP_ATTR_SID),
1392 sid,
1393 ctx->suffix);
1394 CHECK_ALLOC_DONE(dn);
1396 smbldap_set_mod(&mods, LDAP_MOD_ADD,
1397 "objectClass", LDAP_OBJ_IDMAP_ENTRY);
1399 smbldap_make_mod(ctx->smbldap_state->ldap_struct,
1400 entry, &mods, type, id_str);
1402 smbldap_make_mod(ctx->smbldap_state->ldap_struct, entry, &mods,
1403 get_attr_key2string(sidmap_attr_list, LDAP_ATTR_SID),
1404 sid);
1406 if ( ! mods) {
1407 DEBUG(2, ("ERROR: No mods?\n"));
1408 ret = NT_STATUS_UNSUCCESSFUL;
1409 goto done;
1412 /* TODO: remove conflicting mappings! */
1414 smbldap_set_mod(&mods, LDAP_MOD_ADD, "objectClass", LDAP_OBJ_SID_ENTRY);
1416 DEBUG(10, ("Set DN %s (%s -> %s)\n", dn, sid, id_str));
1418 rc = smbldap_add(ctx->smbldap_state, dn, mods);
1419 ldap_mods_free(mods, True);
1421 if (rc != LDAP_SUCCESS) {
1422 char *ld_error = NULL;
1423 ldap_get_option(ctx->smbldap_state->ldap_struct,
1424 LDAP_OPT_ERROR_STRING, &ld_error);
1425 DEBUG(0,("ldap_set_mapping_internals: Failed to add %s to %lu "
1426 "mapping [%s]\n", sid,
1427 (unsigned long)map->xid.id, type));
1428 DEBUG(0, ("ldap_set_mapping_internals: Error was: %s (%s)\n",
1429 ld_error ? ld_error : "(NULL)", ldap_err2string (rc)));
1430 if (ld_error) {
1431 ldap_memfree(ld_error);
1433 ret = NT_STATUS_UNSUCCESSFUL;
1434 goto done;
1437 DEBUG(10,("ldap_set_mapping: Successfully created mapping from %s to "
1438 "%lu [%s]\n", sid, (unsigned long)map->xid.id, type));
1440 ret = NT_STATUS_OK;
1442 done:
1443 talloc_free(memctx);
1444 return ret;
1447 /**********************************
1448 Close the idmap ldap instance
1449 **********************************/
1451 static NTSTATUS idmap_ldap_close(struct idmap_domain *dom)
1453 struct idmap_ldap_context *ctx;
1455 if (dom->private_data) {
1456 ctx = talloc_get_type(dom->private_data,
1457 struct idmap_ldap_context);
1459 talloc_free(ctx);
1460 dom->private_data = NULL;
1463 return NT_STATUS_OK;
1466 static struct idmap_methods idmap_ldap_methods = {
1468 .init = idmap_ldap_db_init,
1469 .unixids_to_sids = idmap_ldap_unixids_to_sids,
1470 .sids_to_unixids = idmap_ldap_sids_to_unixids,
1471 .set_mapping = idmap_ldap_set_mapping,
1472 .close_fn = idmap_ldap_close
1475 static struct idmap_alloc_methods idmap_ldap_alloc_methods = {
1477 .init = idmap_ldap_alloc_init,
1478 .allocate_id = idmap_ldap_allocate_id,
1479 .get_id_hwm = idmap_ldap_get_hwm,
1480 .set_id_hwm = idmap_ldap_set_hwm,
1481 .close_fn = idmap_ldap_alloc_close,
1482 /* .dump_data = TODO */
1485 NTSTATUS idmap_alloc_ldap_init(void)
1487 return smb_register_idmap_alloc(SMB_IDMAP_INTERFACE_VERSION, "ldap",
1488 &idmap_ldap_alloc_methods);
1491 NTSTATUS idmap_ldap_init(void)
1493 NTSTATUS ret;
1495 /* FIXME: bad hack to actually register also the alloc_ldap module
1496 * without changining configure.in */
1497 ret = idmap_alloc_ldap_init();
1498 if (! NT_STATUS_IS_OK(ret)) {
1499 return ret;
1501 return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "ldap",
1502 &idmap_ldap_methods);