]> git.gir.st - ircpipe.git/log
ircpipe.git
2 weeks agohighlight: keep C1 controls intact master
Tobias Girstmair [Thu, 30 May 2024 07:26:46 +0000 (09:26 +0200)]
highlight: keep C1 controls intact

this pretty obviously broke utf8.

2 weeks agoadd license (gplv3)
Tobias Girstmair [Wed, 29 May 2024 20:17:26 +0000 (22:17 +0200)]
add license (gplv3)

2 weeks agotune connect and setup timeouts
Tobias Girstmair [Wed, 29 May 2024 19:39:53 +0000 (21:39 +0200)]
tune connect and setup timeouts

it seems some servers have their 'Checking Ident'/'No Ident response'
timeout also at roughly 15 seconds, so this can cause a race. giving
sockets ten seconds for connect to succeed felt too generous.

2 weeks agoadd examples, split out caveats, and other readme improvements
Tobias Girstmair [Wed, 29 May 2024 19:31:34 +0000 (21:31 +0200)]
add examples, split out caveats, and other readme improvements

2 weeks agoimplement 'display version' command line switch
Tobias Girstmair [Wed, 29 May 2024 18:42:27 +0000 (20:42 +0200)]
implement 'display version' command line switch

intentionally undocumented.

2 weeks agomake highlight strip control characters
Tobias Girstmair [Wed, 29 May 2024 18:33:03 +0000 (20:33 +0200)]
make highlight strip control characters

excluding \r \n, of course. this could easily have been a seperate
output filter (something like `tr -d '[:cntrl:]'` modulo CR/LF).

2 weeks agoProvide the beginnings of some proper documentation
Tobias Girstmair [Wed, 29 May 2024 18:08:50 +0000 (20:08 +0200)]
Provide the beginnings of some proper documentation

this replaces spec.txt, which was just a loose collection of thoughts.

2 weeks agoclean up makefile
Tobias Girstmair [Wed, 29 May 2024 18:07:18 +0000 (20:07 +0200)]
clean up makefile

2 weeks agoRevert "allow building without libtls"
Tobias Girstmair [Wed, 29 May 2024 18:01:49 +0000 (20:01 +0200)]
Revert "allow building without libtls"

this is extremely ugly. by keeping in the revision history, it should be
cherry-pickable when so desired.

This reverts commit 15803f20b91e3dc483fa35c58c2d4267e5f19488.

2 weeks agoallow building without libtls
Tobias Girstmair [Wed, 29 May 2024 18:01:16 +0000 (20:01 +0200)]
allow building without libtls

2 weeks agoimplement setup timeout
Tobias Girstmair [Wed, 29 May 2024 16:23:17 +0000 (18:23 +0200)]
implement setup timeout

our current handling of only a specific set of error numerics makes us
vulnerable to hangs, when an unexpected code was received. we should
really respect a response timeout here (which must be quite large due to
ident!)

note that connect timeout is not handled by this (but by setsockopt);
it's a bit unfortunate that when that triggers, errno is EINPROGRESS
("Operation now in progress"), as that's a bit confusing.

2 weeks agoRevert "send all initialization commands at once"
Tobias Girstmair [Sun, 26 May 2024 11:54:01 +0000 (13:54 +0200)]
Revert "send all initialization commands at once"

nope, causes hangs.

This reverts commit c92baa7c54cfc57df2bbd9ca2df9e79bddb9cc3a.

3 weeks agosend all initialization commands at once
Tobias Girstmair [Sun, 26 May 2024 11:30:44 +0000 (13:30 +0200)]
send all initialization commands at once

there should be no need to wait for RPL_WELCOME before sending a JOIN
message.

3 weeks agomove todos from spec file to todon'ts
Tobias Girstmair [Sun, 26 May 2024 08:49:18 +0000 (10:49 +0200)]
move todos from spec file to todon'ts

