--- INSTALL.run.orig Sun Jan 23 08:43:27 2000 +++ INSTALL.run Tue Aug 1 13:19:07 2000 @@ -67,6 +67,12 @@ which can do fine-grain control. The coarse grain posting access here is determined by the POSTING_OK environment variable. + Note: in the examples below, you may want to run "snauth" instead + of "snntpd ...". Snauth would only allow authorized users to read + and will allow all authorized users to post (so you do not have + to set POSTING_OK yourself). Snauth uses PAM for authentication - + make sure your /etc/pam.d/sn is reasonable. + Running under inetd/tcpd: In /etc/hosts.allow, insert a line: --- snauth.c.orig Wed Dec 31 16:00:00 1969 +++ snauth.c Mon May 7 09:36:30 2001 @@ -0,0 +1,143 @@ +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#define MAXLINE 1024 + +char * name; + +int debug = 0; + +void usage (char * err) { + if (err!=NULL) fprintf(stderr, "Error: %s\n", err); + fprintf(stderr,"Usage:\n\t%s [-p ]\n\n\t-p \tuse as the application name for PAM authentication (default - sn)\n-d\tSend debugging information to syslog\n",name); + exit(1); +} + +char * get_line(char * line, int size) { + char * res = fgets(line, size, stdin); + if (res!=NULL) { + if (debug) syslog(LOG_DEBUG," <<< %s",line); + if (!strncasecmp(line,"QUIT",4)) { + if (debug) syslog(LOG_DEBUG," >>> 205 ."); + fputs("205 .\r\n",stdout); + exit(0); + } + } + return res; +} + +int nntp_conv (int num_msg, const struct pam_message **msg, struct pam_response **resp, void * app_data) { + int i,j; + char line[MAXLINE]; + char * res=NULL; + + for (i=0;imsg_style) { + case PAM_PROMPT_ECHO_ON: + if (debug) syslog(LOG_DEBUG," >>> 480 Authentication required - %s\n",msg[i]->msg); + printf("480 Authentication required - %s\r\n",msg[i]->msg); + if (get_line(line,MAXLINE) == NULL) return PAM_CONV_ERR; + if (strncasecmp(line,"AUTHINFO USER ",14)) res=NULL; + else res=strdup(line+14); + break; + case PAM_PROMPT_ECHO_OFF: + if (debug) syslog(LOG_DEBUG," >>> 381 Password required - %s\n",msg[i]->msg); + printf("381 Password required - %s\r\n",msg[i]->msg); + if (get_line(line,MAXLINE) == NULL) return PAM_CONV_ERR; + if (strncasecmp(line,"AUTHINFO PASS ",14)) res=NULL; + else res=strdup(line+14); + break; + case PAM_TEXT_INFO: + break; + case PAM_ERROR_MSG: + if (debug) syslog(LOG_DEBUG," >>> 481 Authentication failure - %s\n",msg[i]->msg); + printf("481 Authentication failure - %s\r\n",msg[i]->msg); + default: + return PAM_CONV_ERR; + + } + if (res!=NULL) for(j=strlen(res)-1; ((j>=0)&&((res[j]=='\r')||(res[j]=='\n')||(res[j]==' ')||(res[j]=='\t'))); res[j--]=0); + resp[i]=(struct pam_response *) malloc(sizeof (struct pam_response)); + resp[i]->resp=res; + resp[i]->resp_retcode=0; + } + + return PAM_SUCCESS; +} + +void setrhost (pam_handle_t *pamh) { + struct sockaddr_in from; + socklen_t fromlen=sizeof (from); + char * host; + struct hostent *hp; + + if (getpeername(0, (struct sockaddr *)&from, &fromlen) < 0) return; + hp = gethostbyaddr((char *)(&from.sin_addr), sizeof (struct in_addr), from.sin_family); + if (hp!=NULL) host = hp->h_name; else host = inet_ntoa(from.sin_addr); + + pam_set_item(pamh,PAM_RHOST,host); + +} + +int main (int argc, char * const argv[]) { + pam_handle_t *pamh = NULL; + char * pam_name = "sn"; + char path[sizeof(BINDIR)+MAXLINE]; + struct pam_conv conv = { nntp_conv, NULL }; + int i; + + name = argv[0]; + for (i=1; i< argc; i++) { + if ((! strcmp(argv[i],"-p"))&&(i+1>> 200 Hi, Posting is OK, but you need to authenticate"); + fputs("200 Hi, Posting is OK, but you need to authenticate\r\n",stdout); + if (get_line(path,sizeof(path)) == NULL) { + syslog (LOG_ERR, "Never got the first message"); + exit(1); + } + if (pam_start(pam_name, NULL, &conv, &pamh) != PAM_SUCCESS) { + syslog (LOG_ERR, "PAM initialization failed"); + exit(1); + } + setrhost (pamh); + + if (pam_authenticate(pamh, PAM_DISALLOW_NULL_AUTHTOK) != PAM_SUCCESS) { + if (debug) syslog(LOG_DEBUG," >>> 481 Authentication failure"); + fputs("481 Authentication failure\r\n",stdout); + exit(1); + } + + pam_end(pamh, PAM_SUCCESS); + closelog(); + + setenv("POSTING_OK","yes",1); + if (debug) syslog(LOG_DEBUG," >>> 281 Auth OK"); + fputs("281 Auth OK\r\n",stdout); + strcpy(path,BINDIR); + strcat(path,":/bin:/usr/bin"); + setenv("PATH",path,1); + strcpy(path,BINDIR); + strcat(path,"/snntpd"); + if (debug) return(execl(path,path,"-S","-d","-d","-d","logger","-p","news.info",NULL)); + else return(execl(path,path,"-S","logger","-p","news.info",NULL)); +} --- Makefile.orig Sun Nov 11 14:28:47 2001 +++ Makefile Sun Nov 11 14:29:33 2001 @@ -53,10 +53,10 @@ addr.o valid.o key.o field.o OBJS =$(AOBJS) snscan.o snprimedb.o sndumpdb.o snntpd.o list.o \ post.o commands.o snexpire.o \ - snmail.o snget.o + snmail.o snget.o snauth.o BINS =snprimedb snntpd snfetch snexpire snsend \ snmail snget sngetd snscan sndumpdb \ - snnewgroup sndelgroup lockf snsplit + snnewgroup sndelgroup lockf snsplit snauth SCRIPTS =dot-outgoing.ex HELLO POST PROGS =$(BINS) $(SCRIPTS) MANS =sn.8 sncat.8 sndelgroup.8 sndumpdb.8 snexpire.8 \ @@ -122,6 +122,8 @@ $(LD) `cat cc-flags` $^ -o $@ $(LIBS) lockf: lockf.o $(LD) `cat cc-flags` $^ -o $@ $(LIBS) +snauth: snauth.o + $(LD) `cat cc-flags` $^ -o $@ -lpam %: %.in sed-cmd sed -f sed-cmd $< >$@ @@ -202,3 +204,4 @@ snmail.o: snmail.c config.h parameters.h hostname.h unfold.h path.h \ addr.h field.h snget.o: snget.c config.h get.h parameters.h path.h valid.h +snauth.o: snauth.c