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 / server / group.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-31  |  2.4 KB  |  121 lines

  1. #ifndef lint
  2. static char    *sccsid = "@(#)group.c    1.12    (Berkeley) 5/11/89";
  3. #endif
  4.  
  5. #include "common.h"
  6.  
  7. #ifdef    XTHREAD
  8. extern char *thread_name();
  9. #endif
  10.  
  11. /*
  12.  * GROUP newsgroup
  13.  *
  14.  * Change the current group to the specified newsgroup.
  15.  * We also change our current directory to that newsgroup if
  16.  * a spool directory for it exists.
  17.  * If the newsgroup specified is invalid, the old newsgroup
  18.  * remains selected.
  19.  */
  20.  
  21. group(argc, argv)
  22.     int    argc;
  23.     char    *argv[];
  24. {
  25.     char    temp_dir[256];
  26.     int    high_msg, low_msg;
  27.     char    *cp;
  28.     char    *reqlist[2];
  29.  
  30.     if (argc != 2) {
  31.         printf("%d Usage: GROUP newsgroup.\r\n", ERR_CMDSYN);
  32.         (void) fflush(stdout);
  33.         return;
  34.     }
  35.  
  36.     if (!canread) {
  37.         printf("%d You only have permission to transfer, sorry.\r\n",
  38.             ERR_ACCESS);
  39.         (void) fflush(stdout);
  40.         return;
  41.     }
  42.  
  43.     if (index(argv[1], '/') != (char *) NULL) {
  44.         printf("%d Invalid group name (bad format).\r\n", ERR_NOGROUP);
  45.         (void) fflush(stdout);
  46.         return;
  47.     }
  48.  
  49.     if (find_group(argv[1], num_groups, &low_msg, &high_msg) < 0) {
  50.         printf("%d Invalid group name (not in active).\r\n",
  51.             ERR_NOGROUP);
  52.         (void) fflush(stdout);
  53.         return;
  54.     }
  55.  
  56.     reqlist[0] = argv[1];
  57.     reqlist[1] = NULL;
  58.  
  59.     if (ngpermcount) {
  60.         if (ngmatch(s1strneql, ALLBUT,
  61.             ngpermlist, ngpermcount, reqlist, 1) == 0) {
  62.             printf("%d You're not allowed to read %s, sorry.\r\n",
  63.                 ERR_ACCESS, argv[1]);
  64.             (void) fflush(stdout);
  65.             return;
  66.         }
  67.     } else if (ALLBUT == 0) {
  68.         printf("%d You're not allowed to read %s, sorry.\r\n",
  69.             ERR_ACCESS, argv[1]);
  70.         (void) fflush(stdout);
  71.         return;
  72.     }
  73.  
  74.     close_crnt();
  75.     (void) chdir(spooldir);
  76.  
  77. #ifdef LOG
  78.     syslog(LOG_INFO, "%s group %s", hostname, argv[1]);
  79. #endif
  80.  
  81.     while ((cp = index(argv[1], '.')) != (char *) NULL)
  82.         *cp = '/';
  83.  
  84.     (void) strcpy(temp_dir, spooldir);
  85.     (void) strcat(temp_dir, "/");
  86.     (void) strcat(temp_dir, argv[1]);
  87.  
  88.     /*
  89.      * (void) because a group can be in the active file
  90.      * but not have a spool directory.  Just leave us
  91.      * chdired to base spool directory if this fails.
  92.      */
  93.     (void) chdir(temp_dir);
  94.  
  95. #ifdef LOG
  96.     ++grps_acsd;
  97. #endif
  98.  
  99.     num_arts = scan_dir(low_msg, high_msg);
  100.     art_ptr = 0;
  101.  
  102.     ingroup = 1;
  103.  
  104. #ifdef    XTHREAD
  105.     threadfile = thread_name(argv[1]);
  106. #endif
  107.  
  108.     while ((cp = index(argv[1], '/')) != (char *) NULL)
  109.         *cp = '.';
  110.  
  111.     printf("%d %d %d %d %s\r\n",
  112.         OK_GROUP,
  113.         num_arts,
  114.         (num_arts > 0 ? art_array[0] : 0),
  115.         (num_arts > 0 ? art_array[num_arts-1] : 0),
  116.         argv[1]);
  117.     (void) fflush(stdout);
  118. }
  119.  
  120.  
  121.