Enabled sshd debug mode in windows, fixed bug in STDIO close(), and tty condition in client_loop()

This commit is contained in:
manojampalam 2016-03-11 14:31:47 -08:00
parent 4ae501e179
commit 173b000a76
6 changed files with 42 additions and 40 deletions

View File

@ -2479,11 +2479,12 @@ channel_input_data(int type, u_int32_t seq, void *ctxt)
if (c->datagram)
buffer_put_string(&c->output, data, data_len);
else {
#if(1)//ndef WIN32_FIXME
#if(0)//ndef WIN32_FIXME
buffer_append(&c->output, data, data_len);
#else
if ( c->client_tty )
telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
buffer_append(&c->output, data, data_len);
//telProcessNetwork ( data, data_len ); // run it by ANSI engine if it is the ssh client
else {
#ifdef WIN32_PRAGMA_REMCON
buffer_append(&c->output, data, data_len); // it is the sshd server, so pass it on

View File

@ -1523,7 +1523,7 @@ client_simple_escape_filter(Channel *c, char *buf, int len)
#ifdef WIN32_FIXME
u_char * client_ansi_parser_filter(Channel *c, u_char **buf, u_int *len) {
/* TODO - account fo error/extended stream*/
if (isatty(c->wfd)) {
if (c->client_tty) {
telProcessNetwork(buffer_ptr(&c->output), buffer_len(&c->output));
buffer_clear(&c->output);
buffer_append(&c->output, " \b", 2);

View File

@ -590,16 +590,17 @@ fileio_close(struct w32_io* pio) {
CancelIo(pio->handle);
//let queued APCs (if any) drain
SleepEx(0, TRUE);
if (pio->type != STD_IO_FD) //STD handles are never explicitly closed
if (pio->type != STD_IO_FD) {//STD handles are never explicitly closed
CloseHandle(pio->handle);
if (pio->read_details.buf)
free(pio->read_details.buf);
if (pio->read_details.buf)
free(pio->read_details.buf);
if (pio->write_details.buf)
free(pio->write_details.buf);
if (pio->write_details.buf)
free(pio->write_details.buf);
free(pio);
free(pio);
}
return 0;
}

View File

@ -108,12 +108,12 @@ typedef void(*sighandler_t)(int);
int w32_temp_DelChildToWatch(HANDLE processtowatch);
int w32_temp_AddChildToWatch(HANDLE processtowatch);
HANDLE w32_fd_to_handle(int fd);
int w32_allocate_fd_for_handle(HANDLE h);
int w32_allocate_fd_for_handle(HANDLE h, BOOL is_sock);
/* temporary definitions to aid in transition */
#define WSHELPDelChildToWatch(a) w32_temp_DelChildToWatch((a))
#define WSHELPAddChildToWatch(a) w32_temp_AddChildToWatch((a))
#define sfd_to_handle(a) w32_fd_to_handle((a))
#define allocate_sfd(a) w32_allocate_fd_for_handle((a))
#define allocate_sfd(a, b) w32_allocate_fd_for_handle((a, b))
//#define WSHELPwopen(a, b) w32_open((a, b))

View File

@ -693,7 +693,7 @@ w32_fd_to_handle(int fd) {
return fd_table.w32_ios[fd]->handle;
}
int w32_allocate_fd_for_handle(HANDLE h) {
int w32_allocate_fd_for_handle(HANDLE h, BOOL is_sock) {
int min_index = fd_table_get_min_index();
struct w32_io* pio;
@ -708,7 +708,7 @@ int w32_allocate_fd_for_handle(HANDLE h) {
}
memset(pio, 0, sizeof(struct w32_io));
pio->type = FILE_FD;
pio->type = is_sock? SOCK_FD : FILE_FD;
pio->handle = h;
fd_table_set(pio, min_index);
return min_index;

54
sshd.c
View File

@ -1699,6 +1699,32 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
startups++;
break;
}
/*
* Got connection. Fork a child to handle it, unless
* we are in debugging mode.
*/
if (debug_flag) {
/*
* In debugging mode. Close the listening
* socket, and start processing the
* connection without forking.
*/
debug("Server will not fork when running in debugging mode.");
close_listen_socks();
*sock_in = *newsock;
*sock_out = *newsock;
close(startup_p[0]);
close(startup_p[1]);
startup_pipe = -1;
pid = getpid();
if (rexec_flag) {
send_rexec_state(config_s[0],
&cfg);
close(config_s[0]);
}
break;
}
#ifdef WIN32_FIXME
/*
@ -1770,32 +1796,6 @@ server_accept_loop(int *sock_in, int *sock_out, int *newsock, int *config_s)
*/
/*
* Got connection. Fork a child to handle it, unless
* we are in debugging mode.
*/
if (debug_flag) {
/*
* In debugging mode. Close the listening
* socket, and start processing the
* connection without forking.
*/
debug("Server will not fork when running in debugging mode.");
close_listen_socks();
*sock_in = *newsock;
*sock_out = *newsock;
close(startup_p[0]);
close(startup_p[1]);
startup_pipe = -1;
pid = getpid();
if (rexec_flag) {
send_rexec_state(config_s[0],
&cfg);
close(config_s[0]);
}
break;
}
/*
* Normal production daemon. Fork, and have
* the child process the connection. The
@ -2820,7 +2820,7 @@ main(int ac, char **av)
int remotesochandle ;
remotesochandle = atoi( getenv("SSHD_REMSOC") );
sock_in = sock_out = newsock = allocate_sfd(remotesochandle) ; //si.hStdInput);
sock_in = sock_out = newsock = w32_allocate_fd_for_handle(remotesochandle, TRUE) ; //si.hStdInput);
// we have the socket handle, delete it for child processes we create like shell
SetEnvironmentVariable("SSHD_REMSOC", NULL);