aboutsummaryrefslogtreecommitdiffstats
path: root/mail/cyrus-imapd23/files/drac_auth.patch
blob: ec1ef5e996967bfd6b73fb8303f5250a7ca181d8 (plain) (blame)
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
Index: acconfig.h
diff -u acconfig.h.orig acconfig.h
--- acconfig.h.orig Fri Feb 14 05:32:50 2003
+++ acconfig.h  Fri Mar 21 20:13:20 2003
@@ -98,6 +98,9 @@
 /* do we have SASL support for APOP? */
 #undef HAVE_APOP
 
+/* the Dynamic Relay Authorization Control package */
+#undef DRAC_AUTH
+
 /* do we have OpenSSL? */
 #undef HAVE_SSL
 
Index: configure.in
diff -u configure.in.orig configure.in
--- configure.in.orig   Wed Mar 19 04:15:14 2003
+++ configure.in    Fri Mar 21 20:20:54 2003
@@ -981,6 +981,19 @@
 SNMP_SUBDIRS=""
 AC_SUBST(SNMP_SUBDIRS)
 
+dnl
+dnl Test for DRAC
+dnl
+DRACLIBS=
+AC_ARG_WITH(drac, [  --with-drac=DIR         use DRAC library in <DIR> [no] ],
+   if test -d "$withval"; then
+       LDFLAGS="$LDFLAGS -L${withval}"
+       AC_CHECK_LIB(drac, dracauth,
+           AC_DEFINE(DRAC_AUTH)
+           DRACLIBS="-ldrac")
+   fi)
+AC_SUBST(DRACLIBS)
+
 CMU_LIBWRAP
 CMU_UCDSNMP
 
Index: imap/Makefile.in
diff -u imap/Makefile.in.orig imap/Makefile.in
--- imap/Makefile.in.orig   Fri Feb 28 03:10:28 2003
+++ imap/Makefile.in    Fri Mar 21 20:23:02 2003
@@ -67,6 +67,7 @@
 SIEVE_LIBS = @SIEVE_LIBS@
 IMAP_COM_ERR_LIBS = @IMAP_COM_ERR_LIBS@
 LIB_WRAP = @LIB_WRAP@
+DRAC_LIBS = @DRACLIBS@
 LIBS = $(IMAP_LIBS) $(IMAP_COM_ERR_LIBS)
 DEPLIBS = ../lib/libcyrus.a ../lib/libcyrus_min.a @DEPLIBS@
 
@@ -206,17 +207,17 @@
 imapd: xversion $(IMAPDOBJS) mutex_fake.o libimap.a $(DEPLIBS) $(SERVICE)
    $(CC) $(LDFLAGS) -o imapd \
     $(SERVICE) $(IMAPDOBJS) mutex_fake.o \
-   libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)
+   libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP) $(DRAC_LIBS)
 
 imapd.pure: $(IMAPDOBJS) mutex_fake.o libimap.a $(DEPLIBS) $(SERVICE)
    $(PURIFY) $(PUREOPT) $(CC) $(LDFLAGS) -o imapd.pure \
     $(SERVICE) $(IMAPDOBJS) mutex_fake.o libimap.a \
-   $(DEPLIBS) $(LIBS) $(LIB_WRAP)
+   $(DEPLIBS) $(LIBS) $(LIB_WRAP) $(DRAC_LIBS)
 
 imapd.quant: $(IMAPDOBJS) mutex_fake.o libimap.a $(DEPLIBS) $(SERVICE)
    $(QUANTIFY) $(QUANTOPT) $(CC) $(LDFLAGS) -o imapd.quant \
     $(SERVICE) $(IMAPDOBJS) mutex_fake.o libimap.a \
-   $(DEPLIBS) $(LIBS) $(LIB_WRAP)
+   $(DEPLIBS) $(LIBS) $(LIB_WRAP) $(DRAC_LIBS) $(DRAC_LIBS)
 
 proxyd: $(PROXYDOBJS) mutex_fake.o libimap.a $(DEPLIBS) $(SERVICE)
    $(CC) $(LDFLAGS) -o proxyd \
@@ -242,7 +243,7 @@
 
 pop3d: pop3d.o backend.o tls.o mutex_fake.o libimap.a $(DEPLIBS) $(SERVICE)
    $(CC) $(LDFLAGS) -o pop3d pop3d.o backend.o tls.o $(SERVICE) \
