home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NNTP-1.000 / NNTP-1 / nntp.1.5.11t / xmit / xmitauth.c < prev   
Encoding:
C/C++ Source or Header  |  1993-10-17  |  1.2 KB  |  79 lines

  1. #ifndef lint
  2. static char *rcsid = "$Header: xmitauth.c,v 1.2 90/07/08 01:03:23 sob Exp $";
  3. #endif
  4. #include <stdio.h>
  5. #include "../common/conf.h"
  6. #include "../common/nntp.h"
  7. #include "nntpxmit.h"
  8.  
  9. #ifdef AUTH
  10.  
  11. extern char Debug;
  12. extern int converse();
  13.  
  14. FILE *sys;
  15.  
  16. xmitauth(host)
  17. char *host;
  18.     {
  19.     char remote[64], user[16], pass[16];
  20.     char buf[1024];
  21.     int i;
  22.     char savedebug;
  23.  
  24.     sys = fopen(PASSFILE, "r");
  25.     if (sys == NULL)
  26.         {
  27.         exit(1);
  28.         }
  29.     
  30.     while(fgets(buf, sizeof(buf), sys))
  31.         {
  32.         if (buf[0] == '#')
  33.             continue;
  34.         
  35.         i = sscanf(buf,"%s %s %s", remote, user, pass);
  36.         /* malformed entry? */
  37.         if (i != 3)
  38.             {
  39.             log(L_NOTICE,"malformed entry in nntp.sys");
  40.             continue;
  41.             }
  42.         
  43.         /* right host? */
  44.         if (!strcasecmp(remote,host))
  45.             break;
  46.         }
  47.     if (feof(sys))
  48.         {
  49.         sprintf(buf,"host %s authinfo not in nntp.sys", host);
  50.         log(L_NOTICE, buf);
  51.         exit(1);
  52.         }
  53.     
  54.     sprintf(buf,"authinfo user %s", user);
  55.     if (converse(buf, sizeof(buf)) != NEED_AUTHDATA)
  56.         {
  57.         log(L_NOTICE, buf);
  58.         exit(1);
  59.         }
  60.     
  61.     /* don't display the password even if debug is on */
  62.     savedebug = Debug;
  63.     Debug = FALSE;
  64.  
  65.     sprintf(buf,"authinfo pass %s", pass);
  66.     if (converse(buf, sizeof(buf)) != OK_AUTH)
  67.         {
  68.         log(L_NOTICE, buf);
  69.         exit(1);
  70.         }
  71.     
  72.     Debug = savedebug;
  73.  
  74.     fclose(sys);
  75.     }
  76.  
  77. #endif AUTH
  78.  
  79.