[Iscs-developers] ISCS/spm/src pepform.cpp,1.7,1.8 pepform.h,1.5,1.6 spmmainform.cpp,1.84,1.85
Status: Beta
Brought to you by:
jsulliva
From: <jsu...@us...> - 2003-12-30 21:10:01
|
Update of /cvsroot/iscs/ISCS/spm/src In directory sc8-pr-cvs1:/tmp/cvs-serv24489/spm/src Modified Files: pepform.cpp pepform.h spmmainform.cpp Log Message: Added PEP input validation for: Route network address is a base network address NAT Network address is a base network address detect duplicate networks Since we allow duplicate networks, removed primary key from protected_networks based upon network + netmask - replaced with index on network lowbinary field in protected_networks now used for base network address in both direct and indirect networks Index: pepform.cpp =================================================================== RCS file: /cvsroot/iscs/ISCS/spm/src/pepform.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** pepform.cpp 30 Dec 2003 06:07:33 -0000 1.7 --- pepform.cpp 30 Dec 2003 21:09:56 -0000 1.8 *************** *** 33,37 **** #include "iputilities.h" #include "so.h" - //#include "pepformtableitems.h" #include "specialtableitems.h" --- 33,36 ---- *************** *** 96,100 **** connect( PEPRouteTable, SIGNAL( contextMenuRequested(int,int,const QPoint&) ), this, SLOT( routePopup(int,int,const QPoint&) ) ); connect( PEPRouteTable, SIGNAL( currentChanged(int, int) ), this, SLOT( routeCurrentChanged(int, int) ) ); - connect( this, SIGNAL(about2EditTableItem(QTable*, const int, const int, const QString& )), this, SLOT(beginTableEdit(QTable*, const int, const int, const QString& )) ); } //====================================================== --- 95,98 ---- *************** *** 223,238 **** //====================================================== - void PEPForm::beginTableEdit( QTable * Table, const int Row, const int Col, const QString & Text ) - { - PreviousTIText = Text; - if ( (Table == PEPRouteTable && Col == 12) || (Table == PrivateIFTable && Col == 10) ) { // We are about to edit the NAT Net address - if ( Table->text(Row, 3).isEmpty() ) { // i.e., the netmask field is blank - QMessageBox::warning(this, tr("SPM - Missing NetMask"), tr("The NetMask field must be completed before\nthe Internal NAT Address can be entered") ); - Table->setCurrentCell(Row, 3); - } - } - } - //====================================================== - void PEPForm::deleteDNS() { --- 221,224 ---- *************** *** 424,427 **** --- 410,439 ---- //====================================================== + QString PEPForm::duplicateNetworks( const QString & Base, const QString & Mask) + { + QString PEPs; + so->Sql = "select count(pep) from protected_networks where lowbinary=" + QString::number( IPUtils->dotDec2Bin(Base) ) + " and netmask='" + Mask + "';"; + if ( ! so->sqlExec(so->SQEdit2, "protected_networks") ) { + QMessageBox::information(this, tr("SPM - Database Communications Failure"), tr("We were unable to ensure that the NAT\nNetwork Address is unique.\nWe will proceed under the assumption that it is.") ); + return PEPs; + } + else { + so->SQEdit2->next(); + if ( so->SQEdit2->value(0).toInt() ) { // i.e., there is a duplicate + so->Sql = "select pep from protected_networks where lowbinary=" + QString::number( IPUtils->dotDec2Bin(Base) ) + " and netmask='" + Mask + "';"; + if ( so->sqlExec(so->SQEdit2, "protected_networks") ) { + while ( so->SQEdit2->next() ) { + PEPs += "\n" + so->SQEdit2->value(0).toString(); + } + } + else { + PEPs = "\nDatabase Communications Failure!\ncould not determine PEPs for duplicate networks"; + } + } + } + return PEPs; + } + //====================================================== + void PEPForm::editDNS() { *************** *** 436,445 **** //====================================================== - void PEPForm::editorStart( QTable * Table, const int Row, const int Col, const QString & Text ) - { - emit about2EditTableItem( Table, Row, Col, Text ); - } - //====================================================== - void PEPForm::enablePrivateVPN( int row ) { --- 448,451 ---- *************** *** 538,541 **** --- 544,548 ---- void PEPForm::finalCheck() { + QString Base, Low, Mask, PEPs; if ( PEPModelComboBox->currentText().isEmpty() ) { QMessageBox::warning(this, tr("SPM - Missing Data"), tr("The Model field is blank")); *************** *** 587,593 **** return; } } for ( int i = 0; i < PEPRouteTable->numRows(); i++ ) { ! if ( PEPRouteTable->text(i, 2).isEmpty() ) { QMessageBox::warning(this, tr("SPM - Missing Network"), tr("A Network field is blank") ); PEPTabWidget->setCurrentPage(1); --- 594,614 ---- return; } + Mask = PrivateIFTable->text(i, 3); + Base = IPUtils->ip2Network(PrivateIFTable->text(i, 2), Mask); + PEPs = duplicateNetworks(Base, Mask); + if ( ! PEPs.isEmpty() ) { + PEPs = " behind:" + PEPs; + if ( QMessageBox::information(this, tr("SPM - Duplicate Network"), tr("%1/%2 already exists%3\nShall I add the network anyway?", "The first parameter is the network base address, the second is the subnet mask and the third is the list of PEPs").arg(Base).arg(Mask).arg(PEPs), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Cancel ) { + PEPTabWidget->setCurrentPage(1); + PrivateIFTable->clearSelection(); + PrivateIFTable->setCurrentCell(i, 2); + return; + } + } } for ( int i = 0; i < PEPRouteTable->numRows(); i++ ) { ! Low = PEPRouteTable->text(i, 2); ! Mask = PEPRouteTable->text(i, 3); ! if ( Low.isEmpty() ) { QMessageBox::warning(this, tr("SPM - Missing Network"), tr("A Network field is blank") ); PEPTabWidget->setCurrentPage(1); *************** *** 596,600 **** return; } ! if ( PEPRouteTable->text(i, 3).isEmpty() ) { QMessageBox::warning(this, tr("SPM - Missing NetMask"), tr("A NetMask field is blank") ); PEPTabWidget->setCurrentPage(1); --- 617,621 ---- return; } ! if ( Mask.isEmpty() ) { QMessageBox::warning(this, tr("SPM - Missing NetMask"), tr("A NetMask field is blank") ); PEPTabWidget->setCurrentPage(1); *************** *** 618,622 **** } if ( PEPRouteTable->text(i, 4).isEmpty() && ((QComboTableItem *)PEPRouteTable->item(i, 0))->currentItem() == 0 ) { // i.e., we have specified neither a gateway nor an interface ! QMessageBox::warning(this, tr("SPM - Missing Gateway"), tr("There is no gateway to the %1 network.\nYou must specify either a gateway address\nor an interface").arg(PEPRouteTable->text(i,2)) ); PEPTabWidget->setCurrentPage(1); PEPRouteTable->clearSelection(); --- 639,643 ---- } if ( PEPRouteTable->text(i, 4).isEmpty() && ((QComboTableItem *)PEPRouteTable->item(i, 0))->currentItem() == 0 ) { // i.e., we have specified neither a gateway nor an interface ! QMessageBox::warning(this, tr("SPM - Missing Gateway"), tr("There is no gateway to the %1 network.\nYou must specify either a gateway address\nor an interface").arg(Low) ); PEPTabWidget->setCurrentPage(1); PEPRouteTable->clearSelection(); *************** *** 624,627 **** --- 645,670 ---- return; } + Base = IPUtils->ip2Network( Low, Mask ); + if ( Base != Low ) { + if (QMessageBox::warning(this, tr("SPM - Invalid Network Address"), tr("%1 is a host rather than a network address\ngiven the subnet mask %2.\nShall I fix it automatically for you?").arg(Low).arg(Mask), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Ok ){ + PEPRouteTable->setText(i, 2, Base); + } + else { + PEPTabWidget->setCurrentPage(1); + PEPRouteTable->clearSelection(); + PEPRouteTable->setCurrentCell(i, 2); + return; + } + } + PEPs = duplicateNetworks(Base, Mask); + if ( ! PEPs.isEmpty() ) { + PEPs = " behind:" + PEPs; + if ( QMessageBox::information(this, tr("SPM - Duplicate Network"), tr("%1/%2 already exists%3\nShall I add the network anyway?", "The first parameter is the network base address, the second is the subnet mask and the third is the list of PEPs").arg(Base).arg(Mask).arg(PEPs), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Cancel ) { + PEPTabWidget->setCurrentPage(1); + PEPRouteTable->clearSelection(); + PEPRouteTable->setCurrentCell(i, 2); + return; + } + } } accept(); *************** *** 707,710 **** --- 750,766 ---- //====================================================== + bool PEPForm::ok2EditTI( QTable * Table, const int Row, const int Col ) + { + if ( (Table == PEPRouteTable && Col == 12) || (Table == PrivateIFTable && Col == 10) ) { // We are about to edit the NAT Net address + if ( Table->text(Row, 3).isEmpty() ) { // i.e., the netmask field is blank + QMessageBox::warning(this, tr("SPM - Missing NetMask"), tr("The NetMask field must be completed before\nthe Internal NAT Address can be entered") ); + Table->setCurrentCell(Row, 3); + return false; + } + } + return true; + } + //====================================================== + void PEPForm::pEPTabChanged() { *************** *** 733,737 **** { bool Success; ! QString Base, Low, High; switch (col) { case 2 : --- 789,793 ---- { bool Success; ! QString Base, Low, High, Mask, PEPs; switch (col) { case 2 : *************** *** 790,793 **** --- 846,850 ---- case 10 : Low = PrivateIFTable->text(row, 10); + Mask = PrivateIFTable->text(row, 3); if ( ! Low.isEmpty() && Low.find(IPUtils->rxip) == -1 ) { QMessageBox::warning(this, tr("SPM - Incomplete NAT Network"), tr("The NAT Network field is incomplete") ); *************** *** 807,810 **** --- 864,876 ---- } } + PEPs = duplicateNetworks(Base, Mask); + if ( ! PEPs.isEmpty() ) { + PEPs = " behind:" + PEPs; + if ( QMessageBox::information(this, tr("SPM - Duplicate Network"), tr("%1/%2 already exists%3\nShall I add the network anyway?", "The first parameter is the network base address, the second is the subnet mask and the third is the list of PEPs").arg(Base).arg(Mask).arg(PEPs), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Cancel ) { + OldRow = row; + OldCol = 10; + return; + } + } break; default : *************** *** 832,835 **** --- 898,902 ---- if ( OldRow != -1 ) { // the previous Cell does not want to be left, e.g., it has invalid data PrivateIFTable->setCurrentCell(OldRow, OldCol ); + PrivateIFTable->editCell(OldRow, OldCol ); OldRow = OldCol = -1; } *************** *** 914,917 **** --- 981,985 ---- if ( OldRow != -1 ) { // the previous Cell does not want to be left, e.g., it has invalid data PublicIFTable->setCurrentCell(OldRow, OldCol ); + PublicIFTable->editCell(OldRow, OldCol ); OldRow = OldCol = -1; } *************** *** 980,984 **** { bool Success; ! QString Base, Low, High; switch (col) { case 2 : --- 1048,1052 ---- { bool Success; ! QString Base, Low, High, Mask, PEPs; switch (col) { case 2 : *************** *** 1083,1086 **** --- 1151,1155 ---- case 12 : Low = PEPRouteTable->text(row, 12); + Mask = PEPRouteTable->text(row, 3); if ( ! Low.isEmpty() && Low.find(IPUtils->rxip) == -1 ) { QMessageBox::warning(this, tr("SPM - Incomplete NAT Network"), tr("The NAT Network field is incomplete") ); *************** *** 1089,1093 **** return; } ! Base = IPUtils->ip2Network( Low, PEPRouteTable->text(row, 3) ); if ( Base != Low ) { if ( QMessageBox::warning(this, tr("SPM - Invalid NAT Network Address"), tr("The Internal NAT Network address\ndoes not match the subnet mask.\nShall I fix it automatically for you?"), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape ) == QMessageBox::Ok ) { --- 1158,1162 ---- return; } ! Base = IPUtils->ip2Network( Low, Mask ); if ( Base != Low ) { if ( QMessageBox::warning(this, tr("SPM - Invalid NAT Network Address"), tr("The Internal NAT Network address\ndoes not match the subnet mask.\nShall I fix it automatically for you?"), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape ) == QMessageBox::Ok ) { *************** *** 1100,1105 **** } } ! if ( PEPRouteTable->text(row, col) != PreviousTIText ) { ! QMessageBox::information(this, "SPM Test", "The NAT Net has truly changed"); } break; --- 1169,1180 ---- } } ! PEPs = duplicateNetworks(Base, Mask); ! if ( ! PEPs.isEmpty() ) { ! PEPs = " behind:" + PEPs; ! if ( QMessageBox::information(this, tr("SPM - Duplicate Network"), tr("%1/%2 already exists%3\nShall I add the network anyway?", "The first parameter is the network base address, the second is the subnet mask and the third is the list of PEPs").arg(Base).arg(Mask).arg(PEPs), QMessageBox::Ok | QMessageBox::Default, QMessageBox::Cancel | QMessageBox::Escape) == QMessageBox::Cancel ) { ! OldRow = row; ! OldCol = 12; ! return; ! } } break; *************** *** 1118,1128 **** if ( OldRow != -1 ) { // the previous Cell does not want to be left, e.g., it has invalid data PEPRouteTable->setCurrentCell(OldRow, OldCol ); OldRow = OldCol = -1; } - if ( Col == 12 && PEPRouteTable->text( Row, 3).isEmpty() ) { // we are at the Net NAT cell but have not specified a subnet mask - if ( PEPRouteTable->cellWidget(Row, Col) ) { - QMessageBox::information(this, "SPM Testing", "We are editing"); - } - } } //====================================================== --- 1193,1199 ---- if ( OldRow != -1 ) { // the previous Cell does not want to be left, e.g., it has invalid data PEPRouteTable->setCurrentCell(OldRow, OldCol ); + PEPRouteTable->editCell(OldRow, OldCol ); OldRow = OldCol = -1; } } //====================================================== *************** *** 1186,1191 **** QDialog::showEvent(se); } ! ! #include "pepform.moc" --- 1257,1261 ---- QDialog::showEvent(se); } ! //====================================================== #include "pepform.moc" *************** *** 1200,1206 **** QWidget * PFIPAddrTableItem::createEditor() const { ! QWidget * Editor = IPAddrTableItem::createEditor(); ! ((PEPForm *)(table()->topLevelWidget()))->editorStart(table(), row(), col(), text()); ! return Editor; } --- 1270,1278 ---- QWidget * PFIPAddrTableItem::createEditor() const { ! if ( ! ((PEPForm *)(table()->topLevelWidget()))->ok2EditTI(table(), row(), col()) ) { ! return 0; ! } ! ((PEPForm *)(table()->topLevelWidget()))->PreviousTIText = text(); ! return IPAddrTableItem::createEditor(); } Index: pepform.h =================================================================== RCS file: /cvsroot/iscs/ISCS/spm/src/pepform.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pepform.h 30 Dec 2003 06:07:34 -0000 1.5 --- pepform.h 30 Dec 2003 21:09:56 -0000 1.6 *************** *** 52,58 **** virtual void addPrivateNetworkRow(); - signals: - virtual void about2EditTableItem( QTable * Table, const int Row, const int Col, const QString & Text ); - protected: bool lastChecked, NetNATSupport, NewPrivIF, NewRoute; --- 52,55 ---- *************** *** 62,70 **** QPopupMenu * PEPPopup; QString PreviousTIText; ! /*$PROTECTED_FUNCTIONS$*/ ! virtual void setNAPTFields(QTable * Table, int Row); virtual bool prepPEPDNSDialog(); virtual int numEths(); ! virtual void editorStart( QTable * Table, const int Row, const int Col, const QString & Text ); protected slots: --- 59,69 ---- QPopupMenu * PEPPopup; QString PreviousTIText; ! ! /*$PROTECTED_FUNCTIONS$*/ ! virtual void setNAPTFields(QTable * Table, int Row); virtual bool prepPEPDNSDialog(); + virtual bool ok2EditTI( QTable * Table, const int Row, const int Col ); virtual int numEths(); ! virtual QString duplicateNetworks( const QString & Base, const QString & Mask); protected slots: *************** *** 94,98 **** virtual void delPrivate( int row ); virtual void deleteDNS(); - virtual void beginTableEdit( QTable * Table, const int Row, const int Col, const QString & Text ); virtual void addDNS(); --- 93,96 ---- Index: spmmainform.cpp =================================================================== RCS file: /cvsroot/iscs/ISCS/spm/src/spmmainform.cpp,v retrieving revision 1.84 retrieving revision 1.85 diff -C2 -d -r1.84 -r1.85 *** spmmainform.cpp 30 Dec 2003 06:07:34 -0000 1.84 --- spmmainform.cpp 30 Dec 2003 21:09:56 -0000 1.85 *************** *** 8891,8896 **** First = First + "network='" + PEPDialog->PrivateIFTable->text( TC->CurrRow, 2 ) + "'"; // Second is already set for this field since it is the primary key ! First = First + ", lowbinary =" + QString::number(IPUtils->dotDec2Bin(PEPDialog->PrivateIFTable->text( TC->CurrRow, 2 )) ); ! Second = Second + " and lowbinary=" + QString::number(IPUtils->dotDec2Bin(PrivateIFTable->text( i, 2 )) ); } if ( PEPDialog->PrivateIFTable->text( TC->CurrRow, 3 ) != PrivateIFTable->text( i, 3 )) { // i.e., the netmask has changed --- 8891,8896 ---- First = First + "network='" + PEPDialog->PrivateIFTable->text( TC->CurrRow, 2 ) + "'"; // Second is already set for this field since it is the primary key ! First = First + ", lowbinary =" + QString::number(IPUtils->dotDec2Bin( IPUtils->ip2Network( PEPDialog->PrivateIFTable->text( TC->CurrRow, 2 ), PEPDialog->PrivateIFTable->text( TC->CurrRow, 3 ) ) ) ); ! Second = Second + " and lowbinary=" + QString::number(IPUtils->dotDec2Bin( IPUtils->ip2Network( PrivateIFTable->text( i, 2 ), PrivateIFTable->text( i, 3 )) ) ); } if ( PEPDialog->PrivateIFTable->text( TC->CurrRow, 3 ) != PrivateIFTable->text( i, 3 )) { // i.e., the netmask has changed |