-    mutex_fake.o libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP)
+    mutex_fake.o libimap.a $(DEPLIBS) $(LIBS) $(LIB_WRAP) $(DRAC_LIBS)
 
 nntpd: nntpd.o backend.o index.o spool.o netnews.o wildmat.o tls.o \
     mutex_fake.o nntp_err.o libimap.a $(DEPLIBS) $(SERVICE)
Index: imap/imapd.c
diff -u imap/imapd.c.orig imap/imapd.c
--- imap/imapd.c.orig   Thu Mar  6 03:32:05 2003
+++ imap/imapd.c    Fri Mar 21 23:25:27 2003
@@ -126,6 +126,18 @@
     1, 1, &imapd_authstate, &imapd_userisadmin, &imapd_userisproxyadmin
 };
 
+#ifdef DRAC_AUTH
+static struct {
+    int interval;      /* dracd "ping" interval; 0 = disabled */
+    unsigned long clientaddr;
+    struct prot_waitevent *event;
+} drac;
+
+extern int dracconn(char *server, char **errmsg);
+extern int dracsend(unsigned long userip, char **errmsg);
+extern int dracdisc(char **errmsg);
+#endif /* DRAC_AUTH */
+
 /* current sub-user state */
 static struct mailbox mboxstruct;
 static struct mailbox *imapd_mailbox;
@@ -447,6 +459,23 @@
     /* setup for sending IMAP IDLE notifications */
     idle_enabled();
 
+#ifdef DRAC_AUTH
+    /* setup for sending DRAC "pings" */
+    drac.event = NULL;
+    drac.interval = config_getint(IMAPOPT_DRACINTERVAL);
+    if (drac.interval < 0) drac.interval = 0;
+    if (drac.interval) {
+   char *err;
+
+   if (dracconn((char*) config_getstring(IMAPOPT_DRACHOST), &err) != 0) {
+       /* disable DRAC */
+       drac.interval = 0;
+       syslog(LOG_ERR, "dracconn: %s", err);
+       syslog(LOG_ERR, "DRAC notifications disabled");
+   }
+    }
+#endif /* DRAC_AUTH */
+
     /* create connection to the SNMP listener, if available. */
     snmp_connect(); /* ignore return code */
     snmp_set_str(SERVER_NAME_VERSION,CYRUS_VERSION);
@@ -533,6 +562,15 @@
        imapd_haveaddr = 1;
        }
    }
+
+#ifdef DRAC_AUTH
+   if (((struct sockaddr *)&imapd_remoteaddr)->sa_family == AF_INET)
+       drac.clientaddr = ((struct sockaddr_in *)&imapd_remoteaddr)->sin_addr.s_addr;
+   else
+       drac.clientaddr = 0;
+    } else {
+   drac.clientaddr = 0;
+#endif /* DRAC_AUTH */
     }
 
     /* create the SASL connection */
@@ -575,6 +613,11 @@
     prot_flush(imapd_out);
     snmp_increment(ACTIVE_CONNECTIONS, -1);
 
+#ifdef DRAC_AUTH
+    if (drac.event) prot_removewaitevent(imapd_in, drac.event);
+    drac.event = NULL;
+#endif /* DRAC_AUTH */
+
     /* cleanup */
     imapd_reset();
 
@@ -645,6 +688,10 @@
 
     cyrus_done();
 
+#ifdef DRAC_AUTH
+    if (drac.interval) (void) dracdisc((char **)NULL);
+#endif /* DRAC_AUTH */
+
     exit(code);
 }
 
@@ -667,6 +714,35 @@
     shut_down(code);
 }
 
+#ifdef DRAC_AUTH
+/*
+ * Ping dracd every 'drac.interval' minutes
+ * to let it know that we are still connected
+ */
+struct prot_waitevent *drac_ping(struct protstream *s,
+                struct prot_waitevent *ev, void *rock)
+{
+    char *err;
+    static int nfailure = 0;
+
+    if (dracsend(drac.clientaddr, &err) != 0) {
+   syslog(LOG_ERR, "dracsend: %s", err);
+   if (++nfailure >= 3) {
+       /* can't contact dracd for 3 consecutive tries - disable DRAC */
+       prot_removewaitevent(s, ev);
+       drac.event = NULL;
+       syslog(LOG_ERR, "DRAC notifications disabled");
+       return NULL;
+   }
+    }
+    else
+   nfailure = 0;
+
+    ev->mark = time(NULL) + (drac.interval * 60);
+    return ev;
+}
+#endif /* DRAC_AUTH */
+
 /*
  * Top-level command loop parsing
  */
