ldapdb.c revision bf49a52178db60df60f2316a3977b2249f7c0edb
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Copyright (C) 2001 Stig Venaas
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
999ae80184e3df1016ac74514124b0459ace4d01Andreas Gustafsson * A simple database driver for LDAP. Not production quality yet.
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonldapdb_create(const char *zone, int argc, char **argv,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson || (argv[0] != strstr( argv[0], "ldap://"))
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson data = isc_mem_get(ns_g_mctx, sizeof(struct ldapdb_data));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson data->hostname = isc_mem_strdup(ns_g_mctx, argv[0] + strlen("ldap://"));
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson isc_mem_put(ns_g_mctx, data, sizeof(struct ldapdb_data));
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafssonldapdb_destroy(const char *zone, void *driverdata, void **dbdata) {
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson isc_mem_put(ns_g_mctx, data, sizeof(struct ldapdb_data));
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson data->ld = ldap_open(data->hostname, data->portno);
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson if (ldap_simple_bind_s(data->ld, NULL, NULL) != LDAP_SUCCESS) {
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafssonldapdb_lookup(const char *zone, const char *name, void *dbdata,
8803b0510877fd08044542edbb55e2be72fae36fAndreas Gustafsson fltr = isc_mem_get(ns_g_mctx, strlen(name) + strlen("(dc=)") + 1);
f4c0131a46ea183238027ef9c3400cc6079b8b85Andreas Gustafsson if (ldap_search_s(data->ld, data->base, LDAP_SCOPE_ONELEVEL, fltr, NULL, 0, &res) != LDAP_SUCCESS) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ldap_search_s(data->ld, data->base, LDAP_SCOPE_ONELEVEL, fltr, NULL, 0, &res);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson isc_mem_put(ns_g_mctx, fltr, strlen(fltr) + 1);
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson for (e = ldap_first_entry(data->ld, res); e != NULL;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson for (a = ldap_first_attribute(ld, e, &ptr); a != NULL;
581db30788a4920ba8558287a0dccf3c1a210c5aAndreas Gustafsson for (a = ldap_first_attribute(ld, e, &ptr); a != NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (s = a; *s; s++)
b2c71d98dfc4dab5c6b8c8f39cf8fed3d899e94cAndreas Gustafsson if ((s == NULL) || (s == a)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson || (s - a >= (signed int)sizeof(type))) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_sdb_putrr(lookup, type, ttl, vals[i]);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonldapdb_allnodes(const char *zone, void *dbdata, dns_sdballnodes_t *allnodes) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if (ldap_search_s(data->ld, data->base, LDAP_SCOPE_ONELEVEL, "(objectclass=*)", NULL, 0, &res) != LDAP_SUCCESS) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson ldap_search_s(data->ld, data->base, LDAP_SCOPE_ONELEVEL, "(objectclass=*)", NULL, 0, &res);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (e = ldap_first_entry(data->ld, res); e != NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (a = ldap_first_attribute(ld, e, &ptr); a != NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson name = isc_mem_strdup(ns_g_mctx, vals[0]);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (a = ldap_first_attribute(ld, e, &ptr); a != NULL;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson for (s = a; *s; s++)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson if ((s == NULL) || (s == a)
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson || (s - a >= (signed int)sizeof(type))) {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson result = dns_sdb_putnamedrr(allnodes, name, type, ttl, vals[i]);
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafssonstatic dns_sdbmethods_t ldapdb_methods = {
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Wrapper around dns_sdb_register().
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson flags = DNS_SDBFLAG_RELATIVEOWNER | DNS_SDBFLAG_RELATIVERDATA;
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson return (dns_sdb_register("ldap", &ldapdb_methods, NULL, flags,
4cd3d6df39927315e3fadc07a8da3788175f4195Andreas Gustafsson * Wrapper around dns_sdb_unregister().