ldap_init.c revision b2611932cf2e95d5b0f8c36cbdc02feee64b6df8
883N/A/*
883N/A SSSD
883N/A
883N/A LDAP Provider Initialization functions
883N/A
883N/A Authors:
883N/A Simo Sorce <ssorce@redhat.com>
883N/A
883N/A Copyright (C) 2009 Red Hat
883N/A
883N/A This program is free software; you can redistribute it and/or modify
883N/A it under the terms of the GNU General Public License as published by
883N/A the Free Software Foundation; either version 3 of the License, or
883N/A (at your option) any later version.
883N/A
883N/A This program is distributed in the hope that it will be useful,
883N/A but WITHOUT ANY WARRANTY; without even the implied warranty of
883N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
883N/A GNU General Public License for more details.
883N/A
883N/A You should have received a copy of the GNU General Public License
883N/A along with this program. If not, see <http://www.gnu.org/licenses/>.
883N/A*/
883N/A
883N/A#include "providers/child_common.h"
883N/A#include "providers/ldap/ldap_common.h"
883N/A#include "providers/ldap/sdap_async_private.h"
883N/A
883N/Astatic void sdap_shutdown(struct be_req *req);
883N/A
883N/A/* Id Handler */
883N/Astruct bet_ops sdap_id_ops = {
883N/A .handler = sdap_account_info_handler,
883N/A .finalize = sdap_shutdown
883N/A};
883N/A
883N/A/* Auth Handler */
883N/Astruct bet_ops sdap_auth_ops = {
883N/A .handler = sdap_pam_auth_handler,
883N/A .finalize = sdap_shutdown
883N/A};
883N/A
883N/A/* Chpass Handler */
883N/Astruct bet_ops sdap_chpass_ops = {
883N/A .handler = sdap_pam_chpass_handler,
883N/A .finalize = sdap_shutdown
883N/A};
883N/A
883N/Aint sssm_ldap_init(struct be_ctx *bectx,
883N/A struct bet_ops **ops,
883N/A void **pvt_data)
883N/A{
883N/A struct sdap_id_ctx *ctx;
883N/A const char *urls;
883N/A int ret;
883N/A
883N/A ctx = talloc_zero(bectx, struct sdap_id_ctx);
883N/A if (!ctx) return ENOMEM;
883N/A
883N/A ctx->be = bectx;
883N/A
883N/A ret = ldap_get_options(ctx, bectx->cdb,
883N/A bectx->conf_path, &ctx->opts);
883N/A if (ret != EOK) {
883N/A goto done;
883N/A }
883N/A
883N/A urls = dp_opt_get_string(ctx->opts->basic, SDAP_URI);
883N/A if (!urls) {
883N/A DEBUG(0, ("Missing ldap_uri\n"));
883N/A ret = EINVAL;
883N/A goto done;
883N/A }
883N/A
883N/A ret = sdap_service_init(ctx, ctx->be, "LDAP", urls, &ctx->service);
883N/A if (ret != EOK) {
883N/A DEBUG(1, ("Failed to initialize failover service!\n"));
883N/A goto done;
883N/A }
883N/A
883N/A ret = setup_tls_config(ctx->opts->basic);
883N/A if (ret != EOK) {
883N/A DEBUG(1, ("setup_tls_config failed [%d][%s].\n",
883N/A ret, strerror(ret)));
883N/A goto done;
883N/A }
883N/A
883N/A ret = sdap_id_setup_tasks(ctx);
883N/A if (ret != EOK) {
883N/A goto done;
883N/A }
883N/A
883N/A ret = setup_child(ctx);
883N/A if (ret != EOK) {
883N/A DEBUG(1, ("setup_child failed [%d][%s].\n",
883N/A ret, strerror(ret)));
883N/A goto done;
883N/A }
883N/A
883N/A *ops = &sdap_id_ops;
883N/A *pvt_data = ctx;
883N/A ret = EOK;
883N/A
883N/Adone:
883N/A if (ret != EOK) {
883N/A talloc_free(ctx);
883N/A }
883N/A return ret;
883N/A}
883N/A
883N/Aint sssm_ldap_auth_init(struct be_ctx *bectx,
883N/A struct bet_ops **ops,
883N/A void **pvt_data)
883N/A{
883N/A struct sdap_auth_ctx *ctx;
883N/A const char *urls;
883N/A int ret;
883N/A
883N/A ctx = talloc(bectx, struct sdap_auth_ctx);
883N/A if (!ctx) return ENOMEM;
883N/A
883N/A ctx->be = bectx;
883N/A
883N/A ret = ldap_get_options(ctx, bectx->cdb,
883N/A bectx->conf_path, &ctx->opts);
883N/A if (ret != EOK) {
883N/A goto done;
883N/A }
883N/A
883N/A urls = dp_opt_get_string(ctx->opts->basic, SDAP_URI);
883N/A if (!urls) {
883N/A DEBUG(0, ("Missing ldap_uri\n"));
883N/A ret = EINVAL;
883N/A goto done;
883N/A }
883N/A
883N/A ret = sdap_service_init(ctx, ctx->be, "LDAP", urls, &ctx->service);
883N/A if (ret != EOK) {
883N/A DEBUG(1, ("Failed to initialize failover service!\n"));
883N/A goto done;
883N/A }
883N/A
883N/A ret = setup_tls_config(ctx->opts->basic);
883N/A if (ret != EOK) {
883N/A DEBUG(1, ("setup_tls_config failed [%d][%s].\n",
883N/A ret, strerror(ret)));
883N/A goto done;
883N/A }
883N/A
883N/A *ops = &sdap_auth_ops;
883N/A *pvt_data = ctx;
883N/A ret = EOK;
883N/A
883N/Adone:
883N/A if (ret != EOK) {
883N/A talloc_free(ctx);
883N/A }
883N/A return ret;
883N/A}
883N/A
883N/Aint sssm_ldap_chpass_init(struct be_ctx *bectx,
883N/A struct bet_ops **ops,
883N/A void **pvt_data)
883N/A{
883N/A int ret;
883N/A
883N/A ret = sssm_ldap_auth_init(bectx, ops, pvt_data);
883N/A
883N/A *ops = &sdap_chpass_ops;
883N/A
883N/A return ret;
883N/A}
883N/A
883N/Astatic void sdap_shutdown(struct be_req *req)
883N/A{
883N/A /* TODO: Clean up any internal data */
883N/A sdap_handler_done(req, DP_ERR_OK, EOK, NULL);
883N/A}
883N/A
883N/A