commit 9591b402cfa2591f244985dfc0dec4203dd96db3
parent 613bc8cd77bb552dc1b3ec5a302f0a8329c8184f
Author: Mario Rosell R. Martinez <mario@mariorosell.es>
Date: Thu, 19 Mar 2026 10:37:19 +0100
thing
Diffstat:
| M | README | | | 15 | +++++---------- |
| M | anntp.h | | | 64 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 69 insertions(+), 10 deletions(-)
diff --git a/README b/README
@@ -1,7 +1,7 @@
-anntp -- async nntp library in C
-================================
+anntp -- a nntp implementation written in C
+===========================================
-anntp is a public-domain, TLS-capable, asynchronous C implementation for POSIX systems of the Network News Transfer Protocol (NNTP), used by Usenet and other similar networks.
+anntp is a public-domain, TLS-capable, C implementation for POSIX systems of the Network News Transfer Protocol (NNTP), used by Usenet and other similar networks.
It is a single header with no dependencies by default (unless you enable TLS, then it depends on OpenSSL), and implements full RFC 977 and 3977.
@@ -34,18 +34,13 @@ Before including `anntp.h`, you can define any of these macros:
Usage
~~~~~
-Before anything, call the `anntp_init()` routine.
-
-The entire API is based on the idea of **connections**, a connection abstracts the well, connection (*duh!*) from a client to a server.
-
-A connection is opened with `anntp_mkconn()`, it takes a server URL, and a bool asking weather to enable TLS or not (ignored if TLS is deactivated), and returns a (*heap-allocated*) connection pointer. It must be closed using `anntp_close()`.
-
-Use `anntp_send(connection, cmd)` to send a command, and get the message by using `anntp_read(connection)`, it returns an unsigned char.
+see the doc/ dir
TODOs
-----
* A higher-level API
+* More
License
-------
diff --git a/anntp.h b/anntp.h
@@ -308,5 +308,69 @@ anntp_readdot(AnntpConnection* cv, char* buf, size_t maxlen)
return (ssize_t)pos;
}
+/* NOTE: I have a gut feeling this is probably a bit insecure without tls... */
+int
+anntp_auth(AnntpConnection* cv, const char* user, const char* pass)
+{
+ /*
+ * NNTP auth:
+ * C: AUTHINFO USER <user>
+ * S: 381 (need password) OR 281 (already authenticated) OR error
+ * C: AUTHINFO PASS <pass>
+ * S: 281 (success) OR error
+ */
+
+ if (!cv || !user || !pass)
+ return -1;
+
+ char line[ANNTP_BUFSIZE];
+ char cmd[ANNTP_BUFSIZE];
+ ssize_t n;
+
+ /* send login */
+ snprintf(cmd, sizeof(cmd), "AUTHINFO USER %s", user);
+
+ n = anntp_writeline(cv, cmd);
+ if (n <= 0)
+ return -1;
+
+ /* read response */
+ n = anntp_readline(cv, line, sizeof(line));
+ if (n <= 0)
+ return -1;
+
+ /* already authenticated */
+ if (strncmp(line, "281", 3) == 0) {
+ return 0;
+ }
+
+ /* must be 381 to continue */
+ if (strncmp(line, "381", 3) != 0) {
+ return -1;
+ }
+
+ snprintf(cmd, sizeof(cmd), "AUTHINFO PASS %s", pass);
+
+ n = anntp_writeline(cv, cmd);
+
+ /* probably a good idea to wipe password from stack */
+ memset(cmd, 0, sizeof(cmd));
+
+ if (n <= 0)
+ return -1;
+
+ n = anntp_readline(cv, line, sizeof(line));
+ if (n <= 0)
+ return -1;
+
+ /* success */
+ if (strncmp(line, "281", 3) == 0) {
+ return 0;
+ }
+
+ /* failure */
+ return -1;
+}
+
#endif /* ANNTP_IMPLEMENTATION */