pamsrv.c revision 07e941c1bbdc752142bbd3b838c540bc7ecd0ed7
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch/*
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen SSSD
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen PAM Responder
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen
76a99afe0914951d20d96e0bf5e6d8d3ea3fd503Timo Sirainen Copyright (C) Simo Sorce <ssorce@redhat.com> 2009
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen Copyright (C) Sumit Bose <sbose@redhat.com> 2009
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen
76a99afe0914951d20d96e0bf5e6d8d3ea3fd503Timo Sirainen This program is free software; you can redistribute it and/or modify
596ec384269cad3b0f0661df89b9cf33cbd171b7Timo Sirainen it under the terms of the GNU General Public License as published by
666286d8ecc6c450b2232dcc628f79454215acfcTimo Sirainen the Free Software Foundation; either version 3 of the License, or
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen (at your option) any later version.
b039dabf4c53f72454e795930e7643b6e0e625f9Timo Sirainen
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen This program is distributed in the hope that it will be useful,
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
fa3fc0b4c821874ccc56a1512604f661b411d3a4Aki Tuomi MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa3fc0b4c821874ccc56a1512604f661b411d3a4Aki Tuomi GNU General Public License for more details.
94e1adead9faddec88a623485b9999a87b1684faTimo Sirainen
503e5ef896c7b4a51cf73efb0d132860a8c747e6Timo Sirainen You should have received a copy of the GNU General Public License
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
cb2b5a7d6e7e651191bf9ee1eda94a6e207288b0Timo Sirainen*/
cb2b5a7d6e7e651191bf9ee1eda94a6e207288b0Timo Sirainen
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen#include <stdio.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <unistd.h>
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen#include <fcntl.h>
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen#include <sys/types.h>
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen#include <sys/stat.h>
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen#include <sys/socket.h>
55639052253ff28c6a0f569ae76dfda33e02c5f2Timo Sirainen#include <sys/un.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <string.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <sys/time.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <errno.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <popt.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen#include <dbus/dbus.h>
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen#include "util/util.h"
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen#include "db/sysdb.h"
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen#include "confdb/confdb.h"
c4db1218645ed8ec8b5ae67c05bc5d7a80c1b8aeTimo Sirainen#include "sbus/sssd_dbus.h"
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen#include "responder/common/responder_packet.h"
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen#include "providers/data_provider.h"
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen#include "monitor/monitor_interfaces.h"
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen#include "sbus/sbus_client.h"
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen#include "responder/pam/pamsrv.h"
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen#include "responder/common/negcache.h"
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen#include "responder/common/responder_sbus.h"
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen#define DEFAULT_PAM_FD_LIMIT 8192
c4db1218645ed8ec8b5ae67c05bc5d7a80c1b8aeTimo Sirainen
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainenstruct mon_cli_iface monitor_pam_methods = {
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen { &mon_cli_iface_meta, 0 },
cb951d3282610a9a0960230865bc5f3e3347b203Timo Sirainen .ping = monitor_common_pong,
a35cbba04d0a2823da98e693bd09a051addffdb2Timo Sirainen .resInit = monitor_common_res_init,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen .shutDown = NULL,
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen .goOffline = NULL,
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen .resetOffline = NULL,
cfeebb6dde3a3140972797c610ae78cc25c0b36cTimo Sirainen .rotateLogs = responder_logrotate,
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen .clearMemcache = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .clearEnumCache = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen};
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainenstatic struct data_provider_iface pam_dp_methods = {
4316355ca8b7698516272520a972291378698140Timo Sirainen { &data_provider_iface_meta, 0 },
4316355ca8b7698516272520a972291378698140Timo Sirainen .RegisterService = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .pamHandler = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .sudoHandler = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .autofsHandler = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .hostHandler = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .getDomains = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen .getAccountInfo = NULL,
4316355ca8b7698516272520a972291378698140Timo Sirainen};
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainenstatic void pam_dp_reconnect_init(struct sbus_connection *conn, int status, void *pvt)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen{
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct be_conn *be_conn = talloc_get_type(pvt, struct be_conn);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen int ret;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Did we reconnect successfully? */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen if (status == SBUS_RECONNECT_SUCCESS) {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, "Reconnected to the Data Provider.\n");
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Identify ourselves to the data provider */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen ret = dp_common_send_id(be_conn->conn,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen DATA_PROVIDER_VERSION,
4316355ca8b7698516272520a972291378698140Timo Sirainen "PAM");
4316355ca8b7698516272520a972291378698140Timo Sirainen /* all fine */
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret == EOK) {
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen handle_requests_after_reconnect(be_conn->rctx);
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen return;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen }
4316355ca8b7698516272520a972291378698140Timo Sirainen }
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* Handle failure */
4316355ca8b7698516272520a972291378698140Timo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "Could not reconnect to %s provider.\n",
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen be_conn->domain->name);
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen /* FIXME: kill the frontend and let the monitor restart it ? */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen /* pam_shutdown(rctx); */
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen}
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainenstatic int pam_process_init(TALLOC_CTX *mem_ctx,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct tevent_context *ev,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct confdb_ctx *cdb)
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen{
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct resp_ctx *rctx;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct sss_cmd_table *pam_cmds;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct be_conn *iter;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen struct pam_ctx *pctx;
4316355ca8b7698516272520a972291378698140Timo Sirainen int ret, max_retries;
4316355ca8b7698516272520a972291378698140Timo Sirainen int id_timeout;
4316355ca8b7698516272520a972291378698140Timo Sirainen int fd_limit;
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen pam_cmds = get_pam_cmds();
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen ret = sss_process_init(mem_ctx, ev, cdb,
4316355ca8b7698516272520a972291378698140Timo Sirainen pam_cmds,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen SSS_PAM_SOCKET_NAME,
0df9428baed48afaff90b4d4f03792d2fd756a43Timo Sirainen SSS_PAM_PRIV_SOCKET_NAME,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen CONFDB_PAM_CONF_ENTRY,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen SSS_PAM_SBUS_SERVICE_NAME,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen SSS_PAM_SBUS_SERVICE_VERSION,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen &monitor_pam_methods,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen "PAM", &pam_dp_methods.vtable,
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen &rctx);
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen if (ret != EOK) {
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "sss_process_init() failed\n");
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen return ret;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen }
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen pctx = talloc_zero(rctx, struct pam_ctx);
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen if (!pctx) {
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen ret = ENOMEM;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen goto done;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen }
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen pctx->rctx = rctx;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen pctx->rctx->pvt_ctx = pctx;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen /* Enable automatic reconnection to the Data Provider */
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen /* FIXME: "retries" is too generic, either get it from a global config
4316355ca8b7698516272520a972291378698140Timo Sirainen * or specify these retries are about the sbus connections to DP */
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen ret = confdb_get_int(pctx->rctx->cdb, CONFDB_PAM_CONF_ENTRY,
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen CONFDB_SERVICE_RECON_RETRIES, 3, &max_retries);
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen if (ret != EOK) {
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen DEBUG(SSSDBG_FATAL_FAILURE,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen "Failed to set up automatic reconnection\n");
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen goto done;
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen for (iter = pctx->rctx->be_conns; iter; iter = iter->next) {
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen sbus_reconnect_init(iter->conn, max_retries,
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen pam_dp_reconnect_init, iter);
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen }
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen /* Set up the negative cache */
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen ret = confdb_get_int(cdb, CONFDB_NSS_CONF_ENTRY,
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen CONFDB_NSS_ENTRY_NEG_TIMEOUT, 15,
d9b8c65d0a0ffc709ba7d23c449dbf2f46b10674Timo Sirainen &pctx->neg_timeout);
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) goto done;
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen /* Set up the PAM identity timeout */
d9b8c65d0a0ffc709ba7d23c449dbf2f46b10674Timo Sirainen ret = confdb_get_int(cdb, CONFDB_PAM_CONF_ENTRY,
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen CONFDB_PAM_ID_TIMEOUT, 5,
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen &id_timeout);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen if (ret != EOK) goto done;
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen pctx->id_timeout = (size_t)id_timeout;
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen ret = sss_ncache_init(pctx, &pctx->ncache);
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen if (ret != EOK) {
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen DEBUG(SSSDBG_FATAL_FAILURE,
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen "fatal error initializing negative cache\n");
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen goto done;
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen }
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen ret = sss_ncache_prepopulate(pctx->ncache, cdb, pctx->rctx);
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen if (ret != EOK) {
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen goto done;
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen }
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen /* Create table for initgroup lookups */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen ret = sss_hash_create(pctx, 10, &pctx->id_table);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen if (ret != EOK) {
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen DEBUG(SSSDBG_FATAL_FAILURE,
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk "Could not create initgroups hash table: [%s]",
e5acc283bf030b0b5c79ca4e52d315c516a299faPascal Volk strerror(ret));
e3077468777f5d324224365e34d7bbc449168e52Timo Sirainen goto done;
e3077468777f5d324224365e34d7bbc449168e52Timo Sirainen }
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen /* Set up file descriptor limits */
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen ret = confdb_get_int(pctx->rctx->cdb,
4316355ca8b7698516272520a972291378698140Timo Sirainen CONFDB_PAM_CONF_ENTRY,
4316355ca8b7698516272520a972291378698140Timo Sirainen CONFDB_SERVICE_FD_LIMIT,
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen DEFAULT_PAM_FD_LIMIT,
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen &fd_limit);
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) {
4316355ca8b7698516272520a972291378698140Timo Sirainen DEBUG(SSSDBG_FATAL_FAILURE,
4316355ca8b7698516272520a972291378698140Timo Sirainen "Failed to set up file descriptor limit\n");
4316355ca8b7698516272520a972291378698140Timo Sirainen goto done;
4316355ca8b7698516272520a972291378698140Timo Sirainen }
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen responder_set_fd_limit(fd_limit);
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen ret = schedule_get_domains_task(rctx, rctx->ev, rctx);
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) {
666286d8ecc6c450b2232dcc628f79454215acfcTimo Sirainen DEBUG(SSSDBG_FATAL_FAILURE, "schedule_get_domains_tasks failed.\n");
4316355ca8b7698516272520a972291378698140Timo Sirainen goto done;
4316355ca8b7698516272520a972291378698140Timo Sirainen }
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen ret = EOK;
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainendone:
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen if (ret != EOK) {
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen talloc_free(rctx);
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen }
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen return ret;
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen}
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainenint main(int argc, const char *argv[])
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen{
4316355ca8b7698516272520a972291378698140Timo Sirainen int opt;
4316355ca8b7698516272520a972291378698140Timo Sirainen poptContext pc;
4316355ca8b7698516272520a972291378698140Timo Sirainen struct main_context *main_ctx;
4316355ca8b7698516272520a972291378698140Timo Sirainen int ret;
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen struct poptOption long_options[] = {
4316355ca8b7698516272520a972291378698140Timo Sirainen POPT_AUTOHELP
4316355ca8b7698516272520a972291378698140Timo Sirainen SSSD_MAIN_OPTS
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen POPT_TABLEEND
4316355ca8b7698516272520a972291378698140Timo Sirainen };
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen /* Set debug level to invalid value so we can deside if -d 0 was used. */
4316355ca8b7698516272520a972291378698140Timo Sirainen debug_level = SSSDBG_INVALID;
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen pc = poptGetContext(argv[0], argc, argv, long_options, 0);
4316355ca8b7698516272520a972291378698140Timo Sirainen while((opt = poptGetNextOpt(pc)) != -1) {
4316355ca8b7698516272520a972291378698140Timo Sirainen switch(opt) {
4316355ca8b7698516272520a972291378698140Timo Sirainen default:
4316355ca8b7698516272520a972291378698140Timo Sirainen fprintf(stderr, "\nInvalid option %s: %s\n\n",
4316355ca8b7698516272520a972291378698140Timo Sirainen poptBadOption(pc, 0), poptStrerror(opt));
4316355ca8b7698516272520a972291378698140Timo Sirainen poptPrintUsage(pc, stderr, 0);
4316355ca8b7698516272520a972291378698140Timo Sirainen return 1;
93f1642397e46497894e6695749e5c52fda61774Timo Sirainen }
4316355ca8b7698516272520a972291378698140Timo Sirainen }
4316355ca8b7698516272520a972291378698140Timo Sirainen
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen poptFreeContext(pc);
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen DEBUG_INIT(debug_level);
4316355ca8b7698516272520a972291378698140Timo Sirainen
3cfc375f0d939c346b9b0e6f0ac78b9bc367dd95Timo Sirainen /* set up things like debug, signals, daemonization, etc... */
4316355ca8b7698516272520a972291378698140Timo Sirainen debug_log_file = "sssd_pam";
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen ret = server_setup("sssd[pam]", 0, CONFDB_PAM_CONF_ENTRY, &main_ctx);
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) return 2;
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen ret = die_if_parent_died();
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) {
4316355ca8b7698516272520a972291378698140Timo Sirainen /* This is not fatal, don't return */
4316355ca8b7698516272520a972291378698140Timo Sirainen DEBUG(SSSDBG_OP_FAILURE,
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen "Could not set up to exit when parent process does\n");
e34d170f8f0e084bd94bfbc1a7085ece67e508dfTimo Sirainen }
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen ret = pam_process_init(main_ctx,
4316355ca8b7698516272520a972291378698140Timo Sirainen main_ctx->event_ctx,
4316355ca8b7698516272520a972291378698140Timo Sirainen main_ctx->confdb_ctx);
4316355ca8b7698516272520a972291378698140Timo Sirainen if (ret != EOK) return 3;
b8a4aab1f117f6760184ad50b1af41ba810b51f9Timo Sirainen
b8a4aab1f117f6760184ad50b1af41ba810b51f9Timo Sirainen /* loop on main */
4316355ca8b7698516272520a972291378698140Timo Sirainen server_loop(main_ctx);
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen return 0;
4316355ca8b7698516272520a972291378698140Timo Sirainen}
4316355ca8b7698516272520a972291378698140Timo Sirainen
4316355ca8b7698516272520a972291378698140Timo Sirainen