3 weeks agoclean up some todos
Tobias Girstmair [Sat, 25 May 2024 21:21:50 +0000 (23:21 +0200)]
clean up some todos

the thing regarding tls_default_ca_cert_file was wrong and is never
needed. EPIPE et al are already "handled" that way. i (foolishly?) don't
expect EINTR or EAGAIN, given that we call poll immediately before.
the sasl todo isn't that important, as we only support plain password
auth with sasl and we don't expect passphrases longer than 300 chars (if
this were violated, the server would just fail our auth attempt with
ERR_SASLTOOLONG/905 (at which point we'd hang, until we implement proper
timeouts during setup. too bad.)).

3 weeks agoparams cannot be empty
Tobias Girstmair [Sat, 25 May 2024 21:00:12 +0000 (23:00 +0200)]
params cannot be empty

... because we always append a final argument, even if it's the empty
string. there actually is a slight bug with empty line or ones with
only a prefix here (command becomes b""), but these are broken anyways.

3 weeks agohighlight: make sure own nick is delimetered properly
Tobias Girstmair [Sat, 25 May 2024 20:48:20 +0000 (22:48 +0200)]
highlight: make sure own nick is delimetered properly

3 weeks agosimplify nick highlighting logic
Tobias Girstmair [Sat, 25 May 2024 20:39:00 +0000 (22:39 +0200)]
simplify nick highlighting logic

it's sufficient to highlight the first occurence per line to draw
attention to it.

3 weeks agoprovide a tool to highlight irc protocol messages
Tobias Girstmair [Sat, 25 May 2024 20:14:57 +0000 (22:14 +0200)]
provide a tool to highlight irc protocol messages

this can be used as a bare-bones irc client like so:
  IRC_PASSWD=... ./ircpipe -n $NICK -p -s $BOUNCER_HOST | ./highlight | ts
('ts' being the timestamping tool from moreutils)

the code for this looks a bit wonky, but that's kind of on purpose:
while we first parse the message, we then not use this for actual output
and instead slice the raw line and splice in control sequences, as to
not accidentally modify the input; copy-pasting from it should yield the
same bytes as it processed (modulo mIRC style color control chars).
using bytes instead of native strings is necessary as to not break on
non-utf8-encoded messages, something that regularly happens in practise.

3 weeks agodeduplicate blocking for irc response during setup
Tobias Girstmair [Sat, 25 May 2024 13:47:37 +0000 (15:47 +0200)]
deduplicate blocking for irc response during setup

3 weeks agofix segfault on D-line
Tobias Girstmair [Sat, 25 May 2024 13:11:10 +0000 (15:11 +0200)]
fix segfault on D-line

when connecting to irc.efnet.nl we get banned after RPL_WELCOME. the
whole (looong) MOTD loads, then we get ERR_YOUREBANNEDCREEP and a fatal
ERROR and the server closes the connection.
this bug manifested, when setting '-j', that poll (ircpipe.c:246)
returns revents == POLLHUP|POLLIN (while we expected only POLLIN). when
read(2)ing from the now-closed socket, we then read 0 bytes. in
irc_answer (ircpipe.c:260), strtok_r then returns NULL on the first
invocation (which again we did not expect, as we did not expect an empty
buffer to get passed). then we tried to look at the first character of
the string, dereferencing NULL and causing a SIGSEGV.

the solution is of course to check that return value of read(2) is > 0.
this is equivalent to aborting on POLLHUP; the comment in irc_poll() has
been adjusted to reflect this as well.

3 weeks agoadd LF to error message
Tobias Girstmair [Sat, 25 May 2024 12:33:14 +0000 (14:33 +0200)]
add LF to error message

4 weeks agodocument non-filtering of escape sequences
Tobias Girstmair [Mon, 20 May 2024 16:44:59 +0000 (18:44 +0200)]
document non-filtering of escape sequences

