From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: liblib: Added generic URI parsing functions. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/ba36e4380cf4 changeset: 14587:ba36e4380cf4 user: Stephan Bosch date: Sat Jun 02 17:06:21 2012 +0300 description: liblib: Added generic URI parsing functions. diffstat: src/lib/Makefile.am | 2 + src/lib/uri-util.c | 723 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/uri-util.h | 49 +++ 3 files changed, 774 insertions(+), 0 deletions(-) diffs (truncated from 799 to 300 lines): diff -r 21d67121985a -r ba36e4380cf4 src/lib/Makefile.am --- a/src/lib/Makefile.am Sat Jun 02 16:55:21 2012 +0300 +++ b/src/lib/Makefile.am Sat Jun 02 17:06:21 2012 +0300 @@ -121,6 +121,7 @@ unlink-directory.c \ unlink-old-files.c \ unichar.c \ + uri-util.c \ utc-offset.c \ utc-mktime.c \ var-expand.c \ @@ -228,6 +229,7 @@ unlink-directory.h \ unlink-old-files.h \ unichar.h \ + uri-util.h \ utc-offset.h \ utc-mktime.h \ var-expand.h \ diff -r 21d67121985a -r ba36e4380cf4 src/lib/uri-util.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/uri-util.c Sat Jun 02 17:06:21 2012 +0300 @@ -0,0 +1,723 @@ +/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "str.h" +#include "network.h" +#include "uri-util.h" + +#include + +/* + * Generic URI parsing. + * + * [URI-GEN] RFC3986 Appendix A: + * + * host = IP-literal / IPv4address / reg-name + * port = *DIGIT + * reg-name = *( unreserved / pct-encoded / sub-delims ) + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" + * pct-encoded = "%" HEXDIG HEXDIG + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" + * IP-literal = "[" ( IPv6address / IPvFuture ) "]" + * IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) + * IPv6address = 6( h16 ":" ) ls32 + * / "::" 5( h16 ":" ) ls32 + * / [ h16 ] "::" 4( h16 ":" ) ls32 + * / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 + * / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 + * / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 + * / [ *4( h16 ":" ) h16 ] "::" ls32 + * / [ *5( h16 ":" ) h16 ] "::" h16 + * / [ *6( h16 ":" ) h16 ] "::" + * h16 = 1*4HEXDIG + * ls32 = ( h16 ":" h16 ) / IPv4address + * IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet + * dec-octet = DIGIT ; 0-9 + * / %x31-39 DIGIT ; 10-99 + * / "1" 2DIGIT ; 100-199 + * / "2" %x30-34 DIGIT ; 200-249 + * / "25" %x30-35 ; 250-255 + */ + +#define URI_MAX_SCHEME_NAME_LEN 64 + +/* Character lookup table + * + * unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" [bit0] + * sub-delims = "!" / "$" / "&" / "'" / "(" / ")" + * / "*" / "+" / "," / ";" / "=" [bit1] + * gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" [bit2] + * pchar = unreserved / sub-delims / ":" / "@" [bit0|bit1|bit3] + * 'uchar' = unreserved / sub-delims / ":" [bit0|bit1|bit4] + * 'fchar' = pchar / "/" / "?" [bit0|bit1|bit3|bit5] + * + */ + +static unsigned const char _uri_char_lookup[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10 + 0, 2, 0, 4, 2, 0, 2, 2, 2, 2, 2, 2, 2, 1, 1, 36, // 20 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 28, 2, 0, 2, 0, 36, // 30 + 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 40 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 4, 0, 1, // 50 + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 60 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, // 70 +}; + +static inline int _decode_hex_digit(const unsigned char digit) +{ + switch (digit) { + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return digit - '0'; + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + return digit - 'a' + 0x0a; + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + return digit - 'A' + 0x0A; + } + return -1; +} + +static int +uri_parse_pct_encoded(struct uri_parser *parser, const unsigned char **p, + const unsigned char *pend, unsigned char *ch_r) +{ + int value; + + if (**p == 0 || *(*p+1) == 0 || (pend != NULL && *p+1 >= pend)) { + parser->error = "Unexpected URI boundary after '%'"; + return -1; + } + + if ((value = _decode_hex_digit(**p)) < 0) { + parser->error = t_strdup_printf( + "Expecting hex digit after '%%', but found '%c'", **p); + return -1; + } + + *ch_r = (value & 0x0f) << 4; + *p += 1; + + if ((value = _decode_hex_digit(**p)) < 0) { + parser->error = t_strdup_printf( + "Expecting hex digit after '%%%c', but found '%c'", *((*p)-1), **p); + return -1; + } + + *ch_r |= (value & 0x0f); + *p += 1; + + if (*ch_r == '\0') { + parser->error = + "Percent encoding is not allowed to encode NUL character"; + return -1; + } + return 1; +} + +static int +uri_parse_unreserved_char(struct uri_parser *parser, unsigned char *ch_r) +{ + if (*parser->cur == '%') { + parser->cur++; + if (uri_parse_pct_encoded(parser, &parser->cur, + parser->end, ch_r) <= 0) + return -1; + return 1; + } + + if ((*parser->cur & 0x80) != 0) + return 0; + + if (_uri_char_lookup[*parser->cur] & 0x01) { + *ch_r = *parser->cur; + parser->cur++; + return 1; + } + return 0; +} + +int uri_parse_unreserved(struct uri_parser *parser, string_t *part) +{ + int len = 0; + + while (parser->cur < parser->end) { + int ret; + unsigned char ch = 0; + + if ((ret = uri_parse_unreserved_char(parser, &ch)) < 0) + return -1; + + if (ret == 0) + break; + + if (part != NULL) + str_append_c(part, ch); + len++; + } + + return len > 0 ? 1 : 0; +} + +bool uri_data_decode(struct uri_parser *parser, const char *data, + const char *until, const char **decoded_r) +{ + const unsigned char *p = (const unsigned char *)data; + const unsigned char *pend = (const unsigned char *)until; + string_t *decoded; + + if (pend == NULL) { + /* NULL means unlimited; solely rely on '\0' */ + pend = (const unsigned char *)(size_t)-1; + } + + if (p >= pend || *p == '\0') { + if (decoded_r != NULL) + *decoded_r = ""; + return TRUE; + } + + decoded = uri_parser_get_tmpbuf(parser, 256); + while (p < pend && *p != '\0') { + unsigned char ch; + + if (*p == '%') { + p++; + if (uri_parse_pct_encoded(parser, &p, NULL, &ch) <= 0) + return FALSE; + + str_append_c(decoded, ch); + } else { + str_append_c(decoded, *p); + p++; + } + } + + if (decoded_r != NULL) + *decoded_r = t_strdup(str_c(decoded)); + return TRUE; +} + +const char *uri_cut_scheme(const char **uri_p) +{ + const char *p = *uri_p; + const char *scheme; + size_t len = 1; + + /* RFC 3968: + * scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) + */ + + if (!i_isalpha(*p)) + return NULL; + p++; + + while (len < URI_MAX_SCHEME_NAME_LEN && *p != '\0') { + if (!i_isalnum(*p) && *p != '+' && *p != '-' && *p != '.') + break; + p++; + len++; + } + + if (*p != ':') + return NULL; + + scheme = t_strdup_until(*uri_p, p); + *uri_p = p + 1; + + return scheme; +} + +int uri_parse_scheme(struct uri_parser *parser, const char **scheme_r) +{ + const char *p; + + if (parser->cur >= parser->end) + return 0; + + p = (const char *)parser->cur; + if ((*scheme_r = uri_cut_scheme(&p)) == NULL) + return 0; + + parser->cur = (const unsigned char *)p; + return 1; +} + +static int +uri_parse_dec_octet(struct uri_parser *parser, string_t *literal, + uint8_t *octet_r) +{ + uint8_t octet = 0; + int count = 0; + + /* RFC 3986: + * + * dec-octet = DIGIT ; 0-9 + * / %x31-39 DIGIT ; 10-99 + * / "1" 2DIGIT ; 100-199 + * / "2" %x30-34 DIGIT ; 200-249 + * / "25" %x30-35 ; 250-255 + */ + + while (parser->cur < parser->end && i_isdigit(*parser->cur)) { + uint8_t prev = octet; + + octet = octet * 10 + (uint8_t)(parser->cur[0] - '0'); + if (octet < prev) + return -1; + + if (literal != NULL) + str_append_c(literal, *parser->cur); + + parser->cur++; + count++; From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: Adds ISO8601/RFC3339 date format parsing and constr... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/21d67121985a changeset: 14586:21d67121985a user: Stephan Bosch date: Sat Jun 02 16:55:21 2012 +0300 description: Adds ISO8601/RFC3339 date format parsing and construction support. Interface is somewhat based on message date parser in src/lib-mail, but it also provides access to struct tm. diffstat: src/lib/Makefile.am | 3 + src/lib/iso8601-date.c | 305 ++++++++++++++++++++++++++++++++++++++++++++ src/lib/iso8601-date.h | 21 +++ src/lib/test-iso8601-date.c | 145 ++++++++++++++++++++ src/lib/test-lib.c | 1 + src/lib/test-lib.h | 1 + 6 files changed, 476 insertions(+), 0 deletions(-) diffs (truncated from 532 to 300 lines): diff -r 8bb23c123ea3 -r 21d67121985a src/lib/Makefile.am --- a/src/lib/Makefile.am Tue May 22 23:19:16 2012 +0300 +++ b/src/lib/Makefile.am Sat Jun 02 16:55:21 2012 +0300 @@ -52,6 +52,7 @@ ipwd.c \ iostream.c \ iostream-rawlog.c \ + iso8601-date.c \ istream.c \ istream-base64-encoder.c \ istream-concat.c \ @@ -171,6 +172,7 @@ iostream-private.h \ iostream-rawlog.h \ iostream-rawlog-private.h \ + iso8601-date.h \ istream.h \ istream-base64-encoder.h \ istream-concat.h \ @@ -252,6 +254,7 @@ test-crc32.c \ test-hash-format.c \ test-hex-binary.c \ + test-iso8601-date.c \ test-istream-base64-encoder.c \ test-istream-concat.c \ test-istream-crlf.c \ diff -r 8bb23c123ea3 -r 21d67121985a src/lib/iso8601-date.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/iso8601-date.c Sat Jun 02 16:55:21 2012 +0300 @@ -0,0 +1,305 @@ +#include "lib.h" +#include "utc-offset.h" +#include "utc-mktime.h" +#include "iso8601-date.h" + +#include + +/* RFC3339/ISO8601 date-time syntax + + date-fullyear = 4DIGIT + date-month = 2DIGIT ; 01-12 + date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on + ; month/year + time-hour = 2DIGIT ; 00-23 + time-minute = 2DIGIT ; 00-59 + time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second + ; rules + time-secfrac = "." 1*DIGIT + time-numoffset = ("+" / "-") time-hour ":" time-minute + time-offset = "Z" / time-numoffset + + partial-time = time-hour ":" time-minute ":" time-second [time-secfrac] + full-date = date-fullyear "-" date-month "-" date-mday + full-time = partial-time time-offset + + date-time = full-date "T" full-time + */ + +struct iso8601_date_parser { + const unsigned char *cur, *end; + + struct tm tm; + int timezone_offset; +}; + +static inline int +iso8601_date_parse_number(struct iso8601_date_parser *parser, + int digits, int *number_r) +{ + int i; + + if (parser->cur >= parser->end || !i_isdigit(parser->cur[0])) + return 0; + + *number_r = parser->cur[0] - '0'; + parser->cur++; + + for (i=0; i < digits-1; i++) { + if (parser->cur >= parser->end || !i_isdigit(parser->cur[0])) + return -1; + *number_r = ((*number_r) * 10) + parser->cur[0] - '0'; + parser->cur++; + } + return 1; +} + +static int +iso8601_date_parse_secfrac(struct iso8601_date_parser *parser) +{ + /* time-secfrac = "." 1*DIGIT + + NOTE: Currently not applied anywhere, so fraction is just skipped. + */ + + /* "." */ + if (parser->cur >= parser->end || parser->cur[0] != '.') + return 0; + parser->cur++; + + /* 1DIGIT */ + if (parser->cur >= parser->end || !i_isdigit(parser->cur[0])) + return -1; + parser->cur++; + + /* *DIGIT */ + while (parser->cur < parser->end && i_isdigit(parser->cur[0])) + parser->cur++; + return 1; +} + +static int is08601_date_parse_time_offset(struct iso8601_date_parser *parser) +{ + int tz_sign = 1, tz_hour = 0, tz_min = 0; + + /* time-offset = "Z" / time-numoffset + time-numoffset = ("+" / "-") time-hour ":" time-minute + time-hour = 2DIGIT ; 00-23 + time-minute = 2DIGIT ; 00-59 + */ + + if (parser->cur >= parser->end) + return 0; + + /* time-offset = "Z" / time-numoffset */ + switch (parser->cur[0]) { + case '-': + tz_sign = -1; + + case '+': + parser->cur++; + + /* time-hour = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &tz_hour) <= 0) + return -1; + if (tz_hour > 23) + return -1; + + /* ":" */ + if (parser->cur >= parser->end || parser->cur[0] != ':') + return -1; + parser->cur++; + + /* time-minute = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &tz_min) <= 0) + return -1; + if (tz_min > 59) + return -1; + break; + case 'Z': + case 'z': + parser->cur++; + break; + default: + return -1; + } + + parser->timezone_offset = tz_sign*(tz_hour*60 + tz_min); + return 1; +} + +static int is08601_date_parse_full_time(struct iso8601_date_parser *parser) +{ + /* full-time = partial-time time-offset + partial-time = time-hour ":" time-minute ":" time-second [time-secfrac] + time-hour = 2DIGIT ; 00-23 + time-minute = 2DIGIT ; 00-59 + time-second = 2DIGIT ; 00-58, 00-59, 00-60 based on leap second + ; rules + */ + + /* time-hour = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &parser->tm.tm_hour) <= 0) + return -1; + + /* ":" */ + if (parser->cur >= parser->end || parser->cur[0] != ':') + return -1; + parser->cur++; + + /* time-minute = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &parser->tm.tm_min) <= 0) + return -1; + + /* ":" */ + if (parser->cur >= parser->end || parser->cur[0] != ':') + return -1; + parser->cur++; + + /* time-second = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &parser->tm.tm_sec) <= 0) + return -1; + + /* [time-secfrac] */ + if (iso8601_date_parse_secfrac(parser) < 0) + return -1; + + /* time-offset */ + if (is08601_date_parse_time_offset(parser) <= 0) + return -1; + return 1; +} + +static int is08601_date_parse_full_date(struct iso8601_date_parser *parser) +{ + /* full-date = date-fullyear "-" date-month "-" date-mday + date-fullyear = 4DIGIT + date-month = 2DIGIT ; 01-12 + date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on + ; month/year + */ + + /* date-fullyear = 4DIGIT */ + if (iso8601_date_parse_number(parser, 4, &parser->tm.tm_year) <= 0) + return -1; + if (parser->tm.tm_year < 1900) + return -1; + parser->tm.tm_year -= 1900; + + /* "-" */ + if (parser->cur >= parser->end || parser->cur[0] != '-') + return -1; + parser->cur++; + + /* date-month = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &parser->tm.tm_mon) <= 0) + return -1; + parser->tm.tm_mon -= 1; + + /* "-" */ + if (parser->cur >= parser->end || parser->cur[0] != '-') + return -1; + parser->cur++; + + /* time-second = 2DIGIT */ + if (iso8601_date_parse_number(parser, 2, &parser->tm.tm_mday) <= 0) + return -1; + return 1; +} + +static int iso8601_date_parse_date_time(struct iso8601_date_parser *parser) +{ + /* date-time = full-date "T" full-time */ + + /* full-date */ + if (is08601_date_parse_full_date(parser) <= 0) + return -1; + + /* "T" */ + if (parser->cur >= parser->end || + (parser->cur[0] != 'T' && parser->cur[0] != 't')) + return -1; + parser->cur++; + + /* full-time */ + if (is08601_date_parse_full_time(parser) <= 0) + return -1; + + if (parser->cur != parser->end) + return -1; + return 1; +} + +static bool +iso8601_date_do_parse(const unsigned char *data, size_t size, struct tm *tm_r, + time_t *timestamp_r, int *timezone_offset_r) +{ + struct iso8601_date_parser parser; + time_t timestamp; + + memset(&parser, 0, sizeof(parser)); + parser.cur = data; + parser.end = data + size; + + if (iso8601_date_parse_date_time(&parser) <= 0) + return FALSE; + + parser.tm.tm_isdst = -1; + timestamp = utc_mktime(&parser.tm); + if (timestamp == (time_t)-1) + return FALSE; + + if (timezone_offset_r != NULL) + *timezone_offset_r = parser.timezone_offset; + if (tm_r != NULL) + *tm_r = parser.tm; + if (timestamp_r != NULL) + *timestamp_r = timestamp - parser.timezone_offset * 60; + return TRUE; +} + +bool iso8601_date_parse(const unsigned char *data, size_t size, + time_t *timestamp_r, int *timezone_offset_r) +{ + return iso8601_date_do_parse(data, size, NULL, + timestamp_r, timezone_offset_r); +} + +bool iso8601_date_parse_tm(const unsigned char *data, size_t size, + struct tm *tm_r, int *timezone_offset_r) From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: Added chain istream. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/2d9b13930a6a changeset: 14588:2d9b13930a6a user: Stephan Bosch date: Sat Jun 02 17:12:06 2012 +0300 description: Added chain istream. This is a nephew of the concat stream with the difference that new child streams can be added dynamically. diffstat: src/lib/Makefile.am | 2 + src/lib/istream-chain.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/istream-chain.h | 18 +++ 3 files changed, 284 insertions(+), 0 deletions(-) diffs (truncated from 309 to 300 lines): diff -r ba36e4380cf4 -r 2d9b13930a6a src/lib/Makefile.am --- a/src/lib/Makefile.am Sat Jun 02 17:06:21 2012 +0300 +++ b/src/lib/Makefile.am Sat Jun 02 17:12:06 2012 +0300 @@ -55,6 +55,7 @@ iso8601-date.c \ istream.c \ istream-base64-encoder.c \ + istream-chain.c \ istream-concat.c \ istream-crlf.c \ istream-data.c \ @@ -176,6 +177,7 @@ iso8601-date.h \ istream.h \ istream-base64-encoder.h \ + istream-chain.h \ istream-concat.h \ istream-crlf.h \ istream-private.h \ diff -r ba36e4380cf4 -r 2d9b13930a6a src/lib/istream-chain.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/istream-chain.c Sat Jun 02 17:12:06 2012 +0300 @@ -0,0 +1,264 @@ +/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "llist.h" +#include "istream-private.h" +#include "istream-chain.h" + +struct chain_istream; + +struct istream_chain_link { + struct istream_chain_link *prev, *next; + + uoff_t start_offset; + struct istream *stream; +}; + +struct istream_chain { + struct istream_chain_link *head, *tail; + + struct chain_istream *stream; +}; + +struct chain_istream { + struct istream_private istream; + + size_t prev_stream_left, prev_skip; + + struct istream_chain chain; +}; + +void i_stream_chain_append(struct istream_chain *chain, struct istream *stream) +{ + struct istream_chain_link *link; + + if (stream == NULL && chain->tail != NULL && chain->tail->stream == NULL) + return; + + link = i_new(struct istream_chain_link, 1); + link->stream = stream; + + if (stream != NULL) { + i_stream_ref(stream); + link->start_offset = stream->v_offset; + } + + if (chain->head == NULL && stream != NULL) { + if (chain->stream->istream.max_buffer_size == 0) { + chain->stream->istream.max_buffer_size = + stream->real_stream->max_buffer_size; + } else { + i_stream_set_max_buffer_size(stream, + chain->stream->istream.max_buffer_size); + } + } + DLLIST2_APPEND(&chain->head, &chain->tail, link); +} + +static void +i_stream_chain_set_max_buffer_size(struct iostream_private *stream, + size_t max_size) +{ + struct chain_istream *cstream = (struct chain_istream *)stream; + struct istream_chain_link *link = cstream->chain.head; + + cstream->istream.max_buffer_size = max_size; + while (link != NULL) { + if (link->stream != NULL) + i_stream_set_max_buffer_size(link->stream, max_size); + link = link->next; + } +} + +static void i_stream_chain_destroy(struct iostream_private *stream) +{ + struct chain_istream *cstream = (struct chain_istream *)stream; + struct istream_chain_link *link = cstream->chain.head; + + while (link != NULL) { + struct istream_chain_link *next = link->next; + + if (link->stream != NULL) + i_stream_unref(&link->stream); + i_free(link); + link = next; + } +} + +static void i_stream_chain_read_next(struct chain_istream *cstream) +{ + struct istream_chain_link *link = cstream->chain.head; + struct istream *prev_input; + const unsigned char *data; + size_t data_size, size; + + i_assert(link != NULL && link->stream != NULL); + i_assert(link->stream->eof); + + prev_input = link->stream; + data = i_stream_get_data(prev_input, &data_size); + + DLLIST2_REMOVE(&cstream->chain.head, &cstream->chain.tail, link); + i_free(link); + + link = cstream->chain.head; + i_assert(link == NULL || link->stream != NULL); + if (link != NULL) + i_stream_seek(link->stream, 0); + + /* we already verified that the data size is less than the + maximum buffer size */ + cstream->istream.pos = 0; + if (data_size > 0) { + if (!i_stream_get_buffer_space(&cstream->istream, data_size, &size)) + i_unreached(); + i_assert(size >= data_size); + } + + cstream->prev_stream_left = data_size; + memcpy(cstream->istream.w_buffer, data, data_size); + i_stream_skip(prev_input, data_size); + i_stream_unref(&prev_input); + cstream->istream.skip = 0; + cstream->istream.pos = data_size; +} + +static ssize_t i_stream_chain_read(struct istream_private *stream) +{ + struct chain_istream *cstream = (struct chain_istream *)stream; + struct istream_chain_link *link = cstream->chain.head; + const unsigned char *data; + size_t size, pos, cur_pos, bytes_skipped; + ssize_t ret; + bool last_stream; + + if (link != NULL && link->stream == NULL) { + stream->istream.eof = TRUE; + return -1; + } + + i_assert(stream->skip >= cstream->prev_skip); + bytes_skipped = stream->skip - cstream->prev_skip; + + if (cstream->prev_stream_left == 0) { + /* no need to worry about buffers, skip everything */ + i_assert(cstream->prev_skip == 0); + } else if (bytes_skipped < cstream->prev_stream_left) { + /* we're still skipping inside buffer */ + cstream->prev_stream_left -= bytes_skipped; + bytes_skipped = 0; + } else { + /* done with the buffer */ + bytes_skipped -= cstream->prev_stream_left; + cstream->prev_stream_left = 0; + } + + stream->pos -= bytes_skipped; + stream->skip -= bytes_skipped; + + if (link == NULL) { + i_assert(bytes_skipped == 0); + return 0; + } + + i_stream_skip(link->stream, bytes_skipped); + + cur_pos = stream->pos - stream->skip - cstream->prev_stream_left; + data = i_stream_get_data(link->stream, &pos); + if (pos > cur_pos) + ret = 0; + else { + /* need to read more */ + i_assert(cur_pos == pos); + ret = i_stream_read(link->stream); + if (ret == -2 || ret == 0) { + return ret; + } + + if (ret == -1 && link->stream->stream_errno != 0) { + stream->istream.stream_errno = + link->stream->stream_errno; + return -1; + } + + /* we either read something or we're at EOF */ + last_stream = link->next != NULL && link->next->stream == NULL; + if (ret == -1 && !last_stream) { + if (stream->pos >= stream->max_buffer_size) + return -2; + + i_stream_chain_read_next(cstream); + cstream->prev_skip = stream->skip; + return i_stream_chain_read(stream); + } + + stream->istream.eof = link->stream->eof && last_stream; + i_assert(ret != -1 || stream->istream.eof); + data = i_stream_get_data(link->stream, &pos); + } + + if (cstream->prev_stream_left == 0) { + stream->buffer = data; + stream->pos -= stream->skip; + stream->skip = 0; + } else if (pos == cur_pos) { + stream->buffer = stream->w_buffer; + } else { + stream->buffer = stream->w_buffer; + if (!i_stream_get_buffer_space(stream, pos - cur_pos, &size)) + return -2; + + if (pos > size) + pos = size; + memcpy(stream->w_buffer + stream->pos, + data + cur_pos, pos - cur_pos); + } + pos += stream->skip + cstream->prev_stream_left; + + ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) : + (ret == 0 ? 0 : -1); + + stream->pos = pos; + cstream->prev_skip = stream->skip; + return ret; +} + +static const struct stat * +i_stream_chain_stat(struct istream_private *stream ATTR_UNUSED, + bool exact ATTR_UNUSED) +{ + i_panic("istream_chain(): stat() not supported"); + return NULL; +} + +static int +i_stream_chain_get_size(struct istream_private *stream ATTR_UNUSED, + bool exact ATTR_UNUSED, uoff_t *size_r ATTR_UNUSED) +{ + i_panic("istream_chain(): get_size() not supported"); + return -1; +} + +struct istream *i_stream_create_chain(struct istream_chain **chain_r) +{ + struct chain_istream *cstream; + + cstream = i_new(struct chain_istream, 1); + cstream->chain.stream = cstream; + cstream->istream.max_buffer_size = 256; + + cstream->istream.iostream.destroy = i_stream_chain_destroy; + cstream->istream.iostream.set_max_buffer_size = + i_stream_chain_set_max_buffer_size; + + cstream->istream.read = i_stream_chain_read; + cstream->istream.stat = i_stream_chain_stat; + cstream->istream.get_size = i_stream_chain_get_size; + + cstream->istream.istream.readable_fd = FALSE; + cstream->istream.istream.blocking = FALSE; + cstream->istream.istream.seekable = FALSE; + + *chain_r = &cstream->chain; + return i_stream_create(&cstream->istream, NULL, -1); +} diff -r ba36e4380cf4 -r 2d9b13930a6a src/lib/istream-chain.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/istream-chain.h Sat Jun 02 17:12:06 2012 +0300 @@ -0,0 +1,18 @@ +#ifndef ISTREAM_CHAIN_H +#define ISTREAM_CHAIN_H + +struct istream_chain; + +/* Flexibly couple input streams into a single chain stream. Input streams can + be added after creation of the chain stream, and the chain stream will not + signal EOF until all streams are read to EOF and the last stream added was + NULL. Streams that were finished to EOF are unreferenced. The chain stream From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: imap-parser: Added IMAP_PARSE_FLAG_INSIDE_LIST flag. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c54dd35e1c0e changeset: 14589:c54dd35e1c0e user: Stephan Bosch date: Sat Jun 02 17:15:18 2012 +0300 description: imap-parser: Added IMAP_PARSE_FLAG_INSIDE_LIST flag. Adds mode flag to IMAP parser which makes it assume it is inside a (...) list, making ')' equal to EOL and '\n' an error. diffstat: src/lib-imap/imap-parser.c | 12 +++++++++++- src/lib-imap/imap-parser.h | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diffs (50 lines): diff -r 2d9b13930a6a -r c54dd35e1c0e src/lib-imap/imap-parser.c --- a/src/lib-imap/imap-parser.c Sat Jun 02 17:12:06 2012 +0300 +++ b/src/lib-imap/imap-parser.c Sat Jun 02 17:15:18 2012 +0300 @@ -171,6 +171,11 @@ if (parser->list_arg == NULL) { /* we're not inside list */ + if ((parser->flags & IMAP_PARSE_FLAG_INSIDE_LIST) != 0) { + parser->eol = TRUE; + parser->cur_type = ARG_PARSE_NONE; + return TRUE; + } parser->error = "Unexpected ')'"; return FALSE; } @@ -289,7 +294,8 @@ imap_parser_save_arg(parser, data, i); break; } else if (data[i] == ')') { - if (parser->list_arg != NULL) { + if (parser->list_arg != NULL || + (parser->flags & IMAP_PARSE_FLAG_INSIDE_LIST) != 0) { imap_parser_save_arg(parser, data, i); break; } else if ((parser->flags & @@ -498,6 +504,10 @@ /* fall through */ case '\n': /* unexpected end of line */ + if ((parser->flags & IMAP_PARSE_FLAG_INSIDE_LIST) != 0) { + parser->error = "Missing ')'"; + return FALSE; + } parser->eol = TRUE; return FALSE; case '"': diff -r 2d9b13930a6a -r c54dd35e1c0e src/lib-imap/imap-parser.h --- a/src/lib-imap/imap-parser.h Sat Jun 02 17:12:06 2012 +0300 +++ b/src/lib-imap/imap-parser.h Sat Jun 02 17:15:18 2012 +0300 @@ -16,7 +16,9 @@ /* Don't check if atom contains invalid characters */ IMAP_PARSE_FLAG_ATOM_ALLCHARS = 0x08, /* Allow strings to contain CRLFs */ - IMAP_PARSE_FLAG_MULTILINE_STR = 0x10 + IMAP_PARSE_FLAG_MULTILINE_STR = 0x10, + /* Parse in list context; ')' parses as EOL */ + IMAP_PARSE_FLAG_INSIDE_LIST = 0x20 }; struct imap_parser; From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: lib-imap: Added IMAP URL parser. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9eef4f7b0187 changeset: 14590:9eef4f7b0187 user: Stephan Bosch date: Sat Jun 02 17:53:31 2012 +0300 description: lib-imap: Added IMAP URL parser. Includes support for IMAP URLAUTH URLs. Includes extensive testsuite. Creation of IMAP URL string from struct data is not implemented and deferred to a future patch when this functionality is needed. diffstat: src/lib-imap/Makefile.am | 7 + src/lib-imap/imap-url.c | 936 +++++++++++++++++++++++++++++++++++++++++++ src/lib-imap/imap-url.h | 70 +++ src/lib-imap/test-imap-url.c | 900 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1913 insertions(+), 0 deletions(-) diffs (truncated from 1956 to 300 lines): diff -r c54dd35e1c0e -r 9eef4f7b0187 src/lib-imap/Makefile.am --- a/src/lib-imap/Makefile.am Sat Jun 02 17:15:18 2012 +0300 +++ b/src/lib-imap/Makefile.am Sat Jun 02 17:53:31 2012 +0300 @@ -16,6 +16,7 @@ imap-match.c \ imap-parser.c \ imap-quote.c \ + imap-url.c \ imap-seqset.c \ imap-utf7.c \ imap-util.c @@ -31,6 +32,7 @@ imap-parser.h \ imap-resp-code.h \ imap-quote.h \ + imap-url.h \ imap-seqset.h \ imap-utf7.h \ imap-util.h @@ -41,6 +43,7 @@ test_programs = \ test-imap-match \ test-imap-parser \ + test-imap-url \ test-imap-utf7 \ test-imap-util @@ -58,6 +61,10 @@ test_imap_parser_LDADD = imap-parser.lo imap-arg.lo $(test_libs) test_imap_parser_DEPENDENCIES = imap-parser.lo imap-arg.lo $(test_libs) +test_imap_url_SOURCES = test-imap-url.c +test_imap_url_LDADD = imap-url.lo $(test_libs) +test_imap_url_DEPENDENCIES = imap-url.lo $(test_libs) + test_imap_utf7_SOURCES = test-imap-utf7.c test_imap_utf7_LDADD = imap-utf7.lo $(test_libs) test_imap_utf7_DEPENDENCIES = imap-utf7.lo $(test_libs) diff -r c54dd35e1c0e -r 9eef4f7b0187 src/lib-imap/imap-url.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-imap/imap-url.c Sat Jun 02 17:53:31 2012 +0300 @@ -0,0 +1,936 @@ +/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "str.h" +#include "strfuncs.h" +#include "str-sanitize.h" +#include "hex-binary.h" +#include "network.h" +#include "iso8601-date.h" +#include "uri-util.h" + +#include "imap-url.h" + +#include + +/* + * IMAP URL parsing + */ + +/* +IMAP URL Grammar overview + +RFC5092 Section 11: + +imapurl = "imap://" iserver ipath-query + ; Defines an absolute IMAP URL +iserver = [iuserinfo "@"] host [ ":" port ] + ; This is the same as "authority" defined in [URI-GEN]. +iuserinfo = enc-user [iauth] / [enc-user] iauth + ; conforms to the generic syntax of "userinfo" as + ; defined in [URI-GEN]. +enc-user = 1*achar + ; %-encoded version of [IMAP4] authorization identity or + ; "userid". +iauth = ";AUTH=" ( "*" / enc-auth-type ) +enc-auth-type = 1*achar + ; %-encoded version of [IMAP4] "auth-type" +ipath-query = ["/" [ icommand ]] + ; Corresponds to "path-abempty [ "?" query ]" in + ; [URI-GEN] +icommand = imessagelist / + imessagepart [iurlauth] +imessagelist = imailbox-ref [ "?" enc-search ] + ; "enc-search" is [URI-GEN] "query". +imessagepart = imailbox-ref iuid [isection] [ipartial] +imailbox-ref = enc-mailbox [uidvalidity] +uidvalidity = ";UIDVALIDITY=" nz-number + ; See [IMAP4] for "nz-number" definition +iuid = "/" iuid-only +iuid-only = ";UID=" nz-number + ; See [IMAP4] for "nz-number" definition +isection = "/" isection-only +isection-only = ";SECTION=" enc-section +ipartial = "/" ipartial-only +ipartial-only = ";PARTIAL=" partial-range +enc-search = 1*bchar + ; %-encoded version of [IMAPABNF] + ; "search-program". Note that IMAP4 + ; literals may not be used in + ; a "search-program", i.e., only + ; quoted or non-synchronizing + ; literals (if the server supports + ; LITERAL+ [LITERAL+]) are allowed. +enc-mailbox = 1*bchar + ; %-encoded version of [IMAP4] "mailbox" +enc-section = 1*bchar + ; %-encoded version of [IMAP4] "section-spec" +partial-range = number ["." nz-number] + ; partial FETCH. The first number is + ; the offset of the first byte, + ; the second number is the length of + ; the fragment. +bchar = achar / ":" / "@" / "/" +achar = uchar / "&" / "=" + ;; Same as [URI-GEN] 'unreserved / sub-delims / + ;; pct-encoded', but ";" is disallowed. +uchar = unreserved / sub-delims-sh / pct-encoded +sub-delims-sh = "!" / "$" / "'" / "(" / ")" / + "*" / "+" / "," + ;; Same as [URI-GEN] sub-delims, + ;; but without ";", "&" and "=". + +The following rules are only used in the presence of the IMAP +[URLAUTH] extension: + +authimapurl = "imap://" iserver "/" imessagepart + ; Same as "imapurl" when "[icommand]" is + ; "imessagepart" +authimapurlfull = authimapurl iurlauth + ; Same as "imapurl" when "[icommand]" is + ; "imessagepart iurlauth" +authimapurlrump = authimapurl iurlauth-rump + +iurlauth = iurlauth-rump iua-verifier +enc-urlauth = 32*HEXDIG +iua-verifier = ":" uauth-mechanism ":" enc-urlauth +iurlauth-rump = [expire] ";URLAUTH=" access +access = ("submit+" enc-user) / ("user+" enc-user) / + "authuser" / "anonymous" +expire = ";EXPIRE=" date-time + ; date-time is defined in [DATETIME] +uauth-mechanism = "INTERNAL" / 1*(ALPHA / DIGIT / "-" / ".") + ; Case-insensitive. + +[URI-GEN] RFC3986 Appendix A: + +Implemented in src/lib/uri-util.c + +*/ + +/* + * Imap URL parser + */ + +struct imap_url_parser { + struct uri_parser parser; + + enum imap_url_parse_flags flags; + + struct imap_url *url; + struct imap_url *base; + + unsigned int relative:1; +}; + +static int +imap_url_parse_number(struct uri_parser *parser, const char *data, + uint32_t *number_r) +{ + uint32_t number = 0; + const char *p = data; + + /* [IMAP4] RFC3501, Section 9 + * + * number = 1*DIGIT + * ; Unsigned 32-bit integer + * ; (0 <= n < 4,294,967,296) + */ + + if (i_isdigit(*p)) { + do { + uint32_t prev = number; + + number = number * 10 + (*p - '0'); + if (number < prev) { + parser->error = "IMAP number is too high"; + return -1; + } + p++; + } while (i_isdigit(*p)); + + if (*p == '\0') { + if (number_r != NULL) + *number_r = number; + return 1; + } + } + + parser->error = t_strdup_printf( + "Value '%s' is not a valid IMAP number", data); + return -1; +} + +static int +imap_url_parse_offset(struct uri_parser *parser, const char *data, + uoff_t *number_r) +{ + uoff_t number = 0; + const char *p = data; + + /* Syntax for big (uoff_t) numbers. Not strictly IMAP syntax, but this + is handled similarly for Dovecot IMAP FETCH BODY partial <.> + implementation. */ + if (i_isdigit(*p)) { + do { + uoff_t prev = number; + + number = number * 10 + (*p - '0'); + if (number < prev) { + parser->error = "IMAP number is too high"; + return -1; + } + p++; + } while (i_isdigit(*p)); + + if (*p == '\0') { + if (number_r != NULL) + *number_r = number; + return 1; + } + } + + parser->error = t_strdup_printf( + "Value '%s' is not a valid IMAP number", data); + return -1; +} + +static int imap_url_parse_iserver(struct imap_url_parser *url_parser) +{ + struct uri_parser *parser = &url_parser->parser; + struct uri_authority auth; + struct imap_url *url = url_parser->url; + const char *data; + int ret = 0; + + /* imapurl = "imap://" iserver {...} + * inetwork-path = "//" iserver {...} + * iserver = [iuserinfo "@"] host [":" port] + * ; This is the same as "authority" defined + * ; in [URI-GEN]. + * iuserinfo = enc-user [iauth] / [enc-user] iauth + * ; conforms to the generic syntax of "userinfo" as + * ; defined in [URI-GEN]. + * enc-user = 1*achar + * ; %-encoded version of [IMAP4] authorization identity or + * ; "userid". + * iauth = ";AUTH=" ( "*" / enc-auth-type ) + * enc-auth-type = 1*achar + * ; %-encoded version of [IMAP4] "auth-type" + */ + + /* "//" iserver */ + if ((ret = uri_parse_authority(parser, &auth)) <= 0) + return ret; + + /* iuserinfo = enc-user [iauth] / [enc-user] iauth */ + if (auth.enc_userinfo != NULL) { + const char *p; + + /* Scan for ";AUTH=" */ + p = strchr(auth.enc_userinfo, ';'); + if (p != NULL) { + if (strncasecmp(p, ";AUTH=",6) != 0) { + parser->error = t_strdup_printf( + "Stray ';' in userinfo `%s'", + auth.enc_userinfo); + return -1; + } + + if (strchr(p+1, ';') != NULL) { + parser->error = "Stray ';' after `;AUTH='"; + return -1; + } + } + + /* enc-user */ + if (url != NULL && p != auth.enc_userinfo) { + if (!uri_data_decode(parser, auth.enc_userinfo, p, &data)) + return -1; + url->userid = p_strdup(parser->pool, data); + } + + /* ( "*" / enc-auth-type ) */ + if (p != NULL) { + p += 6; + if (*p == '\0') { + parser->error = "Empty auth-type value after ';AUTH='"; From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: imap: Implemented CATENATE extension. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/5344ff4215b4 changeset: 14592:5344ff4215b4 user: Stephan Bosch date: Sat Jun 02 18:14:16 2012 +0300 description: imap: Implemented CATENATE extension. diffstat: README | 1 + configure.in | 2 +- src/imap/cmd-append.c | 633 +++++++++++++++++++++++++++++++++++-------------- 3 files changed, 453 insertions(+), 183 deletions(-) diffs (truncated from 793 to 300 lines): diff -r 07e6ca397a72 -r 5344ff4215b4 README --- a/README Sat Jun 02 17:56:27 2012 +0300 +++ b/README Sat Jun 02 18:14:16 2012 +0300 @@ -40,6 +40,7 @@ 3691 - IMAP4 UNSELECT command 4314 - IMAP4 Access Control List (ACL) Extension 4315 - IMAP UIDPLUS extension + 4469 - IMAP CATENATE Extension 4551 - IMAP Extension for Conditional STORE Operation or Quick Flag Changes Resynchronization 4731 - IMAP4 Extension to SEARCH Command for Controlling diff -r 07e6ca397a72 -r 5344ff4215b4 configure.in --- a/configure.in Sat Jun 02 17:56:27 2012 +0300 +++ b/configure.in Sat Jun 02 18:14:16 2012 +0300 @@ -2704,7 +2704,7 @@ dnl IDLE doesn't really belong to banner. It's there just to make Blackberries dnl happy, because otherwise BIS server disables push email. capability_banner="IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE" -capability="$capability_banner SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE" +capability="$capability_banner SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS SPECIAL-USE" AC_DEFINE_UNQUOTED(CAPABILITY_STRING, "$capability", IMAP capabilities) AC_DEFINE_UNQUOTED(CAPABILITY_BANNER_STRING, "$capability_banner", IMAP capabilities advertised in banner) diff -r 07e6ca397a72 -r 5344ff4215b4 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Sat Jun 02 17:56:27 2012 +0300 +++ b/src/imap/cmd-append.c Sat Jun 02 18:14:16 2012 +0300 @@ -3,12 +3,14 @@ #include "imap-common.h" #include "ioloop.h" #include "istream.h" +#include "istream-chain.h" #include "ostream.h" #include "str.h" #include "imap-parser.h" #include "imap-date.h" #include "imap-util.h" #include "imap-commands.h" +#include "imap-msgpart-url.h" #include @@ -26,14 +28,19 @@ struct mailbox_transaction_context *t; time_t started; + struct istream_chain *catchain; + uoff_t cat_msg_size; + struct istream *input; - uoff_t msg_size; + struct istream *litinput; + uoff_t literal_size; struct imap_parser *save_parser; struct mail_save_context *save_ctx; unsigned int count; unsigned int message_input:1; + unsigned int catenate:1; unsigned int failed:1; }; @@ -50,7 +57,7 @@ ctx->count, secs); if (ctx->input != NULL) { str_printfa(str, ", %"PRIuUOFF_T"/%"PRIuUOFF_T" bytes", - ctx->input->v_offset, ctx->msg_size); + ctx->input->v_offset, ctx->literal_size); } str_append_c(str, ')'); return str_c(str); @@ -112,37 +119,6 @@ client_continue_pending_input(client); } -/* Returns -1 = error, 0 = need more data, 1 = successful. flags and - internal_date may be NULL as a result, but mailbox and msg_size are always - set when successful. */ -static int validate_args(const struct imap_arg *args, - const struct imap_arg **flags_r, - const char **internal_date_r, uoff_t *msg_size_r, - bool *nonsync_r) -{ - /* [] */ - if (!imap_arg_get_list(args, flags_r)) - *flags_r = NULL; - else - args++; - - /* [] */ - if (args->type != IMAP_ARG_STRING) - *internal_date_r = NULL; - else { - *internal_date_r = imap_arg_as_astring(args); - args++; - } - - if (!imap_arg_get_literal_size(args, msg_size_r)) { - *nonsync_r = FALSE; - return FALSE; - } - - *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; - return TRUE; -} - static void cmd_append_finish(struct cmd_append_context *ctx) { imap_parser_unref(&ctx->save_parser); @@ -155,6 +131,8 @@ o_stream_set_flush_callback(ctx->client->output, client_output, ctx->client); + if (ctx->litinput != NULL) + i_stream_unref(&ctx->litinput); if (ctx->input != NULL) i_stream_unref(&ctx->input); if (ctx->save_ctx != NULL) @@ -184,11 +162,10 @@ return TRUE; } - if (ctx->input->v_offset == ctx->msg_size) { + if (ctx->litinput->v_offset == ctx->literal_size) { /* finished, but with MULTIAPPEND and LITERAL+ we may get more messages. */ - i_stream_unref(&ctx->input); - ctx->input = NULL; + i_stream_unref(&ctx->litinput); ctx->message_input = FALSE; imap_parser_reset(ctx->save_parser); @@ -210,7 +187,7 @@ /* we have to read the nonsynced literal so we don't treat the message data as commands. */ - ctx->input = i_stream_create_limit(ctx->client->input, ctx->msg_size); + ctx->input = i_stream_create_limit(ctx->client->input, ctx->literal_size); ctx->message_input = TRUE; ctx->cmd->func = cmd_append_continue_cancel; @@ -218,20 +195,405 @@ return cmd_append_continue_cancel(ctx->cmd); } +static int +cmd_append_catenate(struct client_command_context *cmd, + const struct imap_arg *args, bool *nonsync_r) +{ + struct client *client = cmd->client; + struct cmd_append_context *ctx = cmd->context; + struct imap_msgpart_url *mpurl; + const char *catpart, *error; + uoff_t newsize; + int ret; + + *nonsync_r = FALSE; + + /* Handle URLs until a TEXT literal is encountered */ + while (imap_arg_get_atom(args, &catpart)) { + const char *caturl; + + if (strcasecmp(catpart, "URL") == 0 ) { + /* URL */ + args++; + if (!imap_arg_get_astring(args, &caturl)) + break; + if (ctx->failed) + return -1; + + mpurl = imap_msgpart_url_parse(client->user, client->mailbox, caturl, &error); + if (mpurl == NULL) { + /* invalid url, abort */ + client_send_tagline(cmd, + t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); + return -1; + } + + if (cmd->cancel) { + imap_msgpart_url_free(&mpurl); + cmd_append_finish(ctx); + return 1; + } + + /* catenate URL */ + if (ctx->save_ctx != NULL) { + struct istream *input = NULL; + uoff_t size; + + if (!imap_msgpart_url_read_part(mpurl, &input, &size, &error)) { + /* invalid url, abort */ + client_send_tagline(cmd, + t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); + return -1; + } + + newsize = ctx->cat_msg_size + size; + if (newsize < ctx->cat_msg_size) { + client_send_tagline(cmd, + "NO [TOOBIG] Composed message grows too big."); + imap_msgpart_url_free(&mpurl); + return -1; + } + + if (input != NULL) { + ctx->cat_msg_size = newsize; + i_stream_chain_append(ctx->catchain, input); + + while (!input->eof) { + ret = i_stream_read(ctx->input); + if (mailbox_save_continue(ctx->save_ctx) < 0) { + /* we still have to finish reading the message + from client */ + mailbox_save_cancel(&ctx->save_ctx); + break; + } + if (ret == -1 || ret == 0) + break; + } + + if (!input->eof) { + client_send_tagline(cmd, t_strdup_printf( + "NO [BADURL %s] Failed to read all data.", caturl)); + imap_msgpart_url_free(&mpurl); + return -1; + } + } + } + imap_msgpart_url_free(&mpurl); + } else if (strcasecmp(catpart, "TEXT") == 0) { + /* TEXT */ + args++; + if (!imap_arg_get_literal_size(args, &ctx->literal_size)) + break; + + *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; + if (ctx->failed) { + /* we failed earlier, make sure we just eat + nonsync-literal if it's given. */ + return -1; + } + + newsize = ctx->cat_msg_size + ctx->literal_size; + if (newsize < ctx->cat_msg_size) { + client_send_tagline(cmd, + "NO [TOOBIG] Composed message grows too big."); + return -1; + } + + /* save the mail */ + ctx->cat_msg_size = newsize; + ctx->litinput = i_stream_create_limit(client->input, ctx->literal_size); + i_stream_chain_append(ctx->catchain, ctx->litinput); + return 1; + } else { + break; + } + args++; + } + + if (IMAP_ARG_IS_EOL(args)) { + /* ")" */ + return 0; + } + client_send_command_error(cmd, "Invalid arguments."); + return -1; +} + +static void cmd_append_finish_catenate(struct client_command_context *cmd) +{ + struct cmd_append_context *ctx = cmd->context; + + i_stream_chain_append(ctx->catchain, NULL); + i_stream_unref(&ctx->input); + ctx->input = NULL; + ctx->catenate = FALSE; + + if (mailbox_save_finish(&ctx->save_ctx) < 0) { + ctx->failed = TRUE; + client_send_storage_error(cmd, ctx->storage); + } +} + +static bool cmd_append_continue_catenate(struct client_command_context *cmd) +{ + struct client *client = cmd->client; + struct cmd_append_context *ctx = cmd->context; + const struct imap_arg *args; + const char *msg; + bool fatal, nonsync = FALSE; + int ret; + + if (cmd->cancel) { + cmd_append_finish(ctx); + return TRUE; + } + + ret = imap_parser_read_args(ctx->save_parser, 0, + IMAP_PARSE_FLAG_LITERAL_SIZE | + IMAP_PARSE_FLAG_INSIDE_LIST, &args); From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: Created lib-imap-storage for IMAP-specific function... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/07e6ca397a72 changeset: 14591:07e6ca397a72 user: Stephan Bosch date: Sat Jun 02 17:56:27 2012 +0300 description: Created lib-imap-storage for IMAP-specific functionality that uses lib-storage. This is done to prevent introducing dependencies on lib-storage in lib-imap. It contains IMAP message part access functionality, including URL-based access. diffstat: configure.in | 5 +- src/Makefile.am | 1 + src/imap/Makefile.am | 2 +- src/imap/imap-fetch-body.c | 53 +---- src/lib-imap-storage/Makefile.am | 21 + src/lib-imap-storage/imap-msgpart-url.c | 230 +++++++++++++++++++ src/lib-imap-storage/imap-msgpart-url.h | 29 ++ src/lib-imap-storage/imap-msgpart.c | 371 ++++++++++++++++++++++++++++++++ src/lib-imap-storage/imap-msgpart.h | 24 ++ src/lib-storage/Makefile.am | 1 + 10 files changed, 683 insertions(+), 54 deletions(-) diffs (truncated from 839 to 300 lines): diff -r 9eef4f7b0187 -r 07e6ca397a72 configure.in --- a/configure.in Sat Jun 02 17:53:31 2012 +0300 +++ b/configure.in Sat Jun 02 17:56:27 2012 +0300 @@ -2512,13 +2512,13 @@ if test "$want_shared_libs" = "yes"; then LIBDOVECOT_DEPS='$(top_builddir)/src/lib-dovecot/libdovecot.la' LIBDOVECOT="$LIBDOVECOT_DEPS" - LIBDOVECOT_STORAGE_DEPS='$(top_builddir)/src/lib-storage/libdovecot-storage.la' + LIBDOVECOT_STORAGE_DEPS='$(top_builddir)/src/lib-storage/libdovecot-storage.la $(top_builddir)/src/lib-imap-storage/libimap-storage.la' LIBDOVECOT_LOGIN='$(top_builddir)/src/login-common/libdovecot-login.la' LIBDOVECOT_LDA='$(top_builddir)/src/lib-lda/libdovecot-lda.la' else LIBDOVECOT_DEPS='$(top_builddir)/src/lib-master/libmaster.la $(top_builddir)/src/lib-settings/libsettings.la $(top_builddir)/src/lib-dict/libdict.la $(top_builddir)/src/lib-dns/libdns.la $(top_builddir)/src/lib-fs/libfs.la $(top_builddir)/src/lib-imap/libimap.la $(top_builddir)/src/lib-mail/libmail.la $(top_builddir)/src/lib-auth/libauth.la $(top_builddir)/src/lib-charset/libcharset.la $(top_builddir)/src/lib/liblib.la' LIBDOVECOT="$LIBDOVECOT_DEPS \$(LIBICONV)" - LIBDOVECOT_STORAGE_LAST='$(top_builddir)/src/lib-storage/list/libstorage_list.la $(top_builddir)/src/lib-storage/index/libstorage_index.la $(top_builddir)/src/lib-storage/libstorage.la $(top_builddir)/src/lib-index/libindex.la' + LIBDOVECOT_STORAGE_LAST='$(top_builddir)/src/lib-storage/list/libstorage_list.la $(top_builddir)/src/lib-storage/index/libstorage_index.la $(top_builddir)/src/lib-storage/libstorage.la $(top_builddir)/src/lib-index/libindex.la $(top_builddir)/src/lib-imap-storage/libimap-storage.la' LIBDOVECOT_STORAGE_FIRST='$(top_builddir)/src/lib-storage/libstorage_service.la $(top_builddir)/src/lib-storage/register/libstorage_register.la' LIBDOVECOT_STORAGE_DEPS="$LIBDOVECOT_STORAGE_FIRST $LINKED_STORAGE_LIBS $LIBDOVECOT_STORAGE_LAST" LIBDOVECOT_LOGIN='$(top_builddir)/src/login-common/liblogin.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la' @@ -2748,6 +2748,7 @@ src/lib-dns/Makefile src/lib-fs/Makefile src/lib-imap/Makefile +src/lib-imap-storage/Makefile src/lib-imap-client/Makefile src/lib-index/Makefile src/lib-lda/Makefile diff -r 9eef4f7b0187 -r 07e6ca397a72 src/Makefile.am --- a/src/Makefile.am Sat Jun 02 17:53:31 2012 +0300 +++ b/src/Makefile.am Sat Jun 02 17:56:27 2012 +0300 @@ -6,6 +6,7 @@ lib-fs \ lib-mail \ lib-imap \ + lib-imap-storage \ lib-master \ lib-dict \ lib-settings diff -r 9eef4f7b0187 -r 07e6ca397a72 src/imap/Makefile.am --- a/src/imap/Makefile.am Sat Jun 02 17:53:31 2012 +0300 +++ b/src/imap/Makefile.am Sat Jun 02 17:56:27 2012 +0300 @@ -9,6 +9,7 @@ -I$(top_srcdir)/src/lib-master \ -I$(top_srcdir)/src/lib-mail \ -I$(top_srcdir)/src/lib-imap \ + -I$(top_srcdir)/src/lib-imap-storage \ -I$(top_srcdir)/src/lib-index \ -I$(top_srcdir)/src/lib-storage @@ -78,7 +79,6 @@ mail-storage-callbacks.c \ main.c - headers = \ imap-client.h \ imap-commands.h \ diff -r 9eef4f7b0187 -r 07e6ca397a72 src/imap/imap-fetch-body.c --- a/src/imap/imap-fetch-body.c Sat Jun 02 17:53:31 2012 +0300 +++ b/src/imap/imap-fetch-body.c Sat Jun 02 17:56:27 2012 +0300 @@ -11,6 +11,7 @@ #include "message-send.h" #include "mail-storage-private.h" #include "imap-parser.h" +#include "imap-msgpart.h" #include "imap-fetch.h" #include @@ -464,63 +465,13 @@ return fetch_data(ctx, body, &size); } -/* Find message_part for section (eg. 1.3.4) */ -static int part_find(struct mail *mail, const struct imap_fetch_body_data *body, - const struct message_part **part_r, const char **section_r) -{ - struct message_part *part; - const char *path; - unsigned int num; - - if (mail_get_parts(mail, &part) < 0) - return -1; - - path = body->section; - while (*path >= '0' && *path <= '9' && part != NULL) { - /* get part number, we have already verified its validity */ - num = 0; - while (*path != '\0' && *path != '.') { - i_assert(*path >= '0' && *path <= '9'); - - num = num*10 + (*path - '0'); - path++; - } - - if (*path == '.') - path++; - - if (part->flags & MESSAGE_PART_FLAG_MULTIPART) { - /* find the part */ - part = part->children; - for (; num > 1 && part != NULL; num--) - part = part->next; - } else { - /* only 1 allowed with non-multipart messages */ - if (num != 1) - part = NULL; - } - - if (part != NULL && - (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) && - (*path >= '0' && *path <= '9')) { - /* if we continue inside the message/rfc822, skip this - body part */ - part = part->children; - } - } - - *part_r = part; - *section_r = path; - return 0; -} - static int fetch_body_mime(struct imap_fetch_context *ctx, struct mail *mail, const struct imap_fetch_body_data *body) { const struct message_part *part; const char *section; - if (part_find(mail, body, &part, §ion) < 0) + if (imap_msgpart_find(mail, body->section, &part, §ion) < 0) return -1; if (part == NULL) { diff -r 9eef4f7b0187 -r 07e6ca397a72 src/lib-imap-storage/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-imap-storage/Makefile.am Sat Jun 02 17:56:27 2012 +0300 @@ -0,0 +1,21 @@ +noinst_LTLIBRARIES = libimap-storage.la + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib \ + -I$(top_srcdir)/src/lib-test \ + -I$(top_srcdir)/src/lib-charset \ + -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-storage \ + -I$(top_srcdir)/src/lib-imap + +libimap_storage_la_SOURCES = \ + imap-msgpart.c \ + imap-msgpart-url.c + +headers = \ + imap-msgpart.h \ + imap-msgpart-url.h + +pkginc_libdir=$(pkgincludedir) +pkginc_lib_HEADERS = $(headers) + diff -r 9eef4f7b0187 -r 07e6ca397a72 src/lib-imap-storage/imap-msgpart-url.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-imap-storage/imap-msgpart-url.c Sat Jun 02 17:56:27 2012 +0300 @@ -0,0 +1,230 @@ +#include "lib.h" +#include "network.h" +#include "istream.h" +#include "message-parser.h" +#include "mail-storage.h" +#include "mail-namespace.h" +#include "imap-url.h" +#include "imap-msgpart.h" +#include "imap-msgpart-url.h" + +struct imap_msgpart_url { + char *mailbox; + uint32_t uidvalidity; + uint32_t uid; + char *section; + uoff_t partial_offset, partial_size; + + struct mail_user *user; + struct mailbox *box; + struct mailbox_transaction_context *trans; + struct mail *mail; + + struct istream *input; + uoff_t part_size; +}; + +struct imap_msgpart_url * +imap_msgpart_url_create(struct mail_user *user, const struct imap_url *url) +{ + struct imap_msgpart_url *mpurl; + + i_assert(url->mailbox != NULL && url->uid != 0 && + url->search_program == NULL); + + mpurl = i_new(struct imap_msgpart_url, 1); + mpurl->user = user; + mpurl->mailbox = i_strdup(url->mailbox); + mpurl->uidvalidity = url->uidvalidity; + mpurl->uid = url->uid; + if (url->section != NULL) + mpurl->section = i_strdup(url->section); + mpurl->partial_offset = url->partial_offset; + mpurl->partial_size = url->partial_size; + return mpurl; +} + +struct imap_msgpart_url * +imap_msgpart_url_parse(struct mail_user *user, struct mailbox *selected_box, + const char *urlstr, const char **error_r) +{ + struct mailbox_status box_status; + struct imap_url base_url, *url; + const char *error; + + /* build base url */ + memset(&base_url, 0, sizeof(base_url)); + if (selected_box != NULL) { + mailbox_get_open_status(selected_box, STATUS_UIDVALIDITY, + &box_status); + base_url.mailbox = mailbox_get_vname(selected_box); + base_url.uidvalidity = box_status.uidvalidity; + } + + /* parse url */ + url = imap_url_parse(urlstr, NULL, &base_url, + IMAP_URL_PARSE_REQUIRE_RELATIVE, &error); + if (url == NULL) { + *error_r = t_strconcat("Invalid IMAP URL: ", error, NULL); + return NULL; + } + if (url->mailbox == NULL) { + *error_r = "Mailbox-relative IMAP URL, but no mailbox selected"; + return NULL; + } + if (url->uid == 0 || url->search_program != NULL) { + *error_r = "Invalid messagepart IMAP URL"; + return NULL; + } + return imap_msgpart_url_create(user, url); +} + +struct mailbox *imap_msgpart_url_get_mailbox(struct imap_msgpart_url *mpurl) +{ + return mpurl->box; +} + +struct mailbox * +imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, + const char **error_r) +{ + struct mailbox_status box_status; + enum mail_error error_code; + enum mailbox_flags flags = MAILBOX_FLAG_READONLY; + struct mail_namespace *ns; + struct mailbox *box; + + if (mpurl->box != NULL) + return mpurl->box; + + /* find mailbox namespace */ + ns = mail_namespace_find(mpurl->user->namespaces, mpurl->mailbox); + if (ns == NULL) { + *error_r = "Nonexistent mailbox namespace"; + return NULL; + } + + /* open mailbox */ + box = mailbox_alloc(ns->list, mpurl->mailbox, flags); + if (mailbox_open(box) < 0) { + *error_r = mail_storage_get_last_error(mailbox_get_storage(box), + &error_code); + mailbox_free(&box); + return NULL; + } + + /* verify UIDVALIDITY */ + mailbox_get_open_status(box, STATUS_UIDVALIDITY, &box_status); + if (mpurl->uidvalidity > 0 && + box_status.uidvalidity != mpurl->uidvalidity) { + *error_r = "Invalid UIDVALIDITY"; + mailbox_free(&box); + return NULL; + } + mpurl->box = box; + return box; +} + +struct mail * +imap_msgpart_url_open_mail(struct imap_msgpart_url *mpurl, const char **error_r) +{ + struct mailbox_transaction_context *t; + struct mail *mail; + + if (mpurl->mail != NULL) + return mpurl->mail; + + /* open mailbox if it is not yet open */ + if (mpurl->box == NULL) { From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: Adds 'anonymous' field to struct mail_user; derived... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/e445670e7332 changeset: 14593:e445670e7332 user: Stephan Bosch date: Sat Jun 02 18:15:46 2012 +0300 description: Adds 'anonymous' field to struct mail_user; derived indirectly from userdb extra fields. Depends: none diffstat: src/lib-auth/auth-master.c | 2 ++ src/lib-auth/auth-master.h | 1 + src/lib-storage/mail-storage-service.c | 7 ++++++- src/lib-storage/mail-user.h | 2 ++ 4 files changed, 11 insertions(+), 1 deletions(-) diffs (66 lines): diff -r 5344ff4215b4 -r e445670e7332 src/lib-auth/auth-master.c --- a/src/lib-auth/auth-master.c Sat Jun 02 18:14:16 2012 +0300 +++ b/src/lib-auth/auth-master.c Sat Jun 02 18:15:46 2012 +0300 @@ -518,6 +518,8 @@ reply_r->home = p_strdup(pool, *fields + 5); else if (strncmp(*fields, "chroot=", 7) == 0) reply_r->chroot = p_strdup(pool, *fields + 7); + else if (strcmp(*fields, "anonymous") == 0) + reply_r->anonymous = TRUE; else { const char *field = p_strdup(pool, *fields); array_append(&reply_r->extra_fields, &field, 1); diff -r 5344ff4215b4 -r e445670e7332 src/lib-auth/auth-master.h --- a/src/lib-auth/auth-master.h Sat Jun 02 18:14:16 2012 +0300 +++ b/src/lib-auth/auth-master.h Sat Jun 02 18:15:46 2012 +0300 @@ -21,6 +21,7 @@ gid_t gid; const char *home, *chroot; ARRAY_TYPE(const_string) extra_fields; + unsigned int anonymous:1; }; struct auth_master_connection * diff -r 5344ff4215b4 -r e445670e7332 src/lib-storage/mail-storage-service.c --- a/src/lib-storage/mail-storage-service.c Sat Jun 02 18:14:16 2012 +0300 +++ b/src/lib-storage/mail-storage-service.c Sat Jun 02 18:15:46 2012 +0300 @@ -77,6 +77,8 @@ const struct mail_user_settings *user_set; const struct setting_parser_info *user_info; struct setting_parser_context *set_parser; + + unsigned int anonymous:1; }; struct module *mail_storage_service_modules = NULL; @@ -252,6 +254,8 @@ set_keyval(ctx, user, "mail_chroot", chroot); } + user->anonymous = reply->anonymous; + str = array_get(&reply->extra_fields, &count); for (i = 0; i < count; i++) { line = str[i]; @@ -600,7 +604,8 @@ &user->input.local_ip, &user->input.remote_ip); mail_user->uid = priv->uid == (uid_t)-1 ? geteuid() : priv->uid; mail_user->gid = priv->gid == (gid_t)-1 ? getegid() : priv->gid; - + mail_user->anonymous = user->anonymous; + mail_set = mail_user_set_get_storage_set(mail_user); if (mail_set->mail_debug) { diff -r 5344ff4215b4 -r e445670e7332 src/lib-storage/mail-user.h --- a/src/lib-storage/mail-user.h Sat Jun 02 18:14:16 2012 +0300 +++ b/src/lib-storage/mail-user.h Sat Jun 02 18:15:46 2012 +0300 @@ -45,6 +45,8 @@ /* User is an administrator. Allow operations not normally allowed for other people. */ unsigned int admin:1; + /* User is anonymous */ + unsigned int anonymous:1; /* This is an autocreated user (e.g. for shared namespace or lda raw storage) */ unsigned int autocreated:1; From dovecot at dovecot.org Sat Jun 2 19:02:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:02:27 +0300 Subject: dovecot-2.2: Error handling API changes to previous IMAP URL rel... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/27c8a6c9088d changeset: 14594:27c8a6c9088d user: Timo Sirainen date: Sat Jun 02 19:01:25 2012 +0300 description: Error handling API changes to previous IMAP URL related changes. diffstat: src/imap/cmd-append.c | 16 +++- src/lib-imap-storage/imap-msgpart-url.c | 114 +++++++++++++++-------------- src/lib-imap-storage/imap-msgpart-url.h | 32 ++++---- src/lib-imap-storage/imap-msgpart.c | 120 +++++++++++++++++-------------- src/lib-imap-storage/imap-msgpart.h | 19 ++-- src/lib-imap/imap-url.c | 21 ++--- src/lib-imap/imap-url.h | 8 +- src/lib-imap/test-imap-url.c | 6 +- src/lib/uri-util.c | 21 ++--- src/lib/uri-util.h | 2 +- 10 files changed, 190 insertions(+), 169 deletions(-) diffs (truncated from 811 to 300 lines): diff -r e445670e7332 -r 27c8a6c9088d src/imap/cmd-append.c --- a/src/imap/cmd-append.c Sat Jun 02 18:15:46 2012 +0300 +++ b/src/imap/cmd-append.c Sat Jun 02 19:01:25 2012 +0300 @@ -220,8 +220,13 @@ if (ctx->failed) return -1; - mpurl = imap_msgpart_url_parse(client->user, client->mailbox, caturl, &error); - if (mpurl == NULL) { + ret = imap_msgpart_url_parse(client->user, client->mailbox, + caturl, &mpurl, &error); + if (ret < 0) { + client_send_storage_error(cmd, ctx->storage); + return -1; + } + if (ret == 0) { /* invalid url, abort */ client_send_tagline(cmd, t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); @@ -239,7 +244,12 @@ struct istream *input = NULL; uoff_t size; - if (!imap_msgpart_url_read_part(mpurl, &input, &size, &error)) { + ret = imap_msgpart_url_read_part(mpurl, &input, &size, &error); + if (ret < 0) { + client_send_storage_error(cmd, ctx->storage); + return -1; + } + if (ret == 0) { /* invalid url, abort */ client_send_tagline(cmd, t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); diff -r e445670e7332 -r 27c8a6c9088d src/lib-imap-storage/imap-msgpart-url.c --- a/src/lib-imap-storage/imap-msgpart-url.c Sat Jun 02 18:15:46 2012 +0300 +++ b/src/lib-imap-storage/imap-msgpart-url.c Sat Jun 02 19:01:25 2012 +0300 @@ -44,9 +44,9 @@ return mpurl; } -struct imap_msgpart_url * -imap_msgpart_url_parse(struct mail_user *user, struct mailbox *selected_box, - const char *urlstr, const char **error_r) +int imap_msgpart_url_parse(struct mail_user *user, struct mailbox *selected_box, + const char *urlstr, struct imap_msgpart_url **url_r, + const char **error_r) { struct mailbox_status box_status; struct imap_url base_url, *url; @@ -62,21 +62,21 @@ } /* parse url */ - url = imap_url_parse(urlstr, NULL, &base_url, - IMAP_URL_PARSE_REQUIRE_RELATIVE, &error); - if (url == NULL) { + if (imap_url_parse(urlstr, &base_url, + IMAP_URL_PARSE_REQUIRE_RELATIVE, &url, &error) < 0) { *error_r = t_strconcat("Invalid IMAP URL: ", error, NULL); - return NULL; + return -1; } if (url->mailbox == NULL) { *error_r = "Mailbox-relative IMAP URL, but no mailbox selected"; - return NULL; + return -1; } if (url->uid == 0 || url->search_program != NULL) { *error_r = "Invalid messagepart IMAP URL"; - return NULL; + return -1; } - return imap_msgpart_url_create(user, url); + *url_r = imap_msgpart_url_create(user, url); + return 0; } struct mailbox *imap_msgpart_url_get_mailbox(struct imap_msgpart_url *mpurl) @@ -84,9 +84,8 @@ return mpurl->box; } -struct mailbox * -imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, - const char **error_r) +int imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, + struct mailbox **box_r, const char **error_r) { struct mailbox_status box_status; enum mail_error error_code; @@ -94,14 +93,16 @@ struct mail_namespace *ns; struct mailbox *box; - if (mpurl->box != NULL) - return mpurl->box; + if (mpurl->box != NULL) { + *box_r = mpurl->box; + return 1; + } /* find mailbox namespace */ ns = mail_namespace_find(mpurl->user->namespaces, mpurl->mailbox); if (ns == NULL) { *error_r = "Nonexistent mailbox namespace"; - return NULL; + return 0; } /* open mailbox */ @@ -110,7 +111,7 @@ *error_r = mail_storage_get_last_error(mailbox_get_storage(box), &error_code); mailbox_free(&box); - return NULL; + return error_code == MAIL_ERROR_TEMP ? -1 : 0; } /* verify UIDVALIDITY */ @@ -119,29 +120,32 @@ box_status.uidvalidity != mpurl->uidvalidity) { *error_r = "Invalid UIDVALIDITY"; mailbox_free(&box); - return NULL; + return 0; } mpurl->box = box; - return box; + *box_r = box; + return 1; } -struct mail * -imap_msgpart_url_open_mail(struct imap_msgpart_url *mpurl, const char **error_r) +int imap_msgpart_url_open_mail(struct imap_msgpart_url *mpurl, + struct mail **mail_r, const char **error_r) { struct mailbox_transaction_context *t; + struct mailbox *box; struct mail *mail; + int ret; - if (mpurl->mail != NULL) - return mpurl->mail; + if (mpurl->mail != NULL) { + *mail_r = mpurl->mail; + return 1; + } /* open mailbox if it is not yet open */ - if (mpurl->box == NULL) { - if (imap_msgpart_url_open_mailbox(mpurl, error_r) == NULL) - return NULL; - } + if ((ret = imap_msgpart_url_open_mailbox(mpurl, &box, error_r)) <= 0) + return ret; /* start transaction */ - t = mailbox_transaction_begin(mpurl->box, 0); + t = mailbox_transaction_begin(box, 0); mail = mail_alloc(t, 0, NULL); /* find the message */ @@ -149,64 +153,64 @@ *error_r = "Message not found"; mail_free(&mail); mailbox_transaction_rollback(&t); - return NULL; + return 0; } mpurl->trans = t; mpurl->mail = mail; - return mail; + *mail_r = mail; + return 1; } -bool imap_msgpart_url_read_part(struct imap_msgpart_url *mpurl, - struct istream **stream_r, uoff_t *size_r, - const char **error_r) +int imap_msgpart_url_read_part(struct imap_msgpart_url *mpurl, + struct istream **stream_r, uoff_t *size_r, + const char **error_r) { + struct mail *mail; struct istream *input; uoff_t part_size; + int ret; if (mpurl->input != NULL) { i_stream_seek(mpurl->input, 0); *stream_r = mpurl->input; *size_r = mpurl->part_size; - return TRUE; + return 1; } - /* open mailbox if it is not yet open */ - if (mpurl->mail == NULL) { - if (imap_msgpart_url_open_mail(mpurl, error_r) == NULL) - return FALSE; - } + /* open mail if it is not yet open */ + if ((ret = imap_msgpart_url_open_mail(mpurl, &mail, error_r)) <= 0) + return ret; /* open the referenced part as a stream */ - if (!imap_msgpart_open(mpurl->mail, mpurl->section, - mpurl->partial_offset, mpurl->partial_size, - &input, &part_size, error_r)) - return FALSE; + if ((ret = imap_msgpart_open(mail, mpurl->section, + mpurl->partial_offset, mpurl->partial_size, + &input, &part_size, error_r)) <= 0) + return ret; mpurl->input = input; mpurl->part_size = part_size; *stream_r = input; *size_r = part_size; - return TRUE; + return 1; } -bool imap_msgpart_url_verify(struct imap_msgpart_url *mpurl, - const char **error_r) +int imap_msgpart_url_verify(struct imap_msgpart_url *mpurl, + const char **error_r) { + struct mail *mail; + int ret; + if (mpurl->input != NULL) - return TRUE; + return 1; - /* open mailbox if it is not yet open */ - if (mpurl->mail == NULL) { - if (imap_msgpart_url_open_mail(mpurl, error_r) == NULL) - return FALSE; - } + /* open mail if it is not yet open */ + if ((ret = imap_msgpart_url_open_mail(mpurl, &mail, error_r)) <= 0) + return ret; /* open the referenced part as a stream */ - if (!imap_msgpart_verify(mpurl->mail, mpurl->section, error_r)) - return FALSE; - return TRUE; + return imap_msgpart_verify(mail, mpurl->section, error_r); } void imap_msgpart_url_free(struct imap_msgpart_url **_mpurl) diff -r e445670e7332 -r 27c8a6c9088d src/lib-imap-storage/imap-msgpart-url.h --- a/src/lib-imap-storage/imap-msgpart-url.h Sat Jun 02 18:15:46 2012 +0300 +++ b/src/lib-imap-storage/imap-msgpart-url.h Sat Jun 02 19:01:25 2012 +0300 @@ -4,26 +4,28 @@ struct imap_url; struct imap_msgpart_url; +/* Functions returning int return 1 on success, 0 if URL doesn't point to + valid mail, -1 on storage error. */ + struct imap_msgpart_url * imap_msgpart_url_create(struct mail_user *user, const struct imap_url *url); -struct imap_msgpart_url * -imap_msgpart_url_parse(struct mail_user *user, struct mailbox *selected_box, - const char *urlstr, const char **error_r); +int imap_msgpart_url_parse(struct mail_user *user, struct mailbox *selected_box, + const char *urlstr, struct imap_msgpart_url **url_r, + const char **error_r); -struct mailbox * -imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, - const char **error_r); +int imap_msgpart_url_open_mailbox(struct imap_msgpart_url *mpurl, + struct mailbox **box_r, const char **error_r); struct mailbox *imap_msgpart_url_get_mailbox(struct imap_msgpart_url *mpurl); -struct mail * -imap_msgpart_url_open_mail(struct imap_msgpart_url *mpurl, const char **error_r); +int imap_msgpart_url_open_mail(struct imap_msgpart_url *mpurl, + struct mail **mail_r, const char **error_r); -/* Returns NULL stream when part has zero length, e.g. when partial offset is - larger than the size of the referenced part */ -bool imap_msgpart_url_read_part(struct imap_msgpart_url *mpurl, - struct istream **stream_r, uoff_t *size_r, - const char **error_r); -bool imap_msgpart_url_verify(struct imap_msgpart_url *mpurl, - const char **error_r); +/* stream_r is set to NULL when part has zero length, e.g. when partial offset + is larger than the size of the referenced part */ +int imap_msgpart_url_read_part(struct imap_msgpart_url *mpurl, + struct istream **stream_r, uoff_t *size_r, + const char **error_r); +int imap_msgpart_url_verify(struct imap_msgpart_url *mpurl, + const char **error_r); void imap_msgpart_url_free(struct imap_msgpart_url **mpurl); From dovecot at dovecot.org Sat Jun 2 19:39:43 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 02 Jun 2012 19:39:43 +0300 Subject: dovecot-2.2: imap: Code cleanup and error handling fixes for CAT... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/848be27099c8 changeset: 14595:848be27099c8 user: Timo Sirainen date: Sat Jun 02 19:39:27 2012 +0300 description: imap: Code cleanup and error handling fixes for CATENATE diffstat: src/imap/cmd-append.c | 238 ++++++++++++++++++++++++++----------------------- 1 files changed, 125 insertions(+), 113 deletions(-) diffs (truncated from 303 to 300 lines): diff -r 27c8a6c9088d -r 848be27099c8 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Sat Jun 02 19:01:25 2012 +0300 +++ b/src/imap/cmd-append.c Sat Jun 02 19:39:27 2012 +0300 @@ -6,6 +6,7 @@ #include "istream-chain.h" #include "ostream.h" #include "str.h" +#include "mail-storage-private.h" #include "imap-parser.h" #include "imap-date.h" #include "imap-util.h" @@ -196,18 +197,116 @@ } static int +cmd_append_catenate_url(struct client_command_context *cmd, const char *caturl) +{ + struct cmd_append_context *ctx = cmd->context; + struct imap_msgpart_url *mpurl; + struct istream *input; + uoff_t size, newsize; + const char *error; + int ret; + + ret = imap_msgpart_url_parse(cmd->client->user, cmd->client->mailbox, + caturl, &mpurl, &error); + if (ret < 0) { + client_send_storage_error(cmd, ctx->storage); + return -1; + } + if (ret == 0) { + /* invalid url, abort */ + client_send_tagline(cmd, + t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); + return -1; + } + + /* catenate URL */ + ret = imap_msgpart_url_read_part(mpurl, &input, &size, &error); + if (ret < 0) { + client_send_storage_error(cmd, ctx->storage); + return -1; + } + if (ret == 0) { + /* invalid url, abort */ + client_send_tagline(cmd, + t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); + return -1; + } + if (size == 0) { + /* empty input */ + imap_msgpart_url_free(&mpurl); + return 0; + } + + newsize = ctx->cat_msg_size + size; + if (newsize < ctx->cat_msg_size) { + client_send_tagline(cmd, + "NO [TOOBIG] Composed message grows too big."); + imap_msgpart_url_free(&mpurl); + return -1; + } + + ctx->cat_msg_size = newsize; + /* add this input stream to chain */ + i_stream_chain_append(ctx->catchain, input); + input = NULL; + /* save by reading the chain stream */ + while (!i_stream_is_eof(ctx->input)) { + ret = i_stream_read(ctx->input); + i_assert(ret != 0); /* we can handle only blocking input here */ + if (mailbox_save_continue(ctx->save_ctx) < 0 || ret == -1) + break; + } + + if (ctx->input->stream_errno != 0) { + errno = ctx->input->stream_errno; + mail_storage_set_critical(ctx->box->storage, + "read(%s) failed: %m (for CATENATE URL %s)", + i_stream_get_name(input), caturl); + client_send_storage_error(cmd, ctx->storage); + ret = -1; + } else if (!input->eof) { + /* save failed */ + client_send_storage_error(cmd, ctx->storage); + ret = -1; + } else { + ret = 0; + } + imap_msgpart_url_free(&mpurl); + return 0; +} + +static int cmd_append_catenate_text(struct client_command_context *cmd) +{ + struct cmd_append_context *ctx = cmd->context; + uoff_t newsize; + + newsize = ctx->cat_msg_size + ctx->literal_size; + if (newsize < ctx->cat_msg_size) { + client_send_tagline(cmd, + "NO [TOOBIG] Composed message grows too big."); + return -1; + } + + /* save the mail */ + ctx->cat_msg_size = newsize; + ctx->litinput = i_stream_create_limit(cmd->client->input, + ctx->literal_size); + i_stream_chain_append(ctx->catchain, ctx->litinput); + return 0; +} + +static int cmd_append_catenate(struct client_command_context *cmd, const struct imap_arg *args, bool *nonsync_r) { - struct client *client = cmd->client; struct cmd_append_context *ctx = cmd->context; - struct imap_msgpart_url *mpurl; - const char *catpart, *error; - uoff_t newsize; - int ret; + const char *catpart; *nonsync_r = FALSE; + if (ctx->failed) + return -1; + /* Handle URLs until a TEXT literal is encountered */ while (imap_arg_get_atom(args, &catpart)) { const char *caturl; @@ -217,103 +316,15 @@ args++; if (!imap_arg_get_astring(args, &caturl)) break; - if (ctx->failed) + if (cmd_append_catenate_url(cmd, caturl) < 0) return -1; - - ret = imap_msgpart_url_parse(client->user, client->mailbox, - caturl, &mpurl, &error); - if (ret < 0) { - client_send_storage_error(cmd, ctx->storage); - return -1; - } - if (ret == 0) { - /* invalid url, abort */ - client_send_tagline(cmd, - t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); - return -1; - } - - if (cmd->cancel) { - imap_msgpart_url_free(&mpurl); - cmd_append_finish(ctx); - return 1; - } - - /* catenate URL */ - if (ctx->save_ctx != NULL) { - struct istream *input = NULL; - uoff_t size; - - ret = imap_msgpart_url_read_part(mpurl, &input, &size, &error); - if (ret < 0) { - client_send_storage_error(cmd, ctx->storage); - return -1; - } - if (ret == 0) { - /* invalid url, abort */ - client_send_tagline(cmd, - t_strdup_printf("NO [BADURL %s] %s.", caturl, error)); - return -1; - } - - newsize = ctx->cat_msg_size + size; - if (newsize < ctx->cat_msg_size) { - client_send_tagline(cmd, - "NO [TOOBIG] Composed message grows too big."); - imap_msgpart_url_free(&mpurl); - return -1; - } - - if (input != NULL) { - ctx->cat_msg_size = newsize; - i_stream_chain_append(ctx->catchain, input); - - while (!input->eof) { - ret = i_stream_read(ctx->input); - if (mailbox_save_continue(ctx->save_ctx) < 0) { - /* we still have to finish reading the message - from client */ - mailbox_save_cancel(&ctx->save_ctx); - break; - } - if (ret == -1 || ret == 0) - break; - } - - if (!input->eof) { - client_send_tagline(cmd, t_strdup_printf( - "NO [BADURL %s] Failed to read all data.", caturl)); - imap_msgpart_url_free(&mpurl); - return -1; - } - } - } - imap_msgpart_url_free(&mpurl); } else if (strcasecmp(catpart, "TEXT") == 0) { /* TEXT */ args++; if (!imap_arg_get_literal_size(args, &ctx->literal_size)) break; - *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; - if (ctx->failed) { - /* we failed earlier, make sure we just eat - nonsync-literal if it's given. */ - return -1; - } - - newsize = ctx->cat_msg_size + ctx->literal_size; - if (newsize < ctx->cat_msg_size) { - client_send_tagline(cmd, - "NO [TOOBIG] Composed message grows too big."); - return -1; - } - - /* save the mail */ - ctx->cat_msg_size = newsize; - ctx->litinput = i_stream_create_limit(client->input, ctx->literal_size); - i_stream_chain_append(ctx->catchain, ctx->litinput); - return 1; + return cmd_append_catenate_text(cmd) < 0 ? -1 : 1; } else { break; } @@ -334,7 +345,6 @@ i_stream_chain_append(ctx->catchain, NULL); i_stream_unref(&ctx->input); - ctx->input = NULL; ctx->catenate = FALSE; if (mailbox_save_finish(&ctx->save_ctx) < 0) { @@ -515,27 +525,30 @@ /* save the mail */ ctx->save_ctx = mailbox_save_alloc(ctx->t); mailbox_save_set_flags(ctx->save_ctx, flags, keywords); + if (keywords != NULL) + mailbox_keywords_unref(&keywords); mailbox_save_set_received_date(ctx->save_ctx, internal_date, timezone_offset); - ret = mailbox_save_begin(&ctx->save_ctx, ctx->input); - ctx->count++; - - if (cat_list != NULL && - (ret = cmd_append_catenate(cmd, cat_list, nonsync_r)) <= 0) { - if (ret < 0) - client->input_skip_line = TRUE; - return ret; - } - - if (keywords != NULL) - mailbox_keywords_unref(&keywords); - - if (ret < 0) { + if (mailbox_save_begin(&ctx->save_ctx, ctx->input) < 0) { /* save initialization failed */ client_send_storage_error(cmd, ctx->storage); return -1; } - return 1; + ctx->count++; + + if (cat_list == NULL) { + /* normal APPEND */ + return 1; + } else if ((ret = cmd_append_catenate(cmd, cat_list, nonsync_r)) < 0) { + client->input_skip_line = TRUE; + return -1; + } else if (ret == 0) { + /* CATENATE consisted only of URLs */ + return 0; + } else { + /* TEXT part found from CATENATE */ + return 1; + } } static bool cmd_append_finish_parsing(struct client_command_context *cmd) @@ -637,8 +650,7 @@ return cmd_append_finish_parsing(cmd); } - /* Handle multiple messages (IMAP URLs) while no literals are - encountered) */ + /* Handle MULTIAPPEND messages while CATENATE contains only URLs */ From dovecot at dovecot.org Mon Jun 4 14:04:30 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 14:04:30 +0300 Subject: dovecot-2.1: mdbox: Make sure map transaction won't succeed afte... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/99d31c803b7b changeset: 14546:99d31c803b7b user: Timo Sirainen date: Mon Jun 04 13:59:40 2012 +0300 description: mdbox: Make sure map transaction won't succeed after mdbox_map_atomic_set_failed() diffstat: src/lib-storage/index/dbox-multi/mdbox-map-private.h | 1 + src/lib-storage/index/dbox-multi/mdbox-map.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diffs (47 lines): diff -r 36d2aff85a69 -r 99d31c803b7b src/lib-storage/index/dbox-multi/mdbox-map-private.h --- a/src/lib-storage/index/dbox-multi/mdbox-map-private.h Tue May 29 22:22:14 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map-private.h Mon Jun 04 13:59:40 2012 +0300 @@ -57,6 +57,7 @@ unsigned int map_refreshed:1; unsigned int locked:1; unsigned int success:1; + unsigned int failed:1; }; int mdbox_map_view_lookup_rec(struct mdbox_map *map, diff -r 36d2aff85a69 -r 99d31c803b7b src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Tue May 29 22:22:14 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 @@ -519,11 +519,13 @@ void mdbox_map_atomic_set_failed(struct mdbox_map_atomic_context *atomic) { atomic->success = FALSE; + atomic->failed = TRUE; } void mdbox_map_atomic_set_success(struct mdbox_map_atomic_context *atomic) { - atomic->success = TRUE; + if (!atomic->failed) + atomic->success = TRUE; } int mdbox_map_atomic_finish(struct mdbox_map_atomic_context **_atomic) @@ -595,7 +597,7 @@ mail_index_reset_error(ctx->atomic->map->index); return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } @@ -1379,7 +1381,7 @@ if (dbox_file_append_commit(&file_appends[i]) < 0) return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } From dovecot at dovecot.org Mon Jun 4 14:04:30 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 14:04:30 +0300 Subject: dovecot-2.1: mdbox: Flush/fsync newly saved mail data before loc... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/61be33b6336c changeset: 14547:61be33b6336c user: Timo Sirainen date: Mon Jun 04 14:03:47 2012 +0300 description: mdbox: Flush/fsync newly saved mail data before locking map. This reduced the amount of time the map needs to be locked. diffstat: src/lib-storage/index/dbox-multi/mdbox-map.c | 15 +++++++++++++++ src/lib-storage/index/dbox-multi/mdbox-map.h | 2 ++ src/lib-storage/index/dbox-multi/mdbox-save.c | 6 ++++++ 3 files changed, 23 insertions(+), 0 deletions(-) diffs (53 lines): diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 14:03:47 2012 +0300 @@ -1369,6 +1369,21 @@ return 0; } +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx) +{ + struct dbox_file_append_context **file_appends; + unsigned int i, count; + + i_assert(ctx->trans == NULL); + + file_appends = array_get_modifiable(&ctx->file_appends, &count); + for (i = 0; i < count; i++) { + if (dbox_file_append_flush(file_appends[i]) < 0) + return -1; + } + return 0; +} + int mdbox_map_append_commit(struct mdbox_map_append_context *ctx) { struct dbox_file_append_context **file_appends; diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-map.h --- a/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 14:03:47 2012 +0300 @@ -115,6 +115,8 @@ int mdbox_map_append_move(struct mdbox_map_append_context *ctx, const ARRAY_TYPE(uint32_t) *map_uids, const ARRAY_TYPE(seq_range) *expunge_map_uids); +/* Flush/fsync appends. */ +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx); /* Returns 0 if ok, -1 if error. */ int mdbox_map_append_commit(struct mdbox_map_append_context *ctx); void mdbox_map_append_free(struct mdbox_map_append_context **ctx); diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-save.c --- a/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 14:03:47 2012 +0300 @@ -287,6 +287,12 @@ i_assert(ctx->ctx.finished); + /* flush/fsync writes to m.* files before locking the map */ + if (mdbox_map_append_flush(ctx->append_ctx) < 0) { + mdbox_transaction_save_rollback(_ctx); + return -1; + } + /* make sure the map gets locked */ if (mdbox_map_atomic_lock(ctx->atomic) < 0) { mdbox_transaction_save_rollback(_ctx); From dovecot at dovecot.org Mon Jun 4 14:13:16 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 14:13:16 +0300 Subject: dovecot-2.0: mdbox: Make sure map transaction won't succeed afte... Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/de5b3386a88a changeset: 13096:de5b3386a88a user: Timo Sirainen date: Mon Jun 04 13:59:40 2012 +0300 description: mdbox: Make sure map transaction won't succeed after mdbox_map_atomic_set_failed() diffstat: src/lib-storage/index/dbox-multi/mdbox-map-private.h | 1 + src/lib-storage/index/dbox-multi/mdbox-map.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diffs (47 lines): diff -r 555e4b002a7f -r de5b3386a88a src/lib-storage/index/dbox-multi/mdbox-map-private.h --- a/src/lib-storage/index/dbox-multi/mdbox-map-private.h Sat May 19 22:25:27 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map-private.h Mon Jun 04 13:59:40 2012 +0300 @@ -55,6 +55,7 @@ unsigned int map_refreshed:1; unsigned int locked:1; unsigned int success:1; + unsigned int failed:1; }; int mdbox_map_view_lookup_rec(struct mdbox_map *map, diff -r 555e4b002a7f -r de5b3386a88a src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Sat May 19 22:25:27 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 @@ -493,11 +493,13 @@ void mdbox_map_atomic_set_failed(struct mdbox_map_atomic_context *atomic) { atomic->success = FALSE; + atomic->failed = TRUE; } void mdbox_map_atomic_set_success(struct mdbox_map_atomic_context *atomic) { - atomic->success = TRUE; + if (!atomic->failed) + atomic->success = TRUE; } int mdbox_map_atomic_finish(struct mdbox_map_atomic_context **_atomic) @@ -569,7 +571,7 @@ mail_index_reset_error(ctx->atomic->map->index); return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } @@ -1294,7 +1296,7 @@ if (dbox_file_append_commit(&file_appends[i]) < 0) return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } From dovecot at dovecot.org Mon Jun 4 14:13:16 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 14:13:16 +0300 Subject: dovecot-2.0: mdbox: Flush/fsync newly saved mail data before loc... Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/f87c09103e82 changeset: 13097:f87c09103e82 user: Timo Sirainen date: Mon Jun 04 14:03:47 2012 +0300 description: mdbox: Flush/fsync newly saved mail data before locking map. This reduced the amount of time the map needs to be locked. diffstat: src/lib-storage/index/dbox-multi/mdbox-map.c | 15 +++++++++++++++ src/lib-storage/index/dbox-multi/mdbox-map.h | 2 ++ src/lib-storage/index/dbox-multi/mdbox-save.c | 6 ++++++ 3 files changed, 23 insertions(+), 0 deletions(-) diffs (53 lines): diff -r de5b3386a88a -r f87c09103e82 src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 14:03:47 2012 +0300 @@ -1284,6 +1284,21 @@ return 0; } +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx) +{ + struct dbox_file_append_context **file_appends; + unsigned int i, count; + + i_assert(ctx->trans == NULL); + + file_appends = array_get_modifiable(&ctx->file_appends, &count); + for (i = 0; i < count; i++) { + if (dbox_file_append_flush(file_appends[i]) < 0) + return -1; + } + return 0; +} + int mdbox_map_append_commit(struct mdbox_map_append_context *ctx) { struct dbox_file_append_context **file_appends; diff -r de5b3386a88a -r f87c09103e82 src/lib-storage/index/dbox-multi/mdbox-map.h --- a/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 14:03:47 2012 +0300 @@ -115,6 +115,8 @@ int mdbox_map_append_move(struct mdbox_map_append_context *ctx, const ARRAY_TYPE(uint32_t) *map_uids, const ARRAY_TYPE(seq_range) *expunge_map_uids); +/* Flush/fsync appends. */ +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx); /* Returns 0 if ok, -1 if error. */ int mdbox_map_append_commit(struct mdbox_map_append_context *ctx); void mdbox_map_append_free(struct mdbox_map_append_context **ctx); diff -r de5b3386a88a -r f87c09103e82 src/lib-storage/index/dbox-multi/mdbox-save.c --- a/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 14:03:47 2012 +0300 @@ -287,6 +287,12 @@ i_assert(ctx->ctx.finished); + /* flush/fsync writes to m.* files before locking the map */ + if (mdbox_map_append_flush(ctx->append_ctx) < 0) { + mdbox_transaction_save_rollback(_ctx); + return -1; + } + /* make sure the map gets locked */ if (mdbox_map_atomic_lock(ctx->atomic) < 0) { mdbox_transaction_save_rollback(_ctx); From dovecot at dovecot.org Mon Jun 4 17:23:19 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 17:23:19 +0300 Subject: dovecot-2.1: doveadm instance list: Added optional name paramete... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/fa75bd3245a4 changeset: 14548:fa75bd3245a4 user: Timo Sirainen date: Mon Jun 04 17:23:07 2012 +0300 description: doveadm instance list: Added optional name parameter to list only specified instance. diffstat: src/doveadm/doveadm-instance.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diffs (31 lines): diff -r 61be33b6336c -r fa75bd3245a4 src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Mon Jun 04 14:03:47 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Mon Jun 04 17:23:07 2012 +0300 @@ -42,7 +42,7 @@ return found; } -static void cmd_instance_list(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_instance_list(int argc, char *argv[]) { struct master_instance_list *list; struct master_instance_list_iter *iter; @@ -58,6 +58,9 @@ list = master_instance_list_init(MASTER_INSTANCE_PATH); iter = master_instance_list_iterate_init(list); while ((inst = master_instance_iterate_list_next(iter)) != NULL) { + if (argc > 1 && strcmp(argv[1], inst->name) != 0) + continue; + doveadm_print(inst->base_dir); doveadm_print(inst->name); doveadm_print(unixdate2str(inst->last_used)); @@ -95,7 +98,7 @@ } struct doveadm_cmd doveadm_cmd_instance[] = { - { cmd_instance_list, "instance list", "" }, + { cmd_instance_list, "instance list", "[]" }, { cmd_instance_remove, "instance remove", " | " } }; From dovecot at dovecot.org Mon Jun 4 21:22:04 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 21:22:04 +0300 Subject: dovecot-2.1: lib-master: Keep track of config paths in "instance... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/d85421a77fa1 changeset: 14549:d85421a77fa1 user: Timo Sirainen date: Mon Jun 04 21:21:28 2012 +0300 description: lib-master: Keep track of config paths in "instances" file. Normally it can be looked up from base_dir/dovecot.conf symlink, but base_dir may get deleted when system starts up. diffstat: src/lib-master/master-instance.c | 60 +++++++++++++++++++++++++++++++++++++-- src/lib-master/master-instance.h | 1 + 2 files changed, 57 insertions(+), 4 deletions(-) diffs (176 lines): diff -r fa75bd3245a4 -r d85421a77fa1 src/lib-master/master-instance.c --- a/src/lib-master/master-instance.c Mon Jun 04 17:23:07 2012 +0300 +++ b/src/lib-master/master-instance.c Mon Jun 04 21:21:28 2012 +0300 @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "abspath.h" #include "array.h" #include "istream.h" #include "ostream.h" @@ -17,6 +18,9 @@ const char *path; ARRAY_DEFINE(instances, struct master_instance); + + unsigned int locked:1; + unsigned int config_paths_changed:1; }; struct master_instance_list_iter { @@ -50,6 +54,22 @@ pool_unref(&list->pool); } +static void +master_instance_update_config_path(struct master_instance_list *list, + struct master_instance *inst) +{ + const char *path, *config_path; + + /* update instance's config path if it has changed */ + path = t_strconcat(inst->base_dir, "/"PACKAGE".conf", NULL); + if (t_readlink(path, &config_path) == 0) { + if (null_strcmp(inst->config_path, config_path) != 0) { + inst->config_path = p_strdup(list->pool, config_path); + list->config_paths_changed = TRUE; + } + } +} + static int master_instance_list_add_line(struct master_instance_list *list, const char *line) @@ -58,9 +78,9 @@ const char *const *args; time_t last_used; - /* */ + /* [] */ args = t_strsplit_tabescaped(line); - if (str_array_length(args) != 3) + if (str_array_length(args) < 3) return -1; if (str_to_time(args[0], &last_used) < 0) return -1; @@ -69,6 +89,8 @@ inst->last_used = last_used; inst->name = p_strdup(list->pool, args[1]); inst->base_dir = p_strdup(list->pool, args[2]); + inst->config_path = p_strdup_empty(list->pool, args[3]); + master_instance_update_config_path(list, inst); return 0; } @@ -117,6 +139,9 @@ str_tabescape_write(str, inst->name); str_append_c(str, '\t'); str_tabescape_write(str, inst->base_dir); + str_append_c(str, '\t'); + if (inst->config_path != NULL) + str_tabescape_write(str, inst->config_path); str_append_c(str, '\n'); (void)o_stream_send(output, str_data(str), str_len(str)); } @@ -135,6 +160,8 @@ { int fd; + i_assert(!list->locked); + *dotlock_r = NULL; fd = file_dotlock_open_mode(&dotlock_set, list->path, 0, 0644, @@ -147,6 +174,7 @@ (void)file_dotlock_delete(dotlock_r); return -1; } + list->locked = TRUE; return fd; } @@ -156,9 +184,13 @@ const char *lock_path = file_dotlock_get_lock_path(*dotlock); int ret; + i_assert(list->locked); + T_BEGIN { ret = master_instance_list_write(list, fd, lock_path); } T_END; + + list->locked = FALSE; if (ret < 0) { (void)file_dotlock_delete(dotlock); return -1; @@ -168,6 +200,7 @@ (void)file_dotlock_delete(dotlock); return -1; } + list->config_paths_changed = FALSE; return file_dotlock_replace(dotlock, 0); } @@ -201,6 +234,7 @@ inst->base_dir = p_strdup(list->pool, base_dir); } inst->last_used = time(NULL); + master_instance_update_config_path(list, inst); return master_instance_write_finish(list, fd, &dotlock); } @@ -263,6 +297,24 @@ return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1; } +static int +master_instance_list_refresh_and_update(struct master_instance_list *list) +{ + struct dotlock *dotlock; + int fd; + + if (master_instance_list_refresh(list) < 0) + return -1; + if (list->config_paths_changed && !list->locked) { + /* write new config paths */ + if ((fd = master_instance_write_init(list, &dotlock)) == -1) + return -1; + if (master_instance_write_finish(list, fd, &dotlock) < 0) + return -1; + } + return 0; +} + const struct master_instance * master_instance_list_find_by_name(struct master_instance_list *list, const char *name) @@ -272,7 +324,7 @@ i_assert(*name != '\0'); if (array_count(&list->instances) == 0) - (void)master_instance_list_refresh(list); + (void)master_instance_list_refresh_and_update(list); array_foreach(&list->instances, inst) { if (strcmp(inst->name, name) == 0) @@ -288,7 +340,7 @@ iter = i_new(struct master_instance_list_iter, 1); iter->list = list; - (void)master_instance_list_refresh(list); + (void)master_instance_list_refresh_and_update(list); return iter; } diff -r fa75bd3245a4 -r d85421a77fa1 src/lib-master/master-instance.h --- a/src/lib-master/master-instance.h Mon Jun 04 17:23:07 2012 +0300 +++ b/src/lib-master/master-instance.h Mon Jun 04 21:21:28 2012 +0300 @@ -9,6 +9,7 @@ time_t last_used; const char *name; const char *base_dir; + const char *config_path; }; struct master_instance_list *master_instance_list_init(const char *path); From dovecot at dovecot.org Mon Jun 4 21:22:04 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 21:22:04 +0300 Subject: dovecot-2.1: doveadm instance list: Added -c parameter to easily... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/ee5d838ebcbb changeset: 14550:ee5d838ebcbb user: Timo Sirainen date: Mon Jun 04 21:21:52 2012 +0300 description: doveadm instance list: Added -c parameter to easily get the instance's config path. diffstat: src/doveadm/doveadm-instance.c | 35 ++++++++++++++++++++++++++++------- 1 files changed, 28 insertions(+), 7 deletions(-) diffs (66 lines): diff -r d85421a77fa1 -r ee5d838ebcbb src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Mon Jun 04 21:21:28 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Mon Jun 04 21:21:52 2012 +0300 @@ -5,6 +5,7 @@ #include "doveadm.h" #include "doveadm-print.h" +#include #include #include #include @@ -48,19 +49,39 @@ struct master_instance_list_iter *iter; const struct master_instance *inst; const char *pidfile_path; + bool show_config = FALSE; + int c; - doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); - doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); - doveadm_print_header_simple("name"); - doveadm_print_header_simple("last used"); - doveadm_print_header_simple("running"); + while ((c = getopt(argc, argv, "c")) > 0) { + switch (c) { + case 'c': + show_config = TRUE; + break; + default: + help(&doveadm_cmd_instance[0]); + } + } + argv += optind; + + if (!show_config) { + doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); + doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); + doveadm_print_header_simple("name"); + doveadm_print_header_simple("last used"); + doveadm_print_header_simple("running"); + } list = master_instance_list_init(MASTER_INSTANCE_PATH); iter = master_instance_list_iterate_init(list); while ((inst = master_instance_iterate_list_next(iter)) != NULL) { - if (argc > 1 && strcmp(argv[1], inst->name) != 0) + if (argv[0] != NULL && strcmp(argv[0], inst->name) != 0) continue; + if (show_config) { + printf("%s\n", inst->config_path == NULL ? "" : + inst->config_path); + continue; + } doveadm_print(inst->base_dir); doveadm_print(inst->name); doveadm_print(unixdate2str(inst->last_used)); @@ -98,7 +119,7 @@ } struct doveadm_cmd doveadm_cmd_instance[] = { - { cmd_instance_list, "instance list", "[]" }, + { cmd_instance_list, "instance list", "[-c] []" }, { cmd_instance_remove, "instance remove", " | " } }; From dovecot at dovecot.org Mon Jun 4 21:58:11 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 21:58:11 +0300 Subject: dovecot-2.1: doveadm config: If -c parameter was given, it wasn'... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/a0ff87fe1f4a changeset: 14551:a0ff87fe1f4a user: Timo Sirainen date: Mon Jun 04 21:58:00 2012 +0300 description: doveadm config: If -c parameter was given, it wasn't passed to doveconf. diffstat: src/doveadm/doveadm.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diffs (21 lines): diff -r ee5d838ebcbb -r a0ff87fe1f4a src/doveadm/doveadm.c --- a/src/doveadm/doveadm.c Mon Jun 04 21:21:52 2012 +0300 +++ b/src/doveadm/doveadm.c Mon Jun 04 21:58:00 2012 +0300 @@ -5,7 +5,7 @@ #include "str.h" #include "env-util.h" #include "execv-const.h" -#include "master-service.h" +#include "master-service-private.h" #include "master-service-settings.h" #include "settings-parser.h" #include "doveadm-print-private.h" @@ -163,6 +163,8 @@ static void cmd_config(int argc ATTR_UNUSED, char *argv[]) { + env_put(t_strconcat(MASTER_CONFIG_FILE_ENV"=", + master_service_get_config_path(master_service), NULL)); argv[0] = BINDIR"/doveconf"; (void)execv(argv[0], argv); i_fatal("execv(%s) failed: %m", argv[0]); From dovecot at dovecot.org Mon Jun 4 22:16:06 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 22:16:06 +0300 Subject: dovecot-2.2: Makefile: Added missing dsync-mailbox.h Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/83b99e13ba47 changeset: 14596:83b99e13ba47 user: Timo Sirainen date: Mon Jun 04 22:15:46 2012 +0300 description: Makefile: Added missing dsync-mailbox.h diffstat: src/doveadm/dsync/Makefile.am | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r 848be27099c8 -r 83b99e13ba47 src/doveadm/dsync/Makefile.am --- a/src/doveadm/dsync/Makefile.am Sat Jun 02 19:39:27 2012 +0300 +++ b/src/doveadm/dsync/Makefile.am Mon Jun 04 22:15:46 2012 +0300 @@ -36,6 +36,7 @@ doveadm-dsync.h \ dsync-brain.h \ dsync-brain-private.h \ + dsync-mailbox.h \ dsync-mailbox-import.h \ dsync-mailbox-export.h \ dsync-mailbox-state.h \ From dovecot at dovecot.org Mon Jun 4 23:33:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 04 Jun 2012 23:33:55 +0300 Subject: dovecot-2.2: Makefile: Added missing dsync-mail.h Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/657d8360cd48 changeset: 14597:657d8360cd48 user: Timo Sirainen date: Mon Jun 04 23:33:40 2012 +0300 description: Makefile: Added missing dsync-mail.h diffstat: src/doveadm/dsync/Makefile.am | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r 83b99e13ba47 -r 657d8360cd48 src/doveadm/dsync/Makefile.am --- a/src/doveadm/dsync/Makefile.am Mon Jun 04 22:15:46 2012 +0300 +++ b/src/doveadm/dsync/Makefile.am Mon Jun 04 23:33:40 2012 +0300 @@ -36,6 +36,7 @@ doveadm-dsync.h \ dsync-brain.h \ dsync-brain-private.h \ + dsync-mail.h \ dsync-mailbox.h \ dsync-mailbox-import.h \ dsync-mailbox-export.h \ From dovecot at dovecot.org Tue Jun 5 00:34:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Tue, 05 Jun 2012 00:34:46 +0300 Subject: dovecot-2.2: Makefile: Added more missing dsync*.h files Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/7d0ce7586c36 changeset: 14598:7d0ce7586c36 user: Timo Sirainen date: Tue Jun 05 00:34:32 2012 +0300 description: Makefile: Added more missing dsync*.h files diffstat: src/doveadm/dsync/Makefile.am | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (13 lines): diff -r 657d8360cd48 -r 7d0ce7586c36 src/doveadm/dsync/Makefile.am --- a/src/doveadm/dsync/Makefile.am Mon Jun 04 23:33:40 2012 +0300 +++ b/src/doveadm/dsync/Makefile.am Tue Jun 05 00:34:32 2012 +0300 @@ -41,7 +41,9 @@ dsync-mailbox-import.h \ dsync-mailbox-export.h \ dsync-mailbox-state.h \ + dsync-mailbox-state-export.h \ dsync-mailbox-tree.h \ + dsync-mailbox-tree-private.h \ dsync-serializer.h \ dsync-deserializer.h \ dsync-slave.h \ From dovecot at dovecot.org Mon Jun 11 16:14:26 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 16:14:26 +0300 Subject: dovecot-2.1: lib-charset: Make sure convert_to_utf8*() never ret... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/0fde692cb565 changeset: 14552:0fde692cb565 user: Timo Sirainen date: Mon Jun 11 16:14:13 2012 +0300 description: lib-charset: Make sure convert_to_utf8*() never returns non-UTF8 output. diffstat: src/lib-charset/charset-iconv.c | 58 ++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 32 deletions(-) diffs (85 lines): diff -r a0ff87fe1f4a -r 0fde692cb565 src/lib-charset/charset-iconv.c --- a/src/lib-charset/charset-iconv.c Mon Jun 04 21:58:00 2012 +0300 +++ b/src/lib-charset/charset-iconv.c Mon Jun 11 16:14:13 2012 +0300 @@ -53,6 +53,20 @@ (void)iconv(t->cd, NULL, NULL, NULL, NULL); } +static int +charset_append_utf8(const void *src, size_t src_size, + buffer_t *dest, bool dtcase) +{ + if (dtcase) + return uni_utf8_to_decomposed_titlecase(src, src_size, dest); + if (!uni_utf8_get_valid_data(src, src_size, dest)) + return -1; + else { + buffer_append(dest, src, src_size); + return 0; + } +} + static bool charset_to_utf8_try(struct charset_translation *t, const unsigned char *src, size_t *src_size, buffer_t *dest, @@ -65,30 +79,15 @@ bool ret = TRUE; if (t->cd == (iconv_t)-1) { - /* no translation needed - just copy it to outbuf uppercased */ - *result = CHARSET_RET_OK; - if (!dtcase) { - buffer_append(dest, src, *src_size); - return TRUE; - } - - if (uni_utf8_to_decomposed_titlecase(src, *src_size, dest) < 0) + /* input is already supposed to be UTF-8 */ + if (charset_append_utf8(src, *src_size, dest, dtcase) < 0) *result = CHARSET_RET_INVALID_INPUT; + else + *result = CHARSET_RET_OK; return TRUE; } - if (!dtcase) { - destleft = buffer_get_size(dest) - dest->used; - if (destleft < *src_size) { - /* The buffer is most likely too small to hold the - output, so increase it at least to the input size. */ - destleft = *src_size; - } - ic_destbuf = buffer_append_space_unsafe(dest, destleft); - } else { - destleft = sizeof(tmpbuf); - ic_destbuf = tmpbuf; - } - + destleft = sizeof(tmpbuf); + ic_destbuf = tmpbuf; srcleft = *src_size; ic_srcbuf = (ICONV_CONST char *) src; @@ -108,17 +107,12 @@ } *src_size -= srcleft; - if (!dtcase) { - /* give back the memory we didn't use */ - buffer_set_used_size(dest, dest->used - destleft); - } else { - size_t tmpsize = sizeof(tmpbuf) - destleft; - - /* we just converted data to UTF-8. it shouldn't be invalid, - but Solaris iconv appears to pass invalid data through - sometimes (e.g. 8 bit characters with UTF-7) */ - (void)uni_utf8_to_decomposed_titlecase(tmpbuf, tmpsize, dest); - } + /* we just converted data to UTF-8. it shouldn't be invalid, but + Solaris iconv appears to pass invalid data through sometimes + (e.g. 8 bit characters with UTF-7) */ + if (charset_append_utf8(tmpbuf, sizeof(tmpbuf) - destleft, + dest, dtcase) < 0) + *result = CHARSET_RET_INVALID_INPUT; return ret; } From dovecot at dovecot.org Mon Jun 11 16:14:48 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 16:14:48 +0300 Subject: dovecot-2.0: lib-charset: Make sure convert_to_utf8*() never ret... Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/797c6fe1b028 changeset: 13098:797c6fe1b028 user: Timo Sirainen date: Mon Jun 11 16:14:13 2012 +0300 description: lib-charset: Make sure convert_to_utf8*() never returns non-UTF8 output. diffstat: src/lib-charset/charset-iconv.c | 58 ++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 32 deletions(-) diffs (85 lines): diff -r f87c09103e82 -r 797c6fe1b028 src/lib-charset/charset-iconv.c --- a/src/lib-charset/charset-iconv.c Mon Jun 04 14:03:47 2012 +0300 +++ b/src/lib-charset/charset-iconv.c Mon Jun 11 16:14:13 2012 +0300 @@ -53,6 +53,20 @@ (void)iconv(t->cd, NULL, NULL, NULL, NULL); } +static int +charset_append_utf8(const void *src, size_t src_size, + buffer_t *dest, bool dtcase) +{ + if (dtcase) + return uni_utf8_to_decomposed_titlecase(src, src_size, dest); + if (!uni_utf8_get_valid_data(src, src_size, dest)) + return -1; + else { + buffer_append(dest, src, src_size); + return 0; + } +} + static bool charset_to_utf8_try(struct charset_translation *t, const unsigned char *src, size_t *src_size, buffer_t *dest, @@ -65,30 +79,15 @@ bool ret = TRUE; if (t->cd == (iconv_t)-1) { - /* no translation needed - just copy it to outbuf uppercased */ - *result = CHARSET_RET_OK; - if (!dtcase) { - buffer_append(dest, src, *src_size); - return TRUE; - } - - if (uni_utf8_to_decomposed_titlecase(src, *src_size, dest) < 0) + /* input is already supposed to be UTF-8 */ + if (charset_append_utf8(src, *src_size, dest, dtcase) < 0) *result = CHARSET_RET_INVALID_INPUT; + else + *result = CHARSET_RET_OK; return TRUE; } - if (!dtcase) { - destleft = buffer_get_size(dest) - dest->used; - if (destleft < *src_size) { - /* The buffer is most likely too small to hold the - output, so increase it at least to the input size. */ - destleft = *src_size; - } - ic_destbuf = buffer_append_space_unsafe(dest, destleft); - } else { - destleft = sizeof(tmpbuf); - ic_destbuf = tmpbuf; - } - + destleft = sizeof(tmpbuf); + ic_destbuf = tmpbuf; srcleft = *src_size; ic_srcbuf = (ICONV_CONST char *) src; @@ -108,17 +107,12 @@ } *src_size -= srcleft; - if (!dtcase) { - /* give back the memory we didn't use */ - buffer_set_used_size(dest, dest->used - destleft); - } else { - size_t tmpsize = sizeof(tmpbuf) - destleft; - - /* we just converted data to UTF-8. it shouldn't be invalid, - but Solaris iconv appears to pass invalid data through - sometimes (e.g. 8 bit characters with UTF-7) */ - (void)uni_utf8_to_decomposed_titlecase(tmpbuf, tmpsize, dest); - } + /* we just converted data to UTF-8. it shouldn't be invalid, but + Solaris iconv appears to pass invalid data through sometimes + (e.g. 8 bit characters with UTF-7) */ + if (charset_append_utf8(tmpbuf, sizeof(tmpbuf) - destleft, + dest, dtcase) < 0) + *result = CHARSET_RET_INVALID_INPUT; return ret; } From dovecot at dovecot.org Mon Jun 11 16:31:03 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 16:31:03 +0300 Subject: dovecot-2.1: lib-master: -i parameter shouldn't imply -k parameter. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/98f2c12eccdb changeset: 14553:98f2c12eccdb user: Timo Sirainen date: Mon Jun 11 16:30:58 2012 +0300 description: lib-master: -i parameter shouldn't imply -k parameter. This was added accidentally when writing the code. diffstat: src/lib-master/master-service.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diffs (11 lines): diff -r 0fde692cb565 -r 98f2c12eccdb src/lib-master/master-service.c --- a/src/lib-master/master-service.c Mon Jun 11 16:14:13 2012 +0300 +++ b/src/lib-master/master-service.c Mon Jun 11 16:30:58 2012 +0300 @@ -359,7 +359,6 @@ if (!get_instance_config(arg, &path)) i_fatal("Unknown instance name: %s", arg); service->config_path = i_strdup(path); - service->keep_environment = TRUE; break; case 'k': service->keep_environment = TRUE; From dovecot at dovecot.org Mon Jun 11 16:54:40 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 16:54:40 +0300 Subject: dovecot-2.1: director: Fixed working as standalone. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/46d01b728647 changeset: 14554:46d01b728647 user: Timo Sirainen date: Mon Jun 11 16:54:14 2012 +0300 description: director: Fixed working as standalone. diffstat: src/director/director.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diffs (15 lines): diff -r 98f2c12eccdb -r 46d01b728647 src/director/director.c --- a/src/director/director.c Mon Jun 11 16:30:58 2012 +0300 +++ b/src/director/director.c Mon Jun 11 16:54:14 2012 +0300 @@ -363,6 +363,11 @@ { /* we're synced again when we receive this SYNC back */ dir->sync_seq++; + if (dir->right == NULL && dir->left == NULL) { + /* we're alone. if we're already synced, + don't become unsynced. */ + return; + } director_set_ring_unsynced(dir); if (dir->sync_frozen) { From dovecot at dovecot.org Mon Jun 11 18:22:17 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 18:22:17 +0300 Subject: dovecot-2.2: shared mailboxes: Per-user flags can now be stored ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/dbd42f7198eb changeset: 14599:dbd42f7198eb user: Timo Sirainen date: Mon Jun 11 18:22:06 2012 +0300 description: shared mailboxes: Per-user flags can now be stored in private index files. This can be enabled by adding e.g.: mail_location = mdbox:/var/shared/mdbox:INDEXPVT=~/mdbox/shared diffstat: src/doveadm/doveadm-dump-log.c | 4 +- src/lib-index/mail-index-private.h | 4 +- src/lib-index/mail-index-transaction-export.c | 31 ++- src/lib-index/mail-index-transaction-finish.c | 4 +- src/lib-index/mail-index-transaction-private.h | 8 +- src/lib-index/mail-index-transaction-update.c | 10 +- src/lib-index/mail-index-transaction-view.c | 2 +- src/lib-index/mail-index.h | 6 +- src/lib-index/mail-transaction-log.h | 3 +- src/lib-index/test-mail-index-transaction-finish.c | 4 +- src/lib-index/test-mail-index-transaction-update.c | 14 +- src/lib-storage/index/Makefile.am | 1 + src/lib-storage/index/index-mail.c | 74 ++++++- src/lib-storage/index/index-storage.c | 6 + src/lib-storage/index/index-storage.h | 1 + src/lib-storage/index/index-sync-private.h | 2 + src/lib-storage/index/index-sync-pvt.c | 221 +++++++++++++++++++++ src/lib-storage/index/index-sync.c | 3 + src/lib-storage/index/index-transaction.c | 51 +++- src/lib-storage/index/shared/shared-list.c | 1 + src/lib-storage/list/mailbox-list-fs.c | 5 + src/lib-storage/list/mailbox-list-maildir.c | 5 + src/lib-storage/mail-storage-private.h | 11 + src/lib-storage/mail-storage.c | 8 +- src/lib-storage/mailbox-list-private.h | 2 + src/lib-storage/mailbox-list.c | 42 ++- src/lib-storage/mailbox-list.h | 7 +- 27 files changed, 466 insertions(+), 64 deletions(-) diffs (truncated from 1035 to 300 lines): diff -r 7d0ce7586c36 -r dbd42f7198eb src/doveadm/doveadm-dump-log.c --- a/src/doveadm/doveadm-dump-log.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/doveadm/doveadm-dump-log.c Mon Jun 11 18:22:06 2012 +0300 @@ -284,8 +284,8 @@ const struct mail_transaction_flag_update *u = data; for (; size > 0; size -= sizeof(*u), u++) { - printf(" - uids=%u-%u (flags +%x-%x)\n", - u->uid1, u->uid2, u->add_flags, u->remove_flags); + printf(" - uids=%u-%u (flags +%x-%x, modseq_inc_flag=%d)\n", + u->uid1, u->uid2, u->add_flags, u->remove_flags, u->modseq_inc_flag); } break; } diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-private.h --- a/src/lib-index/mail-index-private.h Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-private.h Mon Jun 11 18:22:06 2012 +0300 @@ -39,8 +39,8 @@ PTR_OFFSET((map)->rec_map->records, (idx) * (map)->hdr.record_size)) #define MAIL_TRANSACTION_FLAG_UPDATE_IS_INTERNAL(u) \ - ((((u)->add_flags | (u)->remove_flags) & \ - MAIL_INDEX_FLAGS_MASK) == 0) + ((((u)->add_flags | (u)->remove_flags) & MAIL_INDEX_FLAGS_MASK) == 0 && \ + (u)->modseq_inc_flag == 0) #define MAIL_INDEX_EXT_KEYWORDS "keywords" diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-export.c --- a/src/lib-index/mail-index-transaction-export.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-transaction-export.c Mon Jun 11 18:22:06 2012 +0300 @@ -20,6 +20,34 @@ buf->data, buf->used); } +static void log_append_flag_updates(struct mail_index_export_context *ctx, + struct mail_index_transaction *t) +{ + ARRAY_DEFINE(log_updates, struct mail_transaction_flag_update); + const struct mail_index_flag_update *updates; + struct mail_transaction_flag_update *log_update; + unsigned int i, count; + + updates = array_get(&t->updates, &count); + if (count == 0) + return; + + i_array_init(&log_updates, count); + + for (i = 0; i < count; i++) { + log_update = array_append_space(&log_updates); + log_update->uid1 = updates[i].uid1; + log_update->uid2 = updates[i].uid2; + log_update->add_flags = updates[i].add_flags & 0xff; + log_update->remove_flags = updates[i].remove_flags & 0xff; + if ((updates[i].add_flags & MAIL_INDEX_MAIL_FLAG_UPDATE_MODSEQ) != 0) + log_update->modseq_inc_flag = 1; + } + log_append_buffer(ctx, log_updates.arr.buffer, + MAIL_TRANSACTION_FLAG_UPDATE); + array_free(&log_updates); +} + static const buffer_t * log_get_hdr_update_buffer(struct mail_index_transaction *t, bool prepend) { @@ -373,8 +401,7 @@ if (array_is_created(&t->updates)) { change_mask |= MAIL_INDEX_SYNC_TYPE_FLAGS; - log_append_buffer(&ctx, t->updates.arr.buffer, - MAIL_TRANSACTION_FLAG_UPDATE); + log_append_flag_updates(&ctx, t); } if (array_is_created(&t->ext_rec_updates)) { diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-finish.c --- a/src/lib-index/mail-index-transaction-finish.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-transaction-finish.c Mon Jun 11 18:22:06 2012 +0300 @@ -80,7 +80,7 @@ static unsigned int mail_transaction_drop_range(struct mail_index_transaction *t, - struct mail_transaction_flag_update update, + struct mail_index_flag_update update, unsigned int update_idx, ARRAY_TYPE(seq_range) *keeps) { @@ -109,7 +109,7 @@ static void mail_index_transaction_finish_flag_updates(struct mail_index_transaction *t) { - const struct mail_transaction_flag_update *updates, *u; + const struct mail_index_flag_update *updates, *u; const struct mail_index_record *rec; unsigned int i, count; ARRAY_TYPE(seq_range) keeps; diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-private.h --- a/src/lib-index/mail-index-transaction-private.h Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-transaction-private.h Mon Jun 11 18:22:06 2012 +0300 @@ -29,6 +29,12 @@ struct mail_index_module_register *reg; }; +struct mail_index_flag_update { + uint32_t uid1, uid2; + uint16_t add_flags; + uint16_t remove_flags; +}; + struct mail_index_transaction { int refcount; @@ -47,7 +53,7 @@ ARRAY_DEFINE(modseq_updates, struct mail_transaction_modseq_update); ARRAY_DEFINE(expunges, struct mail_transaction_expunge_guid); - ARRAY_DEFINE(updates, struct mail_transaction_flag_update); + ARRAY_DEFINE(updates, struct mail_index_flag_update); size_t last_update_idx; unsigned char pre_hdr_change[sizeof(struct mail_index_header)]; diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-update.c --- a/src/lib-index/mail-index-transaction-update.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-transaction-update.c Mon Jun 11 18:22:06 2012 +0300 @@ -388,7 +388,7 @@ unsigned int right_idx, uint32_t seq) { - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int idx, count; updates = array_get(&t->updates, &count); @@ -414,10 +414,10 @@ static void mail_index_insert_flag_update(struct mail_index_transaction *t, - struct mail_transaction_flag_update u, + struct mail_index_flag_update u, unsigned int idx) { - struct mail_transaction_flag_update *updates, tmp_update; + struct mail_index_flag_update *updates, tmp_update; unsigned int count, first_idx, max; updates = array_get_modifiable(&t->updates, &count); @@ -543,7 +543,7 @@ enum mail_flags flags) { struct mail_index_record *rec; - struct mail_transaction_flag_update u, *last_update; + struct mail_index_flag_update u, *last_update; unsigned int idx, first_idx, count; update_minmax_flagupdate_seq(t, seq1, seq2); @@ -1108,7 +1108,7 @@ bool mail_index_cancel_flag_updates(struct mail_index_transaction *t, uint32_t seq) { - struct mail_transaction_flag_update *updates, tmp_update; + struct mail_index_flag_update *updates, tmp_update; unsigned int i, count; if (!array_is_created(&t->updates)) diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index-transaction-view.c --- a/src/lib-index/mail-index-transaction-view.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index-transaction-view.c Mon Jun 11 18:22:06 2012 +0300 @@ -85,7 +85,7 @@ const struct mail_index_record *rec, uint32_t seq) { struct mail_index_transaction *t = tview->t; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; struct mail_index_record *trec; unsigned int idx, count; diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-index.h --- a/src/lib-index/mail-index.h Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-index.h Mon Jun 11 18:22:06 2012 +0300 @@ -42,9 +42,11 @@ enum mail_index_mail_flags { /* For private use by backend. Replacing flags doesn't change this. */ - MAIL_INDEX_MAIL_FLAG_BACKEND = 0x40, + MAIL_INDEX_MAIL_FLAG_BACKEND = 0x40, /* Message flags haven't been written to backend */ - MAIL_INDEX_MAIL_FLAG_DIRTY = 0x80 + MAIL_INDEX_MAIL_FLAG_DIRTY = 0x80, + /* Force updating this message's modseq via a flag update record */ + MAIL_INDEX_MAIL_FLAG_UPDATE_MODSEQ = 0x100 }; #define MAIL_INDEX_FLAGS_MASK \ diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/mail-transaction-log.h --- a/src/lib-index/mail-transaction-log.h Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/mail-transaction-log.h Mon Jun 11 18:22:06 2012 +0300 @@ -90,7 +90,8 @@ uint32_t uid1, uid2; uint8_t add_flags; uint8_t remove_flags; - uint16_t padding; + uint8_t modseq_inc_flag; + uint8_t padding; }; struct mail_transaction_keyword_update { diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/test-mail-index-transaction-finish.c --- a/src/lib-index/test-mail-index-transaction-finish.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/test-mail-index-transaction-finish.c Mon Jun 11 18:22:06 2012 +0300 @@ -60,8 +60,8 @@ static void test_mail_index_transaction_finish_flag_updates(void) { struct mail_index_transaction *t; - const struct mail_transaction_flag_update *updates; - struct mail_transaction_flag_update u; + const struct mail_index_flag_update *updates; + struct mail_index_flag_update u; unsigned int count; t = t_new(struct mail_index_transaction, 1); diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-index/test-mail-index-transaction-update.c --- a/src/lib-index/test-mail-index-transaction-update.c Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-index/test-mail-index-transaction-update.c Mon Jun 11 18:22:06 2012 +0300 @@ -139,7 +139,7 @@ static void test_mail_index_flag_update_fastpath(void) { struct mail_index_transaction *t; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int count; hdr.messages_count = 20; @@ -168,12 +168,10 @@ test_assert(updates[0].add_flags == MAIL_DELETED); test_assert(updates[0].remove_flags == (MAIL_ANSWERED | MAIL_FLAGGED | MAIL_SEEN | MAIL_DRAFT)); - test_assert(updates[0].padding == 0); test_assert(updates[1].uid1 == 16); test_assert(updates[1].uid2 == 16); test_assert(updates[1].add_flags == MAIL_DELETED); test_assert(updates[1].remove_flags == 0); - test_assert(updates[1].padding == 0); test_assert(!t->log_updates); test_end(); } @@ -181,7 +179,7 @@ static void test_mail_index_flag_update_simple_merges(void) { struct mail_index_transaction *t; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int count; hdr.messages_count = 20; @@ -224,7 +222,7 @@ static void test_mail_index_flag_update_complex_merges(void) { struct mail_index_transaction *t; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int count; hdr.messages_count = 20; @@ -283,7 +281,7 @@ flags_array_check(struct mail_index_transaction *t, const enum mail_flags *flags, unsigned int msg_count) { - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int i, count, seq; if (array_is_created(&t->updates)) @@ -357,7 +355,7 @@ static void test_mail_index_cancel_flag_updates(void) { struct mail_index_transaction *t; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int count; hdr.messages_count = 20; @@ -390,7 +388,7 @@ { struct mail_index_transaction *t; const struct mail_index_record *appends; - const struct mail_transaction_flag_update *updates; + const struct mail_index_flag_update *updates; unsigned int count; uint32_t seq; diff -r 7d0ce7586c36 -r dbd42f7198eb src/lib-storage/index/Makefile.am --- a/src/lib-storage/index/Makefile.am Tue Jun 05 00:34:32 2012 +0300 +++ b/src/lib-storage/index/Makefile.am Mon Jun 11 18:22:06 2012 +0300 @@ -26,6 +26,7 @@ index-storage.c \ index-sync.c \ index-sync-changes.c \ + index-sync-pvt.c \ index-sync-search.c \ From dovecot at dovecot.org Mon Jun 11 23:39:02 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 11 Jun 2012 23:39:02 +0300 Subject: dovecot-2.1: shared mailboxes: Avoid doing "@domain" userdb look... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/28ddc2058877 changeset: 14555:28ddc2058877 user: Timo Sirainen date: Mon Jun 11 23:38:45 2012 +0300 description: shared mailboxes: Avoid doing "@domain" userdb lookups. diffstat: src/lib-storage/index/shared/shared-list.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diffs (18 lines): diff -r 46d01b728647 -r 28ddc2058877 src/lib-storage/index/shared/shared-list.c --- a/src/lib-storage/index/shared/shared-list.c Mon Jun 11 16:54:14 2012 +0300 +++ b/src/lib-storage/index/shared/shared-list.c Mon Jun 11 23:38:45 2012 +0300 @@ -43,8 +43,12 @@ const char *name; name = mailbox_list_get_storage_name(*list, vname); - if (shared_storage_get_namespace(&ns, &name) < 0) - return -1; + if (*name == '\0' && (ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0) { + /* trying to access the shared/ prefix itself */ + } else { + if (shared_storage_get_namespace(&ns, &name) < 0) + return -1; + } *list = ns->list; *storage_r = ns->storage; return 0; From dovecot at dovecot.org Tue Jun 12 00:53:10 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Tue, 12 Jun 2012 00:53:10 +0300 Subject: dovecot-2.0: Released v2.0.21. Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/e95790d301b4 changeset: 13099:e95790d301b4 user: Timo Sirainen date: Tue Jun 12 00:03:54 2012 +0300 description: Released v2.0.21. diffstat: NEWS | 10 ++++++++++ configure.in | 2 +- 2 files changed, 11 insertions(+), 1 deletions(-) diffs (27 lines): diff -r 797c6fe1b028 -r e95790d301b4 NEWS --- a/NEWS Mon Jun 11 16:14:13 2012 +0300 +++ b/NEWS Tue Jun 12 00:03:54 2012 +0300 @@ -1,3 +1,13 @@ +v2.0.21 2012-06-12 Timo Sirainen + + + dict: file backend supports now also fcntl/flock locking optionally + - imap-login: Memory leak fixed + - imap: Non-UTF8 input on SEARCH command parameters could have crashed + - auth: Fixed crash with DIGEST-MD5 when attempting to do master user + login without master passdbs. + - sdbox: Don't use more fds than necessary when copying mails. + - mdbox kept the user's storage locked a bit longer than it needed to + v2.0.20 2012-04-09 Timo Sirainen + doveadm user: Added -m parameter to show some of the mail settings. diff -r 797c6fe1b028 -r e95790d301b4 configure.in --- a/configure.in Mon Jun 11 16:14:13 2012 +0300 +++ b/configure.in Tue Jun 12 00:03:54 2012 +0300 @@ -1,5 +1,5 @@ AC_PREREQ([2.59]) -AC_INIT([Dovecot],[2.0.20],[dovecot at dovecot.org]) +AC_INIT([Dovecot],[2.0.21],[dovecot at dovecot.org]) AC_CONFIG_SRCDIR([src]) AM_INIT_AUTOMAKE([foreign]) From dovecot at dovecot.org Tue Jun 12 00:53:10 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Tue, 12 Jun 2012 00:53:10 +0300 Subject: dovecot-2.0: Added tag 2.0.21 for changeset e95790d301b4 Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/668e65e9ff5b changeset: 13100:668e65e9ff5b user: Timo Sirainen date: Tue Jun 12 00:03:54 2012 +0300 description: Added tag 2.0.21 for changeset e95790d301b4 diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r e95790d301b4 -r 668e65e9ff5b .hgtags --- a/.hgtags Tue Jun 12 00:03:54 2012 +0300 +++ b/.hgtags Tue Jun 12 00:03:54 2012 +0300 @@ -71,3 +71,4 @@ 346526718aad285ce6a055fb2472c716f49e5dda 2.0.18 4b680f5055c7b838d3252328736c5e2419731dfa 2.0.19 cec3271fc830bcef11462f222ffbb30844d587eb 2.0.20 +e95790d301b4fb05a00a036f31d58e64eba23204 2.0.21 From dovecot at dovecot.org Tue Jun 12 00:53:10 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Tue, 12 Jun 2012 00:53:10 +0300 Subject: dovecot-2.0: Added signature for changeset e95790d301b4 Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/066c1acd272b changeset: 13101:066c1acd272b user: Timo Sirainen date: Tue Jun 12 00:04:01 2012 +0300 description: Added signature for changeset e95790d301b4 diffstat: .hgsigs | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r 668e65e9ff5b -r 066c1acd272b .hgsigs --- a/.hgsigs Tue Jun 12 00:03:54 2012 +0300 +++ b/.hgsigs Tue Jun 12 00:04:01 2012 +0300 @@ -34,3 +34,4 @@ 346526718aad285ce6a055fb2472c716f49e5dda 0 iEYEABECAAYFAk84L6AACgkQyUhSUUBViskcPACfSRM+K7pQesMLEkV0m9uiMXJYoqcAn0vTpk0vkkF15Y+C0fPdkCS47aio 4b680f5055c7b838d3252328736c5e2419731dfa 0 iEYEABECAAYFAk9iBAEACgkQyUhSUUBVismySACgkhAfpqvzdWpm17r+5jqShqx4cdwAnA+yd4UeUvLGR70HCsU+mCfiFzn6 cec3271fc830bcef11462f222ffbb30844d587eb 0 iEYEABECAAYFAk+CtlgACgkQyUhSUUBVisluUACfQ5uxj42hv/1X5Q+9PYWzk1q6fC0An0ErX8xpjdLAMu38AOqbhOAmVBQc +e95790d301b4fb05a00a036f31d58e64eba23204 0 iEYEABECAAYFAk/WXTsACgkQyUhSUUBViskinwCdG673ACBes4h4uMIy1mctWRGuoyUAn0Rw/mFF0kdkq5gBd1jd9RpoI93T From dovecot at dovecot.org Wed Jun 13 15:34:44 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 13 Jun 2012 15:34:44 +0300 Subject: dovecot-2.1: master: If service_count=1 and process_limit=1 and ... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/4c31e450a867 changeset: 14556:4c31e450a867 user: Timo Sirainen date: Wed Jun 13 15:34:39 2012 +0300 description: master: If service_count=1 and process_limit=1 and >1 clients connect, log about service_count being why. diffstat: src/master/service-monitor.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diffs (36 lines): diff -r 28ddc2058877 -r 4c31e450a867 src/master/service-monitor.c --- a/src/master/service-monitor.c Mon Jun 11 23:38:45 2012 +0300 +++ b/src/master/service-monitor.c Wed Jun 13 15:34:39 2012 +0300 @@ -237,19 +237,27 @@ static void service_drop_connections(struct service_listener *l) { struct service *service = l->service; + const char *limit_name; unsigned int limit; int fd; if (service->last_drop_warning + SERVICE_DROP_WARN_INTERVAL_SECS < ioloop_time) { service->last_drop_warning = ioloop_time; - limit = service->process_limit > 1 ? - service->process_limit : service->client_limit; + if (service->process_limit > 1) { + limit_name = "process_limit"; + limit = service->process_limit; + } else if (service->set->service_count == 1) { + i_assert(service->client_limit == 1); + limit_name = "client_limit/service_count"; + limit = 1; + } else { + limit_name = "client_limit"; + limit = service->client_limit; + } i_warning("service(%s): %s (%u) reached, " "client connections are being dropped", - service->set->name, - service->process_limit > 1 ? - "process_limit" : "client_limit", limit); + service->set->name, limit_name, limit); } if (service->type == SERVICE_TYPE_LOGIN) { From dovecot at dovecot.org Wed Jun 13 16:29:43 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 13 Jun 2012 16:29:43 +0300 Subject: dovecot-2.1: lib-master: Fixed assert crash in some situations a... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/c58a27eecdd4 changeset: 14557:c58a27eecdd4 user: Timo Sirainen date: Wed Jun 13 16:29:37 2012 +0300 description: lib-master: Fixed assert crash in some situations after updating instance name. diffstat: src/lib-master/master-instance.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (19 lines): diff -r 4c31e450a867 -r c58a27eecdd4 src/lib-master/master-instance.c --- a/src/lib-master/master-instance.c Wed Jun 13 15:34:39 2012 +0300 +++ b/src/lib-master/master-instance.c Wed Jun 13 16:29:37 2012 +0300 @@ -257,6 +257,7 @@ strcmp(orig_inst->base_dir, base_dir) != 0) { /* name already used */ (void)file_dotlock_delete(&dotlock); + list->locked = FALSE; return 0; } @@ -292,6 +293,7 @@ if (i == count) { (void)file_dotlock_delete(&dotlock); + list->locked = FALSE; return 0; } return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1; From dovecot at dovecot.org Fri Jun 15 15:12:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 15 Jun 2012 15:12:46 +0300 Subject: dovecot-2.1: maildir++ quota: If reading maildirsize fails with ... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/cad676b57cc8 changeset: 14558:cad676b57cc8 user: Timo Sirainen date: Fri Jun 15 15:12:33 2012 +0300 description: maildir++ quota: If reading maildirsize fails with ESTALE, retry it. diffstat: src/plugins/quota/quota-maildir.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-) diffs (57 lines): diff -r c58a27eecdd4 -r cad676b57cc8 src/plugins/quota/quota-maildir.c --- a/src/plugins/quota/quota-maildir.c Wed Jun 13 16:29:37 2012 +0300 +++ b/src/plugins/quota/quota-maildir.c Fri Jun 15 15:12:33 2012 +0300 @@ -546,12 +546,15 @@ !CMP_DEV_T(st1.st_dev, st2.st_dev); } -static int maildirsize_read(struct maildir_quota_root *root) +static int maildirsize_read(struct maildir_quota_root *root, bool *retry) { char buf[5120+1]; unsigned int i, size; + bool retry_estale = *retry; int ret; + *retry = FALSE; + if (!maildirsize_has_changed(root)) return 1; @@ -562,8 +565,10 @@ size = 0; while ((ret = read(root->fd, buf + size, sizeof(buf)-1 - size)) != 0) { if (ret < 0) { - if (errno == ESTALE) + if (errno == ESTALE && retry_estale) { + *retry = TRUE; break; + } i_error("read(%s) failed: %m", root->maildirsize_path); break; } @@ -644,14 +649,20 @@ static int maildirquota_read_limits(struct maildir_quota_root *root) { - int ret; + bool retry = TRUE; + int ret, n = 0; if (!maildirquota_limits_init(root)) return 1; - T_BEGIN { - ret = maildirsize_read(root); - } T_END; + do { + if (n == NFS_ESTALE_RETRY_COUNT) + retry = FALSE; + T_BEGIN { + ret = maildirsize_read(root, &retry); + } T_END; + n++; + } while (ret == -1 && retry); return ret; } From dovecot at dovecot.org Fri Jun 15 17:12:38 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 15 Jun 2012 17:12:38 +0300 Subject: dovecot-2.1: example-config: imap_logout_format default was wrong. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/a4cd22976ddb changeset: 14559:a4cd22976ddb user: Timo Sirainen date: Fri Jun 15 17:12:24 2012 +0300 description: example-config: imap_logout_format default was wrong. diffstat: doc/example-config/conf.d/20-imap.conf | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r cad676b57cc8 -r a4cd22976ddb doc/example-config/conf.d/20-imap.conf --- a/doc/example-config/conf.d/20-imap.conf Fri Jun 15 15:12:33 2012 +0300 +++ b/doc/example-config/conf.d/20-imap.conf Fri Jun 15 17:12:24 2012 +0300 @@ -18,7 +18,7 @@ # IMAP logout format string: # %i - total number of bytes read from client # %o - total number of bytes sent to client - #imap_logout_format = bytes=%i/%o + #imap_logout_format = in=%i out=%o # Override the IMAP CAPABILITY response. If the value begins with '+', # add the given capabilities on top of the defaults (e.g. +XFOO XBAR). From dovecot at dovecot.org Fri Jun 15 23:45:07 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 15 Jun 2012 23:45:07 +0300 Subject: dovecot-2.1: doveadm log errors: Added -s parameter Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/8de41fa0fbf1 changeset: 14560:8de41fa0fbf1 user: Timo Sirainen date: Fri Jun 15 23:44:53 2012 +0300 description: doveadm log errors: Added -s parameter diffstat: src/doveadm/doveadm-log.c | 34 ++++++++++++++++++++++++++-------- 1 files changed, 26 insertions(+), 8 deletions(-) diffs (77 lines): diff -r a4cd22976ddb -r 8de41fa0fbf1 src/doveadm/doveadm-log.c --- a/src/doveadm/doveadm-log.c Fri Jun 15 17:12:24 2012 +0300 +++ b/src/doveadm/doveadm-log.c Fri Jun 15 23:44:53 2012 +0300 @@ -23,6 +23,8 @@ #define LOG_ERRORS_FNAME "log-errors" #define LOG_TIMESTAMP_FORMAT "%b %d %H:%M:%S" +extern struct doveadm_cmd doveadm_cmd_log[]; + static void cmd_log_test(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) { struct failure_context ctx; @@ -278,7 +280,7 @@ } } -static void cmd_log_error_write(const char *const *args) +static void cmd_log_error_write(const char *const *args, time_t min_timestamp) { /* */ const char *type_prefix = "?"; @@ -297,16 +299,32 @@ i_error("Invalid timestamp: %s", args[1]); t = 0; } - - printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), - args[2], type_prefix, args[3]); + if (t >= min_timestamp) { + printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), + args[2], type_prefix, args[3]); + } } -static void cmd_log_errors(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_log_errors(int argc, char *argv[]) { struct istream *input; const char *path, *line, *const *args; - int fd; + time_t min_timestamp = 0; + int c, fd; + + while ((c = getopt(argc, argv, "s:")) > 0) { + switch (c) { + case 's': + if (str_to_time(optarg, &min_timestamp) < 0) + i_fatal("Invalid timestamp: %s", optarg); + break; + default: + help(&doveadm_cmd_log[3]); + } + } + argv += optind - 1; + if (argv[1] != NULL) + help(&doveadm_cmd_log[3]); path = t_strconcat(doveadm_settings->base_dir, "/"LOG_ERRORS_FNAME, NULL); @@ -319,7 +337,7 @@ while ((line = i_stream_read_next_line(input)) != NULL) T_BEGIN { args = t_strsplit_tabescaped(line); if (str_array_length(args) == 4) - cmd_log_error_write(args); + cmd_log_error_write(args, min_timestamp); else { i_error("Invalid input from log: %s", line); doveadm_exit_code = EX_PROTOCOL; @@ -332,7 +350,7 @@ { cmd_log_test, "log test", "" }, { cmd_log_reopen, "log reopen", "" }, { cmd_log_find, "log find", "[]" }, - { cmd_log_errors, "log errors", "" } + { cmd_log_errors, "log errors", "[-s ]" } }; void doveadm_register_log_commands(void) From dovecot at dovecot.org Sat Jun 16 01:59:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 16 Jun 2012 01:59:55 +0300 Subject: dovecot-2.1: doveadm log errors: Usage text update Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/db32881669e6 changeset: 14561:db32881669e6 user: Timo Sirainen date: Sat Jun 16 01:59:44 2012 +0300 description: doveadm log errors: Usage text update diffstat: src/doveadm/doveadm-log.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 8de41fa0fbf1 -r db32881669e6 src/doveadm/doveadm-log.c --- a/src/doveadm/doveadm-log.c Fri Jun 15 23:44:53 2012 +0300 +++ b/src/doveadm/doveadm-log.c Sat Jun 16 01:59:44 2012 +0300 @@ -350,7 +350,7 @@ { cmd_log_test, "log test", "" }, { cmd_log_reopen, "log reopen", "" }, { cmd_log_find, "log find", "[]" }, - { cmd_log_errors, "log errors", "[-s ]" } + { cmd_log_errors, "log errors", "[-s ]" } }; void doveadm_register_log_commands(void) From dovecot at dovecot.org Sat Jun 16 02:03:58 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 16 Jun 2012 02:03:58 +0300 Subject: dovecot-2.1: imapc: Removed brokenly used explicit data stack fr... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/a28c8043842d changeset: 14562:a28c8043842d user: Timo Sirainen date: Sat Jun 16 02:03:53 2012 +0300 description: imapc: Removed brokenly used explicit data stack frame. Fixes crashes when a message has more than 8 keywords. diffstat: src/lib-storage/index/imapc/imapc-mailbox.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r db32881669e6 -r a28c8043842d src/lib-storage/index/imapc/imapc-mailbox.c --- a/src/lib-storage/index/imapc/imapc-mailbox.c Sat Jun 16 01:59:44 2012 +0300 +++ b/src/lib-storage/index/imapc/imapc-mailbox.c Sat Jun 16 02:03:53 2012 +0300 @@ -338,7 +338,7 @@ mail_index_update_flags(mbox->delayed_sync_trans, lseq, MODIFY_REPLACE, flags); } - if (seen_flags) T_BEGIN { + if (seen_flags) { ARRAY_TYPE(keyword_indexes) old_kws; struct mail_keywords *kw; @@ -354,7 +354,7 @@ lseq, MODIFY_REPLACE, kw); } mail_index_keywords_unref(&kw); - } T_END; + } imapc_mailbox_idle_notify(mbox); } From dovecot at dovecot.org Sat Jun 16 02:06:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 16 Jun 2012 02:06:27 +0300 Subject: dovecot-2.2: example-config: Refer to ssl=required in disable_pl... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/27f769be0f85 changeset: 14600:27f769be0f85 user: Timo Sirainen date: Sat Jun 16 02:06:16 2012 +0300 description: example-config: Refer to ssl=required in disable_plaintext_auth setting. diffstat: doc/example-config/conf.d/10-auth.conf | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r dbd42f7198eb -r 27f769be0f85 doc/example-config/conf.d/10-auth.conf --- a/doc/example-config/conf.d/10-auth.conf Mon Jun 11 18:22:06 2012 +0300 +++ b/doc/example-config/conf.d/10-auth.conf Sat Jun 16 02:06:16 2012 +0300 @@ -6,6 +6,7 @@ # SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP # matches the local IP (ie. you're connecting from the same computer), the # connection is considered secure and plaintext authentication is allowed. +# See also ssl=required setting. #disable_plaintext_auth = yes # Authentication cache size (e.g. 10M). 0 means it's disabled. Note that From dovecot at dovecot.org Mon Jun 18 13:19:49 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 18 Jun 2012 13:19:49 +0300 Subject: dovecot-2.1: doveadm: Fixed crash with proxying some commands. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/9fc78d06252c changeset: 14563:9fc78d06252c user: Timo Sirainen date: Mon Jun 18 13:19:41 2012 +0300 description: doveadm: Fixed crash with proxying some commands. diffstat: src/doveadm/doveadm-print.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diffs (51 lines): diff -r a28c8043842d -r 9fc78d06252c src/doveadm/doveadm-print.c --- a/src/doveadm/doveadm-print.c Sat Jun 16 02:03:53 2012 +0300 +++ b/src/doveadm/doveadm-print.c Mon Jun 18 13:19:41 2012 +0300 @@ -18,6 +18,7 @@ const struct doveadm_print_vfuncs *v; unsigned int header_idx; + bool print_stream_open; }; static struct doveadm_print_context *ctx; @@ -52,7 +53,7 @@ doveadm_print_header(key_title, key_title, 0); } -void doveadm_print(const char *value) +static void doveadm_print_sticky_headers(void) { const struct doveadm_print_header_context *headers; unsigned int count; @@ -68,7 +69,13 @@ break; } } +} +void doveadm_print(const char *value) +{ + i_assert(!ctx->print_stream_open); + + doveadm_print_sticky_headers(); ctx->v->print(value); ctx->header_idx++; } @@ -82,9 +89,15 @@ void doveadm_print_stream(const void *value, size_t size) { + if (!ctx->print_stream_open) { + doveadm_print_sticky_headers(); + ctx->print_stream_open = TRUE; + } ctx->v->print_stream(value, size); - if (size == 0) + if (size == 0) { ctx->header_idx++; + ctx->print_stream_open = FALSE; + } } void doveadm_print_sticky(const char *key, const char *value) From dovecot at dovecot.org Mon Jun 18 13:21:11 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 18 Jun 2012 13:21:11 +0300 Subject: dovecot-2.1: lib-ssl-iostream: Don't assert-crash if underlying ... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/39d9e75fec02 changeset: 14564:39d9e75fec02 user: Timo Sirainen date: Mon Jun 18 13:21:03 2012 +0300 description: lib-ssl-iostream: Don't assert-crash if underlying connection suddenly disconnects. diffstat: src/lib-ssl-iostream/iostream-openssl.c | 7 +++++-- src/lib-ssl-iostream/istream-openssl.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diffs (42 lines): diff -r 9fc78d06252c -r 39d9e75fec02 src/lib-ssl-iostream/iostream-openssl.c --- a/src/lib-ssl-iostream/iostream-openssl.c Mon Jun 18 13:19:41 2012 +0300 +++ b/src/lib-ssl-iostream/iostream-openssl.c Mon Jun 18 13:21:03 2012 +0300 @@ -388,7 +388,8 @@ return 0; } if (ssl_io->closed) { - errno = ssl_io->plain_stream_errno; + errno = ssl_io->plain_stream_errno != 0 ? + ssl_io->plain_stream_errno : EPIPE; return -1; } return 1; @@ -396,7 +397,8 @@ ssl_io->want_read = TRUE; (void)ssl_iostream_bio_sync(ssl_io); if (ssl_io->closed) { - errno = ssl_io->plain_stream_errno; + errno = ssl_io->plain_stream_errno != 0 ? + ssl_io->plain_stream_errno : EPIPE; return -1; } return ssl_io->want_read ? 0 : 1; @@ -406,6 +408,7 @@ errstr = ssl_iostream_error(); errno = EINVAL; } else if (ret != 0) { + i_assert(errno != 0); errstr = strerror(errno); } else { /* EOF. */ diff -r 9fc78d06252c -r 39d9e75fec02 src/lib-ssl-iostream/istream-openssl.c --- a/src/lib-ssl-iostream/istream-openssl.c Mon Jun 18 13:19:41 2012 +0300 +++ b/src/lib-ssl-iostream/istream-openssl.c Mon Jun 18 13:21:03 2012 +0300 @@ -38,6 +38,7 @@ if (ret <= 0) { if (ret < 0) { /* handshake failed */ + i_assert(errno != 0); stream->istream.stream_errno = errno; } return ret; From dovecot at dovecot.org Mon Jun 18 17:05:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 18 Jun 2012 17:05:39 +0300 Subject: dovecot-2.1: fts-squat: Fixed handling multiple SEARCH parameters. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/4ce1f9649592 changeset: 14565:4ce1f9649592 user: Timo Sirainen date: Mon Jun 18 17:05:27 2012 +0300 description: fts-squat: Fixed handling multiple SEARCH parameters. diffstat: src/plugins/fts-squat/fts-backend-squat.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diffs (16 lines): diff -r 39d9e75fec02 -r 4ce1f9649592 src/plugins/fts-squat/fts-backend-squat.c --- a/src/plugins/fts-squat/fts-backend-squat.c Mon Jun 18 13:21:03 2012 +0300 +++ b/src/plugins/fts-squat/fts-backend-squat.c Mon Jun 18 17:05:27 2012 +0300 @@ -452,9 +452,10 @@ &result->maybe_uids); if (ret < 0) return -1; - if (ret > 0) + if (ret > 0) { args->match_always = TRUE; - first = FALSE; + first = FALSE; + } } return 0; } From dovecot at dovecot.org Wed Jun 20 00:48:20 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 00:48:20 +0300 Subject: dovecot-2.2: message parser: Fixes to handling CRLF linefeeds. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c34d4e3ff342 changeset: 14601:c34d4e3ff342 user: Timo Sirainen date: Wed Jun 20 00:48:08 2012 +0300 description: message parser: Fixes to handling CRLF linefeeds. An extra CR could have been left to the end of a MIME part that belonged to its --boundary. diffstat: src/lib-mail/message-parser.c | 24 +++++++++++++++++++----- 1 files changed, 19 insertions(+), 5 deletions(-) diffs (49 lines): diff -r 27f769be0f85 -r c34d4e3ff342 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Sat Jun 16 02:06:16 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 00:48:08 2012 +0300 @@ -291,6 +291,7 @@ struct message_block *block_r, bool first_line) { struct message_part *part; + size_t line_size; /* get back to parent MIME part, summing the child MIME part sizes into parent's body sizes */ @@ -310,12 +311,21 @@ /* the boundary itself should already be in buffer. add that. */ block_r->data = i_stream_get_data(ctx->input, &block_r->size); - i_assert(block_r->size >= ctx->skip + 2 + boundary->len + - (first_line ? 0 : 1)); + i_assert(block_r->size >= ctx->skip); block_r->data += ctx->skip; - /* [\n]--[--] */ - block_r->size = (first_line ? 0 : 1) + 2 + boundary->len + - (boundary->epilogue_found ? 2 : 0); + /* [[\r]\n]--[--] */ + if (first_line) + line_size = 0; + else if (block_r->data[0] == '\r') { + i_assert(block_r->data[1] == '\n'); + line_size = 2; + } else { + i_assert(block_r->data[0] == '\n'); + line_size = 1; + } + line_size += 2 + boundary->len + (boundary->epilogue_found ? 2 : 0); + i_assert(block_r->size >= ctx->skip + line_size); + block_r->size = line_size; parse_body_add_block(ctx, block_r); ctx->parse_next_block = parse_next_body_skip_boundary_line; @@ -382,6 +392,10 @@ } else if (boundary_start == 0) { /* no linefeeds in this block. we can just skip it. */ ret = 0; + if (block_r->data[block_r->size-1] == '\r') { + /* this may be the beginning of the \r\n--boundary */ + block_r->size--; + } boundary_start = block_r->size; } else { /* the boundary wasn't found from this data block, From dovecot at dovecot.org Wed Jun 20 02:20:36 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:20:36 +0300 Subject: dovecot-2.2: message header parser: Fixed handling very long mul... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/8a4e5e5d82b5 changeset: 14602:8a4e5e5d82b5 user: Timo Sirainen date: Wed Jun 20 01:40:14 2012 +0300 description: message header parser: Fixed handling very long multiline headers. If the header's line fit exactly to input stream's buffer so that the parser couldn't see the following character, it assumed that the header ended. diffstat: src/lib-mail/message-header-parser.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diffs (33 lines): diff -r c34d4e3ff342 -r 8a4e5e5d82b5 src/lib-mail/message-header-parser.c --- a/src/lib-mail/message-header-parser.c Wed Jun 20 00:48:08 2012 +0300 +++ b/src/lib-mail/message-header-parser.c Wed Jun 20 01:40:14 2012 +0300 @@ -159,6 +159,17 @@ break; } } + if (i == min_pos && (msg[size-1] == '\r' || + msg[size-1] == '\n')) { + /* we may or may not have a full header, + but we don't know until we get the + next character. leave out the + linefeed and finish the header on + the next run. */ + size--; + if (size > 0 && msg[size-1] == '\r') + size--; + } continues = TRUE; } @@ -201,7 +212,10 @@ } } - if (i < parse_size) { + if (i < parse_size && i+1 == size && ret == -2) { + /* we don't know if the line continues. */ + i++; + } else if (i < parse_size) { /* got a line */ if (ctx->skip_line) { /* skipping a line with a huge header name */ From dovecot at dovecot.org Wed Jun 20 02:20:36 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:20:36 +0300 Subject: dovecot-2.2: message header parser: Don't skip header if header ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/49607e4a97d4 changeset: 14603:49607e4a97d4 user: Timo Sirainen date: Wed Jun 20 01:45:55 2012 +0300 description: message header parser: Don't skip header if header name is longer than input buffer. We'll instead now just return the name in smaller blocks with no_newline=TRUE. This allows the caller to reconstruct the exact same message. diffstat: src/lib-mail/message-header-parser.c | 16 ---------------- 1 files changed, 0 insertions(+), 16 deletions(-) diffs (26 lines): diff -r 8a4e5e5d82b5 -r 49607e4a97d4 src/lib-mail/message-header-parser.c --- a/src/lib-mail/message-header-parser.c Wed Jun 20 01:40:14 2012 +0300 +++ b/src/lib-mail/message-header-parser.c Wed Jun 20 01:45:55 2012 +0300 @@ -134,22 +134,6 @@ /* a) line is larger than input buffer b) header ended unexpectedly */ - if (colon_pos == UINT_MAX && ret == -2 && !continued) { - /* header name is huge. just skip it. */ - i_assert(size > 1); - if (msg[size-1] == '\r') - size--; - - if (ctx->hdr_size != NULL) { - ctx->hdr_size->physical_size += size; - ctx->hdr_size->virtual_size += size; - } - i_stream_skip(ctx->input, size); - ctx->skip_line = TRUE; - startpos = 0; - continue; - } - if (ret == -2) { /* go back to last LWSP if found. */ size_t min_pos = !continued ? colon_pos : 0; From dovecot at dovecot.org Wed Jun 20 02:22:03 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:22:03 +0300 Subject: dovecot-2.2: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/217fe26a3176 changeset: 14604:217fe26a3176 user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r 49607e4a97d4 -r 217fe26a3176 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Wed Jun 20 01:45:55 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -153,7 +153,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Wed Jun 20 02:23:54 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:23:54 +0300 Subject: dovecot-2.2: message parser: Added MESSAGE_PARSER_FLAG_INCLUDE_B... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/6846c2e50eba changeset: 14605:6846c2e50eba user: Timo Sirainen date: Wed Jun 20 02:22:27 2012 +0300 description: message parser: Added MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES flag. diffstat: src/lib-mail/message-parser.c | 10 +++++++++- src/lib-mail/message-parser.h | 8 +++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diffs (56 lines): diff -r 217fe26a3176 -r 6846c2e50eba src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:22:27 2012 +0300 @@ -269,7 +269,10 @@ ptr = memchr(block_r->data, '\n', block_r->size); if (ptr == NULL) { parse_body_add_block(ctx, block_r); - return 1; + if (block_r->size > 0 && + (ctx->flags & MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES) != 0) + return 1; + return 0; } /* found the LF */ @@ -286,6 +289,9 @@ /* a new MIME part begins */ ctx->parse_next_block = parse_next_mime_header_init; } + if (block_r->size > 0 && + (ctx->flags & MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES) != 0) + return 1; return ctx->parse_next_block(ctx, block_r); } @@ -333,6 +339,8 @@ ctx->parse_next_block = parse_next_body_skip_boundary_line; + if ((ctx->flags & MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES) != 0) + return 1; return ctx->parse_next_block(ctx, block_r); } diff -r 217fe26a3176 -r 6846c2e50eba src/lib-mail/message-parser.h --- a/src/lib-mail/message-parser.h Wed Jun 20 02:21:54 2012 +0300 +++ b/src/lib-mail/message-parser.h Wed Jun 20 02:22:27 2012 +0300 @@ -6,13 +6,15 @@ enum message_parser_flags { /* Don't return message bodies in message_blocks. */ - MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK = 0x01, + MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK = 0x01, /* Buggy software creates Content-Type: headers without Mime-Version: header. By default we allow this and assume message is MIME if Content-Type: is found. This flag disables this. */ - MESSAGE_PARSER_FLAG_MIME_VERSION_STRICT = 0x02, + MESSAGE_PARSER_FLAG_MIME_VERSION_STRICT = 0x02, /* Return multipart (preamble and epilogue) blocks */ - MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS = 0x04 + MESSAGE_PARSER_FLAG_INCLUDE_MULTIPART_BLOCKS = 0x04, + /* Return --boundary lines */ + MESSAGE_PARSER_FLAG_INCLUDE_BOUNDARIES = 0x08 }; /* Note that these flags are used directly by message-parser-serialize, so From dovecot at dovecot.org Wed Jun 20 02:23:54 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:23:54 +0300 Subject: dovecot-2.2: Added istream-binary-converter to convert binary MI... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/7b1378fe8820 changeset: 14606:7b1378fe8820 user: Timo Sirainen date: Wed Jun 20 02:23:42 2012 +0300 description: Added istream-binary-converter to convert binary MIME parts to base64. diffstat: src/lib-mail/Makefile.am | 7 + src/lib-mail/istream-binary-converter.c | 303 +++++++++++++++++++++++++++ src/lib-mail/istream-binary-converter.h | 6 + src/lib-mail/test-istream-binary-converter.c | 152 +++++++++++++ 4 files changed, 468 insertions(+), 0 deletions(-) diffs (truncated from 511 to 300 lines): diff -r 6846c2e50eba -r 7b1378fe8820 src/lib-mail/Makefile.am --- a/src/lib-mail/Makefile.am Wed Jun 20 02:22:27 2012 +0300 +++ b/src/lib-mail/Makefile.am Wed Jun 20 02:23:42 2012 +0300 @@ -6,6 +6,7 @@ -I$(top_srcdir)/src/lib-charset libmail_la_SOURCES = \ + istream-binary-converter.c \ istream-dot.c \ istream-header-filter.c \ mail-user-hash.c \ @@ -27,6 +28,7 @@ rfc822-parser.c headers = \ + istream-binary-converter.h \ istream-dot.h \ istream-header-filter.h \ mail-user-hash.h \ @@ -53,6 +55,7 @@ test_programs = \ test-istream-dot \ + test-istream-binary-converter \ test-istream-header-filter \ test-mbox-from \ test-message-address \ @@ -76,6 +79,10 @@ test_istream_dot_LDADD = istream-dot.lo $(test_libs) test_istream_dot_DEPENDENCIES = istream-dot.lo $(test_libs) +test_istream_binary_converter_SOURCES = test-istream-binary-converter.c +test_istream_binary_converter_LDADD = istream-binary-converter.lo message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs) +test_istream_binary_converter_DEPENDENCIES = istream-binary-converter.lo message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs) + test_istream_header_filter_SOURCES = test-istream-header-filter.c test_istream_header_filter_LDADD = istream-header-filter.lo message-header-parser.lo $(test_libs) test_istream_header_filter_DEPENDENCIES = istream-header-filter.lo message-header-parser.lo $(test_libs) diff -r 6846c2e50eba -r 7b1378fe8820 src/lib-mail/istream-binary-converter.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-binary-converter.c Wed Jun 20 02:23:42 2012 +0300 @@ -0,0 +1,303 @@ +/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "buffer.h" +#include "base64.h" +#include "istream-private.h" +#include "message-parser.h" +#include "istream-binary-converter.h" + +#define BASE64_BLOCK_INPUT_SIZE 3 +#define BASE64_BLOCK_SIZE 4 +#define BASE64_BLOCKS_PER_LINE (76/BASE64_BLOCK_SIZE) + +struct binary_converter_istream { + struct istream_private istream; + + pool_t pool; + struct message_parser_ctx *parser; + struct message_part *convert_part; + char base64_delayed[BASE64_BLOCK_INPUT_SIZE-1]; + unsigned int base64_delayed_len; + unsigned int base64_block_pos; + + buffer_t *hdr_buf; + unsigned int cte_header_len; + unsigned int content_type_seen:1; +}; + +static void * +stream_alloc_data(struct binary_converter_istream *bstream, size_t size) +{ + struct istream_private *stream = &bstream->istream; + size_t old_size, avail_size; + + (void)i_stream_get_buffer_space(stream, size, &avail_size); + if (avail_size < size) { + old_size = stream->buffer_size; + stream->buffer_size = nearest_power(stream->pos + size); + stream->w_buffer = i_realloc(stream->w_buffer, old_size, + stream->buffer_size); + stream->buffer = stream->w_buffer; + (void)i_stream_get_buffer_space(stream, size, &avail_size); + i_assert(avail_size >= size); + } + return stream->w_buffer + stream->pos; +} + +static void stream_add_data(struct binary_converter_istream *bstream, + const void *data, size_t size) +{ + if (bstream->hdr_buf != NULL) { + buffer_append(bstream->hdr_buf, data, size); + } else if (size > 0) { + memcpy(stream_alloc_data(bstream, size), data, size); + bstream->istream.pos += size; + } +} + +static void stream_encode_base64(struct binary_converter_istream *bstream, + const void *_data, size_t size) +{ + const unsigned char *data = _data; + buffer_t buf; + void *dest; + size_t encode_size, max_encoded_size; + unsigned char base64_block[BASE64_BLOCK_INPUT_SIZE]; + unsigned int base64_block_len, missing_len, encode_blocks; + + if (bstream->base64_delayed_len > 0) { + if (bstream->base64_delayed_len == 1 && size == 1) { + bstream->base64_delayed[1] = data[0]; + bstream->base64_delayed_len++; + return; + } + memcpy(base64_block, bstream->base64_delayed, + bstream->base64_delayed_len); + base64_block_len = bstream->base64_delayed_len; + if (size == 0) { + /* finish base64 */ + } else { + missing_len = BASE64_BLOCK_INPUT_SIZE - base64_block_len; + i_assert(size >= missing_len); + memcpy(base64_block + base64_block_len, + data, missing_len); + data += missing_len; + size -= missing_len; + base64_block_len = BASE64_BLOCK_INPUT_SIZE; + } + + if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) { + memcpy(stream_alloc_data(bstream, 2), "\r\n", 2); + bstream->istream.pos += 2; + bstream->base64_block_pos = 0; + } + + dest = stream_alloc_data(bstream, BASE64_BLOCK_SIZE); + buffer_create_data(&buf, dest, BASE64_BLOCK_SIZE); + base64_encode(base64_block, base64_block_len, &buf); + bstream->istream.pos += buf.used; + bstream->base64_block_pos++; + bstream->base64_delayed_len = 0; + } + + while (size >= BASE64_BLOCK_INPUT_SIZE) { + if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) { + memcpy(stream_alloc_data(bstream, 2), "\r\n", 2); + bstream->istream.pos += 2; + bstream->base64_block_pos = 0; + } + + /* try to encode one full line of base64 blocks */ + encode_size = I_MIN(size, BASE64_BLOCKS_PER_LINE*BASE64_BLOCK_SIZE); + if (encode_size % BASE64_BLOCK_INPUT_SIZE != 0) + encode_size -= encode_size % BASE64_BLOCK_INPUT_SIZE; + encode_blocks = encode_size/BASE64_BLOCK_INPUT_SIZE; + if (bstream->base64_block_pos + encode_blocks > BASE64_BLOCKS_PER_LINE) { + encode_blocks = BASE64_BLOCKS_PER_LINE - + bstream->base64_block_pos; + encode_size = encode_blocks * BASE64_BLOCK_INPUT_SIZE; + } + + max_encoded_size = MAX_BASE64_ENCODED_SIZE(encode_size); + dest = stream_alloc_data(bstream, max_encoded_size); + buffer_create_data(&buf, dest, max_encoded_size); + base64_encode(data, encode_size, &buf); + bstream->istream.pos += buf.used; + bstream->base64_block_pos += encode_blocks; + + data += encode_size; + size -= encode_size; + } + if (size > 0) { + /* encode these when more data is available */ + i_assert(size < BASE64_BLOCK_INPUT_SIZE); + memcpy(bstream->base64_delayed, data, size); + bstream->base64_delayed_len = size; + } +} + +static bool part_can_convert(const struct message_part *part) +{ + /* some MUAs use "c-t-e: binary" for multiparts. + we don't want to convert them. */ + return (part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0; +} + +static void stream_add_hdr(struct binary_converter_istream *bstream, + const struct message_header_line *hdr) +{ + if (!hdr->continued) { + stream_add_data(bstream, hdr->name, hdr->name_len); + stream_add_data(bstream, hdr->middle, hdr->middle_len); + } + + stream_add_data(bstream, hdr->value, hdr->value_len); + if (!hdr->no_newline) + stream_add_data(bstream, "\r\n", 2); +} + +static ssize_t i_stream_binary_converter_read(struct istream_private *stream) +{ + /* @UNSAFE */ + struct binary_converter_istream *bstream = + (struct binary_converter_istream *)stream; + struct message_block block; + size_t old_size, new_size; + + if (stream->pos - stream->skip >= stream->max_buffer_size) + return -2; + + switch (message_parser_parse_next_block(bstream->parser, &block)) { + case -1: + /* done / error */ + stream->istream.eof = TRUE; + stream->istream.stream_errno = stream->parent->stream_errno; + return -1; + case 0: + /* need more data */ + return 0; + default: + break; + } + + old_size = stream->pos - stream->skip; + + if (block.part != bstream->convert_part && + bstream->convert_part != NULL) { + /* end of base64 encoded part */ + stream_encode_base64(bstream, NULL, 0); + } + + if (block.hdr != NULL) { + /* parsing a header */ + if (strcasecmp(block.hdr->name, "Content-Type") == 0) + bstream->content_type_seen = TRUE; + + if (strcasecmp(block.hdr->name, "Content-Transfer-Encoding") == 0 && + !block.hdr->continued && !block.hdr->continues && + block.hdr->value_len == 6 && + i_memcasecmp(block.hdr->value, "binary", 6) == 0 && + part_can_convert(block.part) && + bstream->convert_part != block.part) { + /* looks like we want to convert this body part to + base64, but if we haven't seen Content-Type yet + delay the decision until we've read the rest of + the header */ + i_assert(block.part != NULL); + bstream->convert_part = block.part; + bstream->base64_block_pos = 0; + if (!bstream->content_type_seen) { + i_assert(bstream->hdr_buf == NULL); + bstream->hdr_buf = buffer_create_dynamic(default_pool, 512); + stream_add_hdr(bstream, block.hdr); + bstream->cte_header_len = bstream->hdr_buf->used; + } else { + stream_add_data(bstream, + "Content-Transfer-Encoding: base64\r\n", 35); + } + } else if (block.hdr->eoh && bstream->hdr_buf != NULL) { + /* finish the decision about decoding */ + buffer_t *buf = bstream->hdr_buf; + const unsigned char *data; + + bstream->hdr_buf = NULL; + if (!part_can_convert(block.part)) { + bstream->convert_part = NULL; + stream_add_data(bstream, buf->data, buf->used); + } else { + stream_add_data(bstream, + "Content-Transfer-Encoding: base64\r\n", 35); + + data = CONST_PTR_OFFSET(buf->data, + bstream->cte_header_len); + stream_add_data(bstream, data, + buf->used - bstream->cte_header_len); + } + stream_add_data(bstream, "\r\n", 2); + buffer_free(&buf); + } else { + stream_add_hdr(bstream, block.hdr); + } + } else if (block.size == 0) { + /* end of header */ + if (bstream->hdr_buf != NULL) { + /* message has no body */ + bstream->convert_part = NULL; + stream_add_data(bstream, bstream->hdr_buf->data, + bstream->hdr_buf->used); + buffer_free(&bstream->hdr_buf); + } + bstream->content_type_seen = FALSE; + } else if (block.part == bstream->convert_part) { + /* convert body part to base64 */ + stream_encode_base64(bstream, block.data, block.size); + } else { + stream_add_data(bstream, block.data, block.size); + } + new_size = stream->pos - stream->skip; From dovecot at dovecot.org Wed Jun 20 02:24:24 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:24:24 +0300 Subject: dovecot-2.0: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/7720fb368e40 changeset: 13102:7720fb368e40 user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r 066c1acd272b -r 7720fb368e40 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Tue Jun 12 00:04:01 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -151,7 +151,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Wed Jun 20 02:24:31 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:24:31 +0300 Subject: dovecot-2.1: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/4461b48fcc1f changeset: 14566:4461b48fcc1f user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r 4ce1f9649592 -r 4461b48fcc1f src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Mon Jun 18 17:05:27 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -151,7 +151,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Wed Jun 20 02:24:48 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:24:48 +0300 Subject: dovecot-1.2: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-1.2/rev/a56eb5db0d87 changeset: 9655:a56eb5db0d87 user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r c80abc48d486 -r a56eb5db0d87 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Sun Mar 04 14:12:19 2012 +0200 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -143,7 +143,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Wed Jun 20 02:25:30 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:25:30 +0300 Subject: dovecot-1.1: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-1.1/rev/0ce9c27b109b changeset: 8377:0ce9c27b109b user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r 0cae9ccf09b9 -r 0ce9c27b109b src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Sun Mar 04 14:12:19 2012 +0200 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -142,7 +142,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Wed Jun 20 02:45:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:45:39 +0300 Subject: dovecot-2.2: imap parser: Added support for parsing literal8 (fo... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/68a8b650578e changeset: 14607:68a8b650578e user: Timo Sirainen date: Wed Jun 20 02:44:35 2012 +0300 description: imap parser: Added support for parsing literal8 (for BINARY extension) diffstat: src/lib-imap/imap-arg.h | 1 + src/lib-imap/imap-parser.c | 25 +++++++++++++++++++++++++ src/lib-imap/imap-parser.h | 4 +++- 3 files changed, 29 insertions(+), 1 deletions(-) diffs (99 lines): diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-arg.h --- a/src/lib-imap/imap-arg.h Wed Jun 20 02:23:42 2012 +0300 +++ b/src/lib-imap/imap-arg.h Wed Jun 20 02:44:35 2012 +0300 @@ -44,6 +44,7 @@ uoff_t literal_size; ARRAY_TYPE(imap_arg_list) list; } _data; + unsigned int literal8:1; /* BINARY literal8 used */ }; /* RFC 3501's astring type */ diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-parser.c --- a/src/lib-imap/imap-parser.c Wed Jun 20 02:23:42 2012 +0300 +++ b/src/lib-imap/imap-parser.c Wed Jun 20 02:44:35 2012 +0300 @@ -16,6 +16,7 @@ ARG_PARSE_ATOM, ARG_PARSE_STRING, ARG_PARSE_LITERAL, + ARG_PARSE_LITERAL8, ARG_PARSE_LITERAL_DATA, ARG_PARSE_LITERAL_DATA_FORCED }; @@ -45,6 +46,7 @@ unsigned int literal_skip_crlf:1; unsigned int literal_nonsync:1; + unsigned int literal8:1; unsigned int literal_size_return:1; unsigned int eol:1; unsigned int fatal_error:1; @@ -248,6 +250,7 @@ IMAP_ARG_LITERAL_SIZE_NONSYNC : IMAP_ARG_LITERAL_SIZE; arg->_data.literal_size = parser->literal_size; + arg->literal8 = parser->literal8; break; } /* fall through */ @@ -257,6 +260,7 @@ else arg->type = IMAP_ARG_STRING; arg->_data.str = imap_parser_strdup(parser, data, size); + arg->literal8 = parser->literal8; arg->str_len = size; break; default: @@ -514,10 +518,21 @@ parser->cur_type = ARG_PARSE_STRING; parser->str_first_escape = -1; break; + case '~': + if ((parser->flags & IMAP_PARSE_FLAG_LITERAL8) != 0) { + parser->error = "literal8 not allowed here"; + return FALSE; + } + parser->cur_type = ARG_PARSE_LITERAL8; + parser->literal_size = 0; + parser->literal_nonsync = FALSE; + parser->literal8 = TRUE; + break; case '{': parser->cur_type = ARG_PARSE_LITERAL; parser->literal_size = 0; parser->literal_nonsync = FALSE; + parser->literal8 = FALSE; break; case '(': imap_parser_open_list(parser); @@ -553,6 +568,16 @@ if (!imap_parser_read_string(parser, data, data_size)) return FALSE; break; + case ARG_PARSE_LITERAL8: + if (parser->cur_pos == data_size) + return FALSE; + if (data[parser->cur_pos] != '{') { + parser->error = "Expected '{'"; + return FALSE; + } + parser->cur_type = ARG_PARSE_LITERAL8; + parser->cur_pos++; + /* fall through */ case ARG_PARSE_LITERAL: if (!imap_parser_read_literal(parser, data, data_size)) return FALSE; diff -r 7b1378fe8820 -r 68a8b650578e src/lib-imap/imap-parser.h --- a/src/lib-imap/imap-parser.h Wed Jun 20 02:23:42 2012 +0300 +++ b/src/lib-imap/imap-parser.h Wed Jun 20 02:44:35 2012 +0300 @@ -18,7 +18,9 @@ /* Allow strings to contain CRLFs */ IMAP_PARSE_FLAG_MULTILINE_STR = 0x10, /* Parse in list context; ')' parses as EOL */ - IMAP_PARSE_FLAG_INSIDE_LIST = 0x20 + IMAP_PARSE_FLAG_INSIDE_LIST = 0x20, + /* Parse literal8 and set it as flag to imap_arg. */ + IMAP_PARSE_FLAG_LITERAL8 = 0x40 }; struct imap_parser; From dovecot at dovecot.org Wed Jun 20 02:45:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:45:39 +0300 Subject: dovecot-2.2: lib-test: Fixed test istream Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/e84f49c08458 changeset: 14608:e84f49c08458 user: Timo Sirainen date: Wed Jun 20 02:44:57 2012 +0300 description: lib-test: Fixed test istream diffstat: src/lib-test/test-common.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diffs (39 lines): diff -r 68a8b650578e -r e84f49c08458 src/lib-test/test-common.c --- a/src/lib-test/test-common.c Wed Jun 20 02:44:35 2012 +0300 +++ b/src/lib-test/test-common.c Wed Jun 20 02:44:57 2012 +0300 @@ -17,7 +17,7 @@ struct test_istream { struct istream_private istream; unsigned int skip_diff; - size_t max_pos, max_buffer_size; + size_t max_pos; bool allow_eof; }; @@ -29,7 +29,7 @@ i_assert(stream->skip <= stream->pos); - if (stream->pos - stream->skip >= tstream->max_buffer_size) + if (stream->pos - stream->skip >= tstream->istream.max_buffer_size) return -2; if (tstream->max_pos < stream->pos) { @@ -88,7 +88,7 @@ (void)i_stream_create(&tstream->istream, NULL, -1); tstream->istream.statbuf.st_size = tstream->max_pos = size; tstream->allow_eof = TRUE; - tstream->max_buffer_size = (size_t)-1; + tstream->istream.max_buffer_size = (size_t)-1; return &tstream->istream.istream; } @@ -110,7 +110,7 @@ struct test_istream *tstream = (struct test_istream *)input->real_stream; - tstream->max_buffer_size = size; + tstream->istream.max_buffer_size = size; } void test_istream_set_size(struct istream *input, uoff_t size) From dovecot at dovecot.org Wed Jun 20 02:45:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 02:45:39 +0300 Subject: dovecot-2.2: imap: Implemented BINARY extension support for APPE... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/284fdbbeb262 changeset: 14609:284fdbbeb262 user: Timo Sirainen date: Wed Jun 20 02:45:20 2012 +0300 description: imap: Implemented BINARY extension support for APPEND/CATENATE. diffstat: src/imap/cmd-append.c | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diffs (63 lines): diff -r e84f49c08458 -r 284fdbbeb262 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Wed Jun 20 02:44:57 2012 +0300 +++ b/src/imap/cmd-append.c Wed Jun 20 02:45:20 2012 +0300 @@ -6,6 +6,7 @@ #include "istream-chain.h" #include "ostream.h" #include "str.h" +#include "istream-binary-converter.h" #include "mail-storage-private.h" #include "imap-parser.h" #include "imap-date.h" @@ -41,6 +42,7 @@ unsigned int count; unsigned int message_input:1; + unsigned int binary_input:1; unsigned int catenate:1; unsigned int failed:1; }; @@ -369,6 +371,7 @@ ret = imap_parser_read_args(ctx->save_parser, 0, IMAP_PARSE_FLAG_LITERAL_SIZE | + IMAP_PARSE_FLAG_LITERAL8 | IMAP_PARSE_FLAG_INSIDE_LIST, &args); if (ret == -1) { if (!ctx->failed) { @@ -430,6 +433,7 @@ enum mail_flags flags; const char *const *keywords_list; struct mail_keywords *keywords; + struct istream *input; const char *internal_date_str; time_t internal_date; int ret, timezone_offset; @@ -458,8 +462,15 @@ valid = TRUE; ctx->catenate = TRUE; } + /* We'll do BINARY conversion only if the CATENATE's first + part is a literal8. If it doesn't and a literal8 is seen + later we'll abort the append with UNKNOWN-CTE. */ + ctx->binary_input = imap_arg_atom_equals(&cat_list[0], "TEXT") && + cat_list[1].literal8; + } else if (imap_arg_get_literal_size(*args, &ctx->literal_size)) { *nonsync_r = (*args)->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; + ctx->binary_input = (*args)->literal8; valid = TRUE; } @@ -521,6 +532,11 @@ ctx->input = ctx->litinput; i_stream_ref(ctx->input); } + if (ctx->binary_input) { + input = i_stream_create_binary_converter(ctx->input); + i_stream_unref(&ctx->input); + ctx->input = input; + } /* save the mail */ ctx->save_ctx = mailbox_save_alloc(ctx->t); From dovecot at dovecot.org Wed Jun 20 05:40:05 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 05:40:05 +0300 Subject: dovecot-2.2: imap: Fixed CATENATE support to send "+ OK" for lit... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/4bcbb3ff9e35 changeset: 14610:4bcbb3ff9e35 user: Timo Sirainen date: Wed Jun 20 05:39:50 2012 +0300 description: imap: Fixed CATENATE support to send "+ OK" for literals. diffstat: src/imap/cmd-append.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diffs (25 lines): diff -r 284fdbbeb262 -r 4bcbb3ff9e35 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Wed Jun 20 02:45:20 2012 +0300 +++ b/src/imap/cmd-append.c Wed Jun 20 05:39:50 2012 +0300 @@ -686,14 +686,14 @@ /* after literal comes CRLF, if we fail make sure we eat it away */ client->input_skip_line = TRUE; + ctx->message_input = TRUE; + } - if (!nonsync) { - o_stream_send(client->output, "+ OK\r\n", 6); - o_stream_flush(client->output); - o_stream_uncork(client->output); - o_stream_cork(client->output); - } - ctx->message_input = TRUE; + if (!nonsync) { + o_stream_send(client->output, "+ OK\r\n", 6); + o_stream_flush(client->output); + o_stream_uncork(client->output); + o_stream_cork(client->output); } cmd->func = cmd_append_continue_message; From dovecot at dovecot.org Wed Jun 20 05:42:01 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 05:42:01 +0300 Subject: dovecot-2.2: imap: Fixes to handling BINARY APPENDs. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/4d7dc53d89e7 changeset: 14611:4d7dc53d89e7 user: Timo Sirainen date: Wed Jun 20 05:41:54 2012 +0300 description: imap: Fixes to handling BINARY APPENDs. diffstat: src/imap/cmd-append.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-) diffs (25 lines): diff -r 4bcbb3ff9e35 -r 4d7dc53d89e7 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Wed Jun 20 05:39:50 2012 +0300 +++ b/src/imap/cmd-append.c Wed Jun 20 05:41:54 2012 +0300 @@ -325,6 +325,11 @@ args++; if (!imap_arg_get_literal_size(args, &ctx->literal_size)) break; + if (args->literal8 && !ctx->binary_input) { + client_send_tagline(cmd, + "NO [UNKNOWN-CTE] Binary input allowed only when the first part is binary."); + return -1; + } *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; return cmd_append_catenate_text(cmd) < 0 ? -1 : 1; } else { @@ -644,7 +649,8 @@ /* [] [] */ ret = imap_parser_read_args(ctx->save_parser, 0, - IMAP_PARSE_FLAG_LITERAL_SIZE, &args); + IMAP_PARSE_FLAG_LITERAL_SIZE | + IMAP_PARSE_FLAG_LITERAL8, &args); if (ret == -1) { if (!ctx->failed) { msg = imap_parser_get_error(ctx->save_parser, &fatal); From dovecot at dovecot.org Wed Jun 20 06:09:21 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:09:21 +0300 Subject: dovecot-2.2: istream-binary-converter: Added maximum memory usag... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/347c2ca867b7 changeset: 14612:347c2ca867b7 user: Timo Sirainen date: Wed Jun 20 06:09:04 2012 +0300 description: istream-binary-converter: Added maximum memory usage limit for header parsing. diffstat: src/lib-mail/istream-binary-converter.c | 73 +++++++++++++++++---------- src/lib-mail/test-istream-binary-converter.c | 4 +- 2 files changed, 47 insertions(+), 30 deletions(-) diffs (140 lines): diff -r 4d7dc53d89e7 -r 347c2ca867b7 src/lib-mail/istream-binary-converter.c --- a/src/lib-mail/istream-binary-converter.c Wed Jun 20 05:41:54 2012 +0300 +++ b/src/lib-mail/istream-binary-converter.c Wed Jun 20 06:09:04 2012 +0300 @@ -10,6 +10,7 @@ #define BASE64_BLOCK_INPUT_SIZE 3 #define BASE64_BLOCK_SIZE 4 #define BASE64_BLOCKS_PER_LINE (76/BASE64_BLOCK_SIZE) +#define MAX_HDR_BUFFER_SIZE (1024*32) struct binary_converter_istream { struct istream_private istream; @@ -26,6 +27,9 @@ unsigned int content_type_seen:1; }; +static void stream_add_data(struct binary_converter_istream *bstream, + const void *data, size_t size); + static void * stream_alloc_data(struct binary_converter_istream *bstream, size_t size) { @@ -45,15 +49,51 @@ return stream->w_buffer + stream->pos; } +static bool part_can_convert(const struct message_part *part) +{ + /* some MUAs use "c-t-e: binary" for multiparts. + we don't want to convert them. */ + return (part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0; +} + +static void +stream_finish_convert_decision(struct binary_converter_istream *bstream) +{ + buffer_t *buf = bstream->hdr_buf; + const unsigned char *data; + + bstream->hdr_buf = NULL; + if (!part_can_convert(bstream->convert_part)) { + bstream->convert_part = NULL; + stream_add_data(bstream, buf->data, buf->used); + } else { + stream_add_data(bstream, + "Content-Transfer-Encoding: base64\r\n", 35); + + data = CONST_PTR_OFFSET(buf->data, bstream->cte_header_len); + stream_add_data(bstream, data, + buf->used - bstream->cte_header_len); + } + buffer_free(&buf); +} + static void stream_add_data(struct binary_converter_istream *bstream, const void *data, size_t size) { + if (size == 0) + return; + if (bstream->hdr_buf != NULL) { - buffer_append(bstream->hdr_buf, data, size); - } else if (size > 0) { - memcpy(stream_alloc_data(bstream, size), data, size); - bstream->istream.pos += size; + if (bstream->hdr_buf->used + size <= MAX_HDR_BUFFER_SIZE) { + buffer_append(bstream->hdr_buf, data, size); + return; + } + /* buffer is getting too large. just finish the decision. */ + stream_finish_convert_decision(bstream); } + + memcpy(stream_alloc_data(bstream, size), data, size); + bstream->istream.pos += size; } static void stream_encode_base64(struct binary_converter_istream *bstream, @@ -137,13 +177,6 @@ } } -static bool part_can_convert(const struct message_part *part) -{ - /* some MUAs use "c-t-e: binary" for multiparts. - we don't want to convert them. */ - return (part->flags & MESSAGE_PART_FLAG_MULTIPART) == 0; -} - static void stream_add_hdr(struct binary_converter_istream *bstream, const struct message_header_line *hdr) { @@ -218,24 +251,8 @@ } } else if (block.hdr->eoh && bstream->hdr_buf != NULL) { /* finish the decision about decoding */ - buffer_t *buf = bstream->hdr_buf; - const unsigned char *data; - - bstream->hdr_buf = NULL; - if (!part_can_convert(block.part)) { - bstream->convert_part = NULL; - stream_add_data(bstream, buf->data, buf->used); - } else { - stream_add_data(bstream, - "Content-Transfer-Encoding: base64\r\n", 35); - - data = CONST_PTR_OFFSET(buf->data, - bstream->cte_header_len); - stream_add_data(bstream, data, - buf->used - bstream->cte_header_len); - } + stream_finish_convert_decision(bstream); stream_add_data(bstream, "\r\n", 2); - buffer_free(&buf); } else { stream_add_hdr(bstream, block.hdr); } diff -r 4d7dc53d89e7 -r 347c2ca867b7 src/lib-mail/test-istream-binary-converter.c --- a/src/lib-mail/test-istream-binary-converter.c Wed Jun 20 05:41:54 2012 +0300 +++ b/src/lib-mail/test-istream-binary-converter.c Wed Jun 20 06:09:04 2012 +0300 @@ -27,8 +27,8 @@ "\r\n" "mime header\r\n" "\r\n--bound\r\n" +"Content-Transfer-Encoding: binary\r\n" "Content-Type: text/plain\r\n" -"Content-Transfer-Encoding: binary\r\n" "\r\n" BINARY_TEXT_LONG "\r\n--bound\r\n" @@ -48,8 +48,8 @@ "\r\n" "mime header\r\n" "\r\n--bound\r\n" +"Content-Transfer-Encoding: base64\r\n" "Content-Type: text/plain\r\n" -"Content-Transfer-Encoding: base64\r\n" "\r\n" BINARY_TEXT_LONG_BASE64 "\r\n--bound\r\n" From dovecot at dovecot.org Wed Jun 20 06:22:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:22:14 +0300 Subject: dovecot-2.2: lib-storage: Added mailbox_move(), which is basical... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/8d596b5adbab changeset: 14613:8d596b5adbab user: Timo Sirainen date: Wed Jun 20 06:15:46 2012 +0300 description: lib-storage: Added mailbox_move(), which is basically copy+expunge. diffstat: src/lib-storage/mail-storage-private.h | 2 ++ src/lib-storage/mail-storage.c | 12 ++++++++++++ src/lib-storage/mail-storage.h | 3 +++ 3 files changed, 17 insertions(+), 0 deletions(-) diffs (47 lines): diff -r 347c2ca867b7 -r 8d596b5adbab src/lib-storage/mail-storage-private.h --- a/src/lib-storage/mail-storage-private.h Wed Jun 20 06:09:04 2012 +0300 +++ b/src/lib-storage/mail-storage-private.h Wed Jun 20 06:15:46 2012 +0300 @@ -470,6 +470,8 @@ unsigned int copying_via_save:1; /* mail is being saved, not copied */ unsigned int saving:1; + /* mail is being moved - ignore quota */ + unsigned int moving:1; }; struct mailbox_sync_context { diff -r 347c2ca867b7 -r 8d596b5adbab src/lib-storage/mail-storage.c --- a/src/lib-storage/mail-storage.c Wed Jun 20 06:09:04 2012 +0300 +++ b/src/lib-storage/mail-storage.c Wed Jun 20 06:15:46 2012 +0300 @@ -1711,6 +1711,18 @@ return ret; } +int mailbox_move(struct mail_save_context **_ctx, struct mail *mail) +{ + struct mail_save_context *ctx = *_ctx; + + ctx->moving = TRUE; + if (mailbox_copy(_ctx, mail) < 0) + return -1; + + mail_expunge(mail); + return 0; +} + int mailbox_save_using_mail(struct mail_save_context **ctx, struct mail *mail) { (*ctx)->saving = TRUE; diff -r 347c2ca867b7 -r 8d596b5adbab src/lib-storage/mail-storage.h --- a/src/lib-storage/mail-storage.h Wed Jun 20 06:09:04 2012 +0300 +++ b/src/lib-storage/mail-storage.h Wed Jun 20 06:15:46 2012 +0300 @@ -679,6 +679,9 @@ /* Copy the given message. You'll need to specify the flags etc. using the mailbox_save_*() functions. */ int mailbox_copy(struct mail_save_context **ctx, struct mail *mail); +/* Move the given message. This is usually equivalent to copy+expunge, + but without enforcing quota. */ +int mailbox_move(struct mail_save_context **ctx, struct mail *mail); /* Same as mailbox_copy(), but treat the message as if it's being saved, not copied. (For example: New mail delivered to multiple maildirs, with each mails being hard link copies.) */ From dovecot at dovecot.org Wed Jun 20 06:22:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:22:14 +0300 Subject: dovecot-2.2: acl: Optimize failing mailbox_move() when expunge r... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/544dc10d4b04 changeset: 14614:544dc10d4b04 user: Timo Sirainen date: Wed Jun 20 06:17:00 2012 +0300 description: acl: Optimize failing mailbox_move() when expunge right is missing. diffstat: src/plugins/acl/acl-mailbox.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diffs (16 lines): diff -r 8d596b5adbab -r 544dc10d4b04 src/plugins/acl/acl-mailbox.c --- a/src/plugins/acl/acl-mailbox.c Wed Jun 20 06:15:46 2012 +0300 +++ b/src/plugins/acl/acl-mailbox.c Wed Jun 20 06:17:00 2012 +0300 @@ -392,6 +392,12 @@ struct acl_mailbox *abox = ACL_CONTEXT(t->box); enum acl_storage_rights save_right; + if (ctx->moving) { + if (acl_mailbox_right_lookup(mail->box, + ACL_STORAGE_RIGHT_EXPUNGE) <= 0) + return -1; + } + save_right = (t->box->flags & MAILBOX_FLAG_POST_SESSION) != 0 ? ACL_STORAGE_RIGHT_POST : ACL_STORAGE_RIGHT_INSERT; if (acl_mailbox_right_lookup(t->box, save_right) <= 0) From dovecot at dovecot.org Wed Jun 20 06:22:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:22:14 +0300 Subject: dovecot-2.2: quota: Ignore quota when handling mailbox_move(). Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/0a2126680120 changeset: 14615:0a2126680120 user: Timo Sirainen date: Wed Jun 20 06:17:40 2012 +0300 description: quota: Ignore quota when handling mailbox_move(). diffstat: src/plugins/quota/quota-storage.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diffs (44 lines): diff -r 544dc10d4b04 -r 0a2126680120 src/plugins/quota/quota-storage.c --- a/src/plugins/quota/quota-storage.c Wed Jun 20 06:17:00 2012 +0300 +++ b/src/plugins/quota/quota-storage.c Wed Jun 20 06:17:40 2012 +0300 @@ -170,8 +170,17 @@ if (qbox->module_ctx.super.copy(ctx, mail) < 0) return -1; - /* if copying used saving internally, we already checked the quota */ - return ctx->copying_via_save ? 0 : quota_check(t, ctx->dest_mail); + if (ctx->copying_via_save) { + /* copying used saving internally, we already checked the + quota */ + return 0; + } + if (ctx->moving) { + /* the mail is being moved. the quota won't increase, so allow + this even if user is currently over quota */ + return 0; + } + return quota_check(t, ctx->dest_mail); } static int @@ -183,7 +192,7 @@ uoff_t size; int ret; - if (i_stream_get_size(input, TRUE, &size) > 0) { + if (i_stream_get_size(input, TRUE, &size) > 0 && !ctx->moving) { /* Input size is known, check for quota immediately. This check isn't perfect, especially because input stream's linefeeds may contain CR+LFs while physical message would @@ -227,6 +236,11 @@ if (qbox->module_ctx.super.save_finish(ctx) < 0) return -1; + if (ctx->moving) { + /* the mail is being moved. the quota won't increase, so allow + this even if user is currently over quota */ + return 0; + } return quota_check(ctx->transaction, ctx->dest_mail); } From dovecot at dovecot.org Wed Jun 20 06:22:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:22:14 +0300 Subject: dovecot-2.2: imap: Implemented MOVE extension. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3a53a2f7927a changeset: 14616:3a53a2f7927a user: Timo Sirainen date: Wed Jun 20 06:21:17 2012 +0300 description: imap: Implemented MOVE extension. diffstat: src/imap/cmd-copy.c | 47 +++++++++++++++++++++++++++++++++++++---------- src/imap/imap-commands.c | 2 ++ src/imap/imap-commands.h | 1 + 3 files changed, 40 insertions(+), 10 deletions(-) diffs (128 lines): diff -r 0a2126680120 -r 3a53a2f7927a src/imap/cmd-copy.c --- a/src/imap/cmd-copy.c Wed Jun 20 06:17:40 2012 +0300 +++ b/src/imap/cmd-copy.c Wed Jun 20 06:21:17 2012 +0300 @@ -28,7 +28,7 @@ } } -static int fetch_and_copy(struct client *client, +static int fetch_and_copy(struct client *client, bool move, struct mailbox_transaction_context *t, struct mail_search_args *search_args, const char **src_uidset_r, @@ -62,8 +62,15 @@ save_ctx = mailbox_save_alloc(t); mailbox_save_copy_flags(save_ctx, mail); - if (mailbox_copy(&save_ctx, mail) < 0) - ret = mail->expunged ? 0 : -1; + if (move) { + if (mailbox_move(&save_ctx, mail) < 0) + ret = -1; + } else { + if (mailbox_copy(&save_ctx, mail) < 0) + ret = -1; + } + if (ret < 0 && mail->expunged) + ret = 0; msgset_generator_next(&srcset_ctx, mail->uid); } @@ -72,15 +79,20 @@ if (mailbox_search_deinit(&search_ctx) < 0) ret = -1; - if (mailbox_transaction_commit(&src_trans) < 0) - ret = -1; + if (ret <= 0 && move) { + /* move failed, don't expunge anything */ + mailbox_transaction_rollback(&src_trans); + } else { + if (mailbox_transaction_commit(&src_trans) < 0) + ret = -1; + } *src_uidset_r = str_c(src_uidset); *copy_count_r = copy_count; return ret; } -bool cmd_copy(struct client_command_context *cmd) +static bool cmd_copy_full(struct client_command_context *cmd, bool move) { struct client *client = cmd->client; struct mail_storage *dest_storage; @@ -114,7 +126,8 @@ t = mailbox_transaction_begin(destbox, MAILBOX_TRANSACTION_FLAG_EXTERNAL | MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS); - ret = fetch_and_copy(client, t, search_args, &src_uidset, ©_count); + ret = fetch_and_copy(client, move, t, search_args, + &src_uidset, ©_count); mail_search_args_unref(&search_args); msg = t_str_new(256); @@ -123,11 +136,12 @@ else if (mailbox_transaction_commit_get_changes(&t, &changes) < 0) ret = -1; else if (copy_count == 0) { - str_append(msg, "OK No messages copied."); + str_append(msg, "OK No messages found."); pool_unref(&changes.pool); } else if (seq_range_count(&changes.saved_uids) == 0) { /* not supported by backend (virtual) */ - str_append(msg, "OK Copy completed."); + str_append(msg, move ? "OK Move completed." : + "OK Copy completed."); pool_unref(&changes.pool); } else { i_assert(copy_count == seq_range_count(&changes.saved_uids)); @@ -135,7 +149,10 @@ str_printfa(msg, "OK [COPYUID %u %s ", changes.uid_validity, src_uidset); imap_write_seq_range(msg, &changes.saved_uids); - str_append(msg, "] Copy completed."); + if (move) + str_append(msg, "] Move completed."); + else + str_append(msg, "] Copy completed."); pool_unref(&changes.pool); } @@ -158,3 +175,13 @@ return TRUE; } } + +bool cmd_copy(struct client_command_context *cmd) +{ + return cmd_copy_full(cmd, FALSE); +} + +bool cmd_uid_move(struct client_command_context *cmd) +{ + return cmd_copy_full(cmd, TRUE); +} diff -r 0a2126680120 -r 3a53a2f7927a src/imap/imap-commands.c --- a/src/imap/imap-commands.c Wed Jun 20 06:17:40 2012 +0300 +++ b/src/imap/imap-commands.c Wed Jun 20 06:21:17 2012 +0300 @@ -56,6 +56,8 @@ { "SORT", cmd_sort, COMMAND_FLAG_USES_SEQS }, { "THREAD", cmd_thread, COMMAND_FLAG_USES_SEQS }, { "UID EXPUNGE", cmd_uid_expunge, COMMAND_FLAG_BREAKS_SEQS }, + { "UID MOVE", cmd_uid_move, COMMAND_FLAG_USES_SEQS | + COMMAND_FLAG_BREAKS_SEQS }, { "UID SORT", cmd_sort, COMMAND_FLAG_BREAKS_SEQS }, { "UID THREAD", cmd_thread, COMMAND_FLAG_BREAKS_SEQS }, { "UNSELECT", cmd_unselect, COMMAND_FLAG_BREAKS_MAILBOX }, diff -r 0a2126680120 -r 3a53a2f7927a src/imap/imap-commands.h --- a/src/imap/imap-commands.h Wed Jun 20 06:17:40 2012 +0300 +++ b/src/imap/imap-commands.h Wed Jun 20 06:21:17 2012 +0300 @@ -110,6 +110,7 @@ bool cmd_sort(struct client_command_context *cmd); bool cmd_thread(struct client_command_context *cmd); bool cmd_uid_expunge(struct client_command_context *cmd); +bool cmd_uid_move(struct client_command_context *cmd); bool cmd_unselect(struct client_command_context *cmd); bool cmd_x_cancel(struct client_command_context *cmd); From dovecot at dovecot.org Wed Jun 20 06:22:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:22:14 +0300 Subject: dovecot-2.2: imap parser: literal8 flag was handled in opposite ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c14c58bedafe changeset: 14617:c14c58bedafe user: Timo Sirainen date: Wed Jun 20 06:21:57 2012 +0300 description: imap parser: literal8 flag was handled in opposite way. diffstat: src/lib-imap/imap-parser.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 3a53a2f7927a -r c14c58bedafe src/lib-imap/imap-parser.c --- a/src/lib-imap/imap-parser.c Wed Jun 20 06:21:17 2012 +0300 +++ b/src/lib-imap/imap-parser.c Wed Jun 20 06:21:57 2012 +0300 @@ -519,7 +519,7 @@ parser->str_first_escape = -1; break; case '~': - if ((parser->flags & IMAP_PARSE_FLAG_LITERAL8) != 0) { + if ((parser->flags & IMAP_PARSE_FLAG_LITERAL8) == 0) { parser->error = "literal8 not allowed here"; return FALSE; } From dovecot at dovecot.org Wed Jun 20 06:32:16 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 20 Jun 2012 06:32:16 +0300 Subject: dovecot-2.2: imap MOVE: Don't commit expunge transaction before ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/344bd3d47ced changeset: 14618:344bd3d47ced user: Timo Sirainen date: Wed Jun 20 06:32:06 2012 +0300 description: imap MOVE: Don't commit expunge transaction before the copy transaction has succeeded. diffstat: src/imap/cmd-copy.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diffs (62 lines): diff -r c14c58bedafe -r 344bd3d47ced src/imap/cmd-copy.c --- a/src/imap/cmd-copy.c Wed Jun 20 06:21:57 2012 +0300 +++ b/src/imap/cmd-copy.c Wed Jun 20 06:32:06 2012 +0300 @@ -30,6 +30,7 @@ static int fetch_and_copy(struct client *client, bool move, struct mailbox_transaction_context *t, + struct mailbox_transaction_context **src_trans_r, struct mail_search_args *search_args, const char **src_uidset_r, unsigned int *copy_count_r) @@ -79,14 +80,7 @@ if (mailbox_search_deinit(&search_ctx) < 0) ret = -1; - if (ret <= 0 && move) { - /* move failed, don't expunge anything */ - mailbox_transaction_rollback(&src_trans); - } else { - if (mailbox_transaction_commit(&src_trans) < 0) - ret = -1; - } - + *src_trans_r = src_trans; *src_uidset_r = str_c(src_uidset); *copy_count_r = copy_count; return ret; @@ -97,7 +91,7 @@ struct client *client = cmd->client; struct mail_storage *dest_storage; struct mailbox *destbox; - struct mailbox_transaction_context *t; + struct mailbox_transaction_context *t, *src_trans; struct mail_search_args *search_args; const char *messageset, *mailbox, *src_uidset; enum mailbox_sync_flags sync_flags = 0; @@ -126,7 +120,7 @@ t = mailbox_transaction_begin(destbox, MAILBOX_TRANSACTION_FLAG_EXTERNAL | MAILBOX_TRANSACTION_FLAG_ASSIGN_UIDS); - ret = fetch_and_copy(client, move, t, search_args, + ret = fetch_and_copy(client, move, t, &src_trans, search_args, &src_uidset, ©_count); mail_search_args_unref(&search_args); @@ -156,7 +150,15 @@ pool_unref(&changes.pool); } - dest_storage = mailbox_get_storage(destbox); + if (ret <= 0 && move) { + /* move failed, don't expunge anything */ + mailbox_transaction_rollback(&src_trans); + } else { + if (mailbox_transaction_commit(&src_trans) < 0) + ret = -1; + } + + dest_storage = mailbox_get_storage(destbox); if (destbox != client->mailbox) { sync_flags |= MAILBOX_SYNC_FLAG_FAST; imap_flags |= IMAP_SYNC_FLAG_SAFE; From dovecot at dovecot.org Thu Jun 21 14:52:07 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 14:52:07 +0300 Subject: dovecot-2.2: lib-storage: Fixed mailbox_status.unseen count for ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/73ee8d00888d changeset: 14619:73ee8d00888d user: Timo Sirainen date: Thu Jun 21 14:51:36 2012 +0300 description: lib-storage: Fixed mailbox_status.unseen count for private indexes. diffstat: src/lib-storage/index/index-status.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diffs (37 lines): diff -r 344bd3d47ced -r 73ee8d00888d src/lib-storage/index/index-status.c --- a/src/lib-storage/index/index-status.c Wed Jun 20 06:32:06 2012 +0300 +++ b/src/lib-storage/index/index-status.c Thu Jun 21 14:51:36 2012 +0300 @@ -33,7 +33,7 @@ enum mailbox_status_items items, struct mailbox_status *status_r) { - const struct mail_index_header *hdr; + const struct mail_index_header *hdr, *hdr_pvt; memset(status_r, 0, sizeof(struct mailbox_status)); @@ -46,6 +46,8 @@ /* we can get most of the status items without any trouble */ hdr = mail_index_get_header(box->view); + hdr_pvt = box->view_pvt == NULL ? NULL : + mail_index_get_header(box->view_pvt); status_r->messages = hdr->messages_count; if ((items & STATUS_RECENT) != 0) { /* make sure recent count is set, in case syncing hasn't @@ -54,7 +56,14 @@ status_r->recent = index_mailbox_get_recent_count(box); i_assert(status_r->recent <= status_r->messages); } - status_r->unseen = hdr->messages_count - hdr->seen_messages_count; + if (hdr_pvt == NULL || + (mailbox_get_private_flags_mask(box) & MAIL_SEEN) == 0) { + status_r->unseen = hdr->messages_count - + hdr->seen_messages_count; + } else { + status_r->unseen = hdr_pvt->messages_count - + hdr_pvt->seen_messages_count; + } status_r->uidvalidity = hdr->uid_validity; status_r->uidnext = hdr->next_uid; status_r->first_recent_uid = hdr->first_recent_uid; From dovecot at dovecot.org Thu Jun 21 18:48:56 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 18:48:56 +0300 Subject: dovecot-2.1: imapc: Don't crash when using multiple imapc namesp... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/b13753851a07 changeset: 14567:b13753851a07 user: Timo Sirainen date: Thu Jun 21 18:48:38 2012 +0300 description: imapc: Don't crash when using multiple imapc namespaces. diffstat: src/lib-storage/index/imapc/imapc-storage.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diffs (32 lines): diff -r 4461b48fcc1f -r b13753851a07 src/lib-storage/index/imapc/imapc-storage.c --- a/src/lib-storage/index/imapc/imapc-storage.c Wed Jun 20 02:21:54 2012 +0300 +++ b/src/lib-storage/index/imapc/imapc-storage.c Thu Jun 21 18:48:38 2012 +0300 @@ -275,6 +275,19 @@ imapc_client_deinit(&storage->client); } +static void imapc_storage_add_list(struct mail_storage *_storage, + struct mailbox_list *_list) +{ + struct imapc_storage *storage = (struct imapc_storage *)_storage; + struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list; + + i_assert(storage->list != NULL); + i_assert(storage->list->sep != '\0'); + + list->storage = storage; + list->sep = storage->list->sep; +} + void imapc_storage_register_untagged(struct imapc_storage *storage, const char *name, imapc_storage_callback_t *callback) @@ -752,7 +765,7 @@ imapc_storage_alloc, imapc_storage_create, imapc_storage_destroy, - NULL, + imapc_storage_add_list, imapc_storage_get_list_settings, NULL, imapc_mailbox_alloc, From dovecot at dovecot.org Thu Jun 21 19:12:16 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 19:12:16 +0300 Subject: dovecot-2.1: quota: Don't crash at init if one of the namespaces... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/046f03b33584 changeset: 14568:046f03b33584 user: Timo Sirainen date: Thu Jun 21 19:12:04 2012 +0300 description: quota: Don't crash at init if one of the namespaces no root dir. diffstat: src/plugins/quota/quota.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r b13753851a07 -r 046f03b33584 src/plugins/quota/quota.c --- a/src/plugins/quota/quota.c Thu Jun 21 18:48:38 2012 +0300 +++ b/src/plugins/quota/quota.c Thu Jun 21 19:12:04 2012 +0300 @@ -639,7 +639,7 @@ for (i = 0; i < count; i++) { path2 = mailbox_list_get_path(namespaces[i]->list, NULL, MAILBOX_LIST_PATH_TYPE_MAILBOX); - if (strcmp(path, path2) == 0) { + if (path2 != NULL && strcmp(path, path2) == 0) { /* duplicate */ return; } From dovecot at dovecot.org Thu Jun 21 21:25:14 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:25:14 +0300 Subject: dovecot-2.1: imap: If DELETE can't succeed because mailbox has c... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/e62979a15657 changeset: 14569:e62979a15657 user: Timo Sirainen date: Thu Jun 21 21:25:04 2012 +0300 description: imap: If DELETE can't succeed because mailbox has children, don't give [ALREADYEXISTS] code. diffstat: src/imap/cmd-delete.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diffs (34 lines): diff -r 046f03b33584 -r e62979a15657 src/imap/cmd-delete.c --- a/src/imap/cmd-delete.c Thu Jun 21 19:12:04 2012 +0300 +++ b/src/imap/cmd-delete.c Thu Jun 21 21:25:04 2012 +0300 @@ -8,7 +8,8 @@ struct client *client = cmd->client; struct mail_namespace *ns; struct mailbox *box; - const char *name; + const char *name, *errstr; + enum mail_error error; /* */ if (!client_read_string_args(cmd, 1, &name)) @@ -32,10 +33,17 @@ mailbox_free(&client->mailbox); } - if (mailbox_delete(box) < 0) - client_send_storage_error(cmd, mailbox_get_storage(box)); - else + if (mailbox_delete(box) == 0) client_send_tagline(cmd, "OK Delete completed."); + else { + errstr = mailbox_get_last_error(box, &error); + if (error != MAIL_ERROR_EXISTS) + client_send_storage_error(cmd, mailbox_get_storage(box)); + else { + /* mailbox has children */ + client_send_tagline(cmd, t_strdup_printf("NO %s", errstr)); + } + } mailbox_free(&box); return TRUE; } From dovecot at dovecot.org Thu Jun 21 21:54:02 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:54:02 +0300 Subject: dovecot-2.2: lib-mail: Added istream-nonuls for converting NUL b... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3a267dec53ca changeset: 14620:3a267dec53ca user: Timo Sirainen date: Thu Jun 21 21:44:28 2012 +0300 description: lib-mail: Added istream-nonuls for converting NUL bytes to something else. diffstat: src/lib-mail/Makefile.am | 3 + src/lib-mail/istream-nonuls.c | 88 +++++++++++++++++++++++++++++++++++++++++++ src/lib-mail/istream-nonuls.h | 7 +++ 3 files changed, 98 insertions(+), 0 deletions(-) diffs (130 lines): diff -r 73ee8d00888d -r 3a267dec53ca src/lib-mail/Makefile.am --- a/src/lib-mail/Makefile.am Thu Jun 21 14:51:36 2012 +0300 +++ b/src/lib-mail/Makefile.am Thu Jun 21 21:44:28 2012 +0300 @@ -9,6 +9,7 @@ istream-binary-converter.c \ istream-dot.c \ istream-header-filter.c \ + istream-nonuls.c \ mail-user-hash.c \ mbox-from.c \ message-address.c \ @@ -31,6 +32,7 @@ istream-binary-converter.h \ istream-dot.h \ istream-header-filter.h \ + istream-nonuls.h \ mail-user-hash.h \ mbox-from.h \ mail-types.h \ @@ -43,6 +45,7 @@ message-id.h \ message-parser.h \ message-part-serialize.h \ + message-binary-part.h \ message-search.h \ message-send.h \ message-size.h \ diff -r 73ee8d00888d -r 3a267dec53ca src/lib-mail/istream-nonuls.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-nonuls.c Thu Jun 21 21:44:28 2012 +0300 @@ -0,0 +1,88 @@ +/* Copyright (c) 2007-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "istream-private.h" +#include "istream-nonuls.h" + +struct nonuls_istream { + struct istream_private istream; + char replace_chr; +}; + +static int i_stream_read_parent(struct istream_private *stream) +{ + size_t size; + ssize_t ret; + + (void)i_stream_get_data(stream->parent, &size); + if (size > 0) + return 1; + + ret = i_stream_read(stream->parent); + if (ret <= 0) { + stream->istream.stream_errno = stream->parent->stream_errno; + stream->istream.eof = stream->parent->eof; + return ret; + } + (void)i_stream_get_data(stream->parent, &size); + i_assert(size != 0); + return 1; +} + +static ssize_t i_stream_nonuls_read(struct istream_private *stream) +{ + struct nonuls_istream *nstream = (struct nonuls_istream *)stream; + const unsigned char *data, *p; + size_t i, size, avail_size; + int ret; + + if ((ret = i_stream_read_parent(stream)) <= 0) + return ret; + + data = i_stream_get_data(stream->parent, &size); + if (!i_stream_get_buffer_space(stream, size, &avail_size)) + return -2; + if (size > avail_size) + size = avail_size; + i_assert(size > 0); + + p = memchr(data, '\0', size); + if (p == NULL) { + /* no NULs in this block */ + memcpy(stream->w_buffer+stream->pos, data, size); + } else { + i = p-data; + memcpy(stream->w_buffer+stream->pos, data, i); + for (; i < size; i++) { + stream->w_buffer[stream->pos+i] = data[i] == '\0' ? + nstream->replace_chr : data[i]; + } + } + stream->pos += size; + i_stream_skip(stream->parent, size); + return size; +} + +static const struct stat * +i_stream_nonuls_stat(struct istream_private *stream, bool exact) +{ + return i_stream_stat(stream->parent, exact); +} + +struct istream *i_stream_create_nonuls(struct istream *input, char replace_chr) +{ + struct nonuls_istream *nstream; + + nstream = i_new(struct nonuls_istream, 1); + nstream->istream.max_buffer_size = input->real_stream->max_buffer_size; + + nstream->istream.read = i_stream_nonuls_read; + nstream->istream.stat = i_stream_nonuls_stat; + + nstream->istream.istream.readable_fd = FALSE; + nstream->istream.istream.blocking = input->blocking; + nstream->istream.istream.seekable = FALSE; + nstream->replace_chr = replace_chr; + return i_stream_create(&nstream->istream, input, + i_stream_get_fd(input)); +} diff -r 73ee8d00888d -r 3a267dec53ca src/lib-mail/istream-nonuls.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-nonuls.h Thu Jun 21 21:44:28 2012 +0300 @@ -0,0 +1,7 @@ +#ifndef ISTREAM_DOT_H +#define ISTREAM_DOT_H + +/* Translate all NUL characters to the specified replace_chr. */ +struct istream *i_stream_create_nonuls(struct istream *input, char replace_chr); + +#endif From dovecot at dovecot.org Thu Jun 21 21:54:03 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:54:03 +0300 Subject: dovecot-2.2: lib-imap: imap_quote() now skips any CR/LF characte... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/bf8a885c2077 changeset: 14621:bf8a885c2077 user: Timo Sirainen date: Thu Jun 21 21:47:06 2012 +0300 description: lib-imap: imap_quote() now skips any CR/LF characters from input. diffstat: src/lib-imap/imap-quote.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diffs (14 lines): diff -r 3a267dec53ca -r bf8a885c2077 src/lib-imap/imap-quote.c --- a/src/lib-imap/imap-quote.c Thu Jun 21 21:44:28 2012 +0300 +++ b/src/lib-imap/imap-quote.c Thu Jun 21 21:47:06 2012 +0300 @@ -121,6 +121,10 @@ str_append_c(dest, '"'); for (; *src != '\0'; src++) { switch (*src) { + case '\r': + case '\n': + /* not allowed */ + break; case '"': case '\\': str_append_c(dest, '\\'); From dovecot at dovecot.org Thu Jun 21 21:54:03 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:54:03 +0300 Subject: dovecot-2.2: lib-imap-storage: imap-msgpart rewrite and API change. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/6fb61872b30a changeset: 14622:6fb61872b30a user: Timo Sirainen date: Thu Jun 21 21:50:35 2012 +0300 description: lib-imap-storage: imap-msgpart rewrite and API change. The new API allows first parsing the validity of section strings and later relying on them being valid without having to re-parse it. The implementation also fixes a few things and adds "partial fetch cache". diffstat: src/lib-imap-storage/Makefile.am | 1 + src/lib-imap-storage/imap-msgpart-url.c | 53 +- src/lib-imap-storage/imap-msgpart.c | 707 ++++++++++++++++++++----------- src/lib-imap-storage/imap-msgpart.h | 46 +- src/lib-storage/mail-storage-private.h | 7 + 5 files changed, 531 insertions(+), 283 deletions(-) diffs (truncated from 1003 to 300 lines): diff -r bf8a885c2077 -r 6fb61872b30a src/lib-imap-storage/Makefile.am --- a/src/lib-imap-storage/Makefile.am Thu Jun 21 21:47:06 2012 +0300 +++ b/src/lib-imap-storage/Makefile.am Thu Jun 21 21:50:35 2012 +0300 @@ -5,6 +5,7 @@ -I$(top_srcdir)/src/lib-test \ -I$(top_srcdir)/src/lib-charset \ -I$(top_srcdir)/src/lib-mail \ + -I$(top_srcdir)/src/lib-index \ -I$(top_srcdir)/src/lib-storage \ -I$(top_srcdir)/src/lib-imap diff -r bf8a885c2077 -r 6fb61872b30a src/lib-imap-storage/imap-msgpart-url.c --- a/src/lib-imap-storage/imap-msgpart-url.c Thu Jun 21 21:47:06 2012 +0300 +++ b/src/lib-imap-storage/imap-msgpart-url.c Thu Jun 21 21:50:35 2012 +0300 @@ -1,3 +1,5 @@ +/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ + #include "lib.h" #include "network.h" #include "istream.h" @@ -162,13 +164,32 @@ return 1; } +static int +imap_msgpart_url_open_part(struct imap_msgpart_url *mpurl, struct mail **mail_r, + struct imap_msgpart **msgpart_r, const char **error_r) +{ + int ret; + + if ((ret = imap_msgpart_url_open_mail(mpurl, mail_r, error_r)) <= 0) + return ret; + + if (imap_msgpart_parse((*mail_r)->box, mpurl->section, msgpart_r) < 0) { + *error_r = "Invalid section"; + return 0; + } + imap_msgpart_set_partial(*msgpart_r, mpurl->partial_offset, + mpurl->partial_size == 0 ? (uoff_t)-1 : + mpurl->partial_size); + return 1; +} + int imap_msgpart_url_read_part(struct imap_msgpart_url *mpurl, struct istream **stream_r, uoff_t *size_r, const char **error_r) { struct mail *mail; - struct istream *input; - uoff_t part_size; + struct imap_msgpart *msgpart; + struct imap_msgpart_open_result result; int ret; if (mpurl->input != NULL) { @@ -179,20 +200,20 @@ } /* open mail if it is not yet open */ - if ((ret = imap_msgpart_url_open_mail(mpurl, &mail, error_r)) <= 0) + ret = imap_msgpart_url_open_part(mpurl, &mail, &msgpart, error_r); + if (ret <= 0) return ret; /* open the referenced part as a stream */ - if ((ret = imap_msgpart_open(mail, mpurl->section, - mpurl->partial_offset, mpurl->partial_size, - &input, &part_size, error_r)) <= 0) + ret = imap_msgpart_open(mail, msgpart, &result); + imap_msgpart_free(&msgpart); + if (ret < 0) { + *error_r = mailbox_get_last_error(mail->box, NULL); return ret; + } - mpurl->input = input; - mpurl->part_size = part_size; - - *stream_r = input; - *size_r = part_size; + *stream_r = mpurl->input = result.input; + *size_r = mpurl->part_size = result.size; return 1; } @@ -200,17 +221,17 @@ const char **error_r) { struct mail *mail; + struct imap_msgpart *msgpart; int ret; if (mpurl->input != NULL) return 1; /* open mail if it is not yet open */ - if ((ret = imap_msgpart_url_open_mail(mpurl, &mail, error_r)) <= 0) - return ret; - - /* open the referenced part as a stream */ - return imap_msgpart_verify(mail, mpurl->section, error_r); + ret = imap_msgpart_url_open_part(mpurl, &mail, &msgpart, error_r); + if (ret > 0) + imap_msgpart_free(&msgpart); + return ret; } void imap_msgpart_url_free(struct imap_msgpart_url **_mpurl) diff -r bf8a885c2077 -r 6fb61872b30a src/lib-imap-storage/imap-msgpart.c --- a/src/lib-imap-storage/imap-msgpart.c Thu Jun 21 21:47:06 2012 +0300 +++ b/src/lib-imap-storage/imap-msgpart.c Thu Jun 21 21:50:35 2012 +0300 @@ -1,25 +1,89 @@ +/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ + #include "lib.h" #include "array.h" #include "istream.h" #include "istream-crlf.h" +#include "istream-nonuls.h" #include "istream-header-filter.h" #include "message-parser.h" -#include "mail-storage.h" +#include "mail-storage-private.h" #include "mail-namespace.h" #include "imap-parser.h" #include "imap-msgpart.h" -int imap_msgpart_find(struct mail *mail, const char *section, - const struct message_part **part_r, - const char **subsection_r) +enum fetch_type { + FETCH_FULL, + FETCH_MIME, + FETCH_HEADER, + FETCH_HEADER_FIELDS, + FETCH_HEADER_FIELDS_NOT, + FETCH_BODY +}; + +struct imap_msgpart { + pool_t pool; + + /* "" for root, otherwise e.g. "1.2.3". the .MIME, .HEADER, etc. + suffix not included */ + const char *section_number; + enum fetch_type fetch_type; + enum mail_fetch_field wanted_fields; + + /* HEADER.FIELDS[.NOT] (list of headers) */ + struct mailbox_header_lookup_ctx *header_ctx; + const char *const *headers; + + /* which part of the message part to fetch (default: 0..(uoff_t)-1) */ + uoff_t partial_offset, partial_size; +}; + +struct imap_msgpart_open_ctx { + /* from matching message_part, set after opening: */ + uoff_t physical_pos; + struct message_size mime_hdr_size; + struct message_size mime_body_size; +}; + +static struct imap_msgpart *imap_msgpart_type(enum fetch_type fetch_type) { - struct message_part *part; + struct imap_msgpart *msgpart; + pool_t pool; + + pool = pool_alloconly_create("imap msgpart", sizeof(*msgpart)+32); + msgpart = p_new(pool, struct imap_msgpart, 1); + msgpart->pool = pool; + msgpart->partial_size = (uoff_t)-1; + msgpart->fetch_type = fetch_type; + if (fetch_type == FETCH_HEADER || fetch_type == FETCH_FULL) + msgpart->wanted_fields |= MAIL_FETCH_STREAM_HEADER; + if (fetch_type == FETCH_BODY || fetch_type == FETCH_FULL) + msgpart->wanted_fields |= MAIL_FETCH_STREAM_BODY; + return msgpart; +} + +struct imap_msgpart *imap_msgpart_full(void) +{ + return imap_msgpart_type(FETCH_FULL); +} + +struct imap_msgpart *imap_msgpart_header(void) +{ + return imap_msgpart_type(FETCH_HEADER); +} + +struct imap_msgpart *imap_msgpart_body(void) +{ + return imap_msgpart_type(FETCH_BODY); +} + +static struct message_part * +imap_msgpart_find(struct message_part *parts, const char *section) +{ + struct message_part *part = parts; const char *path; unsigned int num; - if (mail_get_parts(mail, &part) < 0) - return -1; - path = section; while (*path >= '0' && *path <= '9' && part != NULL) { /* get part number, we have already verified its validity */ @@ -53,21 +117,18 @@ part = part->children; } } - - *part_r = part; - *subsection_r = path; - return 0; + i_assert(part == NULL || *path == '\0'); + return part; } static int -imap_msgpart_get_header_fields(const char *header_list, - const char *const **fields_r, size_t *count_r) +imap_msgpart_get_header_fields(pool_t pool, const char *header_list, + ARRAY_TYPE(const_string) *fields) { struct istream *input; struct imap_parser *parser; const struct imap_arg *args, *hdr_list; unsigned int list_count; - ARRAY_TYPE(const_string) fields = ARRAY_INIT; unsigned int i; int result = 0; @@ -76,304 +137,452 @@ if (imap_parser_finish_line(parser, 0, 0, &args) > 0 && imap_arg_get_list_full(args, &hdr_list, &list_count) && + args[1].type == IMAP_ARG_EOL && list_count > 0) { const char *value; - if (fields_r != NULL) - t_array_init(&fields, list_count); - + p_array_init(fields, pool, list_count); for (i = 0; i < list_count; i++) { if (!imap_arg_get_astring(&hdr_list[i], &value)) { result = -1; break; } - if (fields_r != NULL) { - value = t_str_ucase(value); - array_append(&fields, &value, 1); - } - } - - if (fields_r != NULL) { - *fields_r = array_get(&fields, &list_count); - *count_r = list_count; + value = p_strdup(pool, t_str_ucase(value)); + array_append(fields, &value, 1); } } else { result = -1; } + /* istream-header-filter requires headers to be sorted */ + array_sort(fields, i_strcasecmp_p); + imap_parser_unref(&parser); i_stream_unref(&input); return result; } static int -imap_msgpart_verify_header_fields(const char *header_list, const char **error_r) +imap_msgpart_parse_header_fields(struct mailbox *box, + struct imap_msgpart *msgpart, + const char *header_list) { + ARRAY_TYPE(const_string) fields; + /* HEADER.FIELDS (list), HEADER.FIELDS.NOT (list) */ - if (imap_msgpart_get_header_fields(header_list, NULL, NULL) < 0) { - *error_r = "Invalid header fields"; + if (imap_msgpart_get_header_fields(msgpart->pool, header_list, + &fields) < 0) + return -1; + + (void)array_append_space(&fields); + msgpart->headers = array_idx(&fields, 0); + msgpart->header_ctx = mailbox_header_lookup_init(box, msgpart->headers); + return 0; +} + +int imap_msgpart_parse(struct mailbox *box, const char *section, + struct imap_msgpart **msgpart_r) From dovecot at dovecot.org Thu Jun 21 21:54:03 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:54:03 +0300 Subject: dovecot-2.2: imap: Rewrote FETCH command to use imap-msgpart API. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/df8ba29d9eb3 changeset: 14623:df8ba29d9eb3 user: Timo Sirainen date: Thu Jun 21 21:52:56 2012 +0300 description: imap: Rewrote FETCH command to use imap-msgpart API. diffstat: src/imap/cmd-select.c | 1 - src/imap/imap-client.h | 12 - src/imap/imap-fetch-body.c | 811 ++++++++------------------------------------ src/imap/imap-fetch.c | 5 +- src/imap/imap-fetch.h | 5 +- 5 files changed, 156 insertions(+), 678 deletions(-) diffs (truncated from 1095 to 300 lines): diff -r 6fb61872b30a -r df8ba29d9eb3 src/imap/cmd-select.c --- a/src/imap/cmd-select.c Thu Jun 21 21:50:35 2012 +0300 +++ b/src/imap/cmd-select.c Thu Jun 21 21:52:56 2012 +0300 @@ -301,7 +301,6 @@ STATUS_HIGHESTMODSEQ, &status); client->mailbox = ctx->box; - client->select_counter++; client->mailbox_examined = readonly; client->messages_count = status.messages; client->recent_count = status.recent; diff -r 6fb61872b30a -r df8ba29d9eb3 src/imap/imap-client.h --- a/src/imap/imap-client.h Thu Jun 21 21:50:35 2012 +0300 +++ b/src/imap/imap-client.h Thu Jun 21 21:52:56 2012 +0300 @@ -78,15 +78,6 @@ unsigned int temp_executed:1; /* temporary execution state tracking */ }; -struct partial_fetch_cache { - unsigned int select_counter; - unsigned int uid; - - uoff_t physical_start; - bool cr_skipped; - struct message_size pos; -}; - struct imap_client_vfuncs { void (*destroy)(struct client *client, const char *reason); }; @@ -111,7 +102,6 @@ struct mail_user *user; struct mailbox *mailbox; struct mailbox_keywords keywords; - unsigned int select_counter; /* increased when mailbox is changed */ unsigned int sync_counter; uint32_t messages_count, recent_count, uidvalidity; enum mailbox_feature enabled_features; @@ -130,8 +120,6 @@ uint64_t sync_last_full_modseq; uint64_t highest_fetch_modseq; - struct partial_fetch_cache last_partial; - /* SEARCHRES extension: Last saved SEARCH result */ ARRAY_TYPE(seq_range) search_saved_uidset; /* SEARCH=CONTEXT extension: Searches that get updated */ diff -r 6fb61872b30a -r df8ba29d9eb3 src/imap/imap-fetch-body.c --- a/src/imap/imap-fetch-body.c Thu Jun 21 21:50:35 2012 +0300 +++ b/src/imap/imap-fetch-body.c Thu Jun 21 21:52:56 2012 +0300 @@ -10,6 +10,7 @@ #include "message-parser.h" #include "message-send.h" #include "mail-storage-private.h" +#include "imap-quote.h" #include "imap-parser.h" #include "imap-msgpart.h" #include "imap-fetch.h" @@ -19,17 +20,10 @@ #include struct imap_fetch_body_data { - struct imap_fetch_body_data *next; + const char *section; /* NOTE: always uppercased */ + struct imap_msgpart *msgpart; - struct mailbox_header_lookup_ctx *header_ctx; - const char *section; /* NOTE: always uppercased */ - uoff_t skip, max_size; /* if you don't want max_size, - set it to (uoff_t)-1 */ - - const char *const *fields; - size_t fields_count; - - unsigned int skip_set:1; + unsigned int partial:1; unsigned int peek:1; }; @@ -42,54 +36,16 @@ mailbox_get_vname(ctx->cur_mail->box), ctx->cur_mail->uid); } -static int seek_partial(unsigned int select_counter, unsigned int uid, - struct partial_fetch_cache *partial, - struct istream *stream, - uoff_t virtual_skip, bool *cr_skipped_r) -{ - if (select_counter == partial->select_counter && uid == partial->uid && - stream->v_offset == partial->physical_start && - virtual_skip >= partial->pos.virtual_size) { - /* we can use the cache */ - virtual_skip -= partial->pos.virtual_size; - } else { - partial->select_counter = select_counter; - partial->uid = uid; - partial->physical_start = stream->v_offset; - partial->cr_skipped = FALSE; - memset(&partial->pos, 0, sizeof(partial->pos)); - } - - i_stream_seek(stream, partial->physical_start + - partial->pos.physical_size); - if (message_skip_virtual(stream, virtual_skip, &partial->pos, - partial->cr_skipped, cr_skipped_r) < 0) - return -1; - - partial->cr_skipped = FALSE; - return 0; -} - -static uoff_t get_send_size(const struct imap_fetch_body_data *body, - uoff_t max_size) -{ - uoff_t size; - - if (body->skip >= max_size) - return 0; - - size = max_size - body->skip; - return size <= body->max_size ? size : body->max_size; -} - static const char *get_body_name(const struct imap_fetch_body_data *body) { string_t *str; str = t_str_new(128); str_printfa(str, "BODY[%s]", body->section); - if (body->skip_set) - str_printfa(str, "<%"PRIuUOFF_T">", body->skip); + if (body->partial) { + str_printfa(str, "<%"PRIuUOFF_T">", + imap_msgpart_get_partial_offset(body->msgpart)); + } return str_c(str); } @@ -114,131 +70,7 @@ return str; } -static off_t imap_fetch_send(struct imap_fetch_context *ctx, - struct ostream *output, struct istream *input, - bool cr_skipped, uoff_t virtual_size, - bool add_missing_eoh, bool *last_cr) -{ - const unsigned char *msg; - size_t i, size; - uoff_t vsize_left, sent; - off_t ret; - unsigned char add; - bool blocks = FALSE; - - /* go through the message data and insert CRs where needed. */ - sent = 0; vsize_left = virtual_size; - while (vsize_left > 0 && !blocks && - i_stream_read_data(input, &msg, &size, 0) > 0) { - add = '\0'; - for (i = 0; i < size && vsize_left > 0; i++) { - vsize_left--; - - if (msg[i] == '\n') { - if ((i > 0 && msg[i-1] != '\r') || - (i == 0 && !cr_skipped)) { - /* missing CR */ - add = '\r'; - break; - } - } else if (msg[i] == '\0') { - add = 128; - break; - } - } - - if ((ret = o_stream_send(output, msg, i)) < 0) - return -1; - if ((uoff_t)ret < i) { - add = '\0'; - blocks = TRUE; - } - - if (ret > 0) - cr_skipped = msg[ret-1] == '\r'; - - i_stream_skip(input, ret); - sent += ret; - - if (add != '\0') { - if ((ret = o_stream_send(output, &add, 1)) < 0) - return -1; - if (ret == 0) - blocks = TRUE; - else { - sent++; - cr_skipped = add == '\r'; - if (add == 128) - i_stream_skip(input, 1); - } - } - } - if (input->stream_errno != 0) { - fetch_read_error(ctx); - return -1; - } - - if (add_missing_eoh && sent + 2 == virtual_size) { - /* Netscape missing EOH workaround. */ - o_stream_set_max_buffer_size(output, (size_t)-1); - if (o_stream_send(output, "\r\n", 2) < 0) - return -1; - sent += 2; - } - - if ((uoff_t)sent != virtual_size && !blocks) { - /* Input stream gave less data than we expected. Two choices - here: either we fill the missing data with spaces or we - disconnect the client. - - We shouldn't really ever get here. One reason is if mail - was deleted from NFS server while we were reading it. - Another is some temporary disk error. - - If we filled the missing data the client could cache it, - and if it was just a temporary error the message would be - permanently left corrupted in client's local cache. So, we - disconnect the client and hope that next try works. */ - i_error("FETCH %s for mailbox %s UID %u got too little data: " - "%"PRIuUOFF_T" vs %"PRIuUOFF_T, ctx->cur_name, - mailbox_get_vname(ctx->cur_mail->box), - ctx->cur_mail->uid, (uoff_t)sent, virtual_size); - mail_set_cache_corrupted(ctx->cur_mail, ctx->cur_size_field); - client_disconnect(ctx->client, "FETCH failed"); - return -1; - } - - *last_cr = cr_skipped; - return sent; -} - -static int fetch_stream_send(struct imap_fetch_context *ctx) -{ - off_t ret; - - o_stream_set_max_buffer_size(ctx->client->output, 4096); - ret = imap_fetch_send(ctx, ctx->client->output, ctx->cur_input, - ctx->skip_cr, ctx->cur_size - ctx->cur_offset, - ctx->cur_append_eoh, &ctx->skip_cr); - o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1); - - if (ret < 0) - return -1; - - ctx->cur_offset += ret; - if (ctx->update_partial) { - struct partial_fetch_cache *p = &ctx->client->last_partial; - - p->cr_skipped = ctx->skip_cr != 0; - p->pos.physical_size = - ctx->cur_input->v_offset - p->physical_start; - p->pos.virtual_size += ret; - } - - return ctx->cur_offset == ctx->cur_size; -} - -static int fetch_stream_send_direct(struct imap_fetch_context *ctx) +static int fetch_stream_continue(struct imap_fetch_context *ctx) { off_t ret; @@ -246,25 +78,20 @@ ret = o_stream_send_istream(ctx->client->output, ctx->cur_input); o_stream_set_max_buffer_size(ctx->client->output, (size_t)-1); - if (ret < 0) - return -1; - - ctx->cur_offset += ret; - - if (ctx->cur_append_eoh && ctx->cur_offset + 2 == ctx->cur_size) { - /* Netscape missing EOH workaround. */ - if (o_stream_send(ctx->client->output, "\r\n", 2) < 0) - return -1; - ctx->cur_offset += 2; - ctx->cur_append_eoh = FALSE; - } + if (ret > 0) + ctx->cur_offset += ret; if (ctx->cur_offset != ctx->cur_size) { /* unfinished */ + if (ctx->cur_input->stream_errno != 0) { + fetch_read_error(ctx); + client_disconnect(ctx->client, "FETCH failed"); + return -1; + } if (!i_stream_have_bytes_left(ctx->cur_input)) { /* Input stream gave less data than expected */ i_error("FETCH %s for mailbox %s UID %u " From dovecot at dovecot.org Thu Jun 21 21:58:53 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 21:58:53 +0300 Subject: dovecot-2.2: imap: Removed unnecessary code. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3a8ada7302a3 changeset: 14624:3a8ada7302a3 user: Timo Sirainen date: Thu Jun 21 21:58:48 2012 +0300 description: imap: Removed unnecessary code. diffstat: src/imap/imap-fetch-body.c | 8 ++------ 1 files changed, 2 insertions(+), 6 deletions(-) diffs (27 lines): diff -r df8ba29d9eb3 -r 3a8ada7302a3 src/imap/imap-fetch-body.c --- a/src/imap/imap-fetch-body.c Thu Jun 21 21:52:56 2012 +0300 +++ b/src/imap/imap-fetch-body.c Thu Jun 21 21:58:48 2012 +0300 @@ -24,7 +24,6 @@ struct imap_msgpart *msgpart; unsigned int partial:1; - unsigned int peek:1; }; static void fetch_read_error(struct imap_fetch_context *ctx) @@ -243,13 +242,10 @@ body = p_new(ctx->fetch_ctx->pool, struct imap_fetch_body_data, 1); - if (strncmp(p, ".PEEK", 5) == 0) { - body->peek = TRUE; + if (strncmp(p, ".PEEK", 5) == 0) p += 5; - } else { + else ctx->fetch_ctx->flags_update_seen = TRUE; - } - if (*p != '[') { ctx->error = "Invalid BODY[..] parameter: Missing '['"; return FALSE; From dovecot at dovecot.org Thu Jun 21 22:50:16 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 22:50:16 +0300 Subject: dovecot-2.2: Makefile: Removed message-binary-part.h which isn't... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9b9c1d9fc995 changeset: 14625:9b9c1d9fc995 user: Timo Sirainen date: Thu Jun 21 22:50:10 2012 +0300 description: Makefile: Removed message-binary-part.h which isn't finished yet. diffstat: src/lib-mail/Makefile.am | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diffs (11 lines): diff -r 3a8ada7302a3 -r 9b9c1d9fc995 src/lib-mail/Makefile.am --- a/src/lib-mail/Makefile.am Thu Jun 21 21:58:48 2012 +0300 +++ b/src/lib-mail/Makefile.am Thu Jun 21 22:50:10 2012 +0300 @@ -45,7 +45,6 @@ message-id.h \ message-parser.h \ message-part-serialize.h \ - message-binary-part.h \ message-search.h \ message-send.h \ message-size.h \ From dovecot at dovecot.org Thu Jun 21 22:56:25 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 22:56:25 +0300 Subject: dovecot-2.2: imap: Compile fix due to recent changes Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/64b0c9851781 changeset: 14626:64b0c9851781 user: Timo Sirainen date: Thu Jun 21 22:56:15 2012 +0300 description: imap: Compile fix due to recent changes diffstat: src/imap/cmd-fetch.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 9b9c1d9fc995 -r 64b0c9851781 src/imap/cmd-fetch.c --- a/src/imap/cmd-fetch.c Thu Jun 21 22:50:10 2012 +0300 +++ b/src/imap/cmd-fetch.c Thu Jun 21 22:56:15 2012 +0300 @@ -144,7 +144,7 @@ static const char *ok_message = "OK Fetch completed."; const char *tagged_reply = ok_message; - if (ctx->partial_fetch) { + if (ctx->skipped_expunged_msgs) { tagged_reply = "OK ["IMAP_RESP_CODE_EXPUNGEISSUED"] " "Some messages were already expunged."; } From dovecot at dovecot.org Thu Jun 21 23:16:01 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 21 Jun 2012 23:16:01 +0300 Subject: dovecot-2.2: lib-imap: Added IMAP_RESP_CODE_UNKNOWN_CTE Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/41e6c2a4a36b changeset: 14627:41e6c2a4a36b user: Timo Sirainen date: Thu Jun 21 23:15:21 2012 +0300 description: lib-imap: Added IMAP_RESP_CODE_UNKNOWN_CTE diffstat: src/imap/cmd-append.c | 4 +++- src/lib-imap/imap-resp-code.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletions(-) diffs (31 lines): diff -r 64b0c9851781 -r 41e6c2a4a36b src/imap/cmd-append.c --- a/src/imap/cmd-append.c Thu Jun 21 22:56:15 2012 +0300 +++ b/src/imap/cmd-append.c Thu Jun 21 23:15:21 2012 +0300 @@ -6,6 +6,7 @@ #include "istream-chain.h" #include "ostream.h" #include "str.h" +#include "imap-resp-code.h" #include "istream-binary-converter.h" #include "mail-storage-private.h" #include "imap-parser.h" @@ -327,7 +328,8 @@ break; if (args->literal8 && !ctx->binary_input) { client_send_tagline(cmd, - "NO [UNKNOWN-CTE] Binary input allowed only when the first part is binary."); + "NO ["IMAP_RESP_CODE_UNKNOWN_CTE"] " + "Binary input allowed only when the first part is binary."); return -1; } *nonsync_r = args->type == IMAP_ARG_LITERAL_SIZE_NONSYNC; diff -r 64b0c9851781 -r 41e6c2a4a36b src/lib-imap/imap-resp-code.h --- a/src/lib-imap/imap-resp-code.h Thu Jun 21 22:56:15 2012 +0300 +++ b/src/lib-imap/imap-resp-code.h Thu Jun 21 23:15:21 2012 +0300 @@ -20,4 +20,6 @@ #define IMAP_RESP_CODE_ALREADYEXISTS "ALREADYEXISTS" #define IMAP_RESP_CODE_NONEXISTENT "NONEXISTENT" +#define IMAP_RESP_CODE_UNKNOWN_CTE "UNKNOWN-CTE" /* BINARY */ + #endif From dovecot at dovecot.org Fri Jun 22 18:51:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 22 Jun 2012 18:51:55 +0300 Subject: dovecot-2.1: lib-ssl-iostream: Memory leak fixes Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/11c07ab07d39 changeset: 14570:11c07ab07d39 user: Timo Sirainen date: Fri Jun 22 18:51:42 2012 +0300 description: lib-ssl-iostream: Memory leak fixes diffstat: src/lib-ssl-iostream/iostream-openssl.c | 12 +++++++----- src/lib-ssl-iostream/istream-openssl.c | 1 + src/lib-ssl-iostream/ostream-openssl.c | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diffs (64 lines): diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/iostream-openssl.c --- a/src/lib-ssl-iostream/iostream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/iostream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -246,7 +246,7 @@ *_ssl_io = NULL; i_assert(ssl_io->refcount > 0); - if (--ssl_io->refcount >= 0) + if (--ssl_io->refcount > 0) return; ssl_iostream_free(ssl_io); @@ -503,6 +503,7 @@ const char *dnsname; bool dns_names = FALSE; unsigned int i, count; + int ret; cert = SSL_get_peer_certificate(ssl); i_assert(cert != NULL); @@ -520,14 +521,15 @@ } } sk_GENERAL_NAME_pop_free(gnames, GENERAL_NAME_free); - X509_free(cert); /* verify against CommonName only when there wasn't any DNS SubjectAltNames */ if (dns_names) - return i < count ? 0 : -1; - - return strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + ret = i < count ? 0 : -1; + else + ret = strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + X509_free(cert); + return ret; } int ssl_iostream_cert_match_name(struct ssl_iostream *ssl_io, diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/istream-openssl.c --- a/src/lib-ssl-iostream/istream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/istream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -21,6 +21,7 @@ { struct ssl_istream *sstream = (struct ssl_istream *)stream; + i_free(sstream->istream.w_buffer); ssl_iostream_unref(&sstream->ssl_io); } diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/ostream-openssl.c --- a/src/lib-ssl-iostream/ostream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/ostream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -24,7 +24,8 @@ sstream->ssl_io->ssl_output = NULL; ssl_iostream_unref(&sstream->ssl_io); - i_free(sstream->buffer); + if (sstream->buffer != NULL) + buffer_free(&sstream->buffer); } static size_t From dovecot at dovecot.org Fri Jun 22 21:59:17 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 22 Jun 2012 21:59:17 +0300 Subject: dovecot-2.2: Makefile: Removed unnecessary code Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/e0cc3fb5dc64 changeset: 14628:e0cc3fb5dc64 user: Timo Sirainen date: Fri Jun 22 21:59:01 2012 +0300 description: Makefile: Removed unnecessary code diffstat: doc/man/Makefile.am | 9 --------- 1 files changed, 0 insertions(+), 9 deletions(-) diffs (17 lines): diff -r 41e6c2a4a36b -r e0cc3fb5dc64 doc/man/Makefile.am --- a/doc/man/Makefile.am Thu Jun 21 23:15:21 2012 +0300 +++ b/doc/man/Makefile.am Fri Jun 22 21:59:01 2012 +0300 @@ -86,12 +86,3 @@ .1.in.1: $(man_includefiles) Makefile $(SHELL) $(srcdir)/sed.sh $(srcdir) $(rundir) $(pkgsysconfdir) \ < $(srcdir)/$< > $@ - -doveadm-instance.1: $(srcdir)/doveadm-instance.1.in $(man_includefiles) Makefile - $(SHELL) $(srcdir)/sed.sh $(srcdir) $(rundir) $(pkgsysconfdir) \ - < $(srcdir)/doveadm-instance.1.in > doveadm-instance.1 - - -doveadm-mount.1: $(srcdir)/doveadm-mount.1.in $(man_includefiles) Makefile - $(SHELL) $(srcdir)/sed.sh $(srcdir) $(rundir) $(pkgsysconfdir) \ - < $(srcdir)/doveadm-mount.1.in > doveadm-mount.1 \ No newline at end of file From dovecot at dovecot.org Sun Jun 24 00:53:11 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 00:53:11 +0300 Subject: dovecot-2.2: Marked functions parameters that are allowed to be ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c93ca5e46a8a changeset: 14629:c93ca5e46a8a user: Timo Sirainen date: Sun Jun 24 00:52:57 2012 +0300 description: Marked functions parameters that are allowed to be NULL. Some APIs were also changed. The non-obvious APIs where NULL parameter was changed to "" are master_service_init() and auth_master_user_list_init(). These checks can currently be enabled only on a patched clang: http://llvm.org/bugs/show_bug.cgi?id=6786 diffstat: src/anvil/main.c | 5 +- src/auth/auth-master-connection.c | 4 +- src/auth/auth-master-connection.h | 2 +- src/auth/auth-request-handler.c | 5 +- src/auth/auth-request.c | 8 +- src/auth/auth-request.h | 9 +- src/auth/auth-settings.h | 3 +- src/auth/auth-stream.h | 2 +- src/auth/auth-worker-server.c | 2 +- src/auth/auth.c | 31 +++++--- src/auth/auth.h | 1 + src/auth/db-checkpassword.h | 2 +- src/auth/db-ldap.c | 4 +- src/auth/db-ldap.h | 2 +- src/auth/db-passwd-file.c | 5 +- src/auth/main.c | 6 +- src/auth/mech-anonymous.c | 2 +- src/auth/mech-apop.c | 2 +- src/auth/mech-cram-md5.c | 2 +- src/auth/mech-ntlm.c | 4 +- src/auth/mech-otp-skey-common.c | 2 +- src/auth/mech-plain-common.c | 2 +- src/auth/mech-rpa.c | 2 +- src/auth/mech-winbind.c | 2 +- src/auth/mech.c | 2 +- src/auth/password-scheme-otp.c | 6 +- src/auth/password-scheme.h | 5 +- src/auth/userdb-passwd.c | 3 +- src/auth/userdb-static.c | 2 +- src/auth/userdb.h | 6 +- src/config/config-parser-private.h | 2 +- src/config/config-request.h | 5 +- src/config/doveconf.c | 4 +- src/config/main.c | 2 +- src/dict/main.c | 2 +- src/director/director-connection.c | 2 +- src/director/director-test.c | 4 +- src/director/director.h | 13 ++- src/dns/dns-client.c | 3 +- src/doveadm/doveadm-director.c | 4 +- src/doveadm/doveadm-log.c | 3 +- src/doveadm/doveadm-mail-fetch.c | 8 +- src/doveadm/doveadm-mail-iter.h | 2 +- src/doveadm/doveadm-mail-mailbox-status.c | 7 +- src/doveadm/dsync/doveadm-dsync.c | 10 +- src/doveadm/dsync/dsync-brain.c | 2 +- src/doveadm/dsync/dsync-mailbox-import.c | 5 +- src/doveadm/dsync/dsync-slave-io.c | 4 +- src/doveadm/main.c | 2 +- src/imap-login/client.c | 2 +- src/imap-login/client.h | 2 +- src/imap/cmd-append.c | 2 +- src/imap/cmd-expunge.c | 5 +- src/imap/imap-client.h | 2 +- src/imap/imap-commands-util.h | 3 +- src/imap/imap-expunge.h | 3 +- src/imap/imap-fetch-body.c | 20 +++-- src/imap/imap-fetch.h | 3 +- src/imap/imap-search.h | 2 +- src/imap/imap-sync.c | 2 +- src/indexer/indexer.c | 2 +- src/indexer/master-connection.c | 2 +- src/ipc/client.c | 3 +- src/ipc/main.c | 2 +- src/lib-auth/auth-client-request.c | 9 +- src/lib-auth/auth-client.h | 5 +- src/lib-auth/auth-master.c | 2 +- src/lib-auth/auth-master.h | 2 +- src/lib-dict/dict.h | 2 +- src/lib-dns/dns-lookup.h | 2 +- src/lib-imap-client/imapc-connection.h | 5 +- src/lib-imap-storage/imap-msgpart.c | 3 +- src/lib-imap/imap-base-subject.c | 12 +-- src/lib-imap/imap-parser.c | 2 +- src/lib-imap/imap-parser.h | 4 +- src/lib-imap/imap-url.c | 3 +- src/lib-imap/imap-util.h | 2 +- src/lib-index/mail-cache-lookup.c | 3 +- src/lib-index/mail-cache-transaction.c | 7 +- src/lib-index/mail-index-alloc-cache.c | 3 +- src/lib-index/mail-index-alloc-cache.h | 2 +- src/lib-index/mail-index-map-hdr.c | 4 +- src/lib-index/mail-index-map.c | 9 +- src/lib-index/mail-index-util.h | 2 +- src/lib-index/mail-index-view.c | 38 ++++------- src/lib-index/mail-index.c | 4 +- src/lib-index/mail-index.h | 8 +- src/lib-lda/mail-deliver.h | 2 +- src/lib-lda/smtp-client.h | 2 +- src/lib-mail/istream-binary-converter.c | 2 +- src/lib-mail/istream-dot.c | 8 +- src/lib-mail/istream-header-filter.h | 3 +- src/lib-mail/message-header-parser.h | 5 +- src/lib-mail/message-parser.h | 4 +- src/lib-mail/message-part-serialize.c | 2 +- src/lib-mail/message-search.h | 3 +- src/lib-mail/message-size.c | 17 ++-- src/lib-mail/message-size.h | 4 +- src/lib-mail/rfc822-parser.h | 2 +- src/lib-mail/test-istream-header-filter.c | 8 +- src/lib-master/anvil-client.h | 2 +- src/lib-master/ipc-client.h | 3 +- src/lib-master/ipc-server.c | 2 +- src/lib-master/master-service-settings-cache.h | 2 +- src/lib-master/master-service-settings.h | 2 +- src/lib-master/master-service.c | 6 +- src/lib-master/master-service.h | 3 +- src/lib-master/mountpoint-list.c | 12 ++- src/lib-ntlm/ntlm-encrypt.c | 4 +- src/lib-ntlm/ntlm-encrypt.h | 3 +- src/lib-otp/otp-parse.c | 8 +- src/lib-settings/settings-parser.c | 40 ++++++----- src/lib-settings/settings.h | 3 +- src/lib-sql/driver-mysql.c | 2 +- src/lib-sql/driver-pgsql.c | 4 +- src/lib-sql/driver-sqlpool.c | 7 +- src/lib-sql/sql-api.c | 2 +- src/lib-storage/index/dbox-common/dbox-file-fix.c | 3 +- src/lib-storage/index/dbox-common/dbox-save.h | 2 +- src/lib-storage/index/dbox-common/dbox-storage.c | 9 +- src/lib-storage/index/dbox-common/dbox-sync-rebuild.c | 3 +- src/lib-storage/index/dbox-multi/mdbox-map.c | 6 +- src/lib-storage/index/dbox-multi/mdbox-storage.c | 9 +- src/lib-storage/index/dbox-multi/mdbox-storage.h | 2 +- src/lib-storage/index/dbox-multi/mdbox-sync.c | 6 +- src/lib-storage/index/dbox-single/sdbox-storage.c | 7 +- src/lib-storage/index/imapc/imapc-mail.c | 2 +- src/lib-storage/index/index-mail-headers.c | 4 +- src/lib-storage/index/index-mail.c | 7 +- src/lib-storage/index/index-mail.h | 10 +- src/lib-storage/index/index-search.c | 10 +- src/lib-storage/index/index-sort.c | 12 ++- src/lib-storage/index/index-storage.h | 3 +- src/lib-storage/index/index-sync-changes.h | 3 +- src/lib-storage/index/maildir/maildir-filename-flags.c | 19 ++++- src/lib-storage/index/maildir/maildir-filename-flags.h | 7 +- src/lib-storage/index/maildir/maildir-mail.c | 12 +- src/lib-storage/index/maildir/maildir-save.c | 13 ++- src/lib-storage/index/maildir/maildir-storage.c | 21 ++---- src/lib-storage/index/maildir/maildir-storage.h | 2 +- src/lib-storage/index/maildir/maildir-sync-index.c | 4 +- src/lib-storage/index/maildir/maildir-sync.c | 5 +- src/lib-storage/index/maildir/maildir-sync.h | 3 +- src/lib-storage/index/maildir/maildir-uidlist.c | 20 +++++- src/lib-storage/index/maildir/maildir-uidlist.h | 4 +- src/lib-storage/index/maildir/maildir-util.c | 6 +- src/lib-storage/index/mbox/mbox-file.c | 2 +- src/lib-storage/index/mbox/mbox-lock.c | 11 +- src/lib-storage/index/mbox/mbox-mail.c | 3 +- src/lib-storage/index/mbox/mbox-storage.c | 7 +- src/lib-storage/index/mbox/mbox-sync-parse.c | 4 +- src/lib-storage/index/mbox/mbox-sync.c | 13 ++- src/lib-storage/index/raw/raw-storage.c | 4 +- src/lib-storage/index/shared/shared-storage.c | 2 +- src/lib-storage/list/mailbox-list-delete.c | 5 +- src/lib-storage/list/mailbox-list-fs-iter.c | 12 +- src/lib-storage/list/mailbox-list-fs.c | 8 +- src/lib-storage/list/mailbox-list-index-status.c | 2 +- src/lib-storage/list/mailbox-list-index.c | 2 +- src/lib-storage/list/mailbox-list-maildir.c | 12 +-- src/lib-storage/mail-namespace.h | 2 +- src/lib-storage/mail-search.h | 5 +- src/lib-storage/mail-storage-service.c | 2 +- src/lib-storage/mail-storage-service.h | 7 +- src/lib-storage/mail-storage.c | 11 ++- src/lib-storage/mail-storage.h | 27 ++++--- src/lib-storage/mail-thread.h | 2 +- src/lib-storage/mail.c | 4 - src/lib-storage/mailbox-get.c | 2 +- src/lib-storage/mailbox-list-private.h | 6 +- src/lib-storage/mailbox-list.c | 61 ++++++++++++----- src/lib-storage/mailbox-list.h | 11 ++- src/lib-storage/mailbox-tree.c | 7 +- src/lib-storage/mailbox-tree.h | 2 +- src/lib-test/test-common.h | 3 +- src/lib/base64.h | 2 +- src/lib/buffer.h | 5 +- src/lib/child-wait.h | 2 +- src/lib/eacces-error.h | 3 +- src/lib/failures.c | 18 +--- src/lib/file-dotlock.c | 2 +- src/lib/hash.c | 6 +- src/lib/hash.h | 3 +- src/lib/hash2.h | 2 +- src/lib/ioloop-notify-fd.h | 5 +- src/lib/ioloop.c | 2 +- src/lib/ioloop.h | 14 ++- src/lib/iso8601-date.c | 18 ++-- src/lib/istream-base64-encoder.c | 6 +- src/lib/istream-chain.c | 14 +++- src/lib/istream-chain.h | 6 +- src/lib/istream-crlf.c | 4 +- src/lib/istream-private.h | 3 +- src/lib/istream-seekable.h | 2 +- src/lib/istream.c | 3 +- src/lib/istream.h | 3 +- src/lib/lib-signals.c | 3 +- src/lib/lib-signals.h | 6 +- src/lib/macros.h | 5 + src/lib/mkdir-parents.c | 4 +- src/lib/module-dir.h | 8 +- src/lib/network.c | 12 +- src/lib/network.h | 15 ++- src/lib/ostream-private.h | 3 +- src/lib/ostream.c | 4 +- src/lib/ostream.h | 2 +- src/lib/restrict-access.h | 4 +- src/lib/safe-mkstemp.c | 2 +- src/lib/strfuncs.c | 2 + src/lib/strfuncs.h | 2 + src/lib/test-iso8601-date.c | 4 +- src/lib/uri-util.c | 2 +- src/lib/uri-util.h | 2 +- src/lib/var-expand.h | 2 +- src/lmtp/client.h | 2 +- src/lmtp/lmtp-proxy.h | 3 +- src/log/main.c | 2 +- src/login-common/client-common-auth.c | 2 +- src/login-common/login-proxy.c | 5 +- src/login-common/login-settings.h | 2 +- src/login-common/sasl-server.c | 10 +- src/login-common/ssl-proxy-openssl.c | 2 +- src/master/common.h | 3 +- src/plugins/acl/acl-backend-vfile-acllist.c | 12 +- src/plugins/acl/acl-plugin.h | 2 +- src/plugins/fts-lucene/fts-backend-lucene.c | 4 +- src/plugins/fts-lucene/lucene-wrapper.h | 7 +- src/plugins/fts-solr/solr-connection.c | 4 +- src/plugins/fts-squat/squat-trie.h | 3 +- src/plugins/fts/fts-storage.c | 3 +- src/plugins/quota/quota-dirsize.c | 4 +- src/plugins/quota/quota-fs.c | 3 +- src/plugins/quota/quota-maildir.c | 3 +- src/plugins/quota/quota.c | 5 +- src/pop3/pop3-client.h | 2 +- src/replication/aggregator/aggregator.c | 3 +- src/replication/replicator/replicator.c | 7 +- src/ssl-params/main.c | 3 +- src/stats/mail-domain.h | 2 +- src/stats/mail-ip.h | 3 +- src/stats/mail-session.h | 2 +- src/stats/mail-user.h | 2 +- src/stats/main.c | 2 +- 243 files changed, 738 insertions(+), 599 deletions(-) diffs (truncated from 4953 to 300 lines): diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/anvil/main.c --- a/src/anvil/main.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/anvil/main.c Sun Jun 24 00:52:57 2012 +0300 @@ -29,7 +29,8 @@ anvil_connection_create(conn->fd, master, conn->fifo); } -static void log_fdpass_input(void *context ATTR_UNUSED) +static void ATTR_NULL(1) +log_fdpass_input(void *context ATTR_UNUSED) { int fd; char c; @@ -57,7 +58,7 @@ const char *error; master_service = master_service_init("anvil", service_flags, - &argc, &argv, NULL); + &argc, &argv, ""); if (master_getopt(master_service) > 0) return FATAL_DEFAULT; if (master_service_settings_read_simple(master_service, diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-master-connection.c --- a/src/auth/auth-master-connection.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-master-connection.c Sun Jun 24 00:52:57 2012 +0300 @@ -383,14 +383,14 @@ return FALSE; auth_request_log_info(auth_request, "passdb", "%s", error); pass_callback(PASSDB_RESULT_USER_UNKNOWN, - NULL, 0, auth_request); + &uchar_nul, 0, auth_request); } else if (conn->userdb_restricted_uid != 0) { /* no permissions to do this lookup */ auth_request_log_error(auth_request, "passdb", "Auth client doesn't have permissions to do " "a PASS lookup: %s", auth_restricted_reason(conn)); pass_callback(PASSDB_RESULT_INTERNAL_FAILURE, - NULL, 0, auth_request); + &uchar_nul, 0, auth_request); } else { auth_request_set_state(auth_request, AUTH_REQUEST_STATE_MECH_CONTINUE); diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-master-connection.h --- a/src/auth/auth-master-connection.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-master-connection.h Sun Jun 24 00:52:57 2012 +0300 @@ -28,7 +28,7 @@ struct auth_master_connection * auth_master_connection_create(struct auth *auth, int fd, const char *path, const struct stat *socket_st, - bool userdb_only); + bool userdb_only) ATTR_NULL(4); void auth_master_connection_destroy(struct auth_master_connection **conn); void auth_master_connection_ref(struct auth_master_connection *conn); diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-request-handler.c --- a/src/auth/auth-request-handler.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-request-handler.c Sun Jun 24 00:52:57 2012 +0300 @@ -37,7 +37,7 @@ static struct aqueue *auth_failures; static struct timeout *to_auth_failures; -static void auth_failure_timeout(void *context); +static void auth_failure_timeout(void *context) ATTR_NULL(1); #undef auth_request_handler_create struct auth_request_handler * @@ -762,7 +762,8 @@ i_assert(auth_request->state == AUTH_REQUEST_STATE_FINISHED); auth_request_handler_reply(auth_request, - AUTH_CLIENT_RESULT_FAILURE, NULL, 0); + AUTH_CLIENT_RESULT_FAILURE, + &uchar_nul, 0); auth_request_unref(&auth_request); } } diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-request.c --- a/src/auth/auth-request.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-request.c Sun Jun 24 00:52:57 2012 +0300 @@ -141,8 +141,7 @@ auth_request_set_state(request, AUTH_REQUEST_STATE_FINISHED); auth_request_refresh_last_access(request); - auth_request_handler_reply(request, AUTH_CLIENT_RESULT_FAILURE, - NULL, 0); + auth_request_handler_reply(request, AUTH_CLIENT_RESULT_FAILURE, "", 0); } void auth_request_internal_failure(struct auth_request *request) @@ -325,7 +324,7 @@ i_assert(request->state == AUTH_REQUEST_STATE_MECH_CONTINUE); if (request->successful) { - auth_request_success(request, NULL, 0); + auth_request_success(request, "", 0); return; } @@ -790,7 +789,8 @@ auth_request_log_debug(request, "password", "passdb doesn't support credential lookups"); auth_request_lookup_credentials_callback( - PASSDB_RESULT_SCHEME_NOT_AVAILABLE, NULL, 0, request); + PASSDB_RESULT_SCHEME_NOT_AVAILABLE, + &uchar_nul, 0, request); } else if (passdb->blocking) { passdb_blocking_lookup_credentials(request); } else { diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-request.h --- a/src/auth/auth-request.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-request.h Sun Jun 24 00:52:57 2012 +0300 @@ -175,13 +175,13 @@ void auth_request_set_field(struct auth_request *request, const char *name, const char *value, - const char *default_scheme); + const char *default_scheme) ATTR_NULL(4); void auth_request_set_field_keyvalue(struct auth_request *request, const char *field, - const char *default_scheme); + const char *default_scheme) ATTR_NULL(3); void auth_request_set_fields(struct auth_request *request, const char *const *fields, - const char *default_scheme); + const char *default_scheme) ATTR_NULL(3); void auth_request_init_userdb_reply(struct auth_request *request); void auth_request_set_userdb_field(struct auth_request *request, @@ -203,7 +203,8 @@ const struct var_expand_table * auth_request_get_var_expand_table(const struct auth_request *auth_request, - auth_request_escape_func_t *escape_func); + auth_request_escape_func_t *escape_func) + ATTR_NULL(2); const char *auth_request_str_escape(const char *string, const struct auth_request *request); diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-settings.h --- a/src/auth/auth-settings.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-settings.h Sun Jun 24 00:52:57 2012 +0300 @@ -67,6 +67,7 @@ struct auth_settings * auth_settings_read(const char *service, pool_t pool, - struct master_service_settings_output *output_r); + struct master_service_settings_output *output_r) + ATTR_NULL(1); #endif diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-stream.h --- a/src/auth/auth-stream.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-stream.h Sun Jun 24 00:52:57 2012 +0300 @@ -5,7 +5,7 @@ struct auth_stream_reply *auth_stream_reply_init(pool_t pool); void auth_stream_reply_add(struct auth_stream_reply *reply, - const char *key, const char *value); + const char *key, const char *value) ATTR_NULL(2, 3); void auth_stream_reply_reset(struct auth_stream_reply *reply); void auth_stream_reply_remove(struct auth_stream_reply *reply, const char *key); diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth-worker-server.c --- a/src/auth/auth-worker-server.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth-worker-server.c Sun Jun 24 00:52:57 2012 +0300 @@ -57,7 +57,7 @@ static void worker_input(struct auth_worker_connection *conn); static void auth_worker_destroy(struct auth_worker_connection **conn, - const char *reason, bool restart); + const char *reason, bool restart) ATTR_NULL(2); static void auth_worker_idle_timeout(struct auth_worker_connection *conn) { diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth.c --- a/src/auth/auth.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth.c Sun Jun 24 00:52:57 2012 +0300 @@ -137,7 +137,7 @@ } } -static struct auth * +static struct auth * ATTR_NULL(2) auth_preinit(const struct auth_settings *set, const char *service, pool_t pool, const struct mechanisms_register *reg) { @@ -229,18 +229,25 @@ unsigned int i, count; a = array_get(&auths, &count); - if (name != NULL) { - for (i = 1; i < count; i++) { - if (strcmp(a[i]->service, name) == 0) - return a[i]; - } - /* not found. maybe we can instead find a !service */ - for (i = 1; i < count; i++) { - if (a[i]->service[0] == '!' && - strcmp(a[i]->service + 1, name) != 0) - return a[i]; - } + for (i = 1; i < count; i++) { + if (strcmp(a[i]->service, name) == 0) + return a[i]; } + /* not found. maybe we can instead find a !service */ + for (i = 1; i < count; i++) { + if (a[i]->service[0] == '!' && + strcmp(a[i]->service + 1, name) != 0) + return a[i]; + } + return a[0]; +} + +struct auth *auth_default_service(void) +{ + struct auth *const *a; + unsigned int count; + + a = array_get(&auths, &count); return a[0]; } diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/auth.h --- a/src/auth/auth.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/auth.h Sun Jun 24 00:52:57 2012 +0300 @@ -33,6 +33,7 @@ extern struct auth_penalty *auth_penalty; struct auth *auth_find_service(const char *name); +struct auth *auth_default_service(void); void auths_preinit(const struct auth_settings *set, pool_t pool, const struct mechanisms_register *reg, diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/db-checkpassword.h --- a/src/auth/db-checkpassword.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/db-checkpassword.h Sun Jun 24 00:52:57 2012 +0300 @@ -24,6 +24,6 @@ struct auth_request *request, const char *auth_password, db_checkpassword_callback_t *callback, - void (*request_callback)()); + void (*request_callback)()) ATTR_NULL(3); #endif diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/db-ldap.c --- a/src/auth/db-ldap.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/db-ldap.c Sun Jun 24 00:52:57 2012 +0300 @@ -753,7 +753,7 @@ net_set_nonblock(conn->fd, TRUE); } -static void +static void ATTR_NULL(1) db_ldap_set_opt(struct ldap_connection *conn, int opt, const void *value, const char *optname, const char *value_str) { @@ -766,7 +766,7 @@ } } -static void +static void ATTR_NULL(1) db_ldap_set_opt_str(struct ldap_connection *conn, int opt, const char *value, const char *optname) { diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/db-ldap.h --- a/src/auth/db-ldap.h Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/db-ldap.h Sun Jun 24 00:52:57 2012 +0300 @@ -167,7 +167,7 @@ void db_ldap_set_attrs(struct ldap_connection *conn, const char *attrlist, char ***attr_names_r, ARRAY_TYPE(ldap_field) *attr_map, - const char *skip_attr); + const char *skip_attr) ATTR_NULL(5); struct ldap_connection *db_ldap_init(const char *config_path, bool userdb); void db_ldap_unref(struct ldap_connection **conn); diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/db-passwd-file.c --- a/src/auth/db-passwd-file.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/db-passwd-file.c Sun Jun 24 00:52:57 2012 +0300 @@ -25,8 +25,9 @@ static struct db_passwd_file *passwd_files; -static void passwd_file_add(struct passwd_file *pw, const char *username, - const char *pass, const char *const *args) +static void ATTR_NULL(3) +passwd_file_add(struct passwd_file *pw, const char *username, + const char *pass, const char *const *args) { /* args = uid, gid, user info, home dir, shell, extra_fields */ struct passwd_user *pu; diff -r e0cc3fb5dc64 -r c93ca5e46a8a src/auth/main.c --- a/src/auth/main.c Fri Jun 22 21:59:01 2012 +0300 +++ b/src/auth/main.c Sun Jun 24 00:52:57 2012 +0300 @@ -227,7 +227,7 @@ /* set proctitles before init()s, since they may set them to error */ auth_refresh_proctitle(); From dovecot at dovecot.org Sun Jun 24 01:04:10 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 01:04:10 +0300 Subject: dovecot-2.0: login proxy: Previous memory leak fix caused Doveco... Message-ID: details: http://hg.dovecot.org/dovecot-2.0/rev/2440e656ed9f changeset: 13103:2440e656ed9f user: Timo Sirainen date: Sun Jun 24 01:03:52 2012 +0300 description: login proxy: Previous memory leak fix caused Dovecot to access freed memory. diffstat: src/login-common/ssl-proxy-openssl.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diffs (31 lines): diff -r 7720fb368e40 -r 2440e656ed9f src/login-common/ssl-proxy-openssl.c --- a/src/login-common/ssl-proxy-openssl.c Wed Jun 20 02:21:54 2012 +0300 +++ b/src/login-common/ssl-proxy-openssl.c Sun Jun 24 01:03:52 2012 +0300 @@ -715,6 +715,7 @@ const char *dnsname; bool dns_names = FALSE; unsigned int i, count; + int ret; cert = SSL_get_peer_certificate(ssl); i_assert(cert != NULL); @@ -732,14 +733,15 @@ } } sk_GENERAL_NAME_pop_free(gnames, GENERAL_NAME_free); - X509_free(cert); /* verify against CommonName only when there wasn't any DNS SubjectAltNames */ if (dns_names) - return i < count ? 0 : -1; - - return strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + ret = i < count ? 0 : -1; + else + ret = strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + X509_free(cert); + return ret; } int ssl_proxy_cert_match_name(struct ssl_proxy *proxy, const char *verify_name) From dovecot at dovecot.org Sun Jun 24 02:20:45 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 02:20:45 +0300 Subject: dovecot-2.1: Fixed signed integer shift overflows. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/6411d91d0755 changeset: 14571:6411d91d0755 user: Timo Sirainen date: Sun Jun 24 02:20:28 2012 +0300 description: Fixed signed integer shift overflows. These didn't actually cause any broken behavior. One of these was caught by http://embed.cs.utah.edu/ioc/ and the rest I grepped. diffstat: src/director/mail-host.c | 2 +- src/lib/primes.c | 2 +- src/lib/utc-mktime.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diffs (36 lines): diff -r 11c07ab07d39 -r 6411d91d0755 src/director/mail-host.c --- a/src/director/mail-host.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/director/mail-host.c Sun Jun 24 02:20:28 2012 +0300 @@ -110,7 +110,7 @@ i2 = htonl(ip2_arr[i]); for (j = last_bits; j < 32; j++) { - if ((i1 & (1 << j)) != (i2 & (1 << j))) { + if ((i1 & (1U << j)) != (i2 & (1U << j))) { i_error("IP address range too large: %s-%s", net_ip2addr(&ip1), net_ip2addr(&ip2)); return -1; diff -r 11c07ab07d39 -r 6411d91d0755 src/lib/primes.c --- a/src/lib/primes.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/lib/primes.c Sun Jun 24 02:20:28 2012 +0300 @@ -41,7 +41,7 @@ unsigned int i; for (i = 31; i > PRIME_SKIP_COUNT; i--) { - if ((num & (1 << i)) != 0) + if ((num & (1U << i)) != 0) return primes[i - PRIME_SKIP_COUNT]; } return primes[0]; diff -r 11c07ab07d39 -r 6411d91d0755 src/lib/utc-mktime.c --- a/src/lib/utc-mktime.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/lib/utc-mktime.c Sun Jun 24 02:20:28 2012 +0300 @@ -33,7 +33,7 @@ #ifdef TIME_T_SIGNED t = 0; #else - t = 1 << (TIME_T_MAX_BITS - 1); + t = (time_t)1 << (TIME_T_MAX_BITS - 1); #endif for (bits = TIME_T_MAX_BITS - 2;; bits--) { try_tm = gmtime(&t); From dovecot at dovecot.org Sun Jun 24 03:13:47 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 03:13:47 +0300 Subject: dovecot-2.2: mailbox_list_index=yes: Fixed a potential crash. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/5a9f9c35a8f0 changeset: 14630:5a9f9c35a8f0 user: Timo Sirainen date: Sun Jun 24 03:02:11 2012 +0300 description: mailbox_list_index=yes: Fixed a potential crash. diffstat: src/lib-storage/list/mailbox-list-index-status.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (13 lines): diff -r c93ca5e46a8a -r 5a9f9c35a8f0 src/lib-storage/list/mailbox-list-index-status.c --- a/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 00:52:57 2012 +0300 +++ b/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 03:02:11 2012 +0300 @@ -81,7 +81,8 @@ ret = FALSE; else { status_r->uidvalidity = rec->uid_validity; - memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); + if (mailbox_guid != NULL) + memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); } } From dovecot at dovecot.org Sun Jun 24 03:13:48 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 03:13:48 +0300 Subject: dovecot-2.1: mailbox_list_index=yes: Fixed a potential crash. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/bb1de2a1d866 changeset: 14572:bb1de2a1d866 user: Timo Sirainen date: Sun Jun 24 03:02:11 2012 +0300 description: mailbox_list_index=yes: Fixed a potential crash. diffstat: src/lib-storage/list/mailbox-list-index-status.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (13 lines): diff -r 6411d91d0755 -r bb1de2a1d866 src/lib-storage/list/mailbox-list-index-status.c --- a/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 02:20:28 2012 +0300 +++ b/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 03:02:11 2012 +0300 @@ -81,7 +81,8 @@ ret = FALSE; else { status_r->uidvalidity = rec->uid_validity; - memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); + if (mailbox_guid != NULL) + memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); } } From dovecot at dovecot.org Sun Jun 24 03:19:30 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 03:19:30 +0300 Subject: dovecot-2.1: director: Fix to handling duplicate USER-WEAK event. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/7be9411da17b changeset: 14573:7be9411da17b user: Timo Sirainen date: Sun Jun 24 03:19:17 2012 +0300 description: director: Fix to handling duplicate USER-WEAK event. diffstat: src/director/director-connection.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r bb1de2a1d866 -r 7be9411da17b src/director/director-connection.c --- a/src/director/director-connection.c Sun Jun 24 03:02:11 2012 +0300 +++ b/src/director/director-connection.c Sun Jun 24 03:19:17 2012 +0300 @@ -711,7 +711,7 @@ bool weak = TRUE; int ret; - if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) < 0) + if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0) return FALSE; if (str_array_length(args) != 2 || From dovecot at dovecot.org Sun Jun 24 18:58:27 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 18:58:27 +0300 Subject: dovecot-2.2: Avoid a NULL warning in mysql_init() when HAVE_ATTR... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/634474af3957 changeset: 14631:634474af3957 user: Timo Sirainen date: Sun Jun 24 18:58:19 2012 +0300 description: Avoid a NULL warning in mysql_init() when HAVE_ATTR_NULL capable compiler is used. diffstat: src/lib-sql/driver-mysql.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diffs (20 lines): diff -r 5a9f9c35a8f0 -r 634474af3957 src/lib-sql/driver-mysql.c --- a/src/lib-sql/driver-mysql.c Sun Jun 24 03:02:11 2012 +0300 +++ b/src/lib-sql/driver-mysql.c Sun Jun 24 18:58:19 2012 +0300 @@ -10,7 +10,16 @@ #include #include #include +#ifdef HAVE_ATTR_NULL +/* ugly way to tell clang that mysql.h is a system header and we don't want + to enable nonnull attributes for it by default.. */ +# 4 "driver-mysql.c" 3 +#endif #include +#ifdef HAVE_ATTR_NULL +# 4 "driver-mysql.c" 3 +# line 20 +#endif #include struct mysql_db { From dovecot at dovecot.org Sun Jun 24 19:33:32 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 19:33:32 +0300 Subject: dovecot-2.2: imap: CATENATE error handling fix Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/932ec9940568 changeset: 14632:932ec9940568 user: Timo Sirainen date: Sun Jun 24 19:12:26 2012 +0300 description: imap: CATENATE error handling fix diffstat: src/imap/cmd-append.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 634474af3957 -r 932ec9940568 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Sun Jun 24 18:58:19 2012 +0300 +++ b/src/imap/cmd-append.c Sun Jun 24 19:12:26 2012 +0300 @@ -275,7 +275,7 @@ ret = 0; } imap_msgpart_url_free(&mpurl); - return 0; + return ret; } static int cmd_append_catenate_text(struct client_command_context *cmd) From dovecot at dovecot.org Sun Jun 24 19:33:32 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 19:33:32 +0300 Subject: dovecot-2.2: dsync: Fixed a potential error if transaction log w... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/fa1898ef59c4 changeset: 14633:fa1898ef59c4 user: Timo Sirainen date: Sun Jun 24 19:13:58 2012 +0300 description: dsync: Fixed a potential error if transaction log was completely empty. diffstat: src/doveadm/dsync/dsync-transaction-log-scan.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diffs (13 lines): diff -r 932ec9940568 -r fa1898ef59c4 src/doveadm/dsync/dsync-transaction-log-scan.c --- a/src/doveadm/dsync/dsync-transaction-log-scan.c Sun Jun 24 19:12:26 2012 +0300 +++ b/src/doveadm/dsync/dsync-transaction-log-scan.c Sun Jun 24 19:13:58 2012 +0300 @@ -358,6 +358,9 @@ max_seq = view->log_file_expunge_seq; max_offset = view->log_file_expunge_offset; + mail_transaction_log_view_get_prev_pos(log_view, &file_seq, + &file_offset); + while (mail_transaction_log_view_next(log_view, &hdr, &data) > 0) { mail_transaction_log_view_get_prev_pos(log_view, &file_seq, &file_offset); From dovecot at dovecot.org Sun Jun 24 19:35:23 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 19:35:23 +0300 Subject: dovecot-2.2: fd_set_nonblock() API changed to i_fatal() on failure. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/a65006d95d53 changeset: 14634:a65006d95d53 user: Timo Sirainen date: Sun Jun 24 19:35:11 2012 +0300 description: fd_set_nonblock() API changed to i_fatal() on failure. Pretty much none of its users were checking if it failed, and there's really no good reason for it to fail anyway. diffstat: src/lib/fd-set-nonblock.c | 15 +++++---------- src/lib/fd-set-nonblock.h | 2 +- src/lib/network.c | 3 +-- 3 files changed, 7 insertions(+), 13 deletions(-) diffs (57 lines): diff -r fa1898ef59c4 -r a65006d95d53 src/lib/fd-set-nonblock.c --- a/src/lib/fd-set-nonblock.c Sun Jun 24 19:13:58 2012 +0300 +++ b/src/lib/fd-set-nonblock.c Sun Jun 24 19:35:11 2012 +0300 @@ -5,24 +5,19 @@ #include -int fd_set_nonblock(int fd, bool nonblock) +void fd_set_nonblock(int fd, bool nonblock) { int flags; flags = fcntl(fd, F_GETFL, 0); - if (flags < 0) { - i_error("fcntl(%d, F_GETFL) failed: %m", fd); - return -1; - } + if (flags < 0) + i_fatal("fcntl(%d, F_GETFL) failed: %m", fd); if (nonblock) flags |= O_NONBLOCK; else flags &= ~O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) < 0) { - i_error("fcntl(%d, F_SETFL) failed: %m", fd); - return -1; - } - return 0; + if (fcntl(fd, F_SETFL, flags) < 0) + i_fatal("fcntl(%d, F_SETFL) failed: %m", fd); } diff -r fa1898ef59c4 -r a65006d95d53 src/lib/fd-set-nonblock.h --- a/src/lib/fd-set-nonblock.h Sun Jun 24 19:13:58 2012 +0300 +++ b/src/lib/fd-set-nonblock.h Sun Jun 24 19:35:11 2012 +0300 @@ -2,6 +2,6 @@ #define FD_SET_NONBLOCK_H /* Set file descriptor to blocking/nonblocking state */ -int fd_set_nonblock(int fd, bool nonblock); +void fd_set_nonblock(int fd, bool nonblock); #endif diff -r fa1898ef59c4 -r a65006d95d53 src/lib/network.c --- a/src/lib/network.c Sun Jun 24 19:13:58 2012 +0300 +++ b/src/lib/network.c Sun Jun 24 19:35:11 2012 +0300 @@ -334,8 +334,7 @@ void net_set_nonblock(int fd, bool nonblock) { - if (fd_set_nonblock(fd, nonblock) < 0) - i_fatal("fd_set_nonblock(%d) failed: %m", fd); + fd_set_nonblock(fd, nonblock); } int net_set_cork(int fd ATTR_UNUSED, bool cork ATTR_UNUSED) From dovecot at dovecot.org Sun Jun 24 19:44:28 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 19:44:28 +0300 Subject: dovecot-2.1: dict file: Don't ignore write failures. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/cc6d2b34965d changeset: 14574:cc6d2b34965d user: Timo Sirainen date: Sun Jun 24 19:44:22 2012 +0300 description: dict file: Don't ignore write failures. diffstat: src/lib-dict/dict-file.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diffs (37 lines): diff -r 7be9411da17b -r cc6d2b34965d src/lib-dict/dict-file.c --- a/src/lib-dict/dict-file.c Sun Jun 24 03:19:17 2012 +0300 +++ b/src/lib-dict/dict-file.c Sun Jun 24 19:44:22 2012 +0300 @@ -492,7 +492,7 @@ /* refresh once more now that we're locked */ if (file_dict_refresh(dict) < 0) { if (dotlock != NULL) - file_dotlock_delete(&dotlock); + (void)file_dotlock_delete(&dotlock); else { (void)close(fd); file_unlock(&lock); @@ -512,12 +512,20 @@ o_stream_cork(output); iter = hash_table_iterate_init(dict->hash); while (hash_table_iterate(iter, &key, &value)) { - o_stream_send_str(output, key); - o_stream_send(output, "\n", 1); - o_stream_send_str(output, value); - o_stream_send(output, "\n", 1); + (void)o_stream_send_str(output, key); + (void)o_stream_send(output, "\n", 1); + (void)o_stream_send_str(output, value); + (void)o_stream_send(output, "\n", 1); } + o_stream_uncork(output); hash_table_iterate_deinit(&iter); + + if (output->stream_errno != 0) { + i_error("write(%s) failed: %m", temp_path); + o_stream_destroy(&output); + (void)close(fd); + return -1; + } o_stream_destroy(&output); if (dotlock != NULL) { From dovecot at dovecot.org Sun Jun 24 20:48:58 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:48:58 +0300 Subject: dovecot-2.2: lib-mail: message_header_decode_utf8() API changed ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/45952eee7ad4 changeset: 14635:45952eee7ad4 user: Timo Sirainen date: Sun Jun 24 19:51:40 2012 +0300 description: lib-mail: message_header_decode_utf8() API changed to not give return value. It's a rather unnecessary optimization and it wasn't even correct when the input wasn't valid UTF8. diffstat: src/lib-mail/message-header-decode.c | 10 +--------- src/lib-mail/message-header-decode.h | 5 ++--- src/lib-mail/test-message-decoder.c | 3 +-- src/lib-mail/test-message-header-decode.c | 5 ++--- src/lib-storage/index/index-mail-headers.c | 5 +++-- 5 files changed, 9 insertions(+), 19 deletions(-) diffs (100 lines): diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/message-header-decode.c --- a/src/lib-mail/message-header-decode.c Sun Jun 24 19:35:11 2012 +0300 +++ b/src/lib-mail/message-header-decode.c Sun Jun 24 19:51:40 2012 +0300 @@ -136,7 +136,6 @@ struct decode_utf8_context { buffer_t *dest; unsigned int changed:1; - unsigned int called:1; unsigned int dtcase:1; }; @@ -148,12 +147,6 @@ struct charset_translation *t; enum charset_flags flags; - /* one call with charset=NULL means nothing changed */ - if (!ctx->called && charset == NULL) - ctx->called = TRUE; - else - ctx->changed = TRUE; - if (charset == NULL || charset_is_utf8(charset)) { /* ASCII / UTF-8 */ if (ctx->dtcase) { @@ -181,7 +174,7 @@ return TRUE; } -bool message_header_decode_utf8(const unsigned char *data, size_t size, +void message_header_decode_utf8(const unsigned char *data, size_t size, buffer_t *dest, bool dtcase) { struct decode_utf8_context ctx; @@ -191,5 +184,4 @@ ctx.dest = dest; ctx.dtcase = dtcase; message_header_decode(data, size, decode_utf8_callback, &ctx); - return ctx.changed || (dest->used - used != size); } diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/message-header-decode.h --- a/src/lib-mail/message-header-decode.h Sun Jun 24 19:35:11 2012 +0300 +++ b/src/lib-mail/message-header-decode.h Sun Jun 24 19:51:40 2012 +0300 @@ -14,9 +14,8 @@ void *context); /* Append decoded RFC2047 header as UTF-8 to given buffer. If dtcase=TRUE, - the header is appended through uni_utf8_to_decomposed_titlecase(). - Returns TRUE if output changed in any way from input. */ -bool message_header_decode_utf8(const unsigned char *data, size_t size, + the header is appended through uni_utf8_to_decomposed_titlecase(). */ +void message_header_decode_utf8(const unsigned char *data, size_t size, buffer_t *dest, bool dtcase); #endif diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/test-message-decoder.c --- a/src/lib-mail/test-message-decoder.c Sun Jun 24 19:35:11 2012 +0300 +++ b/src/lib-mail/test-message-decoder.c Sun Jun 24 19:51:40 2012 +0300 @@ -9,11 +9,10 @@ #include "message-decoder.h" #include "test-common.h" -bool message_header_decode_utf8(const unsigned char *data, size_t size, +void message_header_decode_utf8(const unsigned char *data, size_t size, buffer_t *dest, bool dtcase ATTR_UNUSED) { buffer_append(dest, data, size); - return FALSE; } void quoted_printable_decode(const unsigned char *src, size_t src_size, diff -r a65006d95d53 -r 45952eee7ad4 src/lib-mail/test-message-header-decode.c --- a/src/lib-mail/test-message-header-decode.c Sun Jun 24 19:35:11 2012 +0300 +++ b/src/lib-mail/test-message-header-decode.c Sun Jun 24 19:51:40 2012 +0300 @@ -40,9 +40,8 @@ dest = t_str_new(256); for (i = 0; i < N_ELEMENTS(data); i += 2) { str_truncate(dest, 0); - test_assert(message_header_decode_utf8((const unsigned char *)data[i], - strlen(data[i]), - dest, FALSE)); + message_header_decode_utf8((const unsigned char *)data[i], + strlen(data[i]), dest, FALSE); test_assert(strcmp(str_c(dest), data[i+1]) == 0); } test_end(); diff -r a65006d95d53 -r 45952eee7ad4 src/lib-storage/index/index-mail-headers.c --- a/src/lib-storage/index/index-mail-headers.c Sun Jun 24 19:35:11 2012 +0300 +++ b/src/lib-storage/index/index-mail-headers.c Sun Jun 24 19:51:40 2012 +0300 @@ -715,8 +715,9 @@ return -1; /* decode MIME encoded-words. decoding may also add new LFs. */ - if (message_header_decode_utf8((const unsigned char *)input, - strlen(input), str, FALSE)) + message_header_decode_utf8((const unsigned char *)input, + strlen(input), str, FALSE); + if (strcmp(str_c(str), input) != 0) input = p_strdup(mail->data_pool, str_c(str)); decoded_list[i] = input; } From dovecot at dovecot.org Sun Jun 24 20:48:58 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:48:58 +0300 Subject: dovecot-2.2: lib-mail: Fixed an edge case with message header pa... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/0cb5fdb4c60d changeset: 14636:0cb5fdb4c60d user: Timo Sirainen date: Sun Jun 24 20:36:05 2012 +0300 description: lib-mail: Fixed an edge case with message header parser and very long lines. If the header was exactly a specific number of bytes, the parser thought the header ended there. diffstat: src/lib-mail/message-header-parser.c | 7 +++++-- src/lib-mail/test-message-header-parser.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diffs (43 lines): diff -r 45952eee7ad4 -r 0cb5fdb4c60d src/lib-mail/message-header-parser.c --- a/src/lib-mail/message-header-parser.c Sun Jun 24 19:51:40 2012 +0300 +++ b/src/lib-mail/message-header-parser.c Sun Jun 24 20:36:05 2012 +0300 @@ -107,7 +107,7 @@ return -1; } - if (size > 0 && !ctx->skip_line && + if (size > 0 && !ctx->skip_line && !continued && (msg[0] == '\n' || (msg[0] == '\r' && size > 1 && msg[1] == '\n'))) { /* end of headers - this mostly happens just @@ -154,6 +154,9 @@ if (size > 0 && msg[size-1] == '\r') size--; } + /* the buffer really has to be more than 2 to + avoid CRLF looping forever */ + i_assert(size > 0); continues = TRUE; } @@ -249,7 +252,7 @@ line->continued = continued; line->crlf_newline = crlf_newline; line->no_newline = no_newline; - if (size == 0) { + if (size == 0 && !continued) { /* end of headers */ line->eoh = TRUE; line->name_len = line->value_len = line->full_value_len = 0; diff -r 45952eee7ad4 -r 0cb5fdb4c60d src/lib-mail/test-message-header-parser.c --- a/src/lib-mail/test-message-header-parser.c Sun Jun 24 19:51:40 2012 +0300 +++ b/src/lib-mail/test-message-header-parser.c Sun Jun 24 20:36:05 2012 +0300 @@ -231,7 +231,7 @@ test_assert(hdr_size.virtual_size == len + 2); } len = strlen(crlf_str); - for (i = 2; i < len; i++) { + for (i = 3; i < len; i++) { test_message_header_parser_long_lines_str(crlf_str, i, &hdr_size); test_assert(hdr_size.physical_size == len); test_assert(hdr_size.virtual_size == len); From dovecot at dovecot.org Sun Jun 24 20:48:58 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:48:58 +0300 Subject: dovecot-2.2: Added file_dotlock_delete_verified() and changed fi... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/a77ad2346cf0 changeset: 14637:a77ad2346cf0 user: Timo Sirainen date: Sun Jun 24 20:48:38 2012 +0300 description: Added file_dotlock_delete_verified() and changed file_dotlock_delete() to return void. diffstat: src/lib-fs/fs-posix.c | 2 +- src/lib-index/mail-cache-compress.c | 4 ++-- src/lib-index/mail-cache.c | 2 +- src/lib-index/mail-transaction-log-file.c | 6 +++--- src/lib-master/master-instance.c | 10 +++++----- src/lib-storage/index/dbox-common/dbox-file.c | 2 +- src/lib-storage/index/maildir/maildir-uidlist.c | 2 +- src/lib-storage/index/mbox/mbox-lock.c | 4 ++-- src/lib-storage/list/subscription-file.c | 4 ++-- src/lib/file-dotlock.c | 7 ++++++- src/lib/file-dotlock.h | 8 +++++--- 11 files changed, 29 insertions(+), 22 deletions(-) diffs (219 lines): diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-fs/fs-posix.c --- a/src/lib-fs/fs-posix.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-fs/fs-posix.c Sun Jun 24 20:48:38 2012 +0300 @@ -445,7 +445,7 @@ if (lock->file_lock != NULL) file_unlock(&lock->file_lock); if (lock->dotlock != NULL) - (void)file_dotlock_delete(&lock->dotlock); + file_dotlock_delete(&lock->dotlock); i_free(lock); } diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-cache-compress.c --- a/src/lib-index/mail-cache-compress.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-index/mail-cache-compress.c Sun Jun 24 20:48:38 2012 +0300 @@ -395,13 +395,13 @@ reverse those changes by re-reading them from file. */ if (mail_cache_header_fields_read(cache) < 0) return -1; - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return -1; } if (fstat(fd, &st) < 0) { mail_cache_set_syscall_error(cache, "fstat()"); - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return -1; } diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-cache.c --- a/src/lib-index/mail-cache.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-index/mail-cache.c Sun Jun 24 20:48:38 2012 +0300 @@ -542,7 +542,7 @@ if (cache->index->lock_method != FILE_LOCK_METHOD_DOTLOCK) file_unlock(&cache->file_lock); else - (void)file_dotlock_delete(&cache->dotlock); + file_dotlock_delete(&cache->dotlock); } static int diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-index/mail-transaction-log-file.c --- a/src/lib-index/mail-transaction-log-file.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-index/mail-transaction-log-file.c Sun Jun 24 20:48:38 2012 +0300 @@ -317,7 +317,7 @@ if (--file->log->dotlock_count > 0) return 0; - ret = file_dotlock_delete(&file->log->dotlock); + ret = file_dotlock_delete_verified(&file->log->dotlock); if (ret < 0) { log_file_set_syscall_error(file, "file_dotlock_delete()"); return -1; @@ -680,7 +680,7 @@ FALSE) > 0 && mail_transaction_log_file_stat(file, FALSE) == 0) { /* yes, it was ok */ - (void)file_dotlock_delete(dotlock); + file_dotlock_delete(dotlock); mail_transaction_log_file_add_to_list(file); return 0; } @@ -803,7 +803,7 @@ is for the existing file */ if (mail_transaction_log_file_create2(file, fd, reset, &dotlock) < 0) { if (dotlock != NULL) - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return -1; } return 0; diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-master/master-instance.c --- a/src/lib-master/master-instance.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-master/master-instance.c Sun Jun 24 20:48:38 2012 +0300 @@ -144,7 +144,7 @@ return -1; } if (master_instance_list_refresh(list) < 0) { - (void)file_dotlock_delete(dotlock_r); + file_dotlock_delete(dotlock_r); return -1; } return fd; @@ -160,12 +160,12 @@ ret = master_instance_list_write(list, fd, lock_path); } T_END; if (ret < 0) { - (void)file_dotlock_delete(dotlock); + file_dotlock_delete(dotlock); return -1; } if (fdatasync(fd) < 0) { i_error("fdatasync(%s) failed: %m", lock_path); - (void)file_dotlock_delete(dotlock); + file_dotlock_delete(dotlock); return -1; } return file_dotlock_replace(dotlock, 0); @@ -222,7 +222,7 @@ if (orig_inst != NULL && strcmp(orig_inst->base_dir, base_dir) != 0) { /* name already used */ - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return 0; } @@ -257,7 +257,7 @@ } if (i == count) { - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return 0; } return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1; diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/dbox-common/dbox-file.c --- a/src/lib-storage/index/dbox-common/dbox-file.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-file.c Sun Jun 24 20:48:38 2012 +0300 @@ -328,7 +328,7 @@ #ifdef DBOX_FILE_LOCK_METHOD_FLOCK file_unlock(&file->lock); #else - (void)file_dotlock_delete(&file->lock); + file_dotlock_delete(&file->lock); #endif } if (file->input != NULL) diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/maildir/maildir-uidlist.c --- a/src/lib-storage/index/maildir/maildir-uidlist.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-storage/index/maildir/maildir-uidlist.c Sun Jun 24 20:48:38 2012 +0300 @@ -243,7 +243,7 @@ return; uidlist->locked_refresh = FALSE; - (void)file_dotlock_delete(&uidlist->dotlock); + file_dotlock_delete(&uidlist->dotlock); } static bool dotlock_callback(unsigned int secs_left, bool stale, void *context) diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/index/mbox/mbox-lock.c --- a/src/lib-storage/index/mbox/mbox-lock.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-storage/index/mbox/mbox-lock.c Sun Jun 24 20:48:38 2012 +0300 @@ -315,7 +315,7 @@ break; case MBOX_DOTLOCK_OP_UNLOCK: /* we're now privileged - avoid doing as much as possible */ - ret = file_dotlock_delete(&mbox->mbox_dotlock); + ret = file_dotlock_delete_verified(&mbox->mbox_dotlock); if (ret < 0) mbox_set_syscall_error(mbox, "file_dotlock_delete()"); mbox->mbox_used_privileges = FALSE; @@ -391,7 +391,7 @@ return 1; if (!mbox->mbox_used_privileges) { - if (file_dotlock_delete(&mbox->mbox_dotlock) <= 0) { + if (file_dotlock_delete_verified(&mbox->mbox_dotlock) <= 0) { mbox_set_syscall_error(mbox, "file_dotlock_delete()"); } diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib-storage/list/subscription-file.c --- a/src/lib-storage/list/subscription-file.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib-storage/list/subscription-file.c Sun Jun 24 20:48:38 2012 +0300 @@ -132,7 +132,7 @@ fd_in = nfs_safe_open(path, O_RDONLY); if (fd_in == -1 && errno != ENOENT) { subswrite_set_syscall_error(list, "open()", path); - (void)file_dotlock_delete(&dotlock); + file_dotlock_delete(&dotlock); return -1; } @@ -181,7 +181,7 @@ o_stream_destroy(&output); if (failed || !changed) { - if (file_dotlock_delete(&dotlock) < 0) { + if (file_dotlock_delete_verified(&dotlock) < 0) { subswrite_set_syscall_error(list, "file_dotlock_delete()", path); failed = TRUE; diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib/file-dotlock.c --- a/src/lib/file-dotlock.c Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib/file-dotlock.c Sun Jun 24 20:48:38 2012 +0300 @@ -721,7 +721,12 @@ return diff > FILE_DOTLOCK_MAX_STAT_MTIME_DIFF; } -int file_dotlock_delete(struct dotlock **dotlock_p) +void file_dotlock_delete(struct dotlock **dotlock_p) +{ + (void)file_dotlock_delete_verified(dotlock_p); +} + +int file_dotlock_delete_verified(struct dotlock **dotlock_p) { struct dotlock *dotlock; const char *lock_path; diff -r 0cb5fdb4c60d -r a77ad2346cf0 src/lib/file-dotlock.h --- a/src/lib/file-dotlock.h Sun Jun 24 20:36:05 2012 +0300 +++ b/src/lib/file-dotlock.h Sun Jun 24 20:48:38 2012 +0300 @@ -58,9 +58,11 @@ enum dotlock_create_flags flags, struct dotlock **dotlock_r); -/* Delete the dotlock file. Returns 1 if successful, 0 if the file was already - been deleted or reused by someone else, -1 if error. */ -int file_dotlock_delete(struct dotlock **dotlock); +/* Delete the dotlock file, ignoring any potential errors. */ +void file_dotlock_delete(struct dotlock **dotlock); +/* Delete the dotlock file. Returns 1 if successful, 0 if the file had already + been deleted or reused by someone else, -1 if I/O error. */ +int file_dotlock_delete_verified(struct dotlock **dotlock); /* Use dotlock as the new content for file. This provides read safety without locks, but it's not very good for large files. Returns fd for lock file. From dovecot at dovecot.org Sun Jun 24 20:52:51 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:52:51 +0300 Subject: dovecot-2.1: Make static analyzer happier. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/c257b9c19915 changeset: 14575:c257b9c19915 user: Timo Sirainen date: Sun Jun 24 20:52:39 2012 +0300 description: Make static analyzer happier. diffstat: src/auth/auth-request.c | 2 ++ src/auth/db-ldap.c | 1 + src/auth/password-scheme.c | 2 +- src/lib-index/mail-transaction-log-file.c | 7 +++++-- src/lib-index/mail-transaction-log.c | 1 + src/lib-storage/index/mbox/mbox-mail.c | 4 ++-- src/lib-storage/index/mbox/mbox-save.c | 1 + src/plugins/fts-squat/squat-uidlist.c | 2 ++ 8 files changed, 15 insertions(+), 5 deletions(-) diffs (122 lines): diff -r cc6d2b34965d -r c257b9c19915 src/auth/auth-request.c --- a/src/auth/auth-request.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/auth-request.c Sun Jun 24 20:52:39 2012 +0300 @@ -1250,6 +1250,8 @@ i_assert(*name != '\0'); i_assert(value != NULL); + i_assert(request->passdb != NULL); + if (strcmp(name, "password") == 0) { auth_request_set_password(request, value, default_scheme, FALSE); diff -r cc6d2b34965d -r c257b9c19915 src/auth/db-ldap.c --- a/src/auth/db-ldap.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/db-ldap.c Sun Jun 24 20:52:39 2012 +0300 @@ -866,6 +866,7 @@ ret = ldap_start_tls_s(conn->ld, NULL, NULL); if (ret != LDAP_SUCCESS) { if (ret == LDAP_OPERATIONS_ERROR && + conn->set.uris != NULL && strncmp(conn->set.uris, "ldaps:", 6) == 0) { i_fatal("LDAP: Don't use both tls=yes " "and ldaps URI"); diff -r cc6d2b34965d -r c257b9c19915 src/auth/password-scheme.c --- a/src/auth/password-scheme.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/password-scheme.c Sun Jun 24 20:52:39 2012 +0300 @@ -367,7 +367,7 @@ str = password_generate_md5_crypt(plaintext, password); return strcmp(str, password) == 0 ? 1 : 0; } else if (password_decode(password, "PLAIN-MD5", - &md5_password, &md5_size, &error) < 0) { + &md5_password, &md5_size, &error) <= 0) { *error_r = "Not a valid MD5-CRYPT or PLAIN-MD5 password"; return -1; } else { diff -r cc6d2b34965d -r c257b9c19915 src/lib-index/mail-transaction-log-file.c --- a/src/lib-index/mail-transaction-log-file.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-index/mail-transaction-log-file.c Sun Jun 24 20:52:39 2012 +0300 @@ -1673,6 +1673,7 @@ file->filepath); return 0; } + i_assert(file->buffer != NULL); return log_file_map_check_offsets(file, start_offset, end_offset); } @@ -1695,9 +1696,11 @@ i_assert(file->buffer == NULL || file->mmap_base != NULL || file->sync_offset >= file->buffer_offset + file->buffer->used); + if (ret <= 0) + return ret; - return ret <= 0 ? ret : - log_file_map_check_offsets(file, start_offset, end_offset); + i_assert(file->buffer != NULL); + return log_file_map_check_offsets(file, start_offset, end_offset); } void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file diff -r cc6d2b34965d -r c257b9c19915 src/lib-index/mail-transaction-log.c --- a/src/lib-index/mail-transaction-log.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-index/mail-transaction-log.c Sun Jun 24 20:52:39 2012 +0300 @@ -463,6 +463,7 @@ /* try again */ } + i_assert(ret < 0 || log->head != NULL); return ret; } diff -r cc6d2b34965d -r c257b9c19915 src/lib-storage/index/mbox/mbox-mail.c --- a/src/lib-storage/index/mbox/mbox-mail.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-storage/index/mbox/mbox-mail.c Sun Jun 24 20:52:39 2012 +0300 @@ -240,6 +240,8 @@ int trailer_size; int ret = 1; + *next_offset_r = (uoff_t)-1; + hdr = mail_index_get_header(mail->mail.mail.transaction->view); if (mail->mail.mail.seq > hdr->messages_count) { /* we're appending a new message */ @@ -341,8 +343,6 @@ mail->mail.mail.uid); } } - if (ret <= 0) - next_offset = (uoff_t)-1; raw_stream = mbox->mbox_stream; hdr_offset = istream_raw_mbox_get_header_offset(raw_stream); diff -r cc6d2b34965d -r c257b9c19915 src/lib-storage/index/mbox/mbox-save.c --- a/src/lib-storage/index/mbox/mbox-save.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Jun 24 20:52:39 2012 +0300 @@ -666,6 +666,7 @@ ctx->finished = TRUE; if (!ctx->failed) { + i_assert(ctx->output != NULL); T_BEGIN { if (mbox_write_content_length(ctx) < 0 || mbox_append_lf(ctx) < 0) diff -r cc6d2b34965d -r c257b9c19915 src/plugins/fts-squat/squat-uidlist.c --- a/src/plugins/fts-squat/squat-uidlist.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/plugins/fts-squat/squat-uidlist.c Sun Jun 24 20:52:39 2012 +0300 @@ -1416,6 +1416,7 @@ squat_uidlist_set_corrupted(uidlist, "uidlist not found"); return -1; } + i_assert(uidlist->cur_block_end_indexes != NULL); if (unlikely(idx > 0 && uidlist->cur_block_end_indexes[idx-1] > uid_list_idx)) { squat_uidlist_set_corrupted(uidlist, "broken block list"); @@ -1430,6 +1431,7 @@ return -1; /* find the uidlist inside the block */ + i_assert(uidlist->cur_block_offsets != NULL); p = CONST_PTR_OFFSET(uidlist->data, uidlist->cur_block_offsets[idx]); end = CONST_PTR_OFFSET(uidlist->data, uidlist->data_size); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Fixed assert-crash on some situations when user had... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/fe688ecd7564 changeset: 14639:fe688ecd7564 user: Timo Sirainen date: Tue May 29 18:38:01 2012 +0300 description: Fixed assert-crash on some situations when user had no supplementary groups. diffstat: src/lib/restrict-access.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 03ea2388bb27 -r fe688ecd7564 src/lib/restrict-access.c --- a/src/lib/restrict-access.c Wed May 23 00:24:06 2012 +0300 +++ b/src/lib/restrict-access.c Tue May 29 18:38:01 2012 +0300 @@ -126,7 +126,7 @@ i_fatal("getgroups() failed: %m"); /* @UNSAFE */ - gid_list = t_new(gid_t, gid_count); + gid_list = t_new(gid_t, gid_count+1); /* +1 in case gid_count=0 */ if ((ret = getgroups(gid_count, gid_list)) < 0) i_fatal("getgroups() failed: %m"); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-storage: Verify that with SEARCH HEADER the hea... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/03ea2388bb27 changeset: 14638:03ea2388bb27 user: Timo Sirainen date: Wed May 23 00:24:06 2012 +0300 description: lib-storage: Verify that with SEARCH HEADER the header name is valid UTF-8. diffstat: src/lib-storage/mail-search-register-imap.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (12 lines): diff -r dbe6d05fd595 -r 03ea2388bb27 src/lib-storage/mail-search-register-imap.c --- a/src/lib-storage/mail-search-register-imap.c Sun May 20 03:08:01 2012 +0300 +++ b/src/lib-storage/mail-search-register-imap.c Wed May 23 00:24:06 2012 +0300 @@ -259,6 +259,8 @@ /* */ if (mail_search_parse_string(ctx->parser, &hdr_name) < 0) return NULL; + if (mail_search_build_get_utf8(ctx, hdr_name, &hdr_name) < 0) + return NULL; return arg_new_header(ctx, SEARCH_HEADER, t_str_ucase(hdr_name)); } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: mdbox: Fixed assert-crash with index rebuild when u... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/969950d53af1 changeset: 14640:969950d53af1 user: Timo Sirainen date: Tue May 29 20:51:14 2012 +0300 description: mdbox: Fixed assert-crash with index rebuild when using ns prefix and mail wasn't originally in INBOX. diffstat: src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (20 lines): diff -r fe688ecd7564 -r 969950d53af1 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Tue May 29 18:38:01 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Tue May 29 20:51:14 2012 +0300 @@ -605,6 +605,7 @@ if (ret > 0 && !deleted && dbox_file_metadata_read(file) > 0) { mailbox = dbox_file_metadata_get(file, DBOX_METADATA_ORIG_MAILBOX); + mailbox = mailbox_list_get_vname(ctx->default_list, mailbox); mailbox = t_strdup(mailbox); } dbox_file_unref(&file); @@ -623,7 +624,7 @@ there. */ created = FALSE; box = ctx->prev_msg.box != NULL && - strcmp(mailbox, ctx->prev_msg.box->name) == 0 ? + strcmp(mailbox, ctx->prev_msg.box->vname) == 0 ? ctx->prev_msg.box : NULL; while (box == NULL) { box = mailbox_alloc(ctx->default_list, mailbox, From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Released v2.1.7. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c92fb8b928f6 changeset: 14641:c92fb8b928f6 user: Timo Sirainen date: Tue May 29 22:22:10 2012 +0300 description: Released v2.1.7. diffstat: NEWS | 19 +++++++++++++++++++ configure.in | 2 +- 2 files changed, 20 insertions(+), 1 deletions(-) diffs (36 lines): diff -r 969950d53af1 -r c92fb8b928f6 NEWS --- a/NEWS Tue May 29 20:51:14 2012 +0300 +++ b/NEWS Tue May 29 22:22:10 2012 +0300 @@ -1,3 +1,22 @@ +v2.1.7 2012-05-29 Timo Sirainen + + * LDAP: Compatibility fix for v2.0: ldap: If attributes contain + ldapAttr=key=template%$ and ldapAttr doesn't exist, skip the key + instead of using "template" value with empty %$ part for the key. + + + pop3: Added pop3_uidl_duplicates setting for changing the behavior + for duplicate UIDLs. + + director: Added "doveadm director ring remove" command. + - director: Don't crash with quickly disconnecting incoming director + connections. + - mdbox: If mail was originally saved to non-INBOX, and namespace + prefix is non-empty, don't assert-crash when rebuilding indexes. + - sdbox: Don't use more fds than necessary when copying mails. + - auth: Fixed crash with DIGEST-MD5 when attempting to do master user + login without master passdbs. + - Several fixes to mail_shared_explicit_inbox=no + - imapc: Use imapc_list_prefix also for listing subscriptions. + v2.1.6 2012-05-07 Timo Sirainen * Session ID is now included by default in auth and login process diff -r 969950d53af1 -r c92fb8b928f6 configure.in --- a/configure.in Tue May 29 20:51:14 2012 +0300 +++ b/configure.in Tue May 29 22:22:10 2012 +0300 @@ -1,5 +1,5 @@ AC_PREREQ([2.59]) -AC_INIT([Dovecot],[2.1.6],[dovecot at dovecot.org]) +AC_INIT([Dovecot],[2.1.7],[dovecot at dovecot.org]) AC_CONFIG_SRCDIR([src]) AM_INIT_AUTOMAKE([foreign]) From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Added tag 2.1.7 for changeset c92fb8b928f6 Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/d3c0c472b1ff changeset: 14642:d3c0c472b1ff user: Timo Sirainen date: Tue May 29 22:22:10 2012 +0300 description: Added tag 2.1.7 for changeset c92fb8b928f6 diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r c92fb8b928f6 -r d3c0c472b1ff .hgtags --- a/.hgtags Tue May 29 22:22:10 2012 +0300 +++ b/.hgtags Tue May 29 22:22:10 2012 +0300 @@ -83,3 +83,4 @@ 2c21c940e19d97a772128a7f281cea302e157d73 2.1.4 469cee314d9c54d2d7101ec9e38579fdc9610eaf 2.1.5 7c249e2a82a9cd33ae15ead6443c3499e16da623 2.1.6 +c92fb8b928f69ca01681a2c2976304b7e4bc3afc 2.1.7 From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Added signature for changeset c92fb8b928f6 Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/36d2aff85a69 changeset: 14643:36d2aff85a69 user: Timo Sirainen date: Tue May 29 22:22:14 2012 +0300 description: Added signature for changeset c92fb8b928f6 diffstat: .hgsigs | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r d3c0c472b1ff -r 36d2aff85a69 .hgsigs --- a/.hgsigs Tue May 29 22:22:10 2012 +0300 +++ b/.hgsigs Tue May 29 22:22:14 2012 +0300 @@ -46,3 +46,4 @@ 2c21c940e19d97a772128a7f281cea302e157d73 0 iEYEABECAAYFAk+CtkYACgkQyUhSUUBVisknxgCfTJw2YPGJ17HbHRGmbwmCyLqepbMAn17j7IYzUfEU0xkXhCgwEAmk7XO4 469cee314d9c54d2d7101ec9e38579fdc9610eaf 0 iEYEABECAAYFAk+VWqkACgkQyUhSUUBVislnXACfVjPqMmPUvYtXQXwqff0h7N76mZUAn02lPeUCyuyr1TF9e1hGM/sKgmko 7c249e2a82a9cd33ae15ead6443c3499e16da623 0 iEYEABECAAYFAk+nX2sACgkQyUhSUUBVisn7uwCbBD3boxBOGEJ8OYsIJ57n5Cr09FAAoIvhxL6EHRB15AMOw4sPaALJ3/bB +c92fb8b928f69ca01681a2c2976304b7e4bc3afc 0 iEYEABECAAYFAk/FIeIACgkQyUhSUUBVisk4IgCfUiXVXntqzPjJcALYRpqw4Zc7a/0An3HKWwgb6PBCbmvxBfTezNkqjqVK From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: mdbox: Flush/fsync newly saved mail data before loc... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/61be33b6336c changeset: 14645:61be33b6336c user: Timo Sirainen date: Mon Jun 04 14:03:47 2012 +0300 description: mdbox: Flush/fsync newly saved mail data before locking map. This reduced the amount of time the map needs to be locked. diffstat: src/lib-storage/index/dbox-multi/mdbox-map.c | 15 +++++++++++++++ src/lib-storage/index/dbox-multi/mdbox-map.h | 2 ++ src/lib-storage/index/dbox-multi/mdbox-save.c | 6 ++++++ 3 files changed, 23 insertions(+), 0 deletions(-) diffs (53 lines): diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 14:03:47 2012 +0300 @@ -1369,6 +1369,21 @@ return 0; } +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx) +{ + struct dbox_file_append_context **file_appends; + unsigned int i, count; + + i_assert(ctx->trans == NULL); + + file_appends = array_get_modifiable(&ctx->file_appends, &count); + for (i = 0; i < count; i++) { + if (dbox_file_append_flush(file_appends[i]) < 0) + return -1; + } + return 0; +} + int mdbox_map_append_commit(struct mdbox_map_append_context *ctx) { struct dbox_file_append_context **file_appends; diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-map.h --- a/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h Mon Jun 04 14:03:47 2012 +0300 @@ -115,6 +115,8 @@ int mdbox_map_append_move(struct mdbox_map_append_context *ctx, const ARRAY_TYPE(uint32_t) *map_uids, const ARRAY_TYPE(seq_range) *expunge_map_uids); +/* Flush/fsync appends. */ +int mdbox_map_append_flush(struct mdbox_map_append_context *ctx); /* Returns 0 if ok, -1 if error. */ int mdbox_map_append_commit(struct mdbox_map_append_context *ctx); void mdbox_map_append_free(struct mdbox_map_append_context **ctx); diff -r 99d31c803b7b -r 61be33b6336c src/lib-storage/index/dbox-multi/mdbox-save.c --- a/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 13:59:40 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-save.c Mon Jun 04 14:03:47 2012 +0300 @@ -287,6 +287,12 @@ i_assert(ctx->ctx.finished); + /* flush/fsync writes to m.* files before locking the map */ + if (mdbox_map_append_flush(ctx->append_ctx) < 0) { + mdbox_transaction_save_rollback(_ctx); + return -1; + } + /* make sure the map gets locked */ if (mdbox_map_atomic_lock(ctx->atomic) < 0) { mdbox_transaction_save_rollback(_ctx); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm instance list: Added optional name paramete... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/fa75bd3245a4 changeset: 14646:fa75bd3245a4 user: Timo Sirainen date: Mon Jun 04 17:23:07 2012 +0300 description: doveadm instance list: Added optional name parameter to list only specified instance. diffstat: src/doveadm/doveadm-instance.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diffs (31 lines): diff -r 61be33b6336c -r fa75bd3245a4 src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Mon Jun 04 14:03:47 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Mon Jun 04 17:23:07 2012 +0300 @@ -42,7 +42,7 @@ return found; } -static void cmd_instance_list(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_instance_list(int argc, char *argv[]) { struct master_instance_list *list; struct master_instance_list_iter *iter; @@ -58,6 +58,9 @@ list = master_instance_list_init(MASTER_INSTANCE_PATH); iter = master_instance_list_iterate_init(list); while ((inst = master_instance_iterate_list_next(iter)) != NULL) { + if (argc > 1 && strcmp(argv[1], inst->name) != 0) + continue; + doveadm_print(inst->base_dir); doveadm_print(inst->name); doveadm_print(unixdate2str(inst->last_used)); @@ -95,7 +98,7 @@ } struct doveadm_cmd doveadm_cmd_instance[] = { - { cmd_instance_list, "instance list", "" }, + { cmd_instance_list, "instance list", "[]" }, { cmd_instance_remove, "instance remove", " | " } }; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: mdbox: Make sure map transaction won't succeed afte... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/99d31c803b7b changeset: 14644:99d31c803b7b user: Timo Sirainen date: Mon Jun 04 13:59:40 2012 +0300 description: mdbox: Make sure map transaction won't succeed after mdbox_map_atomic_set_failed() diffstat: src/lib-storage/index/dbox-multi/mdbox-map-private.h | 1 + src/lib-storage/index/dbox-multi/mdbox-map.c | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diffs (47 lines): diff -r 36d2aff85a69 -r 99d31c803b7b src/lib-storage/index/dbox-multi/mdbox-map-private.h --- a/src/lib-storage/index/dbox-multi/mdbox-map-private.h Tue May 29 22:22:14 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map-private.h Mon Jun 04 13:59:40 2012 +0300 @@ -57,6 +57,7 @@ unsigned int map_refreshed:1; unsigned int locked:1; unsigned int success:1; + unsigned int failed:1; }; int mdbox_map_view_lookup_rec(struct mdbox_map *map, diff -r 36d2aff85a69 -r 99d31c803b7b src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Tue May 29 22:22:14 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Mon Jun 04 13:59:40 2012 +0300 @@ -519,11 +519,13 @@ void mdbox_map_atomic_set_failed(struct mdbox_map_atomic_context *atomic) { atomic->success = FALSE; + atomic->failed = TRUE; } void mdbox_map_atomic_set_success(struct mdbox_map_atomic_context *atomic) { - atomic->success = TRUE; + if (!atomic->failed) + atomic->success = TRUE; } int mdbox_map_atomic_finish(struct mdbox_map_atomic_context **_atomic) @@ -595,7 +597,7 @@ mail_index_reset_error(ctx->atomic->map->index); return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } @@ -1379,7 +1381,7 @@ if (dbox_file_append_commit(&file_appends[i]) < 0) return -1; } - ctx->atomic->success = TRUE; + mdbox_map_atomic_set_success(ctx->atomic); return 0; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-master: Keep track of config paths in "instance... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/d85421a77fa1 changeset: 14647:d85421a77fa1 user: Timo Sirainen date: Mon Jun 04 21:21:28 2012 +0300 description: lib-master: Keep track of config paths in "instances" file. Normally it can be looked up from base_dir/dovecot.conf symlink, but base_dir may get deleted when system starts up. diffstat: src/lib-master/master-instance.c | 60 +++++++++++++++++++++++++++++++++++++-- src/lib-master/master-instance.h | 1 + 2 files changed, 57 insertions(+), 4 deletions(-) diffs (176 lines): diff -r fa75bd3245a4 -r d85421a77fa1 src/lib-master/master-instance.c --- a/src/lib-master/master-instance.c Mon Jun 04 17:23:07 2012 +0300 +++ b/src/lib-master/master-instance.c Mon Jun 04 21:21:28 2012 +0300 @@ -1,6 +1,7 @@ /* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ #include "lib.h" +#include "abspath.h" #include "array.h" #include "istream.h" #include "ostream.h" @@ -17,6 +18,9 @@ const char *path; ARRAY_DEFINE(instances, struct master_instance); + + unsigned int locked:1; + unsigned int config_paths_changed:1; }; struct master_instance_list_iter { @@ -50,6 +54,22 @@ pool_unref(&list->pool); } +static void +master_instance_update_config_path(struct master_instance_list *list, + struct master_instance *inst) +{ + const char *path, *config_path; + + /* update instance's config path if it has changed */ + path = t_strconcat(inst->base_dir, "/"PACKAGE".conf", NULL); + if (t_readlink(path, &config_path) == 0) { + if (null_strcmp(inst->config_path, config_path) != 0) { + inst->config_path = p_strdup(list->pool, config_path); + list->config_paths_changed = TRUE; + } + } +} + static int master_instance_list_add_line(struct master_instance_list *list, const char *line) @@ -58,9 +78,9 @@ const char *const *args; time_t last_used; - /* */ + /* [] */ args = t_strsplit_tabescaped(line); - if (str_array_length(args) != 3) + if (str_array_length(args) < 3) return -1; if (str_to_time(args[0], &last_used) < 0) return -1; @@ -69,6 +89,8 @@ inst->last_used = last_used; inst->name = p_strdup(list->pool, args[1]); inst->base_dir = p_strdup(list->pool, args[2]); + inst->config_path = p_strdup_empty(list->pool, args[3]); + master_instance_update_config_path(list, inst); return 0; } @@ -117,6 +139,9 @@ str_tabescape_write(str, inst->name); str_append_c(str, '\t'); str_tabescape_write(str, inst->base_dir); + str_append_c(str, '\t'); + if (inst->config_path != NULL) + str_tabescape_write(str, inst->config_path); str_append_c(str, '\n'); (void)o_stream_send(output, str_data(str), str_len(str)); } @@ -135,6 +160,8 @@ { int fd; + i_assert(!list->locked); + *dotlock_r = NULL; fd = file_dotlock_open_mode(&dotlock_set, list->path, 0, 0644, @@ -147,6 +174,7 @@ (void)file_dotlock_delete(dotlock_r); return -1; } + list->locked = TRUE; return fd; } @@ -156,9 +184,13 @@ const char *lock_path = file_dotlock_get_lock_path(*dotlock); int ret; + i_assert(list->locked); + T_BEGIN { ret = master_instance_list_write(list, fd, lock_path); } T_END; + + list->locked = FALSE; if (ret < 0) { (void)file_dotlock_delete(dotlock); return -1; @@ -168,6 +200,7 @@ (void)file_dotlock_delete(dotlock); return -1; } + list->config_paths_changed = FALSE; return file_dotlock_replace(dotlock, 0); } @@ -201,6 +234,7 @@ inst->base_dir = p_strdup(list->pool, base_dir); } inst->last_used = time(NULL); + master_instance_update_config_path(list, inst); return master_instance_write_finish(list, fd, &dotlock); } @@ -263,6 +297,24 @@ return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1; } +static int +master_instance_list_refresh_and_update(struct master_instance_list *list) +{ + struct dotlock *dotlock; + int fd; + + if (master_instance_list_refresh(list) < 0) + return -1; + if (list->config_paths_changed && !list->locked) { + /* write new config paths */ + if ((fd = master_instance_write_init(list, &dotlock)) == -1) + return -1; + if (master_instance_write_finish(list, fd, &dotlock) < 0) + return -1; + } + return 0; +} + const struct master_instance * master_instance_list_find_by_name(struct master_instance_list *list, const char *name) @@ -272,7 +324,7 @@ i_assert(*name != '\0'); if (array_count(&list->instances) == 0) - (void)master_instance_list_refresh(list); + (void)master_instance_list_refresh_and_update(list); array_foreach(&list->instances, inst) { if (strcmp(inst->name, name) == 0) @@ -288,7 +340,7 @@ iter = i_new(struct master_instance_list_iter, 1); iter->list = list; - (void)master_instance_list_refresh(list); + (void)master_instance_list_refresh_and_update(list); return iter; } diff -r fa75bd3245a4 -r d85421a77fa1 src/lib-master/master-instance.h --- a/src/lib-master/master-instance.h Mon Jun 04 17:23:07 2012 +0300 +++ b/src/lib-master/master-instance.h Mon Jun 04 21:21:28 2012 +0300 @@ -9,6 +9,7 @@ time_t last_used; const char *name; const char *base_dir; + const char *config_path; }; struct master_instance_list *master_instance_list_init(const char *path); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm instance list: Added -c parameter to easily... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/ee5d838ebcbb changeset: 14648:ee5d838ebcbb user: Timo Sirainen date: Mon Jun 04 21:21:52 2012 +0300 description: doveadm instance list: Added -c parameter to easily get the instance's config path. diffstat: src/doveadm/doveadm-instance.c | 35 ++++++++++++++++++++++++++++------- 1 files changed, 28 insertions(+), 7 deletions(-) diffs (66 lines): diff -r d85421a77fa1 -r ee5d838ebcbb src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Mon Jun 04 21:21:28 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Mon Jun 04 21:21:52 2012 +0300 @@ -5,6 +5,7 @@ #include "doveadm.h" #include "doveadm-print.h" +#include #include #include #include @@ -48,19 +49,39 @@ struct master_instance_list_iter *iter; const struct master_instance *inst; const char *pidfile_path; + bool show_config = FALSE; + int c; - doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); - doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); - doveadm_print_header_simple("name"); - doveadm_print_header_simple("last used"); - doveadm_print_header_simple("running"); + while ((c = getopt(argc, argv, "c")) > 0) { + switch (c) { + case 'c': + show_config = TRUE; + break; + default: + help(&doveadm_cmd_instance[0]); + } + } + argv += optind; + + if (!show_config) { + doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); + doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); + doveadm_print_header_simple("name"); + doveadm_print_header_simple("last used"); + doveadm_print_header_simple("running"); + } list = master_instance_list_init(MASTER_INSTANCE_PATH); iter = master_instance_list_iterate_init(list); while ((inst = master_instance_iterate_list_next(iter)) != NULL) { - if (argc > 1 && strcmp(argv[1], inst->name) != 0) + if (argv[0] != NULL && strcmp(argv[0], inst->name) != 0) continue; + if (show_config) { + printf("%s\n", inst->config_path == NULL ? "" : + inst->config_path); + continue; + } doveadm_print(inst->base_dir); doveadm_print(inst->name); doveadm_print(unixdate2str(inst->last_used)); @@ -98,7 +119,7 @@ } struct doveadm_cmd doveadm_cmd_instance[] = { - { cmd_instance_list, "instance list", "[]" }, + { cmd_instance_list, "instance list", "[-c] []" }, { cmd_instance_remove, "instance remove", " | " } }; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-charset: Make sure convert_to_utf8*() never ret... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/0fde692cb565 changeset: 14650:0fde692cb565 user: Timo Sirainen date: Mon Jun 11 16:14:13 2012 +0300 description: lib-charset: Make sure convert_to_utf8*() never returns non-UTF8 output. diffstat: src/lib-charset/charset-iconv.c | 58 ++++++++++++++++++---------------------- 1 files changed, 26 insertions(+), 32 deletions(-) diffs (85 lines): diff -r a0ff87fe1f4a -r 0fde692cb565 src/lib-charset/charset-iconv.c --- a/src/lib-charset/charset-iconv.c Mon Jun 04 21:58:00 2012 +0300 +++ b/src/lib-charset/charset-iconv.c Mon Jun 11 16:14:13 2012 +0300 @@ -53,6 +53,20 @@ (void)iconv(t->cd, NULL, NULL, NULL, NULL); } +static int +charset_append_utf8(const void *src, size_t src_size, + buffer_t *dest, bool dtcase) +{ + if (dtcase) + return uni_utf8_to_decomposed_titlecase(src, src_size, dest); + if (!uni_utf8_get_valid_data(src, src_size, dest)) + return -1; + else { + buffer_append(dest, src, src_size); + return 0; + } +} + static bool charset_to_utf8_try(struct charset_translation *t, const unsigned char *src, size_t *src_size, buffer_t *dest, @@ -65,30 +79,15 @@ bool ret = TRUE; if (t->cd == (iconv_t)-1) { - /* no translation needed - just copy it to outbuf uppercased */ - *result = CHARSET_RET_OK; - if (!dtcase) { - buffer_append(dest, src, *src_size); - return TRUE; - } - - if (uni_utf8_to_decomposed_titlecase(src, *src_size, dest) < 0) + /* input is already supposed to be UTF-8 */ + if (charset_append_utf8(src, *src_size, dest, dtcase) < 0) *result = CHARSET_RET_INVALID_INPUT; + else + *result = CHARSET_RET_OK; return TRUE; } - if (!dtcase) { - destleft = buffer_get_size(dest) - dest->used; - if (destleft < *src_size) { - /* The buffer is most likely too small to hold the - output, so increase it at least to the input size. */ - destleft = *src_size; - } - ic_destbuf = buffer_append_space_unsafe(dest, destleft); - } else { - destleft = sizeof(tmpbuf); - ic_destbuf = tmpbuf; - } - + destleft = sizeof(tmpbuf); + ic_destbuf = tmpbuf; srcleft = *src_size; ic_srcbuf = (ICONV_CONST char *) src; @@ -108,17 +107,12 @@ } *src_size -= srcleft; - if (!dtcase) { - /* give back the memory we didn't use */ - buffer_set_used_size(dest, dest->used - destleft); - } else { - size_t tmpsize = sizeof(tmpbuf) - destleft; - - /* we just converted data to UTF-8. it shouldn't be invalid, - but Solaris iconv appears to pass invalid data through - sometimes (e.g. 8 bit characters with UTF-7) */ - (void)uni_utf8_to_decomposed_titlecase(tmpbuf, tmpsize, dest); - } + /* we just converted data to UTF-8. it shouldn't be invalid, but + Solaris iconv appears to pass invalid data through sometimes + (e.g. 8 bit characters with UTF-7) */ + if (charset_append_utf8(tmpbuf, sizeof(tmpbuf) - destleft, + dest, dtcase) < 0) + *result = CHARSET_RET_INVALID_INPUT; return ret; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-master: -i parameter shouldn't imply -k parameter. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/98f2c12eccdb changeset: 14651:98f2c12eccdb user: Timo Sirainen date: Mon Jun 11 16:30:58 2012 +0300 description: lib-master: -i parameter shouldn't imply -k parameter. This was added accidentally when writing the code. diffstat: src/lib-master/master-service.c | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diffs (11 lines): diff -r 0fde692cb565 -r 98f2c12eccdb src/lib-master/master-service.c --- a/src/lib-master/master-service.c Mon Jun 11 16:14:13 2012 +0300 +++ b/src/lib-master/master-service.c Mon Jun 11 16:30:58 2012 +0300 @@ -359,7 +359,6 @@ if (!get_instance_config(arg, &path)) i_fatal("Unknown instance name: %s", arg); service->config_path = i_strdup(path); - service->keep_environment = TRUE; break; case 'k': service->keep_environment = TRUE; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm config: If -c parameter was given, it wasn'... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/a0ff87fe1f4a changeset: 14649:a0ff87fe1f4a user: Timo Sirainen date: Mon Jun 04 21:58:00 2012 +0300 description: doveadm config: If -c parameter was given, it wasn't passed to doveconf. diffstat: src/doveadm/doveadm.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diffs (21 lines): diff -r ee5d838ebcbb -r a0ff87fe1f4a src/doveadm/doveadm.c --- a/src/doveadm/doveadm.c Mon Jun 04 21:21:52 2012 +0300 +++ b/src/doveadm/doveadm.c Mon Jun 04 21:58:00 2012 +0300 @@ -5,7 +5,7 @@ #include "str.h" #include "env-util.h" #include "execv-const.h" -#include "master-service.h" +#include "master-service-private.h" #include "master-service-settings.h" #include "settings-parser.h" #include "doveadm-print-private.h" @@ -163,6 +163,8 @@ static void cmd_config(int argc ATTR_UNUSED, char *argv[]) { + env_put(t_strconcat(MASTER_CONFIG_FILE_ENV"=", + master_service_get_config_path(master_service), NULL)); argv[0] = BINDIR"/doveconf"; (void)execv(argv[0], argv); i_fatal("execv(%s) failed: %m", argv[0]); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: director: Fixed working as standalone. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/46d01b728647 changeset: 14652:46d01b728647 user: Timo Sirainen date: Mon Jun 11 16:54:14 2012 +0300 description: director: Fixed working as standalone. diffstat: src/director/director.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diffs (15 lines): diff -r 98f2c12eccdb -r 46d01b728647 src/director/director.c --- a/src/director/director.c Mon Jun 11 16:30:58 2012 +0300 +++ b/src/director/director.c Mon Jun 11 16:54:14 2012 +0300 @@ -363,6 +363,11 @@ { /* we're synced again when we receive this SYNC back */ dir->sync_seq++; + if (dir->right == NULL && dir->left == NULL) { + /* we're alone. if we're already synced, + don't become unsynced. */ + return; + } director_set_ring_unsynced(dir); if (dir->sync_frozen) { From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: shared mailboxes: Avoid doing "@domain" userdb look... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/28ddc2058877 changeset: 14653:28ddc2058877 user: Timo Sirainen date: Mon Jun 11 23:38:45 2012 +0300 description: shared mailboxes: Avoid doing "@domain" userdb lookups. diffstat: src/lib-storage/index/shared/shared-list.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-) diffs (18 lines): diff -r 46d01b728647 -r 28ddc2058877 src/lib-storage/index/shared/shared-list.c --- a/src/lib-storage/index/shared/shared-list.c Mon Jun 11 16:54:14 2012 +0300 +++ b/src/lib-storage/index/shared/shared-list.c Mon Jun 11 23:38:45 2012 +0300 @@ -43,8 +43,12 @@ const char *name; name = mailbox_list_get_storage_name(*list, vname); - if (shared_storage_get_namespace(&ns, &name) < 0) - return -1; + if (*name == '\0' && (ns->flags & NAMESPACE_FLAG_AUTOCREATED) == 0) { + /* trying to access the shared/ prefix itself */ + } else { + if (shared_storage_get_namespace(&ns, &name) < 0) + return -1; + } *list = ns->list; *storage_r = ns->storage; return 0; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: master: If service_count=1 and process_limit=1 and ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/4c31e450a867 changeset: 14654:4c31e450a867 user: Timo Sirainen date: Wed Jun 13 15:34:39 2012 +0300 description: master: If service_count=1 and process_limit=1 and >1 clients connect, log about service_count being why. diffstat: src/master/service-monitor.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diffs (36 lines): diff -r 28ddc2058877 -r 4c31e450a867 src/master/service-monitor.c --- a/src/master/service-monitor.c Mon Jun 11 23:38:45 2012 +0300 +++ b/src/master/service-monitor.c Wed Jun 13 15:34:39 2012 +0300 @@ -237,19 +237,27 @@ static void service_drop_connections(struct service_listener *l) { struct service *service = l->service; + const char *limit_name; unsigned int limit; int fd; if (service->last_drop_warning + SERVICE_DROP_WARN_INTERVAL_SECS < ioloop_time) { service->last_drop_warning = ioloop_time; - limit = service->process_limit > 1 ? - service->process_limit : service->client_limit; + if (service->process_limit > 1) { + limit_name = "process_limit"; + limit = service->process_limit; + } else if (service->set->service_count == 1) { + i_assert(service->client_limit == 1); + limit_name = "client_limit/service_count"; + limit = 1; + } else { + limit_name = "client_limit"; + limit = service->client_limit; + } i_warning("service(%s): %s (%u) reached, " "client connections are being dropped", - service->set->name, - service->process_limit > 1 ? - "process_limit" : "client_limit", limit); + service->set->name, limit_name, limit); } if (service->type == SERVICE_TYPE_LOGIN) { From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-master: Fixed assert crash in some situations a... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c58a27eecdd4 changeset: 14655:c58a27eecdd4 user: Timo Sirainen date: Wed Jun 13 16:29:37 2012 +0300 description: lib-master: Fixed assert crash in some situations after updating instance name. diffstat: src/lib-master/master-instance.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diffs (19 lines): diff -r 4c31e450a867 -r c58a27eecdd4 src/lib-master/master-instance.c --- a/src/lib-master/master-instance.c Wed Jun 13 15:34:39 2012 +0300 +++ b/src/lib-master/master-instance.c Wed Jun 13 16:29:37 2012 +0300 @@ -257,6 +257,7 @@ strcmp(orig_inst->base_dir, base_dir) != 0) { /* name already used */ (void)file_dotlock_delete(&dotlock); + list->locked = FALSE; return 0; } @@ -292,6 +293,7 @@ if (i == count) { (void)file_dotlock_delete(&dotlock); + list->locked = FALSE; return 0; } return master_instance_write_finish(list, fd, &dotlock) < 0 ? -1 : 1; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: maildir++ quota: If reading maildirsize fails with ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/cad676b57cc8 changeset: 14656:cad676b57cc8 user: Timo Sirainen date: Fri Jun 15 15:12:33 2012 +0300 description: maildir++ quota: If reading maildirsize fails with ESTALE, retry it. diffstat: src/plugins/quota/quota-maildir.c | 23 +++++++++++++++++------ 1 files changed, 17 insertions(+), 6 deletions(-) diffs (57 lines): diff -r c58a27eecdd4 -r cad676b57cc8 src/plugins/quota/quota-maildir.c --- a/src/plugins/quota/quota-maildir.c Wed Jun 13 16:29:37 2012 +0300 +++ b/src/plugins/quota/quota-maildir.c Fri Jun 15 15:12:33 2012 +0300 @@ -546,12 +546,15 @@ !CMP_DEV_T(st1.st_dev, st2.st_dev); } -static int maildirsize_read(struct maildir_quota_root *root) +static int maildirsize_read(struct maildir_quota_root *root, bool *retry) { char buf[5120+1]; unsigned int i, size; + bool retry_estale = *retry; int ret; + *retry = FALSE; + if (!maildirsize_has_changed(root)) return 1; @@ -562,8 +565,10 @@ size = 0; while ((ret = read(root->fd, buf + size, sizeof(buf)-1 - size)) != 0) { if (ret < 0) { - if (errno == ESTALE) + if (errno == ESTALE && retry_estale) { + *retry = TRUE; break; + } i_error("read(%s) failed: %m", root->maildirsize_path); break; } @@ -644,14 +649,20 @@ static int maildirquota_read_limits(struct maildir_quota_root *root) { - int ret; + bool retry = TRUE; + int ret, n = 0; if (!maildirquota_limits_init(root)) return 1; - T_BEGIN { - ret = maildirsize_read(root); - } T_END; + do { + if (n == NFS_ESTALE_RETRY_COUNT) + retry = FALSE; + T_BEGIN { + ret = maildirsize_read(root, &retry); + } T_END; + n++; + } while (ret == -1 && retry); return ret; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: example-config: imap_logout_format default was wrong. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/a4cd22976ddb changeset: 14657:a4cd22976ddb user: Timo Sirainen date: Fri Jun 15 17:12:24 2012 +0300 description: example-config: imap_logout_format default was wrong. diffstat: doc/example-config/conf.d/20-imap.conf | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r cad676b57cc8 -r a4cd22976ddb doc/example-config/conf.d/20-imap.conf --- a/doc/example-config/conf.d/20-imap.conf Fri Jun 15 15:12:33 2012 +0300 +++ b/doc/example-config/conf.d/20-imap.conf Fri Jun 15 17:12:24 2012 +0300 @@ -18,7 +18,7 @@ # IMAP logout format string: # %i - total number of bytes read from client # %o - total number of bytes sent to client - #imap_logout_format = bytes=%i/%o + #imap_logout_format = in=%i out=%o # Override the IMAP CAPABILITY response. If the value begins with '+', # add the given capabilities on top of the defaults (e.g. +XFOO XBAR). From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm log errors: Added -s parameter Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/8de41fa0fbf1 changeset: 14658:8de41fa0fbf1 user: Timo Sirainen date: Fri Jun 15 23:44:53 2012 +0300 description: doveadm log errors: Added -s parameter diffstat: src/doveadm/doveadm-log.c | 34 ++++++++++++++++++++++++++-------- 1 files changed, 26 insertions(+), 8 deletions(-) diffs (77 lines): diff -r a4cd22976ddb -r 8de41fa0fbf1 src/doveadm/doveadm-log.c --- a/src/doveadm/doveadm-log.c Fri Jun 15 17:12:24 2012 +0300 +++ b/src/doveadm/doveadm-log.c Fri Jun 15 23:44:53 2012 +0300 @@ -23,6 +23,8 @@ #define LOG_ERRORS_FNAME "log-errors" #define LOG_TIMESTAMP_FORMAT "%b %d %H:%M:%S" +extern struct doveadm_cmd doveadm_cmd_log[]; + static void cmd_log_test(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) { struct failure_context ctx; @@ -278,7 +280,7 @@ } } -static void cmd_log_error_write(const char *const *args) +static void cmd_log_error_write(const char *const *args, time_t min_timestamp) { /* */ const char *type_prefix = "?"; @@ -297,16 +299,32 @@ i_error("Invalid timestamp: %s", args[1]); t = 0; } - - printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), - args[2], type_prefix, args[3]); + if (t >= min_timestamp) { + printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), + args[2], type_prefix, args[3]); + } } -static void cmd_log_errors(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_log_errors(int argc, char *argv[]) { struct istream *input; const char *path, *line, *const *args; - int fd; + time_t min_timestamp = 0; + int c, fd; + + while ((c = getopt(argc, argv, "s:")) > 0) { + switch (c) { + case 's': + if (str_to_time(optarg, &min_timestamp) < 0) + i_fatal("Invalid timestamp: %s", optarg); + break; + default: + help(&doveadm_cmd_log[3]); + } + } + argv += optind - 1; + if (argv[1] != NULL) + help(&doveadm_cmd_log[3]); path = t_strconcat(doveadm_settings->base_dir, "/"LOG_ERRORS_FNAME, NULL); @@ -319,7 +337,7 @@ while ((line = i_stream_read_next_line(input)) != NULL) T_BEGIN { args = t_strsplit_tabescaped(line); if (str_array_length(args) == 4) - cmd_log_error_write(args); + cmd_log_error_write(args, min_timestamp); else { i_error("Invalid input from log: %s", line); doveadm_exit_code = EX_PROTOCOL; @@ -332,7 +350,7 @@ { cmd_log_test, "log test", "" }, { cmd_log_reopen, "log reopen", "" }, { cmd_log_find, "log find", "[]" }, - { cmd_log_errors, "log errors", "" } + { cmd_log_errors, "log errors", "[-s ]" } }; void doveadm_register_log_commands(void) From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm log errors: Usage text update Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/db32881669e6 changeset: 14659:db32881669e6 user: Timo Sirainen date: Sat Jun 16 01:59:44 2012 +0300 description: doveadm log errors: Usage text update diffstat: src/doveadm/doveadm-log.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 8de41fa0fbf1 -r db32881669e6 src/doveadm/doveadm-log.c --- a/src/doveadm/doveadm-log.c Fri Jun 15 23:44:53 2012 +0300 +++ b/src/doveadm/doveadm-log.c Sat Jun 16 01:59:44 2012 +0300 @@ -350,7 +350,7 @@ { cmd_log_test, "log test", "" }, { cmd_log_reopen, "log reopen", "" }, { cmd_log_find, "log find", "[]" }, - { cmd_log_errors, "log errors", "[-s ]" } + { cmd_log_errors, "log errors", "[-s ]" } }; void doveadm_register_log_commands(void) From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: imapc: Removed brokenly used explicit data stack fr... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/a28c8043842d changeset: 14660:a28c8043842d user: Timo Sirainen date: Sat Jun 16 02:03:53 2012 +0300 description: imapc: Removed brokenly used explicit data stack frame. Fixes crashes when a message has more than 8 keywords. diffstat: src/lib-storage/index/imapc/imapc-mailbox.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r db32881669e6 -r a28c8043842d src/lib-storage/index/imapc/imapc-mailbox.c --- a/src/lib-storage/index/imapc/imapc-mailbox.c Sat Jun 16 01:59:44 2012 +0300 +++ b/src/lib-storage/index/imapc/imapc-mailbox.c Sat Jun 16 02:03:53 2012 +0300 @@ -338,7 +338,7 @@ mail_index_update_flags(mbox->delayed_sync_trans, lseq, MODIFY_REPLACE, flags); } - if (seen_flags) T_BEGIN { + if (seen_flags) { ARRAY_TYPE(keyword_indexes) old_kws; struct mail_keywords *kw; @@ -354,7 +354,7 @@ lseq, MODIFY_REPLACE, kw); } mail_index_keywords_unref(&kw); - } T_END; + } imapc_mailbox_idle_notify(mbox); } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: doveadm: Fixed crash with proxying some commands. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9fc78d06252c changeset: 14661:9fc78d06252c user: Timo Sirainen date: Mon Jun 18 13:19:41 2012 +0300 description: doveadm: Fixed crash with proxying some commands. diffstat: src/doveadm/doveadm-print.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-) diffs (51 lines): diff -r a28c8043842d -r 9fc78d06252c src/doveadm/doveadm-print.c --- a/src/doveadm/doveadm-print.c Sat Jun 16 02:03:53 2012 +0300 +++ b/src/doveadm/doveadm-print.c Mon Jun 18 13:19:41 2012 +0300 @@ -18,6 +18,7 @@ const struct doveadm_print_vfuncs *v; unsigned int header_idx; + bool print_stream_open; }; static struct doveadm_print_context *ctx; @@ -52,7 +53,7 @@ doveadm_print_header(key_title, key_title, 0); } -void doveadm_print(const char *value) +static void doveadm_print_sticky_headers(void) { const struct doveadm_print_header_context *headers; unsigned int count; @@ -68,7 +69,13 @@ break; } } +} +void doveadm_print(const char *value) +{ + i_assert(!ctx->print_stream_open); + + doveadm_print_sticky_headers(); ctx->v->print(value); ctx->header_idx++; } @@ -82,9 +89,15 @@ void doveadm_print_stream(const void *value, size_t size) { + if (!ctx->print_stream_open) { + doveadm_print_sticky_headers(); + ctx->print_stream_open = TRUE; + } ctx->v->print_stream(value, size); - if (size == 0) + if (size == 0) { ctx->header_idx++; + ctx->print_stream_open = FALSE; + } } void doveadm_print_sticky(const char *key, const char *value) From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: fts-squat: Fixed handling multiple SEARCH parameters. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/4ce1f9649592 changeset: 14663:4ce1f9649592 user: Timo Sirainen date: Mon Jun 18 17:05:27 2012 +0300 description: fts-squat: Fixed handling multiple SEARCH parameters. diffstat: src/plugins/fts-squat/fts-backend-squat.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diffs (16 lines): diff -r 39d9e75fec02 -r 4ce1f9649592 src/plugins/fts-squat/fts-backend-squat.c --- a/src/plugins/fts-squat/fts-backend-squat.c Mon Jun 18 13:21:03 2012 +0300 +++ b/src/plugins/fts-squat/fts-backend-squat.c Mon Jun 18 17:05:27 2012 +0300 @@ -452,9 +452,10 @@ &result->maybe_uids); if (ret < 0) return -1; - if (ret > 0) + if (ret > 0) { args->match_always = TRUE; - first = FALSE; + first = FALSE; + } } return 0; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-ssl-iostream: Don't assert-crash if underlying ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/39d9e75fec02 changeset: 14662:39d9e75fec02 user: Timo Sirainen date: Mon Jun 18 13:21:03 2012 +0300 description: lib-ssl-iostream: Don't assert-crash if underlying connection suddenly disconnects. diffstat: src/lib-ssl-iostream/iostream-openssl.c | 7 +++++-- src/lib-ssl-iostream/istream-openssl.c | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diffs (42 lines): diff -r 9fc78d06252c -r 39d9e75fec02 src/lib-ssl-iostream/iostream-openssl.c --- a/src/lib-ssl-iostream/iostream-openssl.c Mon Jun 18 13:19:41 2012 +0300 +++ b/src/lib-ssl-iostream/iostream-openssl.c Mon Jun 18 13:21:03 2012 +0300 @@ -388,7 +388,8 @@ return 0; } if (ssl_io->closed) { - errno = ssl_io->plain_stream_errno; + errno = ssl_io->plain_stream_errno != 0 ? + ssl_io->plain_stream_errno : EPIPE; return -1; } return 1; @@ -396,7 +397,8 @@ ssl_io->want_read = TRUE; (void)ssl_iostream_bio_sync(ssl_io); if (ssl_io->closed) { - errno = ssl_io->plain_stream_errno; + errno = ssl_io->plain_stream_errno != 0 ? + ssl_io->plain_stream_errno : EPIPE; return -1; } return ssl_io->want_read ? 0 : 1; @@ -406,6 +408,7 @@ errstr = ssl_iostream_error(); errno = EINVAL; } else if (ret != 0) { + i_assert(errno != 0); errstr = strerror(errno); } else { /* EOF. */ diff -r 9fc78d06252c -r 39d9e75fec02 src/lib-ssl-iostream/istream-openssl.c --- a/src/lib-ssl-iostream/istream-openssl.c Mon Jun 18 13:19:41 2012 +0300 +++ b/src/lib-ssl-iostream/istream-openssl.c Mon Jun 18 13:21:03 2012 +0300 @@ -38,6 +38,7 @@ if (ret <= 0) { if (ret < 0) { /* handshake failed */ + i_assert(errno != 0); stream->istream.stream_errno = errno; } return ret; From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: message parser: Fixed infinite loop when parsing a ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/4461b48fcc1f changeset: 14664:4461b48fcc1f user: Timo Sirainen date: Wed Jun 20 02:21:54 2012 +0300 description: message parser: Fixed infinite loop when parsing a specific message. diffstat: src/lib-mail/message-parser.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diffs (15 lines): diff -r 4ce1f9649592 -r 4461b48fcc1f src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Mon Jun 18 17:05:27 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 20 02:21:54 2012 +0300 @@ -151,7 +151,10 @@ } } - ctx->want_count = 1; + if (!*full_r) { + /* reset number of wanted characters if we actually got them */ + ctx->want_count = 1; + } return 1; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: imapc: Don't crash when using multiple imapc namesp... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/b13753851a07 changeset: 14665:b13753851a07 user: Timo Sirainen date: Thu Jun 21 18:48:38 2012 +0300 description: imapc: Don't crash when using multiple imapc namespaces. diffstat: src/lib-storage/index/imapc/imapc-storage.c | 15 ++++++++++++++- 1 files changed, 14 insertions(+), 1 deletions(-) diffs (32 lines): diff -r 4461b48fcc1f -r b13753851a07 src/lib-storage/index/imapc/imapc-storage.c --- a/src/lib-storage/index/imapc/imapc-storage.c Wed Jun 20 02:21:54 2012 +0300 +++ b/src/lib-storage/index/imapc/imapc-storage.c Thu Jun 21 18:48:38 2012 +0300 @@ -275,6 +275,19 @@ imapc_client_deinit(&storage->client); } +static void imapc_storage_add_list(struct mail_storage *_storage, + struct mailbox_list *_list) +{ + struct imapc_storage *storage = (struct imapc_storage *)_storage; + struct imapc_mailbox_list *list = (struct imapc_mailbox_list *)_list; + + i_assert(storage->list != NULL); + i_assert(storage->list->sep != '\0'); + + list->storage = storage; + list->sep = storage->list->sep; +} + void imapc_storage_register_untagged(struct imapc_storage *storage, const char *name, imapc_storage_callback_t *callback) @@ -752,7 +765,7 @@ imapc_storage_alloc, imapc_storage_create, imapc_storage_destroy, - NULL, + imapc_storage_add_list, imapc_storage_get_list_settings, NULL, imapc_mailbox_alloc, From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: quota: Don't crash at init if one of the namespaces... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/046f03b33584 changeset: 14666:046f03b33584 user: Timo Sirainen date: Thu Jun 21 19:12:04 2012 +0300 description: quota: Don't crash at init if one of the namespaces no root dir. diffstat: src/plugins/quota/quota.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r b13753851a07 -r 046f03b33584 src/plugins/quota/quota.c --- a/src/plugins/quota/quota.c Thu Jun 21 18:48:38 2012 +0300 +++ b/src/plugins/quota/quota.c Thu Jun 21 19:12:04 2012 +0300 @@ -639,7 +639,7 @@ for (i = 0; i < count; i++) { path2 = mailbox_list_get_path(namespaces[i]->list, NULL, MAILBOX_LIST_PATH_TYPE_MAILBOX); - if (strcmp(path, path2) == 0) { + if (path2 != NULL && strcmp(path, path2) == 0) { /* duplicate */ return; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: imap: If DELETE can't succeed because mailbox has c... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/e62979a15657 changeset: 14667:e62979a15657 user: Timo Sirainen date: Thu Jun 21 21:25:04 2012 +0300 description: imap: If DELETE can't succeed because mailbox has children, don't give [ALREADYEXISTS] code. diffstat: src/imap/cmd-delete.c | 16 ++++++++++++---- 1 files changed, 12 insertions(+), 4 deletions(-) diffs (34 lines): diff -r 046f03b33584 -r e62979a15657 src/imap/cmd-delete.c --- a/src/imap/cmd-delete.c Thu Jun 21 19:12:04 2012 +0300 +++ b/src/imap/cmd-delete.c Thu Jun 21 21:25:04 2012 +0300 @@ -8,7 +8,8 @@ struct client *client = cmd->client; struct mail_namespace *ns; struct mailbox *box; - const char *name; + const char *name, *errstr; + enum mail_error error; /* */ if (!client_read_string_args(cmd, 1, &name)) @@ -32,10 +33,17 @@ mailbox_free(&client->mailbox); } - if (mailbox_delete(box) < 0) - client_send_storage_error(cmd, mailbox_get_storage(box)); - else + if (mailbox_delete(box) == 0) client_send_tagline(cmd, "OK Delete completed."); + else { + errstr = mailbox_get_last_error(box, &error); + if (error != MAIL_ERROR_EXISTS) + client_send_storage_error(cmd, mailbox_get_storage(box)); + else { + /* mailbox has children */ + client_send_tagline(cmd, t_strdup_printf("NO %s", errstr)); + } + } mailbox_free(&box); return TRUE; } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: lib-ssl-iostream: Memory leak fixes Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/11c07ab07d39 changeset: 14668:11c07ab07d39 user: Timo Sirainen date: Fri Jun 22 18:51:42 2012 +0300 description: lib-ssl-iostream: Memory leak fixes diffstat: src/lib-ssl-iostream/iostream-openssl.c | 12 +++++++----- src/lib-ssl-iostream/istream-openssl.c | 1 + src/lib-ssl-iostream/ostream-openssl.c | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diffs (64 lines): diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/iostream-openssl.c --- a/src/lib-ssl-iostream/iostream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/iostream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -246,7 +246,7 @@ *_ssl_io = NULL; i_assert(ssl_io->refcount > 0); - if (--ssl_io->refcount >= 0) + if (--ssl_io->refcount > 0) return; ssl_iostream_free(ssl_io); @@ -503,6 +503,7 @@ const char *dnsname; bool dns_names = FALSE; unsigned int i, count; + int ret; cert = SSL_get_peer_certificate(ssl); i_assert(cert != NULL); @@ -520,14 +521,15 @@ } } sk_GENERAL_NAME_pop_free(gnames, GENERAL_NAME_free); - X509_free(cert); /* verify against CommonName only when there wasn't any DNS SubjectAltNames */ if (dns_names) - return i < count ? 0 : -1; - - return strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + ret = i < count ? 0 : -1; + else + ret = strcmp(get_cname(cert), verify_name) == 0 ? 0 : -1; + X509_free(cert); + return ret; } int ssl_iostream_cert_match_name(struct ssl_iostream *ssl_io, diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/istream-openssl.c --- a/src/lib-ssl-iostream/istream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/istream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -21,6 +21,7 @@ { struct ssl_istream *sstream = (struct ssl_istream *)stream; + i_free(sstream->istream.w_buffer); ssl_iostream_unref(&sstream->ssl_io); } diff -r e62979a15657 -r 11c07ab07d39 src/lib-ssl-iostream/ostream-openssl.c --- a/src/lib-ssl-iostream/ostream-openssl.c Thu Jun 21 21:25:04 2012 +0300 +++ b/src/lib-ssl-iostream/ostream-openssl.c Fri Jun 22 18:51:42 2012 +0300 @@ -24,7 +24,8 @@ sstream->ssl_io->ssl_output = NULL; ssl_iostream_unref(&sstream->ssl_io); - i_free(sstream->buffer); + if (sstream->buffer != NULL) + buffer_free(&sstream->buffer); } static size_t From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Fixed signed integer shift overflows. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/6411d91d0755 changeset: 14669:6411d91d0755 user: Timo Sirainen date: Sun Jun 24 02:20:28 2012 +0300 description: Fixed signed integer shift overflows. These didn't actually cause any broken behavior. One of these was caught by http://embed.cs.utah.edu/ioc/ and the rest I grepped. diffstat: src/director/mail-host.c | 2 +- src/lib/primes.c | 2 +- src/lib/utc-mktime.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diffs (36 lines): diff -r 11c07ab07d39 -r 6411d91d0755 src/director/mail-host.c --- a/src/director/mail-host.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/director/mail-host.c Sun Jun 24 02:20:28 2012 +0300 @@ -110,7 +110,7 @@ i2 = htonl(ip2_arr[i]); for (j = last_bits; j < 32; j++) { - if ((i1 & (1 << j)) != (i2 & (1 << j))) { + if ((i1 & (1U << j)) != (i2 & (1U << j))) { i_error("IP address range too large: %s-%s", net_ip2addr(&ip1), net_ip2addr(&ip2)); return -1; diff -r 11c07ab07d39 -r 6411d91d0755 src/lib/primes.c --- a/src/lib/primes.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/lib/primes.c Sun Jun 24 02:20:28 2012 +0300 @@ -41,7 +41,7 @@ unsigned int i; for (i = 31; i > PRIME_SKIP_COUNT; i--) { - if ((num & (1 << i)) != 0) + if ((num & (1U << i)) != 0) return primes[i - PRIME_SKIP_COUNT]; } return primes[0]; diff -r 11c07ab07d39 -r 6411d91d0755 src/lib/utc-mktime.c --- a/src/lib/utc-mktime.c Fri Jun 22 18:51:42 2012 +0300 +++ b/src/lib/utc-mktime.c Sun Jun 24 02:20:28 2012 +0300 @@ -33,7 +33,7 @@ #ifdef TIME_T_SIGNED t = 0; #else - t = 1 << (TIME_T_MAX_BITS - 1); + t = (time_t)1 << (TIME_T_MAX_BITS - 1); #endif for (bits = TIME_T_MAX_BITS - 2;; bits--) { try_tm = gmtime(&t); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: mailbox_list_index=yes: Fixed a potential crash. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/bb1de2a1d866 changeset: 14670:bb1de2a1d866 user: Timo Sirainen date: Sun Jun 24 03:02:11 2012 +0300 description: mailbox_list_index=yes: Fixed a potential crash. diffstat: src/lib-storage/list/mailbox-list-index-status.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (13 lines): diff -r 6411d91d0755 -r bb1de2a1d866 src/lib-storage/list/mailbox-list-index-status.c --- a/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 02:20:28 2012 +0300 +++ b/src/lib-storage/list/mailbox-list-index-status.c Sun Jun 24 03:02:11 2012 +0300 @@ -81,7 +81,8 @@ ret = FALSE; else { status_r->uidvalidity = rec->uid_validity; - memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); + if (mailbox_guid != NULL) + memcpy(mailbox_guid, rec->guid, GUID_128_SIZE); } } From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: director: Fix to handling duplicate USER-WEAK event. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/7be9411da17b changeset: 14671:7be9411da17b user: Timo Sirainen date: Sun Jun 24 03:19:17 2012 +0300 description: director: Fix to handling duplicate USER-WEAK event. diffstat: src/director/director-connection.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r bb1de2a1d866 -r 7be9411da17b src/director/director-connection.c --- a/src/director/director-connection.c Sun Jun 24 03:02:11 2012 +0300 +++ b/src/director/director-connection.c Sun Jun 24 03:19:17 2012 +0300 @@ -711,7 +711,7 @@ bool weak = TRUE; int ret; - if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) < 0) + if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0) return FALSE; if (str_array_length(args) != 2 || From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: Make static analyzer happier. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/c257b9c19915 changeset: 14673:c257b9c19915 user: Timo Sirainen date: Sun Jun 24 20:52:39 2012 +0300 description: Make static analyzer happier. diffstat: src/auth/auth-request.c | 2 ++ src/auth/db-ldap.c | 1 + src/auth/password-scheme.c | 2 +- src/lib-index/mail-transaction-log-file.c | 7 +++++-- src/lib-index/mail-transaction-log.c | 1 + src/lib-storage/index/mbox/mbox-mail.c | 4 ++-- src/lib-storage/index/mbox/mbox-save.c | 1 + src/plugins/fts-squat/squat-uidlist.c | 2 ++ 8 files changed, 15 insertions(+), 5 deletions(-) diffs (122 lines): diff -r cc6d2b34965d -r c257b9c19915 src/auth/auth-request.c --- a/src/auth/auth-request.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/auth-request.c Sun Jun 24 20:52:39 2012 +0300 @@ -1250,6 +1250,8 @@ i_assert(*name != '\0'); i_assert(value != NULL); + i_assert(request->passdb != NULL); + if (strcmp(name, "password") == 0) { auth_request_set_password(request, value, default_scheme, FALSE); diff -r cc6d2b34965d -r c257b9c19915 src/auth/db-ldap.c --- a/src/auth/db-ldap.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/db-ldap.c Sun Jun 24 20:52:39 2012 +0300 @@ -866,6 +866,7 @@ ret = ldap_start_tls_s(conn->ld, NULL, NULL); if (ret != LDAP_SUCCESS) { if (ret == LDAP_OPERATIONS_ERROR && + conn->set.uris != NULL && strncmp(conn->set.uris, "ldaps:", 6) == 0) { i_fatal("LDAP: Don't use both tls=yes " "and ldaps URI"); diff -r cc6d2b34965d -r c257b9c19915 src/auth/password-scheme.c --- a/src/auth/password-scheme.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/auth/password-scheme.c Sun Jun 24 20:52:39 2012 +0300 @@ -367,7 +367,7 @@ str = password_generate_md5_crypt(plaintext, password); return strcmp(str, password) == 0 ? 1 : 0; } else if (password_decode(password, "PLAIN-MD5", - &md5_password, &md5_size, &error) < 0) { + &md5_password, &md5_size, &error) <= 0) { *error_r = "Not a valid MD5-CRYPT or PLAIN-MD5 password"; return -1; } else { diff -r cc6d2b34965d -r c257b9c19915 src/lib-index/mail-transaction-log-file.c --- a/src/lib-index/mail-transaction-log-file.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-index/mail-transaction-log-file.c Sun Jun 24 20:52:39 2012 +0300 @@ -1673,6 +1673,7 @@ file->filepath); return 0; } + i_assert(file->buffer != NULL); return log_file_map_check_offsets(file, start_offset, end_offset); } @@ -1695,9 +1696,11 @@ i_assert(file->buffer == NULL || file->mmap_base != NULL || file->sync_offset >= file->buffer_offset + file->buffer->used); + if (ret <= 0) + return ret; - return ret <= 0 ? ret : - log_file_map_check_offsets(file, start_offset, end_offset); + i_assert(file->buffer != NULL); + return log_file_map_check_offsets(file, start_offset, end_offset); } void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file diff -r cc6d2b34965d -r c257b9c19915 src/lib-index/mail-transaction-log.c --- a/src/lib-index/mail-transaction-log.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-index/mail-transaction-log.c Sun Jun 24 20:52:39 2012 +0300 @@ -463,6 +463,7 @@ /* try again */ } + i_assert(ret < 0 || log->head != NULL); return ret; } diff -r cc6d2b34965d -r c257b9c19915 src/lib-storage/index/mbox/mbox-mail.c --- a/src/lib-storage/index/mbox/mbox-mail.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-storage/index/mbox/mbox-mail.c Sun Jun 24 20:52:39 2012 +0300 @@ -240,6 +240,8 @@ int trailer_size; int ret = 1; + *next_offset_r = (uoff_t)-1; + hdr = mail_index_get_header(mail->mail.mail.transaction->view); if (mail->mail.mail.seq > hdr->messages_count) { /* we're appending a new message */ @@ -341,8 +343,6 @@ mail->mail.mail.uid); } } - if (ret <= 0) - next_offset = (uoff_t)-1; raw_stream = mbox->mbox_stream; hdr_offset = istream_raw_mbox_get_header_offset(raw_stream); diff -r cc6d2b34965d -r c257b9c19915 src/lib-storage/index/mbox/mbox-save.c --- a/src/lib-storage/index/mbox/mbox-save.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/lib-storage/index/mbox/mbox-save.c Sun Jun 24 20:52:39 2012 +0300 @@ -666,6 +666,7 @@ ctx->finished = TRUE; if (!ctx->failed) { + i_assert(ctx->output != NULL); T_BEGIN { if (mbox_write_content_length(ctx) < 0 || mbox_append_lf(ctx) < 0) diff -r cc6d2b34965d -r c257b9c19915 src/plugins/fts-squat/squat-uidlist.c --- a/src/plugins/fts-squat/squat-uidlist.c Sun Jun 24 19:44:22 2012 +0300 +++ b/src/plugins/fts-squat/squat-uidlist.c Sun Jun 24 20:52:39 2012 +0300 @@ -1416,6 +1416,7 @@ squat_uidlist_set_corrupted(uidlist, "uidlist not found"); return -1; } + i_assert(uidlist->cur_block_end_indexes != NULL); if (unlikely(idx > 0 && uidlist->cur_block_end_indexes[idx-1] > uid_list_idx)) { squat_uidlist_set_corrupted(uidlist, "broken block list"); @@ -1430,6 +1431,7 @@ return -1; /* find the uidlist inside the block */ + i_assert(uidlist->cur_block_offsets != NULL); p = CONST_PTR_OFFSET(uidlist->data, uidlist->cur_block_offsets[idx]); end = CONST_PTR_OFFSET(uidlist->data, uidlist->data_size); From dovecot at dovecot.org Sun Jun 24 20:57:39 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:39 +0300 Subject: dovecot-2.2: dict file: Don't ignore write failures. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/cc6d2b34965d changeset: 14672:cc6d2b34965d user: Timo Sirainen date: Sun Jun 24 19:44:22 2012 +0300 description: dict file: Don't ignore write failures. diffstat: src/lib-dict/dict-file.c | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diffs (37 lines): diff -r 7be9411da17b -r cc6d2b34965d src/lib-dict/dict-file.c --- a/src/lib-dict/dict-file.c Sun Jun 24 03:19:17 2012 +0300 +++ b/src/lib-dict/dict-file.c Sun Jun 24 19:44:22 2012 +0300 @@ -492,7 +492,7 @@ /* refresh once more now that we're locked */ if (file_dict_refresh(dict) < 0) { if (dotlock != NULL) - file_dotlock_delete(&dotlock); + (void)file_dotlock_delete(&dotlock); else { (void)close(fd); file_unlock(&lock); @@ -512,12 +512,20 @@ o_stream_cork(output); iter = hash_table_iterate_init(dict->hash); while (hash_table_iterate(iter, &key, &value)) { - o_stream_send_str(output, key); - o_stream_send(output, "\n", 1); - o_stream_send_str(output, value); - o_stream_send(output, "\n", 1); + (void)o_stream_send_str(output, key); + (void)o_stream_send(output, "\n", 1); + (void)o_stream_send_str(output, value); + (void)o_stream_send(output, "\n", 1); } + o_stream_uncork(output); hash_table_iterate_deinit(&iter); + + if (output->stream_errno != 0) { + i_error("write(%s) failed: %m", temp_path); + o_stream_destroy(&output); + (void)close(fd); + return -1; + } o_stream_destroy(&output); if (dotlock != NULL) { From dovecot at dovecot.org Sun Jun 24 20:57:40 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:57:40 +0300 Subject: dovecot-2.2: Merged changes from v2.1 tree. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/efd276ab2577 changeset: 14674:efd276ab2577 user: Timo Sirainen date: Sun Jun 24 20:57:06 2012 +0300 description: Merged changes from v2.1 tree. diffstat: .hgsigs | 1 + .hgtags | 1 + NEWS | 19 ++++ doc/example-config/conf.d/20-imap.conf | 2 +- src/auth/auth-request.c | 2 + src/auth/db-ldap.c | 1 + src/auth/password-scheme.c | 2 +- src/director/director-connection.c | 2 +- src/director/director.c | 5 + src/director/mail-host.c | 2 +- src/doveadm/doveadm-instance.c | 38 ++++++++- src/doveadm/doveadm-log.c | 34 ++++++-- src/doveadm/doveadm-print.c | 17 +++- src/doveadm/doveadm.c | 4 +- src/imap/cmd-delete.c | 16 +++- src/lib-charset/charset-iconv.c | 58 ++++++-------- src/lib-dict/dict-file.c | 18 +++- src/lib-index/mail-transaction-log-file.c | 7 +- src/lib-index/mail-transaction-log.c | 1 + src/lib-master/master-instance.c | 62 ++++++++++++++- src/lib-master/master-instance.h | 1 + src/lib-master/master-service.c | 1 - src/lib-ssl-iostream/iostream-openssl.c | 19 +++- src/lib-ssl-iostream/istream-openssl.c | 2 + src/lib-ssl-iostream/ostream-openssl.c | 3 +- src/lib-storage/index/dbox-multi/mdbox-map-private.h | 1 + src/lib-storage/index/dbox-multi/mdbox-map.c | 23 +++++- src/lib-storage/index/dbox-multi/mdbox-map.h | 2 + src/lib-storage/index/dbox-multi/mdbox-save.c | 6 + src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c | 3 +- src/lib-storage/index/imapc/imapc-mailbox.c | 4 +- src/lib-storage/index/imapc/imapc-storage.c | 15 +++- src/lib-storage/index/mbox/mbox-mail.c | 4 +- src/lib-storage/index/mbox/mbox-save.c | 1 + src/lib-storage/index/shared/shared-list.c | 8 +- src/lib-storage/mail-search-register-imap.c | 2 + src/lib/primes.c | 2 +- src/lib/restrict-access.c | 2 +- src/lib/utc-mktime.c | 2 +- src/master/service-monitor.c | 18 +++- src/plugins/fts-squat/fts-backend-squat.c | 5 +- src/plugins/fts-squat/squat-uidlist.c | 2 + src/plugins/quota/quota-maildir.c | 23 ++++- src/plugins/quota/quota.c | 2 +- 44 files changed, 337 insertions(+), 106 deletions(-) diffs (truncated from 1250 to 300 lines): diff -r a77ad2346cf0 -r efd276ab2577 .hgsigs --- a/.hgsigs Sun Jun 24 20:48:38 2012 +0300 +++ b/.hgsigs Sun Jun 24 20:57:06 2012 +0300 @@ -46,3 +46,4 @@ 2c21c940e19d97a772128a7f281cea302e157d73 0 iEYEABECAAYFAk+CtkYACgkQyUhSUUBVisknxgCfTJw2YPGJ17HbHRGmbwmCyLqepbMAn17j7IYzUfEU0xkXhCgwEAmk7XO4 469cee314d9c54d2d7101ec9e38579fdc9610eaf 0 iEYEABECAAYFAk+VWqkACgkQyUhSUUBVislnXACfVjPqMmPUvYtXQXwqff0h7N76mZUAn02lPeUCyuyr1TF9e1hGM/sKgmko 7c249e2a82a9cd33ae15ead6443c3499e16da623 0 iEYEABECAAYFAk+nX2sACgkQyUhSUUBVisn7uwCbBD3boxBOGEJ8OYsIJ57n5Cr09FAAoIvhxL6EHRB15AMOw4sPaALJ3/bB +c92fb8b928f69ca01681a2c2976304b7e4bc3afc 0 iEYEABECAAYFAk/FIeIACgkQyUhSUUBVisk4IgCfUiXVXntqzPjJcALYRpqw4Zc7a/0An3HKWwgb6PBCbmvxBfTezNkqjqVK diff -r a77ad2346cf0 -r efd276ab2577 .hgtags --- a/.hgtags Sun Jun 24 20:48:38 2012 +0300 +++ b/.hgtags Sun Jun 24 20:57:06 2012 +0300 @@ -83,3 +83,4 @@ 2c21c940e19d97a772128a7f281cea302e157d73 2.1.4 469cee314d9c54d2d7101ec9e38579fdc9610eaf 2.1.5 7c249e2a82a9cd33ae15ead6443c3499e16da623 2.1.6 +c92fb8b928f69ca01681a2c2976304b7e4bc3afc 2.1.7 diff -r a77ad2346cf0 -r efd276ab2577 NEWS --- a/NEWS Sun Jun 24 20:48:38 2012 +0300 +++ b/NEWS Sun Jun 24 20:57:06 2012 +0300 @@ -1,3 +1,22 @@ +v2.1.7 2012-05-29 Timo Sirainen + + * LDAP: Compatibility fix for v2.0: ldap: If attributes contain + ldapAttr=key=template%$ and ldapAttr doesn't exist, skip the key + instead of using "template" value with empty %$ part for the key. + + + pop3: Added pop3_uidl_duplicates setting for changing the behavior + for duplicate UIDLs. + + director: Added "doveadm director ring remove" command. + - director: Don't crash with quickly disconnecting incoming director + connections. + - mdbox: If mail was originally saved to non-INBOX, and namespace + prefix is non-empty, don't assert-crash when rebuilding indexes. + - sdbox: Don't use more fds than necessary when copying mails. + - auth: Fixed crash with DIGEST-MD5 when attempting to do master user + login without master passdbs. + - Several fixes to mail_shared_explicit_inbox=no + - imapc: Use imapc_list_prefix also for listing subscriptions. + v2.1.6 2012-05-07 Timo Sirainen * Session ID is now included by default in auth and login process diff -r a77ad2346cf0 -r efd276ab2577 doc/example-config/conf.d/20-imap.conf --- a/doc/example-config/conf.d/20-imap.conf Sun Jun 24 20:48:38 2012 +0300 +++ b/doc/example-config/conf.d/20-imap.conf Sun Jun 24 20:57:06 2012 +0300 @@ -18,7 +18,7 @@ # IMAP logout format string: # %i - total number of bytes read from client # %o - total number of bytes sent to client - #imap_logout_format = bytes=%i/%o + #imap_logout_format = in=%i out=%o # Override the IMAP CAPABILITY response. If the value begins with '+', # add the given capabilities on top of the defaults (e.g. +XFOO XBAR). diff -r a77ad2346cf0 -r efd276ab2577 src/auth/auth-request.c --- a/src/auth/auth-request.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/auth/auth-request.c Sun Jun 24 20:57:06 2012 +0300 @@ -1258,6 +1258,8 @@ i_assert(*name != '\0'); i_assert(value != NULL); + i_assert(request->passdb != NULL); + if (strcmp(name, "password") == 0) { auth_request_set_password(request, value, default_scheme, FALSE); diff -r a77ad2346cf0 -r efd276ab2577 src/auth/db-ldap.c --- a/src/auth/db-ldap.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/auth/db-ldap.c Sun Jun 24 20:57:06 2012 +0300 @@ -866,6 +866,7 @@ ret = ldap_start_tls_s(conn->ld, NULL, NULL); if (ret != LDAP_SUCCESS) { if (ret == LDAP_OPERATIONS_ERROR && + conn->set.uris != NULL && strncmp(conn->set.uris, "ldaps:", 6) == 0) { i_fatal("LDAP: Don't use both tls=yes " "and ldaps URI"); diff -r a77ad2346cf0 -r efd276ab2577 src/auth/password-scheme.c --- a/src/auth/password-scheme.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/auth/password-scheme.c Sun Jun 24 20:57:06 2012 +0300 @@ -367,7 +367,7 @@ str = password_generate_md5_crypt(plaintext, password); return strcmp(str, password) == 0 ? 1 : 0; } else if (password_decode(password, "PLAIN-MD5", - &md5_password, &md5_size, &error) < 0) { + &md5_password, &md5_size, &error) <= 0) { *error_r = "Not a valid MD5-CRYPT or PLAIN-MD5 password"; return -1; } else { diff -r a77ad2346cf0 -r efd276ab2577 src/director/director-connection.c --- a/src/director/director-connection.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/director/director-connection.c Sun Jun 24 20:57:06 2012 +0300 @@ -711,7 +711,7 @@ bool weak = TRUE; int ret; - if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) < 0) + if ((ret = director_cmd_is_seen(conn, &args, &dir_host)) != 0) return FALSE; if (str_array_length(args) != 2 || diff -r a77ad2346cf0 -r efd276ab2577 src/director/director.c --- a/src/director/director.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/director/director.c Sun Jun 24 20:57:06 2012 +0300 @@ -363,6 +363,11 @@ { /* we're synced again when we receive this SYNC back */ dir->sync_seq++; + if (dir->right == NULL && dir->left == NULL) { + /* we're alone. if we're already synced, + don't become unsynced. */ + return; + } director_set_ring_unsynced(dir); if (dir->sync_frozen) { diff -r a77ad2346cf0 -r efd276ab2577 src/director/mail-host.c --- a/src/director/mail-host.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/director/mail-host.c Sun Jun 24 20:57:06 2012 +0300 @@ -110,7 +110,7 @@ i2 = htonl(ip2_arr[i]); for (j = last_bits; j < 32; j++) { - if ((i1 & (1 << j)) != (i2 & (1 << j))) { + if ((i1 & (1U << j)) != (i2 & (1U << j))) { i_error("IP address range too large: %s-%s", net_ip2addr(&ip1), net_ip2addr(&ip2)); return -1; diff -r a77ad2346cf0 -r efd276ab2577 src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Sun Jun 24 20:57:06 2012 +0300 @@ -5,6 +5,7 @@ #include "doveadm.h" #include "doveadm-print.h" +#include #include #include #include @@ -42,22 +43,45 @@ return found; } -static void cmd_instance_list(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_instance_list(int argc, char *argv[]) { struct master_instance_list *list; struct master_instance_list_iter *iter; const struct master_instance *inst; const char *pidfile_path; + bool show_config = FALSE; + int c; - doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); - doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); - doveadm_print_header_simple("name"); - doveadm_print_header_simple("last used"); - doveadm_print_header_simple("running"); + while ((c = getopt(argc, argv, "c")) > 0) { + switch (c) { + case 'c': + show_config = TRUE; + break; + default: + help(&doveadm_cmd_instance[0]); + } + } + argv += optind; + + if (!show_config) { + doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); + doveadm_print_header("path", "path", DOVEADM_PRINT_HEADER_FLAG_EXPAND); + doveadm_print_header_simple("name"); + doveadm_print_header_simple("last used"); + doveadm_print_header_simple("running"); + } list = master_instance_list_init(MASTER_INSTANCE_PATH); iter = master_instance_list_iterate_init(list); while ((inst = master_instance_iterate_list_next(iter)) != NULL) { + if (argv[0] != NULL && strcmp(argv[0], inst->name) != 0) + continue; + + if (show_config) { + printf("%s\n", inst->config_path == NULL ? "" : + inst->config_path); + continue; + } doveadm_print(inst->base_dir); doveadm_print(inst->name); doveadm_print(unixdate2str(inst->last_used)); @@ -95,7 +119,7 @@ } struct doveadm_cmd doveadm_cmd_instance[] = { - { cmd_instance_list, "instance list", "" }, + { cmd_instance_list, "instance list", "[-c] []" }, { cmd_instance_remove, "instance remove", " | " } }; diff -r a77ad2346cf0 -r efd276ab2577 src/doveadm/doveadm-log.c --- a/src/doveadm/doveadm-log.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/doveadm/doveadm-log.c Sun Jun 24 20:57:06 2012 +0300 @@ -23,6 +23,8 @@ #define LOG_ERRORS_FNAME "log-errors" #define LOG_TIMESTAMP_FORMAT "%b %d %H:%M:%S" +extern struct doveadm_cmd doveadm_cmd_log[]; + static void ATTR_NULL(2) cmd_log_test(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) { @@ -279,7 +281,7 @@ } } -static void cmd_log_error_write(const char *const *args) +static void cmd_log_error_write(const char *const *args, time_t min_timestamp) { /* */ const char *type_prefix = "?"; @@ -298,16 +300,32 @@ i_error("Invalid timestamp: %s", args[1]); t = 0; } - - printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), - args[2], type_prefix, args[3]); + if (t >= min_timestamp) { + printf("%s %s%s%s\n", t_strflocaltime(LOG_TIMESTAMP_FORMAT, t), + args[2], type_prefix, args[3]); + } } -static void cmd_log_errors(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED) +static void cmd_log_errors(int argc, char *argv[]) { struct istream *input; const char *path, *line, *const *args; - int fd; + time_t min_timestamp = 0; + int c, fd; + + while ((c = getopt(argc, argv, "s:")) > 0) { + switch (c) { + case 's': + if (str_to_time(optarg, &min_timestamp) < 0) + i_fatal("Invalid timestamp: %s", optarg); + break; + default: + help(&doveadm_cmd_log[3]); + } + } + argv += optind - 1; + if (argv[1] != NULL) + help(&doveadm_cmd_log[3]); path = t_strconcat(doveadm_settings->base_dir, "/"LOG_ERRORS_FNAME, NULL); @@ -320,7 +338,7 @@ while ((line = i_stream_read_next_line(input)) != NULL) T_BEGIN { args = t_strsplit_tabescaped(line); if (str_array_length(args) == 4) - cmd_log_error_write(args); + cmd_log_error_write(args, min_timestamp); else { i_error("Invalid input from log: %s", line); doveadm_exit_code = EX_PROTOCOL; @@ -333,7 +351,7 @@ { cmd_log_test, "log test", "" }, { cmd_log_reopen, "log reopen", "" }, { cmd_log_find, "log find", "[]" }, - { cmd_log_errors, "log errors", "" } + { cmd_log_errors, "log errors", "[-s ]" } }; void doveadm_register_log_commands(void) diff -r a77ad2346cf0 -r efd276ab2577 src/doveadm/doveadm-print.c --- a/src/doveadm/doveadm-print.c Sun Jun 24 20:48:38 2012 +0300 +++ b/src/doveadm/doveadm-print.c Sun Jun 24 20:57:06 2012 +0300 @@ -18,6 +18,7 @@ const struct doveadm_print_vfuncs *v; unsigned int header_idx; + bool print_stream_open; }; static struct doveadm_print_context *ctx; @@ -52,7 +53,7 @@ doveadm_print_header(key_title, key_title, 0); } -void doveadm_print(const char *value) +static void doveadm_print_sticky_headers(void) { const struct doveadm_print_header_context *headers; unsigned int count; @@ -68,7 +69,13 @@ break; } From dovecot at dovecot.org Sun Jun 24 20:58:15 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 20:58:15 +0300 Subject: dovecot-2.2: Make static analyzer happier. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/f07ba5e7d97d changeset: 14675:f07ba5e7d97d user: Timo Sirainen date: Sun Jun 24 20:58:04 2012 +0300 description: Make static analyzer happier. diffstat: src/doveadm/dsync/dsync-mailbox-import.c | 4 ++++ src/lib-index/mail-transaction-log-view.c | 2 ++ 2 files changed, 6 insertions(+), 0 deletions(-) diffs (40 lines): diff -r efd276ab2577 -r f07ba5e7d97d src/doveadm/dsync/dsync-mailbox-import.c --- a/src/doveadm/dsync/dsync-mailbox-import.c Sun Jun 24 20:57:06 2012 +0300 +++ b/src/doveadm/dsync/dsync-mailbox-import.c Sun Jun 24 20:58:04 2012 +0300 @@ -331,6 +331,7 @@ diff = importer_mail_cmp(&m1, &m2); if (diff < 0) { /* add a record for local mail */ + i_assert(importer->cur_mail != NULL); newmail->guid = p_strdup(importer->pool, importer->cur_guid); newmail->uid = importer->cur_mail->uid; newmail->uid_in_local = TRUE; @@ -338,6 +339,7 @@ newmail->uid >= importer->remote_uid_next; remote_saved = FALSE; } else if (diff > 0) { + i_assert(save_change != NULL); newmail->guid = save_change->guid; newmail->uid = save_change->uid; newmail->uid_in_local = FALSE; @@ -346,6 +348,8 @@ remote_saved = TRUE; } else { /* identical */ + i_assert(importer->cur_mail != NULL); + i_assert(save_change != NULL); newmail->guid = save_change->guid; newmail->uid = importer->cur_mail->uid; newmail->uid_in_local = TRUE; diff -r efd276ab2577 -r f07ba5e7d97d src/lib-index/mail-transaction-log-view.c --- a/src/lib-index/mail-transaction-log-view.c Sun Jun 24 20:57:06 2012 +0300 +++ b/src/lib-index/mail-transaction-log-view.c Sun Jun 24 20:58:04 2012 +0300 @@ -284,6 +284,8 @@ { struct mail_transaction_log_file *file, *first = view->log->files; + i_assert(first != NULL); + /* make sure .log.2 file is opened */ (void)mail_transaction_log_find_file(view->log, 1, FALSE, &file); From dovecot at dovecot.org Sun Jun 24 21:15:09 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:15:09 +0300 Subject: dovecot-2.2: seq_range_array_add() API changed. Added other func... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/69ba6977bed8 changeset: 14676:69ba6977bed8 user: Timo Sirainen date: Sun Jun 24 21:14:56 2012 +0300 description: seq_range_array_add() API changed. Added other functions to provide the less common use cases. diffstat: src/doveadm/dsync/dsync-mailbox-export.c | 14 +++++----- src/doveadm/dsync/dsync-mailbox-import.c | 5 +-- src/imap/cmd-store.c | 3 +- src/imap/imap-search.c | 2 +- src/lib-index/mail-index-sync-update.c | 2 +- src/lib-index/mail-index-transaction-finish.c | 4 +- src/lib-index/mail-index-transaction-sort-appends.c | 2 +- src/lib-index/mail-index-transaction-update.c | 8 ++++-- src/lib-index/mail-index-view-sync.c | 8 +++--- src/lib-storage/index/dbox-multi/mdbox-map.c | 6 ++-- src/lib-storage/index/dbox-multi/mdbox-purge.c | 8 +++--- src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c | 2 +- src/lib-storage/index/dbox-multi/mdbox-sync.c | 2 +- src/lib-storage/index/imapc/imapc-save.c | 4 +- src/lib-storage/index/index-search.c | 6 ++-- src/lib-storage/index/index-sync-search.c | 2 +- src/lib-storage/index/index-sync.c | 2 +- src/lib-storage/mail-search.c | 2 +- src/lib-storage/mailbox-get.c | 4 +- src/lib-storage/mailbox-search-result.c | 8 +++--- src/lib/seq-range-array.c | 19 +++++++++++---- src/lib/seq-range-array.h | 12 +++++++-- src/lib/test-seq-range-array.c | 12 +++++----- src/plugins/fts-lucene/lucene-wrapper.cc | 4 +- src/plugins/fts-solr/solr-connection.c | 2 +- src/plugins/fts-squat/squat-trie.c | 2 +- src/plugins/fts-squat/squat-uidlist.c | 2 +- src/plugins/fts/fts-api.c | 2 +- src/plugins/fts/fts-expunge-log.c | 2 +- src/plugins/fts/fts-search.c | 2 +- src/plugins/virtual/virtual-search.c | 4 +- src/plugins/virtual/virtual-storage.c | 2 +- src/plugins/virtual/virtual-sync.c | 16 ++++++------ 33 files changed, 95 insertions(+), 80 deletions(-) diffs (truncated from 758 to 300 lines): diff -r f07ba5e7d97d -r 69ba6977bed8 src/doveadm/dsync/dsync-mailbox-export.c --- a/src/doveadm/dsync/dsync-mailbox-export.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/doveadm/dsync/dsync-mailbox-export.c Sun Jun 24 21:14:56 2012 +0300 @@ -212,7 +212,7 @@ if (exporter->auto_export_mails && !exporter->mails_have_guids) { /* GUIDs not supported, mail is requested by UIDs */ - seq_range_array_add(&exporter->requested_uids, 0, change->uid); + seq_range_array_add(&exporter->requested_uids, change->uid); return; } if (*change->guid == '\0') { @@ -232,7 +232,7 @@ if (exporter->auto_export_mails) instances->requested = TRUE; } - seq_range_array_add(&instances->seqs, 0, seq); + seq_range_array_add(&instances->seqs, seq); } static int @@ -273,7 +273,7 @@ const struct dsync_mail_change *change = value; if (change->type == DSYNC_MAIL_CHANGE_TYPE_FLAG_CHANGE) - seq_range_array_add(uids, 0, change->uid); + seq_range_array_add(uids, change->uid); } hash_table_iterate_deinit(&iter); } @@ -494,7 +494,7 @@ seq = uids[0].seq1; if (!instances->searched) { instances->searched = TRUE; - seq_range_array_add(&sarg->value.seqset, 0, seq); + seq_range_array_add(&sarg->value.seqset, seq); } else if (seq_range_exists(&exporter->expunged_seqs, seq)) { /* we're on a second round, refetching expunged messages */ @@ -508,7 +508,7 @@ } uids = array_idx(&instances->seqs, 0); seq = uids[0].seq1; - seq_range_array_add(&sarg->value.seqset, 0, seq); + seq_range_array_add(&sarg->value.seqset, seq); } } hash_table_iterate_deinit(&iter); @@ -608,7 +608,7 @@ if (*request->guid == '\0') { i_assert(request->uid > 0); - seq_range_array_add(&exporter->requested_uids, 0, request->uid); + seq_range_array_add(&exporter->requested_uids, request->uid); return; } @@ -648,7 +648,7 @@ } /* the message was expunged. if the GUID has another instance, try sending it later. */ - seq_range_array_add(&exporter->expunged_seqs, 0, mail->seq); + seq_range_array_add(&exporter->expunged_seqs, mail->seq); } /* if some instances of messages were expunged, retry fetching them with other instances */ diff -r f07ba5e7d97d -r 69ba6977bed8 src/doveadm/dsync/dsync-mailbox-import.c --- a/src/doveadm/dsync/dsync-mailbox-import.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/doveadm/dsync/dsync-mailbox-import.c Sun Jun 24 21:14:56 2012 +0300 @@ -199,7 +199,7 @@ /* this message exists locally, but remote didn't send expunge-change for it. if the message's uid <= last-common-uid, it should be deleted */ - seq_range_array_add(&importer->maybe_expunge_uids, 0, + seq_range_array_add(&importer->maybe_expunge_uids, importer->cur_mail->uid); } @@ -751,8 +751,7 @@ /* we don't know yet if we should expunge this message or not. queue it until we do. */ i_assert(change->uid > importer->last_common_uid); - seq_range_array_add(&importer->maybe_expunge_uids, 0, - change->uid); + seq_range_array_add(&importer->maybe_expunge_uids, change->uid); } } diff -r f07ba5e7d97d -r 69ba6977bed8 src/imap/cmd-store.c --- a/src/imap/cmd-store.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/imap/cmd-store.c Sun Jun 24 21:14:56 2012 +0300 @@ -189,8 +189,7 @@ /* check early so there's less work for transaction commit if something has to be cancelled */ if (mail_get_modseq(mail) > ctx.max_modseq) { - seq_range_array_add(&modified_set, 0, - mail->seq); + seq_range_array_add(&modified_set, mail->seq); continue; } } diff -r f07ba5e7d97d -r 69ba6977bed8 src/imap/imap-search.c --- a/src/imap/imap-search.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/imap/imap-search.c Sun Jun 24 21:14:56 2012 +0300 @@ -334,7 +334,7 @@ } if ((ctx->return_options & SEARCH_RETURN_SAVE) != 0) { seq_range_array_add(&ctx->cmd->client->search_saved_uidset, - 0, mail->uid); + mail->uid); } if ((ctx->return_options & SEARCH_RETURN_RELEVANCY) != 0) { const char *str; diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-index/mail-index-sync-update.c --- a/src/lib-index/mail-index-sync-update.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-index/mail-index-sync-update.c Sun Jun 24 21:14:56 2012 +0300 @@ -545,7 +545,7 @@ rec->uid); break; } - seq_range_array_add(&uids, 0, rec->uid); + seq_range_array_add(&uids, rec->uid); } /* do this in reverse so the memmove()s are smaller */ diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-index/mail-index-transaction-finish.c --- a/src/lib-index/mail-index-transaction-finish.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-index/mail-index-transaction-finish.c Sun Jun 24 21:14:56 2012 +0300 @@ -129,7 +129,7 @@ if ((rec->flags & u->add_flags) != u->add_flags || (rec->flags & u->remove_flags) != 0) { /* keep this change */ - seq_range_array_add(&keeps, 0, seq); + seq_range_array_add(&keeps, seq); } } i = mail_transaction_drop_range(t, updates[i], i, &keeps); @@ -163,7 +163,7 @@ ret1 = mail_index_cancel_flag_updates(t, seq); ret2 = mail_index_cancel_keyword_updates(t, seq); if (ret1 || ret2) - seq_range_array_add(t->conflict_seqs, 0, seq); + seq_range_array_add(t->conflict_seqs, seq); } } mail_index_transaction_set_log_updates(t); diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-index/mail-index-transaction-sort-appends.c --- a/src/lib-index/mail-index-transaction-sort-appends.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-index/mail-index-transaction-sort-appends.c Sun Jun 24 21:14:56 2012 +0300 @@ -95,7 +95,7 @@ idx1 = range[i].seq1 - first_new_seq; idx2 = range[i].seq2 - first_new_seq; for (idx = idx1; idx <= idx2; idx++) - seq_range_array_add(array, 0, old_to_newseq_map[idx]); + seq_range_array_add(array, old_to_newseq_map[idx]); } array_free(&old_seqs); } diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-index/mail-index-transaction-update.c --- a/src/lib-index/mail-index-transaction-update.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-index/mail-index-transaction-update.c Sun Jun 24 21:14:56 2012 +0300 @@ -1089,15 +1089,17 @@ seq_range_array_remove(&u->add_seq, seq); /* Don't bother updating remove_seq for new messages, since their initial state is "no keyword" anyway */ - if (seq < t->first_new_seq) - seq_range_array_add(&u->remove_seq, 16, seq); + if (seq < t->first_new_seq) { + seq_range_array_add_with_init(&u->remove_seq, + 16, seq); + } } } if (add_keywords != NULL) { for (i = 0; i < add_keywords->count; i++) { u = array_idx_modifiable(&t->keyword_updates, add_keywords->idx[i]); - seq_range_array_add(&u->add_seq, 16, seq); + seq_range_array_add_with_init(&u->add_seq, 16, seq); seq_range_array_remove(&u->remove_seq, seq); } } diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-index/mail-index-view-sync.c --- a/src/lib-index/mail-index-view-sync.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-index/mail-index-view-sync.c Sun Jun 24 21:14:56 2012 +0300 @@ -145,7 +145,7 @@ src_count = src_size / sizeof(*src); for (i = 0; i < src_count; i++) - seq_range_array_add(dest, 0, src[i].uid); + seq_range_array_add(dest, src[i].uid); } static int @@ -394,7 +394,7 @@ be avoided by always keeping a private copy of the map in the view, but that's a waste of memory for as rare of a problem as this. */ if (changed) - seq_range_array_add(&ctx->lost_flags, 0, new_rec->uid); + seq_range_array_add(&ctx->lost_flags, new_rec->uid); return 0; } @@ -437,7 +437,7 @@ i++; j++; } else if (old_rec->uid < new_rec->uid) { /* message expunged */ - seq_range_array_add(&ctx->expunges, 0, old_rec->uid); + seq_range_array_add(&ctx->expunges, old_rec->uid); i++; } else { /* new message appeared out of nowhere */ @@ -451,7 +451,7 @@ /* if there are old messages left, they're all expunged */ for (; i < old_count; i++) { old_rec = MAIL_INDEX_MAP_IDX(old_map, i); - seq_range_array_add(&ctx->expunges, 0, old_rec->uid); + seq_range_array_add(&ctx->expunges, old_rec->uid); } /* if there are new messages left, they're all new messages */ thdr.type = MAIL_TRANSACTION_APPEND | MAIL_TRANSACTION_EXTERNAL; diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-storage/index/dbox-multi/mdbox-map.c --- a/src/lib-storage/index/dbox-multi/mdbox-map.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c Sun Jun 24 21:14:56 2012 +0300 @@ -444,7 +444,7 @@ &data, &expunged); if (data != NULL && !expunged) { rec = data; - seq_range_array_add(file_ids_r, 0, rec->file_id); + seq_range_array_add(file_ids_r, rec->file_id); } } return 0; @@ -971,7 +971,7 @@ &file_id) < 0) continue; - seq_range_array_add(file_ids_r, 0, file_id); + seq_range_array_add(file_ids_r, file_id); } if (errno != 0) { mail_storage_set_critical(storage, @@ -1023,7 +1023,7 @@ if (seq_range_exists(&checked_file_ids, rec->file_id)) continue; - seq_range_array_add(&checked_file_ids, 0, rec->file_id); + seq_range_array_add(&checked_file_ids, rec->file_id); if (++backwards_lookup_count > MAX_BACKWARDS_LOOKUPS) { /* we've wasted enough time here */ diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-storage/index/dbox-multi/mdbox-purge.c --- a/src/lib-storage/index/dbox-multi/mdbox-purge.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c Sun Jun 24 21:14:56 2012 +0300 @@ -369,7 +369,7 @@ &ext_refs); if (ret <= 0) break; - seq_range_array_add(&expunged_map_uids, 0, + seq_range_array_add(&expunged_map_uids, msgs[i].map_uid); } else { /* non-expunged message. write it to output file. */ @@ -534,7 +534,7 @@ str_truncate(path, dir_len); str_append(path, d->d_name); - seq_range_array_add(&ctx->primary_file_ids, 0, file_id); + seq_range_array_add(&ctx->primary_file_ids, file_id); } if (array_count(&ctx->primary_file_ids) > 0) { const struct seq_range *range = @@ -602,7 +602,7 @@ hash_table_insert(ctx->altmoves, POINTER_CAST(cur_map_uid), POINTER_CAST(MDBOX_MSG_ACTION_MOVE_TO_ALT)); - seq_range_array_add(&ctx->purge_file_ids, 0, + seq_range_array_add(&ctx->purge_file_ids, cur_rec.file_id); } } @@ -634,7 +634,7 @@ hash_table_insert(ctx->altmoves, POINTER_CAST(cur_map_uid), POINTER_CAST(MDBOX_MSG_ACTION_MOVE_FROM_ALT)); - seq_range_array_add(&ctx->purge_file_ids, 0, cur_rec.file_id); + seq_range_array_add(&ctx->purge_file_ids, cur_rec.file_id); } ctx->have_altmoves = hash_table_count(ctx->altmoves) > 0; return ret; diff -r f07ba5e7d97d -r 69ba6977bed8 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Sun Jun 24 20:58:04 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c Sun Jun 24 21:14:56 2012 +0300 @@ -262,7 +262,7 @@ if (rebuild_rename_file(ctx, dir, &fname, &file_id) < 0) return -1; } - seq_range_array_add(&ctx->seen_file_ids, 0, file_id); + seq_range_array_add(&ctx->seen_file_ids, file_id); From dovecot at dovecot.org Sun Jun 24 21:19:41 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:19:41 +0300 Subject: dovecot-2.2: seq_range_array_remove() now returns void. Added se... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/737a49f472d1 changeset: 14677:737a49f472d1 user: Timo Sirainen date: Sun Jun 24 21:19:33 2012 +0300 description: seq_range_array_remove() now returns void. Added seq_ranger_array_try_remove(). diffstat: src/lib-index/mail-index-transaction-update.c | 2 +- src/lib-storage/index/index-sync.c | 2 +- src/lib-storage/mailbox-search-result.c | 2 +- src/lib/seq-range-array.c | 11 ++++++++--- src/lib/seq-range-array.h | 6 ++++-- src/lib/test-seq-range-array.c | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diffs (97 lines): diff -r 69ba6977bed8 -r 737a49f472d1 src/lib-index/mail-index-transaction-update.c --- a/src/lib-index/mail-index-transaction-update.c Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib-index/mail-index-transaction-update.c Sun Jun 24 21:19:33 2012 +0300 @@ -1149,7 +1149,7 @@ static bool mail_index_cancel_array(ARRAY_TYPE(seq_range) *array, uint32_t seq) { if (array_is_created(array)) { - if (seq_range_array_remove(array, seq)) { + if (seq_range_array_try_remove(array, seq)) { if (array_count(array) == 0) array_free(array); return TRUE; diff -r 69ba6977bed8 -r 737a49f472d1 src/lib-storage/index/index-sync.c --- a/src/lib-storage/index/index-sync.c Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib-storage/index/index-sync.c Sun Jun 24 21:19:33 2012 +0300 @@ -129,7 +129,7 @@ for (; seq1 <= seq2; seq1++) { mail_index_lookup_uid(box->view, seq1, &uid); - if (seq_range_array_remove(&ibox->recent_flags, uid)) + if (seq_range_array_try_remove(&ibox->recent_flags, uid)) ibox->recent_flags_count--; } } diff -r 69ba6977bed8 -r 737a49f472d1 src/lib-storage/mailbox-search-result.c --- a/src/lib-storage/mailbox-search-result.c Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib-storage/mailbox-search-result.c Sun Jun 24 21:19:33 2012 +0300 @@ -131,7 +131,7 @@ void mailbox_search_result_remove(struct mail_search_result *result, uint32_t uid) { - if (seq_range_array_remove(&result->uids, uid)) { + if (seq_range_array_try_remove(&result->uids, uid)) { if (array_is_created(&result->removed_uids)) { seq_range_array_add(&result->removed_uids, uid); seq_range_array_remove(&result->added_uids, uid); diff -r 69ba6977bed8 -r 737a49f472d1 src/lib/seq-range-array.c --- a/src/lib/seq-range-array.c Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib/seq-range-array.c Sun Jun 24 21:19:33 2012 +0300 @@ -166,7 +166,12 @@ seq_range_array_add_range(dest, range->seq1, range->seq2); } -bool seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) +void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) +{ + (void)seq_range_array_remove(array, seq); +} + +bool seq_range_array_try_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) { struct seq_range *data, value; unsigned int idx, left_idx, right_idx, count; @@ -249,13 +254,13 @@ FIXME: it would be faster if we did only one binary lookup here and handled the splitting ourself.. */ - if (seq_range_array_remove(array, seq1)) + if (seq_range_array_try_remove(array, seq1)) remove_count++; if (seq1 == seq2) return remove_count; seq1++; - if (seq_range_array_remove(array, seq2--)) + if (seq_range_array_try_remove(array, seq2--)) remove_count++; if (seq1 > seq2) return remove_count; diff -r 69ba6977bed8 -r 737a49f472d1 src/lib/seq-range-array.h --- a/src/lib/seq-range-array.h Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib/seq-range-array.h Sun Jun 24 21:19:33 2012 +0300 @@ -25,8 +25,10 @@ uint32_t seq1, uint32_t seq2); void seq_range_array_merge(ARRAY_TYPE(seq_range) *dest, const ARRAY_TYPE(seq_range) *src); -/* Remove given sequrence from range. Returns TRUE if it was found. */ -bool seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); +/* Remove the given sequrence from range. */ +void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); +/* Remove the given sequrence from range. Returns TRUE if it was found. */ +bool seq_range_array_try_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); /* Remove a sequence range. Returns number of sequences actually removed. */ unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array, uint32_t seq1, uint32_t seq2); diff -r 69ba6977bed8 -r 737a49f472d1 src/lib/test-seq-range-array.c --- a/src/lib/test-seq-range-array.c Sun Jun 24 21:14:56 2012 +0300 +++ b/src/lib/test-seq-range-array.c Sun Jun 24 21:19:33 2012 +0300 @@ -47,7 +47,7 @@ memset(shadowbuf + seq1, 1, seq2 - seq1 + 1); break; case 2: - ret = seq_range_array_remove(&range, seq1) ? 1 : 0; + ret = seq_range_array_try_remove(&range, seq1) ? 1 : 0; ret2 = shadowbuf[seq1] != 0 ? 1 : 0; shadowbuf[seq1] = 0; break; From dovecot at dovecot.org Sun Jun 24 21:30:07 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:30:07 +0300 Subject: dovecot-2.2: seq_range_array_add() API change triggered a crash ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/42d1459958ec changeset: 14678:42d1459958ec user: Timo Sirainen date: Sun Jun 24 21:29:56 2012 +0300 description: seq_range_array_add() API change triggered a crash in buggy code. diffstat: src/lib-index/mail-index-transaction-finish.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diffs (16 lines): diff -r 737a49f472d1 -r 42d1459958ec src/lib-index/mail-index-transaction-finish.c --- a/src/lib-index/mail-index-transaction-finish.c Sun Jun 24 21:19:33 2012 +0300 +++ b/src/lib-index/mail-index-transaction-finish.c Sun Jun 24 21:29:56 2012 +0300 @@ -162,8 +162,10 @@ if (mail_index_modseq_lookup(t->view, seq) > t->max_modseq) { ret1 = mail_index_cancel_flag_updates(t, seq); ret2 = mail_index_cancel_keyword_updates(t, seq); - if (ret1 || ret2) - seq_range_array_add(t->conflict_seqs, seq); + if (ret1 || ret2) { + seq_range_array_add_with_init(t->conflict_seqs, + 16, seq); + } } } mail_index_transaction_set_log_updates(t); From dovecot at dovecot.org Sun Jun 24 21:35:38 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:35:38 +0300 Subject: dovecot-2.1: lib-lda: Duplicate database write failures weren't ... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/4edce2f57264 changeset: 14576:4edce2f57264 user: Timo Sirainen date: Sun Jun 24 21:35:18 2012 +0300 description: lib-lda: Duplicate database write failures weren't detected. diffstat: src/lib-lda/duplicate.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diffs (38 lines): diff -r c257b9c19915 -r 4edce2f57264 src/lib-lda/duplicate.c --- a/src/lib-lda/duplicate.c Sun Jun 24 20:52:39 2012 +0300 +++ b/src/lib-lda/duplicate.c Sun Jun 24 21:35:18 2012 +0300 @@ -296,7 +296,8 @@ hdr.version = DUPLICATE_VERSION; output = o_stream_create_fd_file(file->new_fd, 0, FALSE); - o_stream_send(output, &hdr, sizeof(hdr)); + o_stream_cork(output); + (void)o_stream_send(output, &hdr, sizeof(hdr)); memset(&rec, 0, sizeof(rec)); iter = hash_table_iterate_init(file->hash); @@ -307,11 +308,21 @@ rec.id_size = d->id_size; rec.user_size = strlen(d->user); - o_stream_send(output, &rec, sizeof(rec)); - o_stream_send(output, d->id, rec.id_size); - o_stream_send(output, d->user, rec.user_size); + (void)o_stream_send(output, &rec, sizeof(rec)); + (void)o_stream_send(output, d->id, rec.id_size); + (void)o_stream_send(output, d->user, rec.user_size); } + o_stream_uncork(output); hash_table_iterate_deinit(&iter); + + if (output->last_failed_errno != 0) { + errno = output->last_failed_errno; + i_error("write(%s) failed: %m", file->path); + o_stream_unref(&output); + file_dotlock_delete(&file->dotlock); + file->new_fd = -1; + return; + } o_stream_unref(&output); file->changed = FALSE; From dovecot at dovecot.org Sun Jun 24 21:35:45 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:35:45 +0300 Subject: dovecot-2.2: lib-lda: Duplicate database write failures weren't ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/f783fdbc3861 changeset: 14679:f783fdbc3861 user: Timo Sirainen date: Sun Jun 24 21:35:18 2012 +0300 description: lib-lda: Duplicate database write failures weren't detected. diffstat: src/lib-lda/duplicate.c | 19 +++++++++++++++---- 1 files changed, 15 insertions(+), 4 deletions(-) diffs (38 lines): diff -r 42d1459958ec -r f783fdbc3861 src/lib-lda/duplicate.c --- a/src/lib-lda/duplicate.c Sun Jun 24 21:29:56 2012 +0300 +++ b/src/lib-lda/duplicate.c Sun Jun 24 21:35:18 2012 +0300 @@ -296,7 +296,8 @@ hdr.version = DUPLICATE_VERSION; output = o_stream_create_fd_file(file->new_fd, 0, FALSE); - o_stream_send(output, &hdr, sizeof(hdr)); + o_stream_cork(output); + (void)o_stream_send(output, &hdr, sizeof(hdr)); memset(&rec, 0, sizeof(rec)); iter = hash_table_iterate_init(file->hash); @@ -307,11 +308,21 @@ rec.id_size = d->id_size; rec.user_size = strlen(d->user); - o_stream_send(output, &rec, sizeof(rec)); - o_stream_send(output, d->id, rec.id_size); - o_stream_send(output, d->user, rec.user_size); + (void)o_stream_send(output, &rec, sizeof(rec)); + (void)o_stream_send(output, d->id, rec.id_size); + (void)o_stream_send(output, d->user, rec.user_size); } + o_stream_uncork(output); hash_table_iterate_deinit(&iter); + + if (output->last_failed_errno != 0) { + errno = output->last_failed_errno; + i_error("write(%s) failed: %m", file->path); + o_stream_unref(&output); + file_dotlock_delete(&file->dotlock); + file->new_fd = -1; + return; + } o_stream_unref(&output); file->changed = FALSE; From dovecot at dovecot.org Sun Jun 24 21:44:06 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sun, 24 Jun 2012 21:44:06 +0300 Subject: dovecot-2.2: master: Problems with creating base_dir/statedir sh... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3ffdb4bf36d3 changeset: 14680:3ffdb4bf36d3 user: Timo Sirainen date: Sun Jun 24 21:43:48 2012 +0300 description: master: Problems with creating base_dir/statedir should be fatals. diffstat: src/master/master-settings.c | 33 +++++++++++---------------------- src/master/master-settings.h | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) diffs (81 lines): diff -r f783fdbc3861 -r 3ffdb4bf36d3 src/master/master-settings.c --- a/src/master/master-settings.c Sun Jun 24 21:35:18 2012 +0300 +++ b/src/master/master-settings.c Sun Jun 24 21:43:48 2012 +0300 @@ -708,7 +708,7 @@ (void)closedir(dirp); } -bool master_settings_do_fixes(const struct master_settings *set) +void master_settings_do_fixes(const struct master_settings *set) { const char *login_dir, *empty_dir; struct stat st; @@ -716,19 +716,13 @@ /* since base dir is under /var/run by default, it may have been deleted. */ - if (mkdir_parents(set->base_dir, 0755) < 0 && errno != EEXIST) { - i_error("mkdir(%s) failed: %m", set->base_dir); - return FALSE; - } + if (mkdir_parents(set->base_dir, 0755) < 0 && errno != EEXIST) + i_fatal("mkdir(%s) failed: %m", set->base_dir); /* allow base_dir to be a symlink, so don't use lstat() */ - if (stat(set->base_dir, &st) < 0) { - i_error("stat(%s) failed: %m", set->base_dir); - return FALSE; - } - if (!S_ISDIR(st.st_mode)) { - i_error("%s is not a directory", set->base_dir); - return FALSE; - } + if (stat(set->base_dir, &st) < 0) + i_fatal("stat(%s) failed: %m", set->base_dir); + if (!S_ISDIR(st.st_mode)) + i_fatal("%s is not a directory", set->base_dir); if ((st.st_mode & 0755) != 0755) { i_warning("Fixing permissions of %s to be world-readable", set->base_dir); @@ -737,10 +731,8 @@ } /* Make sure our permanent state directory exists */ - if (mkdir_parents(PKG_STATEDIR, 0750) < 0 && errno != EEXIST) { - i_error("mkdir(%s) failed: %m", PKG_STATEDIR); - return FALSE; - } + if (mkdir_parents(PKG_STATEDIR, 0750) < 0 && errno != EEXIST) + i_fatal("mkdir(%s) failed: %m", PKG_STATEDIR); login_dir = t_strconcat(set->base_dir, "/login", NULL); if (settings_have_auth_unix_listeners_in(set, login_dir)) { @@ -758,10 +750,8 @@ unlink_sockets(login_dir, ""); } else { /* still make sure that login directory exists */ - if (mkdir(login_dir, 0755) < 0 && errno != EEXIST) { - i_error("mkdir(%s) failed: %m", login_dir); - return FALSE; - } + if (mkdir(login_dir, 0755) < 0 && errno != EEXIST) + i_fatal("mkdir(%s) failed: %m", login_dir); } empty_dir = t_strconcat(set->base_dir, "/empty", NULL); @@ -769,5 +759,4 @@ i_warning("Corrected permissions for empty directory " "%s", empty_dir); } - return TRUE; } diff -r f783fdbc3861 -r 3ffdb4bf36d3 src/master/master-settings.h --- a/src/master/master-settings.h Sun Jun 24 21:35:18 2012 +0300 +++ b/src/master/master-settings.h Sun Jun 24 21:43:48 2012 +0300 @@ -29,6 +29,6 @@ extern const struct setting_parser_info master_setting_parser_info; -bool master_settings_do_fixes(const struct master_settings *set); +void master_settings_do_fixes(const struct master_settings *set); #endif From dovecot at dovecot.org Mon Jun 25 00:02:30 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 00:02:30 +0300 Subject: dovecot-2.2: Added o_stream_nsend*() and related functions to ma... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/ca37d1577291 changeset: 14681:ca37d1577291 user: Timo Sirainen date: Mon Jun 25 00:01:59 2012 +0300 description: Added o_stream_nsend*() and related functions to make delayed error handling safer. Once o_stream_nsend*() is called, o_stream_nfinish() must be called before stream is destroyed to finish checking if there were any errors. If something failed and the stream is just wanted to be closed, o_stream_ignore_last_errors() can be called. For streams where errors don't really make any difference (network sockets) you can call o_stream_set_no_error_handling() immediately after creating the stream. diffstat: src/anvil/anvil-connection.c | 10 +- src/anvil/connect-limit.c | 2 +- src/anvil/penalty.c | 2 +- src/auth/auth-client-connection.c | 9 +- src/auth/auth-client-connection.h | 4 +- src/auth/auth-master-connection.c | 27 ++++---- src/auth/auth-postfix-connection.c | 3 +- src/auth/auth-worker-client.c | 13 ++- src/auth/auth-worker-server.c | 5 +- src/auth/main.c | 4 +- src/auth/mech-winbind.c | 3 +- src/config/config-connection.c | 29 ++++---- src/config/doveconf.c | 33 +++++----- src/dict/dict-commands.c | 12 +- src/dict/dict-connection.c | 1 + src/director/auth-connection.c | 3 +- src/director/director-connection.c | 2 +- src/director/director-test.c | 19 +++-- src/director/doveadm-connection.c | 41 ++++++------ src/director/login-connection.c | 5 +- src/dns/dns-client.c | 9 +- src/doveadm/client-connection.c | 19 +++-- src/doveadm/doveadm-mail-fetch.c | 1 + src/doveadm/doveadm-print-server.c | 4 +- src/doveadm/dsync/dsync-slave-io.c | 19 +++-- src/doveadm/server-connection.c | 9 +- src/imap-login/imap-proxy.c | 9 +- src/imap/cmd-append.c | 8 +- src/imap/cmd-copy.c | 4 +- src/imap/cmd-thread.c | 6 +- src/imap/imap-client.c | 11 +- src/imap/imap-fetch-body.c | 12 +-- src/imap/imap-fetch.c | 5 +- src/imap/imap-search.c | 9 +- src/imap/imap-sync.c | 4 +- src/imap/mail-storage-callbacks.c | 8 +- src/indexer/indexer-client.c | 7 +- src/indexer/worker-connection.c | 5 +- src/ipc/client.c | 13 ++- src/ipc/ipc-connection.c | 5 +- src/lib-auth/auth-master.c | 7 +- src/lib-dict/dict-file.c | 11 +- src/lib-fs/fs-posix.c | 4 +- src/lib-fs/ostream-cmp.c | 2 +- src/lib-imap-client/imapc-connection.c | 5 +- src/lib-imap/imap-parser.c | 4 +- src/lib-index/mail-cache-compress.c | 13 +-- src/lib-index/mail-index-strmap.c | 43 ++++++------- src/lib-index/mail-index-write.c | 14 ++-- src/lib-lda/duplicate.c | 12 +-- src/lib-lda/lmtp-client.c | 19 +++-- src/lib-lda/mail-send.c | 6 +- src/lib-lda/smtp-client.c | 2 +- src/lib-master/anvil-client.c | 5 +- src/lib-master/ipc-client.c | 3 +- src/lib-master/ipc-server.c | 11 +- src/lib-master/master-instance.c | 13 +-- src/lib-master/master-login-auth.c | 5 +- src/lib-master/master-login.c | 3 +- src/lib-storage/index/cydir/cydir-save.c | 7 +- src/lib-storage/index/dbox-common/dbox-file-fix.c | 47 +++++++++------ src/lib-storage/index/dbox-common/dbox-file.c | 6 +- src/lib-storage/index/dbox-common/dbox-save.c | 13 +-- src/lib-storage/index/dbox-multi/mdbox-purge.c | 11 +- src/lib-storage/index/dbox-single/sdbox-file.c | 5 +- src/lib-storage/index/imapc/imapc-save.c | 5 +- src/lib-storage/index/index-attachment.c | 40 +++++------- src/lib-storage/index/maildir/maildir-save.c | 6 +- src/lib-storage/index/maildir/maildir-uidlist.c | 18 ++--- src/lib-storage/index/mbox/mbox-save.c | 9 +- src/lib-storage/index/pop3c/pop3c-client.c | 15 ++-- src/lib-storage/list/subscription-file.c | 8 +- src/lib/ostream-file.c | 2 +- src/lib/ostream-private.h | 2 + src/lib/ostream-rawlog.c | 2 +- src/lib/ostream.c | 68 +++++++++++++++++++++- src/lib/ostream.h | 20 ++++++ src/lib/test-ostream-file.c | 6 +- src/lmtp/client.c | 3 +- src/lmtp/lmtp-proxy.c | 4 +- src/login-common/client-common-auth.c | 2 +- src/login-common/client-common.c | 1 + src/login-common/login-proxy.c | 3 +- src/plugins/acl/acl-backend-vfile-acllist.c | 5 +- src/plugins/acl/acl-backend-vfile.c | 6 +- src/plugins/fts-squat/squat-trie.c | 25 +++---- src/plugins/fts-squat/squat-uidlist.c | 60 +++++++++---------- src/plugins/imap-quota/imap-quota-plugin.c | 8 +- src/plugins/zlib/doveadm-zlib.c | 3 +- src/plugins/zlib/ostream-bzlib.c | 2 +- src/plugins/zlib/ostream-zlib.c | 2 +- src/pop3-login/pop3-proxy.c | 10 +- src/pop3/pop3-client.c | 1 + src/pop3/pop3-commands.c | 4 +- src/replication/aggregator/notify-connection.c | 6 +- src/replication/aggregator/replicator-connection.c | 5 +- src/replication/replicator/doveadm-connection.c | 5 +- src/replication/replicator/notify-connection.c | 3 +- src/replication/replicator/replicator-queue.c | 8 +- src/ssl-params/main.c | 5 +- src/stats/client-export.c | 34 +++++----- src/stats/client.c | 1 + src/stats/mail-server-connection.c | 3 - src/util/rawlog.c | 8 +- 104 files changed, 593 insertions(+), 490 deletions(-) diffs (truncated from 3801 to 300 lines): diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/anvil-connection.c --- a/src/anvil/anvil-connection.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/anvil/anvil-connection.c Mon Jun 25 00:01:59 2012 +0300 @@ -90,15 +90,15 @@ return -1; } value = connect_limit_lookup(connect_limit, args[0]); - (void)o_stream_send_str(conn->output, - t_strdup_printf("%u\n", value)); + o_stream_nsend_str(conn->output, + t_strdup_printf("%u\n", value)); } else if (strcmp(cmd, "PENALTY-GET") == 0) { if (args[0] == NULL) { *error_r = "PENALTY-GET: Not enough parameters"; return -1; } value = penalty_get(penalty, args[0], &stamp); - (void)o_stream_send_str(conn->output, + o_stream_nsend_str(conn->output, t_strdup_printf("%u %s\n", value, dec2str(stamp))); } else if (strcmp(cmd, "PENALTY-INC") == 0) { if (args[0] == NULL || args[1] == NULL || args[2] == NULL) { @@ -183,8 +183,10 @@ conn = i_new(struct anvil_connection, 1); conn->fd = fd; conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); - if (!fifo) + if (!fifo) { conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + o_stream_set_no_error_handling(conn->output, TRUE); + } conn->io = io_add(fd, IO_READ, anvil_connection_input, conn); conn->master = master; conn->fifo = fifo; diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/connect-limit.c --- a/src/anvil/connect-limit.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/anvil/connect-limit.c Mon Jun 25 00:01:59 2012 +0300 @@ -185,5 +185,5 @@ break; } hash_table_iterate_deinit(&iter); - (void)o_stream_send(output, "\n", 1); + o_stream_nsend(output, "\n", 1); } diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/penalty.c --- a/src/anvil/penalty.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/anvil/penalty.c Mon Jun 25 00:01:59 2012 +0300 @@ -268,5 +268,5 @@ if (o_stream_send(output, str_data(str), str_len(str)) < 0) break; } - (void)o_stream_send(output, "\n", 1); + o_stream_nsend(output, "\n", 1); } diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-client-connection.c --- a/src/auth/auth-client-connection.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-client-connection.c Mon Jun 25 00:01:59 2012 +0300 @@ -54,7 +54,7 @@ iov[0].iov_len = strlen(cmd); iov[1].iov_base = "\n"; iov[1].iov_len = 1; - (void)o_stream_sendv(conn->output, iov, 2); + o_stream_nsendv(conn->output, iov, 2); if (o_stream_get_buffer_used_size(conn->output) >= OUTBUF_THROTTLE_SIZE) { @@ -292,8 +292,8 @@ auth_client_connection_unref(&conn); } -struct auth_client_connection * -auth_client_connection_create(struct auth *auth, int fd, bool login_requests) +void auth_client_connection_create(struct auth *auth, int fd, + bool login_requests) { static unsigned int connect_uid_counter = 0; struct auth_client_connection *conn; @@ -310,6 +310,7 @@ conn->input = i_stream_create_fd(fd, AUTH_CLIENT_MAX_LINE_LENGTH, FALSE); conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + o_stream_set_no_error_handling(conn->output, TRUE); o_stream_set_flush_callback(conn->output, auth_client_output, conn); conn->io = io_add(fd, IO_READ, auth_client_input, conn); @@ -325,8 +326,6 @@ if (o_stream_send(conn->output, str_data(str), str_len(str)) < 0) auth_client_disconnected(&conn); - - return conn; } void auth_client_connection_destroy(struct auth_client_connection **_conn) diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-client-connection.h --- a/src/auth/auth-client-connection.h Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-client-connection.h Mon Jun 25 00:01:59 2012 +0300 @@ -22,8 +22,8 @@ unsigned int version_received:1; }; -struct auth_client_connection * -auth_client_connection_create(struct auth *auth, int fd, bool login_requests); +void auth_client_connection_create(struct auth *auth, int fd, + bool login_requests); void auth_client_connection_destroy(struct auth_client_connection **conn); struct auth_client_connection * diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-master-connection.c --- a/src/auth/auth-master-connection.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-master-connection.c Mon Jun 25 00:01:59 2012 +0300 @@ -87,7 +87,7 @@ iov[1].iov_base = "\n"; iov[1].iov_len = 1; - (void)o_stream_sendv(conn->output, iov, 2); + o_stream_nsendv(conn->output, iov, 2); } static bool @@ -119,19 +119,19 @@ if (client_conn == NULL) { i_error("Master requested auth for nonexistent client %u", client_pid); - (void)o_stream_send_str(conn->output, - t_strdup_printf("FAIL\t%u\n", id)); + o_stream_nsend_str(conn->output, + t_strdup_printf("FAIL\t%u\n", id)); } else if (memcmp(client_conn->cookie, cookie, sizeof(cookie)) != 0) { i_error("Master requested auth for client %u with invalid cookie", client_pid); - (void)o_stream_send_str(conn->output, - t_strdup_printf("FAIL\t%u\n", id)); + o_stream_nsend_str(conn->output, + t_strdup_printf("FAIL\t%u\n", id)); } else if (!auth_request_handler_master_request( client_conn->request_handler, conn, id, client_id)) { i_error("Master requested auth for non-login client %u", client_pid); - (void)o_stream_send_str(conn->output, - t_strdup_printf("FAIL\t%u\n", id)); + o_stream_nsend_str(conn->output, + t_strdup_printf("FAIL\t%u\n", id)); } return TRUE; } @@ -260,7 +260,7 @@ } str_append_c(str, '\n'); - (void)o_stream_send(conn->output, str_data(str), str_len(str)); + o_stream_nsend(conn->output, str_data(str), str_len(str)); auth_request_unref(&auth_request); auth_master_connection_unref(&conn); @@ -320,7 +320,7 @@ i_debug("master out: %s", str_c(str)); str_append_c(str, '\n'); - (void)o_stream_send(conn->output, str_data(str), str_len(str)); + o_stream_nsend(conn->output, str_data(str), str_len(str)); auth_request_unref(&auth_request); auth_master_connection_unref(&conn); @@ -446,7 +446,7 @@ str = t_strdup_printf("DONE\t%u\t%s\n", ctx->auth_request->id, ctx->failed ? "fail" : ""); - (void)o_stream_send_str(ctx->conn->output, str); + o_stream_nsend_str(ctx->conn->output, str); master_input_list_finish(ctx); return; } @@ -496,7 +496,7 @@ i_error("Auth client doesn't have permissions to list users: %s", auth_restricted_reason(conn)); str = t_strdup_printf("DONE\t%u\tfail\n", id); - (void)o_stream_send_str(conn->output, str); + o_stream_nsend_str(conn->output, str); return TRUE; } @@ -505,7 +505,7 @@ if (userdb == NULL) { i_error("Trying to iterate users, but userdbs don't support it"); str = t_strdup_printf("DONE\t%u\tfail\n", id); - (void)o_stream_send_str(conn->output, str); + o_stream_nsend_str(conn->output, str); return TRUE; } @@ -693,6 +693,7 @@ conn->auth = auth; conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + o_stream_set_no_error_handling(conn->output, TRUE); o_stream_set_flush_callback(conn->output, master_output, conn); conn->io = io_add(fd, IO_READ, master_input, conn); conn->userdb_only = userdb_only; @@ -701,7 +702,7 @@ AUTH_MASTER_PROTOCOL_MAJOR_VERSION, AUTH_MASTER_PROTOCOL_MINOR_VERSION, my_pid); - (void)o_stream_send_str(conn->output, line); + o_stream_nsend_str(conn->output, line); DLLIST_PREPEND(&auth_master_connections, conn); if (auth_master_connection_set_permissions(conn, socket_st) < 0) { diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-postfix-connection.c --- a/src/auth/auth-postfix-connection.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-postfix-connection.c Mon Jun 25 00:01:59 2012 +0300 @@ -95,7 +95,7 @@ i_debug("postfix out: %s", str_c(str)); str_append_c(str, '\n'); - (void)o_stream_send(conn->output, str_data(str), str_len(str)); + o_stream_nsend(conn->output, str_data(str), str_len(str)); i_assert(conn->io == NULL); if (!conn->destroyed) @@ -179,6 +179,7 @@ conn->auth = auth; conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + o_stream_set_no_error_handling(conn->output, TRUE); conn->io = io_add(fd, IO_READ, postfix_input, conn); DLLIST_PREPEND(&auth_postfix_connections, conn); return conn; diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-worker-client.c --- a/src/auth/auth-worker-client.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-worker-client.c Mon Jun 25 00:01:59 2012 +0300 @@ -102,8 +102,8 @@ string_t *str) { if (worker_restart_request) - o_stream_send_str(client->output, "RESTART\n"); - o_stream_send(client->output, str_data(str), str_len(str)); + o_stream_nsend_str(client->output, "RESTART\n"); + o_stream_nsend(client->output, str_data(str), str_len(str)); } static void verify_plain_callback(enum passdb_result result, @@ -464,7 +464,7 @@ T_BEGIN { str = t_str_new(128); str_printfa(str, "%u\t*\t%s\n", ctx->auth_request->id, user); - o_stream_send(ctx->client->output, str_data(str), str_len(str)); + o_stream_nsend(ctx->client->output, str_data(str), str_len(str)); } T_END; if (ctx->sending) { @@ -694,6 +694,7 @@ client->input = i_stream_create_fd(fd, AUTH_WORKER_MAX_LINE_LENGTH, FALSE); client->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + o_stream_set_no_error_handling(client->output, TRUE); o_stream_set_flush_callback(client->output, auth_worker_output, client); client->io = io_add(fd, IO_READ, auth_worker_input, client); auth_worker_refresh_proctitle(CLIENT_STATE_HANDSHAKE); @@ -755,7 +756,7 @@ auth_worker_client_error = TRUE; if (auth_worker_client != NULL && !auth_worker_client->error_sent) { - o_stream_send_str(auth_worker_client->output, "ERROR\n"); + o_stream_nsend_str(auth_worker_client->output, "ERROR\n"); auth_worker_client->error_sent = TRUE; } auth_worker_refresh_proctitle(""); @@ -766,7 +767,7 @@ auth_worker_client_error = FALSE; if (auth_worker_client != NULL && auth_worker_client->error_sent) { - o_stream_send_str(auth_worker_client->output, "SUCCESS\n"); + o_stream_nsend_str(auth_worker_client->output, "SUCCESS\n"); auth_worker_client->error_sent = FALSE; } auth_worker_refresh_proctitle(CLIENT_STATE_IDLE); @@ -775,6 +776,6 @@ void auth_worker_client_send_shutdown(void) { if (auth_worker_client != NULL) - o_stream_send_str(auth_worker_client->output, "SHUTDOWN\n"); + o_stream_nsend_str(auth_worker_client->output, "SHUTDOWN\n"); auth_worker_refresh_proctitle(CLIENT_STATE_STOP); } diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-worker-server.c --- a/src/auth/auth-worker-server.c Sun Jun 24 21:43:48 2012 +0300 +++ b/src/auth/auth-worker-server.c Mon Jun 25 00:01:59 2012 +0300 @@ -101,7 +101,7 @@ iov[2].iov_base = "\n"; iov[2].iov_len = 1; - o_stream_sendv(conn->output, iov, 3); + o_stream_nsendv(conn->output, iov, 3); i_assert(conn->request == NULL); conn->request = request; @@ -145,7 +145,7 @@ binary_to_hex_append(str, userdb_md5, sizeof(userdb_md5)); str_append_c(str, '\n'); From dovecot at dovecot.org Mon Jun 25 00:18:41 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 00:18:41 +0300 Subject: dovecot-2.1: pop3c: Fixed losing timeout on ioloop change. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/edb8d177bd37 changeset: 14577:edb8d177bd37 user: Timo Sirainen date: Mon Jun 25 00:18:31 2012 +0300 description: pop3c: Fixed losing timeout on ioloop change. diffstat: src/lib-storage/index/pop3c/pop3c-client.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 4edce2f57264 -r edb8d177bd37 src/lib-storage/index/pop3c/pop3c-client.c --- a/src/lib-storage/index/pop3c/pop3c-client.c Sun Jun 24 21:35:18 2012 +0300 +++ b/src/lib-storage/index/pop3c/pop3c-client.c Mon Jun 25 00:18:31 2012 +0300 @@ -166,7 +166,7 @@ static void pop3c_client_ioloop_changed(struct pop3c_client *client) { if (client->to != NULL) - io_loop_move_timeout(&client->to); + client->to = io_loop_move_timeout(&client->to); if (client->io != NULL) client->io = io_loop_move_io(&client->io); if (client->output != NULL) From dovecot at dovecot.org Mon Jun 25 01:14:28 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 01:14:28 +0300 Subject: dovecot-2.2: Make sure we check all the functions' return values... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/d0d7b810646b changeset: 14682:d0d7b810646b user: Timo Sirainen date: Mon Jun 25 01:14:03 2012 +0300 description: Make sure we check all the functions' return values. Minor API changes to simplify this. Checked using a patched clang that adds attribute(warn_unused_result) to all functions. This commit fixes several error handling mistakes. diffstat: src/anvil/main.c | 2 +- src/auth/auth-request.c | 4 +- src/auth/mech-digest-md5.c | 2 +- src/auth/mech-scram-sha1.c | 2 +- src/auth/passdb-blocking.c | 11 +- src/auth/password-scheme-otp.c | 6 +- src/auth/userdb-blocking.c | 2 +- src/auth/userdb-sql.c | 2 +- src/config/doveconf.c | 2 +- src/config/main.c | 2 +- src/config/old-set-parser.c | 2 + src/dict/dict-commands.c | 2 +- src/dict/main.c | 2 +- src/director/director-connection.c | 5 +- src/director/director-host.c | 5 +- src/director/director.c | 2 +- src/director/doveadm-connection.c | 4 +- src/director/mail-host.c | 4 +- src/director/main.c | 4 +- src/director/test-user-directory.c | 8 +- src/doveadm/doveadm-dump-dbox.c | 4 +- src/doveadm/doveadm-mail-server.c | 6 +- src/doveadm/doveadm-mailbox-list-iter.c | 13 +- src/doveadm/doveadm-mount.c | 8 +- src/doveadm/doveadm-penalty.c | 2 +- src/doveadm/doveadm-stats.c | 12 +- src/doveadm/dsync/doveadm-dsync.c | 13 +- src/doveadm/dsync/dsync-brain-mailbox-tree.c | 4 +- src/doveadm/dsync/dsync-brain-mailbox.c | 10 +- src/doveadm/dsync/dsync-brain-mails.c | 2 +- src/doveadm/dsync/dsync-mailbox-import.c | 19 ++-- src/doveadm/dsync/dsync-mailbox-tree.c | 2 +- src/doveadm/dsync/dsync-slave.c | 4 +- src/doveadm/dsync/dsync-slave.h | 3 +- src/doveadm/server-connection.c | 12 +- src/doveadm/server-connection.h | 5 +- src/imap-login/client.c | 2 +- src/imap/cmd-fetch.c | 2 +- src/imap/cmd-idle.c | 2 +- src/imap/cmd-list.c | 2 +- src/imap/imap-client.c | 9 +- src/imap/imap-client.h | 7 +- src/imap/imap-fetch-body.c | 9 +- src/imap/imap-sync.c | 6 +- src/imap/main.c | 4 +- src/indexer/master-connection.c | 10 +- src/lib-auth/auth-client.c | 2 +- src/lib-imap/imap-parser.c | 2 +- src/lib-imap/imap-quote.c | 27 +++-- src/lib-index/mail-cache-compress.c | 2 +- src/lib-index/mail-cache-transaction.c | 4 +- src/lib-index/mail-cache.c | 2 +- src/lib-index/mail-index-fsck.c | 2 +- src/lib-index/mail-index-map-hdr.c | 2 +- src/lib-index/mail-index-modseq.c | 7 +- src/lib-index/mail-index-private.h | 12 +- src/lib-index/mail-index-strmap.c | 6 +- src/lib-index/mail-index-sync-update.c | 2 +- src/lib-index/mail-index-transaction-private.h | 2 +- src/lib-index/mail-index-transaction-sort-appends.c | 6 +- src/lib-index/mail-index-transaction-update.c | 7 +- src/lib-index/mail-index-view-sync.c | 6 +- src/lib-index/mail-index-write.c | 4 +- src/lib-index/mail-index.c | 40 ++++---- src/lib-index/mail-transaction-log-file.c | 62 ++++++++----- src/lib-index/test-mail-index-transaction-update.c | 11 +- src/lib-index/test-mail-transaction-log-append.c | 7 +- src/lib-mail/message-header-decode.c | 1 - src/lib-mail/message-part-serialize.c | 14 +- src/lib-mail/rfc822-parser.c | 2 +- src/lib-mail/test-istream-dot.c | 2 +- src/lib-ntlm/ntlm-des.c | 7 +- src/lib-ntlm/ntlm-des.h | 4 +- src/lib-ntlm/ntlm-encrypt.c | 10 +- src/lib-ntlm/ntlm-encrypt.h | 7 +- src/lib-otp/otp-hash.c | 4 +- src/lib-otp/otp-hash.h | 2 +- src/lib-storage/index/dbox-common/dbox-file-fix.c | 2 +- src/lib-storage/index/dbox-common/dbox-file.c | 5 +- src/lib-storage/index/dbox-common/dbox-sync-rebuild.c | 2 +- src/lib-storage/index/dbox-multi/mdbox-purge.c | 6 +- src/lib-storage/index/dbox-single/sdbox-copy.c | 2 +- src/lib-storage/index/imapc/imapc-mail.c | 3 +- src/lib-storage/index/imapc/imapc-storage.c | 2 +- src/lib-storage/index/index-mail.c | 24 +++- src/lib-storage/index/index-search.c | 9 +- src/lib-storage/index/index-sort-string.c | 4 +- src/lib-storage/index/index-sort.c | 4 +- src/lib-storage/index/index-status.c | 16 ++- src/lib-storage/index/index-storage.h | 3 + src/lib-storage/index/index-sync-changes.c | 8 +- src/lib-storage/index/index-sync.c | 21 ++-- src/lib-storage/index/index-thread.c | 5 +- src/lib-storage/index/maildir/maildir-uidlist.c | 6 +- src/lib-storage/index/mbox/istream-raw-mbox.c | 2 +- src/lib-storage/index/mbox/mbox-mail.c | 6 +- src/lib-storage/index/mbox/mbox-save.c | 83 ++++++++++++------ src/lib-storage/index/mbox/mbox-storage.c | 3 +- src/lib-storage/index/mbox/mbox-storage.h | 2 +- src/lib-storage/index/mbox/mbox-sync.c | 3 +- src/lib-storage/index/pop3c/pop3c-client.c | 2 +- src/lib-storage/index/raw/raw-mail.c | 6 +- src/lib-storage/mail-search-build.c | 2 +- src/lib-storage/mail-storage-private.h | 2 +- src/lib-storage/mail.c | 15 ++- src/lib-storage/mailbox-get.c | 2 +- src/lib-storage/mailbox-uidvalidity.c | 6 +- src/lib/data-stack.c | 8 +- src/lib/hash.c | 8 +- src/lib/hostpid.c | 9 +- src/lib/iostream-rawlog.c | 7 +- src/lib/md4.c | 6 +- src/lib/md5.c | 6 +- src/lib/mountpoint.c | 3 +- src/lib/nfs-workarounds.c | 11 +- src/lib/nfs-workarounds.h | 2 +- src/lib/seq-range-array.c | 39 +++++--- src/lib/seq-range-array.h | 20 ++- src/lib/test-base64.c | 2 +- src/lib/test-network.c | 4 +- src/lib/test-ostream-file.c | 8 +- src/lib/test-seq-range-array.c | 2 +- src/log/log-connection.c | 9 +- src/log/log-connection.h | 7 +- src/login-common/client-common-auth.c | 2 +- src/login-common/login-proxy-state.c | 2 +- src/login-common/login-proxy.c | 2 +- src/login-common/ssl-proxy-openssl.c | 12 +- src/master/main.c | 4 +- src/master/service-anvil.c | 2 +- src/master/service-process.c | 6 +- src/master/service-process.h | 2 +- src/plugins/autocreate/autocreate-plugin.c | 7 +- src/plugins/expire/doveadm-expire.c | 10 +- src/plugins/expire/expire-plugin.c | 5 +- src/plugins/fts-lucene/fts-backend-lucene.c | 8 +- src/plugins/fts-squat/squat-trie.c | 4 +- src/plugins/fts-squat/squat-uidlist.c | 19 ++-- src/plugins/fts/fts-storage.c | 5 +- src/plugins/imap-acl/imap-acl-plugin.c | 2 +- src/plugins/imap-quota/imap-quota-plugin.c | 2 +- src/plugins/imap-zlib/imap-zlib-plugin.c | 2 +- src/plugins/quota/quota-maildir.c | 7 +- src/plugins/quota/quota.c | 8 +- src/plugins/stats/stats-connection.c | 2 +- src/plugins/virtual/virtual-mail.c | 2 +- src/plugins/virtual/virtual-sync.c | 2 +- src/plugins/zlib/doveadm-zlib.c | 2 +- src/plugins/zlib/ostream-zlib.c | 12 +- src/pop3/main.c | 4 +- src/pop3/pop3-client.c | 10 +- src/pop3/pop3-client.h | 5 +- src/pop3/pop3-commands.c | 37 +++---- src/replication/aggregator/notify-connection.c | 2 +- src/replication/replicator/notify-connection.c | 2 +- src/stats/main.c | 2 +- src/util/rawlog.c | 2 +- 157 files changed, 623 insertions(+), 492 deletions(-) diffs (truncated from 3703 to 300 lines): diff -r ca37d1577291 -r d0d7b810646b src/anvil/main.c --- a/src/anvil/main.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/anvil/main.c Mon Jun 25 01:14:03 2012 +0300 @@ -26,7 +26,7 @@ bool master = conn->listen_fd == MASTER_LISTEN_FD_FIRST; master_service_client_connection_accept(conn); - anvil_connection_create(conn->fd, master, conn->fifo); + (void)anvil_connection_create(conn->fd, master, conn->fifo); } static void ATTR_NULL(1) diff -r ca37d1577291 -r d0d7b810646b src/auth/auth-request.c --- a/src/auth/auth-request.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/auth-request.c Mon Jun 25 01:14:03 2012 +0300 @@ -237,9 +237,9 @@ if (strcmp(key, "service") == 0) request->service = p_strdup(request->pool, value); else if (strcmp(key, "lip") == 0) - net_addr2ip(value, &request->local_ip); + (void)net_addr2ip(value, &request->local_ip); else if (strcmp(key, "rip") == 0) - net_addr2ip(value, &request->remote_ip); + (void)net_addr2ip(value, &request->remote_ip); else if (strcmp(key, "lport") == 0) request->local_port = atoi(value); else if (strcmp(key, "rport") == 0) diff -r ca37d1577291 -r d0d7b810646b src/auth/mech-digest-md5.c --- a/src/auth/mech-digest-md5.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/mech-digest-md5.c Mon Jun 25 01:14:03 2012 +0300 @@ -283,7 +283,7 @@ { unsigned int i; - str_lcase(key); + (void)str_lcase(key); if (strcmp(key, "realm") == 0) { if (request->auth_request.realm == NULL && *value != '\0') diff -r ca37d1577291 -r d0d7b810646b src/auth/mech-scram-sha1.c --- a/src/auth/mech-scram-sha1.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/mech-scram-sha1.c Mon Jun 25 01:14:03 2012 +0300 @@ -328,7 +328,7 @@ return FALSE; } - str_array_remove(fields, fields[field_count-1]); + (void)str_array_remove(fields, fields[field_count-1]); request->client_final_message_without_proof = p_strdup(request->pool, t_strarray_join(fields, ",")); diff -r ca37d1577291 -r d0d7b810646b src/auth/passdb-blocking.c --- a/src/auth/passdb-blocking.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/passdb-blocking.c Mon Jun 25 01:14:03 2012 +0300 @@ -88,7 +88,8 @@ auth_request_export(request, reply); auth_request_ref(request); - auth_worker_call(request->pool, reply, verify_plain_callback, request); + (void)auth_worker_call(request->pool, reply, + verify_plain_callback, request); } static bool lookup_credentials_callback(const char *reply, void *context) @@ -130,8 +131,8 @@ auth_request_export(request, reply); auth_request_ref(request); - auth_worker_call(request->pool, reply, - lookup_credentials_callback, request); + (void)auth_worker_call(request->pool, reply, + lookup_credentials_callback, request); } static bool @@ -158,6 +159,6 @@ auth_request_export(request, reply); auth_request_ref(request); - auth_worker_call(request->pool, reply, - set_credentials_callback, request); + (void)auth_worker_call(request->pool, reply, + set_credentials_callback, request); } diff -r ca37d1577291 -r d0d7b810646b src/auth/password-scheme-otp.c --- a/src/auth/password-scheme-otp.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/password-scheme-otp.c Mon Jun 25 01:14:03 2012 +0300 @@ -23,10 +23,12 @@ } else { /* Generate new OTP credentials from plaintext */ unsigned char random_data[OTP_MAX_SEED_LEN / 2]; + const char *random_hex; random_fill(random_data, sizeof(random_data)); - i_strocpy(state.seed, binary_to_hex(random_data, - OTP_MAX_SEED_LEN / 2), sizeof(state.seed)); + random_hex = binary_to_hex(random_data, sizeof(random_data)); + if (i_strocpy(state.seed, random_hex, sizeof(state.seed)) < 0) + i_unreached(); state.seq = 1024; state.algo = algo; diff -r ca37d1577291 -r d0d7b810646b src/auth/userdb-blocking.c --- a/src/auth/userdb-blocking.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/userdb-blocking.c Mon Jun 25 01:14:03 2012 +0300 @@ -58,7 +58,7 @@ auth_request_export(request, reply); auth_request_ref(request); - auth_worker_call(request->pool, reply, user_callback, request); + (void)auth_worker_call(request->pool, reply, user_callback, request); } static bool iter_callback(const char *reply, void *context) diff -r ca37d1577291 -r d0d7b810646b src/auth/userdb-sql.c --- a/src/auth/userdb-sql.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/auth/userdb-sql.c Mon Jun 25 01:14:03 2012 +0300 @@ -136,7 +136,7 @@ sql_result_ref(sql_result); if (ctx->freed) - userdb_sql_iterate_deinit(&ctx->ctx); + (void)userdb_sql_iterate_deinit(&ctx->ctx); else if (ctx->call_iter) userdb_sql_iterate_next(&ctx->ctx); } diff -r ca37d1577291 -r d0d7b810646b src/config/doveconf.c --- a/src/config/doveconf.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/config/doveconf.c Mon Jun 25 01:14:03 2012 +0300 @@ -478,7 +478,7 @@ config_dump_human_deinit(ctx); if (dump_section) - config_dump_human(filter, "", scope, setting_name_filter); + (void)config_dump_human(filter, "", scope, setting_name_filter); return 0; } diff -r ca37d1577291 -r d0d7b810646b src/config/main.c --- a/src/config/main.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/config/main.c Mon Jun 25 01:14:03 2012 +0300 @@ -11,7 +11,7 @@ static void client_connected(struct master_service_connection *conn) { master_service_client_connection_accept(conn); - config_connection_create(conn->fd); + (void)config_connection_create(conn->fd); } int main(int argc, char *argv[]) diff -r ca37d1577291 -r d0d7b810646b src/config/old-set-parser.c --- a/src/config/old-set-parser.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/config/old-set-parser.c Mon Jun 25 01:14:03 2012 +0300 @@ -6,6 +6,8 @@ #include "config-parser-private.h" #include "old-set-parser.h" +#define config_apply_line (void)config_apply_line + struct socket_set { const char *path, *mode, *user, *group; bool master; diff -r ca37d1577291 -r d0d7b810646b src/dict/dict-commands.c --- a/src/dict/dict-commands.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/dict/dict-commands.c Mon Jun 25 01:14:03 2012 +0300 @@ -101,7 +101,7 @@ conn->iter_ctx = dict_iterate_init_multiple(conn->dict, args+1, flags); o_stream_set_flush_callback(conn->output, cmd_iterate_flush, conn); - cmd_iterate_flush(conn); + (void)cmd_iterate_flush(conn); return 0; } diff -r ca37d1577291 -r d0d7b810646b src/dict/main.c --- a/src/dict/main.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/dict/main.c Mon Jun 25 01:14:03 2012 +0300 @@ -23,7 +23,7 @@ static void client_connected(struct master_service_connection *conn) { master_service_client_connection_accept(conn); - dict_connection_create(conn->fd); + (void)dict_connection_create(conn->fd); } static void main_preinit(void) diff -r ca37d1577291 -r d0d7b810646b src/director/director-connection.c --- a/src/director/director-connection.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/director-connection.c Mon Jun 25 01:14:03 2012 +0300 @@ -538,7 +538,8 @@ return FALSE; } - director_user_refresh(conn, username_hash, host, timestamp, weak, &user); + (void)director_user_refresh(conn, username_hash, host, + timestamp, weak, &user); return TRUE; } @@ -1081,7 +1082,7 @@ } if (host == NULL || !host->self) - director_resend_sync(dir); + (void)director_resend_sync(dir); return TRUE; } diff -r ca37d1577291 -r d0d7b810646b src/director/director-host.c --- a/src/director/director-host.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/director-host.c Mon Jun 25 01:14:03 2012 +0300 @@ -158,7 +158,7 @@ i_fatal("Unknown director host: %s", host); for (i = 0; i < ips_count; i++) - director_host_add(dir, &ips[i], port); + (void)director_host_add(dir, &ips[i], port); } void director_host_add_from_string(struct director *dir, const char *hosts) @@ -175,7 +175,8 @@ /* standalone director */ struct ip_addr ip; - net_addr2ip("127.0.0.1", &ip); + if (net_addr2ip("127.0.0.1", &ip) < 0) + i_unreached(); dir->self_host = director_host_add(dir, &ip, 0); dir->self_host->self = TRUE; } diff -r ca37d1577291 -r d0d7b810646b src/director/director.c --- a/src/director/director.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/director.c Mon Jun 25 01:14:03 2012 +0300 @@ -121,7 +121,7 @@ while we're still trying to connect to it */ host->last_network_failure = 0; - director_connection_init_out(dir, fd, host); + (void)director_connection_init_out(dir, fd, host); return 0; } diff -r ca37d1577291 -r d0d7b810646b src/director/doveadm-connection.c --- a/src/director/doveadm-connection.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/doveadm-connection.c Mon Jun 25 01:14:03 2012 +0300 @@ -419,9 +419,9 @@ else if (strcmp(cmd, "DIRECTOR-LIST") == 0) doveadm_cmd_director_list(conn); else if (strcmp(cmd, "DIRECTOR-ADD") == 0) - doveadm_cmd_director_add(conn, args); + ret = doveadm_cmd_director_add(conn, args); else if (strcmp(cmd, "DIRECTOR-REMOVE") == 0) - doveadm_cmd_director_remove(conn, args); + ret = doveadm_cmd_director_remove(conn, args); else if (strcmp(cmd, "HOST-SET") == 0) ret = doveadm_cmd_host_set(conn, args); else if (strcmp(cmd, "HOST-REMOVE") == 0) diff -r ca37d1577291 -r d0d7b810646b src/director/mail-host.c --- a/src/director/mail-host.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/mail-host.c Mon Jun 25 01:14:03 2012 +0300 @@ -59,7 +59,7 @@ } for (i = 0; i < ips_count; i++) - mail_host_add_ip(list, &ips[i]); + (void)mail_host_add_ip(list, &ips[i]); return 0; } @@ -120,7 +120,7 @@ /* create hosts from the final bits */ do { ip1_arr[i] = ntohl(i1); - mail_host_add_ip(list, &ip1); + (void)mail_host_add_ip(list, &ip1); i1++; } while (ip1_arr[i] != ip2_arr[i]); return 0; diff -r ca37d1577291 -r d0d7b810646b src/director/main.c --- a/src/director/main.c Mon Jun 25 00:01:59 2012 +0300 +++ b/src/director/main.c Mon Jun 25 01:14:03 2012 +0300 @@ -37,7 +37,7 @@ return -1; } - director_connection_init_in(director, fd, ip); + (void)director_connection_init_in(director, fd, ip); return 0; } @@ -90,7 +90,7 @@ auth = auth_connection_init(socket_path); if (auth_connection_connect(auth) == 0) { master_service_client_connection_accept(conn); - login_connection_init(director, conn->fd, auth, userdb); + (void)login_connection_init(director, conn->fd, auth, userdb); } else { auth_connection_deinit(&auth); } diff -r ca37d1577291 -r d0d7b810646b src/director/test-user-directory.c From dovecot at dovecot.org Mon Jun 25 02:15:56 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 02:15:56 +0300 Subject: dovecot-2.2: Added i_stream_get_data_size(). Used it where possi... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9646f80ac3e9 changeset: 14683:9646f80ac3e9 user: Timo Sirainen date: Mon Jun 25 02:15:22 2012 +0300 description: Added i_stream_get_data_size(). Used it where possible. diffstat: src/director/director-connection.c | 5 +---- src/doveadm/dsync/dsync-slave-io.c | 6 ++---- src/imap/cmd-append.c | 8 ++------ src/imap/imap-client.c | 11 +++-------- src/lib-dict/dict-client.c | 4 +--- src/lib-mail/istream-dot.c | 4 ++-- src/lib-mail/istream-header-filter.c | 2 +- src/lib-mail/istream-nonuls.c | 7 ++----- src/lib-mail/message-parser.c | 8 ++------ src/lib-storage/index/istream-mail.c | 2 +- src/lib-storage/index/mbox/istream-raw-mbox.c | 4 +--- src/lib-storage/index/pop3c/pop3c-client.c | 6 ++---- src/lib/istream-base64-encoder.c | 6 +++--- src/lib/istream-crlf.c | 4 ++-- src/lib/istream-seekable.c | 8 +++----- src/lib/istream-tee.c | 6 ++---- src/lib/istream.c | 10 ++++++++++ src/lib/istream.h | 1 + src/lib/test-istream-base64-encoder.c | 3 +-- src/lib/test-istream-concat.c | 2 +- src/lib/test-istream-seekable.c | 4 ++-- src/plugins/fts/fts-expunge-log.c | 2 +- src/plugins/zlib/istream-bzlib.c | 2 +- src/plugins/zlib/istream-zlib.c | 2 +- 24 files changed, 48 insertions(+), 69 deletions(-) diffs (truncated from 502 to 300 lines): diff -r d0d7b810646b -r 9646f80ac3e9 src/director/director-connection.c --- a/src/director/director-connection.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/director/director-connection.c Mon Jun 25 02:15:22 2012 +0300 @@ -1275,10 +1275,7 @@ /* just read everything the remote sends, and wait for it to disconnect. we mainly just want the remote to read the CONNECT we sent it. */ - size_t size; - - (void)i_stream_get_data(conn->input, &size); - i_stream_skip(conn->input, size); + i_stream_skip(conn->input, i_stream_get_data_size(conn->input)); return; } diff -r d0d7b810646b -r 9646f80ac3e9 src/doveadm/dsync/dsync-slave-io.c --- a/src/doveadm/dsync/dsync-slave-io.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave-io.c Mon Jun 25 02:15:22 2012 +0300 @@ -144,8 +144,6 @@ static int dsync_slave_io_read_mail_stream(struct dsync_slave_io *slave) { - size_t size; - if (i_stream_read(slave->mail_input) < 0) { if (slave->mail_input->stream_errno != 0) { errno = slave->mail_input->stream_errno; @@ -159,8 +157,8 @@ slave->mail_input = NULL; return 1; } - (void)i_stream_get_data(slave->mail_input, &size); - i_stream_skip(slave->mail_input, size); + i_stream_skip(slave->mail_input, + i_stream_get_data_size(slave->mail_input)); return 0; } diff -r d0d7b810646b -r 9646f80ac3e9 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/imap/cmd-append.c Mon Jun 25 02:15:22 2012 +0300 @@ -150,7 +150,6 @@ static bool cmd_append_continue_cancel(struct client_command_context *cmd) { struct cmd_append_context *ctx = cmd->context; - size_t size; if (cmd->cancel) { cmd_append_finish(ctx); @@ -158,8 +157,7 @@ } (void)i_stream_read(ctx->input); - (void)i_stream_get_data(ctx->input, &size); - i_stream_skip(ctx->input, size); + i_stream_skip(ctx->input, i_stream_get_data_size(ctx->input)); if (cmd->client->input->closed) { cmd_append_finish(ctx); @@ -712,7 +710,6 @@ { struct client *client = cmd->client; struct cmd_append_context *ctx = cmd->context; - size_t size; int ret = 0; if (cmd->cancel) { @@ -736,8 +733,7 @@ if (ctx->save_ctx == NULL) { (void)i_stream_read(ctx->input); - (void)i_stream_get_data(ctx->input, &size); - i_stream_skip(ctx->input, size); + i_stream_skip(ctx->input, i_stream_get_data_size(ctx->input)); } if (ctx->litinput->eof || client->input->closed) { diff -r d0d7b810646b -r 9646f80ac3e9 src/imap/imap-client.c --- a/src/imap/imap-client.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/imap/imap-client.c Mon Jun 25 02:15:22 2012 +0300 @@ -600,8 +600,6 @@ void client_continue_pending_input(struct client *client) { - size_t size; - i_assert(!client->handling_input); if (client->input_lock != NULL) { @@ -626,8 +624,8 @@ client_add_missing_io(client); /* if there's unread data in buffer, handle it. */ - (void)i_stream_get_data(client->input, &size); - if (size > 0 && !client->disconnected) { + if (i_stream_get_data_size(client->input) > 0 && + !client->disconnected) { if (client_handle_input(client)) client_continue_pending_input(client); } @@ -750,8 +748,6 @@ static bool client_handle_next_command(struct client *client, bool *remove_io_r) { - size_t size; - *remove_io_r = FALSE; if (client->input_lock != NULL) { @@ -772,8 +768,7 @@ /* don't bother creating a new client command before there's at least some input */ - (void)i_stream_get_data(client->input, &size); - if (size == 0) + if (i_stream_get_data_size(client->input) == 0) return FALSE; /* beginning a new command */ diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-dict/dict-client.c --- a/src/lib-dict/dict-client.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-dict/dict-client.c Mon Jun 25 02:15:22 2012 +0300 @@ -669,15 +669,13 @@ static void dict_async_input(struct client_dict *dict) { char *line; - size_t size; int ret; i_assert(!dict->in_iteration); do { ret = client_dict_read_one_line(dict, &line); - (void)i_stream_get_data(dict->input, &size); - } while (ret == 0 && size > 0); + } while (ret == 0 && i_stream_get_data_size(dict->input) > 0); if (ret < 0) io_remove(&dict->io); diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-mail/istream-dot.c --- a/src/lib-mail/istream-dot.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-mail/istream-dot.c Mon Jun 25 02:15:22 2012 +0300 @@ -27,7 +27,7 @@ size_t size, avail; ssize_t ret; - (void)i_stream_get_data(stream->parent, &size); + size = i_stream_get_data_size(stream->parent); if (size == 0) { ret = i_stream_read(stream->parent); if (ret <= 0 && (ret != -2 || stream->skip == 0)) { @@ -40,7 +40,7 @@ } return ret; } - (void)i_stream_get_data(stream->parent, &size); + size = i_stream_get_data_size(stream->parent); i_assert(size != 0); } diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-mail/istream-header-filter.c --- a/src/lib-mail/istream-header-filter.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-mail/istream-header-filter.c Mon Jun 25 02:15:22 2012 +0300 @@ -407,7 +407,7 @@ while (!mstream->header_read && i_stream_read(&mstream->istream.istream) != -1) { - (void)i_stream_get_data(&mstream->istream.istream, &pos); + pos = i_stream_get_data_size(&mstream->istream.istream); i_stream_skip(&mstream->istream.istream, pos); } } diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-mail/istream-nonuls.c --- a/src/lib-mail/istream-nonuls.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-mail/istream-nonuls.c Mon Jun 25 02:15:22 2012 +0300 @@ -11,11 +11,9 @@ static int i_stream_read_parent(struct istream_private *stream) { - size_t size; ssize_t ret; - (void)i_stream_get_data(stream->parent, &size); - if (size > 0) + if (i_stream_get_data_size(stream->parent) > 0) return 1; ret = i_stream_read(stream->parent); @@ -24,8 +22,7 @@ stream->istream.eof = stream->parent->eof; return ret; } - (void)i_stream_get_data(stream->parent, &size); - i_assert(size != 0); + i_assert(i_stream_get_data_size(stream->parent) != 0); return 1; } diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-mail/message-parser.c Mon Jun 25 02:15:22 2012 +0300 @@ -505,7 +505,6 @@ { struct message_part *part = ctx->part; struct message_header_line *hdr; - size_t size; int ret; if (ctx->skip > 0) { @@ -515,8 +514,7 @@ ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr); if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 0)) { - (void)i_stream_get_data(ctx->input, &size); - ctx->want_count = size + 1; + ctx->want_count = i_stream_get_data_size(ctx->input) + 1; return ret; } @@ -890,13 +888,11 @@ struct message_block *block_r) { struct message_header_line *hdr; - size_t size; int ret; ret = message_parse_header_next(ctx->hdr_parser_ctx, &hdr); if (ret == 0 || (ret < 0 && ctx->input->stream_errno != 0)) { - (void)i_stream_get_data(ctx->input, &size); - ctx->want_count = size + 1; + ctx->want_count = i_stream_get_data_size(ctx->input) + 1; return ret; } diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-storage/index/istream-mail.c --- a/src/lib-storage/index/istream-mail.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-storage/index/istream-mail.c Mon Jun 25 02:15:22 2012 +0300 @@ -65,7 +65,7 @@ stream->istream.v_offset); ret = i_stream_read_copy_from_parent(&stream->istream); - (void)i_stream_get_data(&stream->istream, &size); + size = i_stream_get_data_size(&stream->istream); if (ret > 0) { mstream->mail->transaction->stats.files_read_bytes += ret; if (!mstream->files_read_increased) { diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-storage/index/mbox/istream-raw-mbox.c --- a/src/lib-storage/index/mbox/istream-raw-mbox.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c Mon Jun 25 02:15:22 2012 +0300 @@ -527,7 +527,6 @@ struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream->real_stream; uoff_t offset; - size_t pos; i_assert(rstream->seeked); @@ -537,8 +536,7 @@ offset = stream->v_offset; i_stream_seek(stream, rstream->hdr_offset); while (rstream->body_offset == (uoff_t)-1) { - (void)i_stream_get_data(stream, &pos); - i_stream_skip(stream, pos); + i_stream_skip(stream, i_stream_get_data_size(stream)); if (i_stream_raw_mbox_read(&rstream->istream) < 0) { if (rstream->corrupted) { diff -r d0d7b810646b -r 9646f80ac3e9 src/lib-storage/index/pop3c/pop3c-client.c --- a/src/lib-storage/index/pop3c/pop3c-client.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib-storage/index/pop3c/pop3c-client.c Mon Jun 25 02:15:22 2012 +0300 @@ -727,15 +727,13 @@ static void pop3c_client_dot_input(struct pop3c_client *client) { ssize_t ret; - size_t size; if (client->to != NULL) timeout_reset(client->to); while ((ret = i_stream_read(client->dot_input)) > 0 || ret == -2) { - (void)i_stream_get_data(client->dot_input, &size); - i_stream_skip(client->dot_input, size); + i_stream_skip(client->dot_input, + i_stream_get_data_size(client->dot_input)); } - (void)i_stream_get_data(client->dot_input, &size); if (ret != 0) { i_assert(ret == -1); if (client->dot_input->stream_errno != 0) { diff -r d0d7b810646b -r 9646f80ac3e9 src/lib/istream-base64-encoder.c --- a/src/lib/istream-base64-encoder.c Mon Jun 25 01:14:03 2012 +0300 +++ b/src/lib/istream-base64-encoder.c Mon Jun 25 02:15:22 2012 +0300 @@ -21,7 +21,7 @@ size_t size; ssize_t ret; - (void)i_stream_get_data(stream->parent, &size); + size = i_stream_get_data_size(stream->parent); if (size >= 4) return 1; From dovecot at dovecot.org Mon Jun 25 02:38:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 02:38:46 +0300 Subject: dovecot-2.2: seq-range-array: Reverted most of recent API changes. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/67b9119fbd09 changeset: 14685:67b9119fbd09 user: Timo Sirainen date: Mon Jun 25 02:22:12 2012 +0300 description: seq-range-array: Reverted most of recent API changes. Added ATTR_NOWARN_UNUSED_RESULT for the functions whose return value can safely be ignored. diffstat: src/lib-index/mail-index-transaction-update.c | 2 +- src/lib-storage/index/dbox-multi/mdbox-sync.c | 2 +- src/lib-storage/index/index-sync.c | 12 ++-- src/lib-storage/mailbox-search-result.c | 2 +- src/lib/seq-range-array.c | 67 +++++++++----------------- src/lib/seq-range-array.h | 32 +++++------- src/lib/test-seq-range-array.c | 4 +- src/plugins/fts/fts-expunge-log.c | 2 +- src/plugins/virtual/virtual-sync.c | 2 +- 9 files changed, 49 insertions(+), 76 deletions(-) diffs (truncated from 327 to 300 lines): diff -r b39e93576e6a -r 67b9119fbd09 src/lib-index/mail-index-transaction-update.c --- a/src/lib-index/mail-index-transaction-update.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib-index/mail-index-transaction-update.c Mon Jun 25 02:22:12 2012 +0300 @@ -1148,7 +1148,7 @@ static bool mail_index_cancel_array(ARRAY_TYPE(seq_range) *array, uint32_t seq) { if (array_is_created(array)) { - if (seq_range_array_try_remove(array, seq)) { + if (seq_range_array_remove(array, seq)) { if (array_count(array) == 0) array_free(array); return TRUE; diff -r b39e93576e6a -r 67b9119fbd09 src/lib-storage/index/dbox-multi/mdbox-sync.c --- a/src/lib-storage/index/dbox-multi/mdbox-sync.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c Mon Jun 25 02:22:12 2012 +0300 @@ -52,7 +52,7 @@ { uint32_t map_uid; - if (seq_range_array_try_add(&ctx->expunged_seqs, seq)) { + if (seq_range_array_add(&ctx->expunged_seqs, seq)) { /* already marked as expunged in this sync */ return 0; } diff -r b39e93576e6a -r 67b9119fbd09 src/lib-storage/index/index-sync.c --- a/src/lib-storage/index/index-sync.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib-storage/index/index-sync.c Mon Jun 25 02:22:12 2012 +0300 @@ -129,7 +129,7 @@ for (; seq1 <= seq2; seq1++) { mail_index_lookup_uid(box->view, seq1, &uid); - if (seq_range_array_try_remove(&ibox->recent_flags, uid)) + if (seq_range_array_remove(&ibox->recent_flags, uid)) ibox->recent_flags_count--; } } @@ -305,15 +305,15 @@ continue; ibox->recent_flags_count -= - seq_range_array_remove_range_count(&ibox->recent_flags, - start_uid + 1, uid - 1); + seq_range_array_remove_range(&ibox->recent_flags, + start_uid + 1, uid - 1); } if (uid + 1 < hdr->next_uid) { ibox->recent_flags_count -= - seq_range_array_remove_range_count(&ibox->recent_flags, - uid + 1, - hdr->next_uid - 1); + seq_range_array_remove_range(&ibox->recent_flags, + uid + 1, + hdr->next_uid - 1); } #ifdef DEBUG if (!mail_index_view_is_inconsistent(view)) { diff -r b39e93576e6a -r 67b9119fbd09 src/lib-storage/mailbox-search-result.c --- a/src/lib-storage/mailbox-search-result.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib-storage/mailbox-search-result.c Mon Jun 25 02:22:12 2012 +0300 @@ -131,7 +131,7 @@ void mailbox_search_result_remove(struct mail_search_result *result, uint32_t uid) { - if (seq_range_array_try_remove(&result->uids, uid)) { + if (seq_range_array_remove(&result->uids, uid)) { if (array_is_created(&result->removed_uids)) { seq_range_array_add(&result->removed_uids, uid); seq_range_array_remove(&result->added_uids, uid); diff -r b39e93576e6a -r 67b9119fbd09 src/lib/seq-range-array.c --- a/src/lib/seq-range-array.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib/seq-range-array.c Mon Jun 25 02:22:12 2012 +0300 @@ -4,8 +4,9 @@ #include "array.h" #include "seq-range-array.h" -static bool seq_range_lookup(const ARRAY_TYPE(seq_range) *array, - uint32_t seq, unsigned int *idx_r) +static bool ATTR_NOWARN_UNUSED_RESULT +seq_range_lookup(const ARRAY_TYPE(seq_range) *array, + uint32_t seq, unsigned int *idx_r) { const struct seq_range *data; unsigned int idx, left_idx, right_idx, count; @@ -33,7 +34,7 @@ return FALSE; } -bool seq_range_array_try_add(ARRAY_TYPE(seq_range) *array, uint32_t seq) +bool seq_range_array_add(ARRAY_TYPE(seq_range) *array, uint32_t seq) { struct seq_range *data, value; unsigned int idx, count; @@ -100,17 +101,12 @@ return FALSE; } -void seq_range_array_add(ARRAY_TYPE(seq_range) *array, uint32_t seq) -{ - (void)seq_range_array_try_add(array, seq); -} - void seq_range_array_add_with_init(ARRAY_TYPE(seq_range) *array, unsigned int init_count, uint32_t seq) { if (!array_is_created(array)) i_array_init(array, init_count); - (void)seq_range_array_try_add(array, seq); + seq_range_array_add(array, seq); } void seq_range_array_add_range(ARRAY_TYPE(seq_range) *array, @@ -119,8 +115,8 @@ struct seq_range *data, value; unsigned int idx1, idx2, count; - (void)seq_range_lookup(array, seq1, &idx1); - (void)seq_range_lookup(array, seq2, &idx2); + seq_range_lookup(array, seq1, &idx1); + seq_range_lookup(array, seq2, &idx2); data = array_get_modifiable(array, &count); if (idx1 > 0 && data[idx1-1].seq2+1 == seq1) @@ -166,12 +162,7 @@ seq_range_array_add_range(dest, range->seq1, range->seq2); } -void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) -{ - (void)seq_range_array_remove(array, seq); -} - -bool seq_range_array_try_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) +bool seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq) { struct seq_range *data, value; unsigned int idx, left_idx, right_idx, count; @@ -243,20 +234,8 @@ return FALSE; } -void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array, - uint32_t seq1, uint32_t seq2) -{ - (void)seq_range_array_remove_range_count(array, seq1, seq2); -} - -void seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src) -{ - (void)seq_range_array_remove_seq_range_count(dest, src); -} - -unsigned int seq_range_array_remove_range_count(ARRAY_TYPE(seq_range) *array, - uint32_t seq1, uint32_t seq2) +unsigned int seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array, + uint32_t seq1, uint32_t seq2) { const struct seq_range *data; unsigned int idx, idx2, count, remove_count = 0; @@ -266,20 +245,20 @@ FIXME: it would be faster if we did only one binary lookup here and handled the splitting ourself.. */ - if (seq_range_array_try_remove(array, seq1)) + if (seq_range_array_remove(array, seq1)) remove_count++; if (seq1 == seq2) return remove_count; seq1++; - if (seq_range_array_try_remove(array, seq2--)) + if (seq_range_array_remove(array, seq2--)) remove_count++; if (seq1 > seq2) return remove_count; /* find the beginning */ data = array_get(array, &count); - (void)seq_range_lookup(array, seq1, &idx); + seq_range_lookup(array, seq1, &idx); if (idx == count) return remove_count; @@ -294,22 +273,21 @@ return remove_count; } -unsigned int -seq_range_array_remove_seq_range_count(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src) +unsigned int seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest, + const ARRAY_TYPE(seq_range) *src) { unsigned int ret = 0; const struct seq_range *src_range; array_foreach(src, src_range) { - ret += seq_range_array_remove_range_count(dest, src_range->seq1, - src_range->seq2); + ret += seq_range_array_remove_range(dest, src_range->seq1, + src_range->seq2); } return ret; } -void seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src) +unsigned int seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest, + const ARRAY_TYPE(seq_range) *src) { const struct seq_range *src_range; unsigned int i, count, ret = 0; @@ -318,15 +296,16 @@ src_range = array_get(src, &count); for (i = 0; i < count; i++) { if (last_seq + 1 < src_range[i].seq1) { - ret += seq_range_array_remove_range_count(dest, + ret += seq_range_array_remove_range(dest, last_seq + 1, src_range[i].seq1 - 1); } last_seq = src_range[i].seq2; } if (last_seq != (uint32_t)-1) { - ret += seq_range_array_remove_range_count(dest, last_seq + 1, - (uint32_t)-1); + ret += seq_range_array_remove_range(dest, last_seq + 1, + (uint32_t)-1); } + return ret; } bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq) diff -r b39e93576e6a -r 67b9119fbd09 src/lib/seq-range-array.h --- a/src/lib/seq-range-array.h Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib/seq-range-array.h Mon Jun 25 02:22:12 2012 +0300 @@ -13,10 +13,8 @@ /* Add sequrence to range. If the array isn't created yet, create it with initial size of init_count. */ -void seq_range_array_add(ARRAY_TYPE(seq_range) *array, uint32_t seq); -/* Like seq_range_array_add(), but reutrn TRUE if seq was already in the - array. */ -bool seq_range_array_try_add(ARRAY_TYPE(seq_range) *array, uint32_t seq); +bool ATTR_NOWARN_UNUSED_RESULT +seq_range_array_add(ARRAY_TYPE(seq_range) *array, uint32_t seq); /* Like seq_range_array_add(), but if the array isn't already initialized do it with i_array_init(). */ void seq_range_array_add_with_init(ARRAY_TYPE(seq_range) *array, @@ -25,24 +23,20 @@ uint32_t seq1, uint32_t seq2); void seq_range_array_merge(ARRAY_TYPE(seq_range) *dest, const ARRAY_TYPE(seq_range) *src); -/* Remove the given sequrence from range. */ -void seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); /* Remove the given sequrence from range. Returns TRUE if it was found. */ -bool seq_range_array_try_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); -/* Remove a sequence range. */ -void seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array, - uint32_t seq1, uint32_t seq2); -void seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src); +bool ATTR_NOWARN_UNUSED_RESULT +seq_range_array_remove(ARRAY_TYPE(seq_range) *array, uint32_t seq); /* Remove a sequence range. Returns number of sequences actually removed. */ -unsigned int seq_range_array_remove_range_count(ARRAY_TYPE(seq_range) *array, - uint32_t seq1, uint32_t seq2); -unsigned int -seq_range_array_remove_seq_range_count(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src); +unsigned int ATTR_NOWARN_UNUSED_RESULT +seq_range_array_remove_range(ARRAY_TYPE(seq_range) *array, + uint32_t seq1, uint32_t seq2); +unsigned int ATTR_NOWARN_UNUSED_RESULT +seq_range_array_remove_seq_range(ARRAY_TYPE(seq_range) *dest, + const ARRAY_TYPE(seq_range) *src); /* Remove sequences from dest that don't exist in src. */ -void seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest, - const ARRAY_TYPE(seq_range) *src); +unsigned int ATTR_NOWARN_UNUSED_RESULT +seq_range_array_intersect(ARRAY_TYPE(seq_range) *dest, + const ARRAY_TYPE(seq_range) *src); /* Returns TRUE if sequence exists in the range. */ bool seq_range_exists(const ARRAY_TYPE(seq_range) *array, uint32_t seq) ATTR_PURE; diff -r b39e93576e6a -r 67b9119fbd09 src/lib/test-seq-range-array.c --- a/src/lib/test-seq-range-array.c Mon Jun 25 02:20:30 2012 +0300 +++ b/src/lib/test-seq-range-array.c Mon Jun 25 02:22:12 2012 +0300 @@ -47,12 +47,12 @@ memset(shadowbuf + seq1, 1, seq2 - seq1 + 1); break; case 2: - ret = seq_range_array_try_remove(&range, seq1) ? 1 : 0; + ret = seq_range_array_remove(&range, seq1) ? 1 : 0; ret2 = shadowbuf[seq1] != 0 ? 1 : 0; shadowbuf[seq1] = 0; break; case 3: - ret = seq_range_array_remove_range_count(&range, seq1, seq2); + ret = seq_range_array_remove_range(&range, seq1, seq2); From dovecot at dovecot.org Mon Jun 25 02:38:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 02:38:46 +0300 Subject: dovecot-2.2: Added ATTR_NOWARN_UNUSED_RESULT, which expands to n... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/b39e93576e6a changeset: 14684:b39e93576e6a user: Timo Sirainen date: Mon Jun 25 02:20:30 2012 +0300 description: Added ATTR_NOWARN_UNUSED_RESULT, which expands to nowarn_unused_result attribute if supported. Requires a patched clang. diffstat: src/lib/macros.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diffs (15 lines): diff -r 9646f80ac3e9 -r b39e93576e6a src/lib/macros.h --- a/src/lib/macros.h Mon Jun 25 02:15:22 2012 +0300 +++ b/src/lib/macros.h Mon Jun 25 02:20:30 2012 +0300 @@ -114,6 +114,11 @@ #else # define ATTR_NULL(...) #endif +#ifdef HAVE_ATTR_NOWARN_UNUSED_RESULT +# define ATTR_NOWARN_UNUSED_RESULT __attribute__((nowarn_unused_result)) +#else +# define ATTR_NOWARN_UNUSED_RESULT +#endif #if __GNUC__ > 2 # define ATTR_MALLOC __attribute__((malloc)) #else From dovecot at dovecot.org Mon Jun 25 02:38:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 02:38:46 +0300 Subject: dovecot-2.2: Added array_append_zero() to write a zero-filled re... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9ff19c1d5f69 changeset: 14686:9ff19c1d5f69 user: Timo Sirainen date: Mon Jun 25 02:38:29 2012 +0300 description: Added array_append_zero() to write a zero-filled record to an array. Replaced (void)array_append_space() calls with it. diffstat: src/auth/auth-settings.c | 2 +- src/auth/db-ldap.c | 2 +- src/config/config-filter.c | 6 +++--- src/config/config-parser.c | 4 ++-- src/doveadm/doveadm-mail-fetch.c | 2 +- src/doveadm/doveadm-mailbox-list-iter.c | 2 +- src/doveadm/dsync/doveadm-dsync.c | 4 ++-- src/doveadm/dsync/dsync-brain-mailbox.c | 4 ++-- src/doveadm/dsync/dsync-mailbox-import.c | 6 +++--- src/imap/cmd-list.c | 4 ++-- src/imap/imap-commands-util.c | 4 ++-- src/imap/imap-fetch.c | 2 +- src/lib-auth/auth-master.c | 2 +- src/lib-imap-storage/imap-msgpart.c | 2 +- src/lib-imap/imap-match.c | 2 +- src/lib-index/mail-cache-compress.c | 2 +- src/lib-index/mail-index-strmap.c | 6 +++--- src/lib-index/mail-index.c | 2 +- src/lib-mail/rfc2231-parser.c | 4 ++-- src/lib-master/master-service-settings.c | 2 +- src/lib-sql/driver-sqlpool.c | 2 +- src/lib-storage/fail-mail.c | 2 +- src/lib-storage/index/dbox-common/dbox-attachment.c | 2 +- src/lib-storage/index/imapc/imapc-mailbox.c | 2 +- src/lib-storage/index/index-mail-headers.c | 4 ++-- src/lib-storage/index/index-mail.c | 4 ++-- src/lib-storage/index/index-search.c | 2 +- src/lib-storage/index/pop3c/pop3c-sync.c | 2 +- src/lib-storage/list/mailbox-list-fs-iter.c | 2 +- src/lib-storage/mailbox-keywords.c | 2 +- src/lib/array.h | 2 ++ src/lib/ioloop-epoll.c | 2 +- src/lib/ioloop-kqueue.c | 2 +- src/lib/uri-util.c | 2 +- src/lib/var-expand.c | 2 +- src/master/main.c | 2 +- src/plugins/acl/doveadm-acl.c | 4 ++-- src/plugins/expire/doveadm-expire.c | 2 +- src/plugins/expire/expire-plugin.c | 2 +- src/plugins/fts-lucene/fts-backend-lucene.c | 2 +- src/plugins/fts-solr/fts-backend-solr-old.c | 2 +- src/plugins/fts-solr/fts-backend-solr.c | 2 +- src/plugins/fts-solr/solr-connection.c | 2 +- src/plugins/fts/fts-search.c | 2 +- src/plugins/imap-acl/imap-acl-plugin.c | 4 ++-- src/plugins/virtual/virtual-save.c | 2 +- src/util/script.c | 2 +- 47 files changed, 64 insertions(+), 62 deletions(-) diffs (truncated from 701 to 300 lines): diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/auth/auth-settings.c --- a/src/auth/auth-settings.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/auth/auth-settings.c Mon Jun 25 02:38:29 2012 +0300 @@ -299,7 +299,7 @@ } array_append(&ips_array, ips, ips_count); } - (void)array_append_space(&ips_array); + array_append_zero(&ips_array); set->proxy_self_ips = array_idx(&ips_array, 0); return TRUE; } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/auth/db-ldap.c --- a/src/auth/db-ldap.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/auth/db-ldap.c Mon Jun 25 02:38:29 2012 +0300 @@ -1063,7 +1063,7 @@ array_append(&ctx.attr_names, &ldap_attr, 1); } } - (void)array_append_space(&ctx.attr_names); + array_append_zero(&ctx.attr_names); *attr_names_r = array_idx_modifiable(&ctx.attr_names, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/config/config-filter.c --- a/src/config/config-filter.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/config/config-filter.c Mon Jun 25 02:38:29 2012 +0300 @@ -221,12 +221,12 @@ } } if (filter->service == NULL) { - (void)array_append_space(&service_names); + array_append_zero(&service_names); output_r->specific_services = array_idx(&service_names, 0); } array_sort(&matches, config_filter_parser_cmp); - (void)array_append_space(&matches); + array_append_zero(&matches); return array_idx(&matches, 0); } @@ -259,7 +259,7 @@ array_append(&matches, &ctx->parsers[i], 1); } array_sort(&matches, config_filter_parser_cmp_rev); - (void)array_append_space(&matches); + array_append_zero(&matches); return array_idx(&matches, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/config/config-parser.c --- a/src/config/config-parser.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/config/config-parser.c Mon Jun 25 02:38:29 2012 +0300 @@ -681,7 +681,7 @@ int ret; new_filter = config_filter_init(ctx->pool); - (void)array_append_space(&ctx->all_parsers); + array_append_zero(&ctx->all_parsers); config_filter_add_all(new_filter, array_idx(&ctx->all_parsers, 0)); if (ctx->hide_errors) @@ -1007,7 +1007,7 @@ using the new list. */ for (i = 0; all_roots[i] != NULL; i++) array_append(&new_roots, &all_roots[i], 1); - (void)array_append_space(&new_roots); + array_append_zero(&new_roots); all_roots = array_idx(&new_roots, 0); } if (array_count(&new_services) > 0) { diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/doveadm/doveadm-mail-fetch.c --- a/src/doveadm/doveadm-mail-fetch.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/doveadm/doveadm-mail-fetch.c Mon Jun 25 02:38:29 2012 +0300 @@ -474,7 +474,7 @@ array_append(&ctx->fields, field, 1); } } - (void)array_append_space(&ctx->header_fields); + array_append_zero(&ctx->header_fields); } static int cmd_fetch_mail(struct fetch_cmd_context *ctx) diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/doveadm/doveadm-mailbox-list-iter.c --- a/src/doveadm/doveadm-mailbox-list-iter.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/doveadm/doveadm-mailbox-list-iter.c Mon Jun 25 02:38:29 2012 +0300 @@ -100,7 +100,7 @@ without lookup ACL right */ return iter; } - (void)array_append_space(&iter->patterns); + array_append_zero(&iter->patterns); iter->only_selectable = TRUE; iter->iter_flags = iter_flags; diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/doveadm/dsync/doveadm-dsync.c --- a/src/doveadm/dsync/doveadm-dsync.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/doveadm/dsync/doveadm-dsync.c Mon Jun 25 02:38:29 2012 +0300 @@ -125,7 +125,7 @@ p = "dsync-server"; } array_append(&cmd_args, &p, 1); - (void)array_append_space(&cmd_args); + array_append_zero(&cmd_args); *cmd_args_r = array_idx(&cmd_args, 0); } @@ -177,7 +177,7 @@ } array_append(&cmd_args, &value, 1); } - (void)array_append_space(&cmd_args); + array_append_zero(&cmd_args); return array_idx(&cmd_args, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/doveadm/dsync/dsync-brain-mailbox.c --- a/src/doveadm/dsync/dsync-brain-mailbox.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/doveadm/dsync/dsync-brain-mailbox.c Mon Jun 25 02:38:29 2012 +0300 @@ -420,7 +420,7 @@ if (array_count(&local_sorted) == 0) { /* local has no cached fields. set them to same as remote. */ - (void)array_append_space(&remote_sorted); + array_append_zero(&remote_sorted); update->cache_updates = array_idx(&remote_sorted, 0); return; } @@ -464,7 +464,7 @@ } i_assert(li == local_count && ri == remote_count); if (array_count(&changes) > 0) { - (void)array_append_space(&changes); + array_append_zero(&changes); update->cache_updates = array_idx(&changes, 0); } } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/doveadm/dsync/dsync-mailbox-import.c --- a/src/doveadm/dsync/dsync-mailbox-import.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/doveadm/dsync/dsync-mailbox-import.c Mon Jun 25 02:38:29 2012 +0300 @@ -619,14 +619,14 @@ /* apply changes */ if (array_count(&add_keywords) > 0) { - (void)array_append_space(&add_keywords); + array_append_zero(&add_keywords); kw = mailbox_keywords_create_valid(mail->box, array_idx(&add_keywords, 0)); mail_update_keywords(mail, MODIFY_ADD, kw); mailbox_keywords_unref(&kw); } if (array_count(&remove_keywords) > 0) { - (void)array_append_space(&remove_keywords); + array_append_zero(&remove_keywords); kw = mailbox_keywords_create_valid(mail->box, array_idx(&remove_keywords, 0)); mail_update_keywords(mail, MODIFY_REMOVE, kw); @@ -1068,7 +1068,7 @@ if (array_count(&keywords) == 0) return NULL; - (void)array_append_space(&keywords); + array_append_zero(&keywords); return array_idx(&keywords, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/imap/cmd-list.c --- a/src/imap/cmd-list.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/imap/cmd-list.c Mon Jun 25 02:38:29 2012 +0300 @@ -786,7 +786,7 @@ pattern = "INBOX"; array_append(&used_patterns, &pattern, 1); } - (void)array_append_space(&used_patterns); /* NULL-terminate */ + array_append_zero(&used_patterns); /* NULL-terminate */ pat = array_idx(&used_patterns, 0); ctx->list_iter = mailbox_list_iter_init_multiple(ns->list, pat, @@ -996,7 +996,7 @@ return TRUE; } - (void)array_append_space(&patterns); /* NULL-terminate */ + array_append_zero(&patterns); /* NULL-terminate */ patterns_strarr = array_idx(&patterns, 0); if (!ctx->used_listext && !lsub && *patterns_strarr[0] == '\0') { /* Only LIST ref "" gets us here */ diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/imap/imap-commands-util.c --- a/src/imap/imap-commands-util.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/imap/imap-commands-util.c Mon Jun 25 02:38:29 2012 +0300 @@ -232,7 +232,7 @@ if (array_count(&keywords) == 0) *keywords_r = NULL; else { - (void)array_append_space(&keywords); /* NULL-terminate */ + array_append_zero(&keywords); /* NULL-terminate */ *keywords_r = array_idx(&keywords, 0); } return TRUE; @@ -309,7 +309,7 @@ array_append(dest, &all_names[kw_index], 1); } - (void)array_append_space(dest); + array_append_zero(dest); return array_idx(dest, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/imap/imap-fetch.c --- a/src/imap/imap-fetch.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/imap/imap-fetch.c Mon Jun 25 02:38:29 2012 +0300 @@ -348,7 +348,7 @@ if (array_count(&ctx->all_headers) > 0 && ((ctx->fetch_data & (MAIL_FETCH_STREAM_HEADER | MAIL_FETCH_STREAM_BODY)) == 0)) { - (void)array_append_space(&ctx->all_headers); + array_append_zero(&ctx->all_headers); data = array_idx(&ctx->all_headers, 0); ctx->all_headers_ctx = diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-auth/auth-master.c --- a/src/lib-auth/auth-master.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/lib-auth/auth-master.c Mon Jun 25 02:38:29 2012 +0300 @@ -186,7 +186,7 @@ array_append(&new_args, &args[i], 1); } } - (void)array_append_space(&new_args); + array_append_zero(&new_args); return array_idx(&new_args, 0); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-imap-storage/imap-msgpart.c --- a/src/lib-imap-storage/imap-msgpart.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/lib-imap-storage/imap-msgpart.c Mon Jun 25 02:38:29 2012 +0300 @@ -175,7 +175,7 @@ &fields) < 0) return -1; - (void)array_append_space(&fields); + array_append_zero(&fields); msgpart->headers = array_idx(&fields, 0); msgpart->header_ctx = mailbox_header_lookup_init(box, msgpart->headers); return 0; diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-imap/imap-match.c --- a/src/lib-imap/imap-match.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/lib-imap/imap-match.c Mon Jun 25 02:38:29 2012 +0300 @@ -189,7 +189,7 @@ inboxcase = TRUE; array_append(&patterns, &p->pattern, 1); } - (void)array_append_space(&patterns); + array_append_zero(&patterns); return imap_match_init_multiple_real(pool, array_idx(&patterns, 0), inboxcase, glob->sep); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-index/mail-cache-compress.c --- a/src/lib-index/mail-cache-compress.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/lib-index/mail-cache-compress.c Mon Jun 25 02:38:29 2012 +0300 @@ -234,7 +234,7 @@ i_array_init(ext_offsets, message_count); for (seq = 1; seq <= message_count; seq++) { if (mail_index_transaction_is_expunged(trans, seq)) { - (void)array_append_space(ext_offsets); + array_append_zero(ext_offsets); continue; } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-index/mail-index-strmap.c --- a/src/lib-index/mail-index-strmap.c Mon Jun 25 02:22:12 2012 +0300 +++ b/src/lib-index/mail-index-strmap.c Mon Jun 25 02:38:29 2012 +0300 @@ -803,7 +803,7 @@ rec.ref_index = ref_index; rec.str_idx = view->next_str_idx++; array_append(&view->recs, &rec, 1); - (void)array_append_space(&view->recs_crc32); + array_append_zero(&view->recs_crc32); view->last_added_uid = uid; view->last_ref_index = ref_index; @@ -813,7 +813,7 @@ mail_index_strmap_zero_terminate(struct mail_index_strmap_view *view) { /* zero-terminate the records array */ - (void)array_append_space(&view->recs); + array_append_zero(&view->recs); array_delete(&view->recs, array_count(&view->recs)-1, 1); } @@ -1238,7 +1238,7 @@ mail_index_strmap_zero_terminate(view); /* zero-terminate the records array */ - (void)array_append_space(&view->recs); + array_append_zero(&view->recs); array_delete(&view->recs, array_count(&view->recs)-1, 1); } diff -r 67b9119fbd09 -r 9ff19c1d5f69 src/lib-index/mail-index.c From dovecot at dovecot.org Mon Jun 25 02:52:43 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 02:52:43 +0300 Subject: dovecot-2.2: Replaced (void)close(fd) and close_keep_errno() wit... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/7c058aa05b0a changeset: 14687:7c058aa05b0a user: Timo Sirainen date: Mon Jun 25 02:52:33 2012 +0300 description: Replaced (void)close(fd) and close_keep_errno() with i_close_fd(). i_close_fd() preserves the errno and logs an error if the close() fails. diffstat: src/auth/db-checkpassword.c | 16 ++++++++-------- src/auth/db-passwd-file.c | 2 +- src/auth/mech-winbind.c | 14 +++++++------- src/config/config-parser.c | 2 +- src/config/sysinfo-get.c | 2 +- src/director/director-test.c | 2 +- src/doveadm/doveadm-dump-log.c | 2 +- src/doveadm/doveadm-dump-mailboxlog.c | 2 +- src/doveadm/doveadm-instance.c | 2 +- src/doveadm/doveadm-master.c | 2 +- src/doveadm/doveadm-sis.c | 2 +- src/doveadm/doveadm-stats.c | 2 +- src/doveadm/dsync/doveadm-dsync.c | 20 ++++++++++---------- src/doveadm/dsync/dsync-slave-io.c | 3 +-- src/imap/main.c | 2 +- src/lda/main.c | 3 +-- src/lib-dict/dict-file.c | 10 +++++----- src/lib-dns/dns-lookup.c | 2 +- src/lib-imap-client/imapc-client.c | 2 +- src/lib-index/mail-cache-compress.c | 5 ++--- src/lib-index/mail-transaction-log.c | 1 - src/lib-lda/smtp-client.c | 9 ++++----- src/lib-master/master-login.c | 2 +- src/lib-master/master-service-settings.c | 6 +++--- src/lib-master/mountpoint-list.c | 4 ++-- src/lib-settings/settings-parser.c | 8 ++++---- src/lib-storage/index/index-attachment.c | 2 +- src/lib-storage/index/maildir/maildir-storage.c | 2 +- src/lib-storage/index/maildir/maildir-uidlist.c | 5 ++--- src/lib-storage/index/mbox/mbox-file.c | 2 +- src/lib-storage/index/mbox/mbox-lock.c | 6 +++--- src/lib-storage/index/mbox/mbox-storage.c | 4 ++-- src/lib-storage/index/pop3c/pop3c-client.c | 3 +-- src/lib-storage/list/mailbox-list-maildir.c | 2 +- src/lib-storage/mailbox-uidvalidity.c | 6 +++--- src/lib/Makefile.am | 2 -- src/lib/askpass.c | 2 +- src/lib/close-keep-errno.c | 13 ------------- src/lib/close-keep-errno.h | 7 ------- src/lib/failures.c | 6 +++--- src/lib/fdatasync-path.c | 2 +- src/lib/file-copy.c | 4 ++-- src/lib/file-dotlock.c | 6 +++--- src/lib/ioloop-notify-dn.c | 4 ++-- src/lib/ioloop-notify-kqueue.c | 2 +- src/lib/iostream-rawlog.c | 2 +- src/lib/istream-seekable.c | 5 ++--- src/lib/macros.h | 8 ++++++++ src/lib/network.c | 17 ++++++++--------- src/lib/nfs-workarounds.c | 6 +++--- src/lib/randgen.c | 2 +- src/lib/safe-mkstemp.c | 2 +- src/lib/test-ostream-file.c | 2 +- src/lib/unlink-directory.c | 13 ++++++------- src/lmtp/commands.c | 2 +- src/login-common/access-lookup.c | 2 +- src/login-common/ssl-proxy-gnutls.c | 2 +- src/master/main.c | 6 +++--- src/master/service-listen.c | 4 ++-- src/master/service-monitor.c | 2 +- src/master/service.c | 2 +- src/plugins/acl/acl-backend-vfile-acllist.c | 2 +- src/plugins/acl/acl-backend-vfile.c | 6 +++--- src/plugins/fts-lucene/fts-backend-lucene.c | 2 +- src/plugins/fts-squat/squat-trie.c | 2 +- src/plugins/fts/doveadm-dump-fts-expunge-log.c | 2 +- src/plugins/fts/fts-expunge-log.c | 2 +- src/plugins/fts/fts-indexer.c | 2 +- src/plugins/fts/fts-parser-script.c | 4 ++-- src/plugins/quota/quota-maildir.c | 10 +++++----- src/plugins/trash/trash-plugin.c | 2 +- src/plugins/virtual/virtual-config.c | 2 +- src/plugins/zlib/doveadm-zlib.c | 2 +- src/plugins/zlib/zlib-plugin.c | 2 +- src/pop3/main.c | 2 +- src/ssl-params/ssl-params.c | 6 +++--- src/util/gdbhelper.c | 2 +- src/util/rawlog.c | 12 ++++++------ 78 files changed, 161 insertions(+), 185 deletions(-) diffs (truncated from 1576 to 300 lines): diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/auth/db-checkpassword.c --- a/src/auth/db-checkpassword.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/auth/db-checkpassword.c Mon Jun 25 02:52:33 2012 +0300 @@ -473,8 +473,8 @@ auth_request_log_error(request, "checkpassword", "pipe() failed: %m"); if (fd_in[0] != -1) { - (void)close(fd_in[0]); - (void)close(fd_in[1]); + i_close_fd(fd_in[0]); + i_close_fd(fd_in[1]); } callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE, NULL, request_callback); @@ -485,10 +485,10 @@ if (pid == -1) { auth_request_log_error(request, "checkpassword", "fork() failed: %m"); - (void)close(fd_in[0]); - (void)close(fd_in[1]); - (void)close(fd_out[0]); - (void)close(fd_out[1]); + i_close_fd(fd_in[0]); + i_close_fd(fd_in[1]); + i_close_fd(fd_out[0]); + i_close_fd(fd_out[1]); callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE, NULL, request_callback); return; @@ -496,8 +496,8 @@ if (pid == 0) { /* child */ - (void)close(fd_in[0]); - (void)close(fd_out[1]); + i_close_fd(fd_in[0]); + i_close_fd(fd_out[1]); checkpassword_exec(db, request, fd_in[1], fd_out[0], auth_password != NULL); /* not reached */ diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/auth/db-passwd-file.c --- a/src/auth/db-passwd-file.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/auth/db-passwd-file.c Mon Jun 25 02:52:33 2012 +0300 @@ -184,7 +184,7 @@ if (fstat(fd, &st) != 0) { i_error("passwd-file %s: fstat() failed: %m", pw->path); - (void)close(fd); + i_close_fd(fd); return FALSE; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/auth/mech-winbind.c --- a/src/auth/mech-winbind.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/auth/mech-winbind.c Mon Jun 25 02:52:33 2012 +0300 @@ -111,15 +111,15 @@ return; } if (pipe(outfd) < 0) { - (void)close(infd[0]); (void)close(infd[1]); + i_close_fd(infd[0]); i_close_fd(infd[1]); return; } pid = fork(); if (pid < 0) { i_error("fork() failed: %m"); - (void)close(infd[0]); (void)close(infd[1]); - (void)close(outfd[0]); (void)close(outfd[1]); + i_close_fd(infd[0]); i_close_fd(infd[1]); + i_close_fd(outfd[0]); i_close_fd(outfd[1]); return; } @@ -127,8 +127,8 @@ /* child */ const char *args[3]; - (void)close(infd[0]); - (void)close(outfd[1]); + i_close_fd(infd[0]); + i_close_fd(outfd[1]); if (dup2(outfd[0], STDIN_FILENO) < 0 || dup2(infd[1], STDOUT_FILENO) < 0) @@ -141,8 +141,8 @@ } /* parent */ - (void)close(infd[1]); - (void)close(outfd[0]); + i_close_fd(infd[1]); + i_close_fd(outfd[0]); winbind->pid = pid; winbind->in_pipe = diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/config/config-parser.c --- a/src/config/config-parser.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/config/config-parser.c Mon Jun 25 02:52:33 2012 +0300 @@ -439,7 +439,7 @@ *error_r = t_strdup_printf("%s: read(%s) failed: %m", key, path); } - (void)close(fd); + i_close_fd(fd); return ret < 0 ? -1 : 0; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/config/sysinfo-get.c --- a/src/config/sysinfo-get.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/config/sysinfo-get.c Mon Jun 25 02:52:33 2012 +0300 @@ -21,7 +21,7 @@ if (fd == -1) return FALSE; ret = read(fd, buf, sizeof(buf)); - (void)close(fd); + i_close_fd(fd); if (ret <= 0) return FALSE; diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/director/director-test.c --- a/src/director/director-test.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/director/director-test.c Mon Jun 25 02:52:33 2012 +0300 @@ -338,7 +338,7 @@ out_fd = net_connect_ip(local_ip, DIRECTOR_OUT_PORT, NULL); if (out_fd == -1) { - (void)close(in_fd); + i_close_fd(in_fd); return; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-dump-log.c --- a/src/doveadm/doveadm-dump-log.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-dump-log.c Mon Jun 25 02:52:33 2012 +0300 @@ -509,7 +509,7 @@ hdr.major_version == MAIL_TRANSACTION_LOG_MAJOR_VERSION && hdr.hdr_size >= MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE) ret = TRUE; - (void)close(fd); + i_close_fd(fd); return ret; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-dump-mailboxlog.c --- a/src/doveadm/doveadm-dump-mailboxlog.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-dump-mailboxlog.c Mon Jun 25 02:52:33 2012 +0300 @@ -100,7 +100,7 @@ break; } } - (void)close(fd); + i_close_fd(fd); return ret; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Mon Jun 25 02:52:33 2012 +0300 @@ -39,7 +39,7 @@ (kill(pid, 0) < 0 && errno == ESRCH)); } } - (void)close(fd); + i_close_fd(fd); return found; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-master.c --- a/src/doveadm/doveadm-master.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-master.c Mon Jun 25 02:52:33 2012 +0300 @@ -41,7 +41,7 @@ (kill(*pid_r, 0) < 0 && errno == ESRCH)); } } - (void)close(fd); + i_close_fd(fd); return found; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-sis.c --- a/src/doveadm/doveadm-sis.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-sis.c Mon Jun 25 02:52:33 2012 +0300 @@ -48,7 +48,7 @@ if (fd1 == -1) { if (errno != ENOENT) i_error("open(%s) failed: %m", path2); - (void)close(fd1); + i_close_fd(fd1); return -1; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/doveadm-stats.c --- a/src/doveadm/doveadm-stats.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/doveadm-stats.c Mon Jun 25 02:52:33 2012 +0300 @@ -496,7 +496,7 @@ array_free(&ctx.lines); pool_unref(&ctx.prev_pool); pool_unref(&ctx.cur_pool); - (void)close(ctx.fd); + i_close_fd(ctx.fd); } static void cmd_stats_top(int argc, char *argv[]) diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/dsync/doveadm-dsync.c --- a/src/doveadm/dsync/doveadm-dsync.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/dsync/doveadm-dsync.c Mon Jun 25 02:52:33 2012 +0300 @@ -79,12 +79,12 @@ dup2(fd_err[1], STDERR_FILENO) < 0) i_fatal("dup2() failed: %m"); - (void)close(fd_in[0]); - (void)close(fd_in[1]); - (void)close(fd_out[0]); - (void)close(fd_out[1]); - (void)close(fd_err[0]); - (void)close(fd_err[1]); + i_close_fd(fd_in[0]); + i_close_fd(fd_in[1]); + i_close_fd(fd_out[0]); + i_close_fd(fd_out[1]); + i_close_fd(fd_err[0]); + i_close_fd(fd_err[1]); execvp_const(args[0], args); default: @@ -92,9 +92,9 @@ break; } - (void)close(fd_in[0]); - (void)close(fd_out[1]); - (void)close(fd_err[1]); + i_close_fd(fd_in[0]); + i_close_fd(fd_out[1]); + i_close_fd(fd_err[1]); ctx->fd_in = fd_out[0]; ctx->fd_out = fd_in[1]; ctx->fd_err = fd_err[0]; @@ -363,7 +363,7 @@ if (ctx->io_err != NULL) io_remove(&ctx->io_err); if (ctx->fd_err != -1) { - (void)close(ctx->fd_err); + i_close_fd(ctx->fd_err); ctx->fd_err = -1; } return ret; diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/doveadm/dsync/dsync-slave-io.c --- a/src/doveadm/dsync/dsync-slave-io.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave-io.c Mon Jun 25 02:52:33 2012 +0300 @@ -2,7 +2,6 @@ #include "lib.h" #include "array.h" -#include "close-keep-errno.h" #include "fd-set-nonblock.h" #include "safe-mkstemp.h" #include "ioloop.h" @@ -1366,7 +1365,7 @@ if (unlink(str_c(path)) < 0) { /* shouldn't happen.. */ i_error("unlink(%s) failed: %m", str_c(path)); - close_keep_errno(fd); + i_close_fd(fd); return -1; } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/imap/main.c --- a/src/imap/main.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/imap/main.c Mon Jun 25 02:52:33 2012 +0300 @@ -277,7 +277,7 @@ i_error("write(client) failed: %m"); } i_error("%s", error); - (void)close(client->fd); + i_close_fd(client->fd); master_service_client_connection_destroyed(master_service); } } diff -r 9ff19c1d5f69 -r 7c058aa05b0a src/lda/main.c --- a/src/lda/main.c Mon Jun 25 02:38:29 2012 +0300 +++ b/src/lda/main.c Mon Jun 25 02:52:33 2012 +0300 @@ -4,7 +4,6 @@ #include "lib-signals.h" #include "env-util.h" #include "fd-set-nonblock.h" -#include "close-keep-errno.h" #include "istream.h" #include "istream-seekable.h" #include "abspath.h" @@ -102,7 +101,7 @@ if (unlink(str_c(path)) < 0) { /* shouldn't happen.. */ i_error("unlink(%s) failed: %m", str_c(path)); - close_keep_errno(fd); + i_close_fd(fd); return -1; } From dovecot at dovecot.org Mon Jun 25 19:40:32 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Mon, 25 Jun 2012 19:40:32 +0300 Subject: dovecot-2.1: imapc: Fixed crash on saving/copying if remote IMAP... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/20703dbd1168 changeset: 14578:20703dbd1168 user: Timo Sirainen date: Mon Jun 25 19:40:24 2012 +0300 description: imapc: Fixed crash on saving/copying if remote IMAP server didn't support UIDPLUS. diffstat: src/lib-storage/index/imapc/imapc-save.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diffs (23 lines): diff -r edb8d177bd37 -r 20703dbd1168 src/lib-storage/index/imapc/imapc-save.c --- a/src/lib-storage/index/imapc/imapc-save.c Mon Jun 25 00:18:31 2012 +0300 +++ b/src/lib-storage/index/imapc/imapc-save.c Mon Jun 25 19:40:24 2012 +0300 @@ -165,7 +165,8 @@ uint32_t uid = 0; if (reply->state == IMAPC_COMMAND_STATE_OK) { - if (strcasecmp(reply->resp_text_key, "APPENDUID") == 0) + if (reply->resp_text_key != NULL && + strcasecmp(reply->resp_text_key, "APPENDUID") == 0) imapc_save_appenduid(ctx->ctx, reply, &uid); imapc_save_add_to_index(ctx->ctx, uid); ctx->ret = 0; @@ -354,7 +355,8 @@ uint32_t uid = 0; if (reply->state == IMAPC_COMMAND_STATE_OK) { - if (strcasecmp(reply->resp_text_key, "COPYUID") == 0) + if (reply->resp_text_key != NULL && + strcasecmp(reply->resp_text_key, "COPYUID") == 0) imapc_save_copyuid(ctx->ctx, reply, &uid); imapc_save_add_to_index(ctx->ctx, uid); ctx->ret = 0; From dovecot at dovecot.org Wed Jun 27 04:26:17 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 04:26:17 +0300 Subject: dovecot-2.2: Avoid using (void)s by adding ATTR_NOWARN_UNUSED_RE... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/128c598d2870 changeset: 14688:128c598d2870 user: Timo Sirainen date: Mon Jun 25 03:21:25 2012 +0300 description: Avoid using (void)s by adding ATTR_NOWARN_UNUSED_RESULT attributes and other ways. diffstat: src/auth/auth-worker-server.h | 2 +- src/auth/passdb-blocking.c | 11 ++++---- src/auth/userdb-blocking.c | 2 +- src/doveadm/doveadm-mail-expunge.c | 2 +- src/doveadm/doveadm-mail.c | 2 +- src/doveadm/dsync/dsync-brain-mailbox-tree.c | 4 +- src/doveadm/dsync/dsync-brain-mailbox.c | 6 ++-- src/doveadm/dsync/dsync-brain-mails.c | 2 +- src/doveadm/dsync/dsync-slave-pipe.c | 4 +- src/doveadm/dsync/dsync-slave.c | 4 ++- src/doveadm/dsync/dsync-slave.h | 17 +++++++------ src/doveadm/dsync/dsync-transaction-log-scan.c | 14 +++++----- src/imap-login/client.c | 2 +- src/imap/cmd-append.c | 2 +- src/imap/imap-client.c | 4 +- src/imap/imap-common.h | 2 +- src/imap/imap-search.c | 2 +- src/imap/imap-sync.c | 2 +- src/imap/imap-sync.h | 2 +- src/lib-dict/dict-client.c | 10 ++++---- src/lib-dict/dict-file.c | 2 +- src/lib-imap-client/imapc-connection.c | 8 +++--- src/lib-imap/imap-bodystructure.c | 4 +- src/lib-index/mail-index-strmap.c | 2 +- src/lib-index/mail-index-transaction.c | 4 +- src/lib-index/mail-index.h | 3 +- src/lib-index/mail-transaction-log-file.c | 2 +- src/lib-mail/istream-binary-converter.c | 4 +- src/lib-mail/message-decoder.c | 2 +- src/lib-mail/message-parser.c | 2 +- src/lib-mail/rfc2231-parser.h | 5 ++- src/lib-storage/index/dbox-multi/mdbox-mail.c | 2 +- src/lib-storage/index/dbox-single/sdbox-mail.c | 2 +- src/lib-storage/index/dbox-single/sdbox-sync.c | 2 +- src/lib-storage/index/index-storage.c | 8 ++---- src/lib-storage/index/index-thread.c | 6 ++-- src/lib-storage/index/index-transaction.c | 2 +- src/lib-storage/index/maildir/maildir-mail.c | 2 +- src/lib-storage/index/maildir/maildir-sync.c | 4 +- src/lib-storage/index/maildir/maildir-uidlist.c | 2 +- src/lib-storage/index/mbox/mbox-lock.c | 31 +++++++++++++----------- src/lib-storage/index/mbox/mbox-lock.h | 3 +- src/lib-storage/index/mbox/mbox-mail.c | 2 +- src/lib-storage/index/mbox/mbox-save.c | 2 +- src/lib-storage/index/mbox/mbox-storage.c | 4 +- src/lib-storage/index/mbox/mbox-sync.c | 6 ++-- src/lib-storage/index/pop3c/pop3c-client.c | 8 +++--- src/lib-storage/list/subscription-file.c | 2 +- src/lib-storage/mail-storage.c | 2 +- src/lib-storage/mail-storage.h | 10 ++++--- src/lib-storage/mailbox-list.h | 5 ++- src/lib-test/test-common.c | 2 +- src/lib/bsearch-insert-pos.h | 10 ++++--- src/lib/file-dotlock.c | 7 +---- src/lib/file-dotlock.h | 5 +-- src/lib/iostream-rawlog.h | 5 ++- src/lib/istream-base64-encoder.c | 2 +- src/lib/istream-data.c | 2 +- src/lib/istream-private.h | 7 +++-- src/lib/istream.c | 2 +- src/lib/network.h | 2 +- src/login-common/client-common-auth.c | 2 +- src/login-common/client-common.h | 2 +- src/login-common/login-proxy.c | 2 +- src/login-common/ssl-proxy-gnutls.c | 4 +- src/login-common/ssl-proxy-openssl.c | 12 ++++---- src/plugins/fts-lucene/fts-backend-lucene.c | 4 +- src/plugins/fts-solr/fts-backend-solr-old.c | 4 +- src/plugins/fts-solr/fts-backend-solr.c | 4 +- src/plugins/fts/fts-api-private.h | 3 +- src/plugins/fts/fts-api.c | 2 +- src/plugins/fts/fts-parser-script.c | 2 +- src/plugins/fts/fts-storage.c | 5 +-- src/plugins/imap-acl/imap-acl-plugin.c | 2 +- src/plugins/imap-quota/imap-quota-plugin.c | 2 +- src/plugins/imap-zlib/imap-zlib-plugin.c | 2 +- src/pop3/pop3-client.c | 7 +---- 77 files changed, 173 insertions(+), 169 deletions(-) diffs (truncated from 1443 to 300 lines): diff -r 7c058aa05b0a -r 128c598d2870 src/auth/auth-worker-server.h --- a/src/auth/auth-worker-server.h Mon Jun 25 02:52:33 2012 +0300 +++ b/src/auth/auth-worker-server.h Mon Jun 25 03:21:25 2012 +0300 @@ -6,7 +6,7 @@ typedef bool auth_worker_callback_t(const char *reply, void *context); -struct auth_worker_connection * +struct auth_worker_connection * ATTR_NOWARN_UNUSED_RESULT auth_worker_call(pool_t pool, struct auth_stream_reply *data, auth_worker_callback_t *callback, void *context); void auth_worker_server_resume_input(struct auth_worker_connection *conn); diff -r 7c058aa05b0a -r 128c598d2870 src/auth/passdb-blocking.c --- a/src/auth/passdb-blocking.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/auth/passdb-blocking.c Mon Jun 25 03:21:25 2012 +0300 @@ -88,8 +88,7 @@ auth_request_export(request, reply); auth_request_ref(request); - (void)auth_worker_call(request->pool, reply, - verify_plain_callback, request); + auth_worker_call(request->pool, reply, verify_plain_callback, request); } static bool lookup_credentials_callback(const char *reply, void *context) @@ -131,8 +130,8 @@ auth_request_export(request, reply); auth_request_ref(request); - (void)auth_worker_call(request->pool, reply, - lookup_credentials_callback, request); + auth_worker_call(request->pool, reply, + lookup_credentials_callback, request); } static bool @@ -159,6 +158,6 @@ auth_request_export(request, reply); auth_request_ref(request); - (void)auth_worker_call(request->pool, reply, - set_credentials_callback, request); + auth_worker_call(request->pool, reply, + set_credentials_callback, request); } diff -r 7c058aa05b0a -r 128c598d2870 src/auth/userdb-blocking.c --- a/src/auth/userdb-blocking.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/auth/userdb-blocking.c Mon Jun 25 03:21:25 2012 +0300 @@ -58,7 +58,7 @@ auth_request_export(request, reply); auth_request_ref(request); - (void)auth_worker_call(request->pool, reply, user_callback, request); + auth_worker_call(request->pool, reply, user_callback, request); } static bool iter_callback(const char *reply, void *context) diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/doveadm-mail-expunge.c --- a/src/doveadm/doveadm-mail-expunge.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/doveadm-mail-expunge.c Mon Jun 25 03:21:25 2012 +0300 @@ -48,7 +48,7 @@ if (ctx->delete_empty_mailbox && ret == 0) { if (mailbox_delete_empty(box) < 0) { - (void)mailbox_get_last_error(box, &error); + error = mailbox_get_last_mail_error(box); if (error != MAIL_ERROR_EXISTS) { doveadm_mail_failed_mailbox(_ctx, box); ret = -1; diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/doveadm-mail.c --- a/src/doveadm/doveadm-mail.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/doveadm-mail.c Mon Jun 25 03:21:25 2012 +0300 @@ -76,7 +76,7 @@ { enum mail_error error; - (void)mail_storage_get_last_error(storage, &error); + mail_storage_get_last_error(storage, &error); doveadm_mail_failed_error(ctx, error); } diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-brain-mailbox-tree.c --- a/src/doveadm/dsync/dsync-brain-mailbox-tree.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-brain-mailbox-tree.c Mon Jun 25 03:21:25 2012 +0300 @@ -122,8 +122,8 @@ deletes = dsync_mailbox_tree_get_deletes(brain->local_mailbox_tree, &count); - (void)dsync_slave_send_mailbox_deletes(brain->slave, deletes, count, - brain->hierarchy_sep); + dsync_slave_send_mailbox_deletes(brain->slave, deletes, count, + brain->hierarchy_sep); brain->state = DSYNC_STATE_RECV_MAILBOX_TREE; } diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-brain-mailbox.c --- a/src/doveadm/dsync/dsync-brain-mailbox.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-brain-mailbox.c Mon Jun 25 03:21:25 2012 +0300 @@ -372,7 +372,7 @@ } /* start exporting this mailbox (wait for remote to start importing) */ - (void)dsync_slave_send_mailbox(brain->slave, &dsync_box); + dsync_slave_send_mailbox(brain->slave, &dsync_box); (void)dsync_brain_sync_mailbox_init(brain, box, &dsync_box, DSYNC_BOX_STATE_MAILBOX); brain->state = DSYNC_STATE_SYNC_MAILS; @@ -560,13 +560,13 @@ memcpy(delete_box.mailbox_guid, dsync_box->mailbox_guid, sizeof(delete_box.mailbox_guid)); delete_box.mailbox_lost = TRUE; - (void)dsync_slave_send_mailbox(brain->slave, &delete_box); + dsync_slave_send_mailbox(brain->slave, &delete_box); return TRUE; } i_assert(local_dsync_box.uid_validity != 0); i_assert(memcmp(dsync_box->mailbox_guid, local_dsync_box.mailbox_guid, sizeof(dsync_box->mailbox_guid)) == 0); - (void)dsync_slave_send_mailbox(brain->slave, &local_dsync_box); + dsync_slave_send_mailbox(brain->slave, &local_dsync_box); dsync_brain_mailbox_update_pre(brain, box, &local_dsync_box, dsync_box); diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-brain-mails.c --- a/src/doveadm/dsync/dsync-brain-mails.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-brain-mails.c Mon Jun 25 03:21:25 2012 +0300 @@ -155,7 +155,7 @@ if (changes_during_sync) brain->changes_during_sync = TRUE; } - (void)dsync_slave_send_mailbox_state(brain->slave, &state); + dsync_slave_send_mailbox_state(brain->slave, &state); } static bool dsync_brain_recv_mail(struct dsync_brain *brain) diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-slave-pipe.c --- a/src/doveadm/dsync/dsync-slave-pipe.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave-pipe.c Mon Jun 25 03:21:25 2012 +0300 @@ -68,7 +68,7 @@ return ret; } -static struct item * +static struct item * ATTR_NOWARN_UNUSED_RESULT dsync_slave_pipe_push_item(struct dsync_slave_pipe *pipe, enum item_type type) { struct item *item; @@ -193,7 +193,7 @@ { struct dsync_slave_pipe *pipe = (struct dsync_slave_pipe *)slave; - (void)dsync_slave_pipe_push_item(pipe->remote, ITEM_END_OF_LIST); + dsync_slave_pipe_push_item(pipe->remote, ITEM_END_OF_LIST); } static void diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-slave.c --- a/src/doveadm/dsync/dsync-slave.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave.c Mon Jun 25 03:21:25 2012 +0300 @@ -40,9 +40,11 @@ DSYNC_SLAVE_SEND_RET_OK; } -void dsync_slave_send_end_of_list(struct dsync_slave *slave) +enum dsync_slave_send_ret +dsync_slave_send_end_of_list(struct dsync_slave *slave) { slave->v.send_end_of_list(slave); + return dsync_slave_send_ret(slave); } enum dsync_slave_send_ret diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-slave.h --- a/src/doveadm/dsync/dsync-slave.h Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave.h Mon Jun 25 03:21:25 2012 +0300 @@ -54,16 +54,17 @@ dsync_slave_recv_handshake(struct dsync_slave *slave, const struct dsync_slave_settings **set_r); -void dsync_slave_send_end_of_list(struct dsync_slave *slave); +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT +dsync_slave_send_end_of_list(struct dsync_slave *slave); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mailbox_state(struct dsync_slave *slave, const struct dsync_mailbox_state *state); enum dsync_slave_recv_ret dsync_slave_recv_mailbox_state(struct dsync_slave *slave, struct dsync_mailbox_state *state_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mailbox_tree_node(struct dsync_slave *slave, const char *const *name, const struct dsync_mailbox_node *node); @@ -72,7 +73,7 @@ const char *const **name_r, const struct dsync_mailbox_node **node_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mailbox_deletes(struct dsync_slave *slave, const struct dsync_mailbox_delete *deletes, unsigned int count, char hierarchy_sep); @@ -81,28 +82,28 @@ const struct dsync_mailbox_delete **deletes_r, unsigned int *count_r, char *hierarchy_sep_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mailbox(struct dsync_slave *slave, const struct dsync_mailbox *dsync_box); enum dsync_slave_recv_ret dsync_slave_recv_mailbox(struct dsync_slave *slave, const struct dsync_mailbox **dsync_box_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_change(struct dsync_slave *slave, const struct dsync_mail_change *change); enum dsync_slave_recv_ret dsync_slave_recv_change(struct dsync_slave *slave, const struct dsync_mail_change **change_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mail_request(struct dsync_slave *slave, const struct dsync_mail_request *request); enum dsync_slave_recv_ret dsync_slave_recv_mail_request(struct dsync_slave *slave, const struct dsync_mail_request **request_r); -enum dsync_slave_send_ret +enum dsync_slave_send_ret ATTR_NOWARN_UNUSED_RESULT dsync_slave_send_mail(struct dsync_slave *slave, const struct dsync_mail *mail); enum dsync_slave_recv_ret diff -r 7c058aa05b0a -r 128c598d2870 src/doveadm/dsync/dsync-transaction-log-scan.c --- a/src/doveadm/dsync/dsync-transaction-log-scan.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/doveadm/dsync/dsync-transaction-log-scan.c Mon Jun 25 03:21:25 2012 +0300 @@ -19,7 +19,7 @@ bool returned_all_changes; }; -static bool +static bool ATTR_NOWARN_UNUSED_RESULT export_change_get(struct dsync_transaction_log_scan *ctx, uint32_t uid, enum dsync_mail_change_type type, struct dsync_mail_change **change_r) @@ -74,9 +74,9 @@ end = CONST_PTR_OFFSET(data, hdr->size); for (; rec != end; rec++) { for (uid = rec->uid1; uid <= rec->uid2; uid++) { - (void)export_change_get(ctx, uid, - DSYNC_MAIL_CHANGE_TYPE_EXPUNGE, - &change); + export_change_get(ctx, uid, + DSYNC_MAIL_CHANGE_TYPE_EXPUNGE, + &change); } } } @@ -95,9 +95,9 @@ end = CONST_PTR_OFFSET(data, hdr->size); for (; rec != end; rec++) { if (uid >= rec->uid1 && uid <= rec->uid2) { - (void)export_change_get(ctx, uid, - DSYNC_MAIL_CHANGE_TYPE_EXPUNGE, - &change); + export_change_get(ctx, uid, + DSYNC_MAIL_CHANGE_TYPE_EXPUNGE, + &change); return TRUE; } } diff -r 7c058aa05b0a -r 128c598d2870 src/imap-login/client.c --- a/src/imap-login/client.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/imap-login/client.c Mon Jun 25 03:21:25 2012 +0300 @@ -371,7 +371,7 @@ } } o_stream_uncork(imap_client->common.output); - (void)client_unref(&client); + client_unref(&client); } static struct client *imap_client_alloc(pool_t pool) diff -r 7c058aa05b0a -r 128c598d2870 src/imap/cmd-append.c --- a/src/imap/cmd-append.c Mon Jun 25 02:52:33 2012 +0300 +++ b/src/imap/cmd-append.c Mon Jun 25 03:21:25 2012 +0300 @@ -114,7 +114,7 @@ (void)client_handle_unfinished_cmd(cmd); else client_command_free(&cmd); - (void)cmd_sync_delayed(client); + cmd_sync_delayed(client); o_stream_uncork(client->output); if (client->disconnected) From dovecot at dovecot.org Wed Jun 27 04:26:17 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 04:26:17 +0300 Subject: dovecot-2.2: Try to avoid (void) casts by adding more ATTR_NOWAR... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/096e4c4d62bb changeset: 14689:096e4c4d62bb user: Timo Sirainen date: Wed Jun 27 04:24:53 2012 +0300 description: Try to avoid (void) casts by adding more ATTR_NOWARN_UNUSED_RESULT. diffstat: src/lib-imap/imap-bodystructure.c | 10 +++++----- src/lib-mail/message-date.c | 8 ++++---- src/lib-mail/message-decoder.c | 4 ++-- src/lib-mail/message-id.c | 4 ++-- src/lib-mail/message-parser.c | 2 +- src/lib-mail/message-search.c | 2 +- src/lib-mail/rfc822-parser.h | 3 ++- src/lib-storage/index/index-attachment.c | 2 +- src/lib/hash.c | 12 ++++++------ src/lib/md4.c | 9 +++++---- src/lib/md5.c | 9 +++++---- src/lib/ostream.c | 2 +- src/plugins/fts/fts-build-mail.c | 2 +- src/plugins/fts/fts-parser-script.c | 2 +- 14 files changed, 37 insertions(+), 34 deletions(-) diffs (truncated from 335 to 300 lines): diff -r 128c598d2870 -r 096e4c4d62bb src/lib-imap/imap-bodystructure.c --- a/src/lib-imap/imap-bodystructure.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-imap/imap-bodystructure.c Wed Jun 27 04:24:53 2012 +0300 @@ -44,7 +44,7 @@ bool charset_found = FALSE; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); str = t_str_new(256); if (rfc822_parse_content_type(&parser, str) < 0) @@ -94,7 +94,7 @@ string_t *str; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); str = t_str_new(256); if (rfc822_parse_mime_token(&parser, str) >= 0) { @@ -112,7 +112,7 @@ string_t *str; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); str = t_str_new(256); if (rfc822_parse_mime_token(&parser, str) < 0) @@ -151,14 +151,14 @@ str = t_str_new(128); str_append_c(str, '"'); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); while (rfc822_parse_atom(&parser, str) >= 0) { str_append(str, "\" \""); if (parser.data == parser.end || *parser.data != ',') break; parser.data++; - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); } if (str_len(str) > 1) { diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/message-date.c --- a/src/lib-mail/message-date.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/message-date.c Wed Jun 27 04:24:53 2012 +0300 @@ -123,7 +123,7 @@ /* [weekday_name "," ] dd month_name [yy]yy hh:mi[:ss] timezone */ memset(&tm, 0, sizeof(tm)); - (void)rfc822_skip_lwsp(&ctx->parser); + rfc822_skip_lwsp(&ctx->parser); /* skip the optional weekday */ if (next_token(ctx, &value, &len) <= 0) @@ -132,7 +132,7 @@ if (*ctx->parser.data != ',') return FALSE; ctx->parser.data++; - (void)rfc822_skip_lwsp(&ctx->parser); + rfc822_skip_lwsp(&ctx->parser); if (next_token(ctx, &value, &len) <= 0) return FALSE; @@ -197,7 +197,7 @@ if (!IS_TIME_SEP(*ctx->parser.data)) return FALSE; ctx->parser.data++; - (void)rfc822_skip_lwsp(&ctx->parser); + rfc822_skip_lwsp(&ctx->parser); if (next_token(ctx, &value, &len) < 0 || len != 2 || !i_isdigit(value[0]) || !i_isdigit(value[1])) @@ -208,7 +208,7 @@ if (ctx->parser.data != ctx->parser.end && IS_TIME_SEP(*ctx->parser.data)) { ctx->parser.data++; - (void)rfc822_skip_lwsp(&ctx->parser); + rfc822_skip_lwsp(&ctx->parser); if (next_token(ctx, &value, &len) <= 0 || len != 2 || !i_isdigit(value[0]) || !i_isdigit(value[1])) diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/message-decoder.c --- a/src/lib-mail/message-decoder.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/message-decoder.c Wed Jun 27 04:24:53 2012 +0300 @@ -102,7 +102,7 @@ value = t_str_new(64); rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); (void)rfc822_parse_mime_token(&parser, value); ctx->content_type = CONTENT_TYPE_UNKNOWN; @@ -137,7 +137,7 @@ return; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); str = t_str_new(64); if (rfc822_parse_content_type(&parser, str) <= 0) return; diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/message-id.c --- a/src/lib-mail/message-id.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/message-id.c Wed Jun 27 04:24:53 2012 +0300 @@ -21,7 +21,7 @@ no-fold-literal = "[" *(dtext / quoted-pair) "]" */ - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); if (*parser.data == '"') ret = rfc822_parse_quoted_string(&parser, msgid); @@ -34,7 +34,7 @@ return FALSE; str_append_c(msgid, '@'); parser.data++; - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); if (rfc822_parse_dot_atom(&parser, msgid) <= 0) return FALSE; diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/message-parser.c --- a/src/lib-mail/message-parser.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/message-parser.c Wed Jun 27 04:24:53 2012 +0300 @@ -464,7 +464,7 @@ ctx->part_seen_content_type = TRUE; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); content_type = t_str_new(64); if (rfc822_parse_content_type(&parser, content_type) < 0) diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/message-search.c --- a/src/lib-mail/message-search.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/message-search.c Wed Jun 27 04:24:53 2012 +0300 @@ -55,7 +55,7 @@ string_t *content_type; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); content_type = t_str_new(64); if (rfc822_parse_content_type(&parser, content_type) >= 0) { diff -r 128c598d2870 -r 096e4c4d62bb src/lib-mail/rfc822-parser.h --- a/src/lib-mail/rfc822-parser.h Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-mail/rfc822-parser.h Wed Jun 27 04:24:53 2012 +0300 @@ -26,7 +26,8 @@ /* Parse comment. Assumes parser's data points to '(' */ int rfc822_skip_comment(struct rfc822_parser_context *ctx); /* Skip LWSP if there is any */ -int rfc822_skip_lwsp(struct rfc822_parser_context *ctx); +int ATTR_NOWARN_UNUSED_RESULT +rfc822_skip_lwsp(struct rfc822_parser_context *ctx); /* Stop at next non-atext char */ int rfc822_parse_atom(struct rfc822_parser_context *ctx, string_t *str); /* Like parse_atom() but don't stop at '.' */ diff -r 128c598d2870 -r 096e4c4d62bb src/lib-storage/index/index-attachment.c --- a/src/lib-storage/index/index-attachment.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib-storage/index/index-attachment.c Wed Jun 27 04:24:53 2012 +0300 @@ -98,7 +98,7 @@ string_t *content_type; rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - (void)rfc822_skip_lwsp(&parser); + rfc822_skip_lwsp(&parser); T_BEGIN { content_type = t_str_new(64); diff -r 128c598d2870 -r 096e4c4d62bb src/lib/hash.c --- a/src/lib/hash.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib/hash.c Wed Jun 27 04:24:53 2012 +0300 @@ -176,7 +176,7 @@ return TRUE; } -static struct hash_node * +static struct hash_node * ATTR_NOWARN_UNUSED_RESULT hash_table_insert_node(struct hash_table *table, void *key, void *value, bool check_existing) { @@ -265,7 +265,7 @@ void hash_table_update(struct hash_table *table, void *key, void *value) { - (void)hash_table_insert_node(table, key, value, TRUE); + hash_table_insert_node(table, key, value, TRUE); } static void @@ -438,16 +438,16 @@ for (i = 0; i < old_size; i++) { node = &old_nodes[i]; if (node->key != NULL) { - (void)hash_table_insert_node(table, node->key, - node->value, FALSE); + hash_table_insert_node(table, node->key, + node->value, FALSE); } for (node = node->next; node != NULL; node = next) { next = node->next; if (node->key != NULL) { - (void)hash_table_insert_node(table, node->key, - node->value, FALSE); + hash_table_insert_node(table, node->key, + node->value, FALSE); } free_node(table, node); } diff -r 128c598d2870 -r 096e4c4d62bb src/lib/md4.c --- a/src/lib/md4.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib/md4.c Wed Jun 27 04:24:53 2012 +0300 @@ -62,7 +62,8 @@ * This processes one or more 64-byte data blocks, but does NOT update * the bit counters. There're no alignment requirements. */ -static const void *body(struct md4_context *ctx, const void *data, size_t size) +static const void * ATTR_NOWARN_UNUSED_RESULT +body(struct md4_context *ctx, const void *data, size_t size) { const unsigned char *ptr; uint32_t a, b, c, d; @@ -193,7 +194,7 @@ memcpy(&ctx->buffer[used], data, free); data = (const unsigned char *) data + free; size -= free; - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); } if (size >= 64) { @@ -217,7 +218,7 @@ if (free < 8) { memset(&ctx->buffer[used], 0, free); - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); used = 0; free = 64; } @@ -234,7 +235,7 @@ ctx->buffer[62] = ctx->hi >> 16; ctx->buffer[63] = ctx->hi >> 24; - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); result[0] = ctx->a; result[1] = ctx->a >> 8; diff -r 128c598d2870 -r 096e4c4d62bb src/lib/md5.c --- a/src/lib/md5.c Mon Jun 25 03:21:25 2012 +0300 +++ b/src/lib/md5.c Wed Jun 27 04:24:53 2012 +0300 @@ -66,7 +66,8 @@ * This processes one or more 64-byte data blocks, but does NOT update * the bit counters. There're no alignment requirements. */ -static const void *body(struct md5_context *ctx, const void *data, size_t size) +static const void * ATTR_NOWARN_UNUSED_RESULT +body(struct md5_context *ctx, const void *data, size_t size) { const unsigned char *ptr; uint_fast32_t a, b, c, d; @@ -208,7 +209,7 @@ memcpy(&ctx->buffer[used], data, free); data = (const unsigned char *) data + free; size -= free; - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); } if (size >= 64) { @@ -232,7 +233,7 @@ if (free < 8) { memset(&ctx->buffer[used], 0, free); - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); used = 0; free = 64; } @@ -249,7 +250,7 @@ ctx->buffer[62] = ctx->hi >> 16; ctx->buffer[63] = ctx->hi >> 24; - (void)body(ctx, ctx->buffer, 64); + body(ctx, ctx->buffer, 64); result[0] = ctx->a; result[1] = ctx->a >> 8; diff -r 128c598d2870 -r 096e4c4d62bb src/lib/ostream.c From dovecot at dovecot.org Wed Jun 27 12:04:01 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 12:04:01 +0300 Subject: dovecot-2.2: gssapi: Allow logging in as users listed in "k5prin... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/183adc90781c changeset: 14690:183adc90781c user: Timo Sirainen date: Wed Jun 27 12:03:51 2012 +0300 description: gssapi: Allow logging in as users listed in "k5principals" extra field. This also enables other passdb extra fields for gssapi mechanism. Based on patch by Sam Morris. diffstat: src/auth/mech-gssapi.c | 87 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 78 insertions(+), 9 deletions(-) diffs (139 lines): diff -r 096e4c4d62bb -r 183adc90781c src/auth/mech-gssapi.c --- a/src/auth/mech-gssapi.c Wed Jun 27 04:24:53 2012 +0300 +++ b/src/auth/mech-gssapi.c Wed Jun 27 12:03:51 2012 +0300 @@ -380,6 +380,29 @@ #ifdef USE_KRB5_USEROK static bool +k5_principal_is_authorized(struct auth_request *request, const char *name) +{ + const char *value, *const *authorized_names, *const *tmp; + + if (request->extra_fields == NULL) + return FALSE; + + value = auth_stream_reply_find(request->extra_fields, "k5principals"); + if (value == NULL) + return FALSE; + + authorized_names = t_strsplit_spaces(value, ","); + for (tmp = authorized_names; *tmp != NULL; tmp++) { + if (strcmp(*tmp, name) == 0) { + auth_request_log_debug(request, "gssapi", + "authorized by k5principals field: %s", name); + return TRUE; + } + } + return FALSE; +} + +static bool mech_gssapi_krb5_userok(struct gssapi_auth_request *request, gss_name_t name, const char *login_user, bool check_name_type) @@ -389,7 +412,7 @@ krb5_error_code krb5_err; gss_OID name_type; const char *princ_display_name; - bool ret = FALSE; + bool authorized = FALSE; /* Parse out the principal's username */ if (!get_display_name(&request->auth_request, name, &name_type, @@ -419,13 +442,20 @@ "krb5_parse_name() failed: %d", (int)krb5_err); } else { + /* See if the principal is in the list of authorized + * principals for the user */ + authorized = k5_principal_is_authorized(&request->auth_request, + princ_display_name); + /* See if the principal is authorized to act as the - specified user */ - ret = krb5_kuserok(ctx, princ, login_user); + specified (UNIX) user */ + if (!authorized) + authorized = krb5_kuserok(ctx, princ, login_user); + krb5_free_principal(ctx, princ); } krb5_free_context(ctx); - return ret; + return authorized; } #endif @@ -483,11 +513,45 @@ #else auth_request_log_info(auth_request, "gssapi", "Cross-realm authentication not supported " - "(authz_name=%s)", login_user); + "(authn_name=%s, authz_name=%s)", request->auth_request.original_username, login_user); return -1; #endif } +static void +gssapi_credentials_callback(enum passdb_result result, + const unsigned char *credentials ATTR_UNUSED, + size_t size ATTR_UNUSED, + struct auth_request *request) +{ + struct gssapi_auth_request *gssapi_request = + (struct gssapi_auth_request *)request; + + /* We don't care much whether the lookup succeeded or not because GSSAPI + * does not strictly require a passdb. But if a passdb is configured, + * now the k5principals field will have been filled in. */ + switch (result) { + case PASSDB_RESULT_INTERNAL_FAILURE: + auth_request_internal_failure(request); + return; + case PASSDB_RESULT_USER_DISABLED: + case PASSDB_RESULT_PASS_EXPIRED: + /* user is explicitly disabled, don't allow it to log in */ + auth_request_fail(request); + return; + case PASSDB_RESULT_SCHEME_NOT_AVAILABLE: + case PASSDB_RESULT_USER_UNKNOWN: + case PASSDB_RESULT_PASSWORD_MISMATCH: + case PASSDB_RESULT_OK: + break; + } + + if (mech_gssapi_userok(gssapi_request, request->user) == 0) + auth_request_success(request, NULL, 0); + else + auth_request_fail(request); +} + static int mech_gssapi_unwrap(struct gssapi_auth_request *request, gss_buffer_desc inbuf) { @@ -531,16 +595,21 @@ return -1; } - if (mech_gssapi_userok(request, login_user) < 0) - return -1; - + /* Set username early, so that the credential lookup is for the + * authorizing user. This means the username in subsequent log + * messagess will be the authorization name, not the authentication + * name, which may mean that future log messages should be adjusted + * to log the right thing. */ if (!auth_request_set_username(auth_request, login_user, &error)) { auth_request_log_info(auth_request, "gssapi", "authz_name: %s", error); return -1; } - auth_request_success(auth_request, NULL, 0); + /* Continue in callback once auth_request is populated with passdb + information. */ + auth_request_lookup_credentials(&request->auth_request, "", + gssapi_credentials_callback); return 0; } From dovecot at dovecot.org Wed Jun 27 12:13:02 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 12:13:02 +0300 Subject: dovecot-2.1: lib-storage: Fixed handling failures when autocreat... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/0e41d7c48a8b changeset: 14579:0e41d7c48a8b user: Timo Sirainen date: Wed Jun 27 12:12:52 2012 +0300 description: lib-storage: Fixed handling failures when autocreating mailboxes. diffstat: src/lib-storage/mail-storage.c | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) diffs (44 lines): diff -r 20703dbd1168 -r 0e41d7c48a8b src/lib-storage/mail-storage.c --- a/src/lib-storage/mail-storage.c Mon Jun 25 19:40:24 2012 +0300 +++ b/src/lib-storage/mail-storage.c Wed Jun 27 12:12:52 2012 +0300 @@ -819,17 +819,18 @@ return 0; } -static void mailbox_autocreate(struct mailbox *box) +static int mailbox_autocreate(struct mailbox *box) { const char *errstr; enum mail_error error; if (mailbox_create(box, NULL, FALSE) < 0) { errstr = mailbox_get_last_error(box, &error); - if (error != MAIL_ERROR_NOTFOUND && !box->inbox_user) { + if (error != MAIL_ERROR_NOTFOUND) { mail_storage_set_critical(box->storage, "Failed to autocreate mailbox %s: %s", box->vname, errstr); + return -1; } } else if (box->set != NULL && strcmp(box->set->autocreate, @@ -838,15 +839,18 @@ mail_storage_set_critical(box->storage, "Failed to autosubscribe to mailbox %s: %s", box->vname, mailbox_get_last_error(box, NULL)); + return -1; } } + return 0; } static int mailbox_autocreate_and_reopen(struct mailbox *box) { int ret; - mailbox_autocreate(box); + if (mailbox_autocreate(box) < 0) + return -1; mailbox_close(box); ret = box->v.open(box); From dovecot at dovecot.org Wed Jun 27 12:25:11 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 12:25:11 +0300 Subject: dovecot-2.1: doveadm mailbox status -A -t: Reset vsize counter b... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/d8d587bd5a29 changeset: 14580:d8d587bd5a29 user: Timo Sirainen date: Wed Jun 27 12:25:05 2012 +0300 description: doveadm mailbox status -A -t: Reset vsize counter between users. diffstat: src/doveadm/doveadm-mail-mailbox-status.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (11 lines): diff -r 0e41d7c48a8b -r d8d587bd5a29 src/doveadm/doveadm-mail-mailbox-status.c --- a/src/doveadm/doveadm-mail-mailbox-status.c Wed Jun 27 12:12:52 2012 +0300 +++ b/src/doveadm/doveadm-mail-mailbox-status.c Wed Jun 27 12:25:05 2012 +0300 @@ -153,6 +153,7 @@ int ret = 0; memset(&ctx->total_status, 0, sizeof(ctx->total_status)); + memset(&ctx->total_metadata, 0, sizeof(ctx->total_metadata)); iter = doveadm_mailbox_list_iter_init(_ctx, user, ctx->search_args, iter_flags); From dovecot at dovecot.org Wed Jun 27 12:29:46 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Wed, 27 Jun 2012 12:29:46 +0300 Subject: dovecot-2.1: pop3c: Added pop3c_master_user setting. Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/06ba409a63d3 changeset: 14581:06ba409a63d3 user: Timo Sirainen date: Wed Jun 27 12:29:42 2012 +0300 description: pop3c: Added pop3c_master_user setting. diffstat: src/lib-storage/index/pop3c/pop3c-settings.c | 2 ++ src/lib-storage/index/pop3c/pop3c-settings.h | 1 + src/lib-storage/index/pop3c/pop3c-storage.c | 1 + 3 files changed, 4 insertions(+), 0 deletions(-) diffs (41 lines): diff -r d8d587bd5a29 -r 06ba409a63d3 src/lib-storage/index/pop3c/pop3c-settings.c --- a/src/lib-storage/index/pop3c/pop3c-settings.c Wed Jun 27 12:25:05 2012 +0300 +++ b/src/lib-storage/index/pop3c/pop3c-settings.c Wed Jun 27 12:29:42 2012 +0300 @@ -18,6 +18,7 @@ DEF(SET_UINT, pop3c_port), DEF(SET_STR_VARS, pop3c_user), + DEF(SET_STR_VARS, pop3c_master_user), DEF(SET_STR, pop3c_password), DEF(SET_ENUM, pop3c_ssl), @@ -35,6 +36,7 @@ .pop3c_port = 110, .pop3c_user = "%u", + .pop3c_master_user = "", .pop3c_password = "", .pop3c_ssl = "no:pop3s:starttls", diff -r d8d587bd5a29 -r 06ba409a63d3 src/lib-storage/index/pop3c/pop3c-settings.h --- a/src/lib-storage/index/pop3c/pop3c-settings.h Wed Jun 27 12:25:05 2012 +0300 +++ b/src/lib-storage/index/pop3c/pop3c-settings.h Wed Jun 27 12:29:42 2012 +0300 @@ -6,6 +6,7 @@ unsigned int pop3c_port; const char *pop3c_user; + const char *pop3c_master_user; const char *pop3c_password; const char *pop3c_ssl; diff -r d8d587bd5a29 -r 06ba409a63d3 src/lib-storage/index/pop3c/pop3c-storage.c --- a/src/lib-storage/index/pop3c/pop3c-storage.c Wed Jun 27 12:25:05 2012 +0300 +++ b/src/lib-storage/index/pop3c/pop3c-storage.c Wed Jun 27 12:29:42 2012 +0300 @@ -60,6 +60,7 @@ client_set.host = set->pop3c_host; client_set.port = set->pop3c_port; client_set.username = set->pop3c_user; + client_set.master_user = set->pop3c_master_user; client_set.password = set->pop3c_password; client_set.dns_client_socket_path = t_strconcat(user->set->base_dir, "/", From dovecot at dovecot.org Thu Jun 28 00:29:45 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 00:29:45 +0300 Subject: dovecot-2.2: Changed i_close_fd() API to set the fd to -1 after ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3945a3646c67 changeset: 14691:3945a3646c67 user: Timo Sirainen date: Thu Jun 28 00:27:13 2012 +0300 description: Changed i_close_fd() API to set the fd to -1 after closing. diffstat: src/auth/db-checkpassword.c | 16 ++++++++-------- src/auth/db-passwd-file.c | 2 +- src/auth/mech-winbind.c | 14 +++++++------- src/config/config-parser.c | 2 +- src/config/sysinfo-get.c | 2 +- src/director/director-test.c | 2 +- src/doveadm/doveadm-dump-log.c | 2 +- src/doveadm/doveadm-dump-mailboxlog.c | 2 +- src/doveadm/doveadm-instance.c | 2 +- src/doveadm/doveadm-master.c | 2 +- src/doveadm/doveadm-sis.c | 2 +- src/doveadm/doveadm-stats.c | 2 +- src/doveadm/dsync/doveadm-dsync.c | 24 +++++++++++------------- src/doveadm/dsync/dsync-slave-io.c | 2 +- src/imap/main.c | 6 ++++-- src/lda/main.c | 2 +- src/lib-dict/dict-file.c | 10 +++++----- src/lib-dns/dns-lookup.c | 2 +- src/lib-imap-client/imapc-client.c | 2 +- src/lib-index/mail-cache-compress.c | 4 ++-- src/lib-lda/smtp-client.c | 8 ++++---- src/lib-master/master-login.c | 2 +- src/lib-master/master-service-settings.c | 6 +++--- src/lib-master/mountpoint-list.c | 4 ++-- src/lib-settings/settings-parser.c | 8 ++++---- src/lib-storage/index/index-attachment.c | 2 +- src/lib-storage/index/maildir/maildir-storage.c | 2 +- src/lib-storage/index/maildir/maildir-uidlist.c | 4 ++-- src/lib-storage/index/mbox/mbox-file.c | 2 +- src/lib-storage/index/mbox/mbox-lock.c | 6 +++--- src/lib-storage/index/mbox/mbox-storage.c | 4 ++-- src/lib-storage/index/pop3c/pop3c-client.c | 2 +- src/lib-storage/list/mailbox-list-maildir.c | 2 +- src/lib-storage/mailbox-uidvalidity.c | 6 +++--- src/lib/askpass.c | 2 +- src/lib/failures.c | 6 +++--- src/lib/fdatasync-path.c | 2 +- src/lib/file-copy.c | 4 ++-- src/lib/file-dotlock.c | 7 +++---- src/lib/ioloop-notify-dn.c | 4 ++-- src/lib/ioloop-notify-kqueue.c | 2 +- src/lib/iostream-rawlog.c | 2 +- src/lib/istream-seekable.c | 5 ++--- src/lib/lib.c | 12 ++++++++++++ src/lib/lib.h | 1 + src/lib/macros.h | 6 ++---- src/lib/network.c | 16 ++++++++-------- src/lib/nfs-workarounds.c | 6 +++--- src/lib/randgen.c | 3 +-- src/lib/safe-mkstemp.c | 2 +- src/lib/test-ostream-file.c | 2 +- src/lib/unlink-directory.c | 12 ++++++------ src/lmtp/commands.c | 2 +- src/login-common/access-lookup.c | 2 +- src/login-common/ssl-proxy-gnutls.c | 2 +- src/master/main.c | 6 +++--- src/master/service-listen.c | 4 ++-- src/master/service-monitor.c | 7 ++++--- src/master/service.c | 2 +- src/plugins/acl/acl-backend-vfile-acllist.c | 2 +- src/plugins/acl/acl-backend-vfile.c | 6 +++--- src/plugins/fts-lucene/fts-backend-lucene.c | 2 +- src/plugins/fts-squat/squat-trie.c | 2 +- src/plugins/fts/doveadm-dump-fts-expunge-log.c | 2 +- src/plugins/fts/fts-expunge-log.c | 2 +- src/plugins/fts/fts-indexer.c | 2 +- src/plugins/fts/fts-parser-script.c | 4 ++-- src/plugins/quota/quota-maildir.c | 17 ++++++----------- src/plugins/trash/trash-plugin.c | 2 +- src/plugins/virtual/virtual-config.c | 2 +- src/plugins/zlib/doveadm-zlib.c | 2 +- src/plugins/zlib/zlib-plugin.c | 2 +- src/pop3/main.c | 4 +++- src/ssl-params/ssl-params.c | 6 +++--- src/util/gdbhelper.c | 2 +- src/util/rawlog.c | 15 ++++++--------- 76 files changed, 178 insertions(+), 175 deletions(-) diffs (truncated from 1518 to 300 lines): diff -r 183adc90781c -r 3945a3646c67 src/auth/db-checkpassword.c --- a/src/auth/db-checkpassword.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/auth/db-checkpassword.c Thu Jun 28 00:27:13 2012 +0300 @@ -473,8 +473,8 @@ auth_request_log_error(request, "checkpassword", "pipe() failed: %m"); if (fd_in[0] != -1) { - i_close_fd(fd_in[0]); - i_close_fd(fd_in[1]); + i_close_fd(&fd_in[0]); + i_close_fd(&fd_in[1]); } callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE, NULL, request_callback); @@ -485,10 +485,10 @@ if (pid == -1) { auth_request_log_error(request, "checkpassword", "fork() failed: %m"); - i_close_fd(fd_in[0]); - i_close_fd(fd_in[1]); - i_close_fd(fd_out[0]); - i_close_fd(fd_out[1]); + i_close_fd(&fd_in[0]); + i_close_fd(&fd_in[1]); + i_close_fd(&fd_out[0]); + i_close_fd(&fd_out[1]); callback(request, DB_CHECKPASSWORD_STATUS_INTERNAL_FAILURE, NULL, request_callback); return; @@ -496,8 +496,8 @@ if (pid == 0) { /* child */ - i_close_fd(fd_in[0]); - i_close_fd(fd_out[1]); + i_close_fd(&fd_in[0]); + i_close_fd(&fd_out[1]); checkpassword_exec(db, request, fd_in[1], fd_out[0], auth_password != NULL); /* not reached */ diff -r 183adc90781c -r 3945a3646c67 src/auth/db-passwd-file.c --- a/src/auth/db-passwd-file.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/auth/db-passwd-file.c Thu Jun 28 00:27:13 2012 +0300 @@ -184,7 +184,7 @@ if (fstat(fd, &st) != 0) { i_error("passwd-file %s: fstat() failed: %m", pw->path); - i_close_fd(fd); + i_close_fd(&fd); return FALSE; } diff -r 183adc90781c -r 3945a3646c67 src/auth/mech-winbind.c --- a/src/auth/mech-winbind.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/auth/mech-winbind.c Thu Jun 28 00:27:13 2012 +0300 @@ -111,15 +111,15 @@ return; } if (pipe(outfd) < 0) { - i_close_fd(infd[0]); i_close_fd(infd[1]); + i_close_fd(&infd[0]); i_close_fd(&infd[1]); return; } pid = fork(); if (pid < 0) { i_error("fork() failed: %m"); - i_close_fd(infd[0]); i_close_fd(infd[1]); - i_close_fd(outfd[0]); i_close_fd(outfd[1]); + i_close_fd(&infd[0]); i_close_fd(&infd[1]); + i_close_fd(&outfd[0]); i_close_fd(&outfd[1]); return; } @@ -127,8 +127,8 @@ /* child */ const char *args[3]; - i_close_fd(infd[0]); - i_close_fd(outfd[1]); + i_close_fd(&infd[0]); + i_close_fd(&outfd[1]); if (dup2(outfd[0], STDIN_FILENO) < 0 || dup2(infd[1], STDOUT_FILENO) < 0) @@ -141,8 +141,8 @@ } /* parent */ - i_close_fd(infd[1]); - i_close_fd(outfd[0]); + i_close_fd(&infd[1]); + i_close_fd(&outfd[0]); winbind->pid = pid; winbind->in_pipe = diff -r 183adc90781c -r 3945a3646c67 src/config/config-parser.c --- a/src/config/config-parser.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/config/config-parser.c Thu Jun 28 00:27:13 2012 +0300 @@ -439,7 +439,7 @@ *error_r = t_strdup_printf("%s: read(%s) failed: %m", key, path); } - i_close_fd(fd); + i_close_fd(&fd); return ret < 0 ? -1 : 0; } diff -r 183adc90781c -r 3945a3646c67 src/config/sysinfo-get.c --- a/src/config/sysinfo-get.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/config/sysinfo-get.c Thu Jun 28 00:27:13 2012 +0300 @@ -21,7 +21,7 @@ if (fd == -1) return FALSE; ret = read(fd, buf, sizeof(buf)); - i_close_fd(fd); + i_close_fd(&fd); if (ret <= 0) return FALSE; diff -r 183adc90781c -r 3945a3646c67 src/director/director-test.c --- a/src/director/director-test.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/director/director-test.c Thu Jun 28 00:27:13 2012 +0300 @@ -338,7 +338,7 @@ out_fd = net_connect_ip(local_ip, DIRECTOR_OUT_PORT, NULL); if (out_fd == -1) { - i_close_fd(in_fd); + i_close_fd(&in_fd); return; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-dump-log.c --- a/src/doveadm/doveadm-dump-log.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-dump-log.c Thu Jun 28 00:27:13 2012 +0300 @@ -509,7 +509,7 @@ hdr.major_version == MAIL_TRANSACTION_LOG_MAJOR_VERSION && hdr.hdr_size >= MAIL_TRANSACTION_LOG_HEADER_MIN_SIZE) ret = TRUE; - i_close_fd(fd); + i_close_fd(&fd); return ret; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-dump-mailboxlog.c --- a/src/doveadm/doveadm-dump-mailboxlog.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-dump-mailboxlog.c Thu Jun 28 00:27:13 2012 +0300 @@ -100,7 +100,7 @@ break; } } - i_close_fd(fd); + i_close_fd(&fd); return ret; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-instance.c --- a/src/doveadm/doveadm-instance.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-instance.c Thu Jun 28 00:27:13 2012 +0300 @@ -39,7 +39,7 @@ (kill(pid, 0) < 0 && errno == ESRCH)); } } - i_close_fd(fd); + i_close_fd(&fd); return found; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-master.c --- a/src/doveadm/doveadm-master.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-master.c Thu Jun 28 00:27:13 2012 +0300 @@ -41,7 +41,7 @@ (kill(*pid_r, 0) < 0 && errno == ESRCH)); } } - i_close_fd(fd); + i_close_fd(&fd); return found; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-sis.c --- a/src/doveadm/doveadm-sis.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-sis.c Thu Jun 28 00:27:13 2012 +0300 @@ -48,7 +48,7 @@ if (fd1 == -1) { if (errno != ENOENT) i_error("open(%s) failed: %m", path2); - i_close_fd(fd1); + i_close_fd(&fd1); return -1; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/doveadm-stats.c --- a/src/doveadm/doveadm-stats.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/doveadm-stats.c Thu Jun 28 00:27:13 2012 +0300 @@ -496,7 +496,7 @@ array_free(&ctx.lines); pool_unref(&ctx.prev_pool); pool_unref(&ctx.cur_pool); - i_close_fd(ctx.fd); + i_close_fd(&ctx.fd); } static void cmd_stats_top(int argc, char *argv[]) diff -r 183adc90781c -r 3945a3646c67 src/doveadm/dsync/doveadm-dsync.c --- a/src/doveadm/dsync/doveadm-dsync.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/dsync/doveadm-dsync.c Thu Jun 28 00:27:13 2012 +0300 @@ -79,12 +79,12 @@ dup2(fd_err[1], STDERR_FILENO) < 0) i_fatal("dup2() failed: %m"); - i_close_fd(fd_in[0]); - i_close_fd(fd_in[1]); - i_close_fd(fd_out[0]); - i_close_fd(fd_out[1]); - i_close_fd(fd_err[0]); - i_close_fd(fd_err[1]); + i_close_fd(&fd_in[0]); + i_close_fd(&fd_in[1]); + i_close_fd(&fd_out[0]); + i_close_fd(&fd_out[1]); + i_close_fd(&fd_err[0]); + i_close_fd(&fd_err[1]); execvp_const(args[0], args); default: @@ -92,9 +92,9 @@ break; } - i_close_fd(fd_in[0]); - i_close_fd(fd_out[1]); - i_close_fd(fd_err[1]); + i_close_fd(&fd_in[0]); + i_close_fd(&fd_out[1]); + i_close_fd(&fd_err[1]); ctx->fd_in = fd_out[0]; ctx->fd_out = fd_in[1]; ctx->fd_err = fd_err[0]; @@ -362,10 +362,8 @@ dsync_slave_deinit(&slave2); if (ctx->io_err != NULL) io_remove(&ctx->io_err); - if (ctx->fd_err != -1) { - i_close_fd(ctx->fd_err); - ctx->fd_err = -1; - } + if (ctx->fd_err != -1) + i_close_fd(&ctx->fd_err); return ret; } diff -r 183adc90781c -r 3945a3646c67 src/doveadm/dsync/dsync-slave-io.c --- a/src/doveadm/dsync/dsync-slave-io.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/doveadm/dsync/dsync-slave-io.c Thu Jun 28 00:27:13 2012 +0300 @@ -1365,7 +1365,7 @@ if (unlink(str_c(path)) < 0) { /* shouldn't happen.. */ i_error("unlink(%s) failed: %m", str_c(path)); - i_close_fd(fd); + i_close_fd(&fd); return -1; } diff -r 183adc90781c -r 3945a3646c67 src/imap/main.c --- a/src/imap/main.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/imap/main.c Thu Jun 28 00:27:13 2012 +0300 @@ -271,13 +271,15 @@ client->auth_req.data_size); if (client_create_from_input(&input, client, client->fd, client->fd, &input_buf, &error) < 0) { - if (write(client->fd, MSG_BYE_INTERNAL_ERROR, + int fd = client->fd; + + if (write(fd, MSG_BYE_INTERNAL_ERROR, strlen(MSG_BYE_INTERNAL_ERROR)) < 0) { if (errno != EAGAIN && errno != EPIPE) i_error("write(client) failed: %m"); } i_error("%s", error); - i_close_fd(client->fd); + i_close_fd(&fd); master_service_client_connection_destroyed(master_service); } } diff -r 183adc90781c -r 3945a3646c67 src/lda/main.c --- a/src/lda/main.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/lda/main.c Thu Jun 28 00:27:13 2012 +0300 @@ -101,7 +101,7 @@ if (unlink(str_c(path)) < 0) { /* shouldn't happen.. */ i_error("unlink(%s) failed: %m", str_c(path)); - i_close_fd(fd); + i_close_fd(&fd); return -1; } diff -r 183adc90781c -r 3945a3646c67 src/lib-dict/dict-file.c --- a/src/lib-dict/dict-file.c Wed Jun 27 12:03:51 2012 +0300 +++ b/src/lib-dict/dict-file.c Thu Jun 28 00:27:13 2012 +0300 From dovecot at dovecot.org Thu Jun 28 01:02:11 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 01:02:11 +0300 Subject: dovecot-2.2: Renamed istream-attachment to istream-sized. Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/9774ae8fff97 changeset: 14692:9774ae8fff97 user: Timo Sirainen date: Thu Jun 28 01:01:58 2012 +0300 description: Renamed istream-attachment to istream-sized. The code didn't really assume anything about the input being an attachment, so this allows reusing the stream for other purposes. diffstat: src/lib-storage/index/Makefile.am | 2 - src/lib-storage/index/dbox-common/dbox-attachment.c | 4 +- src/lib-storage/index/istream-attachment.c | 124 -------------------- src/lib-storage/index/istream-attachment.h | 6 - src/lib/Makefile.am | 2 + src/lib/istream-sized.c | 121 +++++++++++++++++++ src/lib/istream-sized.h | 8 + 7 files changed, 133 insertions(+), 134 deletions(-) diffs (truncated from 334 to 300 lines): diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/Makefile.am --- a/src/lib-storage/index/Makefile.am Thu Jun 28 00:27:13 2012 +0300 +++ b/src/lib-storage/index/Makefile.am Thu Jun 28 01:01:58 2012 +0300 @@ -12,7 +12,6 @@ -I$(top_srcdir)/src/lib-storage libstorage_index_la_SOURCES = \ - istream-attachment.c \ istream-mail.c \ index-attachment.c \ index-mail.c \ @@ -34,7 +33,6 @@ index-transaction.c headers = \ - istream-attachment.h \ istream-mail.h \ index-attachment.h \ index-mail.h \ diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/dbox-common/dbox-attachment.c --- a/src/lib-storage/index/dbox-common/dbox-attachment.c Thu Jun 28 00:27:13 2012 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-attachment.c Thu Jun 28 01:01:58 2012 +0300 @@ -4,7 +4,7 @@ #include "istream.h" #include "istream-concat.h" #include "str.h" -#include "istream-attachment.h" +#include "istream-sized.h" #include "istream-base64-encoder.h" #include "dbox-file.h" #include "dbox-save.h" @@ -195,7 +195,7 @@ input2 = input; } - input = i_stream_create_attachment(input2, extref->size); + input = i_stream_create_sized(input2, extref->size); i_stream_unref(&input2); array_append(&streams, &input, 1); } diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/istream-attachment.c --- a/src/lib-storage/index/istream-attachment.c Thu Jun 28 00:27:13 2012 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,124 +0,0 @@ -/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */ - -#include "lib.h" -#include "istream-private.h" -#include "istream-attachment.h" - -struct attachment_istream { - struct istream_private istream; - - uoff_t size; -}; - -static ssize_t i_stream_attachment_read(struct istream_private *stream) -{ - struct attachment_istream *astream = - (struct attachment_istream *)stream; - uoff_t left; - ssize_t ret; - size_t pos; - - if (stream->istream.v_offset + - (stream->pos - stream->skip) >= astream->size) { - stream->istream.eof = TRUE; - return -1; - } - - i_stream_seek(stream->parent, astream->istream.parent_start_offset + - stream->istream.v_offset); - - stream->pos -= stream->skip; - stream->skip = 0; - - stream->buffer = i_stream_get_data(stream->parent, &pos); - if (pos > stream->pos) - ret = 0; - else do { - if ((ret = i_stream_read(stream->parent)) == -2) - return -2; - - stream->istream.stream_errno = stream->parent->stream_errno; - stream->istream.eof = stream->parent->eof; - stream->buffer = i_stream_get_data(stream->parent, &pos); - } while (pos <= stream->pos && ret > 0); - - left = astream->size - stream->istream.v_offset; - if (pos == left) - stream->istream.eof = TRUE; - else if (pos > left) { - i_error("Attachment file %s larger than expected " - "(%"PRIuUOFF_T")", i_stream_get_name(stream->parent), - astream->size); - pos = left; - stream->istream.eof = TRUE; - } else if (!stream->istream.eof) { - /* still more to read */ - } else if (stream->istream.stream_errno == ENOENT) { - /* lost the file */ - } else { - i_error("Attachment file %s smaller than expected " - "(%"PRIuUOFF_T" < %"PRIuUOFF_T")", - i_stream_get_name(stream->parent), - stream->istream.v_offset, astream->size); - stream->istream.stream_errno = EIO; - } - - ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) : - (ret == 0 ? 0 : -1); - stream->pos = pos; - i_assert(ret != -1 || stream->istream.eof || - stream->istream.stream_errno != 0); - return ret; -} - -static void -i_stream_attachment_seek(struct istream_private *stream, - uoff_t v_offset, bool mark ATTR_UNUSED) -{ - struct attachment_istream *astream = - (struct attachment_istream *)stream; - - i_assert(v_offset <= astream->size); - - stream->istream.v_offset = v_offset; - stream->skip = stream->pos = 0; -} - -static const struct stat * -i_stream_attachment_stat(struct istream_private *stream, bool exact ATTR_UNUSED) -{ - struct attachment_istream *astream = - (struct attachment_istream *)stream; - const struct stat *st; - - /* parent stream may be base64-decoder. don't waste time decoding the - entire stream, since we already know what the size is supposed - to be. */ - st = i_stream_stat(stream->parent, FALSE); - if (st == NULL) - return NULL; - - stream->statbuf = *st; - stream->statbuf.st_size = astream->size; - return &stream->statbuf; -} - -struct istream *i_stream_create_attachment(struct istream *input, uoff_t size) -{ - struct attachment_istream *astream; - - astream = i_new(struct attachment_istream, 1); - astream->size = size; - astream->istream.max_buffer_size = input->real_stream->max_buffer_size; - - astream->istream.parent = input; - astream->istream.read = i_stream_attachment_read; - astream->istream.seek = i_stream_attachment_seek; - astream->istream.stat = i_stream_attachment_stat; - - astream->istream.istream.readable_fd = input->readable_fd; - astream->istream.istream.blocking = input->blocking; - astream->istream.istream.seekable = input->seekable; - return i_stream_create(&astream->istream, input, - i_stream_get_fd(input)); -} diff -r 3945a3646c67 -r 9774ae8fff97 src/lib-storage/index/istream-attachment.h --- a/src/lib-storage/index/istream-attachment.h Thu Jun 28 00:27:13 2012 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -#ifndef ISTREAM_ATTACHMENT_H -#define ISTREAM_ATTACHMENT_H - -struct istream *i_stream_create_attachment(struct istream *input, uoff_t size); - -#endif diff -r 3945a3646c67 -r 9774ae8fff97 src/lib/Makefile.am --- a/src/lib/Makefile.am Thu Jun 28 00:27:13 2012 +0300 +++ b/src/lib/Makefile.am Thu Jun 28 01:01:58 2012 +0300 @@ -63,6 +63,7 @@ istream-mmap.c \ istream-rawlog.c \ istream-seekable.c \ + istream-sized.c \ istream-tee.c \ ioloop.c \ ioloop-iolist.c \ @@ -181,6 +182,7 @@ istream-private.h \ istream-rawlog.h \ istream-seekable.h \ + istream-sized.h \ istream-tee.h \ ioloop.h \ ioloop-iolist.h \ diff -r 3945a3646c67 -r 9774ae8fff97 src/lib/istream-sized.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib/istream-sized.c Thu Jun 28 01:01:58 2012 +0300 @@ -0,0 +1,121 @@ +/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "istream-private.h" +#include "istream-sized.h" + +struct sized_istream { + struct istream_private istream; + + uoff_t size; +}; + +static ssize_t i_stream_sized_read(struct istream_private *stream) +{ + struct sized_istream *sstream = + (struct sized_istream *)stream; + uoff_t left; + ssize_t ret; + size_t pos; + + if (stream->istream.v_offset + + (stream->pos - stream->skip) >= sstream->size) { + stream->istream.eof = TRUE; + return -1; + } + + i_stream_seek(stream->parent, sstream->istream.parent_start_offset + + stream->istream.v_offset); + + stream->pos -= stream->skip; + stream->skip = 0; + + stream->buffer = i_stream_get_data(stream->parent, &pos); + if (pos > stream->pos) + ret = 0; + else do { + if ((ret = i_stream_read(stream->parent)) == -2) + return -2; + + stream->istream.stream_errno = stream->parent->stream_errno; + stream->istream.eof = stream->parent->eof; + stream->buffer = i_stream_get_data(stream->parent, &pos); + } while (pos <= stream->pos && ret > 0); + + left = sstream->size - stream->istream.v_offset; + if (pos == left) + stream->istream.eof = TRUE; + else if (pos > left) { + i_error("%s is larger than expected (%"PRIuUOFF_T")", + i_stream_get_name(stream->parent), sstream->size); + pos = left; + stream->istream.eof = TRUE; + } else if (!stream->istream.eof) { + /* still more to read */ + } else if (stream->istream.stream_errno == ENOENT) { + /* lost the file */ + } else { + i_error("%s smaller than expected " + "(%"PRIuUOFF_T" < %"PRIuUOFF_T")", + i_stream_get_name(stream->parent), + stream->istream.v_offset, sstream->size); + stream->istream.stream_errno = EIO; + } + + ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) : + (ret == 0 ? 0 : -1); + stream->pos = pos; + i_assert(ret != -1 || stream->istream.eof || + stream->istream.stream_errno != 0); + return ret; +} + +static void +i_stream_sized_seek(struct istream_private *stream, + uoff_t v_offset, bool mark ATTR_UNUSED) +{ + struct sized_istream *sstream = (struct sized_istream *)stream; + + i_assert(v_offset <= sstream->size); + + stream->istream.v_offset = v_offset; + stream->skip = stream->pos = 0; +} + +static const struct stat * +i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED) +{ + struct sized_istream *sstream = (struct sized_istream *)stream; + const struct stat *st; + + /* parent stream may be base64-decoder. don't waste time decoding the + entire stream, since we already know what the size is supposed + to be. */ + st = i_stream_stat(stream->parent, FALSE); + if (st == NULL) + return NULL; + + stream->statbuf = *st; + stream->statbuf.st_size = sstream->size; From dovecot at dovecot.org Thu Jun 28 03:20:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 03:20:55 +0300 Subject: dovecot-2.2: istreams: Renamed i_stream_get_buffer_space() to i_... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/d7d1f24dde34 changeset: 14693:d7d1f24dde34 user: Timo Sirainen date: Thu Jun 28 01:30:50 2012 +0300 description: istreams: Renamed i_stream_get_buffer_space() to i_stream_try_alloc() diffstat: src/lib-mail/istream-binary-converter.c | 4 ++-- src/lib-mail/istream-dot.c | 4 ++-- src/lib-mail/istream-nonuls.c | 2 +- src/lib-ssl-iostream/istream-openssl.c | 2 +- src/lib/istream-base64-encoder.c | 5 ++--- src/lib/istream-chain.c | 4 ++-- src/lib/istream-concat.c | 5 ++--- src/lib/istream-crlf.c | 2 +- src/lib/istream-file.c | 2 +- src/lib/istream-private.h | 4 ++-- src/lib/istream.c | 6 +++--- 11 files changed, 19 insertions(+), 21 deletions(-) diffs (191 lines): diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib-mail/istream-binary-converter.c --- a/src/lib-mail/istream-binary-converter.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib-mail/istream-binary-converter.c Thu Jun 28 01:30:50 2012 +0300 @@ -36,14 +36,14 @@ struct istream_private *stream = &bstream->istream; size_t old_size, avail_size; - i_stream_get_buffer_space(stream, size, &avail_size); + i_stream_try_alloc(stream, size, &avail_size); if (avail_size < size) { old_size = stream->buffer_size; stream->buffer_size = nearest_power(stream->pos + size); stream->w_buffer = i_realloc(stream->w_buffer, old_size, stream->buffer_size); stream->buffer = stream->w_buffer; - i_stream_get_buffer_space(stream, size, &avail_size); + i_stream_try_alloc(stream, size, &avail_size); i_assert(avail_size >= size); } return stream->w_buffer + stream->pos; diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib-mail/istream-dot.c --- a/src/lib-mail/istream-dot.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib-mail/istream-dot.c Thu Jun 28 01:30:50 2012 +0300 @@ -44,7 +44,7 @@ i_assert(size != 0); } - if (!i_stream_get_buffer_space(stream, size, &avail)) + if (!i_stream_try_alloc(stream, size, &avail)) return -2; return 1; } @@ -113,7 +113,7 @@ ssize_t ret, ret1; if (dstream->pending[0] != '\0') { - if (!i_stream_get_buffer_space(stream, 1, &avail)) + if (!i_stream_try_alloc(stream, 1, &avail)) return -2; dest = stream->pos; (void)flush_pending(dstream, &dest); diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib-mail/istream-nonuls.c --- a/src/lib-mail/istream-nonuls.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib-mail/istream-nonuls.c Thu Jun 28 01:30:50 2012 +0300 @@ -37,7 +37,7 @@ return ret; data = i_stream_get_data(stream->parent, &size); - if (!i_stream_get_buffer_space(stream, size, &avail_size)) + if (!i_stream_try_alloc(stream, size, &avail_size)) return -2; if (size > avail_size) size = avail_size; diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib-ssl-iostream/istream-openssl.c --- a/src/lib-ssl-iostream/istream-openssl.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib-ssl-iostream/istream-openssl.c Thu Jun 28 01:30:50 2012 +0300 @@ -45,7 +45,7 @@ return ret; } - if (!i_stream_get_buffer_space(stream, 1, &size)) + if (!i_stream_try_alloc(stream, 1, &size)) return -2; while ((ret = SSL_read(sstream->ssl_io->ssl, diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-base64-encoder.c --- a/src/lib/istream-base64-encoder.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-base64-encoder.c Thu Jun 28 01:30:50 2012 +0300 @@ -52,8 +52,7 @@ if (bstream->cur_line_len == bstream->chars_per_line) { /* @UNSAFE: end of line, add newline */ - if (!i_stream_get_buffer_space(stream, - bstream->crlf ? 2 : 1, &avail)) + if (!i_stream_try_alloc(stream, bstream->crlf ? 2 : 1, &avail)) return FALSE; if (bstream->crlf) @@ -62,7 +61,7 @@ bstream->cur_line_len = 0; } - i_stream_get_buffer_space(stream, (size+2)/3*4, &avail); + i_stream_try_alloc(stream, (size+2)/3*4, &avail); buffer_avail = stream->buffer_size - stream->pos; if ((size + 2) / 3 * 4 > buffer_avail) { diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-chain.c --- a/src/lib/istream-chain.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-chain.c Thu Jun 28 01:30:50 2012 +0300 @@ -122,7 +122,7 @@ maximum buffer size */ cstream->istream.pos = 0; if (data_size > 0) { - if (!i_stream_get_buffer_space(&cstream->istream, data_size, &size)) + if (!i_stream_try_alloc(&cstream->istream, data_size, &size)) i_unreached(); i_assert(size >= data_size); } @@ -217,7 +217,7 @@ stream->buffer = stream->w_buffer; } else { stream->buffer = stream->w_buffer; - if (!i_stream_get_buffer_space(stream, pos - cur_pos, &size)) + if (!i_stream_try_alloc(stream, pos - cur_pos, &size)) return -2; if (pos > size) diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-concat.c --- a/src/lib/istream-concat.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-concat.c Thu Jun 28 01:30:50 2012 +0300 @@ -71,8 +71,7 @@ maximum buffer size */ cstream->istream.pos = 0; if (data_size > 0) { - if (!i_stream_get_buffer_space(&cstream->istream, - data_size, &size)) + if (!i_stream_try_alloc(&cstream->istream, data_size, &size)) i_unreached(); i_assert(size >= data_size); } @@ -156,7 +155,7 @@ stream->buffer = stream->w_buffer; } else { stream->buffer = stream->w_buffer; - if (!i_stream_get_buffer_space(stream, pos - cur_pos, &size)) + if (!i_stream_try_alloc(stream, pos - cur_pos, &size)) return -2; if (pos > size) diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-crlf.c --- a/src/lib/istream-crlf.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-crlf.c Thu Jun 28 01:30:50 2012 +0300 @@ -30,7 +30,7 @@ i_assert(size != 0); } - if (!i_stream_get_buffer_space(stream, size, &avail)) + if (!i_stream_try_alloc(stream, size, &avail)) return -2; return 1; } diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-file.c --- a/src/lib/istream-file.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-file.c Thu Jun 28 01:30:50 2012 +0300 @@ -55,7 +55,7 @@ size_t size; ssize_t ret; - if (!i_stream_get_buffer_space(stream, 1, &size)) + if (!i_stream_try_alloc(stream, 1, &size)) return -2; if (stream->fd == -1) { diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream-private.h --- a/src/lib/istream-private.h Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream-private.h Thu Jun 28 01:30:50 2012 +0300 @@ -54,8 +54,8 @@ void i_stream_compress(struct istream_private *stream); void i_stream_grow_buffer(struct istream_private *stream, size_t bytes); bool ATTR_NOWARN_UNUSED_RESULT -i_stream_get_buffer_space(struct istream_private *stream, - size_t wanted_size, size_t *size_r); +i_stream_try_alloc(struct istream_private *stream, + size_t wanted_size, size_t *size_r); ssize_t i_stream_read_copy_from_parent(struct istream *istream); void i_stream_default_seek(struct istream_private *stream, uoff_t v_offset, bool mark); diff -r 9774ae8fff97 -r d7d1f24dde34 src/lib/istream.c --- a/src/lib/istream.c Thu Jun 28 01:01:58 2012 +0300 +++ b/src/lib/istream.c Thu Jun 28 01:30:50 2012 +0300 @@ -495,8 +495,8 @@ } } -bool i_stream_get_buffer_space(struct istream_private *stream, - size_t wanted_size, size_t *size_r) +bool i_stream_try_alloc(struct istream_private *stream, + size_t wanted_size, size_t *size_r) { i_assert(wanted_size > 0); @@ -521,7 +521,7 @@ struct istream_private *stream = _stream->real_stream; size_t size2; - i_stream_get_buffer_space(stream, size, &size2); + i_stream_try_alloc(stream, size, &size2); if (size > size2) return FALSE; From dovecot at dovecot.org Thu Jun 28 03:20:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 03:20:55 +0300 Subject: dovecot-2.2: Added i_stream_alloc() Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/8909e8428b82 changeset: 14694:8909e8428b82 user: Timo Sirainen date: Thu Jun 28 03:18:55 2012 +0300 description: Added i_stream_alloc() diffstat: src/lib-mail/istream-binary-converter.c | 38 ++++++++------------------------ src/lib/istream-private.h | 1 + src/lib/istream.c | 17 ++++++++++++++ 3 files changed, 28 insertions(+), 28 deletions(-) diffs (126 lines): diff -r d7d1f24dde34 -r 8909e8428b82 src/lib-mail/istream-binary-converter.c --- a/src/lib-mail/istream-binary-converter.c Thu Jun 28 01:30:50 2012 +0300 +++ b/src/lib-mail/istream-binary-converter.c Thu Jun 28 03:18:55 2012 +0300 @@ -30,25 +30,6 @@ static void stream_add_data(struct binary_converter_istream *bstream, const void *data, size_t size); -static void * -stream_alloc_data(struct binary_converter_istream *bstream, size_t size) -{ - struct istream_private *stream = &bstream->istream; - size_t old_size, avail_size; - - i_stream_try_alloc(stream, size, &avail_size); - if (avail_size < size) { - old_size = stream->buffer_size; - stream->buffer_size = nearest_power(stream->pos + size); - stream->w_buffer = i_realloc(stream->w_buffer, old_size, - stream->buffer_size); - stream->buffer = stream->w_buffer; - i_stream_try_alloc(stream, size, &avail_size); - i_assert(avail_size >= size); - } - return stream->w_buffer + stream->pos; -} - static bool part_can_convert(const struct message_part *part) { /* some MUAs use "c-t-e: binary" for multiparts. @@ -92,13 +73,14 @@ stream_finish_convert_decision(bstream); } - memcpy(stream_alloc_data(bstream, size), data, size); + memcpy(i_stream_alloc(&bstream->istream, size), data, size); bstream->istream.pos += size; } static void stream_encode_base64(struct binary_converter_istream *bstream, const void *_data, size_t size) { + struct istream_private *stream = &bstream->istream; const unsigned char *data = _data; buffer_t buf; void *dest; @@ -128,23 +110,23 @@ } if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) { - memcpy(stream_alloc_data(bstream, 2), "\r\n", 2); - bstream->istream.pos += 2; + memcpy(i_stream_alloc(stream, 2), "\r\n", 2); + stream->pos += 2; bstream->base64_block_pos = 0; } - dest = stream_alloc_data(bstream, BASE64_BLOCK_SIZE); + dest = i_stream_alloc(stream, BASE64_BLOCK_SIZE); buffer_create_data(&buf, dest, BASE64_BLOCK_SIZE); base64_encode(base64_block, base64_block_len, &buf); - bstream->istream.pos += buf.used; + stream->pos += buf.used; bstream->base64_block_pos++; bstream->base64_delayed_len = 0; } while (size >= BASE64_BLOCK_INPUT_SIZE) { if (bstream->base64_block_pos == BASE64_BLOCKS_PER_LINE) { - memcpy(stream_alloc_data(bstream, 2), "\r\n", 2); - bstream->istream.pos += 2; + memcpy(i_stream_alloc(stream, 2), "\r\n", 2); + stream->pos += 2; bstream->base64_block_pos = 0; } @@ -160,10 +142,10 @@ } max_encoded_size = MAX_BASE64_ENCODED_SIZE(encode_size); - dest = stream_alloc_data(bstream, max_encoded_size); + dest = i_stream_alloc(stream, max_encoded_size); buffer_create_data(&buf, dest, max_encoded_size); base64_encode(data, encode_size, &buf); - bstream->istream.pos += buf.used; + stream->pos += buf.used; bstream->base64_block_pos += encode_blocks; data += encode_size; diff -r d7d1f24dde34 -r 8909e8428b82 src/lib/istream-private.h --- a/src/lib/istream-private.h Thu Jun 28 01:30:50 2012 +0300 +++ b/src/lib/istream-private.h Thu Jun 28 03:18:55 2012 +0300 @@ -56,6 +56,7 @@ bool ATTR_NOWARN_UNUSED_RESULT i_stream_try_alloc(struct istream_private *stream, size_t wanted_size, size_t *size_r); +void *i_stream_alloc(struct istream_private *stream, size_t size); ssize_t i_stream_read_copy_from_parent(struct istream *istream); void i_stream_default_seek(struct istream_private *stream, uoff_t v_offset, bool mark); diff -r d7d1f24dde34 -r 8909e8428b82 src/lib/istream.c --- a/src/lib/istream.c Thu Jun 28 01:30:50 2012 +0300 +++ b/src/lib/istream.c Thu Jun 28 03:18:55 2012 +0300 @@ -515,6 +515,23 @@ return stream->pos != stream->buffer_size; } +void *i_stream_alloc(struct istream_private *stream, size_t size) +{ + size_t old_size, avail_size; + + i_stream_try_alloc(stream, size, &avail_size); + if (avail_size < size) { + old_size = stream->buffer_size; + stream->buffer_size = nearest_power(stream->pos + size); + stream->w_buffer = i_realloc(stream->w_buffer, old_size, + stream->buffer_size); + stream->buffer = stream->w_buffer; + i_stream_try_alloc(stream, size, &avail_size); + i_assert(avail_size >= size); + } + return stream->w_buffer + stream->pos; +} + bool i_stream_add_data(struct istream *_stream, const unsigned char *data, size_t size) { From dovecot at dovecot.org Thu Jun 28 03:20:55 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 03:20:55 +0300 Subject: dovecot-2.2: hash-format object can now be reset to build multip... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/d419c6cde162 changeset: 14695:d419c6cde162 user: Timo Sirainen date: Thu Jun 28 03:20:34 2012 +0300 description: hash-format object can now be reset to build multiple hashes. diffstat: src/lib/hash-format.c | 32 ++++++++++++++++++++++++-------- src/lib/hash-format.h | 4 ++++ 2 files changed, 28 insertions(+), 8 deletions(-) diffs (93 lines): diff -r 8909e8428b82 -r d419c6cde162 src/lib/hash-format.c --- a/src/lib/hash-format.c Thu Jun 28 03:18:55 2012 +0300 +++ b/src/lib/hash-format.c Thu Jun 28 03:20:34 2012 +0300 @@ -27,6 +27,7 @@ const char *str; struct hash_format_list *list, **pos; + unsigned char *digest; }; static int @@ -148,6 +149,16 @@ list->method->loop(list->context, data, size); } +void hash_format_reset(struct hash_format *format) +{ + struct hash_format_list *list; + + for (list = format->list; list != NULL; list = list->next) { + memset(list->context, 0, list->method->context_size); + list->method->init(list->context); + } +} + static void hash_format_digest(string_t *dest, const struct hash_format_list *list, const unsigned char *digest) @@ -182,21 +193,18 @@ } } -void hash_format_deinit(struct hash_format **_format, string_t *dest) +void hash_format_write(struct hash_format *format, string_t *dest) { - struct hash_format *format = *_format; struct hash_format_list *list; const char *p; - unsigned char *digest; unsigned int i, max_digest_size = 0; - *_format = NULL; - for (list = format->list; list != NULL; list = list->next) { if (max_digest_size < list->method->digest_size) max_digest_size = list->method->digest_size; } - digest = p_malloc(format->pool, max_digest_size); + if (format->digest == NULL) + format->digest = p_malloc(format->pool, max_digest_size); list = format->list; for (i = 0; format->str[i] != '\0'; i++) { @@ -207,15 +215,23 @@ /* we already verified that the string is ok */ i_assert(list != NULL); - list->method->result(list->context, digest); - hash_format_digest(dest, list, digest); + list->method->result(list->context, format->digest); + hash_format_digest(dest, list, format->digest); list = list->next; p = strchr(format->str+i, '}'); i_assert(p != NULL); i = p - format->str; } +} +void hash_format_deinit(struct hash_format **_format, string_t *dest) +{ + struct hash_format *format = *_format; + + *_format = NULL; + + hash_format_write(format, dest); pool_unref(&format->pool); } diff -r 8909e8428b82 -r d419c6cde162 src/lib/hash-format.h --- a/src/lib/hash-format.h Thu Jun 28 03:18:55 2012 +0300 +++ b/src/lib/hash-format.h Thu Jun 28 03:20:34 2012 +0300 @@ -11,6 +11,10 @@ /* Add more data to hash. */ void hash_format_loop(struct hash_format *format, const void *data, size_t size); +/* Finish the hash and write it into given string. */ +void hash_format_write(struct hash_format *format, string_t *dest); +/* Reset hash to initial state. */ +void hash_format_reset(struct hash_format *format); /* Write the hash into given string and free used memory. */ void hash_format_deinit(struct hash_format **format, string_t *dest); /* Free used memory without writing to string. */ From dovecot at dovecot.org Thu Jun 28 06:32:06 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 06:32:06 +0300 Subject: dovecot-2.1: imap: If selected mailbox is DELETEd, disconnect cl... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/81a659ab9183 changeset: 14582:81a659ab9183 user: Timo Sirainen date: Thu Jun 28 06:32:00 2012 +0300 description: imap: If selected mailbox is DELETEd, disconnect client. diffstat: src/imap/cmd-delete.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diffs (30 lines): diff -r 06ba409a63d3 -r 81a659ab9183 src/imap/cmd-delete.c --- a/src/imap/cmd-delete.c Wed Jun 27 12:29:42 2012 +0300 +++ b/src/imap/cmd-delete.c Thu Jun 28 06:32:00 2012 +0300 @@ -10,6 +10,7 @@ struct mailbox *box; const char *name, *errstr; enum mail_error error; + bool disconnect = FALSE; /* */ if (!client_read_string_args(cmd, 1, &name)) @@ -31,6 +32,7 @@ /* deleting selected mailbox. close it first */ client_search_updates_free(client); mailbox_free(&client->mailbox); + disconnect = TRUE; } if (mailbox_delete(box) == 0) @@ -45,5 +47,10 @@ } } mailbox_free(&box); + + if (disconnect) { + client_disconnect_with_error(cmd->client, + "Selected mailbox was deleted, have to disconnect."); + } return TRUE; } From dovecot at dovecot.org Thu Jun 28 09:28:15 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Thu, 28 Jun 2012 09:28:15 +0300 Subject: dovecot-2.2: Fixed ostream's new error handling not to always as... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/b1a0e44e1dac changeset: 14696:b1a0e44e1dac user: Timo Sirainen date: Thu Jun 28 09:28:05 2012 +0300 description: Fixed ostream's new error handling not to always assert-crash. diffstat: src/lib/ostream.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r d419c6cde162 -r b1a0e44e1dac src/lib/ostream.c --- a/src/lib/ostream.c Thu Jun 28 03:20:34 2012 +0300 +++ b/src/lib/ostream.c Thu Jun 28 09:28:05 2012 +0300 @@ -35,7 +35,7 @@ { struct ostream *stream = *_stream; - if (!stream->real_stream->last_errors_not_checked && + if (stream->real_stream->last_errors_not_checked && !stream->real_stream->error_handling_disabled && stream->real_stream->iostream.refcount == 1) { i_panic("output stream %s is missing error handling", From dovecot at dovecot.org Fri Jun 29 06:15:10 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 06:15:10 +0300 Subject: dovecot-2.1: dbox: Fixed a potential crash when building message... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/3efbc4a8219b changeset: 14583:3efbc4a8219b user: Timo Sirainen date: Fri Jun 29 06:14:51 2012 +0300 description: dbox: Fixed a potential crash when building message stream from external attachments. diffstat: src/lib-storage/index/dbox-common/dbox-attachment.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (14 lines): diff -r 81a659ab9183 -r 3efbc4a8219b src/lib-storage/index/dbox-common/dbox-attachment.c --- a/src/lib-storage/index/dbox-common/dbox-attachment.c Thu Jun 28 06:32:00 2012 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-attachment.c Fri Jun 29 06:14:51 2012 +0300 @@ -212,9 +212,9 @@ input = i_stream_create_limit(*stream, trailer_size); array_append(&streams, &input, 1); - (void)array_append_space(&streams); } } + (void)array_append_space(&streams); inputs = array_idx_modifiable(&streams, 0); i_stream_unref(stream); From dovecot at dovecot.org Fri Jun 29 08:01:25 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 08:01:25 +0300 Subject: dovecot-2.2: istreams: Set (file), (fd) or (buffer) as default n... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/69334bf138cf changeset: 14697:69334bf138cf user: Timo Sirainen date: Fri Jun 29 07:56:02 2012 +0300 description: istreams: Set (file), (fd) or (buffer) as default name for those input streams. diffstat: src/lib/istream-data.c | 1 + src/lib/istream-file.c | 5 ++++- src/lib/ostream-buffer.c | 5 ++++- 3 files changed, 9 insertions(+), 2 deletions(-) diffs (52 lines): diff -r b1a0e44e1dac -r 69334bf138cf src/lib/istream-data.c --- a/src/lib/istream-data.c Thu Jun 28 09:28:05 2012 +0300 +++ b/src/lib/istream-data.c Fri Jun 29 07:56:02 2012 +0300 @@ -33,5 +33,6 @@ stream->istream.seekable = TRUE; i_stream_create(stream, NULL, -1); stream->statbuf.st_size = size; + i_stream_set_name(&stream->istream, "(buffer)"); return &stream->istream; } diff -r b1a0e44e1dac -r 69334bf138cf src/lib/istream-file.c --- a/src/lib/istream-file.c Thu Jun 28 09:28:05 2012 +0300 +++ b/src/lib/istream-file.c Fri Jun 29 07:56:02 2012 +0300 @@ -171,6 +171,7 @@ i_stream_create_file_common(int fd, size_t max_buffer_size, bool autoclose_fd) { struct file_istream *fstream; + struct istream *input; struct stat st; bool is_file; @@ -206,7 +207,9 @@ } fstream->istream.istream.readable_fd = TRUE; - return i_stream_create(&fstream->istream, NULL, fd); + input = i_stream_create(&fstream->istream, NULL, fd); + i_stream_set_name(input, is_file ? "(file)" : "(fd)"); + return input; } struct istream *i_stream_create_fd(int fd, size_t max_buffer_size, diff -r b1a0e44e1dac -r 69334bf138cf src/lib/ostream-buffer.c --- a/src/lib/ostream-buffer.c Thu Jun 28 09:28:05 2012 +0300 +++ b/src/lib/ostream-buffer.c Fri Jun 29 07:56:02 2012 +0300 @@ -51,6 +51,7 @@ struct ostream *o_stream_create_buffer(buffer_t *buf) { struct buffer_ostream *bstream; + struct ostream *output; bstream = i_new(struct buffer_ostream, 1); bstream->ostream.max_buffer_size = (size_t)-1; @@ -59,5 +60,7 @@ bstream->ostream.write_at = o_stream_buffer_write_at; bstream->buf = buf; - return o_stream_create(&bstream->ostream, NULL); + output = o_stream_create(&bstream->ostream, NULL); + o_stream_set_name(output, "(buffer)"); + return output; } From dovecot at dovecot.org Fri Jun 29 08:01:25 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 08:01:25 +0300 Subject: dovecot-2.2: lib-mail: Added istream-attachment-[connector|extra... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/ffab35ef2e5b changeset: 14698:ffab35ef2e5b user: Timo Sirainen date: Fri Jun 29 08:00:19 2012 +0300 description: lib-mail: Added istream-attachment-[connector|extractor]. istream-attachment-extractor can be used to parse messages and extract attachment MIME parts from them to wanted output streams. The attachments are base64-decoded if they can be later re-encoded to original input without any changes. istream-attachment-connector does the reverse by taking the base istream and attachment istreams and merging them together to create the original istream. diffstat: src/lib-mail/Makefile.am | 20 +- src/lib-mail/istream-attachment-connector.c | 123 ++++ src/lib-mail/istream-attachment-connector.h | 26 + src/lib-mail/istream-attachment-extractor.c | 689 ++++++++++++++++++++++++++++ src/lib-mail/istream-attachment-extractor.h | 59 ++ src/lib-mail/test-istream-attachment.c | 293 +++++++++++ 6 files changed, 1208 insertions(+), 2 deletions(-) diffs (truncated from 1262 to 300 lines): diff -r 69334bf138cf -r ffab35ef2e5b src/lib-mail/Makefile.am --- a/src/lib-mail/Makefile.am Fri Jun 29 07:56:02 2012 +0300 +++ b/src/lib-mail/Makefile.am Fri Jun 29 08:00:19 2012 +0300 @@ -6,6 +6,8 @@ -I$(top_srcdir)/src/lib-charset libmail_la_SOURCES = \ + istream-attachment-connector.c \ + istream-attachment-extractor.c \ istream-binary-converter.c \ istream-dot.c \ istream-header-filter.c \ @@ -29,6 +31,8 @@ rfc822-parser.c headers = \ + istream-attachment-connector.h \ + istream-attachment-extractor.h \ istream-binary-converter.h \ istream-dot.h \ istream-header-filter.h \ @@ -57,6 +61,7 @@ test_programs = \ test-istream-dot \ + test-istream-attachment \ test-istream-binary-converter \ test-istream-header-filter \ test-mbox-from \ @@ -81,9 +86,20 @@ test_istream_dot_LDADD = istream-dot.lo $(test_libs) test_istream_dot_DEPENDENCIES = istream-dot.lo $(test_libs) +message_parser_objects = \ + message-parser.lo \ + message-header-parser.lo \ + message-size.lo \ + rfc822-parser.lo \ + rfc2231-parser.lo + test_istream_binary_converter_SOURCES = test-istream-binary-converter.c -test_istream_binary_converter_LDADD = istream-binary-converter.lo message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs) -test_istream_binary_converter_DEPENDENCIES = istream-binary-converter.lo message-parser.lo message-header-parser.lo message-size.lo rfc822-parser.lo rfc2231-parser.lo $(test_libs) +test_istream_binary_converter_LDADD = istream-binary-converter.lo $(message_parser_objects) $(test_libs) +test_istream_binary_converter_DEPENDENCIES = istream-binary-converter.lo $(message_parser_objects) $(test_libs) + +test_istream_attachment_SOURCES = test-istream-attachment.c +test_istream_attachment_LDADD = istream-attachment-extractor.lo istream-attachment-connector.lo $(message_parser_objects) $(test_libs) +test_istream_attachment_DEPENDENCIES = istream-attachment-extractor.lo istream-attachment-connector.lo $(message_parser_objects) $(test_libs) test_istream_header_filter_SOURCES = test-istream-header-filter.c test_istream_header_filter_LDADD = istream-header-filter.lo message-header-parser.lo $(test_libs) diff -r 69334bf138cf -r ffab35ef2e5b src/lib-mail/istream-attachment-connector.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-attachment-connector.c Fri Jun 29 08:00:19 2012 +0300 @@ -0,0 +1,123 @@ +/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "array.h" +#include "istream.h" +#include "istream-concat.h" +#include "istream-sized.h" +#include "istream-base64-encoder.h" +#include "istream-attachment-connector.h" + +struct istream_attachment_connector { + pool_t pool; + struct istream *base_input; + uoff_t msg_size; + + uoff_t encoded_offset; + ARRAY_DEFINE(streams, struct istream *); +}; + +struct istream_attachment_connector * +istream_attachment_connector_begin(struct istream *base_input, uoff_t msg_size) +{ + struct istream_attachment_connector *conn; + pool_t pool; + + pool = pool_alloconly_create("istream-attachment-connector", 1024); + conn = p_new(pool, struct istream_attachment_connector, 1); + conn->pool = pool; + conn->base_input = base_input; + conn->msg_size = msg_size; + p_array_init(&conn->streams, pool, 8); + i_stream_ref(conn->base_input); + return conn; +} + +int istream_attachment_connector_add(struct istream_attachment_connector *conn, + struct istream *decoded_input, + uoff_t start_offset, uoff_t encoded_size, + unsigned int base64_blocks_per_line, + bool base64_have_crlf, + const char **error_r) +{ + struct istream *input, *input2; + uoff_t base_prefix_size; + + if (start_offset < conn->encoded_offset) { + *error_r = t_strdup_printf( + "Attachment %s points before the previous attachment " + "(%"PRIuUOFF_T" < %"PRIuUOFF_T")", + i_stream_get_name(decoded_input), + start_offset, conn->encoded_offset); + return -1; + } + base_prefix_size = start_offset - conn->encoded_offset; + if (start_offset + encoded_size > conn->msg_size) { + *error_r = t_strdup_printf( + "Attachment %s points outside message " + "(%"PRIuUOFF_T" + %"PRIuUOFF_T" > %"PRIuUOFF_T")", + i_stream_get_name(decoded_input), + start_offset, encoded_size, + conn->msg_size); + return -1; + } + + if (base_prefix_size > 0) { + /* add a part of the base message before the attachment */ + input = i_stream_create_limit(conn->base_input, + base_prefix_size); + array_append(&conn->streams, &input, 1); + i_stream_skip(conn->base_input, base_prefix_size); + conn->encoded_offset += base_prefix_size; + } + conn->encoded_offset += encoded_size; + + if (base64_blocks_per_line == 0) { + input = decoded_input; + i_stream_ref(input); + } else { + input = i_stream_create_base64_encoder(decoded_input, + base64_blocks_per_line*4, + base64_have_crlf); + } + input2 = i_stream_create_sized(input, encoded_size); + array_append(&conn->streams, &input2, 1); + i_stream_unref(&input); + return 0; +} + +struct istream * +istream_attachment_connector_finish(struct istream_attachment_connector **_conn) +{ + struct istream_attachment_connector *conn = *_conn; + struct istream **inputs, *input; + uoff_t trailer_size; + + *_conn = NULL; + + if (conn->base_input->v_offset != conn->msg_size) { + i_assert(conn->base_input->v_offset < conn->msg_size); + + trailer_size = conn->msg_size - conn->encoded_offset; + input = i_stream_create_limit(conn->base_input, trailer_size); + array_append(&conn->streams, &input, 1); + } + array_append_zero(&conn->streams); + + inputs = array_idx_modifiable(&conn->streams, 0); + input = i_stream_create_concat(inputs); + + i_stream_unref(&conn->base_input); + pool_unref(&conn->pool); + return input; +} + +void istream_attachment_connector_abort(struct istream_attachment_connector **_conn) +{ + struct istream_attachment_connector *conn = *_conn; + + *_conn = NULL; + + i_stream_unref(&conn->base_input); + pool_unref(&conn->pool); +} diff -r 69334bf138cf -r ffab35ef2e5b src/lib-mail/istream-attachment-connector.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-attachment-connector.h Fri Jun 29 08:00:19 2012 +0300 @@ -0,0 +1,26 @@ +#ifndef ISTREAM_ATTACHMENT_CONNECTOR_H +#define ISTREAM_ATTACHMENT_CONNECTOR_H + +/* Start building a message stream. The base_input contains the message + without attachments. The final stream must be exactly msg_size bytes. */ +struct istream_attachment_connector * +istream_attachment_connector_begin(struct istream *base_input, uoff_t msg_size); + +/* Add the given input stream as attachment. The attachment starts at the given + start_offset in the (original) message. If base64_blocks_per_line is + non-zero, the input is base64-encoded with the given settings. The + (resulting base64-encoded) input must have exactly encoded_size bytes. + + Returns 0 if the input was ok, -1 if we've already reached msg_size */ +int istream_attachment_connector_add(struct istream_attachment_connector *conn, + struct istream *decoded_input, + uoff_t start_offset, uoff_t encoded_size, + unsigned int base64_blocks_per_line, + bool base64_have_crlf, + const char **error_r); + +struct istream * +istream_attachment_connector_finish(struct istream_attachment_connector **conn); +void istream_attachment_connector_abort(struct istream_attachment_connector **conn); + +#endif diff -r 69334bf138cf -r ffab35ef2e5b src/lib-mail/istream-attachment-extractor.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/lib-mail/istream-attachment-extractor.c Fri Jun 29 08:00:19 2012 +0300 @@ -0,0 +1,689 @@ +/* Copyright (c) 2012 Dovecot authors, see the included COPYING file */ + +#include "lib.h" +#include "istream-private.h" +#include "ostream.h" +#include "base64.h" +#include "buffer.h" +#include "str.h" +#include "hash-format.h" +#include "rfc822-parser.h" +#include "message-parser.h" +#include "istream-attachment-extractor.h" + +#define BASE64_ATTACHMENT_MAX_EXTRA_BYTES 1024 + +enum mail_attachment_state { + MAIL_ATTACHMENT_STATE_NO, + MAIL_ATTACHMENT_STATE_MAYBE, + MAIL_ATTACHMENT_STATE_YES +}; + +enum base64_state { + BASE64_STATE_0 = 0, + BASE64_STATE_1, + BASE64_STATE_2, + BASE64_STATE_3, + BASE64_STATE_CR, + BASE64_STATE_EOB, + BASE64_STATE_EOM +}; + +struct attachment_istream_part { + char *content_type, *content_disposition; + enum mail_attachment_state state; + /* start offset of the message part in the original input stream */ + uoff_t start_offset; + + /* for saving attachments base64-decoded: */ + enum base64_state base64_state; + unsigned int base64_line_blocks, cur_base64_blocks; + uoff_t base64_bytes; + bool base64_have_crlf; /* CRLF linefeeds */ + bool base64_failed; + + int temp_fd; + struct ostream *temp_output; + buffer_t *part_buf; +}; + +struct attachment_istream { + struct istream_private istream; + pool_t pool; + + struct istream_attachment_settings set; + void *context; + + struct message_parser_ctx *parser; + struct message_part *cur_part; + struct attachment_istream_part part; + + bool retry_read; +}; + +static void stream_add_data(struct attachment_istream *astream, + const void *data, size_t size) +{ + if (size > 0) { + memcpy(i_stream_alloc(&astream->istream, size), data, size); + astream->istream.pos += size; + } +} + +static void parse_content_type(struct attachment_istream *astream, + const struct message_header_line *hdr) +{ + struct rfc822_parser_context parser; + string_t *content_type; + + rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); + rfc822_skip_lwsp(&parser); + + T_BEGIN { + content_type = t_str_new(64); + if (rfc822_parse_content_type(&parser, content_type) >= 0) { + i_free(astream->part.content_type); + astream->part.content_type = + i_strdup(str_c(content_type)); From dovecot at dovecot.org Fri Jun 29 08:01:25 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 08:01:25 +0300 Subject: dovecot-2.2: lib-storage: Use the new istream-attachment-* APIs ... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/38b0986605a6 changeset: 14699:38b0986605a6 user: Timo Sirainen date: Fri Jun 29 08:01:08 2012 +0300 description: lib-storage: Use the new istream-attachment-* APIs to handle external mail attachments. diffstat: src/lib-storage/index/dbox-common/dbox-attachment.c | 82 +- src/lib-storage/index/index-attachment.c | 713 +++---------------- 2 files changed, 133 insertions(+), 662 deletions(-) diffs (truncated from 925 to 300 lines): diff -r ffab35ef2e5b -r 38b0986605a6 src/lib-storage/index/dbox-common/dbox-attachment.c --- a/src/lib-storage/index/dbox-common/dbox-attachment.c Fri Jun 29 08:00:19 2012 +0300 +++ b/src/lib-storage/index/dbox-common/dbox-attachment.c Fri Jun 29 08:01:08 2012 +0300 @@ -2,10 +2,8 @@ #include "lib.h" #include "istream.h" -#include "istream-concat.h" #include "str.h" -#include "istream-sized.h" -#include "istream-base64-encoder.h" +#include "istream-attachment-connector.h" #include "dbox-file.h" #include "dbox-save.h" #include "dbox-attachment.h" @@ -143,13 +141,12 @@ const char **error_r) { ARRAY_TYPE(mail_attachment_extref) extrefs_arr; - ARRAY_DEFINE(streams, struct istream *); const struct mail_attachment_extref *extref; - struct istream **inputs, *input, *input2; + struct istream_attachment_connector *conn; + struct istream *input; const char *path, *path_suffix; - uoff_t psize, last_voffset = 0; - unsigned int i; - int ret = 1; + uoff_t msg_size; + int ret; *error_r = NULL; @@ -159,69 +156,30 @@ *error_r = "Broken ext-refs string"; return 0; } - psize = dbox_file_get_plaintext_size(file); + msg_size = dbox_file_get_plaintext_size(file); + conn = istream_attachment_connector_begin(*stream, msg_size); - t_array_init(&streams, 8); + path_suffix = file->storage->v.get_attachment_path_suffix(file); array_foreach(&extrefs_arr, extref) { - path_suffix = file->storage->v.get_attachment_path_suffix(file); path = t_strdup_printf("%s/%s%s", file->storage->attachment_dir, extref->path, path_suffix); + input = i_stream_create_file(path, IO_BLOCK_SIZE); - if (extref->start_offset != last_voffset) { - uoff_t part_size = extref->start_offset - last_voffset; - - if ((*stream)->v_offset + part_size > psize) { - *error_r = t_strdup_printf( - "ext-refs point outside message " - "(%"PRIuUOFF_T" + %"PRIuUOFF_T" > %"PRIuUOFF_T")", - (*stream)->v_offset, part_size, psize); - ret = 0; - } - - input = i_stream_create_limit(*stream, part_size); - array_append(&streams, &input, 1); - i_stream_seek(*stream, (*stream)->v_offset + part_size); - last_voffset += part_size; - } - - last_voffset += extref->size; - input2 = i_stream_create_file(path, IO_BLOCK_SIZE); - - if (extref->base64_blocks_per_line > 0) { - input = i_stream_create_base64_encoder(input2, - extref->base64_blocks_per_line*4, - extref->base64_have_crlf); - i_stream_unref(&input2); - input2 = input; - } - - input = i_stream_create_sized(input2, extref->size); - i_stream_unref(&input2); - array_append(&streams, &input, 1); - } - - if (psize != (*stream)->v_offset) { - if ((*stream)->v_offset > psize) { - *error_r = t_strdup_printf( - "ext-refs point outside message " - "(%"PRIuUOFF_T" > %"PRIuUOFF_T")", - (*stream)->v_offset, psize); - ret = 0; - } else { - uoff_t trailer_size = psize - last_voffset; - - input = i_stream_create_limit(*stream, trailer_size); - array_append(&streams, &input, 1); - array_append_zero(&streams); + ret = istream_attachment_connector_add(conn, input, + extref->start_offset, extref->size, + extref->base64_blocks_per_line, + extref->base64_have_crlf, error_r); + i_stream_unref(&input); + if (ret < 0) { + istream_attachment_connector_abort(&conn); + return 0; } } - inputs = array_idx_modifiable(&streams, 0); + input = istream_attachment_connector_finish(&conn); i_stream_unref(stream); - *stream = i_stream_create_concat(inputs); - for (i = 0; inputs[i] != NULL; i++) - i_stream_unref(&inputs[i]); - return ret; + *stream = input; + return 1; } int dbox_attachment_file_get_stream(struct dbox_file *file, diff -r ffab35ef2e5b -r 38b0986605a6 src/lib-storage/index/index-attachment.c --- a/src/lib-storage/index/index-attachment.c Fri Jun 29 08:00:19 2012 +0300 +++ b/src/lib-storage/index/index-attachment.c Fri Jun 29 08:01:08 2012 +0300 @@ -10,57 +10,17 @@ #include "str.h" #include "message-parser.h" #include "rfc822-parser.h" +#include "istream-attachment-extractor.h" #include "mail-user.h" #include "index-mail.h" #include "index-attachment.h" -#define BASE64_ATTACHMENT_MAX_EXTRA_BYTES 1024 - -enum mail_attachment_state { - MAIL_ATTACHMENT_STATE_NO, - MAIL_ATTACHMENT_STATE_MAYBE, - MAIL_ATTACHMENT_STATE_YES -}; - -enum base64_state { - BASE64_STATE_0 = 0, - BASE64_STATE_1, - BASE64_STATE_2, - BASE64_STATE_3, - BASE64_STATE_CR, - BASE64_STATE_EOB, - BASE64_STATE_EOM -}; - -struct mail_save_attachment_part { - char *content_type, *content_disposition; - enum mail_attachment_state state; - /* start offset of the message part in the original input stream */ - uoff_t start_offset; - - /* for saving attachments base64-decoded: */ - enum base64_state base64_state; - unsigned int base64_line_blocks, cur_base64_blocks; - uoff_t base64_bytes; - bool base64_have_crlf; /* CRLF linefeeds */ - bool base64_failed; - - int temp_fd; - struct ostream *output; - struct hash_format *part_hash; - buffer_t *part_buf; -}; - struct mail_save_attachment { pool_t pool; - struct message_parser_ctx *parser; struct fs *fs; struct istream *input; - /* per-MIME part data */ - struct mail_save_attachment_part part; - struct message_part *prev_part; - + struct fs_file *cur_file; ARRAY_TYPE(mail_attachment_extref) extrefs; }; @@ -70,102 +30,25 @@ storage->set->mail_attachment_dir); } -void index_attachment_save_begin(struct mail_save_context *ctx, - struct fs *fs, struct istream *input) +static bool index_attachment_want(const struct istream_attachment_header *hdr, + void *context) { - struct mail_storage *storage = ctx->transaction->box->storage; - pool_t pool; + struct mail_save_context *ctx = context; + struct mail_attachment_part apart; - i_assert(ctx->attach == NULL); + memset(&apart, 0, sizeof(apart)); + apart.part = hdr->part; + apart.content_type = hdr->content_type; + apart.content_disposition = hdr->content_disposition; - if (*storage->set->mail_attachment_dir == '\0') - return; - - pool = pool_alloconly_create("save attachment", 1024*4); - ctx->attach = p_new(pool, struct mail_save_attachment, 1); - ctx->attach->pool = pool; - ctx->attach->fs = fs; - ctx->attach->input = input; - ctx->attach->parser = - message_parser_init(ctx->attach->pool, input, 0, 0); - p_array_init(&ctx->attach->extrefs, ctx->attach->pool, 8); + return ctx->part_is_attachment == NULL ? TRUE : + ctx->part_is_attachment(ctx, &apart); } -static void parse_content_type(struct mail_save_context *ctx, - const struct message_header_line *hdr) +static int index_attachment_open_temp_fd(void *context) { - struct rfc822_parser_context parser; - string_t *content_type; - - rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL); - rfc822_skip_lwsp(&parser); - - T_BEGIN { - content_type = t_str_new(64); - if (rfc822_parse_content_type(&parser, content_type) >= 0) { - i_free(ctx->attach->part.content_type); - ctx->attach->part.content_type = - i_strdup(str_c(content_type)); - } - } T_END; -} - -static void -parse_content_disposition(struct mail_save_context *ctx, - const struct message_header_line *hdr) -{ - /* just pass it as-is to backend. */ - i_free(ctx->attach->part.content_disposition); - ctx->attach->part.content_disposition = - i_strndup(hdr->full_value, hdr->full_value_len); -} - -static void index_attachment_save_mail_header(struct mail_save_context *ctx, - struct message_header_line *hdr) -{ - if (hdr->continues) { - hdr->use_full_value = TRUE; - return; - } - - if (strcasecmp(hdr->name, "Content-Type") == 0) - parse_content_type(ctx, hdr); - else if (strcasecmp(hdr->name, "Content-Disposition") == 0) - parse_content_disposition(ctx, hdr); - - o_stream_nsend(ctx->output, hdr->name, hdr->name_len); - o_stream_nsend(ctx->output, hdr->middle, hdr->middle_len); - o_stream_nsend(ctx->output, hdr->full_value, hdr->full_value_len); - if (!hdr->no_newline) { - if (hdr->crlf_newline) - o_stream_nsend(ctx->output, "\r\n", 2); - else - o_stream_nsend(ctx->output, "\n", 1); - } -} - -static bool save_is_attachment(struct mail_save_context *ctx, - struct message_part *part) -{ - struct mail_attachment_part apart; - - if ((part->flags & MESSAGE_PART_FLAG_MULTIPART) != 0) { - /* multiparts may contain attachments as children, - but they're never themselves */ - return FALSE; - } - if (ctx->part_is_attachment == NULL) - return TRUE; - - memset(&apart, 0, sizeof(apart)); - apart.part = part; - apart.content_type = ctx->attach->part.content_type; - apart.content_disposition = ctx->attach->part.content_disposition; - return ctx->part_is_attachment(ctx, &apart); -} - -static int index_attachment_save_temp_open_fd(struct mail_storage *storage) -{ + struct mail_save_context *ctx = context; + struct mail_storage *storage = ctx->transaction->box->storage; string_t *temp_path; int fd; @@ -186,203 +69,22 @@ return fd; } From dovecot at dovecot.org Fri Jun 29 08:05:13 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 08:05:13 +0300 Subject: dovecot-2.1: lib-storage: External mail attachment parsing didn'... Message-ID: details: http://hg.dovecot.org/dovecot-2.1/rev/6b08977c4b75 changeset: 14584:6b08977c4b75 user: Timo Sirainen date: Fri Jun 29 08:05:08 2012 +0300 description: lib-storage: External mail attachment parsing didn't handle CRLF linefeeds correctly. This simply meant that if mail_save_crlf=yes was used, base64-encoded attachments weren't saved base64-decoded. diffstat: src/lib-storage/index/index-attachment.c | 44 +++++++++++++++++-------------- 1 files changed, 24 insertions(+), 20 deletions(-) diffs (68 lines): diff -r 3efbc4a8219b -r 6b08977c4b75 src/lib-storage/index/index-attachment.c --- a/src/lib-storage/index/index-attachment.c Fri Jun 29 06:14:51 2012 +0300 +++ b/src/lib-storage/index/index-attachment.c Fri Jun 29 08:05:08 2012 +0300 @@ -448,6 +448,28 @@ } static int +index_attachment_base64_decode_lf(struct mail_save_attachment_part *part) +{ + part->base64_state = BASE64_STATE_0; + if (part->cur_base64_blocks < part->base64_line_blocks) { + /* last line */ + part->base64_state = BASE64_STATE_EOM; + return 0; + } else if (part->base64_line_blocks == 0) { + /* first line */ + if (part->cur_base64_blocks == 0) + return -1; + part->base64_line_blocks = part->cur_base64_blocks; + } else if (part->cur_base64_blocks == part->base64_line_blocks) { + /* line is ok */ + } else { + return -1; + } + part->cur_base64_blocks = 0; + return 1; +} + +static int index_attachment_try_base64_decode_char(struct mail_save_attachment_part *part, size_t pos, char chr) { @@ -458,25 +480,7 @@ else if (chr == '\r') part->base64_state = BASE64_STATE_CR; else if (chr == '\n') { - part->base64_state = BASE64_STATE_0; - if (part->cur_base64_blocks < - part->base64_line_blocks) { - /* last line */ - part->base64_state = BASE64_STATE_EOM; - return 0; - } else if (part->base64_line_blocks == 0) { - /* first line */ - if (part->cur_base64_blocks == 0) - return -1; - part->base64_line_blocks = - part->cur_base64_blocks; - } else if (part->cur_base64_blocks == - part->base64_line_blocks) { - /* line is ok */ - } else { - return -1; - } - part->cur_base64_blocks = 0; + return index_attachment_base64_decode_lf(part); } else { return -1; } @@ -511,7 +515,7 @@ if (chr != '\n') return -1; part->base64_have_crlf = TRUE; - break; + return index_attachment_base64_decode_lf(part); case BASE64_STATE_EOB: if (chr != '=') return -1; From dovecot at dovecot.org Fri Jun 29 09:02:37 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 09:02:37 +0300 Subject: dovecot-2.2: istreams: Added default seek() implementation for s... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/11e774a9d22c changeset: 14700:11e774a9d22c user: Timo Sirainen date: Fri Jun 29 09:01:56 2012 +0300 description: istreams: Added default seek() implementation for seekable streams. diffstat: src/lib-storage/index/istream-mail.c | 9 --------- src/lib/istream-base64-encoder.c | 2 +- src/lib/istream-limit.c | 8 -------- src/lib/istream-private.h | 4 ++-- src/lib/istream-seekable.c | 8 -------- src/lib/istream-sized.c | 13 ------------- src/lib/istream.c | 17 +++++++++++++---- 7 files changed, 16 insertions(+), 45 deletions(-) diffs (165 lines): diff -r 38b0986605a6 -r 11e774a9d22c src/lib-storage/index/istream-mail.c --- a/src/lib-storage/index/istream-mail.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib-storage/index/istream-mail.c Fri Jun 29 09:01:56 2012 +0300 @@ -93,14 +93,6 @@ return ret; } -static void -i_stream_mail_seek(struct istream_private *stream, - uoff_t v_offset, bool mark ATTR_UNUSED) -{ - stream->istream.v_offset = v_offset; - stream->skip = stream->pos = 0; -} - static const struct stat * i_stream_mail_stat(struct istream_private *stream, bool exact) { @@ -121,7 +113,6 @@ mstream->istream.parent = input; mstream->istream.read = i_stream_mail_read; - mstream->istream.seek = i_stream_mail_seek; mstream->istream.stat = i_stream_mail_stat; mstream->istream.istream.blocking = input->blocking; diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-base64-encoder.c --- a/src/lib/istream-base64-encoder.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream-base64-encoder.c Fri Jun 29 09:01:56 2012 +0300 @@ -147,7 +147,7 @@ bstream->cur_line_len = 0; i_stream_seek(stream->parent, 0); } - i_stream_default_seek(stream, v_offset, mark); + i_stream_default_seek_nonseekable(stream, v_offset, mark); } struct istream * diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-limit.c --- a/src/lib/istream-limit.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream-limit.c Fri Jun 29 09:01:56 2012 +0300 @@ -71,13 +71,6 @@ return ret; } -static void i_stream_limit_seek(struct istream_private *stream, uoff_t v_offset, - bool mark ATTR_UNUSED) -{ - stream->istream.v_offset = v_offset; - stream->skip = stream->pos = 0; -} - static const struct stat * i_stream_limit_stat(struct istream_private *stream, bool exact) { @@ -126,7 +119,6 @@ lstream->istream.iostream.destroy = i_stream_limit_destroy; lstream->istream.parent = input; lstream->istream.read = i_stream_limit_read; - lstream->istream.seek = i_stream_limit_seek; lstream->istream.stat = i_stream_limit_stat; lstream->istream.get_size = i_stream_limit_get_size; diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-private.h --- a/src/lib/istream-private.h Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream-private.h Fri Jun 29 09:01:56 2012 +0300 @@ -58,7 +58,7 @@ size_t wanted_size, size_t *size_r); void *i_stream_alloc(struct istream_private *stream, size_t size); ssize_t i_stream_read_copy_from_parent(struct istream *istream); -void i_stream_default_seek(struct istream_private *stream, - uoff_t v_offset, bool mark); +void i_stream_default_seek_nonseekable(struct istream_private *stream, + uoff_t v_offset, bool mark); #endif diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-seekable.c --- a/src/lib/istream-seekable.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream-seekable.c Fri Jun 29 09:01:56 2012 +0300 @@ -286,13 +286,6 @@ return ret; } -static void i_stream_seekable_seek(struct istream_private *stream, - uoff_t v_offset, bool mark ATTR_UNUSED) -{ - stream->istream.v_offset = v_offset; - stream->skip = stream->pos = 0; -} - static const struct stat * i_stream_seekable_stat(struct istream_private *stream, bool exact) { @@ -388,7 +381,6 @@ i_stream_seekable_set_max_buffer_size; sstream->istream.read = i_stream_seekable_read; - sstream->istream.seek = i_stream_seekable_seek; sstream->istream.stat = i_stream_seekable_stat; sstream->istream.istream.readable_fd = FALSE; diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream-sized.c --- a/src/lib/istream-sized.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream-sized.c Fri Jun 29 09:01:56 2012 +0300 @@ -70,18 +70,6 @@ return ret; } -static void -i_stream_sized_seek(struct istream_private *stream, - uoff_t v_offset, bool mark ATTR_UNUSED) -{ - struct sized_istream *sstream = (struct sized_istream *)stream; - - i_assert(v_offset <= sstream->size); - - stream->istream.v_offset = v_offset; - stream->skip = stream->pos = 0; -} - static const struct stat * i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED) { @@ -110,7 +98,6 @@ sstream->istream.parent = input; sstream->istream.read = i_stream_sized_read; - sstream->istream.seek = i_stream_sized_seek; sstream->istream.stat = i_stream_sized_stat; sstream->istream.istream.readable_fd = input->readable_fd; diff -r 38b0986605a6 -r 11e774a9d22c src/lib/istream.c --- a/src/lib/istream.c Fri Jun 29 08:01:08 2012 +0300 +++ b/src/lib/istream.c Fri Jun 29 09:01:56 2012 +0300 @@ -567,8 +567,16 @@ i_stream_unref(&_stream->parent); } -void i_stream_default_seek(struct istream_private *stream, - uoff_t v_offset, bool mark ATTR_UNUSED) +static void +i_stream_default_seek_seekable(struct istream_private *stream, + uoff_t v_offset, bool mark ATTR_UNUSED) +{ + stream->istream.v_offset = v_offset; + stream->skip = stream->pos = 0; +} + +void i_stream_default_seek_nonseekable(struct istream_private *stream, + uoff_t v_offset, bool mark ATTR_UNUSED) { size_t available; @@ -632,8 +640,9 @@ if (_stream->iostream.destroy == NULL) _stream->iostream.destroy = i_stream_default_destroy; if (_stream->seek == NULL) { - i_assert(!_stream->istream.seekable); - _stream->seek = i_stream_default_seek; + _stream->seek = _stream->istream.seekable ? + i_stream_default_seek_seekable : + i_stream_default_seek_nonseekable; } if (_stream->stat == NULL) _stream->stat = i_stream_default_stat; From dovecot at dovecot.org Fri Jun 29 09:15:33 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Fri, 29 Jun 2012 09:15:33 +0300 Subject: dovecot-2.2: istreams: Added default stat() implementation for f... Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/89e0aad6ba88 changeset: 14701:89e0aad6ba88 user: Timo Sirainen date: Fri Jun 29 09:15:26 2012 +0300 description: istreams: Added default stat() implementation for filter streams. diffstat: src/lib-mail/istream-attachment-extractor.c | 7 ------- src/lib-mail/istream-binary-converter.c | 7 ------- src/lib-mail/istream-dot.c | 8 -------- src/lib-mail/istream-nonuls.c | 8 +------- src/lib-storage/index/istream-mail.c | 9 +-------- src/lib/istream-base64-encoder.c | 13 ------------- src/lib/istream-crlf.c | 8 -------- src/lib/istream-limit.c | 1 - src/lib/istream-private.h | 1 + src/lib/istream-rawlog.c | 9 ++------- src/lib/istream-sized.c | 3 +-- src/lib/istream.c | 11 +++++++++-- 12 files changed, 15 insertions(+), 70 deletions(-) diffs (281 lines): diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-attachment-extractor.c --- a/src/lib-mail/istream-attachment-extractor.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib-mail/istream-attachment-extractor.c Fri Jun 29 09:15:26 2012 +0300 @@ -619,12 +619,6 @@ return ret; } -static const struct stat * -i_stream_attachment_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - static void i_stream_attachment_close(struct iostream_private *stream) { struct attachment_istream *astream = @@ -665,7 +659,6 @@ astream->istream.max_buffer_size = input->real_stream->max_buffer_size; astream->istream.read = i_stream_attachment_read; - astream->istream.stat = i_stream_attachment_stat; astream->istream.iostream.close = i_stream_attachment_close; astream->istream.istream.readable_fd = FALSE; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-binary-converter.c --- a/src/lib-mail/istream-binary-converter.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib-mail/istream-binary-converter.c Fri Jun 29 09:15:26 2012 +0300 @@ -260,12 +260,6 @@ return new_size - old_size; } -static const struct stat * -i_stream_binary_converter_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - static void i_stream_binary_converter_close(struct iostream_private *stream) { struct binary_converter_istream *bstream = @@ -286,7 +280,6 @@ bstream->istream.max_buffer_size = input->real_stream->max_buffer_size; bstream->istream.read = i_stream_binary_converter_read; - bstream->istream.stat = i_stream_binary_converter_stat; bstream->istream.iostream.close = i_stream_binary_converter_close; bstream->istream.istream.readable_fd = FALSE; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-dot.c --- a/src/lib-mail/istream-dot.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib-mail/istream-dot.c Fri Jun 29 09:15:26 2012 +0300 @@ -211,21 +211,13 @@ return ret; } -static const struct stat * -i_stream_dot_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - struct istream *i_stream_create_dot(struct istream *input, bool send_last_lf) { struct dot_istream *dstream; dstream = i_new(struct dot_istream, 1); dstream->istream.max_buffer_size = input->real_stream->max_buffer_size; - dstream->istream.read = i_stream_dot_read; - dstream->istream.stat = i_stream_dot_stat; dstream->istream.istream.readable_fd = FALSE; dstream->istream.istream.blocking = input->blocking; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-mail/istream-nonuls.c --- a/src/lib-mail/istream-nonuls.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib-mail/istream-nonuls.c Fri Jun 29 09:15:26 2012 +0300 @@ -60,21 +60,15 @@ return size; } -static const struct stat * -i_stream_nonuls_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - struct istream *i_stream_create_nonuls(struct istream *input, char replace_chr) { struct nonuls_istream *nstream; nstream = i_new(struct nonuls_istream, 1); nstream->istream.max_buffer_size = input->real_stream->max_buffer_size; + nstream->istream.stream_size_passthrough = TRUE; nstream->istream.read = i_stream_nonuls_read; - nstream->istream.stat = i_stream_nonuls_stat; nstream->istream.istream.readable_fd = FALSE; nstream->istream.istream.blocking = input->blocking; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib-storage/index/istream-mail.c --- a/src/lib-storage/index/istream-mail.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib-storage/index/istream-mail.c Fri Jun 29 09:15:26 2012 +0300 @@ -93,12 +93,6 @@ return ret; } -static const struct stat * -i_stream_mail_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - struct istream *i_stream_create_mail(struct mail *mail, struct istream *input, bool input_has_body) { @@ -110,10 +104,9 @@ mstream->expected_size = (uoff_t)-1; (void)i_stream_mail_try_get_cached_size(mstream); mstream->istream.max_buffer_size = input->real_stream->max_buffer_size; + mstream->istream.stream_size_passthrough = TRUE; - mstream->istream.parent = input; mstream->istream.read = i_stream_mail_read; - mstream->istream.stat = i_stream_mail_stat; mstream->istream.istream.blocking = input->blocking; mstream->istream.istream.seekable = input->seekable; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-base64-encoder.c --- a/src/lib/istream-base64-encoder.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-base64-encoder.c Fri Jun 29 09:15:26 2012 +0300 @@ -120,17 +120,6 @@ return post_count - pre_count; } -static const struct stat * -i_stream_base64_encoder_stat(struct istream_private *stream, bool exact) -{ - if (exact) { - /* too much trouble to implement until it's actually needed */ - i_panic("istream-base64-encoder: " - "stat() doesn't support getting exact size"); - } - return i_stream_stat(stream->parent, exact); -} - static void i_stream_base64_encoder_seek(struct istream_private *stream, uoff_t v_offset, bool mark) @@ -163,9 +152,7 @@ bstream->crlf = crlf; bstream->istream.max_buffer_size = input->real_stream->max_buffer_size; - bstream->istream.parent = input; bstream->istream.read = i_stream_base64_encoder_read; - bstream->istream.stat = i_stream_base64_encoder_stat; bstream->istream.seek = i_stream_base64_encoder_seek; bstream->istream.istream.readable_fd = FALSE; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-crlf.c --- a/src/lib/istream-crlf.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-crlf.c Fri Jun 29 09:15:26 2012 +0300 @@ -172,12 +172,6 @@ return ret; } -static const struct stat * -i_stream_crlf_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - static struct istream * i_stream_create_crlf_full(struct istream *input, bool crlf) { @@ -185,10 +179,8 @@ cstream = i_new(struct crlf_istream, 1); cstream->istream.max_buffer_size = input->real_stream->max_buffer_size; - cstream->istream.read = crlf ? i_stream_crlf_read_crlf : i_stream_crlf_read_lf; - cstream->istream.stat = i_stream_crlf_stat; cstream->istream.istream.readable_fd = FALSE; cstream->istream.istream.blocking = input->blocking; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-limit.c --- a/src/lib/istream-limit.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-limit.c Fri Jun 29 09:15:26 2012 +0300 @@ -117,7 +117,6 @@ lstream->istream.max_buffer_size = input->real_stream->max_buffer_size; lstream->istream.iostream.destroy = i_stream_limit_destroy; - lstream->istream.parent = input; lstream->istream.read = i_stream_limit_read; lstream->istream.stat = i_stream_limit_stat; lstream->istream.get_size = i_stream_limit_get_size; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-private.h --- a/src/lib/istream-private.h Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-private.h Fri Jun 29 09:15:26 2012 +0300 @@ -45,6 +45,7 @@ string_t *line_str; /* for i_stream_next_line() if w_buffer == NULL */ unsigned int return_nolf_line:1; + unsigned int stream_size_passthrough:1; /* stream is parent's size */ }; struct istream * ATTR_NOWARN_UNUSED_RESULT diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-rawlog.c --- a/src/lib/istream-rawlog.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-rawlog.c Fri Jun 29 09:15:26 2012 +0300 @@ -69,12 +69,6 @@ return ret; } -static const struct stat * -i_stream_rawlog_stat(struct istream_private *stream, bool exact) -{ - return i_stream_stat(stream->parent, exact); -} - struct istream * i_stream_create_rawlog(struct istream *input, const char *rawlog_path, int rawlog_fd, bool autoclose_fd) @@ -86,13 +80,14 @@ rstream = i_new(struct rawlog_istream, 1); rstream->istream.max_buffer_size = input->real_stream->max_buffer_size; + rstream->istream.stream_size_passthrough = TRUE; + rstream->riostream.rawlog_path = i_strdup(rawlog_path); rstream->riostream.rawlog_fd = rawlog_fd; rstream->riostream.autoclose_fd = autoclose_fd; rstream->riostream.write_timestamp = TRUE; rstream->istream.read = i_stream_rawlog_read; - rstream->istream.stat = i_stream_rawlog_stat; rstream->istream.iostream.close = i_stream_rawlog_close; rstream->istream.iostream.destroy = i_stream_rawlog_destroy; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream-sized.c --- a/src/lib/istream-sized.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream-sized.c Fri Jun 29 09:15:26 2012 +0300 @@ -71,7 +71,7 @@ } static const struct stat * -i_stream_sized_stat(struct istream_private *stream, bool sized ATTR_UNUSED) +i_stream_sized_stat(struct istream_private *stream, bool exact ATTR_UNUSED) { struct sized_istream *sstream = (struct sized_istream *)stream; const struct stat *st; @@ -96,7 +96,6 @@ sstream->size = size; sstream->istream.max_buffer_size = input->real_stream->max_buffer_size; - sstream->istream.parent = input; sstream->istream.read = i_stream_sized_read; sstream->istream.stat = i_stream_sized_stat; diff -r 11e774a9d22c -r 89e0aad6ba88 src/lib/istream.c --- a/src/lib/istream.c Fri Jun 29 09:01:56 2012 +0300 +++ b/src/lib/istream.c Fri Jun 29 09:15:26 2012 +0300 @@ -601,9 +601,16 @@ } static const struct stat * -i_stream_default_stat(struct istream_private *stream, bool exact ATTR_UNUSED) +i_stream_default_stat(struct istream_private *stream, bool exact) { - return &stream->statbuf; + if (stream->parent == NULL) + return &stream->statbuf; + + if (exact && !stream->stream_size_passthrough) { + i_panic("istream %s: stat() doesn't support getting exact size", + i_stream_get_name(&stream->istream)); + } + return i_stream_stat(stream->parent, exact); } static int From dovecot at dovecot.org Sat Jun 30 22:27:57 2012 From: dovecot at dovecot.org (dovecot at dovecot.org) Date: Sat, 30 Jun 2012 22:27:57 +0300 Subject: dovecot-2.2: o_stream_nsend() comment update Message-ID: details: http://hg.dovecot.org/dovecot-2.2/rev/3d3689c2c81d changeset: 14702:3d3689c2c81d user: Timo Sirainen date: Sat Jun 30 22:27:34 2012 +0300 description: o_stream_nsend() comment update diffstat: src/lib/ostream.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff -r 89e0aad6ba88 -r 3d3689c2c81d src/lib/ostream.h --- a/src/lib/ostream.h Fri Jun 29 09:15:26 2012 +0300 +++ b/src/lib/ostream.h Sat Jun 30 22:27:34 2012 +0300 @@ -89,8 +89,8 @@ unsigned int iov_count); ssize_t o_stream_send_str(struct ostream *stream, const char *str); /* Send with delayed error handling. o_stream_has_errors() or - o_stream_ignore_errors() must be called after these functions before the - stream is destroyed. */ + o_stream_ignore_last_errors() must be called after these functions before + the stream is destroyed. */ void o_stream_nsend(struct ostream *stream, const void *data, size_t size); void o_stream_nsendv(struct ostream *stream, const struct const_iovec *iov, unsigned int iov_count);