Выбрать главу

There are a number of NNTP packages. One of the more widely known is the NNTP daemon, also known as the reference implementation. Originally, it was written by Stan Barber and Phil Lapsley to illustrate the details of RFC-977. As with much of the good software available today, you may find it prepackaged for your Linux distribution, or you can obtain the source and compile it yourself. If you choose to compile it yourself, you will need to be quite familiar with your distribution to ensure you configure all of the file paths correctly.

The nntpd package has a server, two clients for pulling and pushing news, and an inews replacement. They live in a B News environment, but with a little tweaking, they will be happy with C News, too. However, if you plan to use NNTP for more than offering newsreaders access to your news server, the reference implementation is not really an option. We will therefore discuss only the NNTP daemon contained in the nntpd package and leave out the client programs.

If you wish to run a large news site, you should look at the InterNet News package, or INN, that was written by Rich Salz. It provides both NNTP and UUCP-based news transport. News transport is definitely better than nntpd. We discuss INN in detail in Chapter 23, Internet News.

The NNTP Protocol

We've mentioned two NNTP commands that are key to how news articles are pushed or pulled between servers. Now we'll look at these in the context of an actual NNTP session to show you how simple the protocol is. For the purposes of our illustration, we'll use a simple telnet client to connect to an INN-based news server at the Virtual Brewery called news.vbrew.com. The server is running a minimal configuration to keep the examples short. We'll look at how to complete the configuration of this server in Chapter 23. In our testing we'll be very careful to generate articles in the junk newsgroup only, to avoid disturbing anyone else.

Connecting to the News Server

Connecting to the news server is a simple as opening a TCP connection to its NNTP port. When you are connected, you will be greeted with a welcome banner. One of the first commands you might try is help. The response you get generally depends upon whether the server believes you are a remote NNTP server or a newsreader, as there are different command sets required. You can change your operating mode using the mode command; we'll look at that in a moment:

$ telnet news.vbrew.com nntp

Trying 172.16.1.1...

Connected to localhost.

Escape character is '^]'.

200 news.vbrew.com InterNetNews server INN 1.7.2 08-Dec-1997 ready

help

100 Legal commands

        authinfo

  help

  ihave

  check

    takethis

    list

    mode

    xmode

    quit

    head

    stat

    xbatch

    xpath

    xreplic

For more information, contact "usenet" at this machine.

.

The responses to NNTP commands always end with a period (.) on a line by itself. The numbers you see in the output listing are response codes and are used by the server to indicate success or failure of a command. The response codes are described in RFC-977; we'll talk about the most important ones as we proceed.

Pushing a News Article onto a Server

We mentioned the IHAVE command when we talked about pushing news articles onto a news server. Let's now have a look at how the IHAVE command actually works:

ihave ‹123456@gw.vk2ktj.ampr.org›

335

From: terry@gw.vk2ktj.ampr.org

Subject: test message sent with ihave

Newsgroups: junk

Distribution: world

Path: gw.vk2ktj.ampr.org

Date: 26 April 1999

Message-ID: ‹123456@gw.vk2ktj.ampr.org›

Body:

This is a test message sent using the NNTP IHAVE command.

.

235

All NNTP commands are case insensitive, so you may enter them in either upper- or lowercase. The IHAVE command takes one mandatory argument, it being the Message ID of the article that is being pushed. Every news article is assigned a unique message ID when it is created. The IHAVE command provides a way of the NNTP server to say which articles it has when it wants to push articles to another server. The sending server will issue an IHAVE command for each article it wishes to push. If the command response code generated by the receiving NNTP server is in the "3xx" range, the sending NNTP server will transmit the complete article, including it's full header, terminating the article with a period on a line by itself. If the response code was in the "4xx" range, the receiving server has chosen not to accept this article, possibly because it already has it, or because of some problem, such as running out of disk space.

When the article has been transmitted, the receiving serve issues another response code indicating whether the article transmission was successful.

Changing to NNRP Reader Mode

Newsreaders use their own set of commands when talking to a news server. To activate these commands, the news server has to be operating in reader mode. Most news servers default to reader mode, unless the IP address of the connecting host is listed as a news-forwarding peer. In any case, NNTP provides a command to explicitly switch into reader mode:

mode reader

200 news.vbrew.com InterNetNews NNRP server INN 1.7.2 08-Dec-1997 ready/

    (posting ok).

help

100 Legal commands

  authinfo user Name|pass Password|generic <prog> <args>

  article [MessageID|Number]

  body [MessageID|Number]

  date

  group newsgroup

  head [MessageID|Number]

  help

  ihave

  last

  list [active|active.times|newsgroups|distributions|distrib.pats|/

      overview.fmt|subscriptions]

  listgroup newsgroup

  mode reader

  newgroups yymmdd hhmmss ["GMT"] [<distributions>]

  newnews newsgroups yymmddhhmmss ["GMT"] [<distributions>]

  next

  post

  slave

  stat [MessageID|Number]

  xgtitle [group_pattern]