summaryrefslogtreecommitdiffstats
path: root/daemons
diff options
context:
space:
mode:
authorSimo Sorce <ssorce@redhat.com>2011-11-14 17:38:53 -0500
committerSimo Sorce <ssorce@redhat.com>2011-11-21 18:52:59 -0500
commitd709dcf8f5d9e311b6703cd444ff220809eeff7a (patch)
tree0caac5fedeb6b7502999b765dbf720f36b0ad7a3 /daemons
parent710f435c200717fa09cf43e4cd2638f775bc8475 (diff)
downloadfreeipa-d709dcf8f5d9e311b6703cd444ff220809eeff7a.tar.gz
freeipa-d709dcf8f5d9e311b6703cd444ff220809eeff7a.tar.xz
freeipa-d709dcf8f5d9e311b6703cd444ff220809eeff7a.zip
ipa-cldap: Implement worker thread.
Diffstat (limited to 'daemons')
-rw-r--r--daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h11
-rw-r--r--daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_worker.c71
2 files changed, 81 insertions, 1 deletions
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
index 013dad2f..ff9818a6 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap.h
@@ -58,6 +58,7 @@
#define IPA_PLUGIN_NAME IPA_CLDAP_PLUGIN_NAME
#define CLDAP_PORT 389
+#define MAX_DG_SIZE 4096
struct ipa_cldap_ctx {
Slapi_ComponentId *plugin_id;
@@ -67,6 +68,16 @@ struct ipa_cldap_ctx {
int sd;
};
+struct ipa_cldap_req {
+ int fd;
+
+ struct sockaddr_storage ss;
+ socklen_t ss_len;
+
+ char dgram[MAX_DG_SIZE];
+ size_t dgsize;
+};
+
void *ipa_cldap_worker(struct ipa_cldap_ctx *ctx);
#endif /* _IPA_CLDAP_H_ */
diff --git a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_worker.c b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_worker.c
index 4bbba535..474c5327 100644
--- a/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_worker.c
+++ b/daemons/ipa-slapi-plugins/ipa-cldap/ipa_cldap_worker.c
@@ -38,12 +38,81 @@
* END COPYRIGHT BLOCK **/
#include "ipa_cldap.h"
+#include <poll.h>
+
+static void ipa_cldap_process(struct ipa_cldap_ctx *ctx,
+ struct ipa_cldap_req *req)
+{
+ free(req);
+ return;
+}
+
+static struct ipa_cldap_req *ipa_cldap_recv_dgram(struct ipa_cldap_ctx *ctx)
+{
+ struct ipa_cldap_req *req;
+
+ req = calloc(1, sizeof(struct ipa_cldap_req));
+ if (!req) {
+ LOG("Failed to allocate memory for req");
+ return NULL;
+ }
+
+ req->fd = ctx->sd;
+ req->ss_len = sizeof(struct sockaddr_storage);
+
+ req->dgsize = recvfrom(req->fd, req->dgram, MAX_DG_SIZE, 0,
+ (struct sockaddr *)&req->ss, &req->ss_len);
+ if (req->dgsize == -1) {
+ LOG_TRACE("Failed to get datagram\n");
+ free(req);
+ return NULL;
+ }
+
+ return req;
+}
void *ipa_cldap_worker(struct ipa_cldap_ctx *ctx)
{
+ struct ipa_cldap_req *req;
+ struct pollfd fds[2];
bool stop = false;
+ int ret;
while (!stop) {
- sleep(1);
+
+ fds[0].fd = ctx->stopfd[0];
+ fds[0].events = POLLIN;
+ fds[0].revents = 0;
+ fds[1].fd = ctx->sd;
+ fds[1].events = POLLIN;
+ fds[1].revents = 0;
+
+ /* wait until a request comes in */
+ ret = poll(fds, 2, -1);
+ if (ret == -1) {
+ if (errno != EINTR) {
+ LOG_FATAL("poll() failed with [%d, %s]. Can't continue.\n",
+ errno, strerror(errno));
+ stop = true;
+ }
+ }
+ if (ret <= 0) {
+ continue;
+ }
+
+ /* got a stop signal, exit the loop */
+ if (fds[0].revents & POLLIN) {
+ stop = true;
+ continue;
+ }
+
+ /* got a CLDAP packet, handle it */
+ if (fds[1].revents & POLLIN) {
+ req = ipa_cldap_recv_dgram(ctx);
+ if (req) {
+ ipa_cldap_process(ctx, req);
+ }
+ }
}
+ return NULL;
}