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); }
static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf, DATA_BLOB blob, NTSTATUS nt_status) { char *p; if (!NT_STATUS_IS_OK(nt_status) && !NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { ERROR_NT(nt_status_squash(nt_status)); } else { set_message(outbuf,4,0,True); nt_status = nt_status_squash(nt_status); SIVAL(outbuf, smb_rcls, NT_STATUS_V(nt_status)); SSVAL(outbuf, smb_vwv0, 0xFF); /* no chaining possible */ SSVAL(outbuf, smb_vwv3, blob.length); p = smb_buf(outbuf); /* should we cap this? */ memcpy(p, blob.data, blob.length); p += blob.length; p += add_signature( outbuf, p ); set_message_end(outbuf,p); } show_msg(outbuf); return send_smb(smbd_server_fd(),outbuf); }
static void send_blocking_reply(char *outbuf, int outsize) { if(outsize > 4) smb_setlen(outbuf,outsize - 4); if (!send_smb(smbd_server_fd(),outbuf)) exit_server("send_blocking_reply: send_smb failed."); }
static void generic_blocking_lock_error(blocking_lock_record *blr, NTSTATUS status) { char *outbuf = OutBuffer; char *inbuf = blr->inbuf; construct_reply_common(inbuf, outbuf); /* whenever a timeout is given w2k maps LOCK_NOT_GRANTED to FILE_LOCK_CONFLICT! (tridge) */ if (NT_STATUS_EQUAL(status, NT_STATUS_LOCK_NOT_GRANTED)) { status = NT_STATUS_FILE_LOCK_CONFLICT; } ERROR_NT(status); if (!send_smb(smbd_server_fd(),outbuf)) exit_server("generic_blocking_lock_error: send_smb failed."); }
/**************************************************************************** check for existance of a dir ****************************************************************************/ static BOOL chkpath(char *path,BOOL report) { pstring path2; pstring inbuf,outbuf; char *p; pstrcpy(path2,path); trim_string(path2,NULL,"\\"); if (!*path2) *path2 = '\\'; bzero(outbuf,smb_size); set_message(outbuf,0,4 + strlen(path2),True); SCVAL(outbuf,smb_com,SMBchkpth); SSVAL(outbuf,smb_tid,cnum); cli_setup_pkt(outbuf); p = smb_buf(outbuf); *p++ = 4; pstrcpy(p,path2); #if 0 { /* this little bit of code can be used to extract NT error codes. Just feed a bunch of "cd foo" commands to smbclient then watch in netmon (tridge) */ static int code=0; SIVAL(outbuf, smb_rcls, code | 0xC0000000); SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | (1<<14)); code++; } #endif send_smb(Client,outbuf); client_receive_smb(Client,inbuf,CLIENT_TIMEOUT); if (report && CVAL(inbuf,smb_rcls) != 0) DEBUG(2,("chkpath: %s\n",smb_errstr(inbuf))); return(CVAL(inbuf,smb_rcls) == 0); }
static BOOL reply_sesssetup_blob(connection_struct *conn, char *outbuf, DATA_BLOB blob, NTSTATUS nt_status) { char *p; set_message(outbuf,4,0,True); nt_status = nt_status_squash(nt_status); SIVAL(outbuf, smb_rcls, NT_STATUS_V(nt_status)); SSVAL(outbuf, smb_vwv0, 0xFF); /* no chaining possible */ SSVAL(outbuf, smb_vwv3, blob.length); p = smb_buf(outbuf); /* should we cap this? */ memcpy(p, blob.data, blob.length); p += blob.length; p += add_signature( outbuf, p ); set_message_end(outbuf,p); return send_smb(smbd_server_fd(),outbuf); }
/**************************************************************************** process an smb from the client - split out from the process() code so it can be used by the oplock break code. ****************************************************************************/ void process_smb(char *inbuf, char *outbuf, int ProcSockID, int threadid) { // extern int Client; #ifdef WITH_SSL #endif /* WITH_SSL */ int msg_type = CVAL(inbuf,0); int32 len = smb_len(inbuf); int nread = len + 4; #ifdef WITH_PROFILE profile_p->smb_count++; #endif #ifdef WITH_VTP if(trans_num == 1 && VT_Check(inbuf)) { VT_Process(); return; } #endif if(msg_type == 0x85) return; /* Keepalive packet. */ nread = construct_reply(inbuf,outbuf,nread,max_send[threadid], ProcSockID ,threadid ); if(nread > 0) { if (nread != smb_len(outbuf) + 4) { } else send_smb(ProcSockID,outbuf); } }
static void filter_child(int c, struct sockaddr_storage *dest_ss) { NTSTATUS status; int s = -1; char packet[128*1024]; /* we have a connection from a new client, now connect to the server */ status = open_socket_out(dest_ss, TCP_SMB_PORT, LONG_CONNECT_TIMEOUT, &s); if (!NT_STATUS_IS_OK(status)) { char addr[INET6_ADDRSTRLEN]; if (dest_ss) { print_sockaddr(addr, sizeof(addr), dest_ss); } d_printf("Unable to connect to %s (%s)\n", dest_ss?addr:"NULL", nt_errstr(status)); exit(1); } while (c != -1 || s != -1) { struct pollfd fds[2]; int num_fds, ret; memset(fds, 0, sizeof(struct pollfd) * 2); fds[0].fd = -1; fds[1].fd = -1; num_fds = 0; if (s != -1) { fds[num_fds].fd = s; fds[num_fds].events = POLLIN|POLLHUP; num_fds += 1; } if (c != -1) { fds[num_fds].fd = c; fds[num_fds].events = POLLIN|POLLHUP; num_fds += 1; } ret = sys_poll_intr(fds, num_fds, -1); if (ret <= 0) { continue; } /* * find c in fds and see if it's readable */ if ((c != -1) && (((fds[0].fd == c) && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) || ((fds[1].fd == c) && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) { size_t len; if (!NT_STATUS_IS_OK(receive_smb_raw( c, packet, sizeof(packet), 0, 0, &len))) { d_printf("client closed connection\n"); exit(0); } filter_request(packet, len); if (!send_smb(s, packet)) { d_printf("server is dead\n"); exit(1); } } /* * find s in fds and see if it's readable */ if ((s != -1) && (((fds[0].fd == s) && (fds[0].revents & (POLLIN|POLLHUP|POLLERR))) || ((fds[1].fd == s) && (fds[1].revents & (POLLIN|POLLHUP|POLLERR))))) { size_t len; if (!NT_STATUS_IS_OK(receive_smb_raw( s, packet, sizeof(packet), 0, 0, &len))) { 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); }