void MainWindow::close_database() { QByteArray ba; if (!dbfile.isEmpty()) { ba += db::intToData(size().width()); ba += db::intToData(size().height()); ba += db::intToData(tabView->currentIndex()); db mydb(dbfile); mydb.set((const unsigned char *)ba.constData(), ba.size(), 1, setting, "mw_geometry"); } setItemEnabled(false); dbindex->clear(); keyView->setModel(NULL); reqView->setModel(NULL); certView->setModel(NULL); tempView->setModel(NULL); crlView->setModel(NULL); if (crls) delete(crls); if (reqs) delete(reqs); if (certs) delete(certs); if (temps) delete(temps); if (keys) delete(keys); reqs = NULL; certs = NULL; temps = NULL; keys = NULL; pki_evp::passwd.cleanse(); pki_evp::passwd = QByteArray(); if (!crls) return; crls = NULL; try { db mydb(dbfile); mydb.shrink( DBFLAG_OUTDATED | DBFLAG_DELETED ); } catch (errorEx &err) { MainWindow::Error(err); } pkcs11::remove_libs(); enableTokenMenu(pkcs11::loaded()); }
int main (void) { if (argv["*"].count() < 2) { usage (); return 1; } string listid = argv["*"][0]; string listowner = argv["*"][1]; string name; string subjecttag; bool moderatedsubs = false; bool moderatedposts = false; if (argv.exists ("--name")) { name = argv["--name"]; } else { name = listid.copyuntil ('@'); } if (argv.exists ("--subjecttag")) { subjecttag = argv["--subjecttag"]; } else { subjecttag = name; } if (argv.exists ("--moderate-subscriptions")) { moderatedsubs = true; } if (argv.exists ("--moderate-posts")) { moderatedposts = true; } limadb mydb (PATH_LIMADB); if (mydb.listexists (listid)) { ferr.printf ("List already exists\n"); return 1; } if (! mydb.createlist (listid, listowner, moderatedposts, moderatedsubs, name, subjecttag)) { return 1; } mailinglist mlist (mydb, listid); listmember &m = mlist.createmember (listowner); m.approved (true); m.moderator (true); return 0; }
int main(int argc, char *argv[]) { if (argc < 2) return 1; QFile::setEncodingFunction(fileNameEncoderFunc); QFile::setDecodingFunction(fileNAmeDecoderFunc); QString database = filename2QString(argv[1]); db mydb(database); unsigned char *p; db_header_t h; int i=0; char type[] = "NKRCLTSUXX"; try { mydb.first(0); while (!mydb.eof()) { p = mydb.load(&h); free(p); printf("%3d: %c V%d O:%6zd, F:%x L:%5d %s\n", i++, type[h.type], h.version, mydb.head_offset, h.flags, h.len, h.name); mydb.next(0); } } catch (errorEx &ex) { printf("Exception: '%s'\n", ex.getCString()); } }
void db_base::saveHeaderState() { QByteArray ba; if (dbName.isEmpty()) return; ba = allHeaders.toData(); db mydb(dbName); mydb.set((const unsigned char *)ba.constData(), ba.size(), 5, setting, class_name + "_hdView"); }
void db_base::updatePKI(pki_base *pki) { db mydb(dbName); QByteArray ba = pki->toData(); if (ba.count() > 0) { mydb.set((const unsigned char*)ba.constData(), ba.count(), pki->getVersion(), pki->getType(), pki->getIntName()); } }
void db_base::insertPKI(pki_base *pki) { QString name; db mydb(dbName); QByteArray ba = pki->toData(); if (ba.count() > 0) { name = mydb.uniq_name(pki->getIntName(), pkitype); pki->setIntName(name); mydb.add((const unsigned char*)ba.constData(), ba.count(), pki->getVersion(), pki->getType(), name); } inToCont(pki); emit columnsContentChanged(); }
int main (void) { if (argv["*"].count() < 1) { ferr.printf ("%% Usage: lima-remove <listid>\n"); return 1; } string listid = argv["*"][0]; limadb mydb (PATH_LIMADB); if (! mydb.deletelist (listid)) { ferr.printf ("%% Error removing list <%s>\n", listid.str()); return 1; } return 0; }
void MainWindow::undelete() { ImportMulti *dlgi = new ImportMulti(this); db_header_t head; db mydb(dbfile); for (mydb.first(DBFLAG_OUTDATED); !mydb.eof(); mydb.next(DBFLAG_OUTDATED)) { mydb.get_header(&head); if (head.flags & DBFLAG_DELETED) { pki_base *item; unsigned char *p = NULL; QString name = QString::fromUtf8(head.name); switch (head.type) { case asym_key: item = new pki_evp(name); break; case x509_req: item = new pki_x509req(name); break; case x509: item = new pki_x509(name); break; case revokation: item = new pki_crl(name); break; case tmpl: item = new pki_temp(name); break; case smartCard: item = new pki_scard(name); break; default: continue; } try { p = mydb.load(&head); item->fromData(p, &head); dlgi->addItem(item); } catch (errorEx &err) { Error(err); delete item; } free(p); } } if (dlgi->entries() > 0) { dlgi->execute(1); } else { QMessageBox::information(this, XCA_TITLE, tr("No deleted items found")); } delete dlgi; }
void db_base::deletePKI() { if (!currentIdx.isValid()) return; pki_base *pki = static_cast<pki_base*>(currentIdx.internalPointer()); try { try { pki->deleteFromToken(); } catch (errorEx &err) { MainWindow::Error(err); } remFromCont(currentIdx); db mydb(dbName); mydb.find(pki->getType(), pki->getIntName()); mydb.erase(); delete pki; } catch (errorEx &err) { MainWindow::Error(err); } }
void MainWindow::setOptions() { Options *opt = new Options(this); opt->setStringOpt(string_opt); opt->setupPkcs11Provider(pkcs11path); if (!opt->exec()) { delete opt; enableTokenMenu(pkcs11::loaded()); return; } QString alg = opt->hashAlgo->currentHashName(); db mydb(dbfile); mydb.set((const unsigned char *)CCHAR(alg), alg.length()+1, 1, setting, "default_hash"); hashBox::setDefault(alg); mandatory_dn = opt->getDnString(); mydb.set((const unsigned char *)CCHAR(mandatory_dn), mandatory_dn.length()+1, 1, setting, "mandatory_dn"); if (opt->getStringOpt() != string_opt) { string_opt = opt->getStringOpt(); ASN1_STRING_set_default_mask_asc((char *)CCHAR(string_opt)); mydb.set((const unsigned char *)CCHAR(string_opt), string_opt.length()+1, 1, setting,"string_opt"); } QString newpath = opt->getPkcs11Provider(); if (newpath != pkcs11path) { pkcs11path = newpath; mydb.set((const unsigned char *) CCHAR(pkcs11path), pkcs11path.length()+1, 1,setting, "pkcs11path"); } enableTokenMenu(pkcs11::loaded()); delete opt; }
// ================================================= MAIN ============================================== int main(int argc, char* argv[]) { // ========================================== Parameters =========================================== bool verbose = false; bool drawM = false; bool ram_db = true; bool load_k = false; std::string filename_db = ":memory:"; const char* filename_calib; const char* inputFilename_rgb; const char* outputFilename; std::vector< std::string > imageList_rgb; // ========================================== Check parameters ========================================== if( argc < 2 ) { help(); return 0; } else { for(int i = 1; i < argc; i++ ) { const char* s = argv[i]; if( strcmp( s, "-i" ) == 0 ) { i++; inputFilename_rgb = argv[i]; } else if( strcmp( s, "-db" ) == 0 ) { i++; filename_db = argv[i]; ram_db = false; } else if( strcmp( s, "-k" ) == 0 ) { i++; filename_calib = argv[i]; load_k = true; } else if( strcmp( s, "-o" ) == 0 ) { i++; outputFilename = argv[i]; } else if( strcmp( s, "-v" ) == 0 ) { verbose = true; } else if( strcmp( s, "-m" ) == 0 ) { drawM = true; } else { help(); return fprintf( stderr, "Unknown option %s\n", s ), -1; } } } if (verbose) cout << "\nParameters read...\t\t[OK]" << '\n'; if (verbose) cout << "Data init...\t\t\t"; // ========================================== Varible declaration ========================================== int num_features; int num_cameras; timer_wall timer1; std::vector< cv::Mat > images, images_depth;//, images_matches; // ==================================================================================================== // ========================================== Start execution ========================================= // ==================================================================================================== // ========================================== Read Images ========================================== if (verbose) { std::cout << "[OK]" << '\n'; // DATA initialization OK std::cout << "Reading Files:\t" << inputFilename_rgb << "\n"; std::cout << "File list...\t\t\t"; } importXMLImageList(inputFilename_rgb, imageList_rgb); //Reading list of images from XML list if (verbose) { std::cout << "[OK]\n"; std::cout << "Loading Images...\t\t"; } for (int i = 0; i < (int)imageList_rgb.size(); i++ ) //Store all images in std::vector<cv::Mat> { images.push_back( cv::imread(imageList_rgb[i], 1) ); } if (verbose) { std::cout << "[OK]\n"; std::cout << "Number of Images: " << images.size() << "\n"; printf("Size of Images: \tWidth: %i || Height: %i\n", images[0].size().width, images[0].size().height); } // ======================================== END Read Images ======================================== Eigen::Matrix3d K; if (load_k) // If Calibration matrix is taken from txt file { Eigen::MatrixXd K_load; importTXTEigen(filename_calib, K_load); K << K_load; } else { double wimg = images[0].size().width; double himg = images[0].size().height; double f = 1000.0; K << f, 0.0, wimg/2, 0.0, f, himg/2, 0.0, 0.0, 1.0; // Camera Matrix (intrinsics) } if (verbose) std::cout << "\nCalibration Matrix:\n" << K << "\n"; HandleDB mydb( (char*)filename_db.c_str() ); mydb.openDB(); if ( ram_db ) // If database is in ram, create table and index { mydb.createFeaturesTable(); mydb.createIndex1(); } if (!mydb.isOpen()) exit(0); if ( ram_db ) // If database is in ram, solve features map and store in db { boost::shared_ptr< SiftED > myfeat( new SiftED(&imageList_rgb) ); myfeat->solveSift(); // myfeat->loadImages(); if( drawM ) myfeat->enableKeyPoint(); boost::shared_ptr< MatchesMap > my_mmap( new MatchesMap(500,35) ); my_mmap->solveMatches(myfeat->getDescriptorsGPU()); my_mmap->robustifyMatches(myfeat->getKeypointsGPU()); timer1.start(); my_mmap->solveDB( &mydb, myfeat->getKeypointsGPU() ); std::cout << "Elapsed time to solve DB: " << timer1.elapsed_s() << " [s]\n"; // my_mmap.txt((char*)"./match.txt", myfeat->getKeypointsGPU()); if( drawM ) my_mmap->plot( &images, myfeat->getKeypointsSet() ); } boost::shared_ptr< FeaturesMap > featM (new FeaturesMap()); featM->solveVisibility( &mydb ); printf("Visibility Matrix [%d x %d]\n",featM->getVisibility()->rows(),featM->getVisibility()->cols()); num_cameras = featM->getNumberCameras(); num_features = featM->getNumberFeatures(); mydb.closeDB(); // SfM sfm01( num_cameras, num_features, K ); // // sfm01.solvePose( &my_mmap.globalMatch, &myfeat.set_of_keypoints); // sfm01.solvePose( (featM->getVisibility()).get(), (featM->getCoordinates()).get() ); // sfm01.solveStructure( (featM->getVisibility()).get(), (featM->getCoordinates()).get() ); // std::cout << "Structure =\n" << sfm01.Structure.transpose() << "\n"; // ========================================== Optimization ========================================== // double intrinsics[4] = { K(0,0), K(1,1), K(0,2), K(1,2) }; // std::vector< double > intrinsics_param(&intrinsics[0], &intrinsics[4]); double distcoeff[5] = {2.5552679187075661e-01, -5.8740292343503686e-01, -3.0863014649845459e-04, 1.9066445284294834e-03, 5.1108649981093257e-01}; std::vector< double > coefficients(&distcoeff[0], &distcoeff[5]); // std::vector< double > coefficients(5,0.0);/// active for dinosaur /* GlobalOptimizerSfM opt01; opt01.setParameters( (featM->getVisibility()).get(), (featM->getCoordinates()).get(), &sfm01.Quat_cumulative, &sfm01.tr_global, &sfm01.Structure ); opt01.setIntrinsics( &K ); opt01.setDistortion( &coefficients ); opt01.runBA();// argv[0] );// bundle adjustment to all data // FINAL DATA PRINTING *************************** sfm01.updateCamera(); // std::cout << "Recover structure matrix:\n" << sfm01.Structure.transpose() << "\n"; writePMVS("./pmvs", imageList_rgb, sfm01.Cameras_RCV, K, coefficients); */ timer1.start(); IncrementalBA opt01( (featM->getVisibility()).get(), (featM->getCoordinates()).get() ); opt01.setIntrinsics( K ); opt01.setDistortion( &coefficients ); opt01.runC(); GlobalOptimizerSfM opt03; opt03.setParameters( (featM->getVisibility()).get(), (featM->getCoordinates()).get(), &opt01.quaternion, &opt01.translation, &opt01.structure ); opt03.setIntrinsics( &K ); opt03.setDistortion( &coefficients ); opt03.runBA();// argv[0] );// bundle adjustment to all data std::cout << "Incrementel BA time: "<< timer1.elapsed_s() << " [s]\n"; opt01.updateCamera(); std::vector< Eigen::Matrix3d > Rotation(opt01.quaternion.size()); for (register int i = 0; i < Rotation.size(); ++i) Rotation[i] = opt01.quaternion[i].toRotationMatrix(); exportPMVS("./pmvs", imageList_rgb, opt01.Camera, K, coefficients); // ========================================== END Optimization ========================================== // plot TESTING // int max_WP = sfm01.plotSt.maxCoeff(); // std::cout << "maximum in plot WP = " << max_WP << "\n"; // std::cout << "plotSt = " << sfm01.plotSt.transpose() << "\n"; // std::vector< std::vector<cv::Point3d> > WP(max_WP+1); // std::vector<cv::Point3d> x3plot; // for (int cam = 0; cam < max_WP+1; cam++) // { // x3plot.clear(); // for (int ft = 0; ft < num_features; ft++) // { // if (cam == sfm01.plotSt(ft)) // { // x3plot.push_back( cv::Point3d(sfm01.Structure(0,ft),sfm01.Structure(1,ft),sfm01.Structure(2,ft)) ); // } // } // std::cout << "x3plot size = " << x3plot.size() << "\n"; // std::cout << "cam = " << cam << "\n"; // WP[cam] = x3plot; // } // end plot TESTING // Plot for IncrementalBA structure in one vector (Global) std::vector< std::vector<cv::Point3d> > WP; std::vector<cv::Point3d> pts; eigen2point3_vector( opt01.structure , pts ); WP.push_back(pts); // sfm data PlotGL::viewer.setRotation( &Rotation ); PlotGL::viewer.setTranslation( &opt01.translation ); PlotGL::viewer.setStructure( &WP ); // PlotGL::viewer.setColor( &Color ); // PLOT for sfm object structure in one vector (Global) // std::vector< std::vector<cv::Point3d> > WP; // std::vector<cv::Point3d> pts; // eigen2point3_vector( sfm01.Structure , pts ); // WP.push_back(pts); // // // sfm data // PlotGL::viewer.setRotation( &sfm01.Rot_global ); // PlotGL::viewer.setTranslation( &sfm01.tr_global ); // PlotGL::viewer.setStructure( &WP ); // // PlotGL::viewer.setColor( &Color ); PlotGL::viewer.run(argc, argv, !ram_db); // false); exit(0); }
// ================================================= MAIN ============================================== int main(int argc, char* argv[]) { // ========================================== Parameters =========================================== bool ram_db = true; bool verbose = false; bool drawM = false; bool load_k = false; bool save_ply = false; const char* filename_calib; const char* inputFilename_rgb; const char* inputFilename_depth; const char* outputFilename; std::string filename_db = ":memory:"; std::vector< std::string > imageList_rgb; std::vector< std::string > imageList_depth; // ========================================== Check parameters ========================================== if( argc < 2 ) { help(argv[0]); return 0; } else { for(int i = 1; i < argc; i++ ) { const char* s = argv[i]; if( strcmp( s, "-i" ) == 0 ) { i++; inputFilename_rgb = argv[i]; } else if( strcmp( s, "-d" ) == 0 ) { i++; inputFilename_depth = argv[i]; } else if( strcmp( s, "-o" ) == 0 ) { i++; outputFilename = argv[i]; save_ply = true; } else if( strcmp( s, "-db" ) == 0 ) { i++; filename_db = argv[i]; ram_db = false; } else if( strcmp( s, "-k" ) == 0 ) { i++; filename_calib = argv[i]; load_k = true; } else if( strcmp( s, "-v" ) == 0 ) { verbose = true; } else if( strcmp( s, "-m" ) == 0 ) { drawM = true; } else { help(argv[0]); return fprintf( stderr, "Unknown option %s\n", s ), -1; } } } if (verbose) cout << "Parameters read...\t\t[OK]" << '\n'; if (verbose) cout << "Data init...\t\t\t"; // ========================================== Varible declaration ========================================== int num_goodmatch = 35; int num_features; int num_cameras; timer_wall timer1; std::vector< cv::Mat > images, images_depth;//, images_matches; typedef std::vector< Eigen::Quaternion<double> > Qd_vector; typedef std::vector< Eigen::Vector3d > V3d_vector; boost::shared_ptr< Qd_vector > Qn_global; boost::shared_ptr< V3d_vector > tr_global; // ========================================== Read Images ========================================== if (verbose) { std::cout << "[OK]" << '\n'; // DATA initialization OK std::cout << "Reading Files:\t" << inputFilename_rgb << " & " << inputFilename_depth << '\n'; std::cout << "File list...\t\t\t"; } importXMLImageList(inputFilename_rgb, imageList_rgb); //Reading list of images from XML list importXMLImageList(inputFilename_depth, imageList_depth); if (verbose) { std::cout << "[OK]\n"; std::cout << "Loading Images...\t\t"; } for (int i = 0; i < (int)imageList_rgb.size(); i++ ) //Store all images in std::vector<cv::Mat> { images.push_back( cv::imread(imageList_rgb[i], 1) ); images_depth.push_back( cv::imread(imageList_depth[i], -1) ); } if (verbose) { std::cout << "[OK]\n"; std::cout << "Number of Images: " << images.size() << "\n"; printf("Size of Images: \tWidth: %i\t||\t Height: %i\n", images[0].size().width, images[0].size().height); std::cout << "\nDetection and Descriptor...\t"; } // ======================================== END Read Images ======================================== Eigen::Matrix3d K; if (load_k) // If Calibration matrix is taken from txt file { Eigen::MatrixXd K_load; importTXTEigen(filename_calib, K_load); K << K_load; } else { double wimg = images[0].size().width - 1.0; double himg = images[0].size().height - 1.0; double f = 520.0; K << f, 0.0, wimg/2, 0.0, f, himg/2, 0.0, 0.0, 1.0; // Camera Matrix (intrinsics) } if (verbose) std::cout << "\nCalibration Matrix:\n" << K << "\n"; // ==================================================================================================== // ========================================== Start execution ========================================= // ==================================================================================================== HandleDB mydb( (char*)filename_db.c_str() ); mydb.openDB(); if ( ram_db ) // If database is in ram, create table and index { mydb.createFeaturesTable(); mydb.createIndex1(); } if (!mydb.isOpen()) exit(0); if ( ram_db ) // If database is in ram, solve features map and store in db { boost::shared_ptr< SiftED > myfeat( new SiftED(&imageList_rgb) ); myfeat->solveSift(); // myfeat->loadImages(); if( drawM ) myfeat->enableKeyPoint(); boost::shared_ptr< MatchesMap > my_mmap( new MatchesMap(500,35) ); my_mmap->solveMatches(myfeat->getDescriptorsGPU()); my_mmap->robustifyMatches(myfeat->getKeypointsGPU()); my_mmap->depthFilter(myfeat->getKeypointsGPU(), &imageList_depth, 3); timer1.start(); my_mmap->solveDB( &mydb, myfeat->getKeypointsGPU() ); DEBUG_1( std::cout << "Elapsed time to solve DB: " << timer1.elapsed_s() << " [s]\n"; ) // my_mmap.txt((char*)"./match.txt", &myfeat.keypointsGPU); if( drawM ) my_mmap->plot( &images, myfeat->getKeypointsSet() ); }
int MainWindow::init_database() { int ret = 2; fprintf(stderr, "Opening database: %s\n", QString2filename(dbfile)); keys = NULL; reqs = NULL; certs = NULL; temps = NULL; crls = NULL; certView->setRootIsDecorated(db_x509::treeview); try { ret = initPass(); if (ret == 2) return ret; keys = new db_key(dbfile, this); reqs = new db_x509req(dbfile, this); certs = new db_x509(dbfile, this); temps = new db_temp(dbfile, this); crls = new db_crl(dbfile, this); } catch (errorEx &err) { Error(err); dbfile = ""; return ret; } mandatory_dn = ""; string_opt = QString("MASK:0x2002"); ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt)); hashBox::resetDefault(); pkcs11path = getDefaultPkcs11Lib(); workingdir = QDir::currentPath(); setOptFlags((QString())); try { pkcs11_lib p(pkcs11path); } catch (errorEx &e) { pkcs11path = QString(); } connect( keys, SIGNAL(newKey(pki_key *)), certs, SLOT(newKey(pki_key *)) ); connect( keys, SIGNAL(delKey(pki_key *)), certs, SLOT(delKey(pki_key *)) ); connect( keys, SIGNAL(newKey(pki_key *)), reqs, SLOT(newKey(pki_key *)) ); connect( keys, SIGNAL(delKey(pki_key *)), reqs, SLOT(delKey(pki_key *)) ); connect( certs, SIGNAL(connNewX509(NewX509 *)), this, SLOT(connNewX509(NewX509 *)) ); connect( reqs, SIGNAL(connNewX509(NewX509 *)), this, SLOT(connNewX509(NewX509 *)) ); connect( reqs, SIGNAL(newCert(pki_x509req *)), certs, SLOT(newCert(pki_x509req *)) ); connect( temps, SIGNAL(newCert(pki_temp *)), certs, SLOT(newCert(pki_temp *)) ); connect( temps, SIGNAL(newReq(pki_temp *)), reqs, SLOT(newItem(pki_temp *)) ); keyView->setIconSize(pki_evp::icon[0]->size()); reqView->setIconSize(pki_x509req::icon[0]->size()); certView->setIconSize(pki_x509::icon[0]->size()); tempView->setIconSize(pki_temp::icon->size()); crlView->setIconSize(pki_crl::icon->size()); keyView->setModel(keys); reqView->setModel(reqs); certView->setModel(certs); tempView->setModel(temps); crlView->setModel(crls); try { db mydb(dbfile); char *p; if (!mydb.find(setting, "workingdir")) { if ((p = (char *)mydb.load(NULL))) { workingdir = p; free(p); } } mydb.first(); if (!mydb.find(setting, "pkcs11path")) { if ((p = (char *)mydb.load(NULL))) { pkcs11path = p; free(p); } } mydb.first(); if (!mydb.find(setting, "default_hash")) { if ((p = (char *)mydb.load(NULL))) { hashBox::setDefault(p); free(p); } } mydb.first(); if (!mydb.find(setting, "mandatory_dn")) { if ((p = (char *)mydb.load(NULL))) { mandatory_dn = p; free(p); } } // what a stupid idea.... mydb.first(); if (!mydb.find(setting, "multiple_key_use")) { mydb.erase(); } mydb.first(); if (!mydb.find(setting, "string_opt")) { if ((p = (char *)mydb.load(NULL))) { string_opt = p; free(p); } } mydb.first(); if (!mydb.find(setting, "suppress")) { if ((p = (char *)mydb.load(NULL))) { QString x = p; free(p); if (x == "1") pki_base::suppress_messages = 1; } } mydb.first(); if (!mydb.find(setting, "optionflags")) { if ((p = (char *)mydb.load(NULL))) { setOptFlags((QString(p))); free(p); } } ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt)); mydb.first(); if (!mydb.find(setting, "mw_geometry")) { db_header_t h; if ((p = (char *)mydb.load(&h))) { if (h.version == 1) { QByteArray ba; ba = QByteArray::fromRawData(p, h.len); int w, h, i; w = db::intFromData(ba); h = db::intFromData(ba); i = db::intFromData(ba); resize(w,h); if (i != -1) tabView->setCurrentIndex(i); } free(p); } } } catch (errorEx &err) { Error(err); return ret; } setWindowTitle(tr(XCA_TITLE)); setItemEnabled(true); if (pki_evp::passwd.isNull()) QMessageBox::information(this, XCA_TITLE, tr("Using or exporting private keys will not be possible without providing the correct password")); dbindex->setText(tr("Database") + ":" + dbfile); load_engine(); return ret; }
int MainWindow::init_database() { int ret = 2; qDebug("Opening database: %s", QString2filename(dbfile)); keys = NULL; reqs = NULL; certs = NULL; temps = NULL; crls = NULL; Entropy::seed_rng(); certView->setRootIsDecorated(db_x509::treeview); try { ret = initPass(); if (ret == 2) return ret; keys = new db_key(dbfile, this); reqs = new db_x509req(dbfile, this); certs = new db_x509(dbfile, this); temps = new db_temp(dbfile, this); crls = new db_crl(dbfile, this); certs->updateAfterDbLoad(); } catch (errorEx &err) { Error(err); dbfile = ""; return ret; } searchEdit->setText(""); searchEdit->show(); statusBar()->addWidget(searchEdit, 1); mandatory_dn = ""; explicit_dn = explicit_dn_default; string_opt = QString("MASK:0x2002"); ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt)); hashBox::resetDefault(); pkcs11path = QString(); workingdir = QDir::currentPath(); setOptFlags((QString())); connect( keys, SIGNAL(newKey(pki_key *)), certs, SLOT(newKey(pki_key *)) ); connect( keys, SIGNAL(delKey(pki_key *)), certs, SLOT(delKey(pki_key *)) ); connect( keys, SIGNAL(newKey(pki_key *)), reqs, SLOT(newKey(pki_key *)) ); connect( keys, SIGNAL(delKey(pki_key *)), reqs, SLOT(delKey(pki_key *)) ); connect( certs, SIGNAL(connNewX509(NewX509 *)), this, SLOT(connNewX509(NewX509 *)) ); connect( reqs, SIGNAL(connNewX509(NewX509 *)), this, SLOT(connNewX509(NewX509 *)) ); connect( reqs, SIGNAL(newCert(pki_x509req *)), certs, SLOT(newCert(pki_x509req *)) ); connect( tempView, SIGNAL(newCert(pki_temp *)), certs, SLOT(newCert(pki_temp *)) ); connect( tempView, SIGNAL(newReq(pki_temp *)), reqs, SLOT(newItem(pki_temp *)) ); keyView->setIconSize(pki_evp::icon[0]->size()); reqView->setIconSize(pki_x509req::icon[0]->size()); certView->setIconSize(pki_x509::icon[0]->size()); tempView->setIconSize(pki_temp::icon->size()); crlView->setIconSize(pki_crl::icon->size()); keyView->setModel(keys); reqView->setModel(reqs); certView->setModel(certs); tempView->setModel(temps); crlView->setModel(crls); try { db mydb(dbfile); while (mydb.find(setting, QString()) == 0) { QString key; db_header_t head; char *p = (char *)mydb.load(&head); if (!p) { if (mydb.next()) break; continue; } key = head.name; if (key == "workingdir") workingdir = p; else if (key == "pkcs11path") pkcs11path = p; else if (key == "default_hash") hashBox::setDefault(p); else if (key == "mandatory_dn") mandatory_dn = p; else if (key == "explicit_dn") explicit_dn = p; /* what a stupid idea.... */ else if (key == "multiple_key_use") mydb.erase(); else if (key == "string_opt") string_opt = p; else if (key == "suppress") mydb.erase(); else if (key == "optionflags1") setOptFlags((QString(p))); /* Different optionflags, since setOptFlags() * does an abort() for unknown flags in * older versions. *Another stupid idea* * This is for backward compatibility */ else if (key == "optionflags") setOptFlags_old((QString(p))); else if (key == "defaultkey") NewKey::setDefault((QString(p))); else if (key == "mw_geometry") set_geometry(p, &head); free(p); if (mydb.next()) break; } } catch (errorEx &err) { Error(err); return ret; } ASN1_STRING_set_default_mask_asc((char*)CCHAR(string_opt)); if (explicit_dn.isEmpty()) explicit_dn = explicit_dn_default; setWindowTitle(tr(XCA_TITLE)); setItemEnabled(true); if (pki_evp::passwd.isNull()) XCA_INFO(tr("Using or exporting private keys will not be possible without providing the correct password")); dbindex->setText(tr("Database") + ": " + dbfile); load_engine(); return ret; }
void MainWindow::close_database() { QByteArray ba; if (!dbfile.isEmpty()) { ba += db::intToData(size().width()); ba += db::intToData(size().height()); ba += db::intToData(tabView->currentIndex()); db mydb(dbfile); mydb.set((const unsigned char *)ba.constData(), ba.size(), 1, setting, "mw_geometry"); } setItemEnabled(false); statusBar()->removeWidget(searchEdit); dbindex->clear(); keyView->setModel(); reqView->setModel(); certView->setModel(); tempView->setModel(); crlView->setModel(); if (crls) delete(crls); if (reqs) delete(reqs); if (certs) delete(certs); if (temps) delete(temps); if (keys) delete(keys); reqs = NULL; certs = NULL; temps = NULL; keys = NULL; pki_evp::passwd.cleanse(); pki_evp::passwd = QByteArray(); if (!crls) return; crls = NULL; try { int ret; db mydb(dbfile); ret = mydb.shrink( DBFLAG_OUTDATED | DBFLAG_DELETED ); if (ret == 1) XCA_INFO(tr("Errors detected and repaired while deleting outdated items from the database. A backup file was created")); if (ret == 2) XCA_INFO(tr("Removing deleted or outdated items from the database failed.")); } catch (errorEx &err) { MainWindow::Error(err); } update_history(dbfile); pkcs11::remove_libs(); enableTokenMenu(pkcs11::loaded()); dbfile.clear(); }
void db_base::loadContainer() { db mydb(dbName); unsigned char *p = NULL; db_header_t head; pki_base *pki; for (int i=0; i < pkitype.count(); i++) { mydb.first(); while (mydb.find(pkitype[i], QString()) == 0) { QString s; p = mydb.load(&head); if (!p) { printf("Load was empty !\n"); goto next; } pki = newPKI(&head); if (pki->getVersion() < head.version) { printf("Item[%s]: Version %d " "> known version: %d -> ignored\n", head.name, head.version, pki->getVersion() ); free(p); delete pki; goto next; } pki->setIntName(QString::fromUtf8(head.name)); try { pki->fromData(p, &head); } catch (errorEx &err) { err.appendString(pki->getIntName()); mainwin->Error(err); delete pki; pki = NULL; } free(p); if (pki) { inToCont(pki); } next: if (mydb.next()) break; } } mydb.first(); if (!mydb.find(setting, class_name + "_hdView")) { QByteArray ba; char *p; if ((p = (char *)mydb.load(&head))) { ba = QByteArray(p, head.len - sizeof(db_header_t)); free(p); } if (head.version != 5) return; try { allHeaders.fromData(ba); } catch (errorEx()) { for (int i=0; i< allHeaders.count(); i++) { allHeaders[i]->reset(); } } } emit columnsContentChanged(); return; }