home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / MUser17src.lha / MultiUser / src / Library / Protection.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-07  |  2.4 KB  |  108 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Protection Bits Management                                            *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 Geert Uytterhoeven                        *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/execbase.h>
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14.  
  15. #include "Protection.h"
  16. #include "Misc.h"
  17. #include "Task.h"
  18. #include "Config.h"
  19. #include "LibHeader.h"
  20.  
  21.  
  22.     /*
  23.      *        Set the Default Protection Bits
  24.      *
  25.      *        Public Library Function
  26.      */
  27.  
  28. BOOL __asm __saveds muSetDefProtectionA(register __a0 struct TagItem *taglist)
  29. {
  30.     struct muTags tags;
  31.  
  32.     if (!InterpreteTagList(taglist, &tags))
  33.         return(FALSE);
  34.     if (tags.Global)
  35.         return(SetLevelDefProtect(tags.Task, tags.DefProtection));
  36.     else
  37.         return(SetTaskDefProtect(tags.Task, tags.DefProtection));
  38. }
  39.  
  40.  
  41.     /*
  42.      *        Get the Default Protection Bits
  43.      *
  44.      *        Public Library Function
  45.      */
  46.  
  47. ULONG __asm __saveds muGetDefProtection(register __d0 struct Task *task)
  48. {
  49.     if (!task)
  50.         task = SysBase->ThisTask;
  51.     return(GetTaskDefProtect(task));
  52. }
  53.  
  54.  
  55.     /*
  56.      *        Set the protection bits for a file or directory
  57.      *
  58.      *        Public Library Function
  59.      */
  60.  
  61. BOOL __asm __saveds muSetProtection(register __d1 STRPTR name,
  62.                                                 register __d2 LONG mask,
  63.                                                 register __a6 struct muBase *muBase)
  64. {
  65.     return(muBase->OLDSetProtection(name, mask, DOSBase));
  66. }
  67.  
  68.  
  69.     /*
  70.      *        Disallow setting the full protection bits
  71.      *
  72.      *        Public Library Function
  73.      */
  74.  
  75. BOOL __asm muLimitDOSSetProtection(register __d0 BOOL flag,
  76.                                               register __a6 struct muBase *muBase)
  77. {
  78.     if (flag)
  79.         muBase->Config.Flags |= muCFGF_LimitDOSSetProtection;
  80.     else
  81.         muBase->Config.Flags &= ~muCFGF_LimitDOSSetProtection;
  82.     return(TRUE);
  83. }
  84.  
  85.  
  86.     /*
  87.      *        Replacement for the dos.library SetProtection() function
  88.      */
  89.  
  90. BOOL __asm __saveds NEWSetProtection(register __d1 STRPTR name,
  91.                                                  register __d2 LONG mask,
  92.                                                  register __a6 struct DosLibrary *dosbase)
  93. {
  94.     BPTR fl;
  95.     struct FileInfoBlock *fib;
  96.  
  97.     if ((muBase->Config.Flags & muCFGF_LimitDOSSetProtection) &&
  98.          (fl = Lock(name, ACCESS_READ))) {
  99.         if (fib = AllocDosObject(DOS_FIB, NULL)) {
  100.             if (Examine(fl, fib))
  101.                 mask = (mask&0x000000ff)|(fib->fib_Protection&0xffffff00);
  102.             FreeDosObject(DOS_FIB, fib);
  103.         }
  104.         UnLock(fl);
  105.     }
  106.     return(muBase->OLDSetProtection(name, mask, dosbase));
  107. }
  108.