🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.nntp
1 messages
1 total messages Started by Chiaki Ishikawa Thu, 11 Mar 1993 09:25
re:Inquiry : INN authinfo-ready rn newsreader. (My Solution)
#1732
Author: Chiaki Ishikawa
Date: Thu, 11 Mar 1993 09:25
342 lines
11429 bytes
Hello.

First of all. Thank you to Rich $alz and friends for great INN
package.

About a week ago, I asked the net if there is an implementation of INN
authinfo-ready newsreader. So far, I have not received an answer.  I
am installing INN package and wanted to use the access-right setup
based on username which was mentioned in the INN documentation.

Since I didn't get any response, I did what a normal red-blooded
programmer type does. I hacked the source myself despite my busy
workload...

Here is what I did and attached is a hacked version of
NNTPsendpassword() for your reference and comment.

This is slightly long, but I hope this message is useful for those
who need to prepare authinfo-ready newsreaders.

I hacked rn-4.4 (maybe slightly out of date) so that

  - it is linked to INN1.3's nntp client library, [This had been done
    already when I posted the earlier question.]

  - it uses a privitized [heavily hacked] version of NNTPsendpassword(), and

  - it calls the hakced NNTPsendpassword() from within init.c.

The result is that I can now set read permission based on username
using a private password file used by the newsreader [see below], and
a corresponding nnrp.access file.

The major problem was that
 - the description of NNTPsendpassword(), and the way the hosts.nntp,
nnrp.access, and other password file(s) work together with innd, nnrpd
from the viewpoint of NEWSREADING WITH ACCESS PERMISSION BASED ON
USERID was not entirely clear.  

It could be that INN is huge and difficult to master in a short time,
my English skill was not so good, or the document leaves much to be
desired :-) The way these files work together were explained very well
for the case of reading and transferring using less restrictive access
permission setup, i.e., ordinary case, I think.

[I am afraid that I am missing something here. But here is what I did
anyway to help others tackle similar projects using INN.]

What I did was to set up a separate password file since it seemed that
I need  a file containing set of password/user in nnrp.access.
This file must be accessible by the newsreader and should be usable
with NNTPsendpassword()-like function.

So I tried to prepare a file similar to nnrp.access.  However, it
turns out that the ready-made routine to send authinfo information,
namely, NNTPpassword expects different format.  The file read by
NNTPpassoword expects lines in the following format.

host:user:passwd[:authstyle]

