!PASS: Set password - modded JHB Oct 84 to use current directory/user
!  GDMR 03/02/87  Verify old password for filestores B & C only (interim fix)
!  GDMR 01/08/88  Send old & new passwords to non-old filestores.  Note that
!                 the old password is in P2, which is incompatible with what
!                 the old-style filestores think is there (a username).

%include "inc:fs.imp"
%include "inc:fsutil.imp"
%include "inc:util.imp"

%begin; !Pass: change password
%integer on=1
%integer x
%string(255) old, new1, new2, user = "?1"
%string(7) directory = "?2", owner = "?3"

  %routine logon(%string(63)u,p)
  %string(127)s = u.",".p
  %integer x
    x = fcomm('M'<<8,""); on = 0
    x = fcomm('L'<<8,s);  on = 1
  %end

  %onevent 3,9 %start
    printstring(event_message)
    printstring(" - you have been logged off") %if on=0
    newline
    %stop
  %finish

  %if RDTE = 16_15 {B} %or RDTE = 16_1B {C} %or RDTE = 16_44 {M} %start
    ! Old filestore, so potentially could change someone else's pass
    user = current directory
    Define Param ("User", user, pam major)
    Process Parameters (cli param)
    directory = current directory
    owner = current user
  %finish

  !! printstring("User ");  printstring(user)
  !! printstring(", owner ");  printstring(owner)
  !! printstring(", RDTE ");  phex(RDTE);  newline

  set terminal mode(noecho)
  x = testsymbol %until testsymbol<0

  %if (RDTE = 16_15 {B} %or RDTE = 16_1B {C} %or RDTE = 16_44 {M}) %start
    ! Old filestore
    %if user=owner %start
      prompt("Old password:"); readline(old)
      logon(owner,old)
      set directory(directory)
    %finish
  %else
     ! New filestore, always ask for old pass
    prompt("Old password:"); readline(old)
  %finish

  prompt("New password:"); readline(new1)
  prompt("Confirm:     "); readline(new2)
  %if new1#new2 %start
    printstring("Not confirmed"); newline; %stop
  %finish
  %if (RDTE = 16_15 {B} %or RDTE = 16_1B {C} %or RDTE = 16_44 {M}) %start
    ! Old style filestore, so P2 is username
    new1 = new1.",".user %if user#owner
  %else
    ! New-style filestore, so P2 is old password
    new1 = new1 . "," . old
  %finish
  x = fcomm('P'<<8,new1)
  %stop %if (RDTE # 16_15 {B} %and RDTE # 16_1B {C} %and RDTE # 16_44 {M}) %c
    %or user#owner

  ! Why does he bother with this next bit, I wonder.....?
  logon(owner,new1)
  set directory(directory)
%endofprogram
