[wiki] [sites] ii: add patch for libtls support || Jan Klemkow

From: <git_AT_suckless.org>
Date: Sun, 16 Oct 2022 22:16:39 +0200

commit f38d666a09182e73b3a20395c6a9e874b61efb1d
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
Date: Sun Oct 16 22:16:21 2022 +0200

    ii: add patch for libtls support

diff --git a/tools.suckless.org/ii/patches/tls/ii-2.0-tls.diff b/tools.suckless.org/ii/patches/tls/ii-2.0-tls.diff
new file mode 100644
index 00000000..24fd0974
--- /dev/null
+++ b/tools.suckless.org/ii/patches/tls/ii-2.0-tls.diff
_AT_@ -0,0 +1,143 @@
+commit fbe27f507fa28ffabe1c777285cfafde2b5b6f5a
+Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
+Date: Sun Oct 16 22:10:00 2022 +0200
+
+ Use libtls to encrypt connections.
+
+diff --git a/Makefile b/Makefile
+index 28c7781..8c19387 100644
+--- a/Makefile
++++ b/Makefile
+_AT_@ -12,7 +12,7 @@ OBJ = $(SRC:.c=.o)
+
+ # use system flags.
+ II_CFLAGS = $(CFLAGS)
+-II_LDFLAGS = $(LDFLAGS)
++II_LDFLAGS = $(LDFLAGS) -ltls
+
+ # on systems which provide strlcpy(3),
+ # remove NEED_STRLCPY from CPPFLAGS and
+diff --git a/ii.1 b/ii.1
+index 59fd798..9f5d93c 100644
+--- a/ii.1
++++ b/ii.1
+_AT_@ -3,6 +3,7 @@
+ ii - irc it or irc improved
+ .SH SYNOPSIS
+ .B ii
++.RB [ -t ]
+ .B -s
+ .I host
+ .RB [ -p
+_AT_@ -34,6 +35,9 @@ For example if you will join a channel just do echo "/j #channel" > in
+ and ii creates a new channel directory with in and out file.
+ .SH OPTIONS
+ .TP
++.BI -t
++TLS encrypted connection
++.TP
+ .BI -s " host"
+ server/host to connect to, for example: irc.freenode.net
+ .TP
+diff --git a/ii.c b/ii.c
+index c402a87..86ad918 100644
+--- a/ii.c
++++ b/ii.c
+_AT_@ -20,6 +20,9 @@
+ #include <time.h>
+ #include <unistd.h>
+
++#include <tls.h>
++struct tls *tls = NULL;
++int ircfd;
+ char *argv0;
+
+ #include "arg.h"
+_AT_@ -101,7 +104,7 @@ die(const char *fmt, ...)
+ static void
+ usage(void)
+ {
+- die("usage: %s -s host [-p port | -u sockname] [-i ircdir]
"
++ die("usage: %s [-t] -s host [-p port | -u sockname] [-i ircdir]
"
+ " [-n nickname] [-f fullname] [-k env_pass]
", argv0);
+ }
+
+_AT_@ -113,11 +116,17 @@ ewritestr(int fd, const char *s)
+
+ len = strlen(s);
+ for (off = 0; off < len; off += w) {
+- if ((w = write(fd, s + off, len - off)) == -1)
++ if (tls && (w = tls_write(tls, s + off, len - off)) == -1)
+ break;
++ if (!tls && (w = write(fd, s + off, len - off)) == -1)
++ break;
++ }
++ if (w == -1) {
++ if (tls)
++ die("%s: tls_write: %s
", argv0, tls_error(tls));
++ else
++ die("%s: write: %s
", argv0, strerror(errno));
+ }
+- if (w == -1)
+- die("%s: write: %s
", argv0, strerror(errno));
+ }
+
+ /* creates directories bottom-up, if necessary */
+_AT_@ -686,8 +695,15 @@ read_line(int fd, char *buf, size_t bufsiz)
+ char c = '+
+ do {
+- if (read(fd, &c, sizeof(char)) != sizeof(char))
+- return -1;
++ if (tls && fd == ircfd) {
++ if (tls_read(tls, &c, sizeof(c)) == -1) {
++ die("");
++ return -1;
++ }
++ } else {
++ if (read(fd, &c, sizeof(char)) != sizeof(char))
++ return -1;
++ }
+ buf[i++] = c;
+ } while (c != '
' && i < bufsiz);
+ buf[i - 1] = '' */
+_AT_@ -799,7 +815,8 @@ main(int argc, char *argv[])
+ const char *key = NULL, *fullname = NULL, *host = "";
+ const char *uds = NULL, *service = "6667";
+ char prefix[PATH_MAX];
+- int ircfd, r;
++ int r;
++ struct tls_config *tls_config = NULL;
+
+ /* use nickname and home dir of user by default */
+ if (!(spw = getpwuid(getuid())))
+_AT_@ -827,6 +844,17 @@ main(int argc, char *argv[])
+ case 's':
+ host = EARGF(usage());
+ break;
++ case 't':
++ if (tls != NULL)
++ break;
++
++ if ((tls = tls_client()) == NULL)
++ die("%s: tls_client
", argv0);
++ if ((tls_config = tls_config_new()) == NULL)
++ die("%s: tls_config_new
", argv0);
++ if (tls_configure(tls, tls_config) == -1)
++ die("%s: tls_configure
", argv0);
++ break;
+ case 'u':
+ uds = EARGF(usage());
+ break;
+_AT_@ -843,6 +871,11 @@ main(int argc, char *argv[])
+ else
+ ircfd = tcpopen(host, service);
+
++ if (tls && tls_connect_socket(tls, ircfd, host) == -1)
++ die("%s: tls_connect_socket: %s
", argv0, tls_error(tls));
++ if (tls && tls_handshake(tls) == -1)
++ die("%s: tls_handshake: %s
", argv0, tls_error(tls));
++
+ #ifdef __OpenBSD__
+ /* OpenBSD pledge(2) support */
+ if (pledge("stdio rpath wpath cpath dpath", NULL) == -1)
diff --git a/tools.suckless.org/ii/patches/tls/index.md b/tools.suckless.org/ii/patches/tls/index.md
new file mode 100644
index 00000000..0a3ba18d
--- /dev/null
+++ b/tools.suckless.org/ii/patches/tls/index.md
_AT_@ -0,0 +1,15 @@
+TLS
+===
+
+Description
+-----------
+Adds tls encryption support via the `-t` argument.
+This patch depends on libtls from [https://www.libressl.org/](LibreSSL).
+
+Download
+--------
+* [ii-2.0-tls.diff](ii-2.0-tls.diff)
+
+Author
+------
+* Written for 2.0 by Jan Klemkow
Received on Sun Oct 16 2022 - 22:16:39 CEST

This archive was generated by hypermail 2.3.0 : Sun Oct 16 2022 - 22:24:54 CEST