コード例 #1
0
ファイル: policy_cache.c プロジェクト: crossbuild/apparmor
bool valid_cached_file_version(const char *cachename)
{
	char buffer[16];
	autofclose FILE *f;
	if (!(f = fopen(cachename, "r"))) {
		PERROR("Error: Could not read cache file '%s', skipping...\n", cachename);
		return false;
	}
	size_t res = fread(buffer, 1, 16, f);
	if (res < 16) {
		if (debug_cache)
			pwarn("%s: cache file '%s' invalid size\n", progname, cachename);
		return false;
	}

	/* 12 byte header that is always the same and then 4 byte version # */
	if (memcmp(buffer, header_string, HEADER_STRING_SIZE) != 0) {
		if (debug_cache)
			pwarn("%s: cache file '%s' has wrong header\n", progname, cachename);
		return false;
	}

	uint32_t version = cpu_to_le32(ENCODE_VERSION(force_complain,
						      policy_version,
						      parser_abi_version,
						      kernel_abi_version));
	if (memcmp(buffer + 12, &version, 4) != 0) {
		if (debug_cache)
			pwarn("%s: cache file '%s' has wrong version\n", progname, cachename);
		return false;
	}

	return true;
}
コード例 #2
0
ファイル: little.c プロジェクト: GaloisInc/sqlite
void set_version(little_file *self) {
  int dfd, fd;
  version_t version = ENCODE_VERSION(self->version);
  int nextfreeblock = ENCODE_INT(self->nextfreeblock);

  dfd = open(self->name, O_RDONLY);
  fd  = openat(dfd, version_file, O_WRONLY | O_CREAT, 0666);
  close(dfd);
  write(fd, &version, sizeof(version_t));
  write(fd, &nextfreeblock, sizeof(int));
  close(fd);
}
コード例 #3
0
void sd_serialize_top_profile(std::ostringstream &buf, Profile *profile)
{
	uint32_t version;

	version = ENCODE_VERSION(force_complain, policy_version,
				 parser_abi_version, kernel_abi_version);

	sd_write_name(buf, "version");
	sd_write_uint32(buf, version);

	if (profile->ns) {
		sd_write_string(buf, profile->ns, "namespace");
	}

	sd_serialize_profile(buf, profile, profile->parent ? 1 : 0);
}
コード例 #4
0
ファイル: little.c プロジェクト: GaloisInc/sqlite
static int write_block(const char* path, int block, const char* buffer, version_t version) {
  int dfd, fd, res, err;
  char name[LITTLE_MAX_PATH];
  trace("W %d %s\n", block, path);
  dfd = open(path,O_RDONLY);
  if (dfd == -1) { perror(NULL); return -errno;}
  snprintf(name,sizeof(name),"%d", block);
  fd = openat(dfd,name,O_WRONLY|O_CREAT,0666);
  close(dfd);
  if (fd == -1) { perror(NULL); return -errno;}
  version = ENCODE_VERSION(version);
  res = write(fd, &version, sizeof(version_t));
  if (res == -1) {
    err=errno;
    close(fd);
    return -err;
  }
  res = write(fd, buffer, LITTLE_SECTOR_SIZE);
  fsync(fd);
  close(fd);
  if (res == -1) { perror(NULL); return -errno;}
  return res;
}