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

  1. /************************************************************
  2. * MultiUser - MultiUser Task/File Support System                *
  3. * ---------------------------------------------------------    *
  4. * Login                                                                        *
  5. * ---------------------------------------------------------    *
  6. * © Copyright 1993-1994 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 "Login_rev.h"
  20.  
  21.  
  22. char __VersTag__[] = VERSTAG;
  23.  
  24.  
  25. int __saveds Start(char *arg)
  26. {
  27.     struct ExecBase *SysBase;
  28.     struct DosLibrary *DOSBase;
  29.     struct muBase *muBase = NULL;
  30.     struct RDArgs *args;
  31.     LONG argarray[] = {
  32. #define argUSERID        0
  33. #define argGUI            1
  34. #define argTASK        2
  35. #define argOWN            3
  36. #define argGLOBAL        4
  37. #define argPROCESS    5
  38.         NULL, NULL, NULL, NULL, NULL, NULL
  39.     };
  40.     struct TagItem tags[6];
  41.     struct Task *task = NULL;
  42.     int rc = RETURN_ERROR;
  43.  
  44.     SysBase = *(struct ExecBase **)4;
  45.  
  46.     if ((!(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 37))) ||
  47.          (!(muBase = (struct muBase *)OpenLibrary("multiuser.library", 39)))) {
  48.         rc = ERROR_INVALID_RESIDENT_LIBRARY;
  49.         goto Exit;
  50.     }
  51.  
  52.     args = ReadArgs("USERID,GUI/S,TASK/K,OWN/S,GLOBAL/S,PROCESS/K/N", argarray,
  53.                          NULL);
  54.     if (!args)
  55.         PrintFault(IoErr(), NULL);
  56.     else if (argarray[argTASK] && argarray[argPROCESS])
  57.         PutStr("You can't specify both TASK and PROCESS\n");
  58.     else if (argarray[argUSERID] && argarray[argOWN])
  59.         PutStr("You can't specify both USERID and OWN\n");
  60.     else if (argarray[argTASK] && !(task = FindTask((char *)argarray[argTASK])))
  61.         VPrintf("Couldn't find task '%s'\n", (ULONG *)&argarray[argTASK]);
  62.     else if (argarray[argPROCESS] &&
  63.                 !(task = (struct Task *)FindCliProc((ULONG)*(ULONG *)argarray[argPROCESS])))
  64.         VPrintf("Couldn't find process %ld\n", (ULONG *)argarray[argPROCESS]);
  65.     else {
  66.         tags[0].ti_Tag = muT_Graphical;
  67.         tags[0].ti_Data = argarray[argGUI];
  68.         tags[1].ti_Tag = muT_Task;
  69.         tags[1].ti_Data = (LONG)task;
  70.         tags[2].ti_Tag = muT_Own;
  71.         tags[2].ti_Data = argarray[argOWN];
  72.         tags[3].ti_Tag = muT_Global;
  73.         tags[3].ti_Data = argarray[argGLOBAL];
  74.         tags[4].ti_Tag = muT_UserID;
  75.         tags[4].ti_Data = argarray[argUSERID];
  76.         tags[5].ti_Tag = TAG_DONE;
  77.         if (muLoginA(tags)) {
  78.             PutStr("Login successful\n");
  79.             rc = RETURN_OK;
  80.         } else {
  81.             PutStr("Login failed\n");
  82.         }
  83.     }
  84.     FreeArgs(args);
  85.  
  86. Exit:
  87.     CloseLibrary((struct Library *)muBase);
  88.     CloseLibrary((struct Library *)DOSBase);
  89.  
  90.     return(rc);
  91. }
  92.