1753928 Members
8982 Online
108810 Solutions
New Discussion юеВ

Re: Help using pty

 
Mike Stroyan
Honored Contributor

Re: Help using pty

The tusc output shows that the parent process has done the writes and is waiting for the child process to exit. You didn't give tusc the "-fp" option, so it doesn't show what the child process is doing.
Andreas Tsamis
Advisor

Re: Help using pty

This is part of the o/p tusc -fp passwd ... It seems that i get prompted to enter new password but it doesn't accept welcom as input. It should prompted me to reenter the pass.
[1862] lseek(4, 2444, SEEK_SET) .......................... = 2444
[1862] read(4, "N e w p a s s w o r d : ", 14) ....... = 14
[1862] open("/dev/tty", O_RDWR, 0666) .................... = 5
[1862] ioctl(5, TCGETA, 0x7f7fe2e8) ...................... = 0
[1862] sigsetreturn(0x7b038fee, 0x6211988, 1392) ......... = 0
[1862] sigvec(SIGINT, 0x7f7fde20, 0x7f7fde30) ............ = 0
[1862] ioctl(5, TCGETA, 0x7f7fdda0) ...................... = 0
[1861] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[1861] time(NULL) ........................................ = 1152591374
[1861] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[1861] write(4, "w e l c o m \n", 7) ..................... = 7
[1861] sigprocmask(SIG_BLOCK, 0x7f7f0c38, 0x7f7f0c58) .... = 0
[1861] getitimer(ITIMER_REAL, 0x7f7f0c78) ................ = 0
[1861] time(NULL) ........................................ = 1152591374
[1861] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ [sleeping]
[1861] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[1861] time(NULL) ........................................ = 1152591377
[1861] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[1861] write(4, "w e l c o m \n", 7) ..................... = 7
[1861] sigprocmask(SIG_BLOCK, 0x7f7f0c38, 0x7f7f0c58) .... = 0
[1861] getitimer(ITIMER_REAL, 0x7f7f0c78) ................ = 0
[1861] time(NULL) ........................................ = 1152591377
[1861] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[1861] time(NULL) ........................................ = 1152591379
[1861] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[1861] wait(0x7f7f0898) .................................. [sleeping]
Mike Stroyan
Honored Contributor

Re: Help using pty

I don't see the child process prompting for the new password. It reads that string out of a file; probably from the message catalog /usr/lib/nls/C/pam_unix.cat. It does a couple of ioctl calls on /dev/tty. But then it doesn't write any prompt. Perhaps it was stopped by an unexpected result from the last ioctl.
Andreas Tsamis
Advisor

Re: Help using pty

You where right. I changed execlp
to execlp("/sbin/passwd", "/sbin/passwd", argv[1], NULL);
and now it reads /etc/passwd and it writes a new password prompt but it still waits
[6592] open("/dev/tty", O_RDONLY, 0666) .................. = 3
[6592] ioctl(3, TCGETA, 0x7f7f0ee8) ...................... = 0
[6592] sigsetreturn(0x2fc98, 0x6211988, 1392) ............ = 0
[6592] sigaction(SIGINT, 0x7f7f0920, 0x7f7f0948) ......... = 0
[6592] ioctl(3, TCGETATTR, 0x7f7f0970) ................... = 0
[6592] ioctl(3, TCSETATTRF, 0x7f7f0970) .................. = 0
[6592] write(2, "N e w p a s s w o r d : ", 13) ........ = 13
[6591] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[6591] time(NULL) ........................................ = 1152679755
[6591] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[6592] read(3, "w ", 1) .................................. = 1
[6591] write(4, "w e l c o m \r", 7) ..................... = 7
[6592] read(3, "e ", 1) .................................. = 1
[6591] sigprocmask(SIG_BLOCK, 0x7f7f0c38, 0x7f7f0c58) .... = 0
[6592] read(3, "l ", 1) .................................. = 1
[6591] getitimer(ITIMER_REAL, 0x7f7f0c78) ................ = 0
[6592] read(3, "c ", 1) .................................. = 1
[6591] time(NULL) ........................................ = 1152679755
[6592] read(3, "o ", 1) .................................. = 1
[6592] read(3, "m ", 1) .................................. = 1
[6592] read(3, "\r", 1) .................................. = 1
[6592] read(3, 0x400081c8, 1) ............................ [sleeping]
[6591] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[6591] time(NULL) ........................................ = 1152679758
[6591] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[6591] write(4, "w e l c o m \r", 7) ..................... = 7
[6592] read(3, "w ", 1) .................................. = 1
[6591] sigprocmask(SIG_BLOCK, 0x7f7f0c38, 0x7f7f0c58) .... = 0
[6592] read(3, "e ", 1) .................................. = 1
[6591] getitimer(ITIMER_REAL, 0x7f7f0c78) ................ = 0
[6592] read(3, "l ", 1) .................................. = 1
[6591] time(NULL) ........................................ = 1152679758
[6592] read(3, "c ", 1) .................................. = 1
[6592] read(3, "o ", 1) .................................. = 1
[6592] read(3, "m ", 1) .................................. = 1
[6592] read(3, "\r", 1) .................................. = 1
[6591] sigtimedwait(0x7f7f0c88, NULL, 0x7f7f0ca8) ........ ERR#11 EAGAIN
[6591] time(NULL) ........................................ = 1152679760
[6591] sigprocmask(SIG_SETMASK, 0x7f7f0c58, NULL) ........ = 0
[6591] wait(0x7f7f0898) .................................. [sleeping]
Mike Stroyan
Honored Contributor

Re: Help using pty

It looks like /sbin/passwd is waiting for a newline. Your program wrote "\n" but passwd read "\r". That would happen if the pty had a termio setting of c_iflag|=INLCR that maps newline to carriage return. It seems that the previous use of that pty pair left it set that way. I would have expected termio to have default values, which "man 7 termio" says would not set the INLCR bit. You could take control of this by using ioctl with TCSETA to set the termio values on the pty before the child process calls exec.
Andreas Tsamis
Advisor

Re: Help using pty

The reason it writes \r is because i changed it in the code. With \n it didn't work so i tried \r but with no result