Search code examples
tclexpect

Ask for a possibly cached password in Expect


I'd like to do something along the lines of

systemd-ask-password --keyname=domain:pw --accept-cached Password:

from Expect. This command works fine, from a terminal, to either return the cached password if it already exists or prompt for it and then cache it. However, I have not managed to figure out a way to make it interact with expect.

send "systemd-ask-password --keyname=domain:pw --accept-cached Password:\r"

produces no output to interact with, and

spawn "systemd-ask-password --keyname=domain:pw --accept-cached Password:\r"

says ": no such file or directory... which implies the spawned process is not even using the same keyring.

I'd be happy enough to use the lower level keyctl, but I'm having the same results with that

What is the correct syntax to make systemd-ask-password or keyctl prompt on the tty?


Solution

  • I think you mean to run the command using the tty that you are currently in. This can be done using exec. For example, the following shell interaction (**** is where I typed none):

    $ cat <<\! >myprog
    set pw [exec systemd-ask-password --keyname=domain:pw --accept-cached Password:]
    send_user "you said pw=$pw\n"
    !
    $ expect myprog
    Password: ****
    you said pw=none
    $ expect myprog
    you said pw=none