ref: c0f88502eeb6f5895783497f8a92467a36d851bf
parent: 63d6d91975e1ca3d634d06e4c1349f381a6f2b8a
author: Ben Purcell <spew@cbza.org>
date: Tue Jan 21 19:56:22 EST 2025
cleanup
--- a/mez.c
+++ b/mez.c
@@ -30,6 +30,42 @@
}
void
+vmsg(int fd, char *fmt, va_list v)
+{
+ static char buf[8192];
+ char *e;
+
+ e = vseprint(buf, buf+sizeof(buf), fmt, v);
+ va_end(v);
+ *e++ = '\r';
+ *e++ = '\n';
+ write(fd, buf, e-buf);
+}
+
+void
+msg(int fd, char *fmt, ...)
+{
+ va_list v;
+
+ va_start(v, fmt);
+ vmsg(fd, fmt, v);
+}
+
+char*
+rtmsg(int fd, char *fmt, ...)
+{
+ static char buf[8192];
+ int bytes;
+ va_list v;
+
+ va_start(v, fmt);
+ vmsg(fd, fmt, v);
+ bytes = read(fd, buf, sizeof(buf));
+ buf[bytes] = '\0';
+ return buf;
+}
+
+void
main(int argc, char **argv)
{
TLSconn conn;
@@ -36,7 +72,8 @@
int fd;
long bytes;
UserPasswd *up;
- char *user, *host, buf[8192], out[8192], b64[512];
+ uchar buf[512];
+ char *user, *host, b64[512];
user = getenv("user");
ARGBEGIN{
@@ -49,7 +86,6 @@
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)
@@ -57,31 +93,23 @@
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);
+ msg(fd, "CAP LS 302");
+ msg(fd, "NICK %s", user);
+ print(rtmsg(fd, "USER %s 0 * %s", user, user));
+ //:domain.dom CAP * LS :draft/chathistory batch soju.im/account-required draft/read-marker setname draft/pre-away message-tags away-notify soju.im/bouncer-networks-notify soju.im/search account-notify cap-notify server-time invite-notify draft/extended-monitor extended-join multi-prefix soju.im/read extended-monitor chghost account-tag soju.im/bouncer-networks echo-message soju.im/webpush sasl=PLAIN soju.im/no-implicit-names draft/no-implicit-names
- fprint(fd, "AUTHENTICATE PLAIN\r\n");
- bytes = read(fd, buf, sizeof(buf));
- buf[bytes] = '\0';
- print(buf);
+ print(rtmsg(fd, "CAP REQ :sasl"));
+ //:domain.dom CAP * ACK sasl
- bytes = snprint(out, sizeof(out), "%c%s%c%s", '\0', user, '\0', up->passwd);
+ print(rtmsg(fd, "AUTHENTICATE PLAIN\r\n"));
+ //AUTHENTICATE +
+
+ bytes = snprint((char*)buf, sizeof(buf), "%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);
+ enc64(b64, sizeof(b64), buf, bytes);
+ print(rtmsg(fd, "AUTHENTICATE %s\r\n", b64));
+ //:domain.dom 903 * :SASL authentication successful
exits(0);
}