Nightly: Can't send password over stdin to su

su wants to use a tty for everything, so it’s difficult to automate privileged commands. On most UNIX systems, echo '<password>' | su <user> -c '<command>' is sufficient to authenticate privileged commands. Yet in Haiku OS, there appears to be no way to supply passwords in an automated fashion to su. su seems to hardcode receiving passwords from a tty device, rather than reading them from STDIN. Nor is there sudo package for Haiku.

One workaround might involve writing an expect script, however in practice I’ve never gotten the syntax to work correctly.

You could propose a patch for the read_password function:
https://git.haiku-os.org/haiku/tree/src/bin/multiuser/multiuser_utils.cpp#n21

On the topic of sudo, have you checked out doas?

1 Like

“Expect” uses a pty device, and you can do that too. I can’t recall that I have ever tried it on Haiku, but I’d be surprised if it doesn’t work perfectly well. See declarations after /* pty functions */ in develop/headers/posix/stdlib.h, and refer to Open Group docs - that would be my guess anyway.

There’s a reason applications like this go around the normal input units. When su comes up in the middle of a procedure, it shouldn’t siphon input out of the standard input, which is likely being used for something else. I don’t know about “most UNIX systems”, but FreeBSD for example doesn’t do that.

1 Like

Unfortunately, I do not see a doas package available for Haiku nightly.

As you pointed out, neither is there a package yet for sudo. I prefer doas, but I like to use OpenBSD and that’s the stock replacement for sudo on that system.