dovecot-2.0: i_stream_create_fd(): If opening a directory, set s...
dovecot at dovecot.org
dovecot at dovecot.org
Thu Aug 12 18:30:04 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/faac0d16d141
changeset: 11986:faac0d16d141
user: Timo Sirainen <tss at iki.fi>
date: Thu Aug 12 16:29:15 2010 +0100
description:
i_stream_create_fd(): If opening a directory, set stream_errno=EISDIR
diffstat:
src/lib/istream-file.c | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diffs (34 lines):
diff -r 25f401276f9b -r faac0d16d141 src/lib/istream-file.c
--- a/src/lib/istream-file.c Thu Aug 12 16:15:13 2010 +0100
+++ b/src/lib/istream-file.c Thu Aug 12 16:29:15 2010 +0100
@@ -172,6 +172,7 @@
{
struct file_istream *fstream;
struct stat st;
+ bool is_file;
fstream = i_new(struct file_istream, 1);
fstream->autoclose_fd = autoclose_fd;
@@ -184,7 +185,21 @@
fstream->istream.stat = i_stream_file_stat;
/* if it's a file, set the flags properly */
- if (fd == -1 || (fstat(fd, &st) == 0 && S_ISREG(st.st_mode))) {
+ if (fd == -1)
+ is_file = TRUE;
+ else if (fstat(fd, &st) < 0)
+ is_file = FALSE;
+ else if (S_ISREG(st.st_mode))
+ is_file = TRUE;
+ else if (!S_ISDIR(st.st_mode))
+ is_file = FALSE;
+ else {
+ /* we're trying to open a directory.
+ we're not designed for it. */
+ fstream->istream.istream.stream_errno = EISDIR;
+ is_file = FALSE;
+ }
+ if (is_file) {
fstream->file = TRUE;
fstream->istream.istream.blocking = TRUE;
fstream->istream.istream.seekable = TRUE;
More information about the dovecot-cvs
mailing list