4 weeks agofree TLS context after closing
Tobias Girstmair [Mon, 20 May 2024 16:36:50 +0000 (18:36 +0200)]
free TLS context after closing

as per libretls docs.

4 weeks agoupdate ircpipe spec document
Tobias Girstmair [Mon, 20 May 2024 16:17:07 +0000 (18:17 +0200)]
update ircpipe spec document

note that joining multiple channels doesn't need special handling; c.f.
     Command: JOIN
  Parameters: <channel>{,<channel>} [<key>{,<key>}]
  Alt Params: 0
one can just say `-j '#chan1,#chan2`. even protected channels work:
  -j '#chan1,#chan2 key1,key2'

4 weeks agoimprove PONG sending
Tobias Girstmair [Mon, 20 May 2024 16:04:18 +0000 (18:04 +0200)]
improve PONG sending

this gets rid of the double-send(2) (which in theory allows us to enable
Nagle's TCP_NODELAY). we need to restore the line terminator that strtok
removed. while the spec says we should send \r\n, it would probably
suffice to non-compliantly just do line[n] = '\n' (and rely on postel's
law to save us). but strtok only overwrites the first delimeter;
transforming "...\n..." into "...\0..." and "...\r\n..." into
"...\0\n...". so by looking ahead one byte we can determine which
terminator(s) were sent by the server and send back the same one(s). of
course, this doesn't hold for \n\r, just \r or \n\n (neither of which we
expect), but it would fall back to a sensible form regardless.

4 weeks agosimplify error messages for non-syscalls
Tobias Girstmair [Mon, 20 May 2024 15:49:06 +0000 (17:49 +0200)]
simplify error messages for non-syscalls

makes no sense to simulate perror for that kind of error.

4 weeks agoimplement socket timeout on connect
Tobias Girstmair [Mon, 20 May 2024 15:44:30 +0000 (17:44 +0200)]
implement socket timeout on connect

before this, we could have hung connecting to unavailable servers for
essentially ever. we only set SO_SNDTIMEO (not SO_RCVTIMEO) as we only
care when packets we send don't get ACKed in time (more specifically, we
only care about the server ACKing our initial SYN), not when the server
stops sending data for a while (the latter we handle using PING/PONG
ourselves).

c.f. https://stackoverflow.com/a/4182564. should cause EINPROGRESS for
connect(2), EAGAIN or EWOULDBLOCK otherwise.

4 weeks agoimplement handler for the usual terminating signals
Tobias Girstmair [Mon, 20 May 2024 15:40:21 +0000 (17:40 +0200)]
implement handler for the usual terminating signals

right now, we just send /QUIT and cleanly shut down the socket. in the
future, this allows us to do something to the socket on SIGUSR{1,2}, for
example.

4 weeks agoinitiate PING if socket idles for too long
Tobias Girstmair [Fri, 17 May 2024 14:55:37 +0000 (16:55 +0200)]
initiate PING if socket idles for too long

note that we only start tracking the monotonic timestamp of last
incoming socket activity in irc_poll(). because of that, we must
initialize recv_ts or we risk never sending the first PING when the
server doesn't send anything after the 001 numeric (e.g. znc with no
joined channels).

there isn't really a reason to configure ping interval/pong timeout, so
we just pick some values.

4 weeks agosimplify sasl handling
Tobias Girstmair [Fri, 17 May 2024 12:10:06 +0000 (14:10 +0200)]
simplify sasl handling

note that we still don't support multiple SASL chunks; the error
handling was just removed from irc_base64() (OR_DIE is incompatible with
assignment). we should probably verify this constraint in main().

5 weeks agodirectly exit from irc_answer() on error, improve error handling
Tobias Girstmair [Sun, 12 May 2024 18:56:26 +0000 (20:56 +0200)]
directly exit from irc_answer() on error, improve error handling

e.g. ERR_YOUREBANNEDCREEP (465) is sent after 001 but before JOIN.

