2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher Copyright (C) 2010 Red Hat
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher This program is free software; you can redistribute it and/or modify
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher it under the terms of the GNU General Public License as published by
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher the Free Software Foundation; either version 3 of the License, or
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher (at your option) any later version.
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher This program is distributed in the hope that it will be useful,
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher GNU General Public License for more details.
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher You should have received a copy of the GNU General Public License
2dd3faebcd3cfd00efda38ffd2585d675e696b12Stephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#define ERROR_INITGR "The '%s' library does not provides the " \
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "_nss_XXX_initgroups_dyn function!\n" \
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "initgroups will be slow as it will require " \
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "full groups enumeration!\n"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#define ERROR_NETGR "The '%s' library does not support netgroups.\n"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina#define ERROR_SERV "The '%s' library does not support services.\n"
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina funcname = talloc_asprintf(NULL, NSS_FN_NAME, libname, name);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t proxy_id_conf(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = confdb_get_string(be_ctx->cdb, tmp_ctx, be_ctx->conf_path,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read confdb [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "No library name given\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = confdb_get_bool(be_ctx->cdb, be_ctx->conf_path,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read confdb [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina libpath = talloc_asprintf(tmp_ctx, "libnss_%s.so.2", libname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t proxy_id_load_symbols(struct proxy_nss_ops *ops,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getpwnam_r, "getpwnam_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getpwuid_r, "getpwuid_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->setpwent, "setpwent", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getpwent_r, "getpwent_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->endpwent, "endpwent", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getgrnam_r, "getgrnam_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getgrgid_r, "getgrgid_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->setgrent, "setgrent", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getgrent_r, "getgrent_r", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->endgrent, "endgrent", NULL, true},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->initgroups_dyn, "initgroups_dyn", ERROR_INITGR, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->setnetgrent, "setnetgrent", ERROR_NETGR, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getnetgrent_r, "getnetgrent_r", ERROR_NETGR, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->endnetgrent, "endnetgrent", ERROR_NETGR, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getservbyname_r, "getservbyname_r", ERROR_SERV, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getservbyport_r, "getservbyport_r", ERROR_SERV, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->setservent, "setservent", ERROR_SERV, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->getservent_r, "getservent_r", ERROR_SERV, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina {(void**)&ops->endservent, "endservent", ERROR_SERV, false},
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina *symbols[i].dest = proxy_dlsym(handle, symbols[i].name, libname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Failed to load _nss_%s_%s, "
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "error: %s.\n", libname, symbols[i].name, dlerror());
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, symbols[i].custom_error, libname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t proxy_setup_sbus(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sbus_address = talloc_asprintf(mem_ctx, "unix:path=%s/%s_%s", PIPE_PATH,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "talloc_asprintf() failed.\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = sbus_new_server(mem_ctx, be_ctx->ev, sbus_address, 0, be_ctx->gid,
7622d9d97eb6747a9f3406633281f2492f8f4a0aFabiano Fidêncio false, &ctx->sbus_srv, proxy_client_init, ctx, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Could not set up sbus server.\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t proxy_auth_conf(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = confdb_get_string(be_ctx->cdb, mem_ctx, be_ctx->conf_path,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to read confdb [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Missing option %s.\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic errno_t proxy_init_auth_ctx(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina auth_ctx = talloc_zero(mem_ctx, struct proxy_auth_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina auth_ctx->timeout_ms = SSS_CLI_SOCKET_TIMEOUT / 4;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = proxy_auth_conf(auth_ctx, be_ctx, &auth_ctx->pam_target);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = proxy_setup_sbus(auth_ctx, auth_ctx, be_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Set up request hash table */
aef0171e0bdc9a683958d69c7ee984fb10cd5de7Petr Cech ret = confdb_get_int(be_ctx->cdb, be_ctx->conf_path,
aef0171e0bdc9a683958d69c7ee984fb10cd5de7Petr Cech "Unable to read confdb [%d]: %s\n", ret, sss_strerror(ret));
aef0171e0bdc9a683958d69c7ee984fb10cd5de7Petr Cech "Option " CONFDB_PROXY_MAX_CHILDREN " must be higher then 0\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina hret = hash_create(auth_ctx->max_children * 2, &auth_ctx->request_table,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Could not initialize request table\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* Initialize auth_ctx since one of the access, auth or chpass is set. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = proxy_init_auth_ctx(mem_ctx, be_ctx, &auth_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to create auth context [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t sssm_proxy_id_init(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ctx = talloc_zero(mem_ctx, struct proxy_id_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = proxy_id_conf(ctx, be_ctx, &libname, &libpath, &ctx->fast_alias);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Unable to load %s module, "
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = proxy_id_load_symbols(&ctx->ops, libname, ctx->handle);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FATAL_FAILURE, "Unable to load NSS symbols [%d]: %s\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_set_method(dp_methods, DPM_ACCOUNT_HANDLER,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina proxy_account_info_handler_send, proxy_account_info_handler_recv, ctx,
3d29430867cf92b2d71afa95abb679711231117cPavel Březina struct proxy_id_ctx, struct dp_id_data, struct dp_reply_std);
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek dp_set_method(dp_methods, DPM_ACCT_DOMAIN_HANDLER,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek default_account_domain_send, default_account_domain_recv, NULL,
c0f9f5a0f6d71a1596ee3cef549b4b02295313c3Jakub Hrozek void, struct dp_get_acct_domain_data, struct dp_reply_std);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t sssm_proxy_auth_init(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina auth_ctx = talloc_get_type(module_data, struct proxy_auth_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina proxy_pam_handler_send, proxy_pam_handler_recv, auth_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_auth_ctx, struct pam_data, struct pam_data *);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t sssm_proxy_chpass_init(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return sssm_proxy_auth_init(mem_ctx, be_ctx, module_data, dp_methods);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t sssm_proxy_access_init(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina auth_ctx = talloc_get_type(module_data, struct proxy_auth_ctx);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina proxy_pam_handler_send, proxy_pam_handler_recv, auth_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct proxy_auth_ctx, struct pam_data, struct pam_data *);