home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d09xx / d0905.lha / MultiUser / C.src / SetDefProtect.c < prev    next >
C/C++ Source or Header  |  1993-08-26  |  4KB  |  169 lines

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Set the Default Protection Bits                                    *
  5. * ---------------------------------------------------------    *
  6. * ⌐ Copyright 1993 by Geert Uytterhoeven                            *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <dos/dos.h>
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15. #include <utility/tagitem.h>
  16. #include <libraries/multiuser.h>
  17. #include <proto/multiuser.h>
  18.  
  19. #include "SetDefProtect_rev.h"
  20.  
  21.  
  22. char __VersTag__[] = VERSTAG;
  23.  
  24.  
  25. #define FLAGS_OWNER    1
  26. #define FLAGS_GROUP    2
  27. #define FLAGS_OTHER    3
  28.  
  29.  
  30. BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type, struct DosLibrary *DOSBase);
  31.  
  32.  
  33. int __saveds Start(char *arg)
  34. {
  35.     struct ExecBase *SysBase;
  36.     struct DosLibrary *DOSBase;
  37.     struct muBase *muBase = NULL;
  38.     struct RDArgs *args;
  39.     LONG argarray[] = {
  40.         NULL, NULL, NULL, NULL
  41.     };
  42.     ULONG flags = NULL;
  43.     int rc = RETURN_ERROR;
  44.     struct TagItem tags[3];
  45.  
  46.     SysBase = *(struct ExecBase **)4;
  47.  
  48.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  49.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))) {
  50.         rc = RETURN_FAIL;
  51.         goto Exit;
  52.     }
  53.  
  54.     args = ReadArgs("FLAGS,GROUP/K,OTHER/K,GLOBAL/S", argarray, NULL);
  55.     if (!args)
  56.         PrintFault(IoErr(), NULL);
  57.     else if (!((argarray[0] && !ProcessFlags((char *)argarray[0], &flags,
  58.                                                           FLAGS_OWNER, DOSBase)) ||
  59.                   (argarray[1] && !ProcessFlags((char *)argarray[1], &flags,
  60.                                                           FLAGS_GROUP, DOSBase)) ||
  61.                   (argarray[2] && !ProcessFlags((char *)argarray[2], &flags,
  62.                                                           FLAGS_OTHER, DOSBase)))) {
  63.         flags ^= FIBF_READ|FIBF_WRITE|FIBF_EXECUTE|FIBF_DELETE;
  64.         tags[0].ti_Tag = muT_DefProtection;
  65.         tags[0].ti_Data = (LONG)flags;
  66.         tags[1].ti_Tag = muT_Global;
  67.         tags[1].ti_Data = (BOOL)argarray[3];
  68.         tags[2].ti_Tag = TAG_DONE;
  69.         if (muSetDefProtectionA(tags))
  70.             rc = RETURN_OK;
  71.         else
  72.             PutStr("SetDefProtect failed\n");
  73.     }
  74.     FreeArgs(args);
  75.  
  76. Exit:
  77.     CloseLibrary((struct Library *)muBase);
  78.     CloseLibrary((struct Library *)DOSBase);
  79.  
  80.     return(rc);
  81. }
  82.  
  83.  
  84. BOOL __regargs ProcessFlags(char *str, ULONG *flags, ULONG type, struct DosLibrary *DOSBase)
  85. {
  86.     int i;
  87.     BOOL rc = TRUE;
  88.  
  89.     for (i = 0; str[i] && rc; i++) {
  90.         switch(str[i]) {
  91.             case 's':
  92.             case 'S':
  93.                 if (type == FLAGS_OWNER)
  94.                     *flags |= FIBF_SCRIPT;
  95.                 else
  96.                     goto Error;
  97.                 break;
  98.  
  99.             case 'p':
  100.             case 'P':
  101.                 if (type == FLAGS_OWNER)
  102.                     *flags |= FIBF_PURE;
  103.                 else
  104.                     goto Error;
  105.                 break;
  106.  
  107.             case 'a':
  108.             case 'A':
  109.                 if (type == FLAGS_OWNER)
  110.                     *flags |= FIBF_ARCHIVE;
  111.                 else
  112.                     goto Error;
  113.                 break;
  114.  
  115.             case 'r':
  116.             case 'R':
  117.                 if (type == FLAGS_OWNER)
  118.                     *flags |= FIBF_READ;
  119.                 else if (type == FLAGS_GROUP)
  120.                     *flags |= FIBF_GRP_READ;
  121.                 else
  122.                     *flags |= FIBF_OTR_READ;
  123.                 break;
  124.  
  125.             case 'w':
  126.             case 'W':
  127.                 if (type == FLAGS_OWNER)
  128.                     *flags |= FIBF_WRITE;
  129.                 else if (type == FLAGS_GROUP)
  130.                     *flags |= FIBF_GRP_WRITE;
  131.                 else
  132.                     *flags |= FIBF_OTR_WRITE;
  133.                 break;
  134.  
  135.             case 'e':
  136.             case 'E':
  137.                 if (type == FLAGS_OWNER)
  138.                     *flags |= FIBF_EXECUTE;
  139.                 else if (type == FLAGS_GROUP)
  140.                     *flags |= FIBF_GRP_EXECUTE;
  141.                 else
  142.                     *flags |= FIBF_OTR_EXECUTE;
  143.                 break;
  144.  
  145.             case 'd':
  146.             case 'D':
  147.                 if (type == FLAGS_OWNER)
  148.                     *flags |= FIBF_DELETE;
  149.                 else if (type == FLAGS_GROUP)
  150.                     *flags |= FIBF_GRP_DELETE;
  151.                 else
  152.                     *flags |= FIBF_OTR_DELETE;
  153.                 break;
  154.  
  155.             default:
  156.             Error:
  157.                 rc = FALSE;
  158.                 PutStr("Invalid flag - must be one of ");
  159.                 if (type == FLAGS_OWNER)
  160.                     PutStr("SPARWED\n");
  161.                 else
  162.                     PutStr("RWED\n");
  163.                 break;
  164.         }
  165.     }
  166.  
  167.     return(rc);
  168. }
  169.