summaryrefslogtreecommitdiff
path: root/libmailutils
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-08-25 14:05:53 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-08-25 14:36:44 +0300
commitfcf34684375b037c92b5012da3fb219b5ea657f3 (patch)
tree3cd02ee44373b52d79bacb27529a18c53ec55aea /libmailutils
parent35fbbaf08f523e6bbe49af4a1cdbe53626e69e29 (diff)
downloadmailutils-fcf34684375b037c92b5012da3fb219b5ea657f3.tar.gz
mailutils-fcf34684375b037c92b5012da3fb219b5ea657f3.tar.bz2
New function: mu_starttls
* libmu_auth/tlsfdstr.c (mu_tlsfd_stream_create): Accept conf==NULL. (mu_starttls): New function. * include/mailutils/tls.h (mu_starttls): New proto. * include/mailutils/imapio.h (mu_imapio_get_transport) (mu_imapio_set_transport): New functions. * libmailutils/imapio/transport.c (mu_imapio_get_transport) (mu_imapio_set_transport): New functions. * libmailutils/stream/iostream.c (mu_iostream_create): Accept NULL out stream. * libmailutils/stream/tcp.c: Support MU_IOCTL_FD (_tcp_instance): New member fd_borrowed. (_tcp_close): Don't close fd if fd_borrowed is set. (_tcp_ioctl): Handle MU_IOCTL_FD. * libmailutils/stream/xscript-stream.c (_xscript_ctl): Accept pstr[1] == NULL. * libmu_auth/notls.c (mu_tlsfd_stream_create) (mu_tlsfd_stream2_convert) (mu_starttls): New placeholders. * libproto/imap/folder.c (_mu_imap_folder_open): Use mu_tlsfd_stream_convert. Fix stream leak. * libproto/imap/starttls.c (mu_imap_starttls): Use mu_starttls. * libproto/mailer/smtp.c (smtp_open): Use mu_tlsfd_stream_convert. * libproto/mailer/smtp_starttls.c (mu_smtp_starttls): Use mu_starttls. * libproto/pop/pop3_stls.c (mu_pop3_stls): Likewise. * libproto/pop/mailbox.c (pop_open): Use mu_tlsfd_stream_convert. Fix stream leak. * mu/libexec/imap.c (com_connect): Use mu_tlsfd_stream_convert. Fix stream leak. * mu/libexec/pop.c: Likewise. * mu/libexec/smtp.c: Likewise. * imap4d/io.c (imap4d_init_tls_server): Use mu_starttls. * pop3d/extra.c: Likewise.
Diffstat (limited to 'libmailutils')
-rw-r--r--libmailutils/imapio/transport.c21
-rw-r--r--libmailutils/stream/iostream.c2
-rw-r--r--libmailutils/stream/tcp.c30
-rw-r--r--libmailutils/stream/xscript-stream.c16
4 files changed, 60 insertions, 9 deletions
diff --git a/libmailutils/imapio/transport.c b/libmailutils/imapio/transport.c
index 2df72f3bb..c6df4bc32 100644
--- a/libmailutils/imapio/transport.c
+++ b/libmailutils/imapio/transport.c
@@ -23,6 +23,27 @@
#include <mailutils/sys/imapio.h>
int
+mu_imapio_get_transport (struct _mu_imapio *io, mu_stream_t *pstream)
+{
+ if (!io)
+ return EINVAL;
+ if (io->_imap_stream)
+ mu_stream_ref (io->_imap_stream);
+ *pstream = io->_imap_stream;
+ return 0;
+}
+
+int
+mu_imapio_set_transport (mu_imapio_t io, mu_stream_t stream)
+{
+ if (!io)
+ return EINVAL;
+ io->_imap_stream = stream;
+ mu_stream_ref (stream);
+ return 0;
+}
+
+int
mu_imapio_get_streams (struct _mu_imapio *io, mu_stream_t *streams)
{
int rc;
diff --git a/libmailutils/stream/iostream.c b/libmailutils/stream/iostream.c
index 7b9eb50ed..9a3b7ca7d 100644
--- a/libmailutils/stream/iostream.c
+++ b/libmailutils/stream/iostream.c
@@ -405,6 +405,8 @@ mu_iostream_create (mu_stream_t *pref, mu_stream_t in, mu_stream_t out)
mu_stream_ref (in);
sp->transport[_MU_STREAM_INPUT] = in;
+ if (!out)
+ out = in;
mu_stream_ref (out);
sp->transport[_MU_STREAM_OUTPUT] = out;
diff --git a/libmailutils/stream/tcp.c b/libmailutils/stream/tcp.c
index 526a35bd1..621f39f87 100644
--- a/libmailutils/stream/tcp.c
+++ b/libmailutils/stream/tcp.c
@@ -50,8 +50,9 @@
struct _tcp_instance
{
struct _mu_stream stream;
- int fd;
- int state;
+ int fd;
+ int state;
+ int fd_borrowed;
struct mu_sockaddr *remote_addr;
struct mu_sockaddr *source_addr;
};
@@ -62,7 +63,7 @@ _tcp_close (mu_stream_t stream)
struct _tcp_instance *tcp = (struct _tcp_instance *)stream;
int err = 0;
- if (tcp->fd != -1)
+ if (tcp->fd != -1 && tcp->fd_borrowed)
{
if (close (tcp->fd) != 0)
{
@@ -169,14 +170,35 @@ _tcp_ioctl (mu_stream_t stream, int code, int opcode, void *ptr)
ptrans[0] = (mu_transport_t) (intptr_t) tcp->fd;
ptrans[1] = NULL;
break;
+
case MU_IOCTL_OP_SET:
- return ENOSYS;
+ tcp->fd = (int) (intptr_t) ptrans[0];
+ break;
+
default:
return EINVAL;
}
}
break;
+ case MU_IOCTL_FD:
+ if (!ptr)
+ return EINVAL;
+ switch (opcode)
+ {
+ case MU_IOCTL_FD_GET_BORROW:
+ *(int*) ptr = tcp->fd_borrowed;
+ break;
+
+ case MU_IOCTL_FD_SET_BORROW:
+ tcp->fd_borrowed = *(int*)ptr;
+ break;
+
+ default:
+ return EINVAL;
+ }
+ break;
+
case MU_IOCTL_TCPSTREAM:
switch (opcode)
{
diff --git a/libmailutils/stream/xscript-stream.c b/libmailutils/stream/xscript-stream.c
index e4a98395d..08b1867f5 100644
--- a/libmailutils/stream/xscript-stream.c
+++ b/libmailutils/stream/xscript-stream.c
@@ -442,19 +442,25 @@ _xscript_ctl (struct _mu_stream *str, int code, int opcode, void *arg)
mu_stream_t *pstr = arg;
mu_stream_t tmp;
- if (pstr[0] != pstr[1])
+ if (pstr[1] == NULL)
{
- status = mu_iostream_create (&tmp, pstr[0], pstr[1]);
- if (status)
- return status;
+ tmp = pstr[0];
+ mu_stream_ref (tmp);
+ status = 0;
}
- else
+ else if (pstr[0] == pstr[1])
{
tmp = pstr[0];
mu_stream_ref (tmp);
mu_stream_ref (tmp);
status = 0;
}
+ else
+ {
+ status = mu_iostream_create (&tmp, pstr[0], pstr[1]);
+ if (status)
+ return status;
+ }
mu_stream_unref (sp->transport);
sp->transport = tmp;

Return to:

Send suggestions and report system problems to the System administrator.