summaryrefslogtreecommitdiffstats
path: root/ldadp.c
diff options
context:
space:
mode:
authorSimon Rettberg2014-03-15 01:49:50 +0100
committerSimon Rettberg2014-03-15 01:49:50 +0100
commitbedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad (patch)
treec7d1995a09f6ed0c4e6873252e957d72f5d07d07 /ldadp.c
downloadldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.gz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.tar.xz
ldadp-bedd2e7ccb1595c23e159eaa952ae1b0b5a3d2ad.zip
Lean and mean initial commit
Not much functionality yet
Diffstat (limited to 'ldadp.c')
-rw-r--r--ldadp.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/ldadp.c b/ldadp.c
new file mode 100644
index 0000000..8afb3bd
--- /dev/null
+++ b/ldadp.c
@@ -0,0 +1,86 @@
+#include "types.h"
+#include "epoll.h"
+#include "client.h"
+#include "server.h"
+#include "proxy.h"
+#include "ini.h"
+#include "helper.h"
+#include <stdio.h>
+#include <socket.h>
+#include <io.h>
+#include <string.h>
+#include <stdlib.h>
+
+static void listen_callback(void *data, int haveIn, int haveOut, int doCleanup);
+static void loadConfig(char *file);
+
+int main(int argc, char **argv)
+{
+ if (argc < 2) {
+ printf("Nö\n");
+ exit(1);
+ }
+ loadConfig(argv[1]);
+ proxy_init();
+ char listen_addr[4] = {0, 0, 0, 0};
+ // Setup socket
+ epoll_listen_t lsn;
+ lsn.callback = &listen_callback;
+ lsn.fd = socket_tcp4();
+ if (lsn.fd == -1) bail("Could not create listen socket");
+ if (socket_bind4_reuse(lsn.fd, listen_addr, 1234) == -1) bail("Could not bind to listening port");
+ if (socket_listen(lsn.fd, 10) == -1) bail("Could not listen");
+ // Setup epoll
+ if (ePoll_init() == -1) bail("epoll_create failed");
+ // Add listener
+ if (ePoll_add(EPOLLIN, (epoll_item_t*)&lsn) == -1) bail("Could not add listen socket to epoll fd");
+ // Init AD uplinks
+ server_initServers();
+ // Do the mainloop
+ for (;;) {
+ if (ePoll_wait(-1) == -1) bail("ePoll wait failed.");
+ }
+ return 0;
+}
+
+static void listen_callback(void *data, int haveIn, int haveOut, int doCleanup)
+{
+ if (doCleanup) bail("doCleanup on Listen socket set.");
+ if (!haveIn) return;
+ epoll_listen_t *listen = (epoll_listen_t *)data;
+ char remote[4];
+ uint16 port;
+ int sock = socket_accept4(listen->fd, remote, &port);
+ if (sock < 0) {
+ printf("Error accepting new connection.\n");
+ return;
+ }
+ printf("Accepted connection.\n");
+ epoll_client_t *client = calloc(1, sizeof(epoll_client_t));
+ client->fd = sock;
+ client->callback = &client_callback;
+ ePoll_add(EPOLLIN | EPOLLOUT | EPOLLET, (epoll_item_t*)client);
+}
+
+static int loadConfig_handler(void *stuff, const char *section, const char *key, const char *value)
+{
+ if (strcmp(key, "binddn") == 0) {
+ server_setBind(section, value);
+ }
+ if (strcmp(key, "bindpw") == 0) {
+ server_setPassword(section, value);
+ }
+ if (strcmp(key, "base") == 0) {
+ server_setBase(section, value);
+ }
+ if (strcmp(key, "alias") == 0) {
+ server_setAlias(section, value);
+ }
+ return 1;
+}
+
+static void loadConfig(char *file)
+{
+ ini_parse(file, &loadConfig_handler, NULL);
+}
+