INN commit: trunk (9 files)

INN Commit Russ_Allbery at isc.org
Wed Dec 24 22:27:08 UTC 2008


    Date: Wednesday, December 24, 2008 @ 14:27:07
  Author: iulius
Revision: 8255

Add the CAPABILITIES command to nnrpd.  Also check whether
the possible keyword is valid.

Remove LIST EXTENSIONS.

close #91

Added:
  trunk/lib/commands.c
Modified:
  trunk/MANIFEST
  trunk/doc/pod/getlist.pod
  trunk/include/inn/libinn.h
  trunk/include/inn/nntp.h
  trunk/lib/Makefile
  trunk/nnrpd/list.c
  trunk/nnrpd/nnrpd.c
  trunk/nnrpd/nnrpd.h

----------------------+
 MANIFEST             |    1 
 doc/pod/getlist.pod  |    5 +-
 include/inn/libinn.h |    1 
 include/inn/nntp.h   |    1 
 lib/Makefile         |    5 ++
 lib/commands.c       |   45 ++++++++++++++++++++++++
 nnrpd/list.c         |   40 ----------------------
 nnrpd/nnrpd.c        |   89 ++++++++++++++++++++++++++++++++++++++++++++++++-
 nnrpd/nnrpd.h        |   35 +++++++++----------
 9 files changed, 160 insertions(+), 62 deletions(-)

Modified: MANIFEST
===================================================================
--- MANIFEST	2008-12-24 11:05:44 UTC (rev 8254)
+++ MANIFEST	2008-12-24 22:27:07 UTC (rev 8255)
@@ -485,6 +485,7 @@
 lib/cleanfrom.c                       Clean out a From line
 lib/clientactive.c                    Client access to the active file
 lib/clientlib.c                       Replacement for C News library routine
+lib/commands.c                        Functions for NNTP commands
 lib/concat.c                          Concatenate strings with dynamic memory
 lib/conffile.c                        Routines for reading *.conf files
 lib/confparse.c                       Generic configuration file parser

Modified: doc/pod/getlist.pod
===================================================================
--- doc/pod/getlist.pod	2008-12-24 11:05:44 UTC (rev 8254)
+++ doc/pod/getlist.pod	2008-12-24 22:27:07 UTC (rev 8255)
@@ -37,9 +37,8 @@
 The listing files other than the F<active> file are common extensions to the
 NNTP protocol and may not be available on all servers.  For instance,
 C<distrib.pats>, C<moderators>, C<motd>, C<overview.fmt> and C<subscriptions>,
-amongst other (like C<extensions>, which is not a file, strictly speaking),
-may be available.  Moreover, a uwildmat(3) pattern I<pattern> may also be
-usable for some of these listing files.
+amongst other, may be available.  Moreover, a uwildmat(3) pattern I<pattern>
+may also be usable for some of these listing files.
 
 For more information on the formats of these files, see distrib.pats(5),
 moderators(5), motd.news(5), overview.fmt(5) and subscriptions(5).

Modified: include/inn/libinn.h
===================================================================
--- include/inn/libinn.h	2008-12-24 11:05:44 UTC (rev 8254)
+++ include/inn/libinn.h	2008-12-24 22:27:07 UTC (rev 8255)
@@ -155,6 +155,7 @@
 
 /* Various checks. */
 extern bool             IsValidArticleNumber(const char *string);
+extern bool             IsValidKeyword(const char *string);
 extern bool             IsValidRange(char *string);
 
 

