home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / cmpprot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-04  |  2.1 KB  |  79 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: cmpprot.c,v 1.4 1995/06/04 21:46:54 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    cmpprot.c
  7.  * Author:    T.E.Dickey
  8.  * Created:    03 Jul 1984 (broke out of 'dirent.c')
  9.  * Last update:
  10.  *        19 Feb 1995, sys utils prototypes
  11.  *        04 Nov 1988, undid last patch, fix by using unsigned type.
  12.  *        12 Nov 1985, limit uid-code to single byte for quick fix
  13.  *        01 Aug 1984, added calls to 'sysrights'
  14.  *
  15.  * Function:    Test the protection information for a file to see if the
  16.  *        current process may access the file.
  17.  *
  18.  * Parameters:    pr_    => GETPROT structure which contains the 16-bit mask
  19.  *               defining the protection of the file, and the owner's
  20.  *               group and member UIC-code.
  21.  *        mode    => string containing "r", "w", "e", "d" (lowercase) for
  22.  *               the corresponding READ, WRITE, EXECUTE and DELETE
  23.  *               rights which are required.
  24.  *
  25.  * Returns:    TRUE if all of the required rights are available.
  26.  *
  27.  * Note:    The C run-time routine 'access' cannot be used for this,
  28.  *        because it does not distinguish between delete-access and
  29.  *        write-access.
  30.  */
  31.  
  32. #include    <rms.h>
  33. #include    <prvdef.h>
  34. #include    <unixlib.h>    /* getuid/getgid */
  35.  
  36. #include    "bool.h"
  37. #include    "getprot.h"
  38.  
  39. #include    "sysutils.h"
  40.  
  41. #define    ACCESS(m)    (((mask << m) & pr_->p_mask) == 0)
  42.  
  43. int    cmpprot (
  44.     GETPROT    *pr_,        /* Data to test            */
  45.     char    *mode)        /* List of access rights needed    */
  46. {
  47. #define    PATCH    0xffff
  48.     unsigned
  49.     short    mask    = 0,        /* Start assuming nothing    */
  50.         grp    = PATCH & getgid(),    /* Group-id        */
  51.         mbm    = PATCH & getuid();    /* ...and member-id    */
  52.     char    *c_    = mode;
  53.  
  54.     if (sysrights(PRV$M_BYPASS,0))                return (TRUE);
  55.  
  56.     while (*c_)
  57.         switch (*c_++)
  58.         {
  59.         case 'r':    mask |= XAB$M_NOREAD;    break;
  60.         case 'w':    mask |= XAB$M_NOWRITE;    break;
  61.         case 'e':    mask |= XAB$M_NOEXE;    break;
  62.         case 'd':    mask |= XAB$M_NODEL;    break;
  63.         }
  64.  
  65.     if (ACCESS(XAB$V_WLD))                    return (TRUE);
  66.  
  67.     /*
  68.      * patch: Must verify if this is correct:
  69.      */
  70.     if (sysrights(PRV$M_SYSPRV,0) &&  ACCESS(XAB$V_SYS))    return (TRUE);
  71.  
  72.     if (grp == pr_->p_grp)
  73.     {
  74.         if (ACCESS(XAB$V_GRP))                return (TRUE);
  75.         if (mbm == pr_->p_mbm && ACCESS(XAB$V_OWN))    return (TRUE);
  76.     }
  77.     return (FALSE);
  78. }
  79.