コード例 #1
0
	void TarUtils::read( const ibrcommon::File &extract_folder, std::istream &input )
	{
		struct archive *a;
		struct archive_entry *entry;
		int ret,fd;

		a = archive_read_new();
		archive_read_support_filter_all(a);
		archive_read_support_compression_all(a);
		archive_read_support_format_tar(a);

		archive_read_open(a, (void*) &input, &__tar_utils_open_callback, &__tar_utils_read_callback, &__tar_utils_close_callback);

		while ((ret = archive_read_next_header(a, &entry)) == ARCHIVE_OK )
		{
			ibrcommon::File filename = extract_folder.get(archive_entry_pathname(entry));
			ibrcommon::File path = filename.getParent();
			ibrcommon::File::createDirectory(path);
			fd = open(filename.getPath().c_str(),O_CREAT|O_WRONLY,0600);
			if(fd < 0) throw ibrcommon::IOException("cannot open file " + path.getPath());
			archive_read_data_into_fd(a,fd);
			close(fd);
		}

		archive_read_free(a);
	}
コード例 #2
0
		void inotifysocket::watch(const ibrcommon::File &path, int opts) throw (ibrcommon::socket_exception)
		{
#ifdef HAVE_SYS_INOTIFY_H
			int wd = inotify_add_watch(this->fd(), path.getPath().c_str(), opts);
			_watch_map[wd] = path;
#endif
		}
コード例 #3
0
		void FileMonitor::watch(const ibrcommon::File &watch)
		{
			IBRCOMMON_LOGGER_DEBUG_TAG("FileMonitor", 5) << "watch on: " << watch.getPath() << IBRCOMMON_LOGGER_ENDL;

			if (!watch.isDirectory())
				throw ibrcommon::Exception("can not watch files, please specify a directory");

			ibrcommon::socketset socks = _socket.getAll();
			if (socks.size() == 0) return;
			inotifysocket &sock = dynamic_cast<inotifysocket&>(**socks.begin());

#ifdef HAVE_SYS_INOTIFY_H
			sock.watch(watch, IN_CREATE | IN_DELETE);
#endif
			_watchset.insert(watch);
		}
コード例 #4
0
		void FileMonitor::adopt(const ibrcommon::File &path)
		{
			// look for ".dtndrive" file
			const ibrcommon::File drivefile = path.get(".dtndrive");
			if (drivefile.exists())
			{
				ibrcommon::ConfigFile cf(drivefile.getPath());

				try {
					const dtn::data::EID eid( cf.read<std::string>("EID") );

					dtn::core::Node n(eid);
					const std::string uri = "file://" + path.getPath() + "/" + cf.read<std::string>("PATH");

					n.add(dtn::core::Node::URI(dtn::core::Node::NODE_DISCOVERED, dtn::core::Node::CONN_FILE, uri, 0, 10));
					dtn::core::BundleCore::getInstance().getConnectionManager().add(n);

					_active_paths[path] = n;

					IBRCOMMON_LOGGER_DEBUG_TAG("FileMonitor", 5) << "Node on drive found: " << n.getEID().getString() << IBRCOMMON_LOGGER_ENDL;

				} catch (const ibrcommon::ConfigFile::key_not_found&) {};
			}
		}
コード例 #5
0
		void SecurityKeyManager::createRSA(const dtn::data::EID &ref, const int bits)
		{
			const ibrcommon::File privkey = getKeyFile(ref, SecurityKey::KEY_PRIVATE);
			const ibrcommon::File pubkey = getKeyFile(ref, SecurityKey::KEY_PUBLIC);
			RSA* rsa = RSA_new();
			BIGNUM* e = BN_new();

			BN_set_word(e, 65537);

			RSA_generate_key_ex(rsa, bits, e, NULL);

			BN_free(e);
			e = NULL;

			// write private key
			int fd = ::open(privkey.getPath().c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0600);

			FILE * rsa_privkey_file = fdopen(fd, "w");
			if (!rsa_privkey_file) {
				IBRCOMMON_LOGGER_TAG(SecurityKeyManager::TAG, error) << "Failed to open " << privkey.getPath() << IBRCOMMON_LOGGER_ENDL;
				RSA_free(rsa);
				return;
			}
			PEM_write_RSAPrivateKey(rsa_privkey_file, rsa, NULL, NULL, 0, NULL, NULL);
			fclose(rsa_privkey_file);

			// write public key
			FILE * rsa_pubkey_file = fopen(pubkey.getPath().c_str(), "w+");
			if (!rsa_pubkey_file) {
				IBRCOMMON_LOGGER_TAG(SecurityKeyManager::TAG, error) << "Failed to open " << privkey.getPath() << IBRCOMMON_LOGGER_ENDL;
				RSA_free(rsa);
				return;
			}
			PEM_write_RSA_PUBKEY(rsa_pubkey_file, rsa);
			fclose(rsa_pubkey_file);

			RSA_free(rsa);

			// set trust-level to high
			SecurityKey key = get(ref, SecurityKey::KEY_PUBLIC);
			key.trustlevel = SecurityKey::HIGH;
			store(key);
		}
コード例 #6
0
ファイル: dtntrigger.cpp プロジェクト: kleymenus/ibrdtn
int init(int argc, char** argv)
{
	int index;
	int c;

	opterr = 0;

	while ((c = getopt (argc, argv, "w:")) != -1)
	switch (c)
	{
		case 'w':
			blob_path = ibrcommon::File(optarg);
			break;

		case '?':
			if (optopt == 'w')
			fprintf (stderr, "Option -%c requires an argument.\n", optopt);
			else if (isprint (optopt))
			fprintf (stderr, "Unknown option `-%c'.\n", optopt);
			else
			fprintf (stderr,
					 "Unknown option character `\\x%x'.\n",
					 optopt);
			return 1;

		default:
			print_help();
			abort();
			break;
	}

	int optindex = 0;
	for (index = optind; index < argc; index++)
	{
		switch (optindex)
		{
		case 0:
			_appname = std::string(argv[index]);
			break;

		case 1:
			_shell = std::string(argv[index]);
			break;

		case 2:
			_script = std::string(argv[index]);
			break;
		}

		optindex++;
	}

	// print help if not enough parameters are set
	if (optindex < 2) { print_help(); exit(0); }

	// enable file based BLOBs if a correct path is set
	if (blob_path.exists())
	{
		ibrcommon::BLOB::changeProvider(new ibrcommon::FileBLOBProvider(blob_path));
	}

	return 0;
}
コード例 #7
0
	FATFile FATFile::getParent() const
	{
		const ibrcommon::File parent = ibrcommon::File::getParent();
		return FATFile(_reader, parent.getPath());
	}
コード例 #8
0
	FATFile FATFile::get(const std::string &filename) const
	{
		const ibrcommon::File child = ibrcommon::File::get(filename);
		return FATFile(_reader, child.getPath());
	}
コード例 #9
0
ファイル: DataStorage.cpp プロジェクト: abrahammartin/ibrdtn
		DataStorage::Hash::Hash(const ibrcommon::File &file) : value(file.getBasename()) {}