cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek/*
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek Authors:
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek Copyright (C) 2013 Red Hat
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek InfoPipe responder: the responder server
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek This program is free software; you can redistribute it and/or modify
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek it under the terms of the GNU General Public License as published by
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek the Free Software Foundation; either version 3 of the License, or
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek (at your option) any later version.
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek This program is distributed in the hope that it will be useful,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek GNU General Public License for more details.
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek You should have received a copy of the GNU General Public License
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek*/
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <stdio.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <unistd.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <fcntl.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <sys/types.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <sys/stat.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <sys/socket.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <sys/un.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <string.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <sys/time.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <errno.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <popt.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include <dbus/dbus.h>
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "util/util.h"
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek#include "util/strtonum.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "sbus/sssd_dbus.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "monitor/monitor_interfaces.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "confdb/confdb.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "responder/ifp/ifp_private.h"
590582be38cdbfde387fcc57df92903d48c5a083Jakub Hrozek#include "responder/ifp/ifp_domains.h"
8a1fd0633e85221da1fb63451516a70d66c0af31Pavel Březina#include "responder/ifp/ifp_components.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek#include "responder/common/responder_sbus.h"
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek#define DEFAULT_ALLOWED_UIDS "0"
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozekstatic int ifp_sysbus_reconnect(struct sbus_request *dbus_req, void *data);
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekstruct mon_cli_iface monitor_ifp_methods = {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek { &mon_cli_iface_meta, 0 },
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek .resInit = monitor_common_res_init,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek .goOffline = NULL,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek .resetOffline = NULL,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek .rotateLogs = responder_logrotate,
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek .sysbusReconnect = ifp_sysbus_reconnect,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek};
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekstruct sss_cmd_table *get_ifp_cmds(void)
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek{
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek static struct sss_cmd_table ifp_cmds[] = {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek { SSS_GET_VERSION, sss_cmd_get_version },
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek { SSS_CLI_NULL, NULL}
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek };
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return ifp_cmds;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek}
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekstatic void ifp_dp_reconnect_init(struct sbus_connection *conn,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int status, void *pvt)
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek{
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct be_conn *be_conn = talloc_get_type(pvt, struct be_conn);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int ret;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* Did we reconnect successfully? */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (status == SBUS_RECONNECT_SUCCESS) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Reconnected to the Data Provider.\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* Identify ourselves to the data provider */
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina ret = rdp_register_client(be_conn, "InfoPipe");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* all fine */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret == EOK) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek handle_requests_after_reconnect(be_conn->rctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* Failed to reconnect */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Could not reconnect to %s provider.\n",
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek be_conn->domain->name);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek}
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozekstatic errno_t
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozeksysbus_init(TALLOC_CTX *mem_ctx,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek struct tevent_context *ev,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek const char *dbus_name,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek void *pvt,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek struct sysbus_ctx **sysbus)
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek{
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DBusError dbus_error;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DBusConnection *conn = NULL;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek struct sysbus_ctx *system_bus = NULL;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek errno_t ret;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek system_bus = talloc_zero(mem_ctx, struct sysbus_ctx);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (system_bus == NULL) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek return ENOMEM;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek dbus_error_init(&dbus_error);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek /* Connect to the well-known system bus */
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek conn = dbus_bus_get(DBUS_BUS_SYSTEM, &dbus_error);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (conn == NULL) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek "Failed to connect to D-BUS system bus: [%s]\n",
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek dbus_error.message);
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek ret = ERR_NO_SYSBUS;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek goto fail;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek dbus_connection_set_exit_on_disconnect(conn, FALSE);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek ret = dbus_bus_request_name(conn, dbus_name,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek /* We want exclusive access */
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DBUS_NAME_FLAG_DO_NOT_QUEUE,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek &dbus_error);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek /* We were unable to register on the system bus */
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek "Unable to request name on the system bus: [%s]\n",
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek dbus_error.message);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek ret = EIO;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek goto fail;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Listening on %s\n", dbus_name);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek /* Integrate with tevent loop */
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek ret = sbus_init_connection(system_bus, ev, conn,
b81ad4a7c59cade13d52216f805d904392627136Jakub Hrozek SBUS_CONN_TYPE_SYSBUS,
7622d9d97eb6747a9f3406633281f2492f8f4a0aFabiano Fidêncio NULL, NULL, &system_bus->conn);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (ret != EOK) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek "Could not integrate D-BUS into mainloop.\n");
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek goto fail;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina ret = ifp_register_sbus_interface(system_bus->conn, pvt);
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina if (ret != EOK) {
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Could not register interfaces\n");
772199031f0ec687fa1fefd939206858c440e5a1Pavel Březina goto fail;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
2b7ef850846029641cc59560c2d8d4ab7254dda5Pavel Březina ifp_register_nodes(pvt, system_bus->conn);
2b7ef850846029641cc59560c2d8d4ab7254dda5Pavel Březina
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek *sysbus = system_bus;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek return EOK;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozekfail:
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (dbus_error_is_set(&dbus_error)) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek "DBus error message: %s\n", dbus_error.message);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek dbus_error_free(&dbus_error);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek if (conn) dbus_connection_unref(conn);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek talloc_free(system_bus);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek return ret;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek}
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozekstatic int ifp_sysbus_reconnect(struct sbus_request *dbus_req, void *data)
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek{
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek struct resp_ctx *rctx = talloc_get_type(data, struct resp_ctx);
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek struct ifp_ctx *ifp_ctx = (struct ifp_ctx*) rctx->pvt_ctx;
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek errno_t ret;
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Attempting to reconnect to the system bus\n");
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek if (ifp_ctx->sysbus) {
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Already connected to sysbus\n");
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek goto done;
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek }
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek /* Connect to the D-BUS system bus and set up methods */
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek ret = sysbus_init(ifp_ctx, ifp_ctx->rctx->ev,
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina IFACE_IFP,
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek ifp_ctx, &ifp_ctx->sysbus);
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek if (ret == ERR_NO_SYSBUS) {
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek "The system bus is not available..\n");
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek goto done;
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek } else if (ret != EOK) {
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek "Failed to connect to the system message bus\n");
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek return ret;
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek }
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek DEBUG(SSSDBG_TRACE_LIBS, "Reconnected to the system bus!\n");
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozekdone:
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek return sbus_request_return_and_finish(dbus_req, DBUS_TYPE_INVALID);
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek}
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekint ifp_process_init(TALLOC_CTX *mem_ctx,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct tevent_context *ev,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct confdb_ctx *cdb)
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek{
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct resp_ctx *rctx;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct sss_cmd_table *ifp_cmds;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct ifp_ctx *ifp_ctx;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct be_conn *iter;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int ret;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int max_retries;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek char *uid_str;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek char *attr_list_str;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek char *wildcard_limit_str;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_cmds = get_ifp_cmds();
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = sss_process_init(mem_ctx, ev, cdb,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_cmds,
8bccd95e275fae760a991da394235e4e70e57bbdMichal Zidek NULL, -1, NULL, -1,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek CONFDB_IFP_CONF_ENTRY,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek SSS_IFP_SBUS_SERVICE_NAME,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek SSS_IFP_SBUS_SERVICE_VERSION,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek &monitor_ifp_methods,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "InfoPipe",
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina NULL,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_connection_setup,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek &rctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "sss_process_init() failed\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return ret;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_ctx = talloc_zero(rctx, struct ifp_ctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ifp_ctx == NULL) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing ifp_ctx\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = ENOMEM;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek goto fail;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_ctx->rctx = rctx;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_ctx->rctx->pvt_ctx = ifp_ctx;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = sss_names_init_from_args(ifp_ctx,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "(?P<name>[^@]+)@?(?P<domain>[^@]*$)",
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "%1$s@%2$s", &ifp_ctx->snctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing regex data\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek goto fail;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ret = confdb_get_string(ifp_ctx->rctx->cdb, ifp_ctx->rctx,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek CONFDB_IFP_CONF_ENTRY, CONFDB_SERVICE_ALLOWED_UIDS,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek DEFAULT_ALLOWED_UIDS, &uid_str);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (ret != EOK) {
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Failed to get allowed UIDs.\n");
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek goto fail;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek ret = csv_string_to_uid_array(ifp_ctx->rctx, uid_str, true,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek &ifp_ctx->rctx->allowed_uids_count,
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek &ifp_ctx->rctx->allowed_uids);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek talloc_free(uid_str);
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek if (ret != EOK) {
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Failed to set allowed UIDs.\n");
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek goto fail;
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek }
3660f49f81e4db07be66fe0887af9d62065f1f2cJakub Hrozek
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek ret = confdb_get_string(ifp_ctx->rctx->cdb, ifp_ctx->rctx,
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek CONFDB_IFP_CONF_ENTRY, CONFDB_IFP_USER_ATTR_LIST,
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek NULL, &attr_list_str);
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek if (ret != EOK) {
7b5a077bd162cb2340d5d4e9f5dcc0dd00709f1aSumit Bose DEBUG(SSSDBG_FATAL_FAILURE, "Failed to get user attribute list.\n");
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek goto fail;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek }
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
a1e4113a5388e34c08459c5b69679c82ac2bddc9Pavel Březina ifp_ctx->user_whitelist = ifp_parse_user_attr_list(ifp_ctx, attr_list_str);
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek talloc_free(attr_list_str);
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek if (ifp_ctx->user_whitelist == NULL) {
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
1f2507e1fd089f2bf3458cfb4faeaa9669d72f98Jakub Hrozek "Failed to parse the allowed attribute list\n");
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek goto fail;
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek }
770dc892f867639f36f84455d65be6287935a529Jakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* Enable automatic reconnection to the Data Provider */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = confdb_get_int(ifp_ctx->rctx->cdb,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek CONFDB_IFP_CONF_ENTRY,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek CONFDB_SERVICE_RECON_RETRIES,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek 3, &max_retries);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "Failed to set up automatic reconnection\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek goto fail;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek /* A bit convoluted way until we have a confdb_get_uint32 */
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ret = confdb_get_string(ifp_ctx->rctx->cdb,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ifp_ctx->rctx,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek CONFDB_IFP_CONF_ENTRY,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek CONFDB_IFP_WILDCARD_LIMIT,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek NULL, /* no limit by default */
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek &wildcard_limit_str);
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (ret != EOK) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek "Failed to retrieve limit for a wildcard search\n");
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek goto fail;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek if (wildcard_limit_str) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek ifp_ctx->wildcard_limit = strtouint32(wildcard_limit_str, NULL, 10);
afdc0179af0ad8ddbedd67422193ef02dcd2bf84Lukas Slebodnik ret = errno;
afdc0179af0ad8ddbedd67422193ef02dcd2bf84Lukas Slebodnik if (ret != EOK) {
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek goto fail;
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek }
bdf32fbb3c947dd1b2c54d1c21d8028a1ddc80e6Jakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek for (iter = ifp_ctx->rctx->be_conns; iter; iter = iter->next) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek sbus_reconnect_init(iter->conn, max_retries,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ifp_dp_reconnect_init, iter);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek /* Connect to the D-BUS system bus and set up methods */
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek ret = sysbus_init(ifp_ctx, ifp_ctx->rctx->ev,
beeef7f627a5ed9264de25ee4c76eb9620c1c984Pavel Březina IFACE_IFP,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek ifp_ctx, &ifp_ctx->sysbus);
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek if (ret == ERR_NO_SYSBUS) {
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek "The system bus is not available..\n");
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek /* Explicitly ignore, the D-Bus daemon will start us */
0c1d65998907930678da2d091789446f2c344d5dJakub Hrozek } else if (ret != EOK) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek "Failed to connect to the system message bus\n");
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek talloc_free(ifp_ctx);
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek return EIO;
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek }
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) {
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
8214510f125879c3b1d247f2ce981ee20b5375d1Jakub Hrozek "schedule_get_domains_tasks failed.\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek goto fail;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "InfoPipe Initialization complete\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return EOK;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekfail:
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek talloc_free(rctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return ret;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek}
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozekint main(int argc, const char *argv[])
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek{
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int opt;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek poptContext pc;
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik char *opt_logger = NULL;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct main_context *main_ctx;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek int ret;
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek uid_t uid;
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek gid_t gid;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek struct poptOption long_options[] = {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek POPT_AUTOHELP
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek SSSD_MAIN_OPTS
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik SSSD_LOGGER_OPTS
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek SSSD_SERVER_OPTS(uid, gid)
9222a4fcbeec9d5a6f84aab31a5131f14d4a6430Fabiano Fidêncio SSSD_RESPONDER_OPTS
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek POPT_TABLEEND
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek };
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
677a31351c80453d9ce006481364399a96312052René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek debug_level = SSSDBG_INVALID;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
458f5245dd5130d12666cce6faf8ef1ec7f80169Pavel Reichl umask(DFL_RSP_UMASK);
458f5245dd5130d12666cce6faf8ef1ec7f80169Pavel Reichl
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek while((opt = poptGetNextOpt(pc)) != -1) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek switch(opt) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek default:
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek fprintf(stderr, "\nInvalid option %s: %s\n\n",
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek poptBadOption(pc, 0), poptStrerror(opt));
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek poptPrintUsage(pc, stderr, 0);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return 1;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek poptFreeContext(pc);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG_INIT(debug_level);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
677a31351c80453d9ce006481364399a96312052René Genz /* set up things like debug, signals, daemonization, etc. */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek debug_log_file = "sssd_ifp";
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik sss_set_logger(opt_logger);
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek ret = server_setup("sssd[ifp]", 0, 0, 0,
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek CONFDB_IFP_CONF_ENTRY, &main_ctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) return 2;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = die_if_parent_died();
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) {
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* This is not fatal, don't return */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek "Could not set up to exit when parent process does\n");
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek }
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek ret = ifp_process_init(main_ctx,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek main_ctx->event_ctx,
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek main_ctx->confdb_ctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek if (ret != EOK) return 3;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek /* loop on main */
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek server_loop(main_ctx);
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek return 0;
cb4d5b588e704114b7090678752d33512baa718eJakub Hrozek}