ssh is reading and writing directly to /dev/tty. In order to control this, you need to do a bit of hokey pokey with setsid, open a new tty for your new process group, and then dup those file descriptors in your parent to pipes that speak to your child. It's a hassle.

I ran across this trying to do y2k testing with sudo, which does the same thing. I'll update this node with code if I can find it ...

Updated:
Admittedly, this isn't perl, but you should be able to adapt ...

pipe(toslave); pipe(frslave); if (fork() == 0) { int fd; close(0); dup(toslave[0]); close(1); dup(frslave[1]); (void)setsid(); /* become session leader and */ /* lose controlling tty */ fd = open("/dev/console", O_RDWR); #ifndef hpux (void)ioctl(fd,TIOCSCTTY,0); #endif free(argv[0]); argv[0] = (char *)malloc(5 * sizeof(char)); sprintf(argv[0],"ssh"); execv("/usr/bin/ssh", argv); fprintf(stderr,"Bad exec (%u)\n", errno); exit(0); } write(toslave[1],PASSWORD, strlen(PASSWORD)); if (! strncmp("-v", argv[1])) exit(wait(NULL)); if (! strncmp("-k", argv[1])) exit(wait(NULL)); num=read(frslave[0],buf,359); buf[num]='\0'; printf("%s", buf); exit(wait(NULL)); }

I'll perlify later this weekend ...


Remember, when you stare long into the abyss, you could have been home eating ice cream.

In reply to Re: Ignoring ssh login request? by idsfa
in thread Ignoring ssh login request? by monk_wannabe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.