author | Michael Krelin <hacker@klever.net> | 2006-10-13 20:52:05 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-10-13 20:52:05 (UTC) |
commit | c47fbc86d50a0199fe9000a7df07609bb0a3bc77 (patch) (unidiff) | |
tree | 87da1735014b97ce01ac754adc5843ecde33cd97 | |
parent | 325e7fc43721df3efaa8539190fada6e6e3aa8fa (diff) | |
download | pumpkin-c47fbc86d50a0199fe9000a7df07609bb0a3bc77.zip pumpkin-c47fbc86d50a0199fe9000a7df07609bb0a3bc77.tar.gz pumpkin-c47fbc86d50a0199fe9000a7df07609bb0a3bc77.tar.bz2 |
Increased default blocksize and added reject with explicit error message for
WRQ request in case I can see the file is too big for us.
git-svn-id: http://svn.klever.net/kin/pumpkin/trunk@193 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | PumpKINDlg.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/PumpKINDlg.cpp b/PumpKINDlg.cpp index bb15211..f41b69f 100644 --- a/PumpKINDlg.cpp +++ b/PumpKINDlg.cpp | |||
@@ -75,49 +75,49 @@ BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) | |||
75 | //}}AFX_MSG_MAP | 75 | //}}AFX_MSG_MAP |
76 | END_MESSAGE_MAP() | 76 | END_MESSAGE_MAP() |
77 | 77 | ||
78 | ///////////////////////////////////////////////////////////////////////////// | 78 | ///////////////////////////////////////////////////////////////////////////// |
79 | // CPumpKINDlg dialog | 79 | // CPumpKINDlg dialog |
80 | 80 | ||
81 | CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) | 81 | CPumpKINDlg::CPumpKINDlg(CWnd* pParent /*=NULL*/) |
82 | : CDialog(CPumpKINDlg::IDD, pParent), m_MinSize(0,0) | 82 | : CDialog(CPumpKINDlg::IDD, pParent), m_MinSize(0,0) |
83 | { | 83 | { |
84 | m_Listener.m_Daddy = this; | 84 | m_Listener.m_Daddy = this; |
85 | 85 | ||
86 | m_bListen = TRUE; | 86 | m_bListen = TRUE; |
87 | 87 | ||
88 | m_ListenPort = 69; | 88 | m_ListenPort = 69; |
89 | m_bTFTPSubdirs = TRUE; | 89 | m_bTFTPSubdirs = TRUE; |
90 | m_RRQMode = rrqAlwaysConfirm; | 90 | m_RRQMode = rrqAlwaysConfirm; |
91 | m_WRQMode = wrqAlwaysConfirm; | 91 | m_WRQMode = wrqAlwaysConfirm; |
92 | m_TFTPTimeOut = CTimeSpan(0,0,0,30); | 92 | m_TFTPTimeOut = CTimeSpan(0,0,0,30); |
93 | m_RetryTimeOut = CTimeSpan(0,0,0,10); | 93 | m_RetryTimeOut = CTimeSpan(0,0,0,10); |
94 | m_LogLength = 100; | 94 | m_LogLength = 100; |
95 | m_SpeakPort = 69; | 95 | m_SpeakPort = 69; |
96 | m_PromptTimeOut=30; | 96 | m_PromptTimeOut=30; |
97 | m_bShown=TRUE; | 97 | m_bShown=TRUE; |
98 | m_bExiting=FALSE; | 98 | m_bExiting=FALSE; |
99 | m_BlockSize=1024; | 99 | m_BlockSize=2048; |
100 | m_bnw.AssignSound("(bang)",IDR_WAVE_RING,CBellsNWhistles::CBang::bangResource); | 100 | m_bnw.AssignSound("(bang)",IDR_WAVE_RING,CBellsNWhistles::CBang::bangResource); |
101 | m_bnw.AssignSound("(done)",IDR_WAVE_FINISHED,CBellsNWhistles::CBang::bangResource); | 101 | m_bnw.AssignSound("(done)",IDR_WAVE_FINISHED,CBellsNWhistles::CBang::bangResource); |
102 | m_bnw.AssignSound("(oops)",IDR_WAVE_ABORTED,CBellsNWhistles::CBang::bangResource); | 102 | m_bnw.AssignSound("(oops)",IDR_WAVE_ABORTED,CBellsNWhistles::CBang::bangResource); |
103 | m_bnw.AssignSound("(none)",(int)0,CBellsNWhistles::CBang::bangNone); | 103 | m_bnw.AssignSound("(none)",(int)0,CBellsNWhistles::CBang::bangNone); |
104 | m_bnwRequest="(bang)"; m_bnwSuccess="(done)"; | 104 | m_bnwRequest="(bang)"; m_bnwSuccess="(done)"; |
105 | m_bnwAbort="(oops)"; | 105 | m_bnwAbort="(oops)"; |
106 | //{{AFX_DATA_INIT(CPumpKINDlg) | 106 | //{{AFX_DATA_INIT(CPumpKINDlg) |
107 | //}}AFX_DATA_INIT | 107 | //}}AFX_DATA_INIT |
108 | // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 | 108 | // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 |
109 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); | 109 | m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); |
110 | m_bmpBack.LoadBitmap(IDB_BACKGROUND); | 110 | m_bmpBack.LoadBitmap(IDB_BACKGROUND); |
111 | m_bmpBack.GetBitmap(&m_bitmapBack); | 111 | m_bmpBack.GetBitmap(&m_bitmapBack); |
112 | m_Retrier = new CRetrier(this); | 112 | m_Retrier = new CRetrier(this); |
113 | ASSERT(m_Retrier); | 113 | ASSERT(m_Retrier); |
114 | m_Trayer = new CTrayer(this); | 114 | m_Trayer = new CTrayer(this); |
115 | ASSERT(m_Trayer); | 115 | ASSERT(m_Trayer); |
116 | /* Ensure we're backwards compatible */ | 116 | /* Ensure we're backwards compatible */ |
117 | ASSERT(CPumpKINDlg::rrqGiveAll==0); | 117 | ASSERT(CPumpKINDlg::rrqGiveAll==0); |
118 | ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1); | 118 | ASSERT(CPumpKINDlg::rrqAlwaysConfirm==1); |
119 | ASSERT(CPumpKINDlg::rrqDenyAll==2); | 119 | ASSERT(CPumpKINDlg::rrqDenyAll==2); |
120 | ASSERT(CPumpKINDlg::wrqTakeAll==0); | 120 | ASSERT(CPumpKINDlg::wrqTakeAll==0); |
121 | ASSERT(CPumpKINDlg::wrqConfirmIfExists==1); | 121 | ASSERT(CPumpKINDlg::wrqConfirmIfExists==1); |
122 | ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2); | 122 | ASSERT(CPumpKINDlg::wrqAlwaysConfirm==2); |
123 | ASSERT(CPumpKINDlg::wrqDenyAll==3); | 123 | ASSERT(CPumpKINDlg::wrqDenyAll==3); |
@@ -1012,48 +1012,52 @@ BOOL CWRQSocket::OnTFTP(tftp* p) | |||
1012 | if(m_bResume) | 1012 | if(m_bResume) |
1013 | m_ACK=m_File.GetLength()/m_blkSize; | 1013 | m_ACK=m_File.GetLength()/m_blkSize; |
1014 | else | 1014 | else |
1015 | m_ACK=0; | 1015 | m_ACK=0; |
1016 | tftp::tftpOptions o; | 1016 | tftp::tftpOptions o; |
1017 | if(p->GetOptions(&o)){ | 1017 | if(p->GetOptions(&o)){ |
1018 | CString v; | 1018 | CString v; |
1019 | if(o.Lookup(tftpoBSize,v)){ | 1019 | if(o.Lookup(tftpoBSize,v)){ |
1020 | m_blkSize=atoi(v); | 1020 | m_blkSize=atoi(v); |
1021 | if(!m_blkSize){// *** More sanity checks | 1021 | if(!m_blkSize){// *** More sanity checks |
1022 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); | 1022 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); |
1023 | return TRUE; | 1023 | return TRUE; |
1024 | } | 1024 | } |
1025 | } | 1025 | } |
1026 | if(o.Lookup(tftpoTOut,v)){ | 1026 | if(o.Lookup(tftpoTOut,v)){ |
1027 | m_timeOut=atoi(v); | 1027 | m_timeOut=atoi(v); |
1028 | if(!m_timeOut){// *** More sanity checks | 1028 | if(!m_timeOut){// *** More sanity checks |
1029 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); | 1029 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); |
1030 | return TRUE; | 1030 | return TRUE; |
1031 | } | 1031 | } |
1032 | } | 1032 | } |
1033 | if(o.Lookup(tftpoTSize,v)){ | 1033 | if(o.Lookup(tftpoTSize,v)){ |
1034 | m_xferSize=atoi(v); | 1034 | m_xferSize=atoi(v); |
1035 | } | 1035 | } |
1036 | if(m_xferSize>=0 && m_xferSize>=(m_blkSize<<16)) { | ||
1037 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); | ||
1038 | return TRUE; | ||
1039 | } | ||
1036 | } | 1040 | } |
1037 | UpdateList(); | 1041 | UpdateList(); |
1038 | DoXfer(); | 1042 | DoXfer(); |
1039 | } | 1043 | } |
1040 | break; | 1044 | break; |
1041 | case tftp::opDATA: | 1045 | case tftp::opDATA: |
1042 | { | 1046 | { |
1043 | UINTblock = p->data.m_DATA.Block(); | 1047 | UINTblock = p->data.m_DATA.Block(); |
1044 | TRY{ | 1048 | TRY{ |
1045 | m_File.Seek((block-1)*m_blkSize,CFile::begin); | 1049 | m_File.Seek((block-1)*m_blkSize,CFile::begin); |
1046 | int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); | 1050 | int bytes = p->length-sizeof(p->data.m_DATA.block)-(tftpHdrSize-tftpSlackSize); |
1047 | if(bytes){ | 1051 | if(bytes){ |
1048 | m_File.Write(p->data.m_DATA.data,bytes); | 1052 | m_File.Write(p->data.m_DATA.data,bytes); |
1049 | // *** Move to the other place where we can do it not that often | 1053 | // *** Move to the other place where we can do it not that often |
1050 | m_File.SetLength(m_File.GetPosition()); | 1054 | m_File.SetLength(m_File.GetPosition()); |
1051 | } | 1055 | } |
1052 | if(bytes<m_blkSize){ | 1056 | if(bytes<m_blkSize){ |
1053 | state=stateFinish; | 1057 | state=stateFinish; |
1054 | ASSERT(m_Daddy); | 1058 | ASSERT(m_Daddy); |
1055 | CString tmp; | 1059 | CString tmp; |
1056 | tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); | 1060 | tmp.Format(IDS_LOG_XFERWRQFINISHED,(LPCTSTR)m_FileName); |
1057 | m_Daddy->LogLine(tmp); | 1061 | m_Daddy->LogLine(tmp); |
1058 | } | 1062 | } |
1059 | m_ACK=block; | 1063 | m_ACK=block; |
@@ -1388,48 +1392,53 @@ tftp::tftpOptions oack; | |||
1388 | if(m_Options.Lookup(tftpoBSize,v)){ | 1392 | if(m_Options.Lookup(tftpoBSize,v)){ |
1389 | m_blkSize=atoi(v); | 1393 | m_blkSize=atoi(v); |
1390 | if(!m_blkSize){// *** Do more about sanity check | 1394 | if(!m_blkSize){// *** Do more about sanity check |
1391 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); | 1395 | Deny(tftp::errOption,IDS_TFTP_ERROR_BSIZE); |
1392 | return TRUE; | 1396 | return TRUE; |
1393 | } | 1397 | } |
1394 | v.Format("%u",m_blkSize); | 1398 | v.Format("%u",m_blkSize); |
1395 | oack[tftpoBSize]=v; | 1399 | oack[tftpoBSize]=v; |
1396 | } | 1400 | } |
1397 | if(m_Options.Lookup(tftpoTOut,v)){ | 1401 | if(m_Options.Lookup(tftpoTOut,v)){ |
1398 | m_timeOut=atoi(v); | 1402 | m_timeOut=atoi(v); |
1399 | if(!m_timeOut){// *** Do more about sanity check | 1403 | if(!m_timeOut){// *** Do more about sanity check |
1400 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); | 1404 | Deny(tftp::errOption,IDS_TFTP_ERROR_TOUT); |
1401 | return TRUE; | 1405 | return TRUE; |
1402 | } | 1406 | } |
1403 | v.Format("%u",m_timeOut); | 1407 | v.Format("%u",m_timeOut); |
1404 | oack[tftpoTOut]=v; | 1408 | oack[tftpoTOut]=v; |
1405 | } | 1409 | } |
1406 | if(m_Options.Lookup(tftpoXResume,v) && m_bResume){ | 1410 | if(m_Options.Lookup(tftpoXResume,v) && m_bResume){ |
1407 | m_ACK=m_File.GetLength()/m_blkSize; | 1411 | m_ACK=m_File.GetLength()/m_blkSize; |
1408 | v.Format("%u",m_ACK); | 1412 | v.Format("%u",m_ACK); |
1409 | oack[tftpoXResume]=v; | 1413 | oack[tftpoXResume]=v; |
1410 | }else | 1414 | }else |
1411 | m_ACK=0; | 1415 | m_ACK=0; |
1416 | // XXX: see if we can negotiate the right block size somehow | ||
1417 | if(m_xferSize>=0 && m_xferSize>=(m_blkSize<<16)) { | ||
1418 | Deny(tftp::errUndefined,IDS_TFTP_ERROR_TOOBIG); | ||
1419 | return TRUE; | ||
1420 | } | ||
1412 | state=stateXfer; | 1421 | state=stateXfer; |
1413 | if(oack.GetCount()){ | 1422 | if(oack.GetCount()){ |
1414 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack)); | 1423 | tftp *p = tftp::Allocate(tftp::tftpOACK::tftpSize(&oack)); |
1415 | ASSERT(p); | 1424 | ASSERT(p); |
1416 | p->SetOpcode(tftp::opOACK); | 1425 | p->SetOpcode(tftp::opOACK); |
1417 | p->data.m_OACK.Set(&oack); | 1426 | p->data.m_OACK.Set(&oack); |
1418 | PostTFTP(p,TRUE); | 1427 | PostTFTP(p,TRUE); |
1419 | }else | 1428 | }else |
1420 | DoXfer(); | 1429 | DoXfer(); |
1421 | return TRUE; | 1430 | return TRUE; |
1422 | } | 1431 | } |
1423 | 1432 | ||
1424 | BOOL CWRQSocket::ConfirmRequest() | 1433 | BOOL CWRQSocket::ConfirmRequest() |
1425 | { | 1434 | { |
1426 | CConfirmWRQDlg cd(NULL); | 1435 | CConfirmWRQDlg cd(NULL); |
1427 | cd.m_Daddy=this; | 1436 | cd.m_Daddy=this; |
1428 | cd.m_File=m_FileName; | 1437 | cd.m_File=m_FileName; |
1429 | cd.m_Host=inet_ntoa(m_Peer.sin_addr); | 1438 | cd.m_Host=inet_ntoa(m_Peer.sin_addr); |
1430 | switch(cd.DoModal()){ | 1439 | switch(cd.DoModal()){ |
1431 | case IDOK: | 1440 | case IDOK: |
1432 | m_Rename=FALSE; | 1441 | m_Rename=FALSE; |
1433 | m_bResume=FALSE; | 1442 | m_bResume=FALSE; |
1434 | return TRUE; | 1443 | return TRUE; |
1435 | case IDC_RENAME: | 1444 | case IDC_RENAME: |