From 9eeb6e2f63fe5fe529e719829c6cc835445ac7b8 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Tue, 19 Apr 2011 15:49:01 +0200 Subject: [PATCH 2/6] Add infrastructure for pac responder --- Makefile.am | 20 ++++ src/confdb/confdb.h | 3 + src/monitor/monitor.c | 2 +- src/responder/pac/pacsrv.c | 205 ++++++++++++++++++++++++++++++++++++++++ src/responder/pac/pacsrv.h | 51 ++++++++++ src/responder/pac/pacsrv_cmd.c | 60 ++++++++++++ 6 files changed, 340 insertions(+), 1 deletions(-) create mode 100644 src/responder/pac/pacsrv.c create mode 100644 src/responder/pac/pacsrv.h create mode 100644 src/responder/pac/pacsrv_cmd.c diff --git a/Makefile.am b/Makefile.am index b8423ba..ec011b2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,10 @@ sssdlibexec_PROGRAMS = \ ldap_child \ proxy_child +if BUILD_PAC_RESPONDER + sssdlibexec_PROGRAMS += sssd_pac +endif + if HAVE_CHECK non_interactive_check_based_tests = \ sysdb-tests \ @@ -190,6 +194,7 @@ AM_CPPFLAGS = \ -DSSSD_CONF_DIR=\"$(sssdconfdir)\" \ -DSSS_NSS_SOCKET_NAME=\"$(pipepath)/nss\" \ -DSSS_PAM_SOCKET_NAME=\"$(pipepath)/pam\" \ + -DSSS_PAC_SOCKET_NAME=\"$(pipepath)/pac\" \ -DSSS_PAM_PRIV_SOCKET_NAME=\"$(pipepath)/private/pam\" \ -DLOCALEDIR=\"$(localedir)\" @@ -288,6 +293,7 @@ dist_noinst_HEADERS = \ src/responder/nss/nsssrv.h \ src/responder/nss/nsssrv_private.h \ src/responder/nss/nsssrv_netgroup.h \ + src/responder/pac/pacsrv.h \ src/responder/common/negcache.h \ src/sbus/sbus_client.h \ src/sbus/sssd_dbus.h \ @@ -398,6 +404,20 @@ sssd_pam_LDADD = \ $(SSSD_LIBS) \ libsss_util.la +sssd_pac_SOURCES = \ + src/responder/pac/pacsrv.c \ + src/responder/pac/pacsrv_cmd.c \ + $(SSSD_UTIL_OBJ) \ + $(SSSD_RESPONDER_OBJ) +sssd_pac_CFLAGS = \ + $(AM_CFLAGS) \ + $(NDR_KRB5PAC_CFLAGS) +sssd_pac_LDADD = \ + $(NDR_KRB5PAC_LIBS) \ + $(TDB_LIBS) \ + $(SSSD_LIBS) \ + libsss_util.la + sssd_be_SOURCES = \ src/providers/data_provider_be.c \ src/providers/data_provider_fo.c \ diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h index c2ae9fc..4f75af8 100644 --- a/src/confdb/confdb.h +++ b/src/confdb/confdb.h @@ -88,6 +88,9 @@ #define CONFDB_PAM_ID_TIMEOUT "pam_id_timeout" #define CONFDB_PAM_PWD_EXPIRATION_WARNING "pam_pwd_expiration_warning" +/* PAC */ +#define CONFDB_PAC_CONF_ENTRY "config/pac" + /* Data Provider */ #define CONFDB_DP_CONF_ENTRY "config/dp" diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c index d1f2e66..bb47a53 100644 --- a/src/monitor/monitor.c +++ b/src/monitor/monitor.c @@ -818,7 +818,7 @@ static int check_local_domain_unique(struct sss_domain_info *domains) static char *check_services(char **services) { - const char *known_services[] = { "nss", "pam", NULL }; + const char *known_services[] = { "nss", "pam", "pac", NULL }; int i; int ii; diff --git a/src/responder/pac/pacsrv.c b/src/responder/pac/pacsrv.c new file mode 100644 index 0000000..d308665 --- /dev/null +++ b/src/responder/pac/pacsrv.c @@ -0,0 +1,205 @@ +/* + SSSD + + PAC Responder + + Copyright (C) Sumit Bose 2011 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "popt.h" +#include "util/util.h" +#include "responder/pac/pacsrv.h" +#include "db/sysdb.h" +#include "confdb/confdb.h" +#include "dbus/dbus.h" +#include "sbus/sssd_dbus.h" +#include "responder/common/responder_packet.h" +#include "responder/common/responder.h" +#include "providers/data_provider.h" +#include "monitor/monitor_interfaces.h" +#include "sbus/sbus_client.h" + +#define SSS_PAC_PIPE_NAME "pac" + +struct sbus_method monitor_pac_methods[] = { + { MON_CLI_METHOD_PING, monitor_common_pong }, + { MON_CLI_METHOD_RES_INIT, monitor_common_res_init }, + { MON_CLI_METHOD_ROTATE, monitor_common_rotate_logs }, + { NULL, NULL } +}; + +struct sbus_interface monitor_pac_interface = { + MONITOR_INTERFACE, + MONITOR_PATH, + SBUS_DEFAULT_VTABLE, + monitor_pac_methods, + NULL +}; + +static struct sbus_method pac_dp_methods[] = { + { NULL, NULL } +}; + +struct sbus_interface pac_dp_interface = { + DP_INTERFACE, + DP_PATH, + SBUS_DEFAULT_VTABLE, + pac_dp_methods, + NULL +}; + + +/* TODO: check if this can be made generic for all responders */ +static void pac_dp_reconnect_init(struct sbus_connection *conn, + int status, void *pvt) +{ + struct be_conn *be_conn = talloc_get_type(pvt, struct be_conn); + int ret; + + /* Did we reconnect successfully? */ + if (status == SBUS_RECONNECT_SUCCESS) { + DEBUG(1, ("Reconnected to the Data Provider.\n")); + + /* Identify ourselves to the data provider */ + ret = dp_common_send_id(be_conn->conn, + DATA_PROVIDER_VERSION, + "PAC"); + /* all fine */ + if (ret == EOK) { + handle_requests_after_reconnect(); + return; + } + } + + /* Failed to reconnect */ + DEBUG(0, ("Could not reconnect to %s provider.\n", + be_conn->domain->name)); + + /* FIXME: kill the frontend and let the monitor restart it ? */ + /* nss_shutdown(rctx); */ +} + +int pac_process_init(TALLOC_CTX *mem_ctx, + struct tevent_context *ev, + struct confdb_ctx *cdb) +{ + struct sss_cmd_table *pac_cmds; + struct be_conn *iter; + struct pac_ctx *pac_ctx; + int ret, max_retries; + + pac_ctx = talloc_zero(mem_ctx, struct pac_ctx); + if (!pac_ctx) { + DEBUG(0, ("fatal error initializing pac_ctx\n")); + return ENOMEM; + } + + pac_cmds = get_pac_cmds(); + + ret = sss_process_init(pac_ctx, ev, cdb, + pac_cmds, + SSS_PAC_SOCKET_NAME, NULL, + CONFDB_PAC_CONF_ENTRY, + PAC_SBUS_SERVICE_NAME, + PAC_SBUS_SERVICE_VERSION, + &monitor_pac_interface, + "PAC", &pac_dp_interface, + &pac_ctx->rctx); + if (ret != EOK) { + return ret; + } + pac_ctx->rctx->pvt_ctx = pac_ctx; + + /* Enable automatic reconnection to the Data Provider */ + ret = confdb_get_int(pac_ctx->rctx->cdb, pac_ctx->rctx, + CONFDB_PAC_CONF_ENTRY, + CONFDB_SERVICE_RECON_RETRIES, + 3, &max_retries); + if (ret != EOK) { + DEBUG(0, ("Failed to set up automatic reconnection\n")); + return ret; + } + + for (iter = pac_ctx->rctx->be_conns; iter; iter = iter->next) { + sbus_reconnect_init(iter->conn, max_retries, + pac_dp_reconnect_init, iter); + } + + DEBUG(1, ("PAC Initialization complete\n")); + + return EOK; +} + +int main(int argc, const char *argv[]) +{ + int opt; + poptContext pc; + struct main_context *main_ctx; + int ret; + + struct poptOption long_options[] = { + POPT_AUTOHELP + SSSD_MAIN_OPTS + POPT_TABLEEND + }; + + pc = poptGetContext(argv[0], argc, argv, long_options, 0); + while((opt = poptGetNextOpt(pc)) != -1) { + switch(opt) { + default: + fprintf(stderr, "\nInvalid option %s: %s\n\n", + poptBadOption(pc, 0), poptStrerror(opt)); + poptPrintUsage(pc, stderr, 0); + return 1; + } + } + + poptFreeContext(pc); + + /* set up things like debug, signals, daemonization, etc... */ + debug_log_file = "sssd_pac"; + + ret = server_setup("sssd[pac]", 0, CONFDB_PAC_CONF_ENTRY, &main_ctx); + if (ret != EOK) return 2; + + ret = die_if_parent_died(); + if (ret != EOK) { + /* This is not fatal, don't return */ + DEBUG(2, ("Could not set up to exit when parent process does\n")); + } + + ret = pac_process_init(main_ctx, + main_ctx->event_ctx, + main_ctx->confdb_ctx); + if (ret != EOK) return 3; + + /* loop on main */ + server_loop(main_ctx); + + return 0; +} + diff --git a/src/responder/pac/pacsrv.h b/src/responder/pac/pacsrv.h new file mode 100644 index 0000000..1b28254 --- /dev/null +++ b/src/responder/pac/pacsrv.h @@ -0,0 +1,51 @@ +/* + SSSD + + PAC Responder, header file + + Copyright (C) Sumit Bose 2011 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef __PACSRV_H__ +#define __PACSRV_H__ + +#include +#include +#include "config.h" +#include "talloc.h" +#include "tevent.h" +#include "ldb.h" +#include "dbus/dbus.h" +#include "sbus/sssd_dbus.h" +#include "responder/common/responder_packet.h" +#include "responder/common/responder.h" + +#define PAC_SBUS_SERVICE_VERSION 0x0001 +#define PAC_SBUS_SERVICE_NAME "pac" + +#define PAC_PACKET_MAX_RECV_SIZE 1024 + +struct getent_ctx; + +struct pac_ctx { + struct resp_ctx *rctx; +}; + +int pac_cmd_execute(struct cli_ctx *cctx); + +struct sss_cmd_table *get_pac_cmds(void); + +#endif /* __PACSRV_H__ */ diff --git a/src/responder/pac/pacsrv_cmd.c b/src/responder/pac/pacsrv_cmd.c new file mode 100644 index 0000000..42ff3f8 --- /dev/null +++ b/src/responder/pac/pacsrv_cmd.c @@ -0,0 +1,60 @@ +/* + SSSD + + PAC Responder + + Copyright (C) Sumit Bose 2011 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "util/util.h" +#include "responder/pac/pacsrv.h" +#include "confdb/confdb.h" +#include "db/sysdb.h" + +struct cli_protocol_version *register_cli_protocol_version(void) +{ + static struct cli_protocol_version pac_cli_protocol_version[] = { + {1, "2011-04-12", "initial version"}, + {0, NULL, NULL} + }; + + return pac_cli_protocol_version; +} + +static struct sss_cmd_table pac_cmds[] = { + {SSS_GET_VERSION, sss_cmd_get_version}, + {SSS_CLI_NULL, NULL} +}; + +struct sss_cmd_table *get_pac_cmds(void) { + return pac_cmds; +} + +int pac_cmd_execute(struct cli_ctx *cctx) +{ + enum sss_cli_command cmd; + int i; + + cmd = sss_packet_get_cmd(cctx->creq->in); + + for (i = 0; pac_cmds[i].cmd != SSS_CLI_NULL; i++) { + if (cmd == pac_cmds[i].cmd) { + return pac_cmds[i].fn(cctx); + } + } + + return EINVAL; +} -- 1.7.5.2