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

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Set the owner of a file - AmigaOS 3.0 (V39+) version        *
  5. * ---------------------------------------------------------    *
  6. * ⌐ Copyright 1993 by Geert Uytterhoeven                            *
  7. * All Rights Reserved.                                                    *
  8. ************************************************************/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <dos/dos.h>
  14. #include <dos/dosasl.h>
  15. #include <proto/exec.h>
  16. #include <proto/dos.h>
  17. #include <string.h>
  18. #include <libraries/multiuser.h>
  19. #include <proto/multiuser.h>
  20.  
  21. #include "SetOwner_rev.h"
  22.  
  23.  
  24. char __VersTag__[] = VERSTAG;
  25.  
  26.  
  27. int __saveds Start(char *arg)
  28. {
  29.     struct ExecBase *SysBase;
  30.     struct DosLibrary *DOSBase;
  31.     struct muBase *muBase = NULL;
  32.     struct RDArgs *args;
  33.     LONG argarray[] = {
  34.         NULL, NULL, NULL, NULL, NULL
  35.     };
  36.     ULONG User = NULL;
  37.     struct muUserInfo *info;
  38.     struct AnchorPath *anchor;
  39.     int rc = RETURN_OK;
  40.     LONG error = NULL;
  41.     BPTR dir;
  42.  
  43.     SysBase = *(struct ExecBase **)4;
  44.     
  45.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 39))) ||
  46.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))) {
  47.         rc = RETURN_FAIL;
  48.         goto Exit;
  49.     }
  50.  
  51.     args = ReadArgs("FILE/A,USER,NOBODY/S,ALL/S,QUIET/S", argarray, NULL);
  52.     if (!args)
  53.         error = IoErr();
  54.     else if (argarray[1] && argarray[2]) {
  55.         PutStr("Invalid options\n");
  56.         rc = RETURN_ERROR;
  57.     } else {
  58.         if (argarray[1]) {
  59.             if (info = muAllocUserInfo()) {
  60.                 strncpy(info->UserID, (char *)argarray[1], muUSERIDSIZE);
  61.                 if (muGetUserInfo(info, muKeyType_UserID)) {
  62.                     User = (info->uid<<16)|info->gid;
  63.                 }
  64.                 muFreeUserInfo(info);
  65.             }
  66.             if (!User) {
  67.                 VPrintf("Unknown User '%s'\n", &argarray[1]);
  68.                 rc = RETURN_ERROR;
  69.             }
  70.         } else if (!argarray[2])
  71.             User = muGetTaskOwner(NULL);
  72.         if (!rc)
  73.             if (anchor = (struct AnchorPath *)AllocVec(sizeof(struct AnchorPath)+1024,
  74.                                                                      MEMF_CLEAR)) {
  75.                 anchor->ap_BreakBits = SIGBREAKF_CTRL_C;
  76.                 anchor->ap_Flags = APF_DOWILD;
  77.                 anchor->ap_Strlen = 1024;
  78.                 if (!(error = MatchFirst((char *)argarray[0], anchor))) {
  79.                     do
  80.                         if (anchor->ap_Flags & APF_DIDDIR)
  81.                             anchor->ap_Flags &= ~APF_DIDDIR;
  82.                         else {
  83.                             if (argarray[3] && (anchor->ap_Info.fib_DirEntryType > 0))
  84.                                 anchor->ap_Flags |= APF_DODIR;
  85.                             dir = CurrentDir(DupLock(anchor->ap_Last->an_Lock));
  86.                             if (!SetOwner(anchor->ap_Info.fib_FileName, User)) {
  87.                                 PutStr(anchor->ap_Buf);
  88.                                 PrintFault(IoErr(), " ");
  89.                             } else if (!argarray[4]) {
  90.                                 PutStr(anchor->ap_Buf);
  91.                                 if (anchor->ap_Info.fib_DirEntryType > 0)
  92.                                     PutStr(" (dir)");
  93.                                 PutStr("...Done\n");
  94.                             }
  95.                             UnLock(CurrentDir(dir));
  96.                         }
  97.                     while (!(error = MatchNext(anchor)));
  98.                     if (error == ERROR_NO_MORE_ENTRIES)
  99.                         error = NULL;
  100.                 } else if (error == ERROR_NO_MORE_ENTRIES)
  101.                     error = ERROR_OBJECT_NOT_FOUND;
  102.                 MatchEnd(anchor);
  103.                 FreeVec(anchor);
  104.             } else
  105.                 error = IoErr();
  106.     }
  107.     FreeArgs(args);
  108.     if (error) {
  109.         PrintFault(error, NULL);
  110.         rc = RETURN_ERROR;
  111.     }
  112.  
  113. Exit:
  114.     CloseLibrary((struct Library *)muBase);
  115.     CloseLibrary((struct Library *)DOSBase);
  116.  
  117.     return(rc);
  118. }
  119.