ref: 63d6d91975e1ca3d634d06e4c1349f381a6f2b8a
author: Ben Purcell <spew@cbza.org>
date: Mon Jan 20 22:00:20 EST 2025
Use factotum
--- /dev/null
+++ b/mez.c
@@ -1,0 +1,87 @@
+#include <u.h>
+#include <libc.h>
+#include <auth.h>
+#include <mp.h>
+#include <libsec.h>
+
+void
+usage(void)
+{
+ fprint(2, "usage: %s [-u user] host\n", argv0);
+ exits("usage");
+}
+
+void
+error(char *s)
+{
+ fprint(2, "%s: fatal error: %s: %r\n", argv0, s);
+ exits(s);
+}
+
+void*
+emallocz(ulong sz, int clr)
+{
+ void *p;
+
+ if((p = mallocz(sz, clr)) == nil)
+ error("Out of memory");
+ setmalloctag(p, getcallerpc(&sz));
+ return p;
+}
+
+void
+main(int argc, char **argv)
+{
+ TLSconn conn;
+ int fd;
+ long bytes;
+ UserPasswd *up;
+ char *user, *host, buf[8192], out[8192], b64[512];
+
+ user = getenv("user");
+ ARGBEGIN{
+ default:
+ usage();
+ case 'u':
+ user = EARGF(usage());
+ break;
+ }ARGEND
+ if (argc != 1)
+ usage();
+ host = argv[0];
+ fprint(2, "user is %s, host is %s\n", user, host);
+ up = auth_getuserpasswd(auth_getkey, "proto=pass server=%s service=irc user=%s", host, user);
+ fd = dial(netmkaddr(host, "tcp", "6697"), nil, nil, nil);
+ if(fd == -1)
+ error("Could not connect");
+ fd = tlsClient(fd, &conn);
+ if(fd == -1)
+ error("Could not negotiate tls connection");
+ fprint(fd, "CAP LS 302\r\n");
+ fprint(fd, "NICK %s\r\n", user);
+ fprint(fd, "USER %s 0 * %s\r\n", user, user);
+ bytes = read(fd, buf, sizeof(buf));
+ buf[bytes] = '\0';
+ print(buf);
+
+ fprint(fd, "CAP REQ :sasl\r\n");
+ bytes = read(fd, buf, sizeof(buf));
+ buf[bytes] = '\0';
+ print(buf);
+
+ fprint(fd, "AUTHENTICATE PLAIN\r\n");
+ bytes = read(fd, buf, sizeof(buf));
+ buf[bytes] = '\0';
+ print(buf);
+
+ bytes = snprint(out, sizeof(out), "%c%s%c%s", '\0', user, '\0', up->passwd);
+ free(up);
+ enc64(b64, sizeof(b64), (uchar*)out, bytes);
+ print("b64 is %s\n", b64);
+ fprint(fd, "AUTHENTICATE %s\r\n", b64);
+ bytes = read(fd, buf, sizeof(buf));
+ buf[bytes] = '\0';
+ print(buf);
+
+ exits(0);
+}
--- /dev/null
+++ b/mkfile
@@ -1,0 +1,10 @@
+</$objtype/mkfile
+
+TARG=mez
+BIN=/$objtype/bin
+OFILES=\
+ mez.$O
+
+HFILES=
+
+</sys/src/cmd/mkone
--
⑨