b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose/*
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose SSSD
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose PAC Responder
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose Copyright (C) Sumit Bose <sbose@redhat.com> 2011
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose This program is free software; you can redistribute it and/or modify
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose it under the terms of the GNU General Public License as published by
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose the Free Software Foundation; either version 3 of the License, or
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose (at your option) any later version.
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose This program is distributed in the hope that it will be useful,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose GNU General Public License for more details.
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose You should have received a copy of the GNU General Public License
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose*/
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <stdio.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <unistd.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <fcntl.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <sys/types.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <sys/stat.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <sys/socket.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <sys/un.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <string.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <sys/time.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include <errno.h>
19b4bb652f5cdc2797b66595eaf8811881aa9873Jakub Hrozek#include <popt.h>
19b4bb652f5cdc2797b66595eaf8811881aa9873Jakub Hrozek#include <dbus/dbus.h>
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "util/util.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "responder/pac/pacsrv.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "db/sysdb.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "confdb/confdb.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "sbus/sssd_dbus.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "responder/common/responder_packet.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "responder/common/responder.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "providers/data_provider.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "monitor/monitor_interfaces.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#include "sbus/sbus_client.h"
a473fb88e6015cf0ccbd2e9005c7e6acca18f452Pavel Březina#include "util/util_sss_idmap.h"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose#define SSS_PAC_PIPE_NAME "pac"
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose#define DEFAULT_PAC_FD_LIMIT 8192
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose#define DEFAULT_ALLOWED_UIDS "0"
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
769347ad4d35d43488eb98f980143495b0db415dStef Walterstruct mon_cli_iface monitor_pac_methods = {
769347ad4d35d43488eb98f980143495b0db415dStef Walter { &mon_cli_iface_meta, 0 },
769347ad4d35d43488eb98f980143495b0db415dStef Walter .resInit = monitor_common_res_init,
769347ad4d35d43488eb98f980143495b0db415dStef Walter .goOffline = NULL,
769347ad4d35d43488eb98f980143495b0db415dStef Walter .resetOffline = NULL,
769347ad4d35d43488eb98f980143495b0db415dStef Walter .rotateLogs = responder_logrotate,
769347ad4d35d43488eb98f980143495b0db415dStef Walter .clearMemcache = NULL,
769347ad4d35d43488eb98f980143495b0db415dStef Walter .clearEnumCache = NULL,
b76419cf8830440b46c20a15585562343c7b1924Jakub Hrozek .sysbusReconnect = NULL,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose};
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose/* TODO: check if this can be made generic for all responders */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bosestatic void pac_dp_reconnect_init(struct sbus_connection *conn,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose int status, void *pvt)
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose{
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct be_conn *be_conn = talloc_get_type(pvt, struct be_conn);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose int ret;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* Did we reconnect successfully? */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (status == SBUS_RECONNECT_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Reconnected to the Data Provider.\n");
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* Identify ourselves to the data provider */
83a79d93035c2d75a1941f3b54426119174044a0Pavel Březina ret = rdp_register_client(be_conn, "PAC");
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* all fine */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret == EOK) {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose handle_requests_after_reconnect(be_conn->rctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose return;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* Failed to reconnect */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Could not reconnect to %s provider.\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov be_conn->domain->name);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
677a31351c80453d9ce006481364399a96312052René Genz /* FIXME: kill the frontend and let the monitor restart it? */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* nss_shutdown(rctx); */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose}
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Boseint pac_process_init(TALLOC_CTX *mem_ctx,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct tevent_context *ev,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct confdb_ctx *cdb)
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose{
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina struct resp_ctx *rctx;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct sss_cmd_table *pac_cmds;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct be_conn *iter;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct pac_ctx *pac_ctx;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose int ret, max_retries;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose enum idmap_error_code err;
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose int fd_limit;
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose char *uid_str;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose pac_cmds = get_pac_cmds();
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina ret = sss_process_init(mem_ctx, ev, cdb,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose pac_cmds,
8bccd95e275fae760a991da394235e4e70e57bbdMichal Zidek SSS_PAC_SOCKET_NAME, -1, NULL, -1,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose CONFDB_PAC_CONF_ENTRY,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose PAC_SBUS_SERVICE_NAME,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose PAC_SBUS_SERVICE_VERSION,
07e941c1bbdc752142bbd3b838c540bc7ecd0ed7Stef Walter &monitor_pac_methods,
04e870d99e72aa3160bdb6ab05d986fb4005c3edPavel Březina "PAC", NULL,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_connection_setup,
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina &rctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "sss_process_init() failed\n");
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina return ret;
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina }
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina pac_ctx = talloc_zero(rctx, struct pac_ctx);
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina if (!pac_ctx) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "fatal error initializing pac_ctx\n");
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina ret = ENOMEM;
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina pac_ctx->rctx = rctx;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose pac_ctx->rctx->pvt_ctx = pac_ctx;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose ret = confdb_get_string(pac_ctx->rctx->cdb, pac_ctx->rctx,
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose CONFDB_PAC_CONF_ENTRY, CONFDB_SERVICE_ALLOWED_UIDS,
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose DEFAULT_ALLOWED_UIDS, &uid_str);
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to get allowed UIDs.\n");
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose }
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose ret = csv_string_to_uid_array(pac_ctx->rctx, uid_str, true,
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose &pac_ctx->rctx->allowed_uids_count,
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose &pac_ctx->rctx->allowed_uids);
ed879c3bd70d4f65784e998b1f9420a9ebe434e4Jakub Hrozek talloc_free(uid_str);
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to set allowed UIDs.\n");
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose }
2d257ccf620ce1b611f89cec8f0a94c88c2f2881Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* Enable automatic reconnection to the Data Provider */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose ret = confdb_get_int(pac_ctx->rctx->cdb,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose CONFDB_PAC_CONF_ENTRY,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose CONFDB_SERVICE_RECON_RETRIES,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose 3, &max_retries);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Failed to set up automatic reconnection\n");
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose for (iter = pac_ctx->rctx->be_conns; iter; iter = iter->next) {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose sbus_reconnect_init(iter->conn, max_retries,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose pac_dp_reconnect_init, iter);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
a473fb88e6015cf0ccbd2e9005c7e6acca18f452Pavel Březina err = sss_idmap_init(sss_idmap_talloc, pac_ctx, sss_idmap_talloc_free,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose &pac_ctx->idmap_ctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (err != IDMAP_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "sss_idmap_init failed.\n");
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina ret = EFAULT;
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose /* Set up file descriptor limits */
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose ret = confdb_get_int(pac_ctx->rctx->cdb,
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose CONFDB_PAC_CONF_ENTRY,
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose CONFDB_SERVICE_FD_LIMIT,
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose DEFAULT_PAC_FD_LIMIT,
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose &fd_limit);
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose if (ret != EOK) {
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to set up file descriptor limit\n");
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina goto fail;
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose }
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose responder_set_fd_limit(fd_limit);
f1a7e4a6e4f2d453077da8b3606feebb7669ef4fSumit Bose
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose ret = confdb_get_int(pac_ctx->rctx->cdb, CONFDB_PAC_CONF_ENTRY,
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose CONFDB_PAC_LIFETIME, 300,
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose &pac_ctx->pac_lifetime);
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose if (ret != EOK) {
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose DEBUG(SSSDBG_FATAL_FAILURE,
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose "Failed to setup negative cache timeout.\n");
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose goto fail;
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose }
d0d7de66c9494621c1bc12384e41e5e38a77fbebSumit Bose
0528fdec17d0031996e919fcd852459e86592c35Jakub Hrozek ret = schedule_get_domains_task(rctx, rctx->ev, rctx, NULL);
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose goto fail;
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose }
909a86af4eb99f5d311d7136cab78dca535ae304Sumit Bose
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "PAC Initialization complete\n");
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose return EOK;
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březinafail:
7c9fe57ad82747a32721ca0a08c5569282f3e0c4Pavel Březina talloc_free(rctx);
6f8ae17869f4f8a1496e3f171ae6b5c11af1845cPavel Březina return ret;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose}
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Boseint main(int argc, const char *argv[])
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose{
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose int opt;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose poptContext pc;
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik char *opt_logger = NULL;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct main_context *main_ctx;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose int ret;
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek uid_t uid;
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek gid_t gid;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose struct poptOption long_options[] = {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose POPT_AUTOHELP
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose SSSD_MAIN_OPTS
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik SSSD_LOGGER_OPTS
ac40d2f2b2b2fc35c95389f5e28febd580bd2b7aJakub Hrozek SSSD_SERVER_OPTS(uid, gid)
e4093605339062548364d338c811431673bdfe25Fabiano Fidêncio SSSD_RESPONDER_OPTS
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose POPT_TABLEEND
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose };
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* Set debug level to invalid value so we can decide if -d 0 was used. */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose debug_level = SSSDBG_INVALID;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
458f5245dd5130d12666cce6faf8ef1ec7f80169Pavel Reichl umask(DFL_RSP_UMASK);
458f5245dd5130d12666cce6faf8ef1ec7f80169Pavel Reichl
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose pc = poptGetContext(argv[0], argc, argv, long_options, 0);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose while((opt = poptGetNextOpt(pc)) != -1) {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose switch(opt) {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose default:
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose fprintf(stderr, "\nInvalid option %s: %s\n\n",
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose poptBadOption(pc, 0), poptStrerror(opt));
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose poptPrintUsage(pc, stderr, 0);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose return 1;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose poptFreeContext(pc);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
9e2c64c6d4f5560e27207193efea6536a566865eMichal Zidek DEBUG_INIT(debug_level);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
677a31351c80453d9ce006481364399a96312052René Genz /* set up things like debug, signals, daemonization, etc. */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose debug_log_file = "sssd_pac";
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik sss_set_logger(opt_logger);
cb75b275d15beedd1fdecc1f8ced657fba282218Lukas Slebodnik
22f4bcbb211bf800af647ad1fc9595a8020a6fe6Jakub Hrozek ret = server_setup("sssd[pac]", 0, uid, gid,
22f4bcbb211bf800af647ad1fc9595a8020a6fe6Jakub Hrozek CONFDB_PAC_CONF_ENTRY, &main_ctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret != EOK) return 2;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose ret = die_if_parent_died();
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret != EOK) {
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* This is not fatal, don't return */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set up to exit when parent process does\n");
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose }
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose ret = pac_process_init(main_ctx,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose main_ctx->event_ctx,
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose main_ctx->confdb_ctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose if (ret != EOK) return 3;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose /* loop on main */
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose server_loop(main_ctx);
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose return 0;
b9e5bd09a5ff7009537a18914dbebcf10498f592Sumit Bose}