Commit 9f9d7b0b 9f9d7b0b7cdb586b34ff08bfa7c752d05088a720 by Sergey Poznyakoff

Fix semantics of MU_IOCTL_SUBSTREAM.

This also fixes e75e9123, which broke TLS support in daemons.

* include/mailutils/stream.h (MU_IOCTL_TOPSTREAM): New ioctl.
* imap4d/imap4d.c (set_strerr_flt)
(clr_strerr_flt): Use MU_IOCTL_TOPSTREAM.
* pop3d/pop3d.c: Likewise.
* libmailutils/stream/fltstream.c (filter_ctl): Handle both
MU_IOCTL_SUBSTREAM and MU_IOCTL_TOPSTREAM.
* libmailutils/stream/iostream.c (_iostream_ctl): Likewise.
* libmailutils/stream/logstream.c (_log_ctl): Likewise.
* libmailutils/stream/xscript-stream.c (_xscript_ctl): Likewise.
1 parent bf8b7ff0
......@@ -415,7 +415,7 @@ set_strerr_flt ()
mu_stream_t flt, trans[2];
int rc;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
char sessidstr[10];
......@@ -432,7 +432,7 @@ set_strerr_flt ()
mu_stream_set_buffer (flt, mu_buffer_line, 0);
trans[0] = flt;
trans[1] = NULL;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
MU_IOCTL_OP_SET, trans);
mu_stream_unref (trans[0]);
if (rc)
......@@ -456,16 +456,16 @@ clr_strerr_flt ()
mu_stream_t flt, trans[2];
int rc;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
flt = trans[0];
rc = mu_stream_ioctl (flt, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
mu_stream_unref (trans[0]);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
MU_IOCTL_OP_SET, trans);
if (rc == 0)
mu_stream_unref (flt);
......
......@@ -73,6 +73,10 @@ enum mu_buffer_type
#define MU_IOCTL_FD 9 /* File descriptor manipulation */
#define MU_IOCTL_SYSLOGSTREAM 10 /* Syslog stream (see below) */
#define MU_IOCTL_FILTER 11 /* Filter streams (see below) */
#define MU_IOCTL_TOPSTREAM 12 /* Same as MU_IOCTL_SUBSTREAM, but
always returns the topmost substream,
traversing stream chains if necessary.
*/
/* Opcodes common for various families */
#define MU_IOCTL_OP_GET 0
......
......@@ -398,7 +398,8 @@ static int
filter_ctl (struct _mu_stream *stream, int code, int opcode, void *ptr)
{
struct _mu_filter_stream *fs = (struct _mu_filter_stream *)stream;
int status;
switch (code)
{
case MU_IOCTL_FILTER:
......@@ -423,6 +424,13 @@ filter_ctl (struct _mu_stream *stream, int code, int opcode, void *ptr)
break;
case MU_IOCTL_SUBSTREAM:
if (fs->transport &&
((status = mu_stream_ioctl (fs->transport, code, opcode, ptr)) == 0
|| status != ENOSYS))
return status;
/* fall through */
case MU_IOCTL_TOPSTREAM:
if (!ptr)
return EINVAL;
else
......
......@@ -159,6 +159,7 @@ _iostream_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
break;
case MU_IOCTL_SUBSTREAM:
case MU_IOCTL_TOPSTREAM:
if (!arg)
return EINVAL;
else
......
......@@ -281,6 +281,7 @@ static int
_log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
{
struct _mu_log_stream *sp = (struct _mu_log_stream *)str;
int status;
switch (code)
{
......@@ -310,6 +311,13 @@ _log_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
break;
case MU_IOCTL_SUBSTREAM:
if (sp->transport &&
((status = mu_stream_ioctl (sp->transport, code, opcode, arg)) == 0 ||
status != ENOSYS))
return status;
/* fall through */
case MU_IOCTL_TOPSTREAM:
if (!arg)
return EINVAL;
else
......
......@@ -288,6 +288,13 @@ _xscript_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
break;
case MU_IOCTL_SUBSTREAM:
if (sp->transport &&
((status = mu_stream_ioctl (sp->transport, code, opcode, arg)) == 0 ||
status != ENOSYS))
return status;
/* fall through */
case MU_IOCTL_TOPSTREAM:
if (!arg)
return EINVAL;
switch (opcode)
......
......@@ -372,7 +372,7 @@ set_strerr_flt ()
mu_stream_t flt, trans[2];
int rc;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
char sessidstr[10];
......@@ -389,7 +389,7 @@ set_strerr_flt ()
mu_stream_set_buffer (flt, mu_buffer_line, 0);
trans[0] = flt;
trans[1] = NULL;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
MU_IOCTL_OP_SET, trans);
mu_stream_unref (trans[0]);
if (rc)
......@@ -413,16 +413,16 @@ clr_strerr_flt ()
mu_stream_t flt, trans[2];
int rc;
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
flt = trans[0];
rc = mu_stream_ioctl (flt, MU_IOCTL_SUBSTREAM, MU_IOCTL_OP_GET, trans);
rc = mu_stream_ioctl (flt, MU_IOCTL_TOPSTREAM, MU_IOCTL_OP_GET, trans);
if (rc == 0)
{
mu_stream_unref (trans[0]);
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_SUBSTREAM,
rc = mu_stream_ioctl (mu_strerr, MU_IOCTL_TOPSTREAM,
MU_IOCTL_OP_SET, trans);
if (rc == 0)
mu_stream_unref (flt);
......