Posted By:
Nathan_Meyers
Posted On:
Monday, November 26, 2001 09:14 AM
This is a pretty ugly problem.
The su utility expects to receive its password through a tty interface on stdin (at least that's how it looks on the Mandrake 8.1 distro). The easiest solution would be to make the user run your installer as root (make the user type "su -c installer" and supply the password).
If that's not possible, here's something that I think will work. It assumes your installer is in C, Perl, or some other environment that lets you manage subprocesses. file descriptors, and pseudo-ttys:
Allocate a pseudo-tty pair.
Fork a subprocess
Reassociate the subprocess' stdin and stdout with the slave pty.
Exec su from the subprocess.
In the parent process, feed the password to the master side of the pty.
No, this isn't pretty. And it assumes that su will always work from a stdin that looks like a tty (which I haven't checked outside of Mandrake 8.1). But I think it has a chance of working.