Well, originally, I thought the `host' is the hostname of the client
machine where the user invokes newsreader such as hacked Rrn to access
remote INN serverw. Wrong! After much dumping of internal data, etc..,
I have found out that NNTPsendpassword uses the host as in the first
field of the above line as the host where the INN (NNTP or NNRPD)
resides instead of the client machine where the user tries to read!? 
(Now, maybe my way of calling NNTPsendpassword in init.c was wrong.
check the source code at the end.) I hope everyone agrees that the use
of words/phrases such as host, hostname, client and server/client in
the document are quite confusing. But this simple fact escaped my
understanding until I began analyzing what NNTPsendpassword does. This
was the biggest hurdle.

Secondly, it seems that we can't leave passwd field empty.  Yes, we
can leave it empty, but it seems that this have the effect of not
using the most restrictive entry in the nnrp.access.  So we need to
make sure we use password for both our private password file and the
nnrp.access file.

Third problem was that NNTPsendpassword() mysteriously picks up ANY(!)
entry that has the matching server field and use it to obtain user and
password field. I have no idea why it behaved this way. (Am I missing
something here?) To make the change easy, the modified code just picks
up the value of environmental variable LOGNAME and use it for
additional matching criteria.  If this value does not match the second
field (user), the line is skipped to look for other matching lines.

Here is the mods.

File: rn init.c 
	In RN distribution, there is another source file that calls
server_init(). I have not yet looked at it yet. 

*** /tmp/RCSAa00371	Thu Mar 11 17:55:58 1993
--- init.c	Thu Mar 11 15:25:22 1993
***************
*** 171,176 ****
--- 171,189 ----
      if (handle_server_response(response, server) < 0)
  	finalize(1);
  
+ #ifdef PMC_USE_PASSWORD
+     {
+       /* PMC: Assume that we use nntplib that comes with INN package 1.3 */
+       /* clientlib.c uses ser_rd_fp, and ser_wr_fp after NNTPconnect! */
+       extern FILE *ser_rd_fp;
+       extern FILE *ser_wr_fp;
+       int rc;
+       rc = NNTPsendpassword(server, ser_rd_fp, ser_wr_fp);  
+       fprintf(stderr,"NNTPsendpassword:server=%s returns = %d\n", 
+ 	      server == NULL ? "(null)" : server, rc); 
+     }
+ #endif
+ 
  #endif
  
      /* open active file, etc. */

FILE: sendpass.c.  This is used instead of the one in the library.

There are some hard-coded constants and such, but you will get the
idea.  Some header files are commented out and some macro definitions,
a typedef, and a couple of extern declarations are inserted so that we
can compile this file under rn source directory.


/*  $Revision: 1.9 $
**
*/
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#if 0
#include "configdata.h"
#endif
#include "nntp.h"
#if 0
#include "paths.h"
#include "libinn.h"
#include "clibrary.h"
#include "macros.h"
#endif

typedef int SIZE_T;

#define EQ(a, b)		(strcmp((a), (b)) == 0)
#define EQn(a, b, n)		(strncmp((a), (b), (SIZE_T)(n)) == 0)
#define caseEQ(a, b)		(strcasecmp((a), (b)) == 0)
#define caseEQn(a, b, n)	(strncasecmp((a), (b), (SIZE_T)(n)) == 0)

extern char *getenv();
extern char *strchr();

/*
**  Send authentication information to an NNTP server.
*/
int
NNTPsendpassword(server, FromServer, ToServer)
    char		*server;
    FILE		*FromServer;
    FILE		*ToServer;
{
    register FILE	*F;
    register char	*p;
#define SMBUF 255
    char		buff[SMBUF];
    char		input[SMBUF];
    char		*user;
    char		*pass;
    char		*style;
    int			oerrno;

    char *LOGNAME = NULL;

    /* What server are we interested in?  Default to the campus one. */
    if (server == NULL
     && ((server = "sparc11.personal-media.co.jp") == NULL))
	return -1;


    LOGNAME = getenv("LOGNAME");
    if(LOGNAME == NULL)
      LOGNAME = "news";

    {
      char *cp = getenv("INN_TEST_ID");
      if(cp != NULL)
	LOGNAME = cp;
    }

    fprintf(stderr,"USERNAME=%s\n", LOGNAME);

/*
 * We must open password file for nnrpd.
 * We use two different password files in case opening of the first one fails..
 */
#define PATH_NNTPPASS "/usr/lib/news/pmc_nnrpd_passwd"
#define PATH_NNTPPASS_2 "/usr2a/news.dir/pmc_nnrpd_passwd"


#if DEBUG
    fprintf(stderr,"\nPASSWORD FILE %s\n\n", PATH_NNTPPASS);
#endif

     /* Open the password file; coarse check on errno, but good enough. */
    if ((F = fopen(PATH_NNTPPASS, "r")) == NULL)
	{
	  perror(PATH_NNTPPASS);
	  fprintf(stderr,"Trying %s\n", PATH_NNTPPASS_2);
	  if(( F = fopen(PATH_NNTPPASS_2,"r")) == NULL)
	    {
	      perror(PATH_NNTPPASS_2);
	      return errno == EPERM ? -1 : 0;
	    }
	}

    /* Scan the file, skipping blank and comment lines. */
    while (fgets(buff, sizeof buff, F) != NULL) {
	if ((p = strchr(buff, '\n')) != NULL)
	    *p = '\0';
	if (buff[0] == '\0' || buff[0] == '#' /*COMMENT_CHAR*/)
	    continue;

	/* Parse the line. */
	if ((user = strchr(buff, ':')) == NULL)
	    continue;
	*user++ = '\0';


	if ((pass = strchr(user, ':')) == NULL)
	    continue;
	*pass++ = '\0';



	if ((style = strchr(pass, ':')) != NULL) {
	    *style++ = '\0';
	    if (!EQ(style, "authinfo")) {
		errno = EDOM;
		break;
	    }
	}

#ifdef DEBUG
	fprintf(stderr,"trial user=%s\n", user);

	fprintf(stderr,"trial pass=%s\n", pass);
#endif

	if( strcmp(user, LOGNAME) != 0)
	  {
#ifdef DEBUG
	    fprintf(stderr, "\nusername =%s, and LOGNAME =%s does not match.\n", user, LOGNAME);
	    fprintf(stderr, "skipping...\n");
#endif
	    continue;
	  }

#ifdef DEBUG
	fprintf(stderr,"server=%s, buff=%s\n", server, buff);
#endif

	if (!caseEQ(server, buff))
	    continue;

	if (*user) {
	    fprintf(stderr,"sending user=%s for authentification.\n", user);
	    /* Send the first part of the command, get a reply. */
	    (void)fprintf(ToServer, "authinfo user %s\r\n", user);
	    if (fflush(ToServer) == EOF || ferror(ToServer))
	      {
		fprintf(stderr,"\nauthinfo send error.\n");
		break;
	      }
	    if (fgets(input, sizeof input, FromServer) == NULL
	     || atoi(input) != NNTP_AUTH_NEXT_VAL)
	      {
		fprintf(stderr,"\nauthinfo reply error.\n");
		break;
	      }
	}

	if (*pass) {
	    /* Send the second part of the command, get a reply. */
	    fprintf(stderr,"sending passwd for authentification.\n");
	    (void)fprintf(ToServer, "authinfo pass %s\r\n", pass);
	    if (fflush(ToServer) == EOF || ferror(ToServer))
	      {
		fprintf(stderr,"\nauthinfo pass send error.\n");
		break;
	      }
	    if (fgets(input, sizeof input, FromServer) == NULL
	     || atoi(input) != NNTP_AUTH_OK_VAL)
	      {
		fprintf(stderr,"\nauthinfo pass reply error.\n");
		break;
	      }
	}

	/* Authenticated. */
	fprintf(stderr,"authenticated.\n");
	(void)fclose(F);
	return 0;
    }

    /* End of file without finding a password, that's okay. */
    fprintf(stderr,"\No password for server=%s, user=%s. (This is OK.)\n",
	    server, LOGNAME);
    if (feof(F)) {
	(void)fclose(F);
	return 0;
    }

    /* Save errno, close the file, fail. */
    fprintf(stderr,"\nerror!!!\n");
    oerrno = errno;
    (void)fclose(F);
    errno = oerrno;
    return -1;
}



======== a few lines of the prepared password file used by
         the hacked up NNTPsendpassword.
	(I am not entirely sure why I don't need FQDN instead of
	`sparc11', but it works currently.)
	Also, I could use better password scheme. I am just checking
	right now.
#
# pmc_nnrpd_passwd
#
sparc11:aizawa:PWaizawa
sparc11:ch:PWch
sparc11:emiko:PWemiko
====

 Chiaki Ishikawa,  Personal Media Corp.,  MY Bldg, 1-7-7 Hiratsuka,
 Shinagawa, Tokyo 142, JAPAN. FAX:+81-3-5702-0359, Phone:+81-3-5702-0351
 UUNET: ishikawa@personal-media.co.jp
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads