-- Copyright (C) 1981, 1982  by Xerox Corporation. All rights reserved. 
-- PasswordViaGrapevine.mesa, HGM, 21-Oct-81 15:17:01

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

PasswordViaGrapevine: PROGRAM IMPORTS String, NameInfoDefs EXPORTS Password =
  BEGIN

  ValidMemberOfGroup: PUBLIC PROCEDURE [name, password, group: LONG STRING]
    RETURNS [Password.Status] =
    BEGIN
    shortName: STRING = [100];
    shortPassword: STRING = [100];
    shortGroup: STRING = [100];
    authenticate: NameInfoDefs.AuthenticateInfo;
    IF name = NIL OR password = NIL OR group = NIL THEN RETURN[nil];
    String.AppendString[shortName, name];
    String.AppendString[shortPassword, password];
    String.AppendString[shortGroup, group];
    authenticate ← NameInfoDefs.Authenticate[shortName, shortPassword];
    SELECT authenticate FROM
      individual =>
        BEGIN
        isMember: NameInfoDefs.Membership;
        isMember ← NameInfoDefs.IsMemberClosure[shortGroup, shortName];
        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.