home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / dirprot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-19  |  1.5 KB  |  66 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: dirprot.c,v 1.4 1995/02/19 18:23:39 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    dirprot.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    10 Jul 1984
  9.  * Last update:
  10.  *        19 Feb 1995, prototyped
  11.  *        25 Aug 1984, cleanup buffer sizes
  12.  *
  13.  * Function:    This procedure is used by FLIST to check access rights of
  14.  *        a list of files, specified in a DCLARG-list.  For example,
  15.  *        to print a list of files, they must all be readable.  This
  16.  *        code uses 'getprot' to perform wildcard (worst-case) testing.
  17.  *
  18.  * Parameters:    cmd_    => original command text (for nicer messages).
  19.  *        d_    => DCLARG-list to test. (Options are ignored.)
  20.  *        mfld    =  parameter number to test (e.g., 1=input, 2=output)
  21.  *        mode_    => String of modes to test (lowercase "rwed", any order).
  22.  *
  23.  * Returns:    TRUE if all accesses are permitted.  If not, a warning message
  24.  *        is generated.
  25.  */
  26.  
  27. #include    <stdio.h>
  28.  
  29. #include    "flist.h"
  30. #include    "dclarg.h"
  31. #include    "getprot.h"
  32.  
  33. dirprot (cmd_, d_, mfld, mode_)
  34. char    *cmd_;
  35. DCLARG    *d_;
  36. int    mfld;
  37. char    *mode_;
  38. {
  39. GETPROT    tstval;
  40. char    *failed    = 0;
  41.  
  42. static
  43. char    sFMT1[]    = "File(s) not found: %%.%ds",
  44.     sFMT2[]    = "No access: %%.%ds (%%s needed)";
  45. char    format[sizeof(sFMT2)+6];
  46.  
  47.     for (; d_; d_ = d_->dcl_next)
  48.     {
  49.         if (isopt (d_->dcl_text[0]))    continue;
  50.         else if (d_->dcl_mfld != mfld)    continue;
  51.  
  52.         if (getprot (&tstval, d_->dcl_text))
  53.             failed = sFMT1;
  54.         else if (! cmpprot (&tstval, mode_))
  55.             failed = sFMT2;
  56.  
  57.         if (failed)
  58.         {
  59.             sprintf (format, failed, d_->dcl_size);
  60.             warn (format, &cmd_[d_->dcl_from], mode_);
  61.             return (FALSE);
  62.         }
  63.     }
  64.     return (TRUE);
  65. }
  66.