SunRPCAuthImpl.mesa
Copyright Ó 1989, 1991, 1992 by Xerox Corporation. All rights reserved.
Demers, January 9, 1988 8:18:50 am PST
Willie-Sue, March 16, 1989 7:02:15 pm PST
Willie-s, August 21, 1991 12:30 pm PDT
DIRECTORY
BasicTime USING [earliestGMT, GMT, Now, Period, TimeNotKnown, Update],
Process USING [Detach, PauseMsec],
RefText USING [New],
Rope USING [ROPE],
SunRPCAuth USING [AuthenticateProc, AuthenticateResult, CheckReplyVerifierProc, ConversationObject, Flavor, GetCredentialsAndNextVerifierProc, InitiateProc, NoShortcutProc, nullFlavor, ProcsObject, SweepProc, TerminateProc]
;
SunRPCAuthImpl: CEDAR MONITOR
IMPORTS BasicTime, Process, RefText
EXPORTS SunRPCAuth
~ {
Types
ROPE: TYPE ~ Rope.ROPE;
Flavor: TYPE ~ SunRPCAuth.Flavor;
nullFlavor: Flavor ~ SunRPCAuth.nullFlavor;
OpaqueValue: TYPE ~ REF TEXT;
nullOpaqueValue: OpaqueValue ¬ RefText.New[0];
Conversation: TYPE ~ REF ConversationObject;
ConversationObject: TYPE ~ SunRPCAuth.ConversationObject;
Procs: TYPE ~ REF ProcsObject;
ProcsObject: TYPE ~ SunRPCAuth.ProcsObject;
GetCredentialsAndNextVerifierProc: TYPE ~ SunRPCAuth.GetCredentialsAndNextVerifierProc;
CheckReplyVerifierProc: TYPE ~ SunRPCAuth.CheckReplyVerifierProc;
NoShortcutProc: TYPE ~ SunRPCAuth.NoShortcutProc;
TerminateProc: TYPE ~ SunRPCAuth.TerminateProc;
InitiateProc: TYPE ~ SunRPCAuth.InitiateProc;
AuthenticateProc: TYPE ~ SunRPCAuth.AuthenticateProc;
SweepProc: TYPE ~ SunRPCAuth.SweepProc;
AuthenticateResult: TYPE ~ SunRPCAuth.AuthenticateResult;
Error: PUBLIC ERROR [code: ATOM] ~ CODE;
Parameters
numFlavors: CARDINAL ~ 5;
msecBetweenSweeps: CARD ¬ 30*1000;
Registration
Registrations: TYPE ~ ARRAY [0..numFlavors) OF Registration;
Registration: TYPE ~ REF RegistrationObject;
RegistrationObject: TYPE ~ RECORD [
initiateProc: InitiateProc,
authenticateProc: AuthenticateProc,
sweepProc: SweepProc,
data: REF
];
registrations: REF Registrations ¬ NEW[Registrations];
Register: PUBLIC PROC [flavor: Flavor, initiate: InitiateProc, authenticate: AuthenticateProc, sweep: SweepProc, registrationData: REF] ~ {
flavorIndex: CARD ¬ flavor;
registration: Registration ¬ NIL;
IF flavorIndex >= numFlavors THEN ERROR Error[$flavorOutOfRange];
IF (initiate # NIL) AND (authenticate # NIL) THEN {
registration ¬ NEW[RegistrationObject];
registration.initiateProc ¬ initiate;
registration.authenticateProc ¬ authenticate;
registration.sweepProc ¬ sweep;
registration.data ¬ registrationData;
};
registrations[flavorIndex] ¬ registration;
};
Daemon
Daemon: PROC ~ {
DO
Process.PauseMsec[msecBetweenSweeps];
DoSweeps[];
ENDLOOP;
};
lastSweepTime: BasicTime.GMT ¬ BasicTime.earliestGMT;
DoSweeps: ENTRY PROC [rollingBack: BOOL ¬ FALSE] ~ {
now: BasicTime.GMT;
secondsSinceLastSweep: CARD;
now ¬ BasicTime.Now[
! BasicTime.TimeNotKnown => {
now ¬ BasicTime.Update[lastSweepTime, (msecBetweenSweeps+999)/1000];
CONTINUE
}
];
secondsSinceLastSweep ¬ BasicTime.Period[
from~IF rollingBack THEN BasicTime.earliestGMT ELSE lastSweepTime,
to~now];
FOR i: CARDINAL IN [0 .. numFlavors) DO
r: Registration ~ registrations[i];
IF (r # NIL) AND (r.sweepProc # NIL) THEN r.sweepProc[r.data, secondsSinceLastSweep];
ENDLOOP;
lastSweepTime ¬ now;
};
Servers
Authenticate: PUBLIC PROC [cFlavor: Flavor, credentials: OpaqueValue, vFlavor: Flavor, verifier: OpaqueValue]
RETURNS [result: AuthenticateResult, replyFlavor: Flavor, replyVerifier: OpaqueValue, c: Conversation]
~ {
flavorIndex: CARD;
registration: Registration;
IF ((flavorIndex ¬ cFlavor) >= numFlavors)
OR ((registration ¬ registrations[flavorIndex]) = NIL)
THEN RETURN [result~badCredentials, replyFlavor~nullFlavor, replyVerifier~NIL, c~NIL];
[result, replyFlavor, replyVerifier, c] ¬ registration.authenticateProc[cFlavor, credentials, vFlavor, verifier, registration.data];
};
Clients
Initiate: PUBLIC PROC [flavor: Flavor, myName, myPassword: ROPE, hisName: ROPE]
RETURNS [c: Conversation] ~ {
flavorIndex: CARD;
registration: Registration;
IF (flavorIndex ¬ flavor) >= numFlavors THEN ERROR Error[$flavorOutOfRange];
IF (registration ¬ registrations[flavorIndex]) = NIL THEN ERROR Error[$flavorNotRegistered];
c ¬ registration.initiateProc[flavor, myName, myPassword, hisName, registration.data];
};
Null Flavor
nullClientConversation: Conversation;
nullClientProcs: Procs;
nullServerConversation: Conversation;
NullInitiate: InitiateProc ~ { RETURN[nullClientConversation] };
NullNoShortcut: NoShortcutProc ~ { RETURN [FALSE] };
NullTerminate: TerminateProc ~ { NULL };
NullGetCredentialsAndNextVerifier: GetCredentialsAndNextVerifierProc ~ {
cFlavor ¬ vFlavor ¬ nullFlavor;
credentials ¬ nullOpaqueValue;
verifier ¬ nullOpaqueValue;
};
NullCheckReplyVerifier: CheckReplyVerifierProc ~ { RETURN[ok] };
NullAuthenticate: AuthenticateProc ~ {
RETURN [result~ok, replyFlavor~nullFlavor, replyVerifier~nullOpaqueValue, c~nullServerConversation];
};
RegisterNull: PROC ~ {
nullClientProcs ¬ NEW[ProcsObject ¬ [NullGetCredentialsAndNextVerifier, NullCheckReplyVerifier, NullNoShortcut, NullTerminate]];
nullClientConversation ¬ NEW[ConversationObject ¬ [nullFlavor, nullClientProcs, NIL]];
nullServerConversation ¬ NEW[ConversationObject ¬ [nullFlavor, NIL, NIL]];
Register[nullFlavor, NullInitiate, NullAuthenticate, NIL, NIL];
};
Initialization
RegisterNull[];
TRUSTED { Process.Detach[ FORK Daemon[] ] };
}...