home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-04 | 16.1 KB | 584 lines | [TEXT/MPS ] |
- //234567890123456789012345678901234567890123456789012345678901234567890123456789
- //===========================================================================
- // File: SampleClientModule.c
- //
- // This is a sample client-side add-on security code resource for Apple
- // Remote Access. It works in conjunction with the other sample code resources
- // to allow additional authentication of a user during remote log-on.
- //
- // It runs as a slave to the corresponding server-side code resource. The
- // server requests an extra password from this code resource. This resource
- // then displays an additional dialog box to prompt the user for a password.
- //
- // Copyright © 1992, 1993 Apple Computer Inc.
- // All rights reserved
- //
- // Author: Farzad Sarabi
- //
- // Modification history:
- //
- // 5/3/1993 Farzad Made changes to support the enhanced SecurityMgr
- // that creates an A5 world for the security modules.
- // 12/17/1992 Farzad Created
- //===========================================================================
-
- #include <Values.h>
- #include <Types.h>
- #include <Resources.h>
- #include <QuickDraw.h>
- #include <Fonts.h>
- #include <Events.h>
- #include <Windows.h>
- #include <Menus.h>
- #include <TextEdit.h>
- #include <Dialogs.h>
-
-
- #include "SecurityInterface.h"
- #include "SamplePackets.h" // has types for packets sent back
- // and forth between the
- // authentication modules
-
-
- // #define SecurityShellVersion 0x0080
-
-
- //===========================================================================
- // Macros
- //===========================================================================
-
- #define kPasswordDialogID 128
- #define kOKButtonID 1
- #define kCancelButtonID 2
- #define kPasswordTextID 3
-
-
-
-
- //===========================================================================
- // Types
- //===========================================================================
- // the following enum contains our state machine's states
-
- typedef enum
- {
- // the tickle routine gets a 0 when ARA sends a tickle, so here we
- // start with a
- kStateGotRequest = 1, // server sent us a request
- kStatePutUpDialog, // display password dialog
- // handled at non-interrupt time
- kStateSentResponse, // sent a response to the other side
- kStateGotAnswer, // response to our password
- kStateSentCancel, // sent a cancel to other side
-
- kStateMiscCompletion // for all other stuff
-
- } TClientStates;
-
- //===========================================================================
- // Data
- //===========================================================================
- // this data will be stored in our A5 world
- static struct
- {
- TSamplePacket fout_pkt;
- TSamplePacket fin_pkt;
-
- DialogPtr fpassword_dialog;
-
- } MyData; // this is only data that is
- // visible to this code resource
-
-
- //===========================================================================
- // Functions
- //===========================================================================
-
- // function prototypes
- static long DoMyStartup( MyReference, LongParam );
- static long DoMyShutdown( MyReference, LongParam );
- static long DoMyBegin( MyReference, LongParam );
- static long DoMyEnd( MyReference, LongParam );
- static long DoMyDataHandler( MyReference, LongParam );
- static long DoMyAbortHandler( MyReference, LongParam );
- static long DoMyTickleHandler( MyReference, LongParam );
- pascal void MyCompletionProc( SecurityReference MyReference,
- int ResultCode,
- void * DataPtr,
- int DataSize,
- long CompletionParam );
-
-
-
-
- pascal long MySecurityProcEntry( SecurityActions Action,
- SecurityReference MyReference,
- long LongParam )
- //===========================================================================
- // Description: this is the entry point for the ??? security operation.
- // It is called by AppleTalk Remote Access to have this
- // security module perform the given operation. It
- // dispatches to a variety of routines based on the
- // requested action.
- //
- // Parameters: Action the action to be performed
- // MyReference this is a unique value representing
- // this instance of this code module.
- // DataPtr the data for this action
- // DataSize the size of data
- //
- // Return Value: long result code, nonzero indicates an
- // error. Its value is one of the
- // SecurityResultCodes.
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- switch ( Action ) {
-
- case kSecurityStartup:
- return DoMyStartup( MyReference, LongParam );
-
-
- case kSecurityShutdown:
- return DoMyShutdown( MyReference, LongParam );
-
-
- case kSecurityBegin:
- return DoMyBegin( MyReference, LongParam );
-
-
- case kSecurityEnd:
- return DoMyEnd( MyReference, LongParam );
-
-
- case kSecurityDataAvailable:
- return DoMyDataHandler( MyReference, LongParam );
-
-
- case kSecurityAbort:
- return DoMyAbortHandler( MyReference, LongParam );
-
-
- case kSecurityTickleAction:
- return DoMyTickleHandler( MyReference, LongParam );
-
- }
-
- return ( kSecurityUnsupportedAction );
- }
-
-
-
-
- static long DoMyStartup( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityStartup action. You
- // should allocate any memory and setup the working
- // environment (e.g. A5 world) here.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(MyReference,LongParam)
-
- // we have our own A5 world and quickdraw globals. We need to
- // initialize everything, since we will be displaying a dialog box.
-
- InitGraf((Ptr) &qd.thePort); // toolbox stuff
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(nil);
- InitCursor();
-
- return ( kSecurityNoErr );
- }
-
-
-
- static long DoMyShutdown( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityShutdown action. You
- // should release any memory allocated by the DoMyStartup
- // routine.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(MyReference,LongParam)
-
- // this action is sent as a response to one of our requests (e.g.
- // ARACompleteOperation) for ending the process
-
- // We would normally use this as an indicator that the operation that
- // the module is performing is ended as per our request. We could do
- // some cleanup here. We should then wait for the ShutDown action as
- // an indication that our module will be unloaded.
-
- return ( kSecurityNoErr );
- }
-
-
-
- static long DoMyBegin( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityBeing action. This
- // routine should start the operations the code resource
- // must do. For example an authentication code resource
- // should start the authentication process.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(LongParam)
-
- // The server will send us a request. The client is basically driven
- // by the requests that come from the server. We need to post a read
- // to get the initial request.
-
- if ( ARARead( MyReference,
- & MyData.fin_pkt,
- sizeof( MyData.fin_pkt ),
- MyCompletionProc,
- kStateGotRequest ) != ARANoErr )
- {
- // Something went wrong. Don't continue. Let ARA know, so it
- // can tear down the connection.
-
- ARACompleteOperation( MyReference );
- return ( kSecurityGenericErr );
- }
-
- return ( kSecurityNoErr );
-
-
- }
-
-
-
- static long DoMyEnd( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityEnd action. The action
- // is sent to signal the end of the operation the code
- // resource was created to do.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(MyReference,LongParam)
-
- // this action is sent as a response to one of our requests (e.g.
- // ARACompleteOperation) for ending the process
-
- // We would normally use this as an indicator that the operation that
- // the module is performing is ended as per our request. We could do
- // some cleanup here. We should then wait for the ShutDown action as
- // an indication that our code resource will be unloaded.
-
- return ( kSecurityNoErr );
- }
-
-
-
- static long DoMyDataHandler( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityDataAvailable action.
- // The action is sent when data has arrived for the code
- // resource.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(MyReference,LongParam)
-
- // Currently DataAvailable action is not being used. It may in the future
- // be put to some use. One possible use might be for cases when you have
- // a modeless dialog box. We could send you the events through the use
- // of this action.
-
- // This action might also be used when we get data during
- // the authentication process, and you don't have a read pending.
-
- // Again, it is not used now but may be used in the future!
-
- return ( kSecurityNoErr );
- }
-
-
-
- static long DoMyAbortHandler( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityAbort action. The
- // abort action is sent when the code resources operation
- // needs to be terminated abnormally.
- //
- // Parameters: MyReference My unique reference
- // LongParam additional information
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(MyReference,LongParam)
-
- // We are being aborted. You need to abort what you are doing.
- // ARAServices will not be available after this (at least the read and
- // writes will not be available, but you shouldn't expect any of the
- // ARA services to be available). The kSecurityAbort action is sent
- // because of some type of exception.
-
- return ( kSecurityNoErr );
- }
-
-
-
- static long DoMyTickleHandler( MyReference, LongParam )
- //===========================================================================
- // Description: this routine handles the kSecurityTickle action. ARA
- // sends this action periodically. The action is also
- // generated as a result of a call to ARATickleMe routine.
- //
- //
- // Parameters: MyReference My unique reference
- // LongParam When ARA calls this value will be 0,
- // otherwise it is the value passed to
- // the ARATickleMe routine.
- //
- // Return Value: long result code, nonzero indicates error
- //
- // Creation Date:
- //
- // Modifications:
- //
- //===========================================================================
- {
- // When ARA is sending us a kSecurityTickle action, the LongParam will
- // be 0 (zero).
-
- if ( LongParam == kStatePutUpDialog )
- { // need to get the user's password
- short item_hit;
- Handle item_handle;
- short item_type;
- Rect item_box;
- DialogPtr tmp_dlg_ptr;
-
-
-
- MyData.fpassword_dialog = GetNewDialog( kPasswordDialogID,
- nil,
- (WindowPtr) -1 );
-
- if ( MyData.fpassword_dialog == nil ) {
- ARADontAllowUser( MyReference,
- "\pSecurity module couldn't load its password dialog box.",
- MyCompletionProc,
- kStateMiscCompletion );
- return ( kSecurityGenericErr );
- }
-
- do
- {
- ModalDialog( nil, & item_hit );
- } while (( item_hit != kOKButtonID ) && ( item_hit != kCancelButtonID ));
-
- tmp_dlg_ptr = MyData.fpassword_dialog;
- MyData.fpassword_dialog = nil;
-
- if ( item_hit == kCancelButtonID )
- {
- MyData.fout_pkt.fpkt_type = kPktCancel;
- ARAWrite( MyReference,
- & MyData.fout_pkt,
- sizeof( MyData.fout_pkt ),
- MyCompletionProc,
- kStateSentCancel );
- }
- else
- { // ok button
- GetDItem( tmp_dlg_ptr,
- kPasswordTextID,
- & item_type,
- & item_handle,
- & item_box );
- GetIText( item_handle,
- MyData.fout_pkt.u.fresponse.fpassword );
- DisposDialog( tmp_dlg_ptr );
- MyData.fout_pkt.fpkt_type = kPktPasswordResponse;
- if ( ARAWrite( MyReference,
- & MyData.fout_pkt,
- sizeof( MyData.fout_pkt ),
- MyCompletionProc,
- kStateSentResponse ) != ARANoErr )
- {
- ARACompleteOperation( MyReference );
- return ( kSecurityGenericErr );
- }
- }
- }
-
- return ( kSecurityNoErr );
- }
-
-
-
-
- pascal void MyCompletionProc( SecurityReference MyReference,
- int ResultCode,
- void * DataPtr,
- int DataSize,
- long CompletionParam )
- //===========================================================================
- // Description: this is the completion routine that is called when the
- // ARA services routines are completed. We use the
- // CompletionParam to indicate the state we are processing.
- //
- // Parameters: MyReference my unique reference
- // ResultCode for the ARA service call
- // DataPtr pointer to the data we passed in
- // DataSize the actual size of data
- // CompletionParam additional info we passed. We use
- // this value to indicate the state
- // we are processing
- //
- // Return Value: none
- //
- // Creation Date: 12/17/1992
- //
- // Modifications:
- //
- //===========================================================================
- {
- #pragma unused(DataPtr,DataSize)
-
- if ( ResultCode == ARAAbort )
- {
- // we are being aborted
- return;
- }
-
- switch ( CompletionParam )
- {
-
- case kStateGotRequest: // server sent us a request
-
- if ( MyData.fin_pkt.fpkt_type == kPktRequestPassword )
- { // server wants the password
-
- ARATickleMe( MyReference, kStatePutUpDialog );
- break;
- }
- else
- { // invalid request
- ARADontAllowUser( MyReference,
- "\pServer sent an invalid request.",
- MyCompletionProc,
- kStateMiscCompletion );
- break;
- }
-
-
- case kStateSentResponse: // sent a response to the other side
- if ( ARARead( MyReference,
- & MyData.fin_pkt,
- sizeof( MyData.fin_pkt ),
- MyCompletionProc,
- kStateGotAnswer ) != ARANoErr )
- {
- ARACompleteOperation( MyReference );
- break; // redundant break. It's here in case
- // someone adds code after the
- // if statement
- }
- break;
-
-
- case kStateGotAnswer:
- switch ( MyData.fin_pkt.fpkt_type )
- {
- case kPktRequestPassword: // server wants the user's password
- ARATickleMe( MyReference, kStatePutUpDialog );
- break;
-
- case kPktAllow:
- ARAAllowUser( MyReference,
- MyCompletionProc,
- kStateMiscCompletion );
- break;
-
- case kPktCancel:
- default:
- ARADontAllowUser( MyReference,
- "\pYou were not authenticated by the server.",
- MyCompletionProc,
- kStateMiscCompletion );
- break;
- }
- break;
-
-
- case kStateSentCancel: // sent a cancel to other side
- ARACompleteOperation( MyReference );
- break;
-
-
- case kStateMiscCompletion: // for all other stuff
- default:
- break; // don't need to do anything
-
- }
-
- return;
- }
-
-
-