// IfsTelnetPassword.bcpl -- Change Password command
// Copyright Xerox Corporation 1979, 1981

// Last modified November 25, 1981  3:26 PM by Taft

get "Ifs.decl"
get "IfsRs.decl"
get "IfsFiles.decl"

external
[
// outgoing procedures
ExecChangePassword

// incoming procedures
EnableCatch; EndCatch; GetString; DefaultPhrase
GetDIF; UpdateCachedDIF; Password
FreePointer; Wss; Ws; Errors; IFSPrintError; FalsePredicate

// incoming statics
dsp; CtxRunning; enableGrapevineAuth
]

//---------------------------------------------------------------------------
let ExecChangePassword(cs) be
//---------------------------------------------------------------------------
// Change Password <directory> <old-password> <new-password>
[
Wss(cs, " (of directory) ")
let name, password, dif = 0, 0, 0
if EnableCatch(cs) then
   [ FreePointer(lv name, lv password, lv dif); EndCatch(cs) ]
DefaultPhrase(cs, CtxRunning>>RSCtx.userInfo>>UserInfo.connName)
name = GetString(cs, 0, Wss, "directory name")
dif = GetDIF(name, true)  // succeeds only for real local DIF
if dif eq 0 then Errors(cs, 0)

Wss(cs, " (old password) ")
password = GetString(cs, 0, Wss, "password", FalsePredicate)
unless Password(password, lv dif>>DIF.password, false) %
 CtxRunning>>RSCtx.userInfo>>UserInfo.capabilities.wheel do
   Errors(cs, 0)
FreePointer(lv password)

Wss(cs, " (new password) ")
password = GetString(cs, 0, Wss, "password")
if password>>String.length eq 0 then Errors(cs, 0)  // disallow null string
Password(password, lv dif>>DIF.password, true)

UpdateCachedDIF(name, dif)

if enableGrapevineAuth & dif>>DIF.validGrapevineRName then
   [
   Ws("*n[Caution: Grapevine authentication is enabled.  This change")
   Ws("*n may not be permanent until you change your Grapevine password")
   Ws("*n using the Maintain program.]")
   ]

FreePointer(lv name, lv password, lv dif)
]