summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/Makefile.in2
-rw-r--r--server/configure.ac2
-rw-r--r--server/examples/config.ldif4
-rw-r--r--server/monitor.c65
-rw-r--r--server/nss/nsssrv.c43
-rw-r--r--server/providers/data_provider.c43
-rw-r--r--server/server.mk37
-rw-r--r--server/util/server.c140
-rw-r--r--server/util/util.h23
9 files changed, 223 insertions, 136 deletions
diff --git a/server/Makefile.in b/server/Makefile.in
index da220ddc3..4c989eefa 100644
--- a/server/Makefile.in
+++ b/server/Makefile.in
@@ -59,7 +59,7 @@ OBJS = $(SERVER_OBJ) @LIBREPLACEOBJ@ $(EXTRA_OBJ)
headers = .h
-BINS = sbin/sssd
+BINS = sbin/sssd sbin/sssd_nss sbin/sssd_dp
DIRS = sbin
diff --git a/server/configure.ac b/server/configure.ac
index 0862187d5..c65500d4c 100644
--- a/server/configure.ac
+++ b/server/configure.ac
@@ -12,7 +12,7 @@ AC_DEFUN([SMB_LIBRARY_ENABLE], [echo -n ""])
AC_DEFUN([SMB_EXT_LIB], [echo -n ""])
AC_DEFUN([SMB_ENABLE], [echo -n ""])
AC_INIT(ldb, 0.9.2)
-AC_CONFIG_SRCDIR([server.c])
+AC_CONFIG_SRCDIR([monitor.c])
AC_LIBREPLACE_ALL_CHECKS
diff --git a/server/examples/config.ldif b/server/examples/config.ldif
index c6518417e..59a2838c5 100644
--- a/server/examples/config.ldif
+++ b/server/examples/config.ldif
@@ -14,12 +14,12 @@ dn: cn=nss,cn=services,cn=config
cn: nss
description: NSS Responder Configuration
unixSocket: /var/lib/sss/pipes/nss
-command: /usr/sbin/sssd -s nss
+command: /usr/libexec/sssd/sssd_nss
dn: cn=dp,cn=services,cn=config
cn: dp
description: Data Provider Configuration
-command: /usr/sbin/sssd -s dp
+command: /usr/libexec/sssd/sssd_dp
dn: cn=monitor,cn=services,cn=config
cn: monitor
diff --git a/server/monitor.c b/server/monitor.c
index 5c2ec9921..fab88ff90 100644
--- a/server/monitor.c
+++ b/server/monitor.c
@@ -26,6 +26,7 @@
#include <sys/wait.h>
#include <sys/time.h>
#include <time.h>
+#include "popt.h"
#include "../events/events.h"
#include "util/util.h"
#include "confdb/confdb.h"
@@ -810,6 +811,68 @@ static int start_service(const char *name, const char *command, pid_t *retpid)
/* child */
args = parse_args(command);
- execvp("./sbin/sssd", args);
+ execvp(args[0], args);
exit(1);
}
+
+int main(int argc, const char *argv[])
+{
+ int opt;
+ poptContext pc;
+ int opt_daemon = 0;
+ int opt_interactive = 0;
+ int flags = 0;
+ struct main_context *main_ctx;
+ int ret;
+
+ struct poptOption long_options[] = {
+ POPT_AUTOHELP
+ SSSD_MAIN_OPTS
+ {"daemon", 'D', POPT_ARG_NONE, &opt_daemon, 0, \
+ "Become a daemon (default)", NULL }, \
+ {"interactive", 'i', POPT_ARG_NONE, &opt_interactive, 0, \
+ "Run interactive (not a daemon)", NULL}, \
+ { NULL }
+ };
+
+ 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;
+ }
+ }
+
+ if (opt_daemon && opt_interactive) {
+ fprintf(stderr, "Option -i|--interactive is not allowed together with -D|--daemon\n");
+ poptPrintUsage(pc, stderr, 0);
+ return 1;
+ }
+
+ poptFreeContext(pc);
+
+ if (opt_daemon) flags |= FLAGS_DAEMON;
+ if (opt_interactive) flags |= FLAGS_INTERACTIVE;
+
+ /* we want a pid file check */
+ flags |= FLAGS_PID_FILE;
+
+ /* set up things like debug , signals, daemonization, etc... */
+ ret = server_setup("sssd", flags, &main_ctx);
+ if (ret != EOK) return 2;
+
+ ret = monitor_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/server/nss/nsssrv.c b/server/nss/nsssrv.c
index ab1ef441d..ccbd7ba80 100644
--- a/server/nss/nsssrv.c
+++ b/server/nss/nsssrv.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <sys/time.h>
#include <errno.h>
+#include "popt.h"
#include "ldb.h"
#include "util/util.h"
#include "nss/nsssrv.h"
@@ -418,3 +419,45 @@ int nss_process_init(TALLOC_CTX *mem_ctx,
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
+ { NULL }
+ };
+
+ 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... */
+ ret = server_setup("sssd[nss]", 0, &main_ctx);
+ if (ret != EOK) return 2;
+
+ ret = nss_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/server/providers/data_provider.c b/server/providers/data_provider.c
index aacb09ef8..bfc37a7c3 100644
--- a/server/providers/data_provider.c
+++ b/server/providers/data_provider.c
@@ -29,6 +29,7 @@
#include <string.h>
#include <sys/time.h>
#include <errno.h>
+#include "popt.h"
#include "ldb.h"
#include "ldb_errors.h"
#include "util/util.h"
@@ -397,3 +398,45 @@ int dp_process_init(TALLOC_CTX *mem_ctx,
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
+ { NULL }
+ };
+
+ 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... */
+ ret = server_setup("sssd[dp]", 0, &main_ctx);
+ if (ret != EOK) return 2;
+
+ ret = dp_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/server/server.mk b/server/server.mk
index 655594366..480e58fe6 100644
--- a/server/server.mk
+++ b/server/server.mk
@@ -1,31 +1,36 @@
-SERVER_OBJ = \
- server.o \
- monitor.o \
- process.o \
+UTIL_OBJ = \
util/debug.o \
util/signal.o \
- util/become_daemon.o \
+ util/server.o \
util/memory.o \
util/btreemap.o \
util/service_helpers.o \
confdb/confdb.o \
- nss/nsssrv.o \
- nss/nsssrv_packet.o \
- nss/nsssrv_cmd.o \
- nss/nsssrv_ldb.o \
sbus/sssd_dbus_common.o \
sbus/sssd_dbus_connection.o \
- sbus/sssd_dbus_server.o \
+ sbus/sssd_dbus_server.o
+
+SERVER_OBJ = \
+ monitor.o
+
+DP_OBJ = \
providers/data_provider.o
-CLIENT_OBJ = \
- sbus/sssd_dbus_common.o \
- sbus/sssd_dbus_connection.o \
- util/debug.o
+NSSSRV_OBJ = \
+ nss/nsssrv.o \
+ nss/nsssrv_packet.o \
+ nss/nsssrv_cmd.o \
+ nss/nsssrv_ldb.o \
install:: all
${INSTALLCMD} -d $(DESTDIR)$(sbindir)
${INSTALLCMD} -m 755 sssd $(DESTDIR)$(sbindir)
-sbin/sssd: $(SERVER_OBJ)
- $(CC) -o sbin/sssd $(SERVER_OBJ) $(LDFLAGS) $(LIBS)
+sbin/sssd: $(SERVER_OBJ) $(UTIL_OBJ)
+ $(CC) -o sbin/sssd $(SERVER_OBJ) $(UTIL_OBJ) $(LDFLAGS) $(LIBS)
+
+sbin/sssd_nss: $(NSSSRV_OBJ) $(UTIL_OBJ)
+ $(CC) -o sbin/sssd_nss $(NSSSRV_OBJ) $(UTIL_OBJ) $(LDFLAGS) $(LIBS)
+
+sbin/sssd_dp: $(DP_OBJ) $(UTIL_OBJ)
+ $(CC) -o sbin/sssd_dp $(DP_OBJ) $(UTIL_OBJ) $(LDFLAGS) $(LIBS)
diff --git a/server/util/server.c b/server/util/server.c
index 45a6948ef..def44f038 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -23,6 +23,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
@@ -231,86 +232,17 @@ static void server_stdin_handler(struct event_context *event_ctx, struct fd_even
}
/*
- main server.
+ main server helpers.
*/
-int main(int argc, const char *argv[])
+int server_setup(const char *name, int flags,
+ struct main_context **main_ctx)
{
- char *service = NULL;
- bool opt_daemon = false;
- bool opt_interactive = false;
- int opt;
- poptContext pc;
struct event_context *event_ctx;
- struct confdb_ctx *confdb_ctx;
- TALLOC_CTX *mem_ctx;
+ struct main_context *ctx;
uint16_t stdin_event_flags;
int ret = EOK;
- bool is_monitor = false;
-
- debug_prg_name = argv[0];
-
- enum {
- OPT_DAEMON = 1000,
- OPT_INTERACTIVE
- };
- struct poptOption long_options[] = {
- POPT_AUTOHELP
- {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON,
- "Become a daemon (default)", NULL },
- {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE,
- "Run interactive (not a daemon)", NULL},
- {"service", 's', POPT_ARG_STRING, &service, 0,
- "Executes a specific service instead of the monitor", NULL},
- {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0,
- "Executes a specific service instead of the monitor", NULL},
- { NULL }
- };
-
- pc = poptGetContext(argv[0], argc, argv, long_options, 0);
- while((opt = poptGetNextOpt(pc)) != -1) {
- switch(opt) {
- case OPT_DAEMON:
- opt_daemon = true;
- break;
- case OPT_INTERACTIVE:
- opt_interactive = true;
- break;
- default:
- fprintf(stderr, "\nInvalid option %s: %s\n\n",
- poptBadOption(pc, 0), poptStrerror(opt));
- poptPrintUsage(pc, stderr, 0);
- return 1;
- }
- }
-
- if (!service) {
- fprintf(stderr,"\nERROR: No service specified\n\n");
- return 5;
- }
-
- if (strcmp(service, "monitor") == 0) is_monitor = true;
-
- if (is_monitor) {
- if (opt_daemon && opt_interactive) {
- fprintf(stderr,"\nERROR: "
- "Option -i|--interactive is not allowed together with -D|--daemon\n\n");
- poptPrintUsage(pc, stderr, 0);
- return 1;
- } else if (!opt_interactive) {
- /* default is --daemon */
- opt_daemon = true;
- }
- } else {
- if (opt_daemon || opt_interactive) {
- fprintf(stderr,"\nERROR: "
- "Options -i or -D not allowed with -s (service)\n\n");
- poptPrintUsage(pc, stderr, 0);
- return 1;
- }
-
- }
- poptFreeContext(pc);
+ debug_prg_name = name;
setup_signals();
@@ -318,14 +250,16 @@ int main(int argc, const char *argv[])
so set our umask to 0177 */
umask(0177);
- if (opt_daemon) {
+ if (flags & FLAGS_DAEMON) {
DEBUG(3,("Becoming a daemon.\n"));
become_daemon(true);
+ }
- ret = pidfile(PID_PATH, "sssd");
+ if (flags & FLAGS_PID_FILE) {
+ ret = pidfile(PID_PATH, name);
if (ret != EOK) {
- fprintf(stderr, "\nERROR: PID File reports daemon already running!\n");
- return 1;
+ DEBUG(0, ("ERROR: PID File reports daemon already running!\n"));
+ return EEXIST;
}
}
@@ -337,19 +271,21 @@ int main(int argc, const char *argv[])
return 1;
}
- mem_ctx = talloc_new(event_ctx);
- if (mem_ctx == NULL) {
+ ctx = talloc(event_ctx, struct main_context);
+ if (ctx == NULL) {
DEBUG(0,("Out of memory, aborting!\n"));
- return 1;
+ return ENOMEM;
}
- ret = confdb_init(mem_ctx, event_ctx, &confdb_ctx);
+ ctx->event_ctx = event_ctx;
+
+ ret = confdb_init(ctx, event_ctx, &ctx->confdb_ctx);
if (ret != EOK) {
DEBUG(0,("The confdb initialization failed\n"));
- return 1;
+ return ret;
}
- if (opt_interactive) {
+ if (flags & FLAGS_INTERACTIVE) {
/* terminate when stdin goes away */
stdin_event_flags = EVENT_FD_READ;
} else {
@@ -362,39 +298,19 @@ int main(int argc, const char *argv[])
signal(SIGTTIN, SIG_IGN);
#endif
event_add_fd(event_ctx, event_ctx, 0, stdin_event_flags,
- server_stdin_handler,
- discard_const(argv[0]));
-
- /* What are we asked to run ? */
- if (is_monitor) {
- /* the monitor */
- ret = monitor_process_init(mem_ctx, event_ctx, confdb_ctx);
-
- } else {
-
- if (strcmp(service, "nss") == 0) {
- ret = nss_process_init(mem_ctx, event_ctx, confdb_ctx);
-
- } else if (strcmp(service, "dp") == 0) {
- ret = dp_process_init(mem_ctx, event_ctx, confdb_ctx);
+ server_stdin_handler, discard_const(name));
- } else {
- fprintf(stderr,
- "\nERROR: Unknown Service specified [%s]\n",
- service);
- ret = EINVAL;
- }
- }
-
- if (ret != EOK) return 3;
+ *main_ctx = ctx;
+ return EOK;
+}
+void server_loop(struct main_context *main_ctx)
+{
/* wait for events - this is where smbd sits for most of its
life */
- event_loop_wait(event_ctx);
+ event_loop_wait(main_ctx->event_ctx);
/* as everything hangs off this event context, freeing it
should initiate a clean shutdown of all services */
- talloc_free(event_ctx);
-
- return 0;
+ talloc_free(main_ctx->event_ctx);
}
diff --git a/server/util/util.h b/server/util/util.h
index 6e30cfd28..1c3fa2e77 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -10,6 +10,10 @@ extern const char *debug_prg_name;
extern int debug_level;
void debug_fn(const char *format, ...);
+#define SSSD_DEBUG_OPTS \
+ {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \
+ "Debug level", NULL},
+
#define DEBUG(level, body) do { \
if (level <= debug_level) { \
debug_fn("[%s] [%s] (%d): ", \
@@ -30,11 +34,24 @@ void debug_fn(const char *format, ...);
#define EOK 0
+#define SSSD_MAIN_OPTS SSSD_DEBUG_OPTS
+
+#define FLAGS_NONE 0x0000
+#define FLAGS_DAEMON 0x0001
+#define FLAGS_INTERACTIVE 0x0002
+#define FLAGS_PID_FILE 0x0004
+
+struct main_context {
+ struct event_context *event_ctx;
+ struct confdb_ctx *confdb_ctx;
+};
+
#include "util/dlinklist.h"
-/* from become_daemon.c */
-void become_daemon(bool Fork);
-int pidfile(const char *path, const char *name);
+/* from server.c */
+int server_setup(const char *name, int flags,
+ struct main_context **main_ctx);
+void server_loop(struct main_context *main_ctx);
/* from signal.c */
#include <signal.h>