static void filter_child(int c, struct in_addr dest_ip) { int s; /* we have a connection from a new client, now connect to the server */ s = open_socket_out(SOCK_STREAM, &dest_ip, 445, LONG_CONNECT_TIMEOUT); if (s == -1) { d_printf("Unable to connect to %s\n", inet_ntoa(dest_ip)); exit(1); } while (c != -1 || s != -1) { fd_set fds; int num; FD_ZERO(&fds); if (s != -1) FD_SET(s, &fds); if (c != -1) FD_SET(c, &fds); num = sys_select_intr(MAX(s+1, c+1),&fds,NULL,NULL,NULL); if (num <= 0) continue; if (c != -1 && FD_ISSET(c, &fds)) { if (!receive_smb(c, packet, BUFFER_SIZE, 0)) { d_printf("client closed connection\n"); exit(0); } filter_request(packet); if (!send_smb(s, packet)) { d_printf("server is dead\n"); exit(1); } } if (s != -1 && FD_ISSET(s, &fds)) { if (!receive_smb(s, packet, BUFFER_SIZE, 0)) { d_printf("server closed connection\n"); exit(0); } filter_reply(packet); if (!send_smb(c, packet)) { d_printf("client is dead\n"); exit(1); } } } d_printf("Connection closed\n"); exit(0); }
/**************************************************************************** wait for keyboard activity, swallowing network packets ****************************************************************************/ static void wait_keyboard(struct cli_state *cli) { fd_set fds; struct timeval timeout; while (1) { FD_ZERO(&fds); FD_SET(cli->fd,&fds); FD_SET(fileno(stdin),&fds); timeout.tv_sec = 20; timeout.tv_usec = 0; sys_select(MAX(cli->fd,fileno(stdin))+1,&fds,&timeout); if (FD_ISSET(fileno(stdin),&fds)) return; /* We deliberately use receive_smb instead of client_receive_smb as we want to receive session keepalives and then drop them here. */ if (FD_ISSET(cli->fd,&fds)) receive_smb(cli->fd,cli->inbuf,0); } }
static int receive_message_or_smb(char *buffer, int buffer_len, //Jesse int *got_smb, int ProcSockID, int threadid) int *got_smb, int fd, int threadid) { int ProcSockID = fd; fd_set fds; *got_smb = False; /* * Setup the select read fd set. */ FD_SET(ProcSockID,&fds); if (FD_ISSET(ProcSockID,&fds)) { *got_smb = True; return receive_smb(ProcSockID, buffer, 0, threadid); } }
BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout) { BOOL ret; for(;;) { ret = receive_smb(fd, buffer, timeout); if (!ret) { DEBUG(10,("client_receive_smb failed\n")); show_msg(buffer); return ret; } /* Ignore session keepalive packets. */ if(CVAL(buffer,0) != 0x85) break; } show_msg(buffer); return ret; }
static void wait_keyboard(char *buffer) #endif { fd_set fds; int selrtn; struct timeval timeout; #ifdef CLIX int delay = 0; #endif while (1) { extern int Client; FD_ZERO(&fds); FD_SET(Client,&fds); #ifndef CLIX FD_SET(fileno(stdin),&fds); #endif timeout.tv_sec = 20; timeout.tv_usec = 0; #ifdef CLIX timeout.tv_sec = 0; #endif selrtn = sys_select(&fds,&timeout); #ifndef CLIX if (FD_ISSET(fileno(stdin),&fds)) return; #else { char ch; int readret; set_blocking(fileno(stdin), False); readret = read_data( fileno(stdin), &ch, 1); set_blocking(fileno(stdin), True); if (readret == -1) { if (errno != EAGAIN) { /* should crash here */ DEBUG(1,("readchar stdin failed\n")); } } else if (readret != 0) { return ch; } } #endif /* We deliberately use receive_smb instead of client_receive_smb as we want to receive session keepalives and then drop them here. */ if (FD_ISSET(Client,&fds)) receive_smb(Client,buffer,0); #ifdef CLIX delay++; if (delay > 100000) { delay = 0; chkpath("\\",False); } #else chkpath("\\",False); #endif } }