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

  1. #ifndef NO_IDENT
  2. static char *Id = "$Id: chprot.c,v 1.7 1995/10/21 19:00:38 tom Exp $";
  3. #endif
  4.  
  5. /*
  6.  * Title:    chprot.c
  7.  * Author:    Thomas E. Dickey
  8.  * Created:    19 Nov 1984
  9.  * Last update:
  10.  *        18 Mar 1995, standardized memory copy/set.
  11.  *        21 Dec 1984, return status-code from I/O status-block.
  12.  *
  13.  * Function:    This procedure uses the ACP to alter the protection code of
  14.  *        one or more VAX/VMS disk files.
  15.  *
  16.  * Arguments:    filespec - address of a file specification, optionally with
  17.  *            wildcards.  Each matching file is altered.
  18.  *        code    - 16-bit VMS file protection code (see XAB.H).  It is
  19.  *              arranged from LSB to MSB: SYSTEM, OWNER, GROUP,
  20.  *              WORLD; within fields NOREAD, NOWRITE, NOEXEC, and
  21.  *              NODELETE.
  22.  *        mask    - 16-bit mask, selecting fields in 'code' to disable.
  23.  *              If zero, we need not read the file's protection
  24.  *              before altering it.
  25.  *
  26.  * Returns:    The first error status found.  (The procedure halts on the
  27.  *        first error.)
  28.  */
  29.  
  30. #include    <starlet.h>
  31. #include    <rms.h>
  32. #include    <descrip.h>
  33. #include    <iodef.h>
  34. #include    <stsdef.h>
  35. #include    <string.h>
  36.  
  37. #include    "bool.h"
  38. #include    "acp.h"
  39. #include    "rmsinit.h"
  40.  
  41. #include    "chprot.h"
  42.  
  43. #define    sys(f)    status = f; if (! $VMS_STATUS_SUCCESS(status))
  44. #define    QIO(func) sys$qiow (0, chnl, func, &iosb, 0, 0,\
  45.             &fibDSC, 0,0,0, &atr[0],0)
  46.  
  47. int
  48. chprot (
  49.     char    *filespec,        /* specifies files to lookup    */
  50.     int    code,
  51.     int    mask)
  52. {
  53.     struct    FAB    fab;
  54.     struct    NAM    nam;        /* used in wildcard parsing    */
  55.  
  56.     char    rsa[NAM$C_MAXRSS],    /* resultant string area    */
  57.         esa[NAM$C_MAXRSS];    /* expanded string area        */
  58.  
  59.     unsigned status;
  60.     IOSB    iosb;
  61.     short    chnl;
  62.     FIB    fib;
  63.     ATR    atr[2];
  64.     short    short_fpro;
  65.  
  66.     $DESCRIPTOR(DSC_name,"");
  67.     struct    dsc$descriptor    fibDSC;
  68.  
  69.     rmsinit_fab (&fab, &nam, nullC, filespec);
  70.     rmsinit_nam (&nam, esa, rsa);
  71.  
  72.     sys(sys$parse(&fab))            return (status);
  73.  
  74.     for (;;)
  75.     {
  76.         sys(sys$search(&fab))
  77.         {
  78.             if (status == RMS$_NMF)
  79.                 status = 0;
  80.             return (status);
  81.         }
  82.  
  83.         DSC_name.dsc$a_pointer = nam.nam$l_rsa;
  84.         DSC_name.dsc$w_length = nam.nam$b_rsl;
  85.  
  86.         fibDSC.dsc$w_length = sizeof(FIB);
  87.         fibDSC.dsc$a_pointer = (char *)&fib;
  88.         memset (&fib, 0, sizeof(fib));
  89.         fib.fib$l_acctl = FIB$M_WRITECK;
  90.         memcpy (fib.fib$w_fid, nam.nam$w_fid, 6);
  91.  
  92.         atr[0].atr$w_type = ATR$C_FPRO;
  93.         atr[0].atr$w_size = ATR$S_FPRO;
  94.         atr[0].atr$l_addr = (char *)&short_fpro;
  95.         atr[1].atr$w_size = atr[1].atr$w_type = 0;
  96.  
  97.         sys(sys$assign(&DSC_name, &chnl, 0, 0))    return (status);
  98.  
  99.         if (mask)
  100.         {
  101.             sys(QIO(IO$_ACCESS))        goto no_access;
  102.             sys(iosb.sts)            goto no_access;
  103.             short_fpro = (short_fpro & mask)
  104.                    | (code & ~mask);
  105.         }
  106.         else
  107.         {
  108.             short_fpro = code;
  109.         }
  110.  
  111.         sys(QIO(IO$_MODIFY))            goto no_access;
  112.         sys(iosb.sts)                goto no_access;
  113.         sys(sys$dassgn (chnl))            return (status);
  114.     }
  115.  
  116. no_access:
  117.     sys$dassgn (chnl);    /* Try to cleanup if error found */
  118.     return (status);
  119. }
  120.