@@ -1664,6 +1740,11 @@
 
     prot_printf(imapd_out, "%s OK %s\r\n", tag, reply);
 
+#ifdef DRAC_AUTH
+    if (drac.interval && drac.clientaddr)
+   drac.event = prot_addwaitevent(imapd_in, 0 /* now */, drac_ping, NULL);
+#endif /* DRAC_AUTH */
+
     /* Create telemetry log */
     imapd_logfd = telemetry_log(imapd_userid, imapd_in, imapd_out);
 
@@ -1786,6 +1867,11 @@
 
     prot_setsasl(imapd_in,  imapd_saslconn);
     prot_setsasl(imapd_out, imapd_saslconn);
+
+#ifdef DRAC_AUTH
+    if (drac.interval && drac.clientaddr)
+   drac.event = prot_addwaitevent(imapd_in, 0 /* now */, drac_ping, NULL);
+#endif /* DRAC_AUTH */
 
     /* Create telemetry log */
     imapd_logfd = telemetry_log(imapd_userid, imapd_in, imapd_out);
Index: imap/pop3d.c
diff -u imap/pop3d.c.orig imap/pop3d.c
--- imap/pop3d.c.orig   Thu Mar 13 01:38:16 2003
+++ imap/pop3d.c    Fri Mar 21 23:37:11 2003
@@ -101,6 +101,10 @@
 extern int opterr;
 
 
+#ifdef DRAC_AUTH
+static int drac_enabled;
+extern int dracauth(char *server, unsigned long userip, char **errmsg);
+#endif /* DRAC_AUTH */
 
 #ifdef HAVE_SSL
 static SSL *tls_conn;
@@ -395,6 +399,10 @@
     prot_settimeout(popd_in, timeout*60);
     prot_setflushonread(popd_in, popd_out);
 
+#ifdef DRAC_AUTH
+    drac_enabled = (config_getint(IMAPOPT_DRACINTERVAL) > 0);
+#endif /* DRAC_AUTH */
+
     if (kflag) kpop();
 
     /* we were connected on pop3s port so we should do 
@@ -1422,6 +1430,21 @@
    popd_mailbox = &mboxstruct;
    proc_register("pop3d", popd_clienthost, popd_userid,
              popd_mailbox->name);
+
+#ifdef DRAC_AUTH
+   if (drac_enabled &&
+       ((struct sockaddr *)&popd_remoteaddr)->sa_family == AF_INET) {
+       char *err;
+
+       if (dracauth((char*) config_getstring(IMAPOPT_DRACHOST),
+            ((struct sockaddr_in *)&popd_remoteaddr)->sin_addr.s_addr, &err) != 0) {
+       /* disable DRAC */
+       drac_enabled = 0;
+       syslog(LOG_ERR, "dracauth: %s", err);
+       syslog(LOG_ERR, "DRAC notifications disabled");
+       }
+   }
+#endif /* DRAC_AUTH */
     }
     else {
    /* remote mailbox */
Index: imap/version.c
diff -u imap/version.c.orig imap/version.c
--- imap/version.c.orig Fri Feb 14 05:33:02 2003
+++ imap/version.c  Fri Mar 21 20:13:21 2003
@@ -143,6 +143,10 @@
     snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
         "; %s", SIEVE_VERSION);
 #endif
+#ifdef DRAC_AUTH
+    snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
+        "; DRAC");
+#endif
 #ifdef HAVE_LIBWRAP
     snprintf(env_buf + strlen(env_buf), MAXIDVALUELEN - strlen(env_buf),
         "; TCP Wrappers");
Index: lib/imapoptions
diff -u lib/imapoptions.orig lib/imapoptions
--- lib/imapoptions.orig    Thu Mar 20 04:00:39 2003
+++ lib/imapoptions Fri Mar 21 20:32:15 2003
@@ -154,6 +154,14 @@
 { "deleteright", "c", STRING }
 /* The right that a user needs to delete a mailbox. */
 
+{ "dracinterval", 5, INT }
+/* If nonzero, enables the use of DRAC (Dynamic Relay Authorization
+   Control) by the pop3d and imapd daemons.  Also sets the interval
+   (in minutes) between re-authorization requests made by imapd. */
+
+{ "drachost", "localhost", STRING }
+/* Hostname of the RPC dracd server. */
+
 { "duplicatesuppression", 1, SWITCH }
 /* If enabled, lmtpd will suppress delivery of a message to a mailbox if
    a message with the same message-id (or resent-message-id) is recorded