-- File: PasswordViaGrapevine.mesa,  Last Edit: HGM  March 18, 1981  9:39 PM

DIRECTORY
  NameInfoDefs USING [Authenticate, AuthenticateInfo, IsMemberClosure, Membership],
  Password USING [Status];

PasswordViaGrapevine: PROGRAM IMPORTS NameInfoDefs EXPORTS Password =
  BEGIN

  ValidMemberOfGroup: PUBLIC PROCEDURE [name, password, group: STRING]
    RETURNS [Password.Status] =
    BEGIN
    authenticate: NameInfoDefs.AuthenticateInfo;
    IF name=NIL OR password=NIL OR group=NIL THEN RETURN[nil];
    authenticate ← NameInfoDefs.Authenticate[name, password];
    SELECT authenticate FROM
      individual =>
        BEGIN
        isMember: NameInfoDefs.Membership;
        isMember ← NameInfoDefs.IsMemberClosure[group, name];
        SELECT isMember FROM
          yes => RETURN[yes];
          no => RETURN[no];
          notGroup => RETURN[notGroup];
          allDown => RETURN[allDown];
          ENDCASE => RETURN[error];
        END;
      group => RETURN[allDown];
      notFound => RETURN[notFound];
      badPwd => RETURN[badPwd];
      allDown => RETURN[allDown];
      ENDCASE => RETURN[error];
    END;

  END.