ad_init.c revision 483728c1f9719e419830cce93b7e411370a5364b
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/*
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding SSSD
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding Authors:
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding Stephen Gallagher <sgallagh@redhat.com>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding Copyright (C) 2012 Red Hat
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding This program is free software; you can redistribute it and/or modify
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding it under the terms of the GNU General Public License as published by
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding the Free Software Foundation; either version 3 of the License, or
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding (at your option) any later version.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding This program is distributed in the hope that it will be useful,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding but WITHOUT ANY WARRANTY; without even the implied warranty of
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding GNU General Public License for more details.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding You should have received a copy of the GNU General Public License
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding along with this program. If not, see <http://www.gnu.org/licenses/>.
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding*/
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include <sys/types.h>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include <unistd.h>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include <sys/stat.h>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include <fcntl.h>
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include <sasl/sasl.h>
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "util/util.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/ad/ad_common.h"
64185f9824e42f21ca7b9ae6c004484215c031a7rbb#include "providers/ad/ad_access.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "providers/ldap/ldap_common.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/ldap/sdap_access.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/ldap/sdap_idmap.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/krb5/krb5_auth.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/krb5/krb5_init_shared.h"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#include "providers/ad/ad_id.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/ad/ad_srv.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/dp_dyndns.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding#include "providers/ad/ad_subdomains.h"
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingstruct ad_options *ad_options = NULL;
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingstatic void
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingad_shutdown(struct be_req *req);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct bet_ops ad_id_ops = {
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding .handler = ad_account_info_handler,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding .finalize = ad_shutdown,
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding .check_online = ad_check_online
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffieldingstruct bet_ops ad_auth_ops = {
7e79e8fd53348f9fc6e8009a4a2522425ab6f08ffielding .handler = krb5_pam_handler,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding .finalize = NULL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct bet_ops ad_chpass_ops = {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding .handler = krb5_pam_handler,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding .finalize = NULL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstruct bet_ops ad_access_ops = {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding .handler = ad_access_handler,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding .finalize = NULL
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding#define AD_COMPAT_ON "1"
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int ad_sasl_getopt(void *context, const char *plugin_name,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *option,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char **result, unsigned *len)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!plugin_name || !result) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return SASL_FAIL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (strcmp(plugin_name, "GSSAPI") != 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return SASL_FAIL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (strcmp(option, "ad_compat") != 0) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return SASL_FAIL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *result = AD_COMPAT_ON;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (len) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *len = 2;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
2d71630471d1c23f0137309e3c3957c633ecbfd6rbb return SASL_OK;
ab5581cc78e9d865b0a6ab1404c53347b3276968rbb}
b6055b7832a0e4d0818416252fff5925aaebae4brbb
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingtypedef int (*sss_sasl_gen_cb_fn)(void);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawickstatic const sasl_callback_t ad_sasl_callbacks[] = {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding { SASL_CB_GETOPT, (sss_sasl_gen_cb_fn)ad_sasl_getopt, NULL },
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm { SASL_CB_LIST_END, NULL, NULL }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding};
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding/* This is quite a hack, we *try* to fool openldap libraries by initializing
b8dd12594991e5c275d82fca865d13c5f9775f4efielding * sasl first so we can pass in the SASL_CB_GETOPT callback we need to set some
b8dd12594991e5c275d82fca865d13c5f9775f4efielding * options. Should be removed as soon as openldap exposes a way to do that */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic void ad_sasl_initialize(void)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* NOTE: this may fail if soe other library in the system happens to
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * initialize and use openldap libraries or directly the cyrus-sasl
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * library as this initialization function can be called only once per
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding * process */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding (void)sasl_client_init(ad_sasl_callbacks);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm}
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawick
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawickstatic errno_t
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawickcommon_ad_init(struct be_ctx *bectx)
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm{
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm errno_t ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ad_servers = NULL;
b8dd12594991e5c275d82fca865d13c5f9775f4efielding char *ad_backup_servers = NULL;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding char *ad_realm;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_sasl_initialize();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Get AD-specific options */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = ad_get_common_options(bectx, bectx->cdb,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding bectx->conf_path,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding bectx->domain,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm &ad_options);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_FATAL_FAILURE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("Could not parse common options: [%s]\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_servers = dp_opt_get_string(ad_options->basic, AD_SERVER);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_backup_servers = dp_opt_get_string(ad_options->basic, AD_BACKUP_SERVER);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_realm = dp_opt_get_string(ad_options->basic, AD_KRB5_REALM);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Set up the failover service */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = ad_failover_init(ad_options, bectx, ad_servers, ad_backup_servers, ad_realm,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding AD_SERVICE_NAME, AD_GC_SERVICE_NAME,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding dp_opt_get_string(ad_options->basic, AD_DOMAIN),
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding &ad_options->service);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_FATAL_FAILURE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("Failed to init AD failover service: [%s]\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = EOK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingdone:
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding}
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingint
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingsssm_ad_id_init(struct be_ctx *bectx,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct bet_ops **ops,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding void **pvt_data)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding{
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding errno_t ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct ad_id_ctx *ad_ctx;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *hostname;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding const char *ad_domain;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding struct ad_srv_plugin_ctx *srv_ctx;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (!ad_options) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = common_ad_init(bectx);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return ret;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ad_options->id_ctx) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* already initialized */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding *ops = &ad_id_ops;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm *pvt_data = ad_options->id_ctx;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding return EOK;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_ctx = ad_id_ctx_init(ad_options, bectx);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ad_ctx == NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm return ENOMEM;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ad_options->id_ctx = ad_ctx;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = ad_dyndns_init(ad_ctx->sdap_id_ctx->be, ad_options);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_MINOR_FAILURE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("Failure setting up automatic DNS update\n"));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Continue without DNS updates */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = sdap_setup_child();
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_FATAL_FAILURE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("setup_child failed [%d][%s].\n",
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret, strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
b14e7600fdbd04c00dca26522b85ca061c42d9f3trawick
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* Set up various SDAP options */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = ad_get_id_options(ad_options, bectx->cdb,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm bectx->conf_path,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding &ad_ctx->sdap_id_ctx->opts);
b8dd12594991e5c275d82fca865d13c5f9775f4efielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = sdap_id_setup_tasks(ad_ctx->sdap_id_ctx);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm goto done;
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawick }
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawick
2eaf6dbe7ea643b3a2b8e1973d9684fac6372c46trawick /* Set up the ID mapping object */
7431131ef5bf15f103cf5f338407ccabb716c0c0rbb ret = sdap_idmap_init(ad_ctx->sdap_id_ctx, ad_ctx->sdap_id_ctx,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm &ad_ctx->sdap_id_ctx->opts->idmap_ctx);
0a09a4a642f7c0d367598394411dbdd4a6d8cd09fielding if (ret != EOK) goto done;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ret = setup_tls_config(ad_ctx->sdap_id_ctx->opts->basic);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (ret != EOK) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_CRIT_FAILURE,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("setup_tls_config failed [%s]\n", strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* setup SRV lookup plugin */
b8dd12594991e5c275d82fca865d13c5f9775f4efielding hostname = dp_opt_get_string(ad_options->basic, AD_HOSTNAME);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding if (dp_opt_get_bool(ad_options->basic, AD_ENABLE_DNS_SITES)) {
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* use AD plugin */
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm ad_domain = dp_opt_get_string(ad_options->basic, AD_DOMAIN);
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm srv_ctx = ad_srv_plugin_ctx_init(bectx, bectx->be_res,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding default_host_dbs, ad_options->id,
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm hostname, ad_domain);
7431131ef5bf15f103cf5f338407ccabb716c0c0rbb if (srv_ctx == NULL) {
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm DEBUG(SSSDBG_FATAL_FAILURE, ("Out of memory?\n"));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = ENOMEM;
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm goto done;
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding }
1ccd992d37d62c8cb2056126f2234f64ec189bfddougm
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding be_fo_set_srv_lookup_plugin(bectx, ad_srv_plugin_send,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ad_srv_plugin_recv, srv_ctx, "AD");
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding } else {
0a09a4a642f7c0d367598394411dbdd4a6d8cd09fielding /* fall back to standard plugin */
ret = be_fo_set_dns_srv_lookup_plugin(bectx, hostname);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Unable to set SRV lookup plugin "
"[%d]: %s\n", ret, strerror(ret)));
goto done;
}
}
/* setup periodical refresh of expired records */
ret = be_refresh_add_cb(bectx->refresh_ctx, BE_REFRESH_TYPE_NETGROUPS,
sdap_refresh_netgroups_send,
sdap_refresh_netgroups_recv,
ad_ctx->sdap_id_ctx);
if (ret != EOK && ret != EEXIST) {
DEBUG(SSSDBG_MINOR_FAILURE, ("Periodical refresh of netgroups "
"will not work [%d]: %s\n", ret, strerror(ret)));
}
*ops = &ad_id_ops;
*pvt_data = ad_ctx;
ret = EOK;
done:
if (ret != EOK) {
talloc_zfree(ad_options->id_ctx);
}
return ret;
}
int
sssm_ad_auth_init(struct be_ctx *bectx,
struct bet_ops **ops,
void **pvt_data)
{
errno_t ret;
struct krb5_ctx *krb5_auth_ctx = NULL;
if (!ad_options) {
ret = common_ad_init(bectx);
if (ret != EOK) {
return ret;
}
}
if (ad_options->auth_ctx) {
/* Already initialized */
*ops = &ad_auth_ops;
*pvt_data = ad_options->auth_ctx;
return EOK;
}
krb5_auth_ctx = talloc_zero(NULL, struct krb5_ctx);
if (!krb5_auth_ctx) {
ret = ENOMEM;
goto done;
}
krb5_auth_ctx->config_type = K5C_GENERIC;
krb5_auth_ctx->service = ad_options->service->krb5_service;
ret = ad_get_auth_options(krb5_auth_ctx, ad_options, bectx,
&krb5_auth_ctx->opts);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE,
("Could not determine Kerberos options\n"));
goto done;
}
ret = krb5_child_init(krb5_auth_ctx, bectx);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE,
("Could not initialize krb5_child settings: [%s]\n",
strerror(ret)));
goto done;
}
ad_options->auth_ctx = talloc_steal(ad_options, krb5_auth_ctx);
*ops = &ad_auth_ops;
*pvt_data = ad_options->auth_ctx;
done:
if (ret != EOK) {
talloc_free(krb5_auth_ctx);
}
return ret;
}
int
sssm_ad_chpass_init(struct be_ctx *bectx,
struct bet_ops **ops,
void **pvt_data)
{
errno_t ret;
if (!ad_options) {
ret = common_ad_init(bectx);
if (ret != EOK) {
return ret;
}
}
if (ad_options->auth_ctx) {
/* Already initialized */
*ops = &ad_chpass_ops;
*pvt_data = ad_options->auth_ctx;
return EOK;
}
ret = sssm_ad_auth_init(bectx, ops, pvt_data);
*ops = &ad_chpass_ops;
ad_options->auth_ctx = *pvt_data;
return ret;
}
int
sssm_ad_access_init(struct be_ctx *bectx,
struct bet_ops **ops,
void **pvt_data)
{
errno_t ret;
struct ad_access_ctx *access_ctx;
struct ad_id_ctx *ad_id_ctx;
access_ctx = talloc_zero(bectx, struct ad_access_ctx);
if (!access_ctx) return ENOMEM;
ret = sssm_ad_id_init(bectx, ops, (void **)&ad_id_ctx);
if (ret != EOK) {
goto fail;
}
access_ctx->sdap_ctx = ad_id_ctx->sdap_id_ctx;
ret = dp_copy_options(access_ctx, ad_options->basic, AD_OPTS_BASIC,
&access_ctx->ad_options);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE,
("Could not initialize access provider options: [%s]\n",
strerror(ret)));
goto fail;
}
/* Set up an sdap_access_ctx for checking expired/locked accounts */
access_ctx->sdap_access_ctx =
talloc_zero(access_ctx, struct sdap_access_ctx);
if (!access_ctx->sdap_access_ctx) {
ret = ENOMEM;
goto fail;
}
access_ctx->sdap_access_ctx->id_ctx = access_ctx->sdap_ctx;
access_ctx->sdap_access_ctx->access_rule[0] = LDAP_ACCESS_EXPIRE;
access_ctx->sdap_access_ctx->access_rule[1] = LDAP_ACCESS_EMPTY;
*ops = &ad_access_ops;
*pvt_data = access_ctx;
return EOK;
fail:
talloc_free(access_ctx);
return ret;
}
static void
ad_shutdown(struct be_req *req)
{
/* TODO: Clean up any internal data */
sdap_handler_done(req, DP_ERR_OK, EOK, NULL);
}
int sssm_ad_subdomains_init(struct be_ctx *bectx,
struct bet_ops **ops,
void **pvt_data)
{
int ret;
struct ad_id_ctx *id_ctx;
const char *ad_domain;
ret = sssm_ad_id_init(bectx, ops, (void **) &id_ctx);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("sssm_ad_id_init failed.\n"));
return ret;
}
if (ad_options == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Global AD options not available.\n"));
return EINVAL;
}
ad_domain = dp_opt_get_string(ad_options->basic, AD_DOMAIN);
ret = ad_subdom_init(bectx, id_ctx, ad_domain, ops, pvt_data);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, ("ad_subdom_init failed.\n"));
return ret;
}
return EOK;
}