]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/patches/cyrus-imapd-2.2.12-64bit_quota-p1.patch
Wir kehren zurueck zu Kudzu, da hwinfo noch mehr Aerger macht.
[people/teissler/ipfire-2.x.git] / src / patches / cyrus-imapd-2.2.12-64bit_quota-p1.patch
1 diff -Naur cyrus-imapd-2.2.12.orig/configure.in cyrus-imapd-2.2.12/configure.in
2 --- cyrus-imapd-2.2.12.orig/configure.in 2005-01-19 00:46:00.000000000 +0100
3 +++ cyrus-imapd-2.2.12/configure.in 2006-04-25 07:35:25.000000000 +0200
4 @@ -100,6 +100,15 @@
5 fi
6 AC_C_INLINE
7
8 +dnl Check if `long long int' is available
9 +AC_CHECK_SIZEOF(long long int)
10 +AC_CHECK_SIZEOF(unsigned long long int)
11 +if test "$ac_cv_sizeof_long_long_int" -eq 8 -a \
12 + "$ac_cv_sizeof_unsigned_long_long_int" -eq 8; then
13 + AC_DEFINE(HAVE_LONG_LONG_INT,[],[Does the compiler support long long int?])
14 + AC_C_BIGENDIAN
15 +fi
16 +
17 CMU_C___ATTRIBUTE__
18 CMU_C_FPIC
19
20 diff -Naur cyrus-imapd-2.2.12.orig/imap/append.c cyrus-imapd-2.2.12/imap/append.c
21 --- cyrus-imapd-2.2.12.orig/imap/append.c 2004-05-22 05:45:48.000000000 +0200
22 +++ cyrus-imapd-2.2.12/imap/append.c 2006-04-25 07:35:25.000000000 +0200
23 @@ -140,7 +140,7 @@
24 if (!r) {
25 if (m.quota.limit >= 0 && quotacheck >= 0 &&
26 m.quota.used + quotacheck >
27 - ((unsigned) m.quota.limit * QUOTA_UNITS)) {
28 + ((uquota_t) m.quota.limit * QUOTA_UNITS)) {
29 r = IMAP_QUOTA_EXCEEDED;
30 }
31 }
32 @@ -208,7 +208,7 @@
33 if (!r) {
34 if (as->m.quota.limit >= 0 && quotacheck >= 0 &&
35 as->m.quota.used + quotacheck >
36 - ((unsigned) as->m.quota.limit * QUOTA_UNITS)) {
37 + ((uquota_t) as->m.quota.limit * QUOTA_UNITS)) {
38 quota_abort(&as->tid);
39 mailbox_close(&as->m);
40 r = IMAP_QUOTA_EXCEEDED;
41 diff -Naur cyrus-imapd-2.2.12.orig/imap/imapd.c cyrus-imapd-2.2.12/imap/imapd.c
42 --- cyrus-imapd-2.2.12.orig/imap/imapd.c 2005-02-14 07:39:55.000000000 +0100
43 +++ cyrus-imapd-2.2.12/imap/imapd.c 2006-04-25 07:35:25.000000000 +0200
44 @@ -2626,10 +2626,10 @@
45 */
46 int warnsize = config_getint(IMAPOPT_QUOTAWARNKB);
47 if (warnsize <= 0 || warnsize >= imapd_mailbox->quota.limit ||
48 - (int)((imapd_mailbox->quota.limit * QUOTA_UNITS) -
49 - imapd_mailbox->quota.used) < (warnsize * QUOTA_UNITS)) {
50 + ((uquota_t) (imapd_mailbox->quota.limit - warnsize)) * QUOTA_UNITS <
51 + imapd_mailbox->quota.used) {
52 usage = ((double) imapd_mailbox->quota.used * 100.0) / (double)
53 - (imapd_mailbox->quota.limit * QUOTA_UNITS);
54 + ((uquota_t) imapd_mailbox->quota.limit * QUOTA_UNITS);
55 if (usage >= 100.0) {
56 prot_printf(imapd_out, "* NO [ALERT] %s\r\n",
57 error_message(IMAP_NO_OVERQUOTA));
58 @@ -4626,7 +4626,7 @@
59 printastring(name);
60 prot_printf(imapd_out, " (");
61 if (quota.limit >= 0) {
62 - prot_printf(imapd_out, "STORAGE %lu %d",
63 + prot_printf(imapd_out, "STORAGE " UQUOTA_T_FMT " %d",
64 quota.used/QUOTA_UNITS, quota.limit);
65 }
66 prot_printf(imapd_out, ")\r\n");
67 @@ -4688,7 +4688,7 @@
68 printastring(mailboxname);
69 prot_printf(imapd_out, " (");
70 if (mailbox.quota.limit >= 0) {
71 - prot_printf(imapd_out, "STORAGE %lu %d",
72 + prot_printf(imapd_out, "STORAGE " UQUOTA_T_FMT " %d",
73 mailbox.quota.used/QUOTA_UNITS,
74 mailbox.quota.limit);
75 }
76 diff -Naur cyrus-imapd-2.2.12.orig/imap/mailbox.c cyrus-imapd-2.2.12/imap/mailbox.c
77 --- cyrus-imapd-2.2.12.orig/imap/mailbox.c 2005-02-14 07:39:57.000000000 +0100
78 +++ cyrus-imapd-2.2.12/imap/mailbox.c 2006-04-25 07:36:13.000000000 +0200
79 @@ -84,6 +84,7 @@
80 #include "seen.h"
81 #include "util.h"
82 #include "xmalloc.h"
83 +#include "byteorder64.h"
84
85 static int mailbox_doing_reconstruct = 0;
86 #define zeromailbox(m) { memset(&m, 0, sizeof(struct mailbox)); \
87 @@ -788,8 +789,17 @@
88 mailbox->last_uid =
89 ntohl(*((bit32 *)(mailbox->index_base+OFFSET_LAST_UID)));
90
91 - mailbox->quota_mailbox_used =
92 - ntohl(*((bit32 *)(mailbox->index_base+OFFSET_QUOTA_MAILBOX_USED-quota_upgrade_offset)));
93 +#ifdef HAVE_LONG_LONG_INT
94 + if (mailbox->minor_version > 5) {
95 + /* newer versions may use 64bit quotas now */
96 + mailbox->quota_mailbox_used =
97 + ntohll(*((bit64 *)(mailbox->index_base+OFFSET_QUOTA_MAILBOX_USED64)));
98 + } else
99 +#endif
100 + {
101 + mailbox->quota_mailbox_used =
102 + ntohl(*((bit32 *)(mailbox->index_base+OFFSET_QUOTA_MAILBOX_USED-quota_upgrade_offset)));
103 + }
104
105 if (mailbox->start_offset < OFFSET_POP3_LAST_LOGIN-quota_upgrade_offset+sizeof(bit32)) {
106 mailbox->pop3_last_login = 0;
107 @@ -1183,9 +1193,18 @@
108 *((bit32 *)(buf+OFFSET_EXISTS)) = htonl(mailbox->exists);
109 *((bit32 *)(buf+OFFSET_LAST_APPENDDATE)) = htonl(mailbox->last_appenddate);
110 *((bit32 *)(buf+OFFSET_LAST_UID)) = htonl(mailbox->last_uid);
111 - *((bit32 *)(buf+OFFSET_QUOTA_RESERVED_FIELD)) = htonl(0); /* RESERVED */
112 +
113 + /* quotas may be 64bit now */
114 +#ifdef HAVE_LONG_LONG_INT
115 + *((bit64 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) =
116 + htonll(mailbox->quota_mailbox_used);
117 +#else
118 + /* zero the unused 32bits */
119 + *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) = htonl(0);
120 *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED)) =
121 htonl(mailbox->quota_mailbox_used);
122 +#endif
123 +
124 *((bit32 *)(buf+OFFSET_POP3_LAST_LOGIN)) = htonl(mailbox->pop3_last_login);
125 *((bit32 *)(buf+OFFSET_UIDVALIDITY)) = htonl(mailbox->uidvalidity);
126 *((bit32 *)(buf+OFFSET_DELETED)) = htonl(mailbox->deleted);
127 @@ -1430,9 +1449,18 @@
128 *((bit32 *)(buf+OFFSET_EXISTS)) = htonl(mailbox->exists);
129 *((bit32 *)(buf+OFFSET_LAST_APPENDDATE)) = htonl(mailbox->last_appenddate);
130 *((bit32 *)(buf+OFFSET_LAST_UID)) = htonl(mailbox->last_uid);
131 - /* OFFSET_QUOTA_RESERVED_FIELD left as zero */
132 +
133 + /* newer versions may use 64bit quotas */
134 +#ifdef HAVE_LONG_LONG_INT
135 + *((bit64 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) =
136 + htonll(mailbox->quota_mailbox_used);
137 +#else
138 + /* zero the unused 32bits */
139 + *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) = htonl(0);
140 *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED)) =
141 htonl(mailbox->quota_mailbox_used);
142 +#endif
143 +
144 *((bit32 *)(buf+OFFSET_POP3_LAST_LOGIN)) = htonl(mailbox->pop3_last_login);
145 *((bit32 *)(buf+OFFSET_UIDVALIDITY)) = htonl(mailbox->uidvalidity);
146 *((bit32 *)(buf+OFFSET_DELETED)) = htonl(mailbox->deleted);
147 @@ -1608,7 +1636,8 @@
148 size_t fnamebuf_len;
149 FILE *newindex = NULL, *newcache = NULL;
150 unsigned long *deleted;
151 - unsigned numdeleted = 0, quotadeleted = 0;
152 + unsigned numdeleted = 0;
153 + uquota_t quotadeleted = 0;
154 unsigned numansweredflag = 0;
155 unsigned numdeletedflag = 0;
156 unsigned numflaggedflag = 0;
157 @@ -1829,8 +1858,13 @@
158 *((bit32 *)(buf+OFFSET_FLAGGED)) = htonl(newflagged);
159
160 /* Fix up quota_mailbox_used */
161 +#ifdef HAVE_LONG_LONG_INT
162 + *((bit64 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) =
163 + htonll(ntohll(*((bit64 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)))-quotadeleted);
164 +#else
165 *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED)) =
166 htonl(ntohl(*((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED)))-quotadeleted);
167 +#endif
168 /* Fix up start offset if necessary */
169 if (mailbox->start_offset < INDEX_HEADER_SIZE) {
170 *((bit32 *)(buf+OFFSET_START_OFFSET)) = htonl(INDEX_HEADER_SIZE);
171 @@ -1862,7 +1896,7 @@
172 if (!r) quota_commit(&tid);
173 else {
174 syslog(LOG_ERR,
175 - "LOSTQUOTA: unable to record free of %u bytes in quota %s",
176 + "LOSTQUOTA: unable to record free of " UQUOTA_T_FMT " bytes in quota %s",
177 quotadeleted, mailbox->quota.root);
178 }
179 }
180 @@ -2250,7 +2284,7 @@
181 strcmp(oldmailbox->quota.root, newmailbox->quota.root) != 0) {
182 if (!r && newmailbox->quota.limit >= 0 &&
183 newmailbox->quota.used + oldmailbox->quota_mailbox_used >
184 - ((unsigned) newmailbox->quota.limit * QUOTA_UNITS)) {
185 + ((uquota_t) newmailbox->quota.limit * QUOTA_UNITS)) {
186 r = IMAP_QUOTA_EXCEEDED;
187 }
188 }
189 @@ -2464,7 +2498,7 @@
190 strcmp(oldmailbox.quota.root, newmailbox.quota.root) != 0) {
191 if (!r && newmailbox.quota.limit >= 0 &&
192 newmailbox.quota.used + oldmailbox.quota_mailbox_used >
193 - ((unsigned) newmailbox.quota.limit * QUOTA_UNITS)) {
194 + ((uquota_t) newmailbox.quota.limit * QUOTA_UNITS)) {
195 r = IMAP_QUOTA_EXCEEDED;
196 }
197 }
198 @@ -2617,7 +2651,7 @@
199 else if (r2 == IMAP_QUOTAROOT_NONEXISTENT) r2 = 0;
200 if (r2) {
201 syslog(LOG_ERR,
202 - "LOSTQUOTA: unable to record use of %lu bytes in quota %s",
203 + "LOSTQUOTA: unable to record use of " UQUOTA_T_FMT " bytes in quota %s",
204 newmailbox.quota_mailbox_used, newmailbox.quota.root);
205 }
206 }
207 diff -Naur cyrus-imapd-2.2.12.orig/imap/mailbox.h cyrus-imapd-2.2.12/imap/mailbox.h
208 --- cyrus-imapd-2.2.12.orig/imap/mailbox.h 2004-01-22 22:17:09.000000000 +0100
209 +++ cyrus-imapd-2.2.12/imap/mailbox.h 2006-04-25 07:35:25.000000000 +0200
210 @@ -45,6 +45,7 @@
211 #include <sys/types.h>
212 #include <sys/stat.h>
213 #include <limits.h>
214 +#include <config.h>
215
216 #include "auth.h"
217 #include "quota.h"
218 @@ -61,6 +62,10 @@
219 #error dont know what to use for bit32
220 #endif
221
222 +#ifdef HAVE_LONG_LONG_INT
223 +typedef unsigned long long int bit64;
224 +#endif
225 +
226 #define MAX_MAILBOX_NAME 490
227 #define MAX_MAILBOX_PATH 4096
228
229 @@ -126,7 +131,7 @@
230 unsigned long exists;
231 time_t last_appenddate;
232 unsigned long last_uid;
233 - unsigned long quota_mailbox_used;
234 + uquota_t quota_mailbox_used;
235 unsigned long pop3_last_login;
236 unsigned long uidvalidity;
237
238 @@ -168,8 +173,8 @@
239 #define OFFSET_EXISTS 20
240 #define OFFSET_LAST_APPENDDATE 24
241 #define OFFSET_LAST_UID 28
242 -#define OFFSET_QUOTA_RESERVED_FIELD 32 /* Reserved for 64bit quotas */
243 -#define OFFSET_QUOTA_MAILBOX_USED 36
244 +#define OFFSET_QUOTA_MAILBOX_USED64 32 /* offset for 64bit quotas */
245 +#define OFFSET_QUOTA_MAILBOX_USED 36 /* offset for 32bit quotas */
246 #define OFFSET_POP3_LAST_LOGIN 40
247 #define OFFSET_UIDVALIDITY 44
248 #define OFFSET_DELETED 48 /* added for ACAP */
249 diff -Naur cyrus-imapd-2.2.12.orig/imap/mbdump.c cyrus-imapd-2.2.12/imap/mbdump.c
250 --- cyrus-imapd-2.2.12.orig/imap/mbdump.c 2004-05-22 05:45:51.000000000 +0200
251 +++ cyrus-imapd-2.2.12/imap/mbdump.c 2006-04-25 07:35:25.000000000 +0200
252 @@ -507,7 +507,7 @@
253 {
254 struct buf file, data;
255 char c;
256 - int quotaused = 0;
257 + uquota_t quotaused = 0;
258 int r = 0;
259 int curfile = -1;
260 const char *userid = NULL;
261 diff -Naur cyrus-imapd-2.2.12.orig/imap/mbexamine.c cyrus-imapd-2.2.12/imap/mbexamine.c
262 --- cyrus-imapd-2.2.12.orig/imap/mbexamine.c 2004-12-17 17:32:16.000000000 +0100
263 +++ cyrus-imapd-2.2.12/imap/mbexamine.c 2006-04-25 07:35:25.000000000 +0200
264 @@ -266,7 +266,7 @@
265 printf(" Minor Version: %d\n", mailbox.minor_version);
266 printf(" Header Size: %ld bytes Record Size: %ld bytes\n",
267 mailbox.start_offset, mailbox.record_size);
268 - printf(" Number of Messages: %lu Mailbox Size: %lu bytes\n",
269 + printf(" Number of Messages: %lu Mailbox Size: " UQUOTA_T_FMT " bytes\n",
270 mailbox.exists, mailbox.quota_mailbox_used);
271 printf(" Last Append Date: (%ld) %s", mailbox.last_appenddate,
272 ctime(&mailbox.last_appenddate));
273 diff -Naur cyrus-imapd-2.2.12.orig/imap/quota.c cyrus-imapd-2.2.12/imap/quota.c
274 --- cyrus-imapd-2.2.12.orig/imap/quota.c 2004-06-30 21:23:26.000000000 +0200
275 +++ cyrus-imapd-2.2.12/imap/quota.c 2006-04-25 07:35:25.000000000 +0200
276 @@ -120,7 +120,7 @@
277 struct quota quota;
278 int refcount;
279 int deleted;
280 - unsigned long newused;
281 + uquota_t newused;
282 };
283
284 #define QUOTAGROW 300
285 @@ -251,7 +251,7 @@
286 }
287 memset(&quota[quota_num], 0, sizeof(struct quotaentry));
288 quota[quota_num].quota.root = xstrndup(key, keylen);
289 - sscanf(data, "%lu %d",
290 + sscanf(data, UQUOTA_T_FMT " %d",
291 &quota[quota_num].quota.used, &quota[quota_num].quota.limit);
292
293 quota_num++;
294 @@ -422,7 +422,7 @@
295 (*count)++;
296 }
297 if (quota[thisquota].quota.used != quota[thisquota].newused) {
298 - printf("%s: usage was %lu, now %lu\n", quota[thisquota].quota.root,
299 + printf("%s: usage was " UQUOTA_T_FMT ", now " UQUOTA_T_FMT "\n", quota[thisquota].quota.root,
300 quota[thisquota].quota.used, quota[thisquota].newused);
301 quota[thisquota].quota.used = quota[thisquota].newused;
302 r = quota_write(&quota[thisquota].quota, tid);
303 @@ -489,12 +489,12 @@
304 int i;
305 char buf[MAX_MAILBOX_PATH+1];
306
307 - printf(" Quota %% Used Used Root\n");
308 + printf(" Quota %% Used Used Root\n");
309
310 for (i = 0; i < quota_num; i++) {
311 if (quota[i].deleted) continue;
312 if (quota[i].quota.limit > 0) {
313 - printf(" %7d %7ld", quota[i].quota.limit,
314 + printf(" %7d " QUOTA_REPORT_FMT , quota[i].quota.limit,
315 ((quota[i].quota.used / QUOTA_UNITS) * 100) / quota[i].quota.limit);
316 }
317 else if (quota[i].quota.limit == 0) {
318 @@ -507,6 +507,6 @@
319 (*quota_namespace.mboxname_toexternal)(&quota_namespace,
320 quota[i].quota.root,
321 "cyrus", buf);
322 - printf(" %7ld %s\n", quota[i].quota.used / QUOTA_UNITS, buf);
323 + printf(" " QUOTA_REPORT_FMT " %s\n", quota[i].quota.used / QUOTA_UNITS, buf);
324 }
325 }
326 diff -Naur cyrus-imapd-2.2.12.orig/imap/quota_db.c cyrus-imapd-2.2.12/imap/quota_db.c
327 --- cyrus-imapd-2.2.12.orig/imap/quota_db.c 2004-05-22 05:45:52.000000000 +0200
328 +++ cyrus-imapd-2.2.12/imap/quota_db.c 2006-04-25 07:35:25.000000000 +0200
329 @@ -89,7 +89,7 @@
330
331 switch (r) {
332 case CYRUSDB_OK:
333 - sscanf(data, "%lu %d", &quota->used, &quota->limit);
334 + sscanf(data, UQUOTA_T_FMT " %d", &quota->used, &quota->limit);
335 break;
336
337 case CYRUSDB_AGAIN:
338 @@ -151,7 +151,7 @@
339 if (!qrlen) return IMAP_QUOTAROOT_NONEXISTENT;
340
341 len = snprintf(buf, sizeof(buf) - 1,
342 - "%lu %d", quota->used, quota->limit);
343 + UQUOTA_T_FMT " %d", quota->used, quota->limit);
344 r = QDB->store(qdb, quota->root, qrlen, buf, len, tid);
345
346 switch (r) {
347 diff -Naur cyrus-imapd-2.2.12.orig/imap/quota.h cyrus-imapd-2.2.12/imap/quota.h
348 --- cyrus-imapd-2.2.12.orig/imap/quota.h 2004-02-27 18:44:56.000000000 +0100
349 +++ cyrus-imapd-2.2.12/imap/quota.h 2006-04-25 07:35:25.000000000 +0200
350 @@ -45,18 +45,37 @@
351 #define INCLUDED_QUOTA_H
352
353 #include "cyrusdb.h"
354 +#include <config.h>
355
356 #define FNAME_QUOTADB "/quotas.db"
357
358 #define QUOTA_UNITS (1024)
359
360 +/* Define the proper quota type, it should either be a
361 + * long or a long long int depending upon what the
362 + * the compiler supports.
363 + */
364 +#ifdef HAVE_LONG_LONG_INT
365 +typedef unsigned long long int uquota_t;
366 +typedef long long int quota_t;
367 +#define UQUOTA_T_FMT "%llu"
368 +#define QUOTA_T_FMT "%lld"
369 +#define QUOTA_REPORT_FMT "%8llu"
370 +#else
371 +typedef unsigned long uquota_t;
372 +typedef long quota_t;
373 +#define UQUOTA_T_FMT "%lu"
374 +#define QUOTA_T_FMT "%ld"
375 +#define QUOTA_REPORT_FMT "%8lu"
376 +#endif
377 +
378 extern struct db *qdb;
379
380 struct quota {
381 char *root;
382
383 /* Information in quota entry */
384 - unsigned long used;
385 + uquota_t used;
386 int limit; /* in QUOTA_UNITS */
387 };
388
389 diff -Naur cyrus-imapd-2.2.12.orig/imap/reconstruct.c cyrus-imapd-2.2.12/imap/reconstruct.c
390 --- cyrus-imapd-2.2.12.orig/imap/reconstruct.c 2004-10-11 16:01:24.000000000 +0200
391 +++ cyrus-imapd-2.2.12/imap/reconstruct.c 2006-04-25 07:35:25.000000000 +0200
392 @@ -93,6 +93,7 @@
393 #include "retry.h"
394 #include "convert_code.h"
395 #include "util.h"
396 +#include "byteorder64.h"
397
398 extern int optind;
399 extern char *optarg;
400 @@ -434,7 +435,7 @@
401 char *list_acl, *list_part;
402 int list_type;
403
404 - unsigned long new_quota = 0;
405 + uquota_t new_quota = 0;
406
407 struct index_record message_index, old_index;
408 static struct index_record zero_index;
409 @@ -690,7 +691,14 @@
410 *((bit32 *)(buf+OFFSET_EXISTS)) = htonl(new_exists);
411 *((bit32 *)(buf+OFFSET_LAST_APPENDDATE)) = htonl(mailbox.last_appenddate);
412 *((bit32 *)(buf+OFFSET_LAST_UID)) = htonl(mailbox.last_uid);
413 +
414 + /* quotas may be 64bit now */
415 +#ifdef HAVE_LONG_LONG_INT
416 + *((bit64 *)(buf+OFFSET_QUOTA_MAILBOX_USED64)) = htonll(new_quota);
417 +#else
418 *((bit32 *)(buf+OFFSET_QUOTA_MAILBOX_USED)) = htonl(new_quota);
419 +#endif
420 +
421 *((bit32 *)(buf+OFFSET_POP3_LAST_LOGIN)) = htonl(mailbox.pop3_last_login);
422 *((bit32 *)(buf+OFFSET_UIDVALIDITY)) = htonl(mailbox.uidvalidity);
423 *((bit32 *)(buf+OFFSET_DELETED)) = htonl(new_deleted);
424 diff -Naur cyrus-imapd-2.2.12.orig/lib/byteorder64.c cyrus-imapd-2.2.12/lib/byteorder64.c
425 --- cyrus-imapd-2.2.12.orig/lib/byteorder64.c 1970-01-01 01:00:00.000000000 +0100
426 +++ cyrus-imapd-2.2.12/lib/byteorder64.c 2006-04-25 07:35:25.000000000 +0200
427 @@ -0,0 +1,95 @@
428 +/* byteorder64.c -- convert 64-bit values between host and network byte order
429 + *
430 + * Copyright (c) 2004 Carnegie Mellon University. All rights reserved.
431 + *
432 + * Redistribution and use in source and binary forms, with or without
433 + * modification, are permitted provided that the following conditions
434 + * are met:
435 + *
436 + * 1. Redistributions of source code must retain the above copyright
437 + * notice, this list of conditions and the following disclaimer.
438 + *
439 + * 2. Redistributions in binary form must reproduce the above copyright
440 + * notice, this list of conditions and the following disclaimer in
441 + * the documentation and/or other materials provided with the
442 + * distribution.
443 + *
444 + * 3. The name "Carnegie Mellon University" must not be used to
445 + * endorse or promote products derived from this software without
446 + * prior written permission. For permission or any other legal
447 + * details, please contact
448 + * Office of Technology Transfer
449 + * Carnegie Mellon University
450 + * 5000 Forbes Avenue
451 + * Pittsburgh, PA 15213-3890
452 + * (412) 268-4387, fax: (412) 268-7395
453 + * tech-transfer@andrew.cmu.edu
454 + *
455 + * 4. Redistributions of any form whatsoever must retain the following
456 + * acknowledgment:
457 + * "This product includes software developed by Computing Services
458 + * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
459 + *
460 + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
461 + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
462 + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
463 + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
464 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
465 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
466 + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
467 + *
468 + * $Id: byteorder64.c,v 1.1.2.1 2004/08/09 18:51:21 ken3 Exp $
469 + */
470 +
471 +#include <config.h>
472 +
473 +#if defined(HAVE_LONG_LONG_INT) && !defined(WORDS_BIGENDIAN)
474 +
475 +#include <netinet/in.h>
476 +
477 +/* Structure used to swap the bytes in a 64-bit unsigned long long. */
478 +union byteswap_64_u {
479 + unsigned long long a;
480 + uint32_t b[2];
481 +};
482 +
483 +/* Function to byteswap 64bit unsigned integers on
484 + * little endian machines to big endian network order.
485 + * On big endian machines this will be a null macro.
486 + * The macro htonll() is defined in byteorder64.h,
487 + * and if needed refers to _htonll() here.
488 + */
489 +unsigned long long _htonll(unsigned long long x)
490 +{
491 + union byteswap_64_u u1;
492 + union byteswap_64_u u2;
493 +
494 + u1.a = x;
495 +
496 + u2.b[0] = htonl(u1.b[1]);
497 + u2.b[1] = htonl(u1.b[0]);
498 +
499 + return u2.a;
500 +}
501 +
502 +
503 +/* Function to byteswap big endian 64bit unsigned integers
504 + * back to little endian host order on little endian machines.
505 + * As above, on big endian machines this will be a null macro.
506 + * The macro ntohll() is defined in byteorder64.h, and if needed,
507 + * refers to _ntohll() here.
508 + */
509 +unsigned long long _ntohll(unsigned long long x)
510 +{
511 + union byteswap_64_u u1;
512 + union byteswap_64_u u2;
513 +
514 + u1.a = x;
515 +
516 + u2.b[1] = ntohl(u1.b[0]);
517 + u2.b[0] = ntohl(u1.b[1]);
518 +
519 + return u2.a;
520 +}
521 +
522 +#endif /* defined(HAVE_LONG_LONG_INT) && !defined(WORDS_BIGENDIAN) */
523 diff -Naur cyrus-imapd-2.2.12.orig/lib/byteorder64.h cyrus-imapd-2.2.12/lib/byteorder64.h
524 --- cyrus-imapd-2.2.12.orig/lib/byteorder64.h 1970-01-01 01:00:00.000000000 +0100
525 +++ cyrus-imapd-2.2.12/lib/byteorder64.h 2006-04-25 07:35:25.000000000 +0200
526 @@ -0,0 +1,65 @@
527 +/* byteorder64.h -- convert 64-bit values between host and network byte order
528 + *
529 + * Copyright (c) 2004 Carnegie Mellon University. All rights reserved.
530 + *
531 + * Redistribution and use in source and binary forms, with or without
532 + * modification, are permitted provided that the following conditions
533 + * are met:
534 + *
535 + * 1. Redistributions of source code must retain the above copyright
536 + * notice, this list of conditions and the following disclaimer.
537 + *
538 + * 2. Redistributions in binary form must reproduce the above copyright
539 + * notice, this list of conditions and the following disclaimer in
540 + * the documentation and/or other materials provided with the
541 + * distribution.
542 + *
543 + * 3. The name "Carnegie Mellon University" must not be used to
544 + * endorse or promote products derived from this software without
545 + * prior written permission. For permission or any other legal
546 + * details, please contact
547 + * Office of Technology Transfer
548 + * Carnegie Mellon University
549 + * 5000 Forbes Avenue
550 + * Pittsburgh, PA 15213-3890
551 + * (412) 268-4387, fax: (412) 268-7395
552 + * tech-transfer@andrew.cmu.edu
553 + *
554 + * 4. Redistributions of any form whatsoever must retain the following
555 + * acknowledgment:
556 + * "This product includes software developed by Computing Services
557 + * at Carnegie Mellon University (http://www.cmu.edu/computing/)."
558 + *
559 + * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
560 + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
561 + * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
562 + * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
563 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
564 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
565 + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
566 + *
567 + * $Id: byteorder64.h,v 1.1.2.2 2004/08/16 11:44:34 ken3 Exp $
568 + */
569 +
570 +#ifndef _BYTEORDER64_H
571 +#define _BYTEORDER64_H
572 +
573 +#include <config.h>
574 +
575 +#ifdef HAVE_LONG_LONG_INT
576 +
577 +/* 64-bit host/network byte-order swap macros */
578 +#ifdef WORDS_BIGENDIAN
579 +#define htonll(x) (x)
580 +#define ntohll(x) (x)
581 +#else
582 +#define htonll(x) _htonll(x)
583 +#define ntohll(x) _ntohll(x)
584 +
585 +/* little-endian 64-bit host/network byte-order swap functions */
586 +extern unsigned long long _htonll(unsigned long long);
587 +extern unsigned long long _ntohll(unsigned long long);
588 +
589 +#endif /* WORDS_BIGENDIAN */
590 +#endif /* HAVE_LONG_LONG_INT */
591 +#endif /* _BYTEORDER64_H */
592 diff -Naur cyrus-imapd-2.2.12.orig/lib/Makefile.in cyrus-imapd-2.2.12/lib/Makefile.in
593 --- cyrus-imapd-2.2.12.orig/lib/Makefile.in 2004-05-28 20:03:04.000000000 +0200
594 +++ cyrus-imapd-2.2.12/lib/Makefile.in 2006-04-25 07:35:25.000000000 +0200
595 @@ -85,7 +85,7 @@
596 $(srcdir)/lsort.h $(srcdir)/stristr.h \
597 $(srcdir)/util.h $(srcdir)/xmalloc.h $(srcdir)/imapurl.h \
598 $(srcdir)/cyrusdb.h $(srcdir)/iptostring.h $(srcdir)/rfc822date.h \
599 - $(srcdir)/libcyr_cfg.h
600 + $(srcdir)/libcyr_cfg.h $(srcdir)/byteorder64.h
601
602 LIBCYR_OBJS = acl.o bsearch.o charset.o glob.o retry.o util.o \
603 libcyr_cfg.o mkgmtime.o prot.o parseaddr.o imclient.o imparse.o \
604 @@ -93,7 +93,7 @@
605 chartable.o imapurl.o nonblock_@WITH_NONBLOCK@.o lock_@WITH_LOCK@.o \
606 gmtoff_@WITH_GMTOFF@.o map_@WITH_MAP@.o $(ACL) $(AUTH) \
607 @LIBOBJS@ @CYRUSDB_OBJS@ \
608 - iptostring.o xmalloc.o wildmat.o
609 + iptostring.o xmalloc.o wildmat.o byteorder64.o
610
611 LIBCYRM_HDRS = $(srcdir)/hash.h $(srcdir)/mpool.h $(srcdir)/xmalloc.h \
612 $(srcdir)/strhash.o $(srcdir)/libconfig.h $(srcdir)/assert.h \
613 diff -Naur cyrus-imapd-2.2.12.orig/lib/prot.c cyrus-imapd-2.2.12/lib/prot.c
614 --- cyrus-imapd-2.2.12.orig/lib/prot.c 2004-02-27 23:08:56.000000000 +0100
615 +++ cyrus-imapd-2.2.12/lib/prot.c 2006-04-25 07:35:25.000000000 +0200
616 @@ -894,6 +894,31 @@
617 prot_write(s, buf, strlen(buf));
618 break;
619
620 +#ifdef HAVE_LONG_LONG_INT
621 + case 'l': {
622 + long long int ll;
623 + unsigned long long int ull;
624 +
625 + switch (*++percent) {
626 + case 'd':
627 + ll = va_arg(pvar, long long int);
628 + snprintf(buf, sizeof(buf), "%lld", ll);
629 + prot_write(s, buf, strlen(buf));
630 + break;
631 +
632 + case 'u':
633 + ull = va_arg(pvar, unsigned long long int);
634 + snprintf(buf, sizeof(buf), "%llu", ull);
635 + prot_write(s, buf, strlen(buf));
636 + break;
637 +
638 + default:
639 + abort();
640 + }
641 + break;
642 + }
643 +#endif
644 +
645 default:
646 abort();
647 }