home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / uucp / Uucp.framework / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-20  |  4.4 KB  |  185 lines

  1. /* util.c
  2.    A couple of UUCP utility functions.
  3.  
  4.    Copyright (C) 1991, 1992, 1993 Ian Lance Taylor
  5.  
  6.    This file is part of the Taylor UUCP package.
  7.  
  8.    This program is free software; you can redistribute it and/or
  9.    modify it under the terms of the GNU General Public License as
  10.    published by the Free Software Foundation; either version 2 of the
  11.    License, or (at your option) any later version.
  12.  
  13.    This program is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with this program; if not, write to the Free Software
  20.    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  21.  
  22.    The author of the program may be contacted at ian@airs.com or
  23.    c/o Cygnus Support, 48 Grove Street, Somerville, MA 02144.
  24.    */
  25.  
  26. #include "uucp.h"
  27.  
  28. #if USE_RCS_ID
  29. const char util_rcsid[] = "$Id: util.c,v 1.8 1995/06/21 19:16:18 ian Rel $";
  30. #endif
  31.  
  32. #include <ctype.h>
  33.  
  34. #include "uudefs.h"
  35. #include "uuconf.h"
  36. #include "system.h"
  37.  
  38. /* Get information for an unknown system.  This will leave the name
  39.    allocated on the heap.  We could fix this by breaking the
  40.    abstraction and adding the name to qsys->palloc.  It makes sure the
  41.    name is not too long, but takes no other useful action.  */
  42.  
  43. boolean
  44. funknown_system (puuconf, zsystem, qsys)
  45.      pointer puuconf;
  46.      const char *zsystem;
  47.      struct uuconf_system *qsys;
  48. {
  49.   char *z;
  50.   int iuuconf;
  51.  
  52.   if (strlen (zsystem) <= cSysdep_max_name_len)
  53.     z = zbufcpy (zsystem);
  54.   else
  55.     {
  56.       char **pznames, **pz;
  57.       boolean ffound;
  58.  
  59.       z = zbufalc (cSysdep_max_name_len + 1);
  60.       memcpy (z, zsystem, cSysdep_max_name_len);
  61.       z[cSysdep_max_name_len] = '\0';
  62.  
  63.       iuuconf = uuconf_system_names (puuconf, &pznames, TRUE);
  64.       if (iuuconf != UUCONF_SUCCESS)
  65.     ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
  66.  
  67.       ffound = FALSE;
  68.       for (pz = pznames; *pz != NULL; pz++)
  69.     {
  70.       if (strcmp (*pz, z) == 0)
  71.         ffound = TRUE;
  72.       xfree ((pointer) *pz);
  73.     }
  74.       xfree ((pointer) pznames);
  75.  
  76.       if (ffound)
  77.     {
  78.       ubuffree (z);
  79.       return FALSE;
  80.     }
  81.     }
  82.  
  83.   iuuconf = uuconf_system_unknown (puuconf, qsys);
  84.   if (iuuconf == UUCONF_NOT_FOUND)
  85.     {
  86.       ubuffree (z);
  87.       return FALSE;
  88.     }
  89.   else if (iuuconf != UUCONF_SUCCESS)
  90.     ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
  91.  
  92.   for (; qsys != NULL; qsys = qsys->uuconf_qalternate)
  93.     qsys->uuconf_zname = z;
  94.  
  95.   return TRUE;
  96. }
  97.  
  98. /* Remove all occurrences of the local system name followed by an
  99.    exclamation point from the front of a string, returning the new
  100.    string.  This is used by uucp and uux.  */
  101.  
  102. char *
  103. zremove_local_sys (qlocalsys, z)
  104.      struct uuconf_system *qlocalsys;
  105.      char *z;
  106. {
  107.   size_t clen;
  108.   char *zexclam;
  109.  
  110.   clen = strlen (qlocalsys->uuconf_zname);
  111.   zexclam = strchr (z, '!');
  112.   while (zexclam != NULL)
  113.     {
  114.       if (z == zexclam
  115.       || (zexclam - z == clen
  116.           && strncmp (z, qlocalsys->uuconf_zname, clen) == 0))
  117.     ;
  118.       else if (qlocalsys->uuconf_pzalias == NULL)
  119.     break;
  120.       else
  121.     {
  122.       char **pzal;
  123.  
  124.       for (pzal = qlocalsys->uuconf_pzalias; *pzal != NULL; pzal++)
  125.         if (strlen (*pzal) == zexclam - z
  126.         && strncmp (z, *pzal, (size_t) (zexclam - z)) == 0)
  127.           break;
  128.       if (*pzal == NULL)
  129.         break;
  130.     }
  131.       z = zexclam + 1;
  132.       zexclam = strchr (z, '!');
  133.     }
  134.  
  135.   return z;
  136. }
  137.  
  138. /* See whether a file is in a directory list, and make sure the user
  139.    has appropriate access.  */
  140.  
  141. boolean
  142. fin_directory_list (zfile, pzdirs, zpubdir, fcheck, freadable, zuser)
  143.      const char *zfile;
  144.      char **pzdirs;
  145.      const char *zpubdir;
  146.      boolean fcheck;
  147.      boolean freadable;
  148.      const char *zuser;
  149. {
  150.   boolean fmatch;
  151.   char **pz;
  152.  
  153.   fmatch = FALSE;
  154.  
  155.   for (pz = pzdirs; *pz != NULL; pz++)
  156.     {
  157.       char *zuse;
  158.  
  159.       if (pz[0][0] == '!')
  160.     {
  161.       zuse = zsysdep_local_file (*pz + 1, zpubdir, (boolean *) NULL);
  162.       if (zuse == NULL)
  163.         return FALSE;
  164.  
  165.       if (fsysdep_in_directory (zfile, zuse, FALSE,
  166.                     FALSE, (const char *) NULL))
  167.         fmatch = FALSE;
  168.     }
  169.       else
  170.     {
  171.       zuse = zsysdep_local_file (*pz, zpubdir, (boolean *) NULL);
  172.       if (zuse == NULL)
  173.         return FALSE;
  174.  
  175.       if (fsysdep_in_directory (zfile, zuse, fcheck,
  176.                     freadable, zuser))
  177.         fmatch = TRUE;
  178.     }
  179.  
  180.       ubuffree (zuse);
  181.     }
  182.  
  183.   return fmatch;
  184. }
  185.