home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1996 May / PCOnline_05_1996.bin / linux / source / n / tcpip / nntp-1.5 / nntp-1 / nntp.1.5.11t / inews / postauth.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-11  |  1.4 KB  |  79 lines

  1. /* 
  2.  * postauth: do authorization handshake when posting requires it.
  3.  * Originally by Brian Kantor. Some modifications by Stan Barber.
  4.  */
  5. #ifndef lint
  6. static char * rcsid = "$Header: postauth.c,v 1.3 90/08/11 21:25:38 sob Exp $";
  7. #endif
  8. #include <stdio.h>
  9. #include "../common/conf.h"
  10. #include "../common/nntp.h"
  11.  
  12. #ifdef AUTH
  13.  
  14. extern FILE *passfile;
  15.  
  16. postauth(host)
  17. char *host;
  18.     {
  19.     char remote[64], user[16], pass[16];
  20.     char buf[1024];
  21.     int i;
  22.  
  23.     if (passfile == NULL)
  24.         {
  25.         fprintf(stderr,"Posting is not allowed from this system.\n");
  26.         exit(1);
  27.         }
  28.  
  29.     while(fgets(buf, sizeof(buf), passfile))
  30.         {
  31.         if (buf[0] == '#')
  32.             continue;
  33.         
  34.         i = sscanf(buf,"%s %s %s", remote, user, pass);
  35.         /* malformed entry? */
  36.         if (i != 3)
  37.             {
  38.             fprintf(stderr,"Posting Authorization Denied. File format error.\n");
  39.             continue;
  40.             }
  41.         
  42.         /* right host? */
  43.         if (!strcasecmp(remote,host))
  44.             break;
  45.         }
  46.     if (feof(passfile))
  47.         {
  48.         fprintf(stderr,"Posting to %s is not allowed from this system\n", host);
  49.         exit(1);
  50.         }
  51.     
  52.     sprintf(buf,"authinfo user %s", user);
  53.     if (converse(buf, sizeof(buf)) != NEED_AUTHDATA)
  54.         {
  55.         fprintf(stderr,"%s\n", buf);
  56.         exit(1);
  57.         }
  58.     
  59.     sprintf(buf,"authinfo pass %s", pass);
  60.     if (converse(buf, sizeof(buf)) != OK_AUTH)
  61.         {
  62.         fprintf(stderr,"%s\n", buf);
  63.         exit(1);
  64.         }
  65.     
  66.     fclose(passfile);
  67.     }
  68.  
  69. int
  70. converse(buf,buflen)
  71. char *buf;
  72. int buflen;
  73.     {
  74.     put_server(buf);
  75.     get_server(buf,buflen);
  76.     return(atoi(buf));
  77.     }
  78. #endif AUTH
  79.