b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek KCM Server - the mainloop and server setup
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek Copyright (C) Red Hat, 2016
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek This program is free software; you can redistribute it and/or modify
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek it under the terms of the GNU General Public License as published by
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek (at your option) any later version.
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek This program is distributed in the hope that it will be useful,
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek GNU General Public License for more details.
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek You should have received a copy of the GNU General Public License
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek#define SSS_KCM_SOCKET_NAME DEFAULT_KCM_SOCKET_PATH
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozekstatic int kcm_responder_ctx_destructor(void *ptr)
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek struct resp_ctx *rctx = talloc_get_type(ptr, struct resp_ctx);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek /* mark that we are shutting down the responder, so it is propagated
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek * into underlying contexts that are freed right before rctx */
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "Responder is being shut down\n");
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozekstatic errno_t kcm_get_ccdb_be(struct kcm_ctx *kctx)
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek "Cannot get the KCM database type [%d]: %s\n",
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek DEBUG(SSSDBG_CONF_SETTINGS, "KCM database type: %s\n", str_db);
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek } else if (strcasecmp(str_db, "secrets") == 0) {
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "Unexpected KCM database type %s\n", str_db);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek "Failed to get file descriptors limit\n");
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek "Cannot get the client idle timeout [%d]: %s\n",
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek /* Ensure that the client timeout is at least ten seconds */
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek "Cannot get KCM socket path [%d]: %s\n",
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek "Cannot get KCM ccache DB [%d]: %s\n",
e89ba95737202d551db2c9524127e6c4cf308796Jakub Hrozek ret = responder_setup_idle_timeout_config(kctx->rctx);
e89ba95737202d551db2c9524127e6c4cf308796Jakub Hrozek "Cannot set up idle responder timeout\n");
e89ba95737202d551db2c9524127e6c4cf308796Jakub Hrozek /* Not fatal */
2b5518eeaacc6245cfa77ee4a7086f16208060fcJakub Hrozek "Cannot create KCM request queue [%d]: %s\n",
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek struct kcm_resp_ctx *kcm_data = talloc_get_type(ptr, struct kcm_resp_ctx);
70fe6e2bb398b8669ad1aebeaf0abcbffc307475Jakub Hrozekstatic struct kcm_resp_ctx *kcm_data_setup(TALLOC_CTX *mem_ctx,
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek kcm_data = talloc_zero(mem_ctx, struct kcm_resp_ctx);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing kcm data\n");
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek kcm_data->db = kcm_ccdb_init(kcm_data, ev, cc_be);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek talloc_set_destructor((TALLOC_CTX*)kcm_data, kcm_data_destructor);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozekstatic int kcm_process_init(TALLOC_CTX *mem_ctx,
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing resp_ctx\n");
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek rctx->confdb_service_path = CONFDB_KCM_CONF_ENTRY;
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek talloc_set_destructor((TALLOC_CTX*)rctx, kcm_responder_ctx_destructor);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing kcm_ctx\n");
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE, "fatal error getting KCM config\n");
35c9dfe9ba78d3a635cd1af0fb6349ba44344623Jakub Hrozek kctx->kcm_data = kcm_data_setup(kctx, ev, kctx->cc_be);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek "fatal error initializing responder data\n");
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek /* Set up file descriptor limits */
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek ret = activate_unix_sockets(rctx, kcm_connection_setup);
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC, "KCM Initialization complete\n");
677a31351c80453d9ce006481364399a96312052René Genz /* Set debug level to invalid value so we can decide if -d 0 was used. */
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek pc = poptGetContext(argv[0], argc, argv, long_options, 0);
677a31351c80453d9ce006481364399a96312052René Genz /* set up things like debug, signals, daemonization, etc. */
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek ret = server_setup("sssd[kcm]", 0, uid, gid, CONFDB_KCM_CONF_ENTRY,
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek /* This is not fatal, don't return */
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek "Could not set up to exit when parent process does\n");
b9c563c29243291f40489bb0dcbf3946fca72d58Jakub Hrozek /* loop on main */