home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / UserTool1_0.lha / UserTool / Source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-21  |  3.5 KB  |  162 lines

  1. /*
  2.  * UserTool - A Tool for managing users in a MuFS environment.
  3.  *
  4.  * $VER: main.c 37.1 (10.1.94)
  5.  */
  6.  
  7. #include <exec/execbase.h>
  8. #include <dos/dos.h>
  9. #include <intuition/intuition.h>
  10.  
  11. #include <libraries/gadtools.h>
  12. #include <libraries/multiuser.h>
  13. #include <libraries/reqtools.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/gadtools_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/reqtools_protos.h>
  19.  
  20. #include <proto/multiuser.h>
  21.  
  22. #include <string.h>
  23.  
  24. #include "UserTool_rev.h"
  25. #include "UserTool.h"
  26. #include "parse.h"
  27. #include "stubs.h"
  28.  
  29. struct List *Users, *Groups;
  30. struct Library *ReqToolsBase = 0L;
  31. struct muBase *muBase = 0L;
  32. struct ExecBase *ExecBase;
  33. UserStruct *CurUser;
  34. GroupStruct *CurGroup;
  35. UBYTE PasswdName[1024], GroupName[1024];
  36. LONG winSig, Startup, PasswdFileDirty, GroupFileDirty;
  37. LONG Tags[] = {
  38.     RT_Window, 0L,
  39.     RT_LockWindow, TRUE,
  40.     RT_Underscore, ( LONG )'_',
  41.     RTEZ_ReqTitle, 0L,
  42.     TAG_END
  43.     };
  44.  
  45. STATIC const UBYTE VersTag[] = VERSTAG;
  46.  
  47. LONG Setup( VOID )
  48. {
  49.     if(!( ReqToolsBase = OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION )))
  50.         return 3L;
  51.  
  52.     if(!( muBase = ( struct muBase * )OpenLibrary( MULTIUSERNAME,
  53.                                                   MULTIUSERVERSION )))
  54.         return 3L;
  55.  
  56.     if( SetupScreen())
  57.         return 1L;
  58.  
  59.     if( OpenUserToolWindow())
  60.         return 2L;
  61.     
  62.     winSig = 1L << UserToolWnd->UserPort->mp_SigBit;
  63.  
  64.     return 0L;
  65. }
  66.  
  67. VOID Shutdown( VOID )
  68. {
  69.     CloseUserToolWindow();
  70.     CloseDownScreen();
  71.     if( muBase )
  72.         CloseLibrary(( struct Library * )muBase );
  73.     if( ReqToolsBase )
  74.         CloseLibrary( ReqToolsBase );
  75. }
  76.  
  77. ULONG UserIsRoot( VOID )
  78. {
  79.     struct muExtOwner *Owner;
  80.     ULONG isRoot;
  81.     
  82.     if( Owner = muGetTaskExtOwner( FindTask( 0L ))) {
  83.         isRoot = muGetRelationshipA( Owner, 0L, 0L ) & muRelF_ROOT_UID;
  84.         muFreeExtOwner( Owner );
  85.     }
  86.  
  87.     return isRoot;
  88. }
  89.     
  90. VOID main( VOID )
  91. {
  92.     LONG cont = TRUE, sigs;
  93.     BPTR muLock;
  94.     
  95.     ExecBase = *(( struct ExecBase ** )0x04 );
  96.  
  97.     if( !Setup() ) {
  98.         Tags[1] = ( LONG )UserToolWnd;
  99.  
  100.         if( !UserIsRoot()) {
  101.             Tags[7] = ( LONG )"Access Violation";
  102.             rtEZRequest( "Sorry, you must be root to run this program.", "Ok",
  103.                         0L, ( struct TagItem * )Tags );
  104.             goto EXIT;
  105.         }
  106.         
  107.         if( muLock = muGetPasswdDirLock()) {
  108.             if( !NameFromLock( muLock, PasswdName, 1024 )) {
  109.                 Tags[7] = ( LONG )"File Error";
  110.                 rtEZRequest( "Error locating the password file.", "Ok", 0L,
  111.                             ( struct TagItem * )Tags );
  112.                 goto EXIT;
  113.             }
  114.             AddPart( PasswdName, muPasswd_FileName, 1024 );
  115.             UnLock( muLock );
  116.         }
  117.  
  118.         if( muLock = muGetConfigDirLock()) {
  119.             if( !NameFromLock( muLock, GroupName, 1024 )) {
  120.                 Tags[7] = ( LONG )"File Error";
  121.                 rtEZRequest( "Error locating the group file.", "Ok", 0L,
  122.                             ( struct TagItem * )Tags );
  123.                 goto EXIT;
  124.             }
  125.             AddPart( GroupName, muGroup_FileName, 1024 );
  126.             UnLock( muLock );
  127.         }
  128.  
  129.         Startup = TRUE;
  130.         if( Users = ParsePasswdFile())
  131.             GT_SetGadgetAttrs( UserToolGadgets[GD_USERS], UserToolWnd, 0l,
  132.                               GTLV_Labels, Users, TAG_DONE );
  133.         if( Groups = ParseGroupFile())
  134.             GT_SetGadgetAttrs( UserToolGadgets[GD_GROUPS], UserToolWnd, 0l,
  135.                               GTLV_Labels, Groups, TAG_DONE );
  136.  
  137.         Startup = FALSE;
  138.         
  139.         UpdateGadgets( 0 );
  140.         GT_SetGadgetAttrs( UserToolGadgets[GD_USERS], UserToolWnd, 0l,
  141.                           GTLV_Selected, 0, TAG_DONE );
  142.  
  143.         UpdateGroups( 0 );
  144.         GT_SetGadgetAttrs( UserToolGadgets[GD_GROUPS], UserToolWnd, 0l,
  145.                           GTLV_Selected, 0, TAG_DONE );
  146.         
  147.         while( cont ) {
  148.             sigs = Wait( winSig | SIGBREAKF_CTRL_C );
  149.  
  150.             if( sigs & winSig )
  151.                 cont = HandleUserToolIDCMP();
  152.             if( sigs & SIGBREAKF_CTRL_C )
  153.                 cont = FALSE;
  154.         }
  155.         
  156.         FreeUserList( Users );
  157.         FreeGroupList( Groups );
  158.     }    
  159. EXIT:
  160.     Shutdown();
  161. }
  162.