/* Ok.. so to explain.. this is basically a C program that can run with a modified version of the proxy2ssh script. It's useful if you don't want to run the cgi from apache.. this is a standalone program that listens on it's own 'http' port and then invokes sshd and hands it the connected sockets as stdin/stdout. I wrote it as an experiment and actually it does have a bit less lag than the cgi version. It really does need quite a bit of work before a release, but what the hell.. those of you who find it here may well be able to figure out how to use it or at least use the concept to write a better one yourself. It needs to run as root - this isn't really a requirement, but if it doesn't run as root, you need to supply more parameters to sshd including it's own private key file that it can read. I couldn't be bothered to setup a seperate key and config for this sshd so I'm just using the (default) system one which requires root. Also if you dont' run it as root then you can only log in as the user that's running this (obviously). To compile it.. should be fairly simple; gcc -o prox2 prox2.c If you want to try it and can't get it to work please feel free to email me. Robert McKay */ #include #include #include #include #include #include extern char **environ; int main (int argc, char *argv[]) { int rfds[2]; int wfds[2]; int m_getfd,c_getfd; int m_postfd,c_postfd; int ret; struct sockaddr_in gets,c_gets; struct sockaddr_in posts,c_posts; int rfd = rfds[1]; int wfd = wfds[1]; char *params[] = { "/usr/sbin/sshd", "-i", 0 }; socklen_t getslen,postslen,c_getslen,c_postslen; ret=socketpair(PF_UNIX, SOCK_STREAM, 0, rfds); ret=socketpair(PF_UNIX, SOCK_STREAM, 0, wfds); m_getfd = socket(PF_INET, SOCK_STREAM, 0); m_postfd = socket(PF_INET, SOCK_STREAM, 0); gets.sin_family = AF_INET; gets.sin_port = htons(9080); ret=inet_pton(AF_INET, "0.0.0.0", &gets.sin_addr); posts.sin_family = AF_INET; posts.sin_port = htons(9081); ret=inet_pton(AF_INET, "0.0.0.0", &posts.sin_addr); ret=bind(m_getfd, (struct sockaddr *)&gets, sizeof(gets)); //ret=bind(m_postfd, (struct sockaddr *)&posts, sizeof(posts)); listen(m_getfd, 2); //listen(m_postfd, 1); c_getslen = sizeof(c_gets); c_getfd = accept(m_getfd, (struct sockaddr *)&c_gets, &c_getslen); usleep(500); // wait for req dprintf(c_getfd, "\nKey: wtfkey\n" ); c_postfd = accept(m_getfd, (struct sockaddr *)&c_gets, &c_getslen); perror("wtf?"); int i=0; for (i=0;i<9;i++) { char c=0; while(c!='\n') { ret=read(c_postfd, &c, 1); } } // set stdin/stdout/stderr to our side of the socketpair dup2(c_postfd, 0); dup2(c_getfd, 1); dup2(c_getfd, 2); execve("/usr/sbin/sshd", params, environ ); }