home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / FINGERD.C < prev    next >
C/C++ Source or Header  |  1994-07-17  |  5KB  |  200 lines

  1. /* Internet Finger server */
  2. #include "global.h"
  3. #ifdef FINGERSERVER
  4. #include "files.h"
  5. #include "mbuf.h"
  6. #include "socket.h"
  7. #include "session.h"
  8. #include "proc.h"
  9. #include "smtp.h"
  10. #include "dirutil.h"
  11. #include "commands.h"
  12. #include "mailbox.h"
  13.  
  14. #ifdef MAILFOR
  15. extern int dombmailfor __ARGS((int argc,char *argv[],void *p));
  16. #endif
  17.  
  18. static void fingerd __ARGS((int s,void *unused,void *p));
  19. #if defined SAMCALLB || QRZCALLB
  20. extern int cb_lookup __ARGS((int, char *, FILE *));
  21. #endif
  22.  
  23.  
  24. /* Start up finger service */
  25. int
  26. finstart(argc,argv,p)
  27. int argc;
  28. char *argv[];
  29. void *p;
  30. {
  31.     int16 port;
  32.  
  33.     if(argc < 2)
  34.         port = IPPORT_FINGER;
  35.     else
  36.         port = atoi(argv[1]);
  37.  
  38.     return start_tcp(port,"FINGER Server",fingerd,1024);
  39. }
  40.  
  41. int
  42. fin0(argc,argv,p)
  43. int argc;
  44. char *argv[];
  45. void *p;
  46. {
  47.     int16 port;
  48.  
  49.     if(argc < 2)
  50.         port = IPPORT_FINGER;
  51.     else
  52.         port = atoi(argv[1]);
  53.  
  54.     return stop_tcp(port);
  55. }
  56.  
  57. #define FLINE 128
  58.  
  59. struct finfo {
  60.     char *name;
  61.     int (*func) __ARGS((int argc,char *argv[],void *p));
  62. };
  63.  
  64. struct finfo Finfo[] = {
  65.     "iheard",   doipheard,
  66. #ifdef N2RJT_FINGERS
  67.     "aheard",   doaxheard,
  68. #endif /* N2RJT_FINGERS */
  69. #ifdef MAILBOX
  70.     "mstat",    dombmailstats,
  71. #ifdef N2RJT_FINGERS
  72.     "mpast", dombpast,
  73. #endif /* N2RJT_FINGERS */
  74. #endif
  75. #ifdef ALLCMD
  76.     "info",     doinfo,
  77. #endif
  78. #ifdef AX25
  79.     "ax25",     doaxstat,
  80. #ifdef MAILFOR
  81.     "mailfor",  dombmailfor,
  82. #endif // MAILFOR
  83. #endif // AX25
  84. #ifdef NETROM
  85.     "netrom",   donrstatus,
  86. #endif
  87.     "memstat",  dostat,
  88.     "socket",   dosock,
  89.     "tcpview",  doview,
  90.     "users",    dombstatus,
  91. #ifdef ASY
  92.     "asystat",  doasystat,
  93. #endif
  94. /* This gives a lot of info you might not want to be known - WG7J */
  95. /*    "ifconfig", doifconfig, */
  96. #ifdef RIP
  97.     "rip", doripstat,
  98. #endif
  99.     NULL,
  100. };
  101.  
  102. static void
  103. fingerd(s,unused,p)
  104. int s;
  105. void *unused;
  106. void *p;
  107. {
  108.     char user[80];
  109.     int ulen,found;
  110.     FILE *fp;
  111.     char *file,*cp;
  112.     struct finfo *fi;
  113.     int outsave;
  114.     char line[FLINE+1];
  115.  
  116.     sockmode(s,SOCK_ASCII);
  117.     sockowner(s,Curproc);
  118.     log(s,"open Finger");
  119.     recvline(s,user,80);
  120.     rip(user);
  121.     ulen = strlen(user);
  122.  
  123. #ifdef CONVERS
  124.     if(ulen && !strcmp(user,"conf"))
  125.         ShowConfUsers(s,0,NULL);
  126.     else if( ulen && !strcmp(user,"links"))
  127.         ShowConfLinks(s,1);
  128.     else {
  129. #endif
  130.         for(fi=Finfo;fi->name;fi++)
  131.             if(!stricmp(fi->name,user))
  132.                 break;
  133.         if(ulen && fi->name) {
  134.             outsave = Curproc->output;
  135.             Curproc->output = s;
  136.             fi->func(1,NULL,NULL);
  137.             Curproc->output = outsave;
  138.         } else {
  139.             if(ulen == 0){
  140.                 fp = dir(Fdir,0);
  141.                 if(fp == NULLFILE)
  142.                     usputs(s,"No finger information available\n");
  143.                 else
  144.                     usputs(s,"Known users on this system:\n");
  145.             } else {
  146. #ifdef USERLOG
  147.                 char *newargv[2];
  148.  
  149.                 outsave = Curproc->output;
  150.                 Curproc->output = s;
  151.                 newargv[1] = user;
  152.                 dombuserinfo(0,newargv,NULL);
  153.                 Curproc->output = outsave;
  154. #endif
  155. #if defined SAMCALLB || QRZCALLB
  156.                 cb_lookup (s, user, (FILE *) 0);
  157. #endif
  158.                 file = pathname(Fdir,user);
  159.                 cp = pathname(Fdir,"");
  160.             /* Check for attempted security violation (e.g., somebody
  161.              * might be trying to finger "../ftpusers"!)
  162.              */
  163.                 if(strncmp(file,cp,strlen(cp)) != 0){
  164.                     fp = NULLFILE;
  165.                     usprintf(s,"Invalid user name %s\n",user);
  166.                 } else if((fp = fopen(file,READ_TEXT)) == NULLFILE) {
  167.                 /* Now search the finger database file for this user - WG7J */
  168.                     found = 0;
  169.                     if((fp = fopen(Fdbase,READ_TEXT)) != NULLFILE) {
  170.                         while(fgets(line,FLINE,fp) != NULLCHAR)
  171.                             if(!strncmp(line,user,ulen)) {
  172.                                 usputs(s,line);
  173.                                 found = 1;
  174.                                 break;
  175.                             }
  176.                         fclose(fp);
  177.                         fp = NULLFILE;
  178.                     }
  179.                     if(!found)
  180.                         usprintf(s,"No user info for %s\n",user);
  181.                 }
  182.                 free(cp);
  183.                 free(file);
  184.             }
  185.             if(fp != NULLFILE){
  186.                 sendfile(fp,s,ASCII_TYPE,0,NULL);
  187.                 fclose(fp);
  188.             }
  189.         }
  190. #ifdef CONVERS
  191.     }
  192. #endif
  193.     if(ulen == 0 && Listusers != NULL)
  194.         (*Listusers)(s);
  195.     close_s(s);
  196.     log(s,"close Finger");
  197. }
  198.  
  199. #endif /* FINGERSERVER */
  200.