home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / disks / tools / chmod / src / chmod.c
Encoding:
C/C++ Source or Header  |  1996-01-22  |  2.0 KB  |  85 lines

  1. #include <stdlib.h>
  2. #include <sys/types.h>
  3. #include <string.h>
  4.  
  5. #include <stdio.h>
  6. #include <proto/exec.h>
  7. #include <libraries/multiuser.h>
  8. #include <proto/multiuser.h>
  9. #include <dos/dos.h>
  10. #include <proto/dos.h>
  11. #include <clib/irmenlib_protos.h>
  12.  
  13. struct muBase *muBase;
  14.  
  15. int filepath(char *file,char *path);
  16. BOOL hookFunc(struct FileInfoBlock *FIB, char *fullName, short recurlevel);
  17.  
  18. char version[]="$VER: chmod 1.0 (06.01.96) ©Thomas Zander";
  19. ULONG bits=0;
  20. BOOL mufs=TRUE;
  21.  
  22. /// main
  23. void main(int argc,char* argv[])
  24. {
  25.     ULONG lang;
  26.     BOOL rec=FALSE;
  27.     if(*argv[1]=='?' || argc<2)
  28.     {
  29.         puts("Usage: chmod protection/a file\n\nprotection is a 4 digit hex number:\n The first digit stands for Amiga bits: Uspa\n The second digit stands for: rwed owner\n The third digit stands for: rwed group\n The fourth Digit stands for: rwed other\n\n");
  30.         return;
  31.     }
  32.     sscanf(argv[1],"%x",&lang);
  33.     if(lang>0xffff)
  34.     {
  35.         puts("4 digits would be enough");
  36.         return;
  37.     }
  38.     if(argc>3 && !stricmp(argv[3],"all"))
  39.         rec=TRUE;
  40.  
  41.  
  42.     if(!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))
  43.     {
  44.         mufs=FALSE;
  45.         puts("No friggin' multiuser.library");
  46.         return;
  47.     }
  48.  
  49.     // lang is dan 1234; 1:extra 2:not(standaard) 3:group 4: otr
  50.     // moet worden 4312 met 2 geinverteerd.
  51.  
  52.     // not op standaard.
  53.     lang=lang^0x0F00;
  54.  
  55.     bits=lang>>8;
  56.     lang=lang<<4;
  57.     bits=bits | (lang & 0x0F00);
  58.     lang=lang<<8;
  59.     bits=bits | (lang & 0xF000);
  60.     if(bits & 0x0080)
  61.         bits^=0x80000080;
  62.     DirScan(argv[2],rec,hookFunc);
  63. }
  64. ///
  65.  
  66. /// hookFunc
  67. BOOL hookFunc(struct FileInfoBlock *FIB, char *fullName, short recurlevel)
  68. {
  69.     char error[128];
  70.     if (mufs=TRUE)
  71.         if (muSetProtection(fullName,bits)==NULL) // unprotect if MuFS.
  72.         {
  73.             Fault(IoErr(),fullName,error,128);
  74.             puts(error);
  75.         }
  76.     else
  77.         if(SetProtection(fullName,bits)==NULL)  // Proctect if != MuFS.
  78.         {
  79.             Fault(IoErr(),fullName,error,128);
  80.             puts(error);
  81.         }
  82.     return(TRUE);
  83. }
  84. ///
  85.