示例#1
0
文件: db_dump.cpp 项目: LiTianjue/xca
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());
	}
}
示例#2
0
void MainWindow::load_history()
{
	QFile file;
	QString name = getUserSettingsDir() + QDir::separator() + "dbhistory";

	file.setFileName(name);
	if (!file.open(QIODevice::ReadOnly))
		return;

	history.clear();
	while (!file.atEnd()) {
		QString name;
		char buf[1024];
		ssize_t size = file.readLine(buf, sizeof buf);
		if (size <= 0)
			break;
		name = filename2QString(buf);
		name = name.trimmed();
		if (name.size() == 0)
			continue;
		if (history.indexOf(name) == -1)
			history << name;
	}
	file.close();
	update_history_menu();
}
示例#3
0
int MainWindow::open_default_db()
{
	if (!dbfile.isEmpty())
		return 0;
	FILE *fp = fopen(QString2filename(getUserSettingsDir() +
					QDir::separator() + "defaultdb"), "r");
	if (!fp)
		return 0;

	char buff[256];
	size_t len = fread(buff, 1, 255, fp);
	fclose(fp);
	buff[len] = 0;
	dbfile = filename2QString(buff).trimmed();
	if (QFile::exists(dbfile))
		return init_database();
	return 0;
}
示例#4
0
/*!
   Load a spkac FILE into this request structure.
   The file format follows the conventions understood by the 'openssl ca'
   command. (see: 'man ca')
*/
int pki_x509req::load_spkac(const QString filename)
{
	QFile file;
	x509name subject;
	EVP_PKEY *pktmp = NULL;
	pki_ign_openssl_error();

	file.setFileName(filename);
        if (!file.open(QIODevice::ReadOnly))
		return 1;

	while (!file.atEnd()) {
		int idx, nid;
		QByteArray line = file.readLine();
		if (line.size() == 0)
			continue;
		idx = line.indexOf('=');
		if (idx == -1)
			goto err;
		QString type = line.left(idx).trimmed();
		line = line.mid(idx+1).trimmed();

		idx = type.lastIndexOf(QRegExp("[:,\\.]"));
		if (idx != -1)
			type = type.mid(idx+1);

		if ((nid = OBJ_txt2nid(CCHAR(type))) == NID_undef) {
			if (type != "SPKAC")
				goto err;
			pki_ign_openssl_error();
			spki = NETSCAPE_SPKI_b64_decode(line, line.size());
			if (!spki)
				goto err;
			/*
			  Now extract the key from the SPKI structure and
			  check the signature.
			 */
			pktmp = NETSCAPE_SPKI_get_pubkey(spki);
			if (pktmp == NULL)
				goto err;

			if (NETSCAPE_SPKI_verify(spki, pktmp) != 1)
				goto err;
		} else {
			// gather all values in the x509name subject.
			subject.addEntryByNid(nid,
				filename2QString(line.constData()));
		}
	}
	if (!pktmp)
		goto err;
	setSubject(subject);
	X509_REQ_set_pubkey(request, pktmp);
	EVP_PKEY_free(pktmp);
	return 0;
err:
	if (pktmp)
		EVP_PKEY_free(pktmp);
	if (spki) {
		NETSCAPE_SPKI_free(spki);
		spki = NULL;
	}
	return 1;
}
示例#5
0
文件: db_dump.cpp 项目: LiTianjue/xca
static QString fileNAmeDecoderFunc(const QByteArray &localFileName)
{
	return filename2QString(localFileName.constData());
}