5 weeks agoNULL-terminate read() calls
Tobias Girstmair [Sun, 12 May 2024 18:29:46 +0000 (20:29 +0200)]
NULL-terminate read() calls

we reuse the samme buffer for all network and local read(2)s. irc_answer
(or more specifically, strtok(3)) expects NULL-terminated strings. this
caused us to re-parse older strings when the buffer shrank between two
consecutive read(2) calls.

5 weeks agorework irc_answer to catch specific error replies and exit when encountered
Tobias Girstmair [Sun, 12 May 2024 17:27:08 +0000 (19:27 +0200)]
rework irc_answer to catch specific error replies and exit when encountered

we still need to pass the error line to the OR_DIE_irc macro, so it's
displayed on stderr (stdout is likely redirected).

6 weeks agorename PORT_PLAIN to PORT_TCP
Tobias Girstmair [Fri, 3 May 2024 18:30:09 +0000 (20:30 +0200)]
rename PORT_PLAIN to PORT_TCP

6 weeks agopartially revert IRCv3 USER
Tobias Girstmair [Fri, 3 May 2024 17:14:45 +0000 (19:14 +0200)]
partially revert IRCv3 USER

tilde prefixing to disable ident lookup seems to not be supported by
libera, so don't bother.

6 weeks agouse IRCv3 USER command
Tobias Girstmair [Fri, 3 May 2024 16:56:40 +0000 (18:56 +0200)]
use IRCv3 USER command

* mode must be '0'
* if the client's host does not expose an ident server, the username
  should be prefixed by '~'

living standard document: https://modern.ircdocs.horse/#user-message

7 weeks agoswitch to RFC2812 style USER command
Tobias Girstmair [Sat, 27 Apr 2024 12:18:17 +0000 (14:18 +0200)]
switch to RFC2812 style USER command

we don't (yet?) allow setting user mode, though.

7 weeks agoimplement TLS_WANT_POLL{IN,OUT}
Tobias Girstmair [Sat, 27 Apr 2024 10:43:40 +0000 (12:43 +0200)]
implement TLS_WANT_POLL{IN,OUT}

we always listen for POLLIN events, so we don't need to explicitly check
for it. not sure if this implementation is correct. modeled after
https://github.com/openbsd/src/blob/master/usr.bin/nc/netcat.c

7 weeks agodefend against malformed messages
Tobias Girstmair [Sat, 27 Apr 2024 10:41:31 +0000 (12:41 +0200)]
defend against malformed messages

if a message consists of only the prefix, we'd overrun the buffer.

7 weeks agodocument password and tls related flags
Tobias Girstmair [Sat, 27 Apr 2024 10:41:11 +0000 (12:41 +0200)]
document password and tls related flags

4 months agoimplement TLS support using libtls or libretls
Tobias Girstmair [Fri, 16 Feb 2024 20:56:12 +0000 (21:56 +0100)]
implement TLS support using libtls or libretls

also fixes some c90 related pedantic warnings and improves error
messages for bad or missing cli parameters.

3 years agoremove debug printfs
Tobias Girstmair [Mon, 28 Dec 2020 16:32:39 +0000 (17:32 +0100)]
remove debug printfs

3 years agouse getaddrinfo() for transparent ipv4/6 support
Tobias Girstmair [Mon, 28 Dec 2020 16:18:22 +0000 (17:18 +0100)]
use getaddrinfo() for transparent ipv4/6 support

introduces a malloc :(

3 years agofix polling standard input
Tobias Girstmair [Mon, 28 Dec 2020 15:15:08 +0000 (16:15 +0100)]
fix polling standard input

3 years agosupport server password (PASS message)
Tobias Girstmair [Mon, 28 Dec 2020 15:00:48 +0000 (16:00 +0100)]
support server password (PASS message)

3 years agoinitial commit
Tobias Girstmair [Wed, 23 Dec 2020 21:16:47 +0000 (22:16 +0100)]
initial commit

Imprint / Impressum