Hello-
I am trying to automate a call to su. Unfortunately, su requires input from a terminal. I have seen examples of how to create a pseudo terminal and I understand that su will accept input from these:
Code:
int fdm, fds;
char *slavename;
extern char *ptsname();
fdm = open("/dev/ptmx", O_RDWR);
grantpt(fdm);
unlockpt(fdm);
slavename = ptsname(fdm);
fds = open(slavename, O_RDWR);
(This is just from a man page I found)
From the man page of ptmx:
Pseudo-terminals can also be used to send input to programs that normally refuse to read input from pipes (such as su(8), and
passwd(8)).
Does anyone have a good example of how to create and use the pseudo terminals for automating a call to su?
Thanks.