diff -uprk.orig openssh-3.6.1p1.orig/sshd.c openssh-3.6.1p1/sshd.c --- openssh-3.6.1p1.orig/sshd.c 2003-04-12 15:32:03 +0400 +++ openssh-3.6.1p1/sshd.c 2003-04-12 15:39:03 +0400 @@ -150,6 +150,9 @@ int saved_argc; int listen_socks[MAX_LISTEN_SOCKS]; int num_listen_socks = 0; +/* This is set to the socket that the server have accepted. */ +static int accepted_sock; + /* * the client's version string, passed by sshd2 in compat mode. if != NULL, * sshd will skip the version-number exchange @@ -806,7 +809,7 @@ main(int ac, char **av) { extern char *optarg; extern int optind; - int opt, sock_in = 0, sock_out = 0, newsock, j, i, fdsetsz, on = 1; + int opt, sock_in = 0, sock_out = 0, j, i, fdsetsz, on = 1; pid_t pid; socklen_t fromlen; fd_set *fdset; @@ -1302,25 +1305,25 @@ main(int ac, char **av) if (!FD_ISSET(listen_socks[i], fdset)) continue; fromlen = sizeof(from); - newsock = accept(listen_socks[i], (struct sockaddr *)&from, + accepted_sock = accept(listen_socks[i], (struct sockaddr *)&from, &fromlen); - if (newsock < 0) { + if (accepted_sock < 0) { if (errno != EINTR && errno != EWOULDBLOCK) error("accept: %.100s", strerror(errno)); continue; } - if (fcntl(newsock, F_SETFL, 0) < 0) { - error("newsock del O_NONBLOCK: %s", strerror(errno)); - close(newsock); + if (fcntl(accepted_sock, F_SETFL, 0) < 0) { + error("accepted_sock del O_NONBLOCK: %s", strerror(errno)); + close(accepted_sock); continue; } if (drop_connection(startups) == 1) { debug("drop connection #%d", startups); - close(newsock); + close(accepted_sock); continue; } if (pipe(startup_p) == -1) { - close(newsock); + close(accepted_sock); continue; } @@ -1345,8 +1348,8 @@ main(int ac, char **av) */ debug("Server will not fork when running in debugging mode."); close_listen_socks(); - sock_in = newsock; - sock_out = newsock; + sock_in = accepted_sock; + sock_out = accepted_sock; startup_pipe = -1; pid = getpid(); break; @@ -1367,8 +1370,8 @@ main(int ac, char **av) startup_pipe = startup_p[1]; close_startup_pipes(); close_listen_socks(); - sock_in = newsock; - sock_out = newsock; + sock_in = accepted_sock; + sock_out = accepted_sock; log_reinit(); break; } @@ -1394,7 +1397,7 @@ main(int ac, char **av) arc4random_stir(); /* Close the new socket (the child is now taking care of it). */ - close(newsock); + close(accepted_sock); } /* child process check (or debug mode) */ if (num_listen_socks < 0) @@ -1534,6 +1537,11 @@ main(int ac, char **av) } authenticated: + +#ifdef HAVE_FCHOWN + fchown(accepted_sock, authctxt->pw->pw_uid, authctxt->pw->pw_gid); +#endif + /* * In privilege separation, we fork another child and prepare * file descriptor passing.