summaryrefslogtreecommitdiffstats
path: root/ldadp.c
diff options
context:
space:
mode:
authorSimon Rettberg2018-11-14 14:37:31 +0100
committerSimon Rettberg2018-11-14 14:37:31 +0100
commit8b8ed36516e9a40df6ac9ac46ab355fee0e5b5f0 (patch)
treeb0267df71f0807319e7e80cf18a27dde1382cc90 /ldadp.c
parentStarted work on proxy-side uid generation/tracking (diff)
downloadldadp-8b8ed36516e9a40df6ac9ac46ab355fee0e5b5f0.tar.gz
ldadp-8b8ed36516e9a40df6ac9ac46ab355fee0e5b5f0.tar.xz
ldadp-8b8ed36516e9a40df6ac9ac46ab355fee0e5b5f0.zip
Support generating uidNumbers on proxy
Diffstat (limited to 'ldadp.c')
-rw-r--r--ldadp.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/ldadp.c b/ldadp.c
index bc5cdf9..c203362 100644
--- a/ldadp.c
+++ b/ldadp.c
@@ -20,16 +20,25 @@
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
+#include <time.h>
+
+#define SAVE_INTERVAL_SEC (1200)
static void listen_callback(void *data, int haveIn, int haveOut, int doCleanup);
static BOOL loadConfig(char *file);
static int localPort = 1234;
static char *certFile = NULL, *keyFile = NULL;
+static BOOL keepRunning = TRUE;
+
+static void sigTerm(int sn)
+{
+ keepRunning = FALSE;
+}
int main(int argc, char **argv)
{
- BOOL isdaemon = TRUE;
+ BOOL isdaemon = TRUE, useUidMapping;
printf("Starting up ldadp %s\n", LDADP_VERSION);
printf("Commit: %s\n", LDADP_COMMIT);
printf("Commit time: %s\n", LDADP_COMMITTIME);
@@ -42,6 +51,11 @@ int main(int argc, char **argv)
}
setbuf(stdout, NULL);
signal(SIGPIPE, SIG_IGN);
+ struct sigaction sact;
+ memset(&sact, 0, sizeof(sact));
+ sact.sa_handler = sigTerm;
+ sigaction(SIGTERM, &sact, NULL);
+ sigaction(SIGINT, &sact, NULL);
if (strcmp(argv[1], "-n") == 0 && argc > 2) {
isdaemon = FALSE;
argv++;
@@ -49,6 +63,7 @@ int main(int argc, char **argv)
}
if (!loadConfig(argv[1])) bail("Cannot read config file %s", argv[1]);
if (localPort < 1 || localPort > 65535) bail("Invalid port given in config");
+ useUidMapping = server_initUidMaps();
proxy_init();
char listen_addr[4] = {0, 0, 0, 0};
// Setup socket
@@ -76,9 +91,21 @@ int main(int argc, char **argv)
// Daeaeaemon
if (isdaemon && daemon(1, 0) == -1) bail("daemon() failed.");
// Do the mainloop
- for (;;) {
+ struct timespec last, now;
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ last = now;
+ while (keepRunning) {
if (ePoll_wait(-1) == -1) bail("ePoll wait failed.");
+ if (useUidMapping) {
+ clock_gettime(CLOCK_MONOTONIC, &now);
+ if ((uint64_t)now.tv_sec - (uint64_t)last.tv_sec > SAVE_INTERVAL_SEC) { // Signed overflow not a good idea in C
+ last = now;
+ server_saveUidMaps();
+ }
+ }
}
+ plog(DEBUG_FATAL, "Shutting down...");
+ server_saveUidMaps();
return 0;
}
@@ -152,10 +179,14 @@ static int loadConfig_handler(void *stuff, const char *section, const char *key,
server_setPlainLdap(section, value);
} else if (strcmp(key, "fixnumeric") == 0) {
server_setFixNumeric(section, value);
+ } else if (strcmp(key, "uidmapstore") == 0) {
+ server_setUidMapStore(section, value);
+ } else if (strcmp(key, "genuidnumber") == 0) {
+ server_setGenUidNumber(section, value);
} else if (strncmp(key, "map.", 4) == 0) {
server_setMap(section, key+4, value);
} else {
- printf("Unknown ADS config option '%s' for server '%s'\n", key, section);
+ plog(DEBUG_WARNING, "WARNING: Unknown ADS config option '%s' for server '%s'\n", key, section);
}
}
return 1;