home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / flistfrontend / src / getprot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-21  |  3.7 KB  |  154 lines

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: getprot.c,v 1.7 1995/10/21 19:00:38 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    getprot.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    02 Jul 1984
  9.  * Last update:
  10.  *        18 Mar 1995, prototypes
  11.  *        15 Jun 1985, CC2.0 changes declaration of uic-code.
  12.  *        14 Dec 1984, use single FAB for search, open.
  13.  *        11 Dec 1984, use ACP if on local node
  14.  *        09 Sep 1984, use "rmsinit"
  15.  *        03 Jul 1984
  16.  *
  17.  * Function:    Obtain protection code for a single file, or for a wildcarded
  18.  *        file specification.  If multiple files are selected, return
  19.  *        the worst-case (i.e., show the least common access provided
  20.  *        in the group).
  21.  *
  22.  * Parameters:    ret_    => the GETPROT structure to load.  GETPROT includes
  23.  *               a 16-bit mask representing the RWED modes in SYSTEM,
  24.  *               OWNER, GROUP and WORLD.  See SYS$LIBRARY:XAB.H for
  25.  *               a layout.  If any bit is set, the mode is disabled.
  26.  *               If an error is found in the lookup, "-1" is returned,
  27.  *               indicating no access.  The group and member codes
  28.  *               are returned in the high-order part of the return
  29.  *               value.  See "getprot.h" for the layout.
  30.  *        name_    => the specification to lookup and test.
  31.  *
  32.  * Returns:    If nonzero, the RMS-status indicating the first failure.
  33.  */
  34.  
  35. #include    <string.h>
  36.  
  37. #include    <starlet.h>
  38. #include    <rms.h>
  39. #include    <descrip.h>
  40. #include    <iodef.h>
  41. #include    <ssdef.h>
  42. #include    <stsdef.h>
  43.  
  44. #include    "acp.h"
  45.  
  46. #include    "bool.h"
  47. #include    "getprot.h"
  48. #include    "rmsinit.h"
  49. #include    "xabproui.h"
  50.  
  51. int    getprot (
  52.     GETPROT    *ret_,
  53.     char    *name_)            /* specifies files to lookup    */
  54. {
  55.     struct    FAB    fab;
  56.     struct    NAM    nam;            /* used in wildcard parsing    */
  57.  
  58.     struct    XABPRO    xabpro;            /* Protection attribute block    */
  59.  
  60.     char    rsa[NAM$C_MAXRSS],        /* resultant string area    */
  61.         esa[NAM$C_MAXRSS];        /* expanded string area (search)*/
  62.  
  63.     unsigned status;
  64.  
  65.     IOSB    iosb;
  66.     short    chnl;
  67.     FIB    fib;
  68.     ATR    atr[4];
  69.  
  70.     unsigned
  71.     short    mask,
  72.         uic_vec[2];
  73. #define    group    uic_vec[1]
  74. #define    member    uic_vec[0]
  75.  
  76.     static $DESCRIPTOR(DSC_name,"");
  77.     struct    dsc$descriptor    fibDSC;
  78.  
  79.     rmsinit_fab (&fab, &nam, 0, name_);
  80.     rmsinit_nam (&nam, rsa, esa);
  81.     xabpro        = cc$rms_xabpro;
  82.     fab.fab$l_xab    = (char *)&xabpro;
  83.  
  84.     mask = group = member = 0;    /* If 0, mask is ok    */
  85.  
  86.     if ((status = sys$parse(&fab)) == RMS$_NORMAL)
  87.     for (;;)
  88.     {
  89.         if ((status = sys$search(&fab)) == RMS$_NMF)
  90.         {
  91.             status    = 0;    /* normal return    */
  92.             break;
  93.         }
  94.         else if (status == RMS$_NORMAL)
  95.         {
  96.             if (nam.nam$l_fnb & NAM$M_NODE)    /* Via DECNET ?    */
  97.             {
  98.                 fab.fab$w_ifi = 0;
  99.                 if ((status = sys$open(&fab)) == RMS$_NORMAL)
  100.                 {
  101.                     mask    |= xabpro.xab$w_pro;
  102.                     xabprouic (&xabpro, &group, &member);
  103.                     sys$close(&fab);
  104.                 }
  105.                 else
  106.                     break;    /* ...no need to look more */
  107.             }
  108.             else
  109.             {
  110.                 DSC_name.dsc$a_pointer = rsa;
  111.                 DSC_name.dsc$w_length = nam.nam$b_rsl;
  112.                 status = sys$assign (&DSC_name, &chnl, 0, 0);
  113.  
  114.                 fibDSC.dsc$w_length = sizeof(FIB);
  115.                 fibDSC.dsc$a_pointer = (char *)&fib;
  116.                 memset (&fib, 0, sizeof(FIB));
  117.                 memcpy (fib.fib$w_fid, nam.nam$w_fid, 6);
  118.  
  119.                 memset (atr, 0, sizeof(atr));
  120.                 atr[0].atr$w_type = ATR$C_UIC;
  121.                 atr[0].atr$w_size = ATR$S_UIC;
  122.                 atr[0].atr$l_addr = (char *)uic_vec;
  123.  
  124.                 atr[1].atr$w_type = ATR$C_FPRO;
  125.                 atr[1].atr$w_size = ATR$S_FPRO;
  126.                 atr[1].atr$l_addr = (char *)&mask;
  127.  
  128.                 status = sys$qiow (
  129.                     0, chnl, IO$_ACCESS, &iosb, 0, 0,
  130.                     &fibDSC, 0,0,0, &atr[0],0);
  131.                 sys$dassgn (chnl);
  132.  
  133.                 if (! $VMS_STATUS_SUCCESS(status)
  134.                 ||    iosb.sts == SS$_NOPRIV)
  135.                     break;    /* Access will fail    */
  136.             }
  137.         }
  138.         else
  139.             break;    /* Any other error, give up    */
  140.     }
  141.  
  142.     if (status)
  143.     {
  144.         mask    = -1;    /* No access    */
  145.         group    =
  146.         member    = 0;    /* ...except by SYSTEM    */
  147.     }
  148.     ret_->p_mask = mask;
  149.     ret_->p_grp  = group;
  150.     ret_->p_mbm  = member;
  151.  
  152.     return (status);
  153. }
  154.