home *** CD-ROM | disk | FTP | other *** search
- /*
- * UserTool - A Tool for managing users in a MuFS environment.
- *
- * $VER: main.c 37.1 (10.1.94)
- */
-
- #include <exec/execbase.h>
- #include <dos/dos.h>
- #include <intuition/intuition.h>
-
- #include <libraries/gadtools.h>
- #include <libraries/multiuser.h>
- #include <libraries/reqtools.h>
-
- #include <clib/exec_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/reqtools_protos.h>
-
- #include <proto/multiuser.h>
-
- #include <string.h>
-
- #include "UserTool_rev.h"
- #include "UserTool.h"
- #include "parse.h"
- #include "stubs.h"
-
- struct List *Users, *Groups;
- struct Library *ReqToolsBase = 0L;
- struct muBase *muBase = 0L;
- struct ExecBase *ExecBase;
- UserStruct *CurUser;
- GroupStruct *CurGroup;
- UBYTE PasswdName[1024], GroupName[1024];
- LONG winSig, Startup, PasswdFileDirty, GroupFileDirty;
- LONG Tags[] = {
- RT_Window, 0L,
- RT_LockWindow, TRUE,
- RT_Underscore, ( LONG )'_',
- RTEZ_ReqTitle, 0L,
- TAG_END
- };
-
- STATIC const UBYTE VersTag[] = VERSTAG;
-
- LONG Setup( VOID )
- {
- if(!( ReqToolsBase = OpenLibrary( REQTOOLSNAME, REQTOOLSVERSION )))
- return 3L;
-
- if(!( muBase = ( struct muBase * )OpenLibrary( MULTIUSERNAME,
- MULTIUSERVERSION )))
- return 3L;
-
- if( SetupScreen())
- return 1L;
-
- if( OpenUserToolWindow())
- return 2L;
-
- winSig = 1L << UserToolWnd->UserPort->mp_SigBit;
-
- return 0L;
- }
-
- VOID Shutdown( VOID )
- {
- CloseUserToolWindow();
- CloseDownScreen();
- if( muBase )
- CloseLibrary(( struct Library * )muBase );
- if( ReqToolsBase )
- CloseLibrary( ReqToolsBase );
- }
-
- ULONG UserIsRoot( VOID )
- {
- struct muExtOwner *Owner;
- ULONG isRoot;
-
- if( Owner = muGetTaskExtOwner( FindTask( 0L ))) {
- isRoot = muGetRelationshipA( Owner, 0L, 0L ) & muRelF_ROOT_UID;
- muFreeExtOwner( Owner );
- }
-
- return isRoot;
- }
-
- VOID main( VOID )
- {
- LONG cont = TRUE, sigs;
- BPTR muLock;
-
- ExecBase = *(( struct ExecBase ** )0x04 );
-
- if( !Setup() ) {
- Tags[1] = ( LONG )UserToolWnd;
-
- if( !UserIsRoot()) {
- Tags[7] = ( LONG )"Access Violation";
- rtEZRequest( "Sorry, you must be root to run this program.", "Ok",
- 0L, ( struct TagItem * )Tags );
- goto EXIT;
- }
-
- if( muLock = muGetPasswdDirLock()) {
- if( !NameFromLock( muLock, PasswdName, 1024 )) {
- Tags[7] = ( LONG )"File Error";
- rtEZRequest( "Error locating the password file.", "Ok", 0L,
- ( struct TagItem * )Tags );
- goto EXIT;
- }
- AddPart( PasswdName, muPasswd_FileName, 1024 );
- UnLock( muLock );
- }
-
- if( muLock = muGetConfigDirLock()) {
- if( !NameFromLock( muLock, GroupName, 1024 )) {
- Tags[7] = ( LONG )"File Error";
- rtEZRequest( "Error locating the group file.", "Ok", 0L,
- ( struct TagItem * )Tags );
- goto EXIT;
- }
- AddPart( GroupName, muGroup_FileName, 1024 );
- UnLock( muLock );
- }
-
- Startup = TRUE;
- if( Users = ParsePasswdFile())
- GT_SetGadgetAttrs( UserToolGadgets[GD_USERS], UserToolWnd, 0l,
- GTLV_Labels, Users, TAG_DONE );
- if( Groups = ParseGroupFile())
- GT_SetGadgetAttrs( UserToolGadgets[GD_GROUPS], UserToolWnd, 0l,
- GTLV_Labels, Groups, TAG_DONE );
-
- Startup = FALSE;
-
- UpdateGadgets( 0 );
- GT_SetGadgetAttrs( UserToolGadgets[GD_USERS], UserToolWnd, 0l,
- GTLV_Selected, 0, TAG_DONE );
-
- UpdateGroups( 0 );
- GT_SetGadgetAttrs( UserToolGadgets[GD_GROUPS], UserToolWnd, 0l,
- GTLV_Selected, 0, TAG_DONE );
-
- while( cont ) {
- sigs = Wait( winSig | SIGBREAKF_CTRL_C );
-
- if( sigs & winSig )
- cont = HandleUserToolIDCMP();
- if( sigs & SIGBREAKF_CTRL_C )
- cont = FALSE;
- }
-
- FreeUserList( Users );
- FreeGroupList( Groups );
- }
- EXIT:
- Shutdown();
- }
-