Package: dovecot / 1:2.2.13-12~deb8u4

dovecot-drac.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Description: Adds support for drac
Origin: http://sourceforge.jp/projects/dovecot2-drac/releases/53176
Author: Timo Sirainen <tss@iki.fi>

--- /dev/null
+++ b/src/plugins/drac/Makefile
@@ -0,0 +1,20 @@
+DOVDIR:=../../..
+LIBS:=-ldrac
+
+local_CFLAGS=-Wall -W -shared -fPIC -DHAVE_CONFIG_H
+INC=-I$(DOVDIR) \
+	-I$(DOVDIR)/src/lib \
+	-I$(DOVDIR)/src/lib-index \
+	-I$(DOVDIR)/src/lib-mail \
+	-I$(DOVDIR)/src/lib-storage \
+	-I$(DOVDIR)/src/lib-storage/index \
+	-I$(DOVDIR)/src/lib-storage/index/maildir \
+	-I../../lib
+
+all: drac_plugin.so
+
+drac_plugin.so: drac-plugin.c
+	$(CC) $(CFLAGS) $(local_CFLAGS) $(INC) $(LDFLAGS) $< -o $@ $(LIBS)
+
+clean:
+	@rm -f *.so *.o
--- /dev/null
+++ b/src/plugins/drac/drac-plugin.c
@@ -0,0 +1,108 @@
+/*
+ *
+ * dovecot plugin for DRAC authentication
+ *
+ * Copyright (C) 2011 DesigNET, INC.
+ *
+ * $Id: drac-plugin.c,v 1.1.1.1 2011/09/09 08:04:34 usuda Exp $
+ *
+ * based:
+ *   http://dovecot.org/patches/1.1/drac.c
+ */
+#include "lib.h"
+#include "net.h"
+#include "ioloop.h"
+#include "mail-user.h"
+#include "mail-storage-private.h"
+#include <stdlib.h>
+#include <string.h>
+
+/* default parameters */
+#define DRAC_TIMEOUT_SECS	(60)
+#define DRAC_HOST		"localhost"
+
+
+/* libdrac function */
+int dracauth(char *, unsigned long, char **);
+
+const char *drac_plugin_version = DOVECOT_VERSION;
+
+static struct timeout *to_drac = NULL;
+static const char *drachost = NULL; /* dracd host */
+static unsigned long in_ip = 0; /* remote ip address */
+static unsigned long dractout = 0; /* drac timeout secs */
+
+static void drac_timeout(void *context ATTR_UNUSED)
+{
+    char *err;
+
+    if(dracauth((char *)drachost, in_ip, &err) != 0) {
+        i_error("%s: dracauth() failed: %s", __FUNCTION__, err);
+    }
+}
+
+static void drac_mail_user_created(struct mail_user *user)
+{
+    const char *dractout_str;
+    char addrname[256];
+    char *ep;
+
+    /* check address family */
+    if(user->remote_ip->family != AF_INET) {
+        if(inet_ntop(user->remote_ip->family, &user->remote_ip->u,
+           addrname, sizeof(addrname)-1) == NULL) {
+            strcpy(addrname, "<unknown>");
+        }
+        i_error("%s: Only IPv4 addresses are supported (%s)", __FUNCTION__,
+                addrname);
+    } else {
+        /* get remote IPv4 address... uum... */
+        memcpy(&in_ip, &user->remote_ip->u, sizeof(in_ip));
+
+        /* get DRAC server name */
+        drachost = mail_user_plugin_getenv(user, "dracdserver");
+        if(drachost == NULL) {
+            drachost = DRAC_HOST;
+        }
+
+        /* get timeout secs */
+        dractout_str = mail_user_plugin_getenv(user, "dracdtimeout");
+        if(dractout_str == NULL) {
+            dractout = DRAC_TIMEOUT_SECS;
+        } else {
+            dractout = strtoul(dractout_str, &ep, 10);
+            /* bad format -> use default value */
+            if(ep != NULL && *ep != '\0') {
+                i_warning("%s: bad dracdtimeout (%s). using default %d",
+                          __FUNCTION__, dractout_str, DRAC_TIMEOUT_SECS);
+                dractout = DRAC_TIMEOUT_SECS;
+            }
+        }
+        i_debug("%s: dracdserver=%s, timeout=%ldsecs", __FUNCTION__,
+               drachost, dractout);
+
+        /* connect to DRAC server */
+        drac_timeout(NULL);
+        to_drac = timeout_add(1000*dractout, drac_timeout, NULL);
+    }
+}
+
+static struct mail_storage_hooks drac_mail_storage_hooks = {
+    .mail_user_created = drac_mail_user_created,
+};
+
+void drac_plugin_init(struct module *module)
+{
+    mail_storage_hooks_add(module, &drac_mail_storage_hooks);
+    i_debug("%s called", __FUNCTION__);
+}
+
+void drac_plugin_deinit(void)
+{
+    if(to_drac != NULL) {
+        timeout_remove(&to_drac);
+        to_drac = NULL;
+    }
+    mail_storage_hooks_remove(&drac_mail_storage_hooks);
+    i_debug("%s called", __FUNCTION__);
+}