Modified: include/inn/nntp.h
===================================================================
--- include/inn/nntp.h	2008-12-24 11:05:44 UTC (rev 8254)
+++ include/inn/nntp.h	2008-12-24 22:27:07 UTC (rev 8255)
@@ -44,6 +44,7 @@
 
 enum nntp_code {
     NNTP_INFO_HELP              = 100,
+    NNTP_INFO_CAPABILITIES      = 101,
     NNTP_INFO_DATE              = 111,
     NNTP_OK_BANNER_POST         = 200,
     NNTP_OK_BANNER_NOPOST       = 201,

Modified: lib/Makefile
===================================================================
--- lib/Makefile	2008-12-24 11:05:44 UTC (rev 8254)
+++ lib/Makefile	2008-12-24 22:27:07 UTC (rev 8255)
@@ -6,7 +6,7 @@
 CFLAGS  = $(GCFLAGS)
 
 # The base library files that are always compiled and included.
-SOURCES       = buffer.c cleanfrom.c clientactive.c clientlib.c concat.c \
+SOURCES       = buffer.c cleanfrom.c clientactive.c clientlib.c commands.c concat.c \
 		conffile.c confparse.c daemonize.c date.c dbz.c defdist.c \
 		dispatch.c fdflags.c fdlimit.c getfqdn.c \
 		getmodaddr.c hash.c hashtab.c headers.c hex.c innconf.c inndcomm.c \
@@ -105,6 +105,9 @@
   ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
   ../include/config.h ../include/inn/innconf.h ../include/inn/defines.h \
   ../include/inn/libinn.h ../include/nntp.h ../include/inn/nntp.h
+commands.o: commands.c ../include/config.h ../include/inn/defines.h \
+  ../include/inn/system.h ../include/inn/options.h ../include/clibrary.h \
+  ../include/config.h ../include/inn/libinn.h ../include/inn/defines.h
 concat.o: concat.c ../include/config.h ../include/inn/defines.h \
   ../include/inn/system.h ../include/inn/options.h \
   ../include/inn/libinn.h ../include/inn/defines.h

Added: lib/commands.c
===================================================================
--- lib/commands.c	                        (rev 0)
+++ lib/commands.c	2008-12-24 22:27:07 UTC (rev 8255)
@@ -0,0 +1,45 @@
+/*  $Id$
+**
+**  Routines for NNTP commands:  manipulation and checks.
+*/
+
+#include "config.h"
+#include "clibrary.h"
+#include <ctype.h>
+
+#include "inn/libinn.h"
+
+
+/*
+**  Return true if the given string is a keyword according to RFC 3977:
+**
+**      A "keyword" MUST consist only of US-ASCII letters, digits, and the
+**      characters dot (".") and dash ("-") and MUST begin with a letter.
+**      Keywords MUST be at least three characters in length.
+*/
+bool
+IsValidKeyword(const char *string)
+{
+    int len = 0;
+
+    /* Not NULL. */
+    if (string == NULL)
+        return false;
+
+    /* Begins with a letter. */
+    if (!CTYPE(isalpha, string[0]))
+        return false;
+
+    for (; *string != '\0'; string++) {
+        if (CTYPE(isalnum, *string) || *string == '.' || *string == '-')
+            len++;
+        else
+            return false;
+    }
+
+    /* At least 3 octets in length. */
+    if (len > 2)
+        return true;
+    else
+        return false;
+}


Property changes on: trunk/lib/commands.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Revision
Name: svn:eol-style
   + native

Modified: nnrpd/list.c
===================================================================
--- nnrpd/list.c	2008-12-24 11:05:44 UTC (rev 8254)
+++ nnrpd/list.c	2008-12-24 22:27:07 UTC (rev 8255)
@@ -11,10 +11,6 @@
 #include "inn/innconf.h"
 #include "inn/messages.h"
 
-#ifdef HAVE_SSL
-extern bool nnrpd_starttls_done;
-#endif /* HAVE_SSL */
-
 typedef struct _LISTINFO {
     const char *method;
     const char * File;
@@ -25,7 +21,6 @@
 } LISTINFO;
 
 static void cmd_list_schema(LISTINFO *lp, int ac, char *av[]);
-static void cmd_list_extensions(LISTINFO *lp, int ac, char *av[]);
 static void cmd_list_headers(LISTINFO *lp, int ac, char *av[]);
 
 static LISTINFO		INFOactive = {
@@ -52,10 +47,6 @@
     "DISTRIB.PATS", INN_PATH_DISTPATS, NULL, false, "distribution patterns",
     "Default distributions in form \"weight:pattern:value\""
 };
-static LISTINFO		INFOextensions = {
-    "EXTENSIONS", NULL, cmd_list_extensions, false, "supported extensions",
-    "Supported NNTP extensions"
-};
 static LISTINFO		INFOgroups = {
     "NEWSGROUPS", INN_PATH_NEWSGROUPS, NULL, true, "newsgroup descriptions",
     "Descriptions in form \"group description\""
@@ -80,7 +71,6 @@
     &INFOheaders,
     &INFOsubs,
     &INFOdistribpats,
-    &INFOextensions,
     &INFOgroups,
     &INFOmoderators,
     &INFOschema,
@@ -110,36 +100,6 @@
 
 
 /*
-**  List supported extensions.
-*/
-static void
-cmd_list_extensions(LISTINFO *lp, int ac UNUSED, char *av[] UNUSED)
-{
-    const char *mechlist = NULL;
-
-    Reply("%d %s.\r\n", NNTP_OK_LIST, lp->Format);
-
-#ifdef HAVE_SSL
-    if (!nnrpd_starttls_done && PERMauthorized != true)
-	Printf("STARTTLS\r\n");
-#endif /* HAVE_SSL */
-
-#ifdef HAVE_SASL
-    /* Check for SASL mechs. */
-    sasl_listmech(sasl_conn, NULL, " SASL:", ",", "", &mechlist, NULL, NULL);
-#endif /* HAVE_SASL */
-
-    if (PERMauthorized != true || mechlist != NULL) {
-	Printf("AUTHINFO%s%s\r\n",
-	       PERMauthorized != true ? " USER" : "",
-	       mechlist != NULL ? mechlist : "");
-    }
-
-    Printf(".\r\n");
-}
-
-
-/*
 **  List supported headers and metadata information.
 */
 static void

Modified: nnrpd/nnrpd.c
===================================================================
--- nnrpd/nnrpd.c	2008-12-24 11:05:44 UTC (rev 8254)
+++ nnrpd/nnrpd.c	2008-12-24 22:27:07 UTC (rev 8255)
@@ -119,6 +119,8 @@
         "|GENERIC program [argument ...]" },
     {	"BODY",		CMDfetch,	true,	1,	2,
 	CMDfetchhelp },
+    {   "CAPABILITIES", CMDcapabilities,false,  1,      2,
+        "[keyword]" },
     {	"DATE",		CMDdate,	false,	1,	1,
 	NULL },
     {	"GROUP",	CMDgroup,	true,	2,	2,
@@ -135,7 +137,7 @@
 	NULL },
     {	"LIST",		CMDlist,	true,	1,	3,
 	"[ACTIVE [wildmat]|ACTIVE.TIMES [wildmat]|DISTRIB.PATS|DISTRIBUTIONS"
-        "|EXTENSIONS|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]"
+        "|HEADERS [MSGID|RANGE]|MODERATORS|MOTD|NEWSGROUPS [wildmat]"
         "|OVERVIEW.FMT|SUBSCRIPTIONS]" },
     {	"LISTGROUP",	CMDgroup,	true,	1,	3,
 	"[newsgroup [range]]" },
@@ -331,6 +333,91 @@
 
 
 /*
+**  The CAPABILITIES command.
+**
+**  nnrpd does not advertise the MODE-READER capability; only innd may
+**  advertise it.
+*/
+void
+CMDcapabilities(int ac, char *av[])
+{
+    if (ac == 2 && !IsValidKeyword(av[1])) {
+        Reply("%d Syntax error\r\n", NNTP_ERR_SYNTAX);
+        return;
+    }
+
+    Reply("%d Capability list:\r\n", NNTP_INFO_CAPABILITIES);
+
+    Printf("VERSION 2\r\n");
+
+    Printf("IMPLEMENTATION %s\r\n", INN_VERSION_STRING);
+
+    /* The client is not already authenticated. */
+    if ((!PERMauthorized || PERMneedauth || PERMcanauthenticate)) {
+        Printf("AUTHINFO");
+        /* No arguments if the server does not permit any authentication commands
+         * in its current state. */
+        if (PERMcanauthenticate
+#ifdef HAVE_SSL
+            && (PERMcanauthenticatewithoutSSL || nnrpd_starttls_done)
+#endif
+           ) {
+#ifdef HAVE_SSL
+            /* USER is advertised only if a TLS layer is active. */
+            Printf(" USER");
+#endif
+#ifdef HAVE_SASL
+            Printf(" SASL");
+#endif
+        }
+        Printf("\r\n");
+    }
+
+    if (PERMcanread) {
+        Printf("HDR\r\n");
+    }
+    
+    if (PERMaccessconf->allowihave && PERMcanpost) {
+        Printf("IHAVE\r\n");
+    }
+
+    Printf("LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT\r\n");
+    
+    if (PERMaccessconf->allownewnews && PERMcanread) {
+        Printf("NEWNEWS\r\n");
+    }
+
+    if (PERMcanread) {
+        Printf("OVER\r\n");
+    }
+
+    if (PERMcanpost) {
+        Printf("POST\r\n");
+    }
+
+    Printf("READER\r\n");
+
+#ifdef HAVE_SASL
+    const char *mechlist = NULL;
+
+    /* Check for available SASL mechanisms. */
+    sasl_listmech(sasl_conn, NULL, "", " ", "", &mechlist, NULL, NULL);
+    Printf("SASL %s\r\n", mechlist != NULL ? mechlist : "");
+#endif
+
+#ifdef HAVE_SSL
+    /* A TLS layer is not active and the client is not already authenticated. */
+    if (!nnrpd_starttls_done
+        && (!PERMauthorized || PERMneedauth || PERMcanauthenticate)) {
+        Printf("STARTTLS\r\n");
+    }
+#endif
+
+    Printf(".\r\n");
+}
+
+
+/*
 **  Catch-all for unimplemented functions.
 */
 void

Modified: nnrpd/nnrpd.h
===================================================================
--- nnrpd/nnrpd.h	2008-12-24 11:05:44 UTC (rev 8254)
+++ nnrpd/nnrpd.h	2008-12-24 22:27:07 UTC (rev 8255)
@@ -234,24 +234,25 @@
 extern void		Reply(const char *fmt, ...);
 extern void             Printf(const char *fmt, ...);
 
-extern void		CMDauthinfo  (int ac, char** av);
-extern void		CMDdate      (int ac, char** av);
-extern void		CMDfetch     (int ac, char** av);
-extern void		CMDgroup     (int ac, char** av);
-extern void		CMDhelp      (int ac, char** av);
-extern void		CMDlist      (int ac, char** av);
-extern void		CMDmode      (int ac, char** av);
-extern void		CMDnewgroups (int ac, char** av);
-extern void		CMDnewnews   (int ac, char** av);
-extern void		CMDnextlast  (int ac, char** av);
-extern void             CMDover      (int ac, char** av);
-extern void		CMDpost      (int ac, char** av);
-extern void             CMDquit      (int ac, char** av);
-extern void		CMDxgtitle   (int ac, char** av);
-extern void		CMDpat       (int ac, char** av);
-extern void		CMD_unimp    (int ac, char** av);
+extern void             CMDauthinfo     (int ac, char** av);
+extern void             CMDcapabilities (int ac, char** av);
+extern void             CMDdate         (int ac, char** av);
+extern void             CMDfetch        (int ac, char** av);
+extern void             CMDgroup        (int ac, char** av);
+extern void             CMDhelp         (int ac, char** av);
+extern void             CMDlist         (int ac, char** av);
+extern void             CMDmode         (int ac, char** av);
+extern void             CMDnewgroups    (int ac, char** av);
+extern void             CMDnewnews      (int ac, char** av);
+extern void             CMDnextlast     (int ac, char** av);
+extern void             CMDover         (int ac, char** av);
+extern void             CMDpost         (int ac, char** av);
+extern void             CMDquit         (int ac, char** av);
+extern void             CMDxgtitle      (int ac, char** av);
+extern void             CMDpat          (int ac, char** av);
+extern void             CMD_unimp       (int ac, char** av);
 #ifdef HAVE_SSL
-extern void		CMDstarttls  (int ac, char** av);
+extern void             CMDstarttls     (int ac, char** av);
 #endif
 
 extern bool CMDgetrange(int ac, char *av[], ARTRANGE *rp, bool *DidReply);




More information about the inn